summaryrefslogtreecommitdiffstats
path: root/cli/commands/cli_env.py
diff options
context:
space:
mode:
authorjose.lausuch <jose.lausuch@ericsson.com>2016-05-10 11:51:18 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-05-10 11:51:18 +0000
commitacd3d80504a56183a4909dce52b56bc7e15bc6cd (patch)
tree9c656eb5db5813865537cb1f0693564dbc38e32b /cli/commands/cli_env.py
parent7eeab2d73796b1054c20b41329835adc090bbf3c (diff)
parentbd00e6f289a69badf7beea827b20764ed3252c7a (diff)
Merge "CLI implementation"
Diffstat (limited to 'cli/commands/cli_env.py')
-rw-r--r--cli/commands/cli_env.py91
1 files changed, 78 insertions, 13 deletions
diff --git a/cli/commands/cli_env.py b/cli/commands/cli_env.py
index b2570d379..9e6372d4d 100644
--- a/cli/commands/cli_env.py
+++ b/cli/commands/cli_env.py
@@ -8,29 +8,94 @@
#
import click
+import git
+import os
+
+import functest.utils.functest_utils as ft_utils
+
+ENV_FILE = "/home/opnfv/functest/conf/env_active"
+FUNCTEST_REPO = "/home/opnfv/repos/functest/"
class CliEnv:
def __init__(self):
pass
+ def prepare(self):
+ if self.status(verbose=False) == 0:
+ answer = raw_input("It seems that the environment has been "
+ "already prepared. Do you want to do "
+ "it again? [y|n]\n")
+ while True:
+ if answer.lower() in ["y", "yes"]:
+ os.remove(ENV_FILE)
+ break
+ elif answer.lower() in ["n", "no"]:
+ return
+ else:
+ answer = raw_input("Invalid answer. Please type [y|n]\n")
+
+ cmd = ("python /home/opnfv/repos/functest/ci/prepare_env.py start")
+ ft_utils.execute_command(cmd)
+
def show(self):
- click.echo("env show")
+ CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE')
+ if CI_INSTALLER_TYPE is None:
+ CI_INSTALLER_TYPE = "Unknown"
+ CI_INSTALLER_IP = os.getenv('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')
+ if CI_SCENARIO is None:
+ CI_SCENARIO = "Unknown"
+
+ CI_NODE = os.getenv('NODE_NAME')
+ if CI_NODE is None:
+ CI_NODE = "Unknown"
+
+ repo = git.Repo(FUNCTEST_REPO)
+ branch = repo.head.reference
+ GIT_BRANCH = branch.name
+ GIT_HASH = branch.commit.hexsha
- def status(self):
- click.echo("env status")
+ CI_BUILD_TAG = os.getenv('BUILD_TAG')
+ if CI_BUILD_TAG is not None:
+ CI_BUILD_TAG = CI_BUILD_TAG.lstrip(
+ "jenkins-").lstrip("functest").lstrip("-")
- def getrc(self):
- click.echo("env getrc")
+ CI_DEBUG = os.getenv('CI_DEBUG')
+ if CI_DEBUG is None:
+ CI_DEBUG = "false"
- def sourcerc(self):
- click.echo("env sourcerc")
+ STATUS = "not ready"
+ if self.status(verbose=False) == 0:
+ STATUS = "ready"
- def setdefaults(self):
- click.echo("env setdefaults")
+ click.echo("+======================================================+")
+ click.echo("| Functest Environment info |")
+ click.echo("+======================================================+")
+ click.echo("| INSTALLER: %s|" % CI_INSTALLER.ljust(41))
+ click.echo("| SCENARIO: %s|" % CI_SCENARIO.ljust(41))
+ click.echo("| POD: %s|" % CI_NODE.ljust(41))
+ click.echo("| GIT BRACNH: %s|" % GIT_BRANCH.ljust(41))
+ click.echo("| GIT HASH: %s|" % GIT_HASH.ljust(41))
+ if CI_BUILD_TAG:
+ click.echo("| BUILD TAG: %s|" % CI_BUILD_TAG.ljust(41))
+ click.echo("| DEBUG FLAG: %s|" % CI_DEBUG.ljust(41))
+ click.echo("+------------------------------------------------------+")
+ click.echo("| STATUS: %s|" % STATUS.ljust(41))
+ click.echo("+------------------------------------------------------+")
+ click.echo("")
- def getdefaults(self):
- click.echo("env getdefaults")
+ def status(self, verbose=True):
+ ret_val = 0
+ if not os.path.isfile(ENV_FILE):
+ if verbose:
+ click.echo("Functest environment is not installed.\n")
+ ret_val = 1
+ elif verbose:
+ click.echo("Functest environment ready to run tests.\n")
- def clean(self):
- click.echo("env clean")
+ return ret_val