From 7bc85184767cca59a87f03bcca19570bbf24b4eb Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Wed, 17 May 2017 10:14:10 +0300 Subject: [PATCH] NSX|V: Fix broken unit tests Commit I54ebf2be14e82f288a9bf177967f1136b72b289e added a unit test that should be modified a little to match the plugin code. In addition, commit Ib748947bcd85253aa22e370a56870afbfbafa19b broke some QoS unit tests. Change-Id: Iab0202a28bfa525c4cd91e776ac2bdba56a807f6 --- vmware_nsx/tests/unit/nsx_v/test_plugin.py | 32 +++++++++++++++++++ .../services/qos/test_nsxv_notification.py | 6 ++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/vmware_nsx/tests/unit/nsx_v/test_plugin.py b/vmware_nsx/tests/unit/nsx_v/test_plugin.py index c797a8fb59..92f361c3a1 100644 --- a/vmware_nsx/tests/unit/nsx_v/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_v/test_plugin.py @@ -1635,6 +1635,38 @@ class TestPortsV2(NsxVPluginV2TestCase, self.assertEqual('direct', res['port']['binding:vnic_type']) + def test_delete_network_port_exists_owned_by_network_port_not_found(self): + """Tests that we continue to gracefully delete the network even if + a neutron:dhcp-owned port was deleted concurrently. + """ + res = self._create_network(fmt=self.fmt, name='net', + admin_state_up=True) + network = self.deserialize(self.fmt, res) + network_id = network['network']['id'] + self._create_port(self.fmt, network_id, + device_owner=constants.DEVICE_OWNER_DHCP) + # Raise PortNotFound when trying to delete the port to simulate a + # concurrent delete race; note that we actually have to delete the port + # "out of band" otherwise deleting the network will fail because of + # constraints in the data model. + plugin = directory.get_plugin() + orig_delete = plugin.delete_port + + def fake_delete_port(context, id, force_delete_dhcp=False): + # Delete the port for real from the database and then raise + # PortNotFound to simulate the race. + self.assertIsNone(orig_delete( + context, id, + force_delete_dhcp=force_delete_dhcp)) + raise n_exc.PortNotFound(port_id=id) + + p = mock.patch.object(plugin, 'delete_port') + mock_del_port = p.start() + mock_del_port.side_effect = fake_delete_port + req = self.new_delete_request('networks', network_id) + res = req.get_response(self.api) + self.assertEqual(webob.exc.HTTPNoContent.code, res.status_int) + class TestSubnetsV2(NsxVPluginV2TestCase, test_plugin.TestSubnetsV2): diff --git a/vmware_nsx/tests/unit/services/qos/test_nsxv_notification.py b/vmware_nsx/tests/unit/services/qos/test_nsxv_notification.py index a9eee450ec..dbef1bd3c8 100644 --- a/vmware_nsx/tests/unit/services/qos/test_nsxv_notification.py +++ b/vmware_nsx/tests/unit/services/qos/test_nsxv_notification.py @@ -151,8 +151,7 @@ class TestQosNsxVNotification(test_plugin.NsxVPluginV2TestCase, self.ctxt, **self.policy_data['policy']) # set the rule in the policy data - if action != 'create': - setattr(_policy, "rules", [self.rule]) + setattr(_policy, "rules", [self.rule]) with mock.patch('neutron.services.qos.qos_plugin.QoSPlugin.' 'get_policy', @@ -218,8 +217,7 @@ class TestQosNsxVNotification(test_plugin.NsxVPluginV2TestCase, self.ctxt, **self.policy_data['policy']) # set the rule in the policy data - if action != 'create': - setattr(_policy, "rules", [self.dscp_rule]) + setattr(_policy, "rules", [self.dscp_rule]) plugin = self.qos_plugin with mock.patch('neutron.services.qos.qos_plugin.QoSPlugin.' 'get_policy',