Use random password generator for IsolatedCreds
Currently, for IsolatedCreds provider, new tenant/user will be created for
testing. However, the user password is hardcoded(with 'pass' as the
default) in the implementation. This patch change that to use random
password generator for user creation.
Change-Id: I36d64e6313a5b4edc03acad64bcdaeab680f9ce0
Implements: blueprint random-password-for-user-creation
diff --git a/requirements.txt b/requirements.txt
index 60dee97..fefd019 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -21,5 +21,5 @@
iso8601>=0.1.9
fixtures>=0.3.14
testscenarios>=0.4
-tempest-lib>=0.5.0
+tempest-lib>=0.6.1
PyYAML>=3.1.0
diff --git a/tempest/common/cred_provider.py b/tempest/common/cred_provider.py
index 461097f..fa80d65 100644
--- a/tempest/common/cred_provider.py
+++ b/tempest/common/cred_provider.py
@@ -98,7 +98,7 @@
@six.add_metaclass(abc.ABCMeta)
class CredentialProvider(object):
- def __init__(self, identity_version=None, name=None, password='pass',
+ def __init__(self, identity_version=None, name=None,
network_resources=None):
"""A CredentialProvider supplies credentials to test classes.
:param identity_version If specified it will return credentials of the
@@ -106,12 +106,8 @@
uses auth_version from configuration
:param name Name of the calling test. Included in provisioned
credentials when credentials are provisioned on the fly
- :param password Used for provisioned credentials when credentials are
- provisioned on the fly
:param network_resources Network resources required for the credentials
"""
- # TODO(andreaf) name and password are tenant isolation specific, and
- # could be removed from this abstract class
self.name = name or "test_creds"
self.identity_version = identity_version or CONF.identity.auth_version
if not auth.is_identity_version_supported(self.identity_version):
diff --git a/tempest/common/isolated_creds.py b/tempest/common/isolated_creds.py
index 5ded3ee..c7b3863 100644
--- a/tempest/common/isolated_creds.py
+++ b/tempest/common/isolated_creds.py
@@ -136,14 +136,13 @@
class IsolatedCreds(cred_provider.CredentialProvider):
- def __init__(self, identity_version=None, name=None, password='pass',
+ def __init__(self, identity_version=None, name=None,
network_resources=None):
- super(IsolatedCreds, self).__init__(identity_version, name, password,
+ super(IsolatedCreds, self).__init__(identity_version, name,
network_resources)
self.network_resources = network_resources
self.isolated_creds = {}
self.ports = []
- self.password = password
self.default_admin_creds = cred_provider.get_configured_credentials(
'identity_admin', fill_in=True,
identity_version=self.identity_version)
@@ -193,9 +192,10 @@
name=project_name, description=project_desc)
username = data_utils.rand_name(root) + suffix
+ user_password = data_utils.rand_password()
email = data_utils.rand_name(root) + suffix + "@example.com"
user = self.creds_client.create_user(
- username, self.password, project, email)
+ username, user_password, project, email)
if admin:
self.creds_client.assign_user_role(user, project,
CONF.identity.admin_role)
@@ -206,7 +206,7 @@
if roles:
for role in roles:
self.creds_client.assign_user_role(user, project, role)
- creds = self.creds_client.get_credentials(user, project, self.password)
+ creds = self.creds_client.get_credentials(user, project, user_password)
return cred_provider.TestResources(creds)
def _create_network_resources(self, tenant_id):
diff --git a/tempest/tests/test_tenant_isolation.py b/tempest/tests/test_tenant_isolation.py
index 95008a2..7fcf8d1 100644
--- a/tempest/tests/test_tenant_isolation.py
+++ b/tempest/tests/test_tenant_isolation.py
@@ -139,8 +139,7 @@
@mock.patch('tempest_lib.common.rest_client.RestClient')
def test_primary_creds(self, MockRestClient):
cfg.CONF.set_default('neutron', False, 'service_available')
- iso_creds = isolated_creds.IsolatedCreds(name='test class',
- password='fake_password')
+ iso_creds = isolated_creds.IsolatedCreds(name='test class')
self._mock_assign_user_role()
self._mock_list_role()
self._mock_tenant_create('1234', 'fake_prim_tenant')
@@ -155,8 +154,7 @@
@mock.patch('tempest_lib.common.rest_client.RestClient')
def test_admin_creds(self, MockRestClient):
cfg.CONF.set_default('neutron', False, 'service_available')
- iso_creds = isolated_creds.IsolatedCreds(name='test class',
- password='fake_password')
+ iso_creds = isolated_creds.IsolatedCreds(name='test class')
self._mock_list_roles('1234', 'admin')
self._mock_user_create('1234', 'fake_admin_user')
self._mock_tenant_create('1234', 'fake_admin_tenant')
@@ -179,8 +177,7 @@
@mock.patch('tempest_lib.common.rest_client.RestClient')
def test_role_creds(self, MockRestClient):
cfg.CONF.set_default('neutron', False, 'service_available')
- iso_creds = isolated_creds.IsolatedCreds('v2', 'test class',
- password='fake_password')
+ iso_creds = isolated_creds.IsolatedCreds('v2', 'test class')
self._mock_list_2_roles()
self._mock_user_create('1234', 'fake_role_user')
self._mock_tenant_create('1234', 'fake_role_tenant')
@@ -208,8 +205,7 @@
@mock.patch('tempest_lib.common.rest_client.RestClient')
def test_all_cred_cleanup(self, MockRestClient):
cfg.CONF.set_default('neutron', False, 'service_available')
- iso_creds = isolated_creds.IsolatedCreds(name='test class',
- password='fake_password')
+ iso_creds = isolated_creds.IsolatedCreds(name='test class')
self._mock_assign_user_role()
self._mock_list_role()
self._mock_tenant_create('1234', 'fake_prim_tenant')
@@ -249,8 +245,7 @@
@mock.patch('tempest_lib.common.rest_client.RestClient')
def test_alt_creds(self, MockRestClient):
cfg.CONF.set_default('neutron', False, 'service_available')
- iso_creds = isolated_creds.IsolatedCreds(name='test class',
- password='fake_password')
+ iso_creds = isolated_creds.IsolatedCreds(name='test class')
self._mock_assign_user_role()
self._mock_list_role()
self._mock_user_create('1234', 'fake_alt_user')
@@ -265,8 +260,7 @@
@mock.patch('tempest_lib.common.rest_client.RestClient')
def test_no_network_creation_with_config_set(self, MockRestClient):
cfg.CONF.set_default('create_isolated_networks', False, group='auth')
- iso_creds = isolated_creds.IsolatedCreds(name='test class',
- password='fake_password')
+ iso_creds = isolated_creds.IsolatedCreds(name='test class')
self._mock_assign_user_role()
self._mock_list_role()
self._mock_user_create('1234', 'fake_prim_user')
@@ -294,8 +288,7 @@
@mock.patch('tempest_lib.common.rest_client.RestClient')
def test_network_creation(self, MockRestClient):
- iso_creds = isolated_creds.IsolatedCreds(name='test class',
- password='fake_password')
+ iso_creds = isolated_creds.IsolatedCreds(name='test class')
self._mock_assign_user_role()
self._mock_list_role()
self._mock_user_create('1234', 'fake_prim_user')
@@ -326,8 +319,7 @@
"description": args['name'],
"security_group_rules": [],
"id": "sg-%s" % args['tenant_id']}]}
- iso_creds = isolated_creds.IsolatedCreds(name='test class',
- password='fake_password')
+ iso_creds = isolated_creds.IsolatedCreds(name='test class')
# Create primary tenant and network
self._mock_assign_user_role()
self._mock_list_role()
@@ -437,8 +429,7 @@
@mock.patch('tempest_lib.common.rest_client.RestClient')
def test_network_alt_creation(self, MockRestClient):
- iso_creds = isolated_creds.IsolatedCreds(name='test class',
- password='fake_password')
+ iso_creds = isolated_creds.IsolatedCreds(name='test class')
self._mock_assign_user_role()
self._mock_list_role()
self._mock_user_create('1234', 'fake_alt_user')
@@ -463,8 +454,7 @@
@mock.patch('tempest_lib.common.rest_client.RestClient')
def test_network_admin_creation(self, MockRestClient):
- iso_creds = isolated_creds.IsolatedCreds(name='test class',
- password='fake_password')
+ iso_creds = isolated_creds.IsolatedCreds(name='test class')
self._mock_assign_user_role()
self._mock_user_create('1234', 'fake_admin_user')
self._mock_tenant_create('1234', 'fake_admin_tenant')
@@ -496,7 +486,6 @@
'dhcp': False,
}
iso_creds = isolated_creds.IsolatedCreds(name='test class',
- password='fake_password',
network_resources=net_dict)
self._mock_assign_user_role()
self._mock_list_role()
@@ -532,7 +521,6 @@
'dhcp': False,
}
iso_creds = isolated_creds.IsolatedCreds(name='test class',
- password='fake_password',
network_resources=net_dict)
self._mock_assign_user_role()
self._mock_list_role()
@@ -550,7 +538,6 @@
'dhcp': False,
}
iso_creds = isolated_creds.IsolatedCreds(name='test class',
- password='fake_password',
network_resources=net_dict)
self._mock_assign_user_role()
self._mock_list_role()
@@ -568,7 +555,6 @@
'dhcp': True,
}
iso_creds = isolated_creds.IsolatedCreds(name='test class',
- password='fake_password',
network_resources=net_dict)
self._mock_assign_user_role()
self._mock_list_role()