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/__init__.py | 0 cli/cli_base.py | 150 ------------------------------------------- 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 --------------------- cli/functest-complete.sh | 8 --- cli/setup.py | 15 ----- 9 files changed, 531 deletions(-) delete mode 100644 cli/__init__.py delete mode 100644 cli/cli_base.py 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 delete mode 100644 cli/functest-complete.sh delete mode 100644 cli/setup.py (limited to 'cli') diff --git a/cli/__init__.py b/cli/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/cli/cli_base.py b/cli/cli_base.py deleted file mode 100644 index 827f8a4b6..000000000 --- a/cli/cli_base.py +++ /dev/null @@ -1,150 +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 click - -from functest.cli.commands.cli_env import CliEnv -from functest.cli.commands.cli_os import CliOpenStack -from functest.cli.commands.cli_testcase import CliTestcase -from functest.cli.commands.cli_tier import CliTier - -CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) - - -@click.group(context_settings=CONTEXT_SETTINGS) -@click.version_option(version='opnfv colorado.0.1 ') -def cli(): - pass - -_env = CliEnv() -_openstack = CliOpenStack() -_testcase = CliTestcase() -_tier = CliTier() - - -@cli.group() -@click.pass_context -def env(ctx): - pass - - -@cli.group() -@click.pass_context -def openstack(ctx): - pass - - -@cli.group() -@click.pass_context -def testcase(ctx): - pass - - -@cli.group() -@click.pass_context -def tier(ctx): - pass - - -@openstack.command('check', help="Checks connectivity and status " - "to the OpenStack deployment.") -def os_check(): - _openstack.check() - - -@openstack.command('snapshot-create', help="Generates a snapshot of the " - "current OpenStack resources.") -def os_snapshot_create(): - _openstack.snapshot_create() - - -@openstack.command('snapshot-show', help="Prints the OpenStack snapshot.") -def os_snapshot_show(): - _openstack.snapshot_show() - - -@openstack.command('clean', - help="Cleans the OpenStack resources except the snapshot.") -def os_clean(): - _openstack.clean() - - -@openstack.command('show-credentials', - help="Prints the OpenStack credentials.") -def os_show_credentials(): - _openstack.show_credentials() - - -@openstack.command('fetch-rc', help="Fetch the OpenStack RC file from " - "the installer.") -def os_fetch_rc(): - _openstack.fetch_credentials() - - -@env.command('prepare', help="Prepares the Functest environment. This step is " - "needed run the tests.") -def env_prepare(): - _env.prepare() - - -@env.command('show', help="Shows information about the current environment.") -def env_show(): - _env.show() - - -@env.command('status', help="Checks if the Functest environment is ready to " - "run the tests.") -def env_status(): - _env.status() - - -@testcase.command('list', help="Lists the available testcases.") -def testcase_list(): - _testcase.list() - - -@testcase.command('show', help="Shows information about a test case.") -@click.argument('testname', type=click.STRING, required=True) -def testcase_show(testname): - _testcase.show(testname) - - -@testcase.command('run', help="Executes a test case.") -@click.argument('testname', type=click.STRING, required=True) -@click.option('-n', '--noclean', is_flag=True, default=False, - help='The created openstack resources by the test' - 'will not be cleaned after the execution.') -def testcase_run(testname, noclean): - _testcase.run(testname, noclean) - - -@tier.command('list', help="Lists the available tiers.") -def tier_list(): - _tier.list() - - -@tier.command('show', help="Shows information about a tier.") -@click.argument('tiername', type=click.STRING, required=True) -def tier_show(tiername): - _tier.show(tiername) - - -@tier.command('get-tests', help="Prints the tests in a tier.") -@click.argument('tiername', type=click.STRING, required=True) -def tier_gettests(tiername): - _tier.gettests(tiername) - - -@tier.command('run', help="Executes all the tests within a tier.") -@click.argument('tiername', type=click.STRING, required=True) -@click.option('-n', '--noclean', is_flag=True, default=False, - help='The created openstack resources by the tests' - 'will not be cleaned after the execution.') -def tier_run(tiername, noclean): - _tier.run(tiername, noclean) diff --git a/cli/commands/__init__.py b/cli/commands/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/cli/commands/cli_env.py b/cli/commands/cli_env.py deleted file mode 100644 index 572012643..000000000 --- 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 2f3f329f3..000000000 --- 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 510d740ba..000000000 --- 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 aa0541981..000000000 --- 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) diff --git a/cli/functest-complete.sh b/cli/functest-complete.sh deleted file mode 100644 index f01490713..000000000 --- a/cli/functest-complete.sh +++ /dev/null @@ -1,8 +0,0 @@ -_functest_completion() { - COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \ - COMP_CWORD=$COMP_CWORD \ - _FUNCTEST_COMPLETE=complete $1 ) ) - return 0 -} - -complete -F _functest_completion -o default functest; diff --git a/cli/setup.py b/cli/setup.py deleted file mode 100644 index 21547e158..000000000 --- a/cli/setup.py +++ /dev/null @@ -1,15 +0,0 @@ -from setuptools import setup - -setup( - name='functest', - version='colorado.0.1', - py_modules=['cli_base'], - include_package_data=True, - install_requires=[ - 'click', - ], - entry_points=''' - [console_scripts] - functest=cli_base:cli - ''', -) -- cgit 1.2.3-korg