From 961d31d83a1b2e872f5e270bcea93519544b5cd2 Mon Sep 17 00:00:00 2001 From: Linda Wang Date: Tue, 22 Aug 2017 11:38:58 +0000 Subject: 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 --- .../unit/openstack/tempest/test_conf_utils.py | 82 ++++++++++++++++++---- 1 file changed, 69 insertions(+), 13 deletions(-) (limited to 'functest/tests/unit/openstack') 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,11 +27,8 @@ 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)), \ @@ -52,11 +46,8 @@ 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')), \ @@ -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.' @@ -205,6 +248,8 @@ class OSTempestConfUtilsTesting(unittest.TestCase): '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', @@ -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.' -- cgit 1.2.3-korg