From 03c412ff011a8d4e86afbada24db675028861728 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Tue, 30 Aug 2016 12:21:25 -0700 Subject: [PATCH] split out l3-ha specific test from TestMl2PortsV2 split out test_update_port_status_notify_port_event_after_update from ml2.test_plugin.TestMl2PortsV2 into TestMl2PortsV2WithL3 The change set of 25f5912cf8f69f18d111bd60a6cc6ee488755ff3 change id of Iedad1ccae45005efaaa74d5571df04197757d07a introduced a test, test_update_port_status_notify_port_event_after_update, that is valid only when l3 plugin support l3-ha. Such assumption isn't always true depending on actual ml2 driver. Since test cases in ml2.test_plugin is used as a common base for multiple drivers, test_update_port_status_notify_port_event_after_update, may or may not pass. So split out tests with very specific assumption into a new dedicated testcase so that each driver can safely reuse tests in tests/unit/plugin/ml2 based on their characteristics. Closes-Bug: #1618601 Change-Id: Ie81dde976649111d029a7d107c99960aded64915 --- neutron/tests/unit/plugins/ml2/test_plugin.py | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py index 8248b34dd8c..2599a97e13c 100644 --- a/neutron/tests/unit/plugins/ml2/test_plugin.py +++ b/neutron/tests/unit/plugins/ml2/test_plugin.py @@ -710,26 +710,6 @@ def test_update_port_status_build(self): self.assertEqual('DOWN', port['port']['status']) self.assertEqual('DOWN', self.port_create_status) - def test_update_port_status_notify_port_event_after_update(self): - ctx = context.get_admin_context() - plugin = manager.NeutronManager.get_plugin() - # enable subscription for events - l3_router_plugin.L3RouterPlugin() - l3plugin = manager.NeutronManager.get_service_plugins().get( - p_const.L3_ROUTER_NAT) - host_arg = {portbindings.HOST_ID: HOST} - with mock.patch.object(l3plugin.l3_rpc_notifier, - 'routers_updated_on_host') as mock_updated: - with self.port(device_owner=constants.DEVICE_OWNER_ROUTER_HA_INTF, - device_id=TEST_ROUTER_ID, - arg_list=(portbindings.HOST_ID,), - **host_arg) as port: - plugin.update_port_status( - ctx, port['port']['id'], - constants.PORT_STATUS_ACTIVE, host=HOST) - mock_updated.assert_called_once_with( - mock.ANY, [TEST_ROUTER_ID], HOST) - def test_update_port_status_short_id(self): ctx = context.get_admin_context() plugin = manager.NeutronManager.get_plugin() @@ -1108,6 +1088,30 @@ def commit(self, con): self.assertTrue(listener.except_raised) +class TestMl2PortsV2WithL3(test_plugin.TestPortsV2, Ml2PluginV2TestCase): + """For testing methods that require the L3 service plugin.""" + + def test_update_port_status_notify_port_event_after_update(self): + ctx = context.get_admin_context() + plugin = manager.NeutronManager.get_plugin() + # enable subscription for events + l3_router_plugin.L3RouterPlugin() + l3plugin = manager.NeutronManager.get_service_plugins().get( + p_const.L3_ROUTER_NAT) + host_arg = {portbindings.HOST_ID: HOST} + with mock.patch.object(l3plugin.l3_rpc_notifier, + 'routers_updated_on_host') as mock_updated: + with self.port(device_owner=constants.DEVICE_OWNER_ROUTER_HA_INTF, + device_id=TEST_ROUTER_ID, + arg_list=(portbindings.HOST_ID,), + **host_arg) as port: + plugin.update_port_status( + ctx, port['port']['id'], + constants.PORT_STATUS_ACTIVE, host=HOST) + mock_updated.assert_called_once_with( + mock.ANY, [TEST_ROUTER_ID], HOST) + + class TestMl2PluginOnly(Ml2PluginV2TestCase): """For testing methods that don't call drivers"""