Browse Source

test_router: Verify the creation and removal of a lrp

Add test to ensure that logical router port associated
with an external network is created and removed as
needed: test_logical_router_port_creation. With that,
the test exercises the code-path where a gateway is
removed before a new one is set. In terms of OpenStack
workflow, that would look like:

  openstack router set --external-gateway $EXT_NET_ID $RTR
  openstack router unset --external-gateway $RTR
  openstack router set --external-gateway $EXT_NET_ID2 $RTR

Also changed test_gateway_chassis_with_bridge_mappings
to include docstring and have a lower bound count to the
mocked objects it uses.

Change-Id: Ib3edc101e9ee0fb53386fac0ae7f272ab3b3646b
Signed-off-by: Flavio Fernandes <>
Related-Bug: #1843485
Closes-Bug: #1844652
(cherry picked from commit 5cffa92daa)
Flavio Fernandes 2 years ago
committed by Terry Wilson
  1. 45


@ -291,7 +291,41 @@ class TestRouter(base.TestOVNFunctionalBase):
expected_networks, gw_port.networks,
'networks in ovn port must match fixed_ips in neutron')
def test_logical_router_port_creation(self):
"""Launchpad bug #1844652: Verify creation and removal of lrp
This test verifies that logical router port is created and removed
based on attaching and detaching the external network to a router.
router = self._create_router('router1', gw_info=None)
router_id = router['id']
"router logical port unexpected before ext net")
# Create external network and assign it to router
ext1 = self._create_ext_network(
'ext1', 'flat', 'physnet3', None, gateway=None, cidr=None)
gw_info = {'network_id': ext1['network']['id']}
self.context, router_id,
{'router': {l3_apidef.EXTERNAL_GW_INFO: gw_info}})
"router logical port missing after ext net add")
# Un-assign external network from router
self.context, router_id,
{'router': {l3_apidef.EXTERNAL_GW_INFO: None}})
"router logical port exists after ext net removal")
def test_gateway_chassis_with_bridge_mappings(self):
"""Check selected ovn chassis based on external network
This test sets different gateway values to ensure that the proper
chassis are candidates, based on the physical network mappings.
ovn_client = self.l3_plugin._ovn_client
# Create external networks with vlan, flat and geneve network types
ext1 = self._create_ext_network(
@ -341,9 +375,14 @@ class TestRouter(base.TestOVNFunctionalBase):
# We can't test call_count for these mocks, as we have disabled
# maintenance_worker which will trigger chassis events
# and eventually calling schedule_unhosted_gateways
# and eventually calling schedule_unhosted_gateways.
# However, we know for sure that these mocks must have been
# called at least 3 times because that is the number of times
# this test invokes them: 1x create_router + 2x update_router
# for client_select mock; and 3x schedule_unhosted_gateways for
# plugin_select mock.
self.assertGreaterEqual(client_select.call_count, 3)
self.assertGreaterEqual(plugin_select.call_count, 3)
def test_router_gateway_port_binding_host_id(self):
# Test setting chassis on chassisredirect port in Port_Binding table,