From 426ad7b517f20ff8c77ed69dcd056db7d5278f18 Mon Sep 17 00:00:00 2001 From: Yujun Zhang Date: Sat, 13 May 2017 11:15:49 +0800 Subject: Refactoring workspace related commands to `project` group - renamed `workspace` to `project`, which is more accurate - group create/setup/run/teardown into `project` - shortcut for project commands, e.g. `qtip create` <=> `qtip project create` - even shorter command alias, e.g. `qtip s` => `qtip setup` Change-Id: I69ba5aa571bccc1cc4687481189c329b099bee91 Signed-off-by: Yujun Zhang --- qtip/cli/commands/cmd_project.py | 75 ++++++++++++++++++++++++++++++++++++++ qtip/cli/commands/cmd_run.py | 17 --------- qtip/cli/commands/cmd_setup.py | 17 --------- qtip/cli/commands/cmd_workspace.py | 45 ----------------------- qtip/cli/entry.py | 13 ++++++- qtip/runner/project.py | 22 +++++++++++ 6 files changed, 108 insertions(+), 81 deletions(-) create mode 100644 qtip/cli/commands/cmd_project.py delete mode 100644 qtip/cli/commands/cmd_run.py delete mode 100644 qtip/cli/commands/cmd_setup.py delete mode 100644 qtip/cli/commands/cmd_workspace.py create mode 100644 qtip/runner/project.py (limited to 'qtip') diff --git a/qtip/cli/commands/cmd_project.py b/qtip/cli/commands/cmd_project.py new file mode 100644 index 00000000..0bf7d82f --- /dev/null +++ b/qtip/cli/commands/cmd_project.py @@ -0,0 +1,75 @@ +############################################################################## +# Copyright (c) 2017 taseer94@gmail.com and others. +# +# 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 +import os + +from qtip.cli import utils +from qtip.runner import project + + +class AliasedGroup(click.Group): + + def get_command(self, ctx, cmd_name): + rv = click.Group.get_command(self, ctx, cmd_name) + if rv is not None: + return rv + matches = [x for x in self.list_commands(ctx) + if x.startswith(cmd_name)] + if not matches: + return None + elif len(matches) == 1: + return click.Group.get_command(self, ctx, matches[0]) + ctx.fail('Too many matches: %s' % ', '.join(sorted(matches))) + + +@click.command(cls=AliasedGroup, help="Project commands") +def cli(): + pass + + +@cli.command(help="Create new testing project") +@click.option('--pod', default='unknown', help='Name of pod under test') +@click.option('--installer', help='OPNFV installer', required=True) +@click.option('--master-host', help='Installer hostname', required=True) +@click.option('--scenario', default='unknown', help='OPNFV scenario') +@click.argument('name') +def create(pod, installer, master_host, scenario, name): + extra_vars = { + 'qtip_package': utils.QTIP_PACKAGE, + 'cwd': os.getcwd(), + 'pod_name': pod, + 'installer': installer, + 'scenario': scenario, + 'installer_master_host': master_host, + 'workspace': name + } + os.system("ANSIBLE_ROLES_PATH={qtip_package}/{roles_path} ansible-playbook" + " -i {qtip_package}/{roles_path}/qtip-workspace/hosts" + " {qtip_package}/{roles_path}/qtip-workspace/create.yml" + " --extra-vars '{extra_vars}'" + "".format(qtip_package=utils.QTIP_PACKAGE, + roles_path=utils.ROLES_PATH, + extra_vars=utils.join_vars(**extra_vars))) + + +@cli.command(help='Setup testing environment') +def setup(): + project.setup() + + +@cli.command(help='Execute testing plan') +def run(): + project.run() + + +@cli.command(help='Teardown testing environment') +def teardown(): + project.teardown() diff --git a/qtip/cli/commands/cmd_run.py b/qtip/cli/commands/cmd_run.py deleted file mode 100644 index 56d416ab..00000000 --- a/qtip/cli/commands/cmd_run.py +++ /dev/null @@ -1,17 +0,0 @@ -############################################################################## -# Copyright (c) 2017 taseer94@gmail.com and others. -# -# 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 -import os - - -@click.command('run', help='Run performance tests') -def cli(): - os.system('ansible-playbook {}/run.yml'.format(os.getcwd())) diff --git a/qtip/cli/commands/cmd_setup.py b/qtip/cli/commands/cmd_setup.py deleted file mode 100644 index ac434561..00000000 --- a/qtip/cli/commands/cmd_setup.py +++ /dev/null @@ -1,17 +0,0 @@ -############################################################################## -# Copyright (c) 2017 taseer94@gmail.com and others. -# -# 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 -import os - - -@click.command('setup', help='Setup QTIP workspace') -def cli(): - os.system('ansible-playbook {}/setup.yml'.format(os.getcwd())) diff --git a/qtip/cli/commands/cmd_workspace.py b/qtip/cli/commands/cmd_workspace.py deleted file mode 100644 index a5b6828f..00000000 --- a/qtip/cli/commands/cmd_workspace.py +++ /dev/null @@ -1,45 +0,0 @@ -############################################################################## -# Copyright (c) 2017 taseer94@gmail.com and others. -# -# 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 -import os - -from qtip.cli import utils - - -@click.group() -def cli(): - """ Manage QTIP workspace """ - pass - - -@cli.command("create", help="Create QTIP workspace") -@click.option('--pod', default='unknown', help='Name of pod under test') -@click.option('--installer', help='OPNFV installer', required=True) -@click.option('--master-host', help='Installer hostname', required=True) -@click.option('--scenario', default='unknown', help='OPNFV scenario') -@click.argument('name') -def create(pod, installer, master_host, scenario, name): - extra_vars = { - 'qtip_package': utils.QTIP_PACKAGE, - 'cwd': os.getcwd(), - 'pod_name': pod, - 'installer': installer, - 'scenario': scenario, - 'installer_master_host': master_host, - 'workspace': name - } - os.system("ANSIBLE_ROLES_PATH={qtip_package}/{roles_path} ansible-playbook" - " -i {qtip_package}/{roles_path}/qtip-workspace/hosts" - " {qtip_package}/{roles_path}/qtip-workspace/create.yml" - " --extra-vars '{extra_vars}'" - "".format(qtip_package=utils.QTIP_PACKAGE, - roles_path=utils.ROLES_PATH, - extra_vars=utils.join_vars(**extra_vars))) diff --git a/qtip/cli/entry.py b/qtip/cli/entry.py index b84a03d0..b557047d 100644 --- a/qtip/cli/entry.py +++ b/qtip/cli/entry.py @@ -12,6 +12,7 @@ import os import pkg_resources as pkg import sys +from qtip.cli.commands.cmd_project import cli as project_commands CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) @@ -28,7 +29,7 @@ cmd_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), 'commands')) -class QtipCli(click.MultiCommand): +class SubCommand(click.MultiCommand): def list_commands(self, ctx): rv = [] @@ -50,7 +51,15 @@ class QtipCli(click.MultiCommand): return mod.cli -@click.command(cls=QtipCli, context_settings=CONTEXT_SETTINGS, +@click.command(cls=SubCommand, context_settings=CONTEXT_SETTINGS, + invoke_without_command=True) +def sub_commands(ctx, verbose, debug): + pass + + +@click.command(cls=click.CommandCollection, + help="Platform performance benchmarking", + sources=[sub_commands, project_commands], invoke_without_command=True) @click.option('-v', '--verbose', is_flag=True, help='Enable verbose mode.') @click.option('-d', '--debug', is_flag=True, help='Enable debug mode.') diff --git a/qtip/runner/project.py b/qtip/runner/project.py new file mode 100644 index 00000000..9eadc9db --- /dev/null +++ b/qtip/runner/project.py @@ -0,0 +1,22 @@ +############################################################################## +# Copyright (c) 2017 ZTE corp. and others. +# +# 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 + + +def setup(): + os.system('ansible-playbook setup.yml') + + +def run(): + os.system('ansible-playbook run.yml') + + +def teardown(): + os.system('ansible-playbook teardown.yml') -- cgit 1.2.3-korg