From 160ed6ff652b80cd0a86d41dc3f66c15cee66290 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Mon, 16 Nov 2020 17:35:07 +0000 Subject: [PATCH] Add missing exception Change Idd49b0c70caedfcd42420ffa2ac926a6087d406e added support for discovery of PMEM devices by the libvirt driver. Some error handling code in this was expected to raise a 'GetPMEMNamespacesFailed' exception, however, a typo meant the exception was actually called 'GetPMEMNamespaceFailed' (singular). This exception was later removed in change I6fd027fb51823b8a8a24ed7b864a2191c4e8e8c0 because it had no references. Re-introduce the exception, this time with the correct name, and add some unit tests to prevent us regressing. Change-Id: I3b597a46314a1b29a952fc0f7a9c4537341e37b8 Signed-off-by: Stephen Finucane Closes-Bug: #1904446 --- nova/exception.py | 4 ++++ nova/tests/unit/virt/libvirt/test_driver.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/nova/exception.py b/nova/exception.py index a70b0c3810e1..862bbab92710 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -2274,6 +2274,10 @@ class PMEMNamespaceConfigInvalid(NovaException): "please check your conf file. ") +class GetPMEMNamespacesFailed(NovaException): + msg_fmt = _("Get PMEM namespaces on host failed: %(reason)s.") + + class VPMEMCleanupFailed(NovaException): msg_fmt = _("Failed to clean up the vpmem backend device %(dev)s: " "%(error)s") diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index cbe5bbabf1f0..d1933971c46f 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -27501,6 +27501,15 @@ class LibvirtPMEMNamespaceTests(test.NoDBTestCase): self.assertRaises(exception.PMEMNamespaceConfigInvalid, drvr._discover_vpmems, vpmem_conf) + @mock.patch('nova.privsep.libvirt.get_pmem_namespaces') + def test_get_vpmems_on_host__exception(self, mock_get_ns): + drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) + mock_get_ns.side_effect = Exception('foo') + + self.assertRaises( + exception.GetPMEMNamespacesFailed, + drvr._get_vpmems_on_host) + @mock.patch('nova.virt.hardware.get_vpmems') def test_get_ordered_vpmems(self, mock_labels): # get orgered vpmems based on flavor extra_specs