Drop fixed_network dependency from CONF

The fixed_network module has very little dependency from config;
removing it so that it may be used by the preprov_creds module.

Change-Id: I24de72a0a997d2824b72338e31fec5329d601074
This commit is contained in:
Andrea Frittoli (andreaf) 2015-10-30 16:39:24 +09:00 committed by Andrea Frittoli
parent 9683827596
commit 940f8c6049
4 changed files with 22 additions and 16 deletions

View File

@ -15,11 +15,8 @@ from oslo_log import log as logging
from tempest_lib.common.utils import misc as misc_utils
from tempest import config
from tempest import exceptions
CONF = config.CONF
LOG = logging.getLogger(__name__)
@ -31,14 +28,14 @@ def get_network_from_name(name, compute_networks_client):
object to use for making the network lists api request
:return: The full dictionary for the network in question
:rtype: dict
:raises InvalidConfiguration: If the name provided is invalid, the networks
:raises InvalidTestResource: If the name provided is invalid, the networks
list returns a 404, there are no found networks, or the found network
is invalid
"""
caller = misc_utils.find_test_caller()
if not name:
raise exceptions.InvalidConfiguration()
raise exceptions.InvalidTestResource(type='network', name=name)
networks = compute_networks_client.list_networks()['networks']
networks = [n for n in networks if n['label'] == name]
@ -53,13 +50,13 @@ def get_network_from_name(name, compute_networks_client):
if caller:
msg = '(%s) %s' % (caller, msg)
LOG.warn(msg)
raise exceptions.InvalidConfiguration()
raise exceptions.InvalidTestResource(type='network', name=name)
else:
msg = "Network with name: %s not found" % name
if caller:
msg = '(%s) %s' % (caller, msg)
LOG.warn(msg)
raise exceptions.InvalidConfiguration()
raise exceptions.InvalidTestResource(type='network', name=name)
# To be consistent between neutron and nova network always use name even
# if label is used in the api response. If neither is present than then
# the returned network is invalid.
@ -69,12 +66,13 @@ def get_network_from_name(name, compute_networks_client):
if caller:
msg = '(%s) %s' % (caller, msg)
LOG.warn(msg)
raise exceptions.InvalidConfiguration()
raise exceptions.InvalidTestResource(type='network', name=name)
network['name'] = name
return network
def get_tenant_network(creds_provider, compute_networks_client):
def get_tenant_network(creds_provider, compute_networks_client,
shared_network_name):
"""Get a network usable by the primary tenant
:param creds_provider: instance of credential provider
@ -83,23 +81,24 @@ def get_tenant_network(creds_provider, compute_networks_client):
neutron and nova-network cases. If this is not an admin network
client, set_network_kwargs might fail in case fixed_network_name
is the network to be used, and it's not visible to the tenant
:param shared_network_name: name of the shared network to be used if no
tenant network is available in the creds provider
:return a dict with 'id' and 'name' of the network
"""
caller = misc_utils.find_test_caller()
fixed_network_name = CONF.compute.fixed_network_name
net_creds = creds_provider.get_primary_creds()
network = getattr(net_creds, 'network', None)
if not network or not network.get('name'):
if fixed_network_name:
if shared_network_name:
msg = ('No valid network provided or created, defaulting to '
'fixed_network_name')
if caller:
msg = '(%s) %s' % (caller, msg)
LOG.debug(msg)
try:
network = get_network_from_name(fixed_network_name,
network = get_network_from_name(shared_network_name,
compute_networks_client)
except exceptions.InvalidConfiguration:
except exceptions.InvalidTestResource:
network = {}
msg = ('Found network %s available for tenant' % network)
if caller:

View File

@ -339,7 +339,7 @@ class PreProvisionedCredentialProvider(cred_provider.CredentialProvider):
try:
network = fixed_network.get_network_from_name(
net_name, compute_network_client)
except exceptions.InvalidConfiguration:
except exceptions.InvalidTestResource:
network = {}
net_creds.set_resources(network=network)
return net_creds

View File

@ -139,6 +139,13 @@ class TearDownException(TempestException):
message = "%(num)d cleanUp operation failed"
# NOTE(andreaf) This exception is added here to facilitate the migration
# of get_network_from_name and preprov_creds to tempest-lib, and it should
# be migrated along with them
class InvalidTestResource(TempestException):
message = "%(name) is not a valid %(type), or the name is ambiguous"
class RFCViolation(RestClientException):
message = "RFC Violation"

View File

@ -612,8 +612,8 @@ class BaseTestCase(testtools.testcase.WithAttributes,
admin_creds = cred_provider.get_admin_creds()
admin_manager = clients.Manager(admin_creds)
networks_client = admin_manager.compute_networks_client
return fixed_network.get_tenant_network(cred_provider,
networks_client)
return fixed_network.get_tenant_network(
cred_provider, networks_client, CONF.compute.fixed_network_name)
def assertEmpty(self, list, msg=None):
self.assertTrue(len(list) == 0, msg)