|
18 | 18 | from neutron_lib.callbacks import events
|
19 | 19 | from neutron_lib.callbacks import registry
|
20 | 20 | from neutron_lib.callbacks import resources
|
| 21 | +from neutron_lib import constants as nlib_consts |
21 | 22 | from neutron_lib import exceptions as n_exc
|
22 | 23 | from neutron_lib.services.trunk import constants as trunk_consts
|
23 | 24 | from oslo_config import cfg
|
24 | 25 |
|
25 | 26 | from neutron.common.ovn.constants import OVN_ML2_MECH_DRIVER_NAME
|
26 | 27 | from neutron.objects.ports import Port
|
27 | 28 | from neutron.objects.ports import PortBinding
|
| 29 | +from neutron.objects import trunk as trunk_objects |
| 30 | +from neutron.services.trunk import drivers |
28 | 31 | from neutron.services.trunk.drivers.ovn import trunk_driver
|
| 32 | +from neutron.services.trunk import plugin as trunk_plugin |
29 | 33 | from neutron.tests import base
|
30 | 34 | from neutron.tests.unit import fake_resources
|
| 35 | +from neutron.tests.unit.plugins.ml2 import test_plugin |
31 | 36 |
|
32 | 37 |
|
33 | 38 | class TestTrunkHandler(base.BaseTestCase):
|
@@ -363,6 +368,70 @@ def test_subport_event_invalid(self, s_deleted, s_added):
|
363 | 368 | s_deleted.assert_not_called()
|
364 | 369 |
|
365 | 370 |
|
| 371 | +class TestTrunkHandlerWithPlugin(test_plugin.Ml2PluginV2TestCase): |
| 372 | + def setUp(self): |
| 373 | + super().setUp() |
| 374 | + self.drivers_patch = mock.patch.object(drivers, 'register').start() |
| 375 | + self.compat_patch = mock.patch.object( |
| 376 | + trunk_plugin.TrunkPlugin, 'check_compatibility').start() |
| 377 | + self.trunk_plugin = trunk_plugin.TrunkPlugin() |
| 378 | + self.trunk_plugin.add_segmentation_type('vlan', lambda x: True) |
| 379 | + self.plugin_driver = mock.Mock() |
| 380 | + self.trunk_handler = trunk_driver.OVNTrunkHandler(self.plugin_driver) |
| 381 | + |
| 382 | + def _create_test_trunk(self, port, subports=None): |
| 383 | + subports = subports if subports else [] |
| 384 | + trunk = {'port_id': port['port']['id'], |
| 385 | + 'project_id': 'test_tenant', |
| 386 | + 'sub_ports': subports} |
| 387 | + response = ( |
| 388 | + self.trunk_plugin.create_trunk(self.context, {'trunk': trunk})) |
| 389 | + return response |
| 390 | + |
| 391 | + def _get_trunk_obj(self, trunk_id): |
| 392 | + return trunk_objects.Trunk.get_object(self.context, id=trunk_id) |
| 393 | + |
| 394 | + def test_parent_active_triggers_trunk_active(self): |
| 395 | + with self.port() as new_parent: |
| 396 | + new_parent['status'] = nlib_consts.PORT_STATUS_ACTIVE |
| 397 | + old_parent = {'status': nlib_consts.PORT_STATUS_DOWN} |
| 398 | + old_trunk = self._create_test_trunk(new_parent) |
| 399 | + old_trunk = self._get_trunk_obj(old_trunk['id']) |
| 400 | + old_trunk.update(status=trunk_consts.TRUNK_DOWN_STATUS) |
| 401 | + trunk_details = {'trunk_id': old_trunk.id} |
| 402 | + new_parent['trunk_details'] = trunk_details |
| 403 | + old_parent['trunk_details'] = trunk_details |
| 404 | + self.trunk_handler.port_updated( |
| 405 | + resources.PORT, |
| 406 | + events.AFTER_UPDATE, |
| 407 | + None, |
| 408 | + payload=events.DBEventPayload( |
| 409 | + self.context, states=(old_parent, new_parent))) |
| 410 | + new_trunk = self._get_trunk_obj(old_trunk.id) |
| 411 | + self.assertEqual( |
| 412 | + trunk_consts.TRUNK_ACTIVE_STATUS, new_trunk.status) |
| 413 | + |
| 414 | + def test_parent_build_does_not_trigger_trunk_active(self): |
| 415 | + with self.port() as new_parent: |
| 416 | + new_parent['status'] = nlib_consts.PORT_STATUS_BUILD |
| 417 | + old_parent = {'status': nlib_consts.PORT_STATUS_DOWN} |
| 418 | + old_trunk = self._create_test_trunk(new_parent) |
| 419 | + old_trunk = self._get_trunk_obj(old_trunk['id']) |
| 420 | + old_trunk.update(status=trunk_consts.TRUNK_DOWN_STATUS) |
| 421 | + trunk_details = {'trunk_id': old_trunk.id} |
| 422 | + new_parent['trunk_details'] = trunk_details |
| 423 | + old_parent['trunk_details'] = trunk_details |
| 424 | + self.trunk_handler.port_updated( |
| 425 | + resources.PORT, |
| 426 | + events.AFTER_UPDATE, |
| 427 | + None, |
| 428 | + payload=events.DBEventPayload( |
| 429 | + self.context, states=(old_parent, new_parent))) |
| 430 | + new_trunk = self._get_trunk_obj(old_trunk.id) |
| 431 | + self.assertNotEqual( |
| 432 | + trunk_consts.TRUNK_ACTIVE_STATUS, new_trunk.status) |
| 433 | + |
| 434 | + |
366 | 435 | class TestTrunkDriver(base.BaseTestCase):
|
367 | 436 | def setUp(self):
|
368 | 437 | super(TestTrunkDriver, self).setUp()
|
|
0 commit comments