aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYujun Zhang <zhang.yujunz@zte.com.cn>2017-05-31 02:59:05 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-05-31 02:59:05 +0000
commit0f1847e312fca1366b14946ad9815b1e1d96e7ea (patch)
tree1ce37138170a1b40c918170c518aae3a6f854211
parenta2fbfdbdea5ad9c2b36d195d0dbff43263304f5a (diff)
parent995f6b5104fa65d95993eebb714bc2b018b85d0f (diff)
Merge "Pass on all unhandled options"
-rw-r--r--qtip/cli/commands/cmd_project.py24
-rw-r--r--qtip/runner/project.py17
-rw-r--r--tests/unit/cli/cmd_project_test.py37
3 files changed, 63 insertions, 15 deletions
diff --git a/qtip/cli/commands/cmd_project.py b/qtip/cli/commands/cmd_project.py
index eefabfc0..f7ac3a83 100644
--- a/qtip/cli/commands/cmd_project.py
+++ b/qtip/cli/commands/cmd_project.py
@@ -15,6 +15,9 @@ from qtip.cli import utils
from qtip.runner import project
+CONTEXT_SETTINGS = dict(ignore_unknown_options=True, allow_extra_args=True, )
+
+
class AliasedGroup(click.Group):
def get_command(self, ctx, cmd_name):
@@ -72,16 +75,19 @@ def create(pod, installer, master_host, scenario, name, template):
extra_vars=utils.join_vars(**extra_vars)))
-@cli.command(help='Setup testing environment')
-def setup():
- project.setup()
+@cli.command(context_settings=CONTEXT_SETTINGS, help='Setup testing environment')
+@click.pass_context
+def setup(ctx):
+ project.setup(ctx.args)
-@cli.command(help='Execute testing plan')
-def run():
- project.run()
+@cli.command(context_settings=CONTEXT_SETTINGS, help='Execute testing plan')
+@click.pass_context
+def run(ctx):
+ project.run(ctx.args)
-@cli.command(help='Teardown testing environment')
-def teardown():
- project.teardown()
+@cli.command(context_settings=CONTEXT_SETTINGS, help='Teardown testing environment')
+@click.pass_context
+def teardown(ctx):
+ project.teardown(ctx.args)
diff --git a/qtip/runner/project.py b/qtip/runner/project.py
index 9eadc9db..90d1e079 100644
--- a/qtip/runner/project.py
+++ b/qtip/runner/project.py
@@ -10,13 +10,18 @@
import os
-def setup():
- os.system('ansible-playbook setup.yml')
+def convert(vals):
+ if vals:
+ return " ".join(vals)
-def run():
- os.system('ansible-playbook run.yml')
+def setup(extra_val=None):
+ os.system('ansible-playbook setup.yml {}'.format(convert(extra_val)))
-def teardown():
- os.system('ansible-playbook teardown.yml')
+def run(extra_val=None):
+ os.system('ansible-playbook run.yml {}'.format(convert(extra_val)))
+
+
+def teardown(extra_val=None):
+ os.system('ansible-playbook teardown.yml {}'.format(convert(extra_val)))
diff --git a/tests/unit/cli/cmd_project_test.py b/tests/unit/cli/cmd_project_test.py
new file mode 100644
index 00000000..8b9216fa
--- /dev/null
+++ b/tests/unit/cli/cmd_project_test.py
@@ -0,0 +1,37 @@
+###############################################################
+# 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
+##############################################################################
+
+from click.testing import CliRunner
+import os
+import pytest
+
+from qtip.cli.entry import cli
+
+
+@pytest.fixture(scope='module')
+def runner():
+ return CliRunner()
+
+
+def test_run(mocker, runner):
+ mocker.patch('os.system')
+ runner.invoke(cli, ['run', '-vvv'])
+ os.system.assert_called_once_with('ansible-playbook run.yml -vvv')
+
+
+def test_setup(mocker, runner):
+ mocker.patch('os.system')
+ runner.invoke(cli, ['setup', '-vvv'])
+ os.system.assert_called_once_with('ansible-playbook setup.yml -vvv')
+
+
+def test_teardown(mocker, runner):
+ mocker.patch('os.system')
+ runner.invoke(cli, ['teardown', '-vvv'])
+ os.system.assert_called_once_with('ansible-playbook teardown.yml -vvv')