Merge "Updated from global requirements"
diff --git a/etc/tempest.conf.sample b/etc/tempest.conf.sample
index ffd0b91..840983c 100644
--- a/etc/tempest.conf.sample
+++ b/etc/tempest.conf.sample
@@ -88,6 +88,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 a52f74c..e3f9f0a 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',
@@ -1144,6 +1145,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),
@@ -1173,7 +1183,8 @@
     (debug_group, DebugGroup),
     (baremetal_group, BaremetalGroup),
     (input_scenario_group, InputScenarioGroup),
-    (negative_group, NegativeGroup)
+    (negative_group, NegativeGroup),
+    (None, DefaultGroup)
 ]
 
 
@@ -1188,7 +1199,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
diff --git a/tempest/tests/common/test_accounts.py b/tempest/tests/common/test_accounts.py
index f2e8b20..2ca20f9 100644
--- a/tempest/tests/common/test_accounts.py
+++ b/tempest/tests/common/test_accounts.py
@@ -291,7 +291,6 @@
             {'username': 'test_user14', 'tenant_name': 'test_tenant14',
              'password': 'p', 'roles': ['role-7', 'role-11'],
              'resources': {'network': 'network-2'}}]
-        # Clear previous mock using self.test_accounts
         self.useFixture(mockpatch.Patch(
             'tempest.common.accounts.read_accounts_yaml',
             return_value=test_accounts))