'refstack')
TEMPEST_CONF_YAML = pkg_resources.resource_filename(
'functest', 'opnfv_tests/openstack/tempest/custom_tests/tempest_conf.yaml')
+TEST_ACCOUNTS_FILE = pkg_resources.resource_filename(
+ 'functest',
+ 'opnfv_tests/openstack/tempest/custom_tests/test_accounts.yaml')
CI_INSTALLER_TYPE = CONST.__getattribute__('INSTALLER_TYPE')
CI_INSTALLER_IP = CONST.__getattribute__('INSTALLER_IP')
return img_flavor_dict
+def create_tenant_user():
+ keystone_client = os_utils.get_keystone_client()
+
+ logger.debug("Creating tenant and user for Tempest suite")
+ tenant_id = os_utils.create_tenant(
+ keystone_client,
+ CONST.__getattribute__('tempest_identity_tenant_name'),
+ CONST.__getattribute__('tempest_identity_tenant_description'))
+ if not tenant_id:
+ logger.error("Failed to create %s tenant"
+ % CONST.__getattribute__('tempest_identity_tenant_name'))
+
+ user_id = os_utils.create_user(
+ keystone_client,
+ CONST.__getattribute__('tempest_identity_user_name'),
+ CONST.__getattribute__('tempest_identity_user_password'),
+ None, tenant_id)
+ if not user_id:
+ logger.error("Failed to create %s user" %
+ CONST.__getattribute__('tempest_identity_user_name'))
+
+ return tenant_id
+
+
def get_verifier_id():
"""
Returns verifer id for current Tempest
config.set('DEFAULT', 'log_file', '{}/tempest.log'.format(deployment_dir))
config.set('oslo_concurrency', 'lock_path',
'{}/lock_files'.format(deployment_dir))
+ generate_test_accounts_file()
+ config.set('auth', 'test_accounts_file', TEST_ACCOUNTS_FILE)
config.set('scenario', 'img_dir', '{}'.format(deployment_dir))
config.set('scenario', 'img_file', 'tempest-image')
config.set('compute', 'image_ref', img_flavor_dict.get("image_id"))
shutil.copyfile(conf_file, confpath)
+def generate_test_accounts_file():
+ """
+ Add needed tenant and user params into test_accounts.yaml
+ """
+
+ logger.debug("Add needed params into test_accounts.yaml...")
+ tenant_id = create_tenant_user()
+ accounts_list = [
+ {
+ 'tenant_name':
+ CONST.__getattribute__('tempest_identity_tenant_name'),
+ 'tenant_id': str(tenant_id),
+ 'username': CONST.__getattribute__('tempest_identity_user_name'),
+ 'password':
+ CONST.__getattribute__('tempest_identity_user_password')
+ }
+ ]
+
+ with open(TEST_ACCOUNTS_FILE, "w") as f:
+ yaml.dump(accounts_list, f, default_flow_style=False)
+
+
def configure_tempest_update_params(tempest_conf_file,
IMAGE_ID=None, FLAVOR_ID=None):
"""
def test_create_tempest_resources_missing_network_dic(self):
with mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
- 'os_utils.get_keystone_client',
- return_value=mock.Mock()), \
- mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
- 'os_utils.create_shared_network_full',
- return_value=None), \
+ 'os_utils.create_shared_network_full',
+ return_value=None), \
self.assertRaises(Exception) as context:
conf_utils.create_tempest_resources()
msg = 'Failed to create private network'
def test_create_tempest_resources_missing_image(self):
with mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
- 'os_utils.get_keystone_client',
+ 'os_utils.create_shared_network_full',
return_value=mock.Mock()), \
- mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
- 'os_utils.create_shared_network_full',
- return_value=mock.Mock()), \
mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
'os_utils.get_or_create_image',
return_value=(mock.Mock(), None)), \
def test_create_tempest_resources_missing_flavor(self):
with mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
- 'os_utils.get_keystone_client',
+ 'os_utils.create_shared_network_full',
return_value=mock.Mock()), \
- mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
- 'os_utils.create_shared_network_full',
- return_value=mock.Mock()), \
mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
'os_utils.get_or_create_image',
return_value=(mock.Mock(), 'image_id')), \
msg = 'Failed to create flavor'
self.assertTrue(msg in context)
+ @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'logger.error')
+ def create_tenant_user_and_tenant_ok(self, mock_logger_error):
+ with mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'os_utils.get_keystone_client',
+ return_value=mock.Mock()), \
+ mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'os_utils.create_tenant',
+ return_value='test_tenant_id'):
+ conf_utils.create_tenant_user()
+ mock_logger_error.assert_not_called()
+
+ @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'logger.error')
+ def create_tenant_user_and_user_ok(self, mock_logger_error):
+ with mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'os_utils.get_keystone_client',
+ return_value=mock.Mock()), \
+ mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'os_utils.create_user',
+ return_value='test_user_id'):
+ conf_utils.create_tenant_user()
+ mock_logger_error.assert_not_called()
+
+ @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'logger.error')
+ def create_tenant_user_and_tenant_failed(self, mock_logger_error):
+ with mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'os_utils.get_keystone_client',
+ return_value=mock.Mock()), \
+ mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'os_utils.create_tenant',
+ return_value=None):
+ conf_utils.create_tenant_user()
+ msg = ("Failed to create %s tenant"
+ % CONST.__getattribute__('tempest_identity_tenant_name'))
+ mock_logger_error.assert_any_call(msg)
+
+ @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'logger.error')
+ def create_tenant_user_and_user_failed(self, mock_logger_error):
+ with mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'os_utils.get_keystone_client',
+ return_value=mock.Mock()), \
+ mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'os_utils.create_user',
+ return_value=None):
+ conf_utils.create_tenant_user()
+ msg = ("Failed to create %s user"
+ % CONST.__getattribute__('tempest_identity_user_name'))
+ mock_logger_error.assert_any_call(msg)
+
def test_get_verifier_id_missing_verifier(self):
CONST.__setattr__('tempest_deployment_name', 'test_deploy_name')
with mock.patch('functest.opnfv_tests.openstack.tempest.'
'conf_utils.ConfigParser.RawConfigParser.'
'write') as mwrite, \
mock.patch('__builtin__.open', mock.mock_open()), \
+ mock.patch('functest.opnfv_tests.openstack.tempest.'
+ 'conf_utils.generate_test_accounts_file'), \
mock.patch('functest.opnfv_tests.openstack.tempest.'
'conf_utils.shutil.copyfile'):
conf_utils.configure_tempest_defcore('test_dep_dir',
self.assertTrue(mread.called)
self.assertTrue(mwrite.called)
+ def test_generate_test_accounts_file_default(self):
+ with mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'create_tenant_user',
+ return_value='test_tenant_id') as mock_create, \
+ mock.patch("__builtin__.open", mock.mock_open()), \
+ mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'yaml.dump') as mock_dump:
+ conf_utils.generate_test_accounts_file()
+ self.assertTrue(mock_create.called)
+ self.assertTrue(mock_dump.called)
+
def _test_missing_param(self, params, image_id, flavor_id):
with mock.patch('functest.opnfv_tests.openstack.tempest.'
'conf_utils.ConfigParser.RawConfigParser.'