From 107e61635c2ab1feb5263380ea63e21cf2e6e65b Mon Sep 17 00:00:00 2001 From: Morgan Richomme Date: Tue, 8 Nov 2016 14:18:12 +0100 Subject: Repo structure modification - create functest subdirectory - rename unit tests - adapt path in exec and config files JIRA: FUNCTEST-525 Change-Id: Ifd5c6edfb5bda1b09f82848e2269ad5fbeb84d0a Signed-off-by: Morgan Richomme --- cli/commands/__init__.py | 0 cli/commands/cli_env.py | 102 ------------------------------------ cli/commands/cli_os.py | 120 ------------------------------------------- cli/commands/cli_testcase.py | 63 ----------------------- cli/commands/cli_tier.py | 73 -------------------------- 5 files changed, 358 deletions(-) delete mode 100644 cli/commands/__init__.py delete mode 100644 cli/commands/cli_env.py delete mode 100644 cli/commands/cli_os.py delete mode 100644 cli/commands/cli_testcase.py delete mode 100644 cli/commands/cli_tier.py (limited to 'cli/commands') diff --git a/cli/commands/__init__.py b/cli/commands/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/cli/commands/cli_env.py b/cli/commands/cli_env.py deleted file mode 100644 index 57201264..00000000 --- a/cli/commands/cli_env.py +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env python -# -# jose.lausuch@ericsson.com -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -# - -import os - -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 - - -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 %s/ci/prepare_env.py start" % FUNCTEST_REPO) - ft_utils.execute_command(cmd) - - def show(self): - 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 - - 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("-") - - CI_DEBUG = os.getenv('CI_DEBUG') - if CI_DEBUG is None: - CI_DEBUG = "false" - - STATUS = "not ready" - if self.status(verbose=False) == 0: - STATUS = "ready" - - 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 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") - - return ret_val diff --git a/cli/commands/cli_os.py b/cli/commands/cli_os.py deleted file mode 100644 index 2f3f329f..00000000 --- a/cli/commands/cli_os.py +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env python -# -# jose.lausuch@ericsson.com -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -# - - -import os - -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 - - -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") - - -class CliOpenStack: - - def __init__(self): - self.os_auth_url = os.getenv('OS_AUTH_URL') - self.endpoint_ip = None - self.endpoint_port = None - if self.os_auth_url is not None: - self.endpoint_ip = self.os_auth_url.rsplit("/")[2].rsplit(":")[0] - self.endpoint_port = self.os_auth_url.rsplit("/")[2].rsplit(":")[1] - - def ping_endpoint(self): - if self.os_auth_url is None: - click.echo("Source the OpenStack credentials first '. $creds'") - exit(0) - response = os.system("ping -c 1 " + self.endpoint_ip + ">/dev/null") - if response == 0: - return 0 - else: - click.echo("Cannot talk to the endpoint %s\n" % self.endpoint_ip) - exit(0) - - def show_credentials(self): - for key, value in os.environ.items(): - if key.startswith('OS_'): - click.echo("{}={}".format(key, value)) - - def fetch_credentials(self): - if os.path.isfile(RC_FILE): - answer = raw_input("It seems the RC file is already present. " - "Do you want to overwrite it? [y|n]\n") - while True: - if answer.lower() in ["y", "yes"]: - break - elif answer.lower() in ["n", "no"]: - return - else: - answer = raw_input("Invalid answer. Please type [y|n]\n") - - CI_INSTALLER_TYPE = os.getenv('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') - 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)) - 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 + "/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): - 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") - while True: - if answer.lower() in ["y", "yes"]: - break - elif answer.lower() in ["n", "no"]: - return - else: - answer = raw_input("Invalid answer. Please type [y|n]\n") - - click.echo("Generating Openstack snapshot...") - os_snapshot.main() - - def snapshot_show(self): - if not os.path.isfile(OS_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: - click.echo("\n%s" - % yaml_file.read()) - - def clean(self): - self.ping_endpoint() - if not os.path.isfile(OS_SNAPSHOT_FILE): - click.echo("Not possible to clean OpenStack without a snapshot. " - "This could cause problems. " - "Run first the command " - "'functest openstack snapshot-create'") - return - os_clean.main() diff --git a/cli/commands/cli_testcase.py b/cli/commands/cli_testcase.py deleted file mode 100644 index 510d740b..00000000 --- a/cli/commands/cli_testcase.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env python -# -# jose.lausuch@ericsson.com -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -# - -""" global variables """ - -import os - -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 - - -class CliTestcase: - - def __init__(self): - CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE') - CI_SCENARIO = os.getenv('DEPLOY_SCENARIO') - testcases = ft_utils.get_testcases_file() - self.tiers = tb.TierBuilder(CI_INSTALLER_TYPE, CI_SCENARIO, testcases) - - def list(self): - summary = "" - for tier in self.tiers.get_tiers(): - for test in tier.get_tests(): - summary += (" %s\n" % test.get_name()) - click.echo(summary) - - def show(self, testname): - description = self.tiers.get_test(testname) - if description is None: - click.echo("The test case '%s' does not exist or is not supported." - % testname) - - click.echo(description) - - def run(self, testname, noclean=False): - if testname == 'vacation': - vacation.main() - elif not os.path.isfile(ENV_FILE): - click.echo("Functest environment is not ready. " - "Run first 'functest env prepare'") - else: - if noclean: - cmd = ("python %s/ci/run_tests.py " - "-n -t %s" % (FUNCTEST_REPO, testname)) - else: - cmd = ("python %s/ci/run_tests.py " - "-t %s" % (FUNCTEST_REPO, testname)) - ft_utils.execute_command(cmd) diff --git a/cli/commands/cli_tier.py b/cli/commands/cli_tier.py deleted file mode 100644 index aa054198..00000000 --- a/cli/commands/cli_tier.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python -# -# jose.lausuch@ericsson.com -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -# - -""" global variables """ - -import os - -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 - - -class CliTier: - - def __init__(self): - CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE') - CI_SCENARIO = os.getenv('DEPLOY_SCENARIO') - testcases = ft_utils.get_testcases_file() - self.tiers = tb.TierBuilder(CI_INSTALLER_TYPE, CI_SCENARIO, testcases) - - def list(self): - summary = "" - for tier in self.tiers.get_tiers(): - summary += (" - %s. %s:\n\t %s\n" - % (tier.get_order(), - tier.get_name(), - tier.get_test_names())) - click.echo(summary) - - def show(self, tiername): - tier = self.tiers.get_tier(tiername) - if tier is None: - tier_names = self.tiers.get_tier_names() - click.echo("The tier with name '%s' does not exist. " - "Available tiers are:\n %s\n" % (tiername, tier_names)) - else: - click.echo(self.tiers.get_tier(tiername)) - - def gettests(self, tiername): - tier = self.tiers.get_tier(tiername) - if tier is None: - tier_names = self.tiers.get_tier_names() - click.echo("The tier with name '%s' does not exist. " - "Available tiers are:\n %s\n" % (tiername, tier_names)) - else: - tests = tier.get_test_names() - 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): - click.echo("Functest environment is not ready. " - "Run first 'functest env prepare'") - else: - if noclean: - cmd = ("python %s/ci/run_tests.py " - "-n -t %s" % (FUNCTEST_REPO, tiername)) - else: - cmd = ("python %s/ci/run_tests.py " - "-t %s" % (FUNCTEST_REPO, tiername)) - ft_utils.execute_command(cmd) -- cgit 1.2.3-korg