From 6adc5cf4d4201ac59b12a4403e2979c08a9fa927 Mon Sep 17 00:00:00 2001 From: AlexMuresan Date: Tue, 5 Dec 2017 11:50:09 +0200 Subject: [PATCH] Raise proper exception in case of vif plug errors The Nova Compute manager expects a VirtualInterfacePlugException exception to be raised when a vif plug fails. This particularly affects the service initialization step. If we're raising an exception other than the above mentioned one, the exception won't be cought, in which case the Nova Compute service will stop. This change ensures that we're raising the expected exception if vif plugging fails. Change-Id: Ibaa405577d4fa06f27fdd9440aca49be0c620af5 Closes-bug: #1736392 --- compute_hyperv/nova/vmops.py | 7 ++++++- compute_hyperv/tests/unit/test_vmops.py | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/compute_hyperv/nova/vmops.py b/compute_hyperv/nova/vmops.py index 1da6641e..7cded522 100644 --- a/compute_hyperv/nova/vmops.py +++ b/compute_hyperv/nova/vmops.py @@ -1017,7 +1017,12 @@ class VMOps(object): def plug_vifs(self, instance, network_info): if network_info: for vif in network_info: - self._vif_driver.plug(instance, vif) + try: + self._vif_driver.plug(instance, vif) + except Exception as exc: + LOG.exception("Failed to plug vif: '%s'.", + vif, instance=instance) + raise exception.VirtualInterfacePlugException(exc) def unplug_vifs(self, instance, network_info): if network_info: diff --git a/compute_hyperv/tests/unit/test_vmops.py b/compute_hyperv/tests/unit/test_vmops.py index 4c3c8170..0994903a 100644 --- a/compute_hyperv/tests/unit/test_vmops.py +++ b/compute_hyperv/tests/unit/test_vmops.py @@ -1598,6 +1598,18 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase): network_info=mock_network_info) self._vmops._vif_driver.plug.assert_has_calls(calls) + def test_plug_vifs_failed(self): + mock_instance = fake_instance.fake_instance_obj(self.context) + fake_vif1 = {'id': mock.sentinel.ID1, + 'type': mock.sentinel.vif_type1} + mock_network_info = [fake_vif1] + + self._vmops._vif_driver.plug.side_effect = exception.NovaException + + self.assertRaises(exception.VirtualInterfacePlugException, + self._vmops.plug_vifs, + mock_instance, mock_network_info) + def test_unplug_vifs(self): mock_instance = fake_instance.fake_instance_obj(self.context) fake_vif1 = {'id': mock.sentinel.ID1,