aboutsummaryrefslogtreecommitdiffstats
path: root/functest/cli/commands
diff options
context:
space:
mode:
authorhelenyao <yaohelan@huawei.com>2016-11-21 06:50:06 -0500
committerjose.lausuch <jose.lausuch@ericsson.com>2016-11-24 15:14:45 +0100
commit3e3c96b2aa15d7757f281ce00518a67e2a1225a9 (patch)
tree9b15e0ceab33a9301ca7cde1a0a36e05f2347584 /functest/cli/commands
parent7a776398ef8b17bd9af5367d712707a903c1c86a (diff)
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 <yaohelan@huawei.com>
Diffstat (limited to 'functest/cli/commands')
-rw-r--r--functest/cli/commands/cli_env.py25
-rw-r--r--functest/cli/commands/cli_os.py33
-rw-r--r--functest/cli/commands/cli_testcase.py20
-rw-r--r--functest/cli/commands/cli_tier.py19
4 files changed, 43 insertions, 54 deletions
diff --git a/functest/cli/commands/cli_env.py b/functest/cli/commands/cli_env.py
index d331cc15..9f793e71 100644
--- a/functest/cli/commands/cli_env.py
+++ b/functest/cli/commands/cli_env.py
@@ -13,9 +13,7 @@ import click
import git
import functest.utils.functest_utils as ft_utils
-
-ENV_FILE = "/home/opnfv/functest/conf/env_active"
-FUNCTEST_REPO = ft_utils.FUNCTEST_REPO
+import functest.utils.functest_constants as ft_constants
class CliEnv:
@@ -30,44 +28,45 @@ class CliEnv:
"it again? [y|n]\n")
while True:
if answer.lower() in ["y", "yes"]:
- os.remove(ENV_FILE)
+ os.remove(ft_constants.ENV_FILE)
break
elif answer.lower() in ["n", "no"]:
return
else:
answer = raw_input("Invalid answer. Please type [y|n]\n")
- cmd = ("python %s/functest/ci/prepare_env.py start" % FUNCTEST_REPO)
+ cmd = ("python %s/functest/ci/prepare_env.py start" %
+ ft_constants.FUNCTEST_REPO_DIR)
ft_utils.execute_command(cmd)
def show(self):
- CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE')
+ CI_INSTALLER_TYPE = ft_constants.CI_INSTALLER_TYPE
if CI_INSTALLER_TYPE is None:
CI_INSTALLER_TYPE = "Unknown"
- CI_INSTALLER_IP = os.getenv('INSTALLER_IP')
+ CI_INSTALLER_IP = ft_constants.CI_INSTALLER_IP
if CI_INSTALLER_IP is None:
CI_INSTALLER_IP = "Unknown"
CI_INSTALLER = ("%s, %s" % (CI_INSTALLER_TYPE, CI_INSTALLER_IP))
- CI_SCENARIO = os.getenv('DEPLOY_SCENARIO')
+ CI_SCENARIO = ft_constants.CI_SCENARIO
if CI_SCENARIO is None:
CI_SCENARIO = "Unknown"
- CI_NODE = os.getenv('NODE_NAME')
+ CI_NODE = ft_constants.CI_NODE
if CI_NODE is None:
CI_NODE = "Unknown"
- repo = git.Repo(FUNCTEST_REPO)
+ repo = git.Repo(ft_constants.FUNCTEST_REPO_DIR)
branch = repo.head.reference
GIT_BRANCH = branch.name
GIT_HASH = branch.commit.hexsha
- CI_BUILD_TAG = os.getenv('BUILD_TAG')
+ CI_BUILD_TAG = ft_constants.CI_BUILD_TAG
if CI_BUILD_TAG is not None:
CI_BUILD_TAG = CI_BUILD_TAG.lstrip(
"jenkins-").lstrip("functest").lstrip("-")
- CI_DEBUG = os.getenv('CI_DEBUG')
+ CI_DEBUG = ft_constants.CI_DEBUG
if CI_DEBUG is None:
CI_DEBUG = "false"
@@ -93,7 +92,7 @@ class CliEnv:
def status(self, verbose=True):
ret_val = 0
- if not os.path.isfile(ENV_FILE):
+ if not os.path.isfile(ft_constants.ENV_FILE):
if verbose:
click.echo("Functest environment is not installed.\n")
ret_val = 1
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 "
diff --git a/functest/cli/commands/cli_testcase.py b/functest/cli/commands/cli_testcase.py
index da78ae9c..efe177d5 100644
--- a/functest/cli/commands/cli_testcase.py
+++ b/functest/cli/commands/cli_testcase.py
@@ -16,20 +16,16 @@ import click
import functest.ci.tier_builder as tb
import functest.utils.functest_utils as ft_utils
import functest.utils.functest_vacation as vacation
-
-
-FUNCTEST_CONF_DIR = \
- ft_utils.get_functest_config('general.directories.dir_functest_conf')
-ENV_FILE = FUNCTEST_CONF_DIR + "/env_active"
-FUNCTEST_REPO = ft_utils.FUNCTEST_REPO
+import functest.utils.functest_constants as ft_constants
class CliTestcase:
def __init__(self):
- CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE')
- CI_SCENARIO = os.getenv('DEPLOY_SCENARIO')
- testcases = ft_utils.get_testcases_file()
+ CI_INSTALLER_TYPE = ft_constants.CI_INSTALLER_TYPE
+ CI_SCENARIO = ft_constants.CI_SCENARIO
+ testcases = ft_constants.FUNCTEST_TESTCASES_YAML
+
self.tiers = tb.TierBuilder(CI_INSTALLER_TYPE, CI_SCENARIO, testcases)
def list(self):
@@ -50,14 +46,14 @@ class CliTestcase:
def run(self, testname, noclean=False):
if testname == 'vacation':
vacation.main()
- elif not os.path.isfile(ENV_FILE):
+ elif not os.path.isfile(ft_constants.ENV_FILE):
click.echo("Functest environment is not ready. "
"Run first 'functest env prepare'")
else:
if noclean:
cmd = ("python %s/functest/ci/run_tests.py "
- "-n -t %s" % (FUNCTEST_REPO, testname))
+ "-n -t %s" % (ft_constants.FUNCTEST_REPO_DIR, testname))
else:
cmd = ("python %s/functest/ci/run_tests.py "
- "-t %s" % (FUNCTEST_REPO, testname))
+ "-t %s" % (ft_constants.FUNCTEST_REPO_DIR, testname))
ft_utils.execute_command(cmd)
diff --git a/functest/cli/commands/cli_tier.py b/functest/cli/commands/cli_tier.py
index fa2de587..9da51072 100644
--- a/functest/cli/commands/cli_tier.py
+++ b/functest/cli/commands/cli_tier.py
@@ -15,20 +15,15 @@ import click
import functest.ci.tier_builder as tb
import functest.utils.functest_utils as ft_utils
-
-
-FUNCTEST_CONF_DIR = \
- ft_utils.get_functest_config('general.directories.dir_functest_conf')
-ENV_FILE = FUNCTEST_CONF_DIR + "/env_active"
-FUNCTEST_REPO = ft_utils.FUNCTEST_REPO
+import functest.utils.functest_constants as ft_constants
class CliTier:
def __init__(self):
- CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE')
- CI_SCENARIO = os.getenv('DEPLOY_SCENARIO')
- testcases = ft_utils.get_testcases_file()
+ CI_INSTALLER_TYPE = ft_constants.CI_INSTALLER_TYPE
+ CI_SCENARIO = ft_constants.CI_SCENARIO
+ testcases = ft_constants.FUNCTEST_TESTCASES_YAML
self.tiers = tb.TierBuilder(CI_INSTALLER_TYPE, CI_SCENARIO, testcases)
def list(self):
@@ -60,14 +55,14 @@ class CliTier:
click.echo("Test cases in tier '%s':\n %s\n" % (tiername, tests))
def run(self, tiername, noclean=False):
- if not os.path.isfile(ENV_FILE):
+ if not os.path.isfile(ft_constants.ENV_FILE):
click.echo("Functest environment is not ready. "
"Run first 'functest env prepare'")
else:
if noclean:
cmd = ("python %s/functest/ci/run_tests.py "
- "-n -t %s" % (FUNCTEST_REPO, tiername))
+ "-n -t %s" % (ft_constants.FUNCTEST_REPO_DIR, tiername))
else:
cmd = ("python %s/functest/ci/run_tests.py "
- "-t %s" % (FUNCTEST_REPO, tiername))
+ "-t %s" % (ft_constants.FUNCTEST_REPO_DIR, tiername))
ft_utils.execute_command(cmd)