From 3e3c96b2aa15d7757f281ce00518a67e2a1225a9 Mon Sep 17 00:00:00 2001 From: helenyao Date: Mon, 21 Nov 2016 06:50:06 -0500 Subject: Extracted all global parameters into functest_constants.py JIRA: FUNCTEST-533 1. Extracted all global variables into functest_constants.py and updated all affected areas accordingly 2. Used os.path.join to replace '/' to come up with the path for better cross-platform support and improve the path accuracy 3. Removed unused variables 4. Updated the hardcoded path in Dockerfile by using variable reference 5. Removed "/" ending from all path variables 6. Updated the unit test Change-Id: Ib30a81d1f0c83fbaef042d63c187c27bd18301bb Signed-off-by: helenyao --- functest/cli/commands/cli_os.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'functest/cli/commands/cli_os.py') diff --git a/functest/cli/commands/cli_os.py b/functest/cli/commands/cli_os.py index 2530b5f2..140be191 100644 --- a/functest/cli/commands/cli_os.py +++ b/functest/cli/commands/cli_os.py @@ -15,19 +15,17 @@ import click import functest.utils.functest_utils as ft_utils import functest.utils.openstack_clean as os_clean import functest.utils.openstack_snapshot as os_snapshot +import functest.utils.functest_constants as ft_constants -FUNCTEST_CONF_DIR = \ - ft_utils.get_functest_config('general.directories.dir_functest_conf') -RC_FILE = os.getenv('creds') -OS_SNAPSHOT_FILE = \ - ft_utils.get_functest_config("general.openstack.snapshot_file") +OPENSTACK_RC_FILE = ft_constants.OPENSTACK_CREDS +OPENSTACK_SNAPSHOT_FILE = ft_constants.OPENSTACK_SNAPSHOT_FILE class CliOpenStack: def __init__(self): - self.os_auth_url = os.getenv('OS_AUTH_URL') + self.os_auth_url = ft_constants.OS_AUTH_URL self.endpoint_ip = None self.endpoint_port = None if self.os_auth_url is not None: @@ -51,7 +49,7 @@ class CliOpenStack: click.echo("{}={}".format(key, value)) def fetch_credentials(self): - if os.path.isfile(RC_FILE): + if os.path.isfile(OPENSTACK_RC_FILE): answer = raw_input("It seems the RC file is already present. " "Do you want to overwrite it? [y|n]\n") while True: @@ -62,29 +60,30 @@ class CliOpenStack: else: answer = raw_input("Invalid answer. Please type [y|n]\n") - CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE') + CI_INSTALLER_TYPE = ft_constants.CI_INSTALLER_TYPE if CI_INSTALLER_TYPE is None: click.echo("The environment variable 'INSTALLER_TYPE' is not" "defined. Please export it") - CI_INSTALLER_IP = os.getenv('INSTALLER_IP') + CI_INSTALLER_IP = ft_constants.CI_INSTALLER_IP if CI_INSTALLER_IP is None: click.echo("The environment variable 'INSTALLER_IP' is not" "defined. Please export it") - cmd = ("/home/opnfv/repos/releng/utils/fetch_os_creds.sh " - "-d %s -i %s -a %s" - % (RC_FILE, CI_INSTALLER_TYPE, CI_INSTALLER_IP)) + cmd = ft_constants.REPOS_DIR + \ + ("/releng/utils/fetch_os_creds.sh " + "-d %s -i %s -a %s" + % (OPENSTACK_RC_FILE, CI_INSTALLER_TYPE, CI_INSTALLER_IP)) click.echo("Fetching credentials from installer node '%s' with IP=%s.." % (CI_INSTALLER_TYPE, CI_INSTALLER_IP)) ft_utils.execute_command(cmd, verbose=False) def check(self): self.ping_endpoint() - cmd = ft_utils.FUNCTEST_REPO + "/functest/ci/check_os.sh" + cmd = ft_constants.FUNCTEST_REPO_DIR + "/functest/ci/check_os.sh" ft_utils.execute_command(cmd, verbose=False) def snapshot_create(self): self.ping_endpoint() - if os.path.isfile(OS_SNAPSHOT_FILE): + if os.path.isfile(OPENSTACK_SNAPSHOT_FILE): answer = raw_input("It seems there is already an OpenStack " "snapshot. Do you want to overwrite it with " "the current OpenStack status? [y|n]\n") @@ -100,18 +99,18 @@ class CliOpenStack: os_snapshot.main() def snapshot_show(self): - if not os.path.isfile(OS_SNAPSHOT_FILE): + if not os.path.isfile(OPENSTACK_SNAPSHOT_FILE): click.echo("There is no OpenStack snapshot created. To create " "one run the command " "'functest openstack snapshot-create'") return - with open(OS_SNAPSHOT_FILE, 'r') as yaml_file: + with open(OPENSTACK_SNAPSHOT_FILE, 'r') as yaml_file: click.echo("\n%s" % yaml_file.read()) def clean(self): self.ping_endpoint() - if not os.path.isfile(OS_SNAPSHOT_FILE): + if not os.path.isfile(OPENSTACK_SNAPSHOT_FILE): click.echo("Not possible to clean OpenStack without a snapshot. " "This could cause problems. " "Run first the command " -- cgit 1.2.3-korg