Add subnet_id option

When tested network contained more than one subnet then test failed
due to assert call.

Subnet_id option specifies which subnet should be used for testing
when more than one subnet in network is present. If subnet_id is
specified then each created VM is assigned a floating IP within
the range of the subnet.

Closes-Bug: 1856671
Change-Id: Ie4d44b16595055201e12f10982fc78683a12d41a
This commit is contained in:
Lukas Piwowarski 2020-01-31 12:28:20 +00:00
parent 4bc12aad2e
commit 2385e0417b
4 changed files with 36 additions and 9 deletions

View File

@ -0,0 +1,8 @@
---
features:
- A new config option 'subnet_id' is added to section
'network' to specify subnet which should be used for
allocation of IPs for VMs created during testing.
It should be used when the tested network contains more
than one subnet otherwise test of external connectivity
will fail. (Fixes bug #1856671)

View File

@ -699,6 +699,11 @@ NetworkGroup = [
cfg.StrOpt('floating_network_name',
help="Default floating network name. Used to allocate floating "
"IPs when neutron is enabled."),
cfg.StrOpt('subnet_id',
default="",
help="Subnet id of subnet which is used for allocation of "
"floating IPs. Specify when two or more subnets are "
"present in network."),
cfg.StrOpt('public_router_id',
default="",
help="Id of the public router that provides external "

View File

@ -1008,13 +1008,18 @@ class NetworkScenarioTest(ScenarioTest):
port_id, ip4 = self._get_server_port_id_and_ip4(thing)
else:
ip4 = None
result = client.create_floatingip(
floating_network_id=external_network_id,
port_id=port_id,
tenant_id=thing['tenant_id'],
fixed_ip_address=ip4
)
kwargs = {
'floating_network_id': external_network_id,
'port_id': port_id,
'tenant_id': thing['tenant_id'],
'fixed_ip_address': ip4,
}
if CONF.network.subnet_id:
kwargs['subnet_id'] = CONF.network.subnet_id
result = client.create_floatingip(**kwargs)
floating_ip = result['floatingip']
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
client.delete_floatingip,
floating_ip['id'])

View File

@ -346,10 +346,19 @@ class TestNetworkBasicOps(manager.NetworkScenarioTest):
network_id=CONF.network.public_network_id)['subnets']
if s['ip_version'] == 4
]
self.assertEqual(1, len(v4_subnets),
"Found %d IPv4 subnets" % len(v4_subnets))
external_ips = [v4_subnets[0]['gateway_ip']]
if len(v4_subnets) > 1:
self.assertTrue(
CONF.network.subnet_id,
"Found %d subnets. Specify subnet using configuration "
"option [network].subnet_id."
% len(v4_subnets))
subnet = self.os_admin.subnets_client.show_subnet(
CONF.network.subnet_id)['subnet']
external_ips = [subnet['gateway_ip']]
else:
external_ips = [v4_subnets[0]['gateway_ip']]
self._check_server_connectivity(self.floating_ip_tuple.floating_ip,
external_ips)