aboutsummaryrefslogtreecommitdiffstats
path: root/functest
diff options
context:
space:
mode:
authorLinda Wang <wangwulin@huawei.com>2018-01-29 07:37:37 +0000
committerLinda Wang <wangwulin@huawei.com>2018-02-01 14:38:16 +0000
commit1825aa713952288e4204ea3b38f0d3c0635a6918 (patch)
tree1f5174de93defbf8e703c73785eaaa118f4a940e /functest
parent416461c30d5a9a0df38e6c1bdef7061fce2c7eaf (diff)
Rename a common credential file for OS and K8S
Change-Id: Ib8d24be4b29ab1de00d5dd5e3442146b2437cb94 Signed-off-by: Linda Wang <wangwulin@huawei.com>
Diffstat (limited to 'functest')
-rw-r--r--functest/api/resources/v1/creds.py4
-rw-r--r--functest/ci/check_deployment.py2
-rw-r--r--functest/ci/config_functest.yaml4
-rw-r--r--functest/ci/run_tests.py14
-rw-r--r--functest/cli/commands/cli_os.py4
-rw-r--r--functest/core/vnf.py2
-rw-r--r--functest/opnfv_tests/openstack/refstack_client/tempest_conf.py2
-rw-r--r--functest/opnfv_tests/openstack/snaps/snaps_utils.py2
-rw-r--r--functest/tests/unit/ci/test_run_tests.py34
-rw-r--r--functest/tests/unit/cli/commands/test_cli_os.py4
-rw-r--r--functest/tests/unit/core/test_vnf.py8
11 files changed, 29 insertions, 51 deletions
diff --git a/functest/api/resources/v1/creds.py b/functest/api/resources/v1/creds.py
index f445017d..c4797fc2 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 8d19d850..bf43b537 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 192a1ee0..ebaccc0c 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 7cba0efb..feef7d6a 100644
--- a/functest/ci/run_tests.py
+++ b/functest/ci/run_tests.py
@@ -99,16 +99,6 @@ class Runner(object):
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"""
try:
@@ -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 a543e845..7595caab 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 5339e42e..0e2e3013 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 5764f366..758d7684 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 6b0ee497..e2f75c3f 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 9f48891e..e5e4a056 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 26956e08..1626ab1b 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 e0eee1a1..112ce53b 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)