Skip to content

Commit

Permalink
split out l3-ha specific test from TestMl2PortsV2
Browse files Browse the repository at this point in the history
split out test_update_port_status_notify_port_event_after_update
from ml2.test_plugin.TestMl2PortsV2 into TestMl2PortsV2WithL3

The change set of 25f5912
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
  • Loading branch information
yamahata committed Aug 31, 2016
1 parent 92bcaed commit 03c412f
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions neutron/tests/unit/plugins/ml2/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"""

Expand Down

0 comments on commit 03c412f

Please sign in to comment.