aboutsummaryrefslogtreecommitdiffstats
path: root/qtip/cli/commands/cmd_project.py
diff options
context:
space:
mode:
authorYujun Zhang <zhang.yujunz@zte.com.cn>2017-05-13 11:15:49 +0800
committerYujun Zhang <zhang.yujunz@zte.com.cn>2017-05-15 15:16:10 +0000
commit426ad7b517f20ff8c77ed69dcd056db7d5278f18 (patch)
tree57518b7531da0ebfa6ea6436ea14c91d947abf6c /qtip/cli/commands/cmd_project.py
parent284cc6fe24375ad6d32cc567d0c64eedc1a4f4b7 (diff)
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 <zhang.yujunz@zte.com.cn>
Diffstat (limited to 'qtip/cli/commands/cmd_project.py')
-rw-r--r--qtip/cli/commands/cmd_project.py75
1 files changed, 75 insertions, 0 deletions
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()