Improve logging in fixed_networks
This commit makes some logging improvements to the common methods in
fixed_networks.py. Previously it was very difficult to trace through
any issues around network selection since it only would log the final
result and on failures. It also didn't attribute any messages to the
tests making the call. This fixes both issues by first leveraging
find_test_caller() from tempest-lib to get the test caller name and
secondly add more logging to help trace through the logic if something
fails. Additionally as part of this it was necessary to add additional
checks to the logic to ensure the logging was accurate and things were
in a known state.
Change-Id: Ifef67ed4578f48d7701635e7d81c144dc28b6120
diff --git a/tempest/common/fixed_network.py b/tempest/common/fixed_network.py
index 67fbab1..b2d7c0b 100644
--- a/tempest/common/fixed_network.py
+++ b/tempest/common/fixed_network.py
@@ -13,6 +13,7 @@
import copy
from oslo_log import log as logging
+from tempest_lib.common.utils import misc as misc_utils
from tempest_lib import exceptions as lib_exc
from tempest.common import isolated_creds
@@ -35,6 +36,7 @@
is the network to be used, and it's not visible to the tenant
:return a dict with 'id' and 'name' of the network
"""
+ caller = misc_utils.find_test_caller()
fixed_network_name = CONF.compute.fixed_network_name
network = None
# NOTE(andreaf) get_primary_network will always be available once
@@ -46,6 +48,12 @@
network = creds_provider.get_primary_creds().network
else:
if fixed_network_name:
+ msg = ('No valid network provided or created, defaulting to '
+ 'fixed_network_name')
+ if caller:
+ LOG.debug('(%s) %s' % (caller, msg))
+ else:
+ LOG.debug(msg)
try:
resp = compute_networks_client.list_networks(
name=fixed_network_name)
@@ -59,19 +67,33 @@
network = networks[0]
else:
msg = "Configured fixed_network_name not found"
+ if caller:
+ msg = '(%s) %s' % (caller, msg)
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'))
+ name = network.get('name', network.get('label'))
+ if name:
+ network['name'] = name
+ else:
+ raise lib_exc.NotFound()
except lib_exc.NotFound:
# In case of nova network, if the fixed_network_name is not
# owned by the tenant, and the network client is not an admin
# one, list_networks will not find it
- LOG.info('Unable to find network %s. '
- 'Starting instance without specifying a network.' %
- fixed_network_name)
+ msg = ('Unable to find network %s. '
+ 'Starting instance without specifying a network.' %
+ fixed_network_name)
+ if caller:
+ LOG.info('(%s) %s' % (caller, msg))
+ else:
+ LOG.info(msg)
network = {'name': fixed_network_name}
- LOG.info('Found network %s available for tenant' % network)
+ msg = ('Found network %s available for tenant' % network)
+ if caller:
+ LOG.info('(%s) %s' % (caller, msg))
+ else:
+ LOG.info(msg)
return network
@@ -87,5 +109,9 @@
return params
if network:
- params.update({"networks": [{'uuid': network['id']}]})
+ if 'id' in network.keys():
+ params.update({"networks": [{'uuid': network['id']}]})
+ else:
+ LOG.warn('The provided network dict: %s was invalid and did not '
+ ' contain an id' % network)
return params