Rename a common credential file for OS and K8S 83/51283/5
authorLinda Wang <wangwulin@huawei.com>
Mon, 29 Jan 2018 07:37:37 +0000 (07:37 +0000)
committerLinda Wang <wangwulin@huawei.com>
Thu, 1 Feb 2018 14:38:16 +0000 (14:38 +0000)
Change-Id: Ib8d24be4b29ab1de00d5dd5e3442146b2437cb94
Signed-off-by: Linda Wang <wangwulin@huawei.com>
14 files changed:
docs/testing/user/configguide/configguide.rst
docs/testing/user/userguide/runfunctest.rst
docs/testing/user/userguide/troubleshooting.rst
functest/api/resources/v1/creds.py
functest/ci/check_deployment.py
functest/ci/config_functest.yaml
functest/ci/run_tests.py
functest/cli/commands/cli_os.py
functest/core/vnf.py
functest/opnfv_tests/openstack/refstack_client/tempest_conf.py
functest/opnfv_tests/openstack/snaps/snaps_utils.py
functest/tests/unit/ci/test_run_tests.py
functest/tests/unit/cli/commands/test_cli_os.py
functest/tests/unit/core/test_vnf.py

index d632864..e514165 100644 (file)
@@ -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:
index 89580e5..d5b9510 100644 (file)
@@ -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
 ----
index 1e342b6..1649ac1 100644 (file)
@@ -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 \
index f445017..c4797fc 100644 (file)
@@ -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)
 
index 8d19d85..bf43b53 100644 (file)
@@ -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
index 192a1ee..ebaccc0 100644 (file)
@@ -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
index 7cba0ef..feef7d6 100644 (file)
@@ -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']))
index a543e84..7595caa 100644 (file)
@@ -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:
index 5339e42..0e2e301 100644 (file)
@@ -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,
index 5764f36..758d768 100644 (file)
@@ -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)
index 6b0ee49..e2f75c3 100644 (file)
@@ -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
index 9f48891..e5e4a05 100644 (file)
@@ -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__":
index 26956e0..1626ab1 100644 (file)
@@ -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')
index e0eee1a..112ce53 100644 (file)
@@ -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)