Merge "Refactor resource creation and cleanup in rally"
[functest.git] / functest / cli / cli_base.py
1 #!/usr/bin/env python
2 #
3 # jose.lausuch@ericsson.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9
10 import click
11 import logging.config
12 import pkg_resources
13
14 from functest.cli.commands.cli_env import CliEnv
15 from functest.cli.commands.cli_os import CliOpenStack
16 from functest.cli.commands.cli_testcase import CliTestcase
17 from functest.cli.commands.cli_tier import CliTier
18
19
20 CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
21
22
23 @click.group(context_settings=CONTEXT_SETTINGS)
24 @click.version_option(version='opnfv colorado.0.1 ')
25 def cli():
26     logging.config.fileConfig(pkg_resources.resource_filename(
27         'functest', 'ci/logging.ini'))
28     logging.captureWarnings(True)
29
30
31 _env = CliEnv()
32 _openstack = CliOpenStack()
33 _testcase = CliTestcase()
34 _tier = CliTier()
35
36
37 @cli.group()
38 @click.pass_context
39 def env(ctx):
40     pass
41
42
43 @cli.group()
44 @click.pass_context
45 def openstack(ctx):
46     pass
47
48
49 @cli.group()
50 @click.pass_context
51 def testcase(ctx):
52     pass
53
54
55 @cli.group()
56 @click.pass_context
57 def tier(ctx):
58     pass
59
60
61 @openstack.command('check', help="Checks connectivity and status "
62                    "to the OpenStack deployment.")
63 def os_check():
64     _openstack.check()
65
66
67 @openstack.command('snapshot-create', help="Generates a snapshot of the "
68                    "current OpenStack resources.")
69 def os_snapshot_create():
70     _openstack.snapshot_create()
71
72
73 @openstack.command('snapshot-show', help="Prints the OpenStack snapshot.")
74 def os_snapshot_show():
75     _openstack.snapshot_show()
76
77
78 @openstack.command('clean',
79                    help="Cleans the OpenStack resources except the snapshot.")
80 def os_clean():
81     _openstack.clean()
82
83
84 @openstack.command('show-credentials',
85                    help="Prints the OpenStack credentials.")
86 def os_show_credentials():
87     _openstack.show_credentials()
88
89
90 @env.command('prepare', help="Prepares the Functest environment. This step is "
91              "needed run the tests.")
92 def env_prepare():
93     _env.prepare()
94
95
96 @env.command('show', help="Shows information about the current environment.")
97 def env_show():
98     _env.show()
99
100
101 @env.command('status', help="Checks if the Functest environment is ready to "
102              "run the tests.")
103 def env_status():
104     _env.status()
105
106
107 @testcase.command('list', help="Lists the available testcases.")
108 def testcase_list():
109     _testcase.list()
110
111
112 @testcase.command('show', help="Shows information about a test case.")
113 @click.argument('testname', type=click.STRING, required=True)
114 def testcase_show(testname):
115     _testcase.show(testname)
116
117
118 @testcase.command('run', help="Executes a test case.")
119 @click.argument('testname', type=click.STRING, required=True)
120 @click.option('-n', '--noclean', is_flag=True, default=False,
121               help='The created openstack resources by the test'
122               'will not be cleaned after the execution.')
123 @click.option('-r', '--report', is_flag=True, default=False,
124               help='Push results to the results DataBase. Only CI Pods'
125               'have rights to do that.')
126 def testcase_run(testname, noclean, report):
127     _testcase.run(testname, noclean, report)
128
129
130 @tier.command('list', help="Lists the available tiers.")
131 def tier_list():
132     _tier.list()
133
134
135 @tier.command('show', help="Shows information about a tier.")
136 @click.argument('tiername', type=click.STRING, required=True)
137 def tier_show(tiername):
138     _tier.show(tiername)
139
140
141 @tier.command('get-tests', help="Prints the tests in a tier.")
142 @click.argument('tiername', type=click.STRING, required=True)
143 def tier_gettests(tiername):
144     _tier.gettests(tiername)
145
146
147 @tier.command('run', help="Executes all the tests within a tier.")
148 @click.argument('tiername', type=click.STRING, required=True)
149 @click.option('-n', '--noclean', is_flag=True, default=False,
150               help='The created openstack resources by the tests'
151               'will not be cleaned after the execution.')
152 @click.option('-r', '--report', is_flag=True, default=False,
153               help='Push results to the results DataBase. Only CI Pods'
154               'have rights to do that.')
155 def tier_run(tiername, noclean, report):
156     _tier.run(tiername, noclean, report)