]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Adds DVR functional test for multi-external networks
authorSwaminathan Vasudevan <swaminathan.vasudevan@hp.com>
Wed, 11 Mar 2015 19:03:42 +0000 (12:03 -0700)
committerSwaminathan Vasudevan <swaminathan.vasudevan@hp.com>
Fri, 10 Apr 2015 16:28:49 +0000 (09:28 -0700)
This patch adds DVR functional test for multiple
external networks related to FIP namespace.
This test validates that FIP namespaces are created
based on the external networks associated with the
router.

Change-Id: I0f8cd352e83f8c2f04bf420a8b0dd6407de6b5ce

neutron/tests/functional/agent/test_l3_agent.py
neutron/tests/unit/agent/l3/test_agent.py

index f19bca1ce2808d5662f5c92fa04d50b527388ab4..8120b0066f5ffa612179a7132902a40cd18e7b33 100755 (executable)
@@ -880,6 +880,48 @@ class TestDvrRouter(L3AgentTestFramework):
     def test_dvr_router_lifecycle_without_ha_with_snat_with_fips(self):
         self._dvr_router_lifecycle(enable_ha=False, enable_snat=True)
 
+    def _helper_create_dvr_router_fips_for_ext_network(
+            self, agent_mode, **dvr_router_kwargs):
+        self.agent.conf.agent_mode = agent_mode
+        router_info = self.generate_dvr_router_info(**dvr_router_kwargs)
+        mocked_ext_net_id = (
+            neutron_l3_agent.L3PluginApi.return_value.get_external_network_id)
+        mocked_ext_net_id.return_value = (
+            router_info['_floatingips'][0]['floating_network_id'])
+        router = self.manage_router(self.agent, router_info)
+        fip_ns = router.fip_ns.get_name()
+        return router, fip_ns
+
+    def _validate_fips_for_external_network(self, router, fip_ns):
+        self.assertTrue(self._namespace_exists(router.ns_name))
+        self.assertTrue(self._namespace_exists(fip_ns))
+        self._assert_dvr_floating_ips(router)
+        self._assert_snat_namespace_does_not_exist(router)
+
+    def test_dvr_router_fips_for_multiple_ext_networks(self):
+        agent_mode = 'dvr'
+        # Create the first router fip with external net1
+        dvr_router1_kwargs = {'ip_address': '19.4.4.3',
+                              'subnet_cidr': '19.4.4.0/24',
+                              'gateway_ip': '19.4.4.1',
+                              'gateway_mac': 'ca:fe:de:ab:cd:ef'}
+        router1, fip1_ns = (
+            self._helper_create_dvr_router_fips_for_ext_network(
+                agent_mode, **dvr_router1_kwargs))
+        # Validate the fip with external net1
+        self._validate_fips_for_external_network(router1, fip1_ns)
+
+        # Create the second router fip with external net2
+        dvr_router2_kwargs = {'ip_address': '19.4.5.3',
+                              'subnet_cidr': '19.4.5.0/24',
+                              'gateway_ip': '19.4.5.1',
+                              'gateway_mac': 'ca:fe:de:ab:cd:fe'}
+        router2, fip2_ns = (
+            self._helper_create_dvr_router_fips_for_ext_network(
+                agent_mode, **dvr_router2_kwargs))
+        # Validate the fip with external net2
+        self._validate_fips_for_external_network(router2, fip2_ns)
+
     def _dvr_router_lifecycle(self, enable_ha=False, enable_snat=False,
                               custom_mtu=2000):
         '''Test dvr router lifecycle
@@ -936,11 +978,13 @@ class TestDvrRouter(L3AgentTestFramework):
         self._assert_interfaces_deleted_from_ovs()
         self._assert_router_does_not_exist(router)
 
-    def generate_dvr_router_info(self, enable_ha=False, enable_snat=False):
+    def generate_dvr_router_info(
+        self, enable_ha=False, enable_snat=False, **kwargs):
         router = test_l3_agent.prepare_router_data(
             enable_snat=enable_snat,
             enable_floating_ip=True,
-            enable_ha=enable_ha)
+            enable_ha=enable_ha,
+            **kwargs)
         internal_ports = router.get(l3_constants.INTERFACE_KEY, [])
         router['distributed'] = True
         router['gw_port_host'] = self.agent.conf.host
index 4c6682bd8aacec7c92f8f7b1dfe038862017f4e5..0f0eb7f5f2d222aba10e2944468789211df6d0e4 100644 (file)
@@ -180,21 +180,23 @@ def router_append_subnet(router, count=1, ip_version=4,
 def prepare_router_data(ip_version=4, enable_snat=None, num_internal_ports=1,
                         enable_floating_ip=False, enable_ha=False,
                         extra_routes=False, dual_stack=False,
-                        v6_ext_gw_with_sub=True):
+                        v6_ext_gw_with_sub=True, **kwargs):
     fixed_ips = []
     subnets = []
     for loop_version in (4, 6):
         if loop_version == 4 and (ip_version == 4 or dual_stack):
-            ip_address = '19.4.4.4'
+            ip_address = kwargs.get('ip_address', '19.4.4.4')
             prefixlen = 24
-            subnet_cidr = '19.4.4.0/24'
-            gateway_ip = '19.4.4.1'
+            subnet_cidr = kwargs.get('subnet_cidr', '19.4.4.0/24')
+            gateway_ip = kwargs.get('gateway_ip', '19.4.4.1')
+            gateway_mac = kwargs.get('gateway_mac', 'ca:fe:de:ad:be:ee')
         elif (loop_version == 6 and (ip_version == 6 or dual_stack) and
               v6_ext_gw_with_sub):
-            ip_address = 'fd00::4'
+            ip_address = kwargs.get('ip_address', 'fd00::4')
             prefixlen = 64
-            subnet_cidr = 'fd00::/64'
-            gateway_ip = 'fd00::1'
+            subnet_cidr = kwargs.get('subnet_cidr', 'fd00::/64')
+            gateway_ip = kwargs.get('gateway_ip', 'fd00::1')
+            gateway_mac = kwargs.get('gateway_mac', 'ca:fe:de:ad:be:ee')
         else:
             continue
         subnet_id = _uuid()
@@ -209,7 +211,7 @@ def prepare_router_data(ip_version=4, enable_snat=None, num_internal_ports=1,
 
     router_id = _uuid()
     ex_gw_port = {'id': _uuid(),
-                  'mac_address': 'ca:fe:de:ad:be:ee',
+                  'mac_address': gateway_mac,
                   'network_id': _uuid(),
                   'fixed_ips': fixed_ips,
                   'subnets': subnets}