Skip to content

Commit

Permalink
Merge "Adds DVR functional test for multi-external networks"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Apr 15, 2015
2 parents 76a5074 + 61aa4a5 commit 949f6e2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
48 changes: 46 additions & 2 deletions neutron/tests/functional/agent/test_l3_agent.py
Expand Up @@ -880,6 +880,48 @@ def test_dvr_router_lifecycle_without_ha_without_snat_with_fips(self):
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
Expand Down Expand Up @@ -936,11 +978,13 @@ def _dvr_router_lifecycle(self, enable_ha=False, enable_snat=False,
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
Expand Down
18 changes: 10 additions & 8 deletions neutron/tests/unit/agent/l3/test_agent.py
Expand Up @@ -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()
Expand All @@ -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}
Expand Down

0 comments on commit 949f6e2

Please sign in to comment.