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
diff --git a/tempest/common/fixed_network.py b/tempest/common/fixed_network.py
index b81830a..1928a22 100644
--- a/tempest/common/fixed_network.py
+++ b/tempest/common/fixed_network.py
@@ -15,11 +15,8 @@
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 @@
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 @@
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 @@
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 @@
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:
diff --git a/tempest/common/preprov_creds.py b/tempest/common/preprov_creds.py
index 5b81148..74cc3f0 100644
--- a/tempest/common/preprov_creds.py
+++ b/tempest/common/preprov_creds.py
@@ -339,7 +339,7 @@
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
diff --git a/tempest/exceptions.py b/tempest/exceptions.py
index c23e70c..031df7f 100644
--- a/tempest/exceptions.py
+++ b/tempest/exceptions.py
@@ -139,6 +139,13 @@
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"
diff --git a/tempest/test.py b/tempest/test.py
index 7b508ac..a9c8ba7 100644
--- a/tempest/test.py
+++ b/tempest/test.py
@@ -612,8 +612,8 @@
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)