Merge "Refactor core VNF class"
[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
13 from functest.cli.commands.cli_env import CliEnv
14 from functest.cli.commands.cli_os import CliOpenStack
15 from functest.cli.commands.cli_testcase import CliTestcase
16 from functest.cli.commands.cli_tier import CliTier
17 from functest.utils.constants import CONST
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(
27         CONST.__getattribute__('dir_functest_logging_cfg'))
28
29
30 _env = CliEnv()
31 _openstack = CliOpenStack()
32 _testcase = CliTestcase()
33 _tier = CliTier()
34
35
36 @cli.group()
37 @click.pass_context
38 def env(ctx):
39     pass
40
41
42 @cli.group()
43 @click.pass_context
44 def openstack(ctx):
45     pass
46
47
48 @cli.group()
49 @click.pass_context
50 def testcase(ctx):
51     pass
52
53
54 @cli.group()
55 @click.pass_context
56 def tier(ctx):
57     pass
58
59
60 @openstack.command('check', help="Checks connectivity and status "
61                    "to the OpenStack deployment.")
62 def os_check():
63     _openstack.check()
64
65
66 @openstack.command('snapshot-create', help="Generates a snapshot of the "
67                    "current OpenStack resources.")
68 def os_snapshot_create():
69     _openstack.snapshot_create()
70
71
72 @openstack.command('snapshot-show', help="Prints the OpenStack snapshot.")
73 def os_snapshot_show():
74     _openstack.snapshot_show()
75
76
77 @openstack.command('clean',
78                    help="Cleans the OpenStack resources except the snapshot.")
79 def os_clean():
80     _openstack.clean()
81
82
83 @openstack.command('show-credentials',
84                    help="Prints the OpenStack credentials.")
85 def os_show_credentials():
86     _openstack.show_credentials()
87
88
89 @env.command('prepare', help="Prepares the Functest environment. This step is "
90              "needed run the tests.")
91 def env_prepare():
92     _env.prepare()
93
94
95 @env.command('show', help="Shows information about the current environment.")
96 def env_show():
97     _env.show()
98
99
100 @env.command('status', help="Checks if the Functest environment is ready to "
101              "run the tests.")
102 def env_status():
103     _env.status()
104
105
106 @testcase.command('list', help="Lists the available testcases.")
107 def testcase_list():
108     _testcase.list()
109
110
111 @testcase.command('show', help="Shows information about a test case.")
112 @click.argument('testname', type=click.STRING, required=True)
113 def testcase_show(testname):
114     _testcase.show(testname)
115
116
117 @testcase.command('run', help="Executes a test case.")
118 @click.argument('testname', type=click.STRING, required=True)
119 @click.option('-n', '--noclean', is_flag=True, default=False,
120               help='The created openstack resources by the test'
121               'will not be cleaned after the execution.')
122 @click.option('-r', '--report', is_flag=True, default=False,
123               help='Push results to the results DataBase. Only CI Pods'
124               'have rights to do that.')
125 def testcase_run(testname, noclean, report):
126     _testcase.run(testname, noclean, report)
127
128
129 @tier.command('list', help="Lists the available tiers.")
130 def tier_list():
131     _tier.list()
132
133
134 @tier.command('show', help="Shows information about a tier.")
135 @click.argument('tiername', type=click.STRING, required=True)
136 def tier_show(tiername):
137     _tier.show(tiername)
138
139
140 @tier.command('get-tests', help="Prints the tests in a tier.")
141 @click.argument('tiername', type=click.STRING, required=True)
142 def tier_gettests(tiername):
143     _tier.gettests(tiername)
144
145
146 @tier.command('run', help="Executes all the tests within a tier.")
147 @click.argument('tiername', type=click.STRING, required=True)
148 @click.option('-n', '--noclean', is_flag=True, default=False,
149               help='The created openstack resources by the tests'
150               'will not be cleaned after the execution.')
151 @click.option('-r', '--report', is_flag=True, default=False,
152               help='Push results to the results DataBase. Only CI Pods'
153               'have rights to do that.')
154 def tier_run(tiername, noclean, report):
155     _tier.run(tiername, noclean, report)