From 1825aa713952288e4204ea3b38f0d3c0635a6918 Mon Sep 17 00:00:00 2001 From: Linda Wang Date: Mon, 29 Jan 2018 07:37:37 +0000 Subject: [PATCH] Rename a common credential file for OS and K8S Change-Id: Ib8d24be4b29ab1de00d5dd5e3442146b2437cb94 Signed-off-by: Linda Wang --- docs/testing/user/configguide/configguide.rst | 28 +++++++++--------- docs/testing/user/userguide/runfunctest.rst | 6 ++-- docs/testing/user/userguide/troubleshooting.rst | 4 +-- functest/api/resources/v1/creds.py | 4 +-- functest/ci/check_deployment.py | 2 +- functest/ci/config_functest.yaml | 4 +-- functest/ci/run_tests.py | 14 ++------- functest/cli/commands/cli_os.py | 4 +-- functest/core/vnf.py | 2 +- .../openstack/refstack_client/tempest_conf.py | 2 +- .../opnfv_tests/openstack/snaps/snaps_utils.py | 2 +- functest/tests/unit/ci/test_run_tests.py | 34 +++++++--------------- functest/tests/unit/cli/commands/test_cli_os.py | 4 +-- functest/tests/unit/core/test_vnf.py | 8 ++--- 14 files changed, 48 insertions(+), 70 deletions(-) diff --git a/docs/testing/user/configguide/configguide.rst b/docs/testing/user/configguide/configguide.rst index d63286475..e514165dc 100644 --- a/docs/testing/user/configguide/configguide.rst +++ b/docs/testing/user/configguide/configguide.rst @@ -44,7 +44,7 @@ cat env:: See section on environment variables for details. -cat openstack.creds:: +cat env_file:: export OS_AUTH_URL=XXX export OS_USER_DOMAIN_NAME=XXX @@ -86,7 +86,7 @@ Testing healthcheck suite Run healthcheck suite:: sudo docker run --env-file env \ - -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/openstack.creds \ + -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/env_file \ -v $(pwd)/images:/home/opnfv/functest/images \ opnfv/functest-healthcheck @@ -107,7 +107,7 @@ Testing smoke suite Run smoke suite:: sudo docker run --env-file env \ - -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/openstack.creds \ + -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/env_file \ -v $(pwd)/images:/home/opnfv/functest/images \ opnfv/functest-smoke @@ -135,7 +135,7 @@ Testing features suite Run features suite:: sudo docker run --env-file env \ - -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/openstack.creds \ + -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/env_file \ -v $(pwd)/images:/home/opnfv/functest/images \ opnfv/functest-features @@ -160,7 +160,7 @@ Testing components suite Run components suite:: sudo docker run --env-file env \ - -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/openstack.creds \ + -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/env_file \ -v $(pwd)/images:/home/opnfv/functest/images \ opnfv/functest-components @@ -179,7 +179,7 @@ Testing vnf suite Run vnf suite:: sudo docker run --env-file env \ - -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/openstack.creds \ + -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/env_file \ -v $(pwd)/images:/home/opnfv/functest/images \ opnfv/functest-vnf @@ -268,7 +268,7 @@ Openstack credentials OpenStack credentials are mandatory and must be provided to Functest. When running the command "functest env prepare", the framework will automatically look for the Openstack credentials file -"/home/opnfv/functest/conf/openstack.creds" and will exit with +"/home/opnfv/functest/conf/env_file" and will exit with error if it is not present or is empty. There are 2 ways to provide that file: @@ -276,7 +276,7 @@ There are 2 ways to provide that file: * by using a Docker volume with -v option when creating the Docker container. This is referred to in docker documentation as "Bind Mounting". See the usage of this parameter in the following chapter. - * or creating manually the file '/home/opnfv/functest/conf/openstack.creds' + * or creating manually the file '/home/opnfv/functest/conf/env_file' inside the running container and pasting the credentials in it. Consult your installer guide for further details. This is however not instructed in this document. @@ -346,7 +346,7 @@ Underneath the '/home/opnfv/functest' directory, the Functest docker container includes two main directories: * The **conf** directory stores configuration files (e.g. the - OpenStack creds are stored in path '/home/opnfv/functest/conf/openstack.creds'), + OpenStack creds are stored in path '/home/opnfv/functest/conf/env_file'), * the **results** directory stores some temporary result log files src and repos directories are used to host third party code used for the tests. @@ -580,7 +580,7 @@ and credentials are working as expected. Once the credentials are there inside the container, they should be sourced before running any Openstack commands:: - source /home/opnfv/functest/conf/openstack.creds + source /home/opnfv/functest/conf/env_file After this, try to run any OpenStack command to see if you get any output, for instance:: @@ -631,14 +631,14 @@ http_proxy and https_proxy environment variables, as well as the 'no_proxy' environment variable are set correctly:: # Make double sure that the 'no_proxy=...' line in the - # 'openstack.creds' file is commented out first. Otherwise, the + # 'env_file' file is commented out first. Otherwise, the # values set into the 'no_proxy' environment variable below will # be ovewrwritten, each time the command - # 'source ~/functest/conf/openstack.creds' is issued. + # 'source ~/functest/conf/env_file' is issued. cd ~/functest/conf/ - sed -i 's/export no_proxy/#export no_proxy/' openstack.creds - source ./openstack.creds + sed -i 's/export no_proxy/#export no_proxy/' env_file + source ./env_file # Next calculate some IP addresses for which http_proxy # usage should be excluded: diff --git a/docs/testing/user/userguide/runfunctest.rst b/docs/testing/user/userguide/runfunctest.rst index 89580e564..d5b95101a 100644 --- a/docs/testing/user/userguide/runfunctest.rst +++ b/docs/testing/user/userguide/runfunctest.rst @@ -12,7 +12,7 @@ Assuming that you pulled the container and your environement is ready, you can simply run the tiers by typing (e.g. with functest-healthcheck):: sudo docker run --env-file env \ - -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/openstack.creds \ + -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/env_file \ -v $(pwd)/images:/home/opnfv/functest/images \ opnfv/functest-healthcheck @@ -44,14 +44,14 @@ different commands within the docker. Considering the healthcheck example, running functest manaully means:: sudo docker run -ti --env-file env \ - -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/openstack.creds \ + -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/env_file \ -v $(pwd)/images:/home/opnfv/functest/images \ opnfv/functest-healthcheck /bin/bash The docker prompt shall be returned. Then within the docker run the following commands:: - $ source /home/opnfv/functest/conf/openstack.creds + $ source /home/opnfv/functest/conf/env_file Tier ---- diff --git a/docs/testing/user/userguide/troubleshooting.rst b/docs/testing/user/userguide/troubleshooting.rst index 1e342b653..1649ac140 100644 --- a/docs/testing/user/userguide/troubleshooting.rst +++ b/docs/testing/user/userguide/troubleshooting.rst @@ -15,7 +15,7 @@ credentials:: or:: - source /home/opnfv/functest/conf/openstack.creds + source /home/opnfv/functest/conf/env_file VIM --- @@ -280,7 +280,7 @@ Example of custom list of tests 'my-custom-tempest-tests.txt':: This is an example of running a customized list of Tempest tests in Functest:: sudo docker run --env-file env \ - -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/openstack.creds \ + -v $(pwd)/openstack.creds:/home/opnfv/functest/conf/env_file \ -v $(pwd)/images:/home/opnfv/functest/images \ -v $(pwd)/my-custom-testcases.yaml:/usr/lib/python2.7/site-packages/functest/ci/testcases.yaml \ -v $(pwd)/my-custom-tempest-tests.txt:/usr/lib/python2.7/site-packages/functest/opnfv_tests/openstack/tempest/custom_tests/test_list.txt \ diff --git a/functest/api/resources/v1/creds.py b/functest/api/resources/v1/creds.py index f445017dc..c4797fc2f 100644 --- a/functest/api/resources/v1/creds.py +++ b/functest/api/resources/v1/creds.py @@ -39,7 +39,7 @@ class V1Creds(ApiResource): endpoint='{0}/credentials'.format(ENDPOINT_CREDS)) def get(self): # pylint: disable=no-self-use """ Get credentials """ - os_utils.source_credentials(CONST.__getattribute__('openstack_creds')) + os_utils.source_credentials(CONST.__getattribute__('env_file')) credentials_show = OpenStack.show_credentials() return jsonify(credentials_show) @@ -65,7 +65,7 @@ class V1Creds(ApiResource): lines = ['export {}={}\n'.format(k, v) for k, v in openrc_vars.items()] - rc_file = CONST.__getattribute__('openstack_creds') + rc_file = CONST.__getattribute__('env_file') with open(rc_file, 'w') as creds_file: creds_file.writelines(lines) diff --git a/functest/ci/check_deployment.py b/functest/ci/check_deployment.py index 8d19d8504..bf43b5372 100644 --- a/functest/ci/check_deployment.py +++ b/functest/ci/check_deployment.py @@ -68,7 +68,7 @@ def get_auth_token(os_creds): class CheckDeployment(object): """ Check deployment class.""" - def __init__(self, rc_file='/home/opnfv/functest/conf/openstack.creds'): + def __init__(self, rc_file='/home/opnfv/functest/conf/env_file'): self.rc_file = rc_file self.services = ('compute', 'network', 'image') self.os_creds = None diff --git a/functest/ci/config_functest.yaml b/functest/ci/config_functest.yaml index 192a1ee0d..ebaccc0cc 100644 --- a/functest/ci/config_functest.yaml +++ b/functest/ci/config_functest.yaml @@ -15,9 +15,9 @@ general: functest_images: /home/opnfv/functest/images rally_inst: /root/.rally - openstack: - creds: /home/opnfv/functest/conf/openstack.creds + env_file: /home/opnfv/functest/conf/env_file + openstack: image_name: Cirros-0.4.0 image_name_alt: Cirros-0.4.0-1 image_file_name: cirros-0.4.0-x86_64-disk.img diff --git a/functest/ci/run_tests.py b/functest/ci/run_tests.py index 7cba0efb2..feef7d6a5 100644 --- a/functest/ci/run_tests.py +++ b/functest/ci/run_tests.py @@ -98,16 +98,6 @@ class Runner(object): CONST.__getattribute__('DEPLOY_SCENARIO'), pkg_resources.resource_filename('functest', 'ci/testcases.yaml')) - @staticmethod - def source_rc_file(): - """Set the environmental vars from openstack.creds""" - - rc_file = CONST.__getattribute__('openstack_creds') - if not os.path.isfile(rc_file): - raise Exception("RC file %s does not exist..." % rc_file) - LOGGER.debug("Sourcing the OpenStack RC file...") - os_utils.source_credentials(rc_file) - @staticmethod def get_run_dict(testname): """Obtain the 'run' block of the testcase from testcases.yaml""" @@ -211,7 +201,9 @@ class Runner(object): self.report_flag = kwargs['report'] try: if 'test' in kwargs: - self.source_rc_file() + LOGGER.debug("Sourcing the credential file...") + os_utils.source_credentials(CONST.__getattribute__('env_file')) + LOGGER.debug("Test args: %s", kwargs['test']) if self.tiers.get_tier(kwargs['test']): self.run_tier(self.tiers.get_tier(kwargs['test'])) diff --git a/functest/cli/commands/cli_os.py b/functest/cli/commands/cli_os.py index a543e8457..7595caab7 100644 --- a/functest/cli/commands/cli_os.py +++ b/functest/cli/commands/cli_os.py @@ -23,14 +23,14 @@ class OpenStack(object): self.os_auth_url = CONST.__getattribute__('OS_AUTH_URL') self.endpoint_ip = None self.endpoint_port = None - self.openstack_creds = CONST.__getattribute__('openstack_creds') + self.openstack_creds = CONST.__getattribute__('env_file') if self.os_auth_url: self.endpoint_ip = urllib.parse.urlparse(self.os_auth_url).hostname self.endpoint_port = urllib.parse.urlparse(self.os_auth_url).port def ping_endpoint(self): if self.os_auth_url is None: - click.echo("Source the OpenStack credentials first '. $creds'") + click.echo("Source the OpenStack credentials first") exit(0) response = os.system("ping -c 1 " + self.endpoint_ip + ">/dev/null") if response == 0: diff --git a/functest/core/vnf.py b/functest/core/vnf.py index 5339e42e8..0e2e30134 100644 --- a/functest/core/vnf.py +++ b/functest/core/vnf.py @@ -107,7 +107,7 @@ class VnfOnBoarding(base.TestCase): self.__logger.info("Prepare VNF: %s, description: %s", self.tenant_name, tenant_description) snaps_creds = openstack_tests.get_credentials( - os_env_file=CONST.__getattribute__('openstack_creds')) + os_env_file=CONST.__getattribute__('env_file')) project_creator = OpenStackProject( snaps_creds, diff --git a/functest/opnfv_tests/openstack/refstack_client/tempest_conf.py b/functest/opnfv_tests/openstack/refstack_client/tempest_conf.py index 5764f366c..758d76847 100644 --- a/functest/opnfv_tests/openstack/refstack_client/tempest_conf.py +++ b/functest/opnfv_tests/openstack/refstack_client/tempest_conf.py @@ -36,7 +36,7 @@ class TempestConf(object): """ Generate tempest.conf file""" try: openstack_utils.source_credentials( - CONST.__getattribute__('openstack_creds')) + CONST.__getattribute__('env_file')) resources = self.resources.create(create_project=True, use_custom_images=True, use_custom_flavors=True) diff --git a/functest/opnfv_tests/openstack/snaps/snaps_utils.py b/functest/opnfv_tests/openstack/snaps/snaps_utils.py index 6b0ee497c..e2f75c3f0 100644 --- a/functest/opnfv_tests/openstack/snaps/snaps_utils.py +++ b/functest/opnfv_tests/openstack/snaps/snaps_utils.py @@ -55,7 +55,7 @@ def get_credentials(proxy_settings_str=None, ssh_proxy_cmd=None): creds_override = CONST.__getattribute__( 'snaps_os_creds_override') os_creds = openstack_tests.get_credentials( - os_env_file=CONST.__getattribute__('openstack_creds'), + os_env_file=CONST.__getattribute__('env_file'), proxy_settings_str=proxy_settings_str, ssh_proxy_cmd=ssh_proxy_cmd, overrides=creds_override) return os_creds diff --git a/functest/tests/unit/ci/test_run_tests.py b/functest/tests/unit/ci/test_run_tests.py index 9f48891e7..e5e4a056b 100644 --- a/functest/tests/unit/ci/test_run_tests.py +++ b/functest/tests/unit/ci/test_run_tests.py @@ -54,22 +54,6 @@ class RunTestsTesting(unittest.TestCase): self.run_tests_parser = run_tests.RunTestsParser() - @mock.patch('functest.ci.run_tests.os.path.isfile', return_value=False) - def test_source_rc_file_ko(self, *args): - with self.assertRaises(Exception): - self.runner.source_rc_file() - args[0].assert_called_once_with( - '/home/opnfv/functest/conf/openstack.creds') - - @mock.patch('functest.ci.run_tests.os.path.isfile', - return_value=True) - def test_source_rc_file_default(self, *args): - with mock.patch('functest.ci.run_tests.os_utils.source_credentials', - return_value=self.creds): - self.runner.source_rc_file() - args[0].assert_called_once_with( - '/home/opnfv/functest/conf/openstack.creds') - @mock.patch('functest.ci.run_tests.ft_utils.get_dict_by_test') def test_get_run_dict(self, *args): retval = {'run': mock.Mock()} @@ -163,7 +147,7 @@ class RunTestsTesting(unittest.TestCase): self.runner.run_all() self.assertTrue(mock_methods[1].called) - @mock.patch('functest.ci.run_tests.Runner.source_rc_file', + @mock.patch('functest.utils.openstack_utils.source_credentials', side_effect=Exception) @mock.patch('functest.ci.run_tests.Runner.summary') def test_main_failed(self, *mock_methods): @@ -174,9 +158,10 @@ class RunTestsTesting(unittest.TestCase): self.runner.tiers.configure_mock(**args) self.assertEqual(self.runner.main(**kwargs), run_tests.Result.EX_ERROR) - mock_methods[1].assert_called_once_with() + mock_methods[1].assert_called_once_with( + '/home/opnfv/functest/conf/env_file') - @mock.patch('functest.ci.run_tests.Runner.source_rc_file') + @mock.patch('functest.utils.openstack_utils.source_credentials') @mock.patch('functest.ci.run_tests.Runner.run_test', return_value=TestCase.EX_OK) @mock.patch('functest.ci.run_tests.Runner.summary') @@ -196,7 +181,7 @@ class RunTestsTesting(unittest.TestCase): run_tests.Result.EX_OK) mock_methods[1].assert_called() - @mock.patch('functest.ci.run_tests.Runner.source_rc_file') + @mock.patch('functest.utils.openstack_utils.source_credentials') @mock.patch('functest.ci.run_tests.Runner.run_test', return_value=TestCase.EX_OK) def test_main_test(self, *mock_methods): @@ -204,12 +189,13 @@ class RunTestsTesting(unittest.TestCase): args = {'get_tier.return_value': None, 'get_test.return_value': 'test_name'} self.runner.tiers = mock.Mock() + mock_methods[1].return_value = self.creds self.runner.tiers.configure_mock(**args) self.assertEqual(self.runner.main(**kwargs), run_tests.Result.EX_OK) mock_methods[0].assert_called_once_with('test_name') - @mock.patch('functest.ci.run_tests.Runner.source_rc_file') + @mock.patch('functest.utils.openstack_utils.source_credentials') @mock.patch('functest.ci.run_tests.Runner.run_all') @mock.patch('functest.ci.run_tests.Runner.summary') def test_main_all_tier(self, *args): @@ -222,9 +208,9 @@ class RunTestsTesting(unittest.TestCase): run_tests.Result.EX_OK) args[0].assert_called_once_with(None) args[1].assert_called_once_with() - args[2].assert_called_once_with() + args[2].assert_called_once_with('/home/opnfv/functest/conf/env_file') - @mock.patch('functest.ci.run_tests.Runner.source_rc_file') + @mock.patch('functest.utils.openstack_utils.source_credentials') def test_main_any_tier_test_ko(self, *args): kwargs = {'get_tier.return_value': None, 'get_test.return_value': None} @@ -233,7 +219,7 @@ class RunTestsTesting(unittest.TestCase): self.assertEqual( self.runner.main(test='any', noclean=True, report=True), run_tests.Result.EX_ERROR) - args[0].assert_called_once_with() + args[0].assert_called_once_with('/home/opnfv/functest/conf/env_file') if __name__ == "__main__": diff --git a/functest/tests/unit/cli/commands/test_cli_os.py b/functest/tests/unit/cli/commands/test_cli_os.py index 26956e08b..1626ab1bc 100644 --- a/functest/tests/unit/cli/commands/test_cli_os.py +++ b/functest/tests/unit/cli/commands/test_cli_os.py @@ -24,7 +24,7 @@ class CliOpenStackTesting(unittest.TestCase): self.os_auth_url = 'http://test_ip:test_port/v2.0' self.installer_type = 'test_installer_type' self.installer_ip = 'test_installer_ip' - self.openstack_creds = 'test_openstack_creds' + self.openstack_creds = 'test_env_file' self.snapshot_file = 'test_snapshot_file' self.cli_os = cli_os.CliOpenStack() @@ -42,7 +42,7 @@ class CliOpenStackTesting(unittest.TestCase): self.cli_os.os_auth_url = None self.cli_os.ping_endpoint() mock_click_echo.assert_called_once_with( - "Source the OpenStack credentials first '. $creds'") + "Source the OpenStack credentials first") mock_exit.assert_called_once_with(0) @mock.patch('functest.cli.commands.cli_os.exit') diff --git a/functest/tests/unit/core/test_vnf.py b/functest/tests/unit/core/test_vnf.py index e0eee1a19..112ce53b7 100644 --- a/functest/tests/unit/core/test_vnf.py +++ b/functest/tests/unit/core/test_vnf.py @@ -118,7 +118,7 @@ class VnfBaseTesting(unittest.TestCase): with self.assertRaises(Exception): self.test.prepare() args[0].assert_called_with( - os_env_file=constants.CONST.__getattribute__('openstack_creds')) + os_env_file=constants.CONST.__getattribute__('env_file')) args[1].assert_not_called() args[2].assert_not_called() @@ -129,7 +129,7 @@ class VnfBaseTesting(unittest.TestCase): with self.assertRaises(Exception): self.test.prepare() args[0].assert_called_with( - os_env_file=constants.CONST.__getattribute__('openstack_creds')) + os_env_file=constants.CONST.__getattribute__('env_file')) args[1].assert_called_with(mock.ANY, mock.ANY) args[2].assert_not_called() @@ -140,7 +140,7 @@ class VnfBaseTesting(unittest.TestCase): with self.assertRaises(Exception): self.test.prepare() args[0].assert_called_with( - os_env_file=constants.CONST.__getattribute__('openstack_creds')) + os_env_file=constants.CONST.__getattribute__('env_file')) args[1].assert_called_with(mock.ANY, mock.ANY) args[2].assert_called_with(mock.ANY, mock.ANY) @@ -150,7 +150,7 @@ class VnfBaseTesting(unittest.TestCase): def test_prepare_default(self, *args): self.assertEqual(self.test.prepare(), testcase.TestCase.EX_OK) args[0].assert_called_with( - os_env_file=constants.CONST.__getattribute__('openstack_creds')) + os_env_file=constants.CONST.__getattribute__('env_file')) args[1].assert_called_with(mock.ANY, mock.ANY) args[2].assert_called_with(mock.ANY, mock.ANY) -- 2.16.6