Add resource prefix string
When running tempest several resources are created and afterwards
deleted. On systems where the cloud under tests is not destroyed
after the tests, it is useful to be able to associated resources
to specific test jobs and test runs.
The 'rand_name' function in tempest-lib exposes a prefix option,
which tempest does not use at the moment.
Adding a new configuration option to make the prefix configurable.
Creating a local version of the rand_name util, which passes the
prefix from configuration. Eventually all calls of rand_name
shall be redirected from tempest_lib to the local version.
In this patch, only the credentials provider is change to
validate that the mechanism is working. Follow-up patches will
migrate the rest of the code base.
Co-Authored-By: Fei Long Wang (flwang@catalyst.net.nz)
Change-Id: If15993f1ca0fd932e13d73c8ef9875ce13d79c53
diff --git a/etc/tempest.conf.sample b/etc/tempest.conf.sample
index 6424f55..e3eace3 100644
--- a/etc/tempest.conf.sample
+++ b/etc/tempest.conf.sample
@@ -91,6 +91,15 @@
# Enables or disables fatal status of deprecations. (boolean value)
#fatal_deprecations = false
+#
+# From tempest.config
+#
+
+# Prefix to be added when generating the name for test resources. It
+# can be used to discover all resources associated with a specific
+# test run when running tempest on a real-life cloud (string value)
+#resources_prefix = tempest
+
[auth]
diff --git a/tempest/common/isolated_creds.py b/tempest/common/isolated_creds.py
index 5ded3ee..f3dd2e6 100644
--- a/tempest/common/isolated_creds.py
+++ b/tempest/common/isolated_creds.py
@@ -16,11 +16,11 @@
import netaddr
from oslo_log import log as logging
import six
-from tempest_lib.common.utils import data_utils
from tempest_lib import exceptions as lib_exc
from tempest import clients
from tempest.common import cred_provider
+from tempest.common.utils import data_utils
from tempest import config
from tempest import exceptions
from tempest.services.identity.v2.json import identity_client as v2_identity
diff --git a/tempest/common/utils/__init__.py b/tempest/common/utils/__init__.py
index 04d898d..81b8110 100644
--- a/tempest/common/utils/__init__.py
+++ b/tempest/common/utils/__init__.py
@@ -1,3 +1,45 @@
+# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from functools import partial
+
+from tempest import config
+
+from tempest_lib.common.utils import data_utils as lib_data_utils
+
+CONF = config.CONF
+
PING_IPV4_COMMAND = 'ping -c 3 '
PING_IPV6_COMMAND = 'ping6 -c 3 '
PING_PACKET_LOSS_REGEX = '(\d{1,3})\.?\d*\% packet loss'
+
+
+class DataUtils(object):
+ def __getattr__(self, attr):
+ if attr in self.__dict__:
+ return self.__dict__[attr]
+
+ if attr == 'rand_name':
+ # NOTE(flwang): This is a proxy to generate a random name that
+ # includes a random number and a prefix if one is configured in
+ # CONF.resources_prefix
+ attr_obj = partial(lib_data_utils.rand_name,
+ prefix=CONF.resources_prefix)
+ else:
+ attr_obj = getattr(lib_data_utils, attr)
+
+ self.__dict__[attr] = attr_obj
+ return attr_obj
+
+data_utils = DataUtils()
diff --git a/tempest/common/validation_resources.py b/tempest/common/validation_resources.py
index d370ebc..18f0b1d 100644
--- a/tempest/common/validation_resources.py
+++ b/tempest/common/validation_resources.py
@@ -14,9 +14,10 @@
from oslo_log import log as logging
from tempest import config
-from tempest_lib.common.utils import data_utils
from tempest_lib import exceptions as lib_exc
+from tempest.common.utils import data_utils
+
CONF = config.CONF
LOG = logging.getLogger(__name__)
diff --git a/tempest/config.py b/tempest/config.py
index 0fa5bf5..75bec4c 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -31,9 +31,10 @@
def register_opt_group(conf, opt_group, options):
- conf.register_group(opt_group)
+ if opt_group:
+ conf.register_group(opt_group)
for opt in options:
- conf.register_opt(opt, group=opt_group.name)
+ conf.register_opt(opt, group=getattr(opt_group, 'name', None))
auth_group = cfg.OptGroup(name='auth',
@@ -1133,6 +1134,15 @@
help="Test generator class for all negative tests"),
]
+DefaultGroup = [
+ cfg.StrOpt('resources_prefix',
+ default='tempest',
+ help="Prefix to be added when generating the name for "
+ "test resources. It can be used to discover all "
+ "resources associated with a specific test run when "
+ "running tempest on a real-life cloud"),
+]
+
_opts = [
(auth_group, AuthGroup),
(compute_group, ComputeGroup),
@@ -1162,7 +1172,8 @@
(debug_group, DebugGroup),
(baremetal_group, BaremetalGroup),
(input_scenario_group, InputScenarioGroup),
- (negative_group, NegativeGroup)
+ (negative_group, NegativeGroup),
+ (None, DefaultGroup)
]
@@ -1177,7 +1188,7 @@
The purpose of this is to allow tools like the Oslo sample config file
generator to discover the options exposed to users.
"""
- return [(g.name, o) for g, o in _opts]
+ return [(getattr(g, 'name', None), o) for g, o in _opts]
# this should never be called outside of this class