|
38 | 38 | from neutron.plugins.ml2.drivers.ovn.mech_driver import mech_driver
|
39 | 39 | from neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb import impl_idl_ovn
|
40 | 40 | from neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb import ovn_client
|
| 41 | +from neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb import ovsdb_monitor |
41 | 42 | from neutron.tests import base as tests_base
|
42 | 43 | from neutron.tests.functional import base
|
43 | 44 |
|
@@ -602,6 +603,74 @@ def _test_external_port_create(self, vnic_type):
|
602 | 603 | self.assertEqual(utils.ovn_name(net_id),
|
603 | 604 | str(ovn_port.ha_chassis_group[0].name))
|
604 | 605 |
|
| 606 | + def _create_router_port(self, vnic_type): |
| 607 | + net_id = self.n1['network']['id'] |
| 608 | + port_data = { |
| 609 | + 'port': {'network_id': net_id, |
| 610 | + 'tenant_id': self._tenant_id, |
| 611 | + portbindings.VNIC_TYPE: 'normal'}} |
| 612 | + |
| 613 | + # Create port |
| 614 | + port_req = self.new_create_request('ports', port_data, self.fmt) |
| 615 | + port_res = port_req.get_response(self.api) |
| 616 | + port = self.deserialize(self.fmt, port_res)['port'] |
| 617 | + |
| 618 | + # Update it as lsp port |
| 619 | + port_upt_data = { |
| 620 | + 'port': {'device_owner': "network:router_gateway"} |
| 621 | + } |
| 622 | + port_req = self.new_update_request( |
| 623 | + 'ports', port_upt_data, port['id'], self.fmt) |
| 624 | + port_res = port_req.get_response(self.api) |
| 625 | + |
| 626 | + def test_add_external_port_avoid_flapping(self): |
| 627 | + class LogicalSwitchPortUpdateUpEventTest(event.RowEvent): |
| 628 | + def __init__(self): |
| 629 | + self.count = 0 |
| 630 | + table = 'Logical_Switch_Port' |
| 631 | + events = (self.ROW_UPDATE,) |
| 632 | + super(LogicalSwitchPortUpdateUpEventTest, self).__init__( |
| 633 | + events, table, (('up', '=', True),), |
| 634 | + old_conditions=(('up', '=', False),)) |
| 635 | + |
| 636 | + def run(self, event, row, old): |
| 637 | + self.count += 1 |
| 638 | + |
| 639 | + def get_count(self): |
| 640 | + return self.count |
| 641 | + |
| 642 | + class LogicalSwitchPortUpdateDownEventTest(event.RowEvent): |
| 643 | + def __init__(self): |
| 644 | + self.count = 0 |
| 645 | + table = 'Logical_Switch_Port' |
| 646 | + events = (self.ROW_UPDATE,) |
| 647 | + super(LogicalSwitchPortUpdateDownEventTest, self).__init__( |
| 648 | + events, table, (('up', '=', False),), |
| 649 | + old_conditions=(('up', '=', True),)) |
| 650 | + |
| 651 | + def run(self, event, row, old): |
| 652 | + self.count += 1 |
| 653 | + |
| 654 | + def get_count(self): |
| 655 | + return self.count |
| 656 | + |
| 657 | + og_up_event = ovsdb_monitor.LogicalSwitchPortUpdateUpEvent(None) |
| 658 | + og_down_event = ovsdb_monitor.LogicalSwitchPortUpdateDownEvent(None) |
| 659 | + test_down_event = LogicalSwitchPortUpdateDownEventTest() |
| 660 | + test_up_event = LogicalSwitchPortUpdateUpEventTest() |
| 661 | + self.nb_api.idl.notify_handler.unwatch_events( |
| 662 | + [og_up_event, og_down_event]) |
| 663 | + self.nb_api.idl.notify_handler.watch_events( |
| 664 | + [test_down_event, test_up_event]) |
| 665 | + # Creating a port the same way as the osp cli cmd |
| 666 | + # openstack router add port ROUTER PORT |
| 667 | + # shouldn't trigger an status flapping (up -> down -> up) |
| 668 | + # it should be created with status false and then change the |
| 669 | + # status as up, triggering only a LogicalSwitchPortUpdateUpEvent. |
| 670 | + self._create_router_port(portbindings.VNIC_DIRECT) |
| 671 | + self.assertEqual(test_down_event.get_count(), 0) |
| 672 | + self.assertEqual(test_up_event.get_count(), 1) |
| 673 | + |
605 | 674 | def test_external_port_create_vnic_direct(self):
|
606 | 675 | self._test_external_port_create(portbindings.VNIC_DIRECT)
|
607 | 676 |
|
|
0 commit comments