Use constants for Functest config file
authorCédric Ollivier <cedric.ollivier@orange.com>
Wed, 21 Feb 2018 10:33:39 +0000 (11:33 +0100)
committerCédric Ollivier <cedric.ollivier@orange.com>
Thu, 22 Feb 2018 09:31:32 +0000 (10:31 +0100)
env_file can't be defined in a config file simply because it's an
entry point (Jenkins jobs, end users)

Change-Id: Ie23c0ef90efc839d60f0f3a9754c58746b1f3a00
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
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/snaps/snaps_utils.py
functest/tests/unit/core/test_vnf.py
functest/utils/constants.py
functest/utils/env.py

index 25c0fd2..3eae196 100644 (file)
@@ -23,7 +23,7 @@ from functest.api.base import ApiResource
 from functest.api.common import api_utils
 from functest.ci import run_tests
 from functest.cli.commands.cli_os import OpenStack
-from functest.utils.constants import CONST
+from functest.utils import constants
 
 LOGGER = logging.getLogger(__name__)
 
@@ -39,7 +39,7 @@ class V1Creds(ApiResource):
         endpoint='{0}/credentials'.format(ENDPOINT_CREDS))
     def get(self):  # pylint: disable=no-self-use
         """ Get credentials """
-        run_tests.Runner.source_envfile(getattr(CONST, 'env_file'))
+        run_tests.Runner.source_envfile(constants.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 = getattr(CONST, 'env_file')
+        rc_file = constants.ENV_FILE
         with open(rc_file, 'w') as creds_file:
             creds_file.writelines(lines)
 
index bf43b53..a475491 100644 (file)
@@ -28,6 +28,7 @@ from snaps.openstack.utils import keystone_utils
 from snaps.openstack.utils import neutron_utils
 from snaps.openstack.utils import nova_utils
 
+from functest.utils import constants
 from functest.opnfv_tests.openstack.snaps import snaps_utils
 
 __author__ = "Jose Lausuch <jose.lausuch@ericsson.com>"
@@ -68,7 +69,7 @@ def get_auth_token(os_creds):
 class CheckDeployment(object):
     """ Check deployment class."""
 
-    def __init__(self, rc_file='/home/opnfv/functest/conf/env_file'):
+    def __init__(self, rc_file=constants.ENV_FILE):
         self.rc_file = rc_file
         self.services = ('compute', 'network', 'image')
         self.os_creds = None
index be7a2db..e93b025 100644 (file)
@@ -15,8 +15,6 @@ general:
         functest_images: /home/opnfv/functest/images
         rally_inst: /root/.rally
 
-    env_file: /home/opnfv/functest/conf/env_file
-
     openstack:
         image_name: Cirros-0.4.0
         image_name_alt: Cirros-0.4.0-1
index ca101ce..0b98030 100644 (file)
@@ -29,10 +29,10 @@ import yaml
 
 from functest.ci import tier_builder
 from functest.core import testcase
+from functest.utils import constants
 from functest.utils import env
 
 LOGGER = logging.getLogger('functest.ci.run_tests')
-ENV_FILE = "/home/opnfv/functest/conf/env_file"
 
 
 class Result(enum.Enum):
@@ -95,7 +95,7 @@ class Runner(object):
             pkg_resources.resource_filename('functest', 'ci/testcases.yaml'))
 
     @staticmethod
-    def source_envfile(rc_file=ENV_FILE):
+    def source_envfile(rc_file=constants.ENV_FILE):
         """Source the env file passed as arg"""
         if not os.path.isfile(rc_file):
             LOGGER.debug("No env file %s found", rc_file)
index 0cf2862..47d55c9 100644 (file)
@@ -14,7 +14,7 @@ import click
 from six.moves import urllib
 
 from functest.ci import check_deployment
-from functest.utils.constants import CONST
+from functest.utils import constants
 
 
 class OpenStack(object):
@@ -23,7 +23,7 @@ class OpenStack(object):
         self.os_auth_url = os.environ['OS_AUTH_URL']
         self.endpoint_ip = None
         self.endpoint_port = None
-        self.openstack_creds = getattr(CONST, 'env_file')
+        self.openstack_creds = constants.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
index 05baf43..cf20492 100644 (file)
@@ -20,6 +20,7 @@ from snaps.openstack.create_project import OpenStackProject
 from snaps.openstack.tests import openstack_tests
 
 from functest.core import testcase
+from functest.utils import constants
 
 __author__ = ("Morgan Richomme <morgan.richomme@orange.com>, "
               "Valentin Boucher <valentin.boucher@orange.com>")
@@ -46,7 +47,6 @@ class VnfOnBoarding(testcase.TestCase):
     """Base model for VNF test cases."""
 
     __logger = logging.getLogger(__name__)
-    env_file = "/home/opnfv/functest/conf/env_file"
 
     def __init__(self, **kwargs):
         super(VnfOnBoarding, self).__init__(**kwargs)
@@ -110,7 +110,7 @@ class VnfOnBoarding(testcase.TestCase):
                 "Prepare VNF: %s, description: %s", self.case_name,
                 self.tenant_description)
             snaps_creds = openstack_tests.get_credentials(
-                os_env_file=self.env_file)
+                os_env_file=constants.ENV_FILE)
 
             self.os_project = OpenStackProject(
                 snaps_creds,
index 4b1c935..fc03ee9 100644 (file)
@@ -9,7 +9,7 @@
 
 """Some common utils wrapping snaps functions """
 
-from functest.utils.constants import CONST
+from functest.utils import constants
 from functest.utils import env
 
 from snaps.openstack.tests import openstack_tests
@@ -52,10 +52,9 @@ def get_credentials(proxy_settings_str=None, ssh_proxy_cmd=None):
     :return: an instance of snaps OSCreds object
     """
     creds_override = None
-    if hasattr(CONST, 'snaps_os_creds_override'):
-        creds_override = getattr(CONST, 'snaps_os_creds_override')
+    if hasattr(constants.CONST, 'snaps_os_creds_override'):
+        creds_override = getattr(constants.CONST, 'snaps_os_creds_override')
     os_creds = openstack_tests.get_credentials(
-        os_env_file=getattr(CONST, 'env_file'),
-        proxy_settings_str=proxy_settings_str, ssh_proxy_cmd=ssh_proxy_cmd,
-        overrides=creds_override)
+        os_env_file=constants.ENV_FILE, proxy_settings_str=proxy_settings_str,
+        ssh_proxy_cmd=ssh_proxy_cmd, overrides=creds_override)
     return os_creds
index 16a6090..0ac672f 100644 (file)
@@ -16,6 +16,7 @@ import mock
 
 from functest.core import vnf
 from functest.core import testcase
+from functest.utils import constants
 
 from snaps.openstack.os_credentials import OSCreds
 
@@ -113,7 +114,7 @@ class VnfBaseTesting(unittest.TestCase):
     def test_prepare_exc1(self, *args):
         with self.assertRaises(Exception):
             self.test.prepare()
-        args[0].assert_called_with(os_env_file=vnf.VnfOnBoarding.env_file)
+        args[0].assert_called_with(os_env_file=constants.ENV_FILE)
         args[1].assert_not_called()
         args[2].assert_not_called()
 
@@ -123,7 +124,7 @@ class VnfBaseTesting(unittest.TestCase):
     def test_prepare_exc2(self, *args):
         with self.assertRaises(Exception):
             self.test.prepare()
-        args[0].assert_called_with(os_env_file=vnf.VnfOnBoarding.env_file)
+        args[0].assert_called_with(os_env_file=constants.ENV_FILE)
         args[1].assert_called_with(mock.ANY, mock.ANY)
         args[2].assert_not_called()
 
@@ -133,7 +134,7 @@ class VnfBaseTesting(unittest.TestCase):
     def test_prepare_exc3(self, *args):
         with self.assertRaises(Exception):
             self.test.prepare()
-        args[0].assert_called_with(os_env_file=vnf.VnfOnBoarding.env_file)
+        args[0].assert_called_with(os_env_file=constants.ENV_FILE)
         args[1].assert_called_with(mock.ANY, mock.ANY)
         args[2].assert_called_with(mock.ANY, mock.ANY)
 
@@ -142,7 +143,7 @@ class VnfBaseTesting(unittest.TestCase):
     @mock.patch('snaps.openstack.tests.openstack_tests.get_credentials')
     def test_prepare_default(self, *args):
         self.assertEqual(self.test.prepare(), testcase.TestCase.EX_OK)
-        args[0].assert_called_with(os_env_file=vnf.VnfOnBoarding.env_file)
+        args[0].assert_called_with(os_env_file=constants.ENV_FILE)
         args[1].assert_called_with(mock.ANY, mock.ANY)
         args[2].assert_called_with(mock.ANY, mock.ANY)
 
index d8a1d54..2184c47 100644 (file)
@@ -8,11 +8,17 @@ import six
 from functest.utils import config
 from functest.utils import env
 
+CONFIG_FUNCTEST_YAML = pkg_resources.resource_filename(
+    'functest', 'ci/config_functest.yaml')
+
+ENV_FILE = '/home/opnfv/functest/conf/env_file'
+
 
 class Constants(object):  # pylint: disable=too-few-public-methods
 
-    CONFIG_FUNCTEST_YAML = pkg_resources.resource_filename(
-        'functest', 'ci/config_functest.yaml')
+    # Backward compatibility (waiting for SDNVPN and SFC)
+    CONFIG_FUNCTEST_YAML = CONFIG_FUNCTEST_YAML
+    env_file = ENV_FILE
 
     def __init__(self):
         for attr_n, attr_v in six.iteritems(config.CONF.__dict__):
index 0c0515b..e75b17d 100644 (file)
@@ -37,10 +37,10 @@ def get(env_var):
 
 class Environment(object):  # pylint: disable=too-few-public-methods
 
-    # Backward compatibilty (waiting for SDNVPN and SFC)
+    # Backward compatibility (waiting for SDNVPN and SFC)
     def __init__(self):
         for key, _ in six.iteritems(INPUTS):
             setattr(self, key, get(key))
 
-# Backward compatibilty (waiting for SDNVPN and SFC)
+# Backward compatibility (waiting for SDNVPN and SFC)
 ENV = Environment()