Handle fixed_network edge cases gracefully

When we added support for using the fixed_network_name config option to
specify the network to boot with in a multi-network env a couple of
configuration edge cases were not taken into account. First the case
of misconfiguration was not handled at all this would cause an ugly
IndexError exception to be raised because no matches were found for
the name specified in config. The other was since the default config
option was set to 'private' and fixed network name is always used when
configured the default for single network environments broke if the
single network. This commit addresses these by removing the default
value for fixed_network_name (and making the help more clear) and
having fixed_network_name handle the misconfiguration case more
clearly by raising an InvalidConfiguration exception.

Change-Id: I06ac0605a1a7e35d1af9a93a3bfc387a78f8be1c
Closes-Bug: #1437328
This commit is contained in:
Matthew Treinish 2015-03-27 10:25:45 -04:00
parent 6a341ef616
commit 03feae04e6
5 changed files with 41 additions and 15 deletions

View File

@ -302,9 +302,11 @@
# value)
#ssh_channel_timeout = 60
# Name of the fixed network that is visible to all test tenants.
# (string value)
#fixed_network_name = private
# Name of the fixed network that is visible to all test tenants. If
# multiple networks are available for a tenant this is the network
# which will be used for creating servers if tempest does not create a
# network or a network is not specified elsewhere (string value)
#fixed_network_name = <None>
# Network used for SSH connections. Ignored if
# use_floatingip_for_ssh=true or run_ssh=false. (string value)

View File

@ -37,12 +37,15 @@ class NetworksTest(base.BaseComputeAdminTest):
@test.idempotent_id('d206d211-8912-486f-86e2-a9d090d1f416')
def test_get_network(self):
networks = self.client.list_networks()
configured_network = [x for x in networks if x['label'] ==
CONF.compute.fixed_network_name]
self.assertEqual(1, len(configured_network),
"{0} networks with label {1}".format(
len(configured_network),
CONF.compute.fixed_network_name))
if CONF.compute.fixed_network_name:
configured_network = [x for x in networks if x['label'] ==
CONF.compute.fixed_network_name]
self.assertEqual(1, len(configured_network),
"{0} networks with label {1}".format(
len(configured_network),
CONF.compute.fixed_network_name))
else:
configured_network = networks
configured_network = configured_network[0]
network = self.client.get_network(configured_network['id'])
self.assertEqual(configured_network['label'], network['label'])
@ -51,5 +54,9 @@ class NetworksTest(base.BaseComputeAdminTest):
def test_list_all_networks(self):
networks = self.client.list_networks()
# Check the configured network is in the list
configured_network = CONF.compute.fixed_network_name
self.assertIn(configured_network, [x['label'] for x in networks])
if CONF.compute.fixed_network_name:
configured_network = CONF.compute.fixed_network_name
self.assertIn(configured_network, [x['label'] for x in networks])
else:
network_name = map(lambda x: x['label'], networks)
self.assertGreaterEqual(len(network_name), 1)

View File

@ -68,7 +68,10 @@ class ListServerFiltersTestJSON(base.BaseV2ComputeTest):
cls.image_ref_alt)
network = cls.get_tenant_network()
cls.fixed_network_name = network['name']
if network:
cls.fixed_network_name = network['name']
else:
cls.fixed_network_name = None
network_kwargs = fixed_network.set_networks_kwarg(network)
cls.s1_name = data_utils.rand_name(cls.__name__ + '-instance')
cls.s1 = cls.create_test_server(name=cls.s1_name,
@ -283,6 +286,9 @@ class ListServerFiltersTestJSON(base.BaseV2ComputeTest):
def test_list_servers_filtered_by_ip(self):
# Filter servers by ip
# Here should be listed 1 server
if not self.fixed_network_name:
msg = 'fixed_network_name needs to be configured to run this test'
raise self.skipException(msg)
self.s1 = self.client.get_server(self.s1['id'])
ip = self.s1['addresses'][self.fixed_network_name][0]['addr']
params = {'ip': ip}
@ -301,6 +307,9 @@ class ListServerFiltersTestJSON(base.BaseV2ComputeTest):
# Filter servers by regex ip
# List all servers filtered by part of ip address.
# Here should be listed all servers
if not self.fixed_network_name:
msg = 'fixed_network_name needs to be configured to run this test'
raise self.skipException(msg)
self.s1 = self.client.get_server(self.s1['id'])
ip = self.s1['addresses'][self.fixed_network_name][0]['addr'][0:-3]
params = {'ip': ip}

View File

@ -16,6 +16,7 @@ from oslo_log import log as logging
from tempest_lib import exceptions as lib_exc
from tempest import config
from tempest import exceptions
CONF = config.CONF
@ -34,6 +35,7 @@ def get_tenant_network(creds_provider, compute_networks_client):
:return a dict with 'id' and 'name' of the network
"""
fixed_network_name = CONF.compute.fixed_network_name
network = None
# NOTE(andreaf) get_primary_network will always be available once
# bp test-accounts-continued is implemented
if (CONF.auth.allow_tenant_isolation and
@ -51,7 +53,11 @@ def get_tenant_network(creds_provider, compute_networks_client):
networks = resp['networks']
else:
raise lib_exc.NotFound()
network = networks[0]
if len(networks) > 0:
network = networks[0]
else:
msg = "Configured fixed_network_name not found"
raise exceptions.InvalidConfiguration(msg)
# To be consistent with network isolation, add name is only
# label is available
network['name'] = network.get('name', network.get('label'))

View File

@ -232,9 +232,11 @@ ComputeGroup = [
help="Timeout in seconds to wait for output from ssh "
"channel."),
cfg.StrOpt('fixed_network_name',
default='private',
help="Name of the fixed network that is visible to all test "
"tenants."),
"tenants. If multiple networks are available for a tenant"
" this is the network which will be used for creating "
"servers if tempest does not create a network or a "
"network is not specified elsewhere"),
cfg.StrOpt('network_for_ssh',
default='public',
help="Network used for SSH connections. Ignored if "