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 <flaviof@redhat.com>
Related-Bug: #1843485
Closes-Bug: #1844652
(cherry picked from commit 5cffa92daa)
(cherry picked from commit b9ab95036b)
(cherry picked from commit f3577c72f1)
changes/65/728565/1
Flavio Fernandes 2 years ago
committed by Terry Wilson
parent
commit
5d9dacf522
  1. 50
      networking_ovn/tests/functional/test_router.py

50
networking_ovn/tests/functional/test_router.py

@ -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']
self.assertIsNone(self._get_gw_port(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.l3_plugin.update_router(
self.context, router_id,
{'router': {l3_apidef.EXTERNAL_GW_INFO: gw_info}})
self.assertIsNotNone(self._get_gw_port(router_id),
"router logical port missing after ext net add")
# Un-assign external network from router
self.l3_plugin.update_router(
self.context, router_id,
{'router': {l3_apidef.EXTERNAL_GW_INFO: None}})
self.assertIsNone(self._get_gw_port(router_id),
"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(
@ -339,12 +373,16 @@ class TestRouter(base.TestOVNFunctionalBase):
self._set_redirect_chassis_to_invalid_chassis(ovn_client)
self.l3_plugin.schedule_unhosted_gateways()
# Check ovn_client._ovn_scheduler.select called for router
# create and updates
self.assertEqual(3, client_select.call_count)
# Check self.l3_plugin.scheduler.select called for
# schedule_unhosted_gateways
self.assertEqual(3, plugin_select.call_count)
# We can't test call_count for these mocks, as we have enabled
# ovn_worker which will trigger chassis events 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):
host_id = 'fake_host'

Loading…
Cancel
Save