From a1b0f64bccea682e55ec5086aef979df57cf686f Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Wed, 21 Feb 2018 10:01:30 +0100 Subject: Automatically download defcore.txt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It stops writing files in Functest package dirs and cleans instance variables in refstack modules too. Change-Id: Iaddbe4fbaf12d1af207b86d4e44258efdc6d6f3a Signed-off-by: Cédric Ollivier --- .../refstack_client/test_refstack_client.py | 43 ++++++++++------------ .../unit/openstack/tempest/test_conf_utils.py | 33 ----------------- .../tests/unit/openstack/tempest/test_tempest.py | 12 +----- 3 files changed, 22 insertions(+), 66 deletions(-) (limited to 'functest/tests/unit') diff --git a/functest/tests/unit/openstack/refstack_client/test_refstack_client.py b/functest/tests/unit/openstack/refstack_client/test_refstack_client.py index e2e7dceb..1d5cc69f 100644 --- a/functest/tests/unit/openstack/refstack_client/test_refstack_client.py +++ b/functest/tests/unit/openstack/refstack_client/test_refstack_client.py @@ -33,12 +33,10 @@ class OSRefstackClientTesting(unittest.TestCase): _config = pkg_resources.resource_filename( 'functest', 'opnfv_tests/openstack/refstack_client/refstack_tempest.conf') - _testlist = pkg_resources.resource_filename( - 'functest', 'opnfv_tests/openstack/refstack_client/defcore.txt') def setUp(self): - self.default_args = {'config': self._config, - 'testlist': self._testlist} + self.default_args = {'config': None, + 'testlist': RefstackClient.defcorelist} os.environ['OS_AUTH_URL'] = 'https://ip:5000/v3' os.environ['OS_INSECURE'] = 'true' self.case_name = 'refstack_defcore' @@ -57,30 +55,28 @@ class OSRefstackClientTesting(unittest.TestCase): 'get_credentials', return_value=self.os_creds): return RefstackClient() - def test_run_defcore_insecure(self): + @mock.patch('functest.utils.functest_utils.execute_command') + def test_run_defcore_insecure(self, m_cmd): insecure = '-k' config = 'tempest.conf' testlist = 'testlist' client = self._create_client() - with mock.patch('functest.opnfv_tests.openstack.refstack_client.' - 'refstack_client.ft_utils.execute_command') as m_cmd: - cmd = ("refstack-client test {0} -c {1} -v --test-list {2}" - .format(insecure, config, testlist)) - client.run_defcore(config, testlist) - m_cmd.assert_any_call(cmd) - - def test_run_defcore(self): + cmd = ("refstack-client test {0} -c {1} -v --test-list {2}".format( + insecure, config, testlist)) + client.run_defcore(config, testlist) + m_cmd.assert_any_call(cmd) + + @mock.patch('functest.utils.functest_utils.execute_command') + def test_run_defcore(self, m_cmd): os.environ['OS_AUTH_URL'] = 'http://ip:5000/v3' insecure = '' config = 'tempest.conf' testlist = 'testlist' client = self._create_client() - with mock.patch('functest.opnfv_tests.openstack.refstack_client.' - 'refstack_client.ft_utils.execute_command') as m_cmd: - cmd = ("refstack-client test {0} -c {1} -v --test-list {2}" - .format(insecure, config, testlist)) - client.run_defcore(config, testlist) - m_cmd.assert_any_call(cmd) + cmd = ("refstack-client test {0} -c {1} -v --test-list {2}".format( + insecure, config, testlist)) + client.run_defcore(config, testlist) + m_cmd.assert_any_call(cmd) @mock.patch('functest.opnfv_tests.openstack.refstack_client.' 'refstack_client.LOGGER.info') @@ -109,7 +105,7 @@ class OSRefstackClientTesting(unittest.TestCase): def _get_main_kwargs(self, key=None): kwargs = {'config': self._config, - 'testlist': self._testlist} + 'testlist': RefstackClient.defcorelist} if key: del kwargs[key] return kwargs @@ -136,15 +132,16 @@ class OSRefstackClientTesting(unittest.TestCase): self._test_argparser('config', self._config) def test_argparser_testlist(self): - self._test_argparser('testlist', self._testlist) + self._test_argparser('testlist', RefstackClient.defcorelist) def test_argparser_multiple_args(self): self.default_args['config'] = self._config - self.default_args['testlist'] = self._testlist + self.default_args['testlist'] = RefstackClient.defcorelist parser = RefstackClientParser() self.assertEqual(parser.parse_args( ["--config={}".format(self._config), - "--testlist={}".format(self._testlist)]), self.default_args) + "--testlist={}".format(RefstackClient.defcorelist)]), + self.default_args) if __name__ == "__main__": diff --git a/functest/tests/unit/openstack/tempest/test_conf_utils.py b/functest/tests/unit/openstack/tempest/test_conf_utils.py index e88bb248..1d5f29a2 100644 --- a/functest/tests/unit/openstack/tempest/test_conf_utils.py +++ b/functest/tests/unit/openstack/tempest/test_conf_utils.py @@ -241,39 +241,6 @@ class OSTempestConfUtilsTesting(unittest.TestCase): conf_utils.configure_tempest('test_dep_dir') self.assertTrue(mock_upd.called) - def test_conf_tempest_defcore_def(self): - with mock.patch('functest.opnfv_tests.openstack.tempest.' - 'conf_utils.configure_verifier', - return_value='test_conf_file'), \ - mock.patch('functest.opnfv_tests.openstack.tempest.' - 'conf_utils.configure_tempest_update_params'), \ - mock.patch('functest.opnfv_tests.openstack.tempest.' - 'conf_utils.ConfigParser.RawConfigParser.' - 'set') as mset, \ - mock.patch('functest.opnfv_tests.openstack.tempest.' - 'conf_utils.ConfigParser.RawConfigParser.' - 'read') as mread, \ - 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', 'test_network_name', 'test_image_id', - 'test_flavor_id', 'test_image_alt_id', 'test_flavor_alt_id', - 'test_tenant_id') - mset.assert_any_call('compute', 'image_ref', 'test_image_id') - mset.assert_any_call('compute', 'image_ref_alt', - 'test_image_alt_id') - mset.assert_any_call('compute', 'flavor_ref', 'test_flavor_id') - mset.assert_any_call('compute', 'flavor_ref_alt', - 'test_flavor_alt_id') - self.assertTrue(mread.called) - self.assertTrue(mwrite.called) - def test_gen_test_accounts_file_def(self): with mock.patch("__builtin__.open", mock.mock_open()), \ mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' diff --git a/functest/tests/unit/openstack/tempest/test_tempest.py b/functest/tests/unit/openstack/tempest/test_tempest.py index 77cf28af..ba2c1c48 100644 --- a/functest/tests/unit/openstack/tempest/test_tempest.py +++ b/functest/tests/unit/openstack/tempest/test_tempest.py @@ -49,15 +49,6 @@ class OSTempestTesting(unittest.TestCase): self.tempestcustom = tempest.TempestCustom() self.tempestdefcore = tempest.TempestDefcore() - @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.LOGGER.debug') - def test_gen_tl_defcore_mode(self, mock_logger_debug): - # pylint: disable=unused-argument - self.tempestcommon.mode = 'defcore' - with mock.patch('functest.opnfv_tests.openstack.tempest.tempest.' - 'shutil.copyfile') as mock_copyfile: - self.tempestcommon.generate_test_list('test_verifier_repo_dir') - self.assertTrue(mock_copyfile.called) - @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.LOGGER.error') @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.LOGGER.debug') def test_gen_tl_cm_missing_file(self, mock_logger_debug, @@ -69,7 +60,8 @@ class OSTempestTesting(unittest.TestCase): self.assertRaises(Exception) as context: msg = "Tempest test list file %s NOT found." self.tempestcommon.generate_test_list('test_verifier_repo_dir') - self.assertTrue((msg % conf_utils.TEMPEST_CUSTOM) in context) + self.assertTrue( + (msg % conf_utils.TEMPEST_CUSTOM) in context.exception) def test_gen_tl_cm_default(self): self.tempestcommon.mode = 'custom' -- cgit 1.2.3-korg