aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests/unit/openstack
diff options
context:
space:
mode:
authorLinda Wang <wangwulin@huawei.com>2017-08-22 11:38:58 +0000
committerLinda Wang <wangwulin@huawei.com>2017-08-22 12:19:27 +0000
commit961d31d83a1b2e872f5e270bcea93519544b5cd2 (patch)
treeb428d7747f6f92ff0acb1abd9ddd33cf2c95bd25 /functest/tests/unit/openstack
parent42562fa3393aa54d1780a428b439cedcd3590a7b (diff)
Config test_accounts_file for refstack_defcore
Tenant and user are required by refstack_defcore, which could be configured in the test_accounts_file. [1] [1]: https://github.com/openstack/refstack-client/blob/master/refstack_client/refstack_client.py#L170-L193 Change-Id: I9c920b6f15f491d671ebf222976305bedf4dd747 Signed-off-by: Linda Wang <wangwulin@huawei.com>
Diffstat (limited to 'functest/tests/unit/openstack')
-rw-r--r--functest/tests/unit/openstack/tempest/test_conf_utils.py82
1 files changed, 69 insertions, 13 deletions
diff --git a/functest/tests/unit/openstack/tempest/test_conf_utils.py b/functest/tests/unit/openstack/tempest/test_conf_utils.py
index bbfcc57d..e2937a18 100644
--- a/functest/tests/unit/openstack/tempest/test_conf_utils.py
+++ b/functest/tests/unit/openstack/tempest/test_conf_utils.py
@@ -18,11 +18,8 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
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'
@@ -30,12 +27,9 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
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)), \
self.assertRaises(Exception) as context:
@@ -52,12 +46,9 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
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')), \
mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
@@ -76,6 +67,58 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
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.'
@@ -206,6 +249,8 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
'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',
img_flavor_dict)
@@ -218,6 +263,17 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
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.'