Fixing some more copyright dates
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / rapid / rapid_cli.py
1 #!/usr/bin/python
2
3 ##
4 ## Copyright (c) 2020 Intel Corporation
5 ##
6 ## Licensed under the Apache License, Version 2.0 (the "License");
7 ## you may not use this file except in compliance with the License.
8 ## You may obtain a copy of the License at
9 ##
10 ##     http://www.apache.org/licenses/LICENSE-2.0
11 ##
12 ## Unless required by applicable law or agreed to in writing, software
13 ## distributed under the License is distributed on an "AS IS" BASIS,
14 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ## See the License for the specific language governing permissions and
16 ## limitations under the License.
17 ##
18
19 import getopt
20 import sys
21
22 class RapidCli(object):
23     """
24     Class to deal with runrapid cli
25     """
26     @staticmethod
27     def usage(test_params):
28         print("usage: runrapid    [--version] [-v]")
29         print("                   [--env ENVIRONMENT_NAME]")
30         print("                   [--test TEST_NAME]")
31         print("                   [--map MACHINE_MAP_FILE]")
32         print("                   [--runtime TIME_FOR_TEST]")
33         print("                   [--configonly False|True]")
34         print("                   [--log DEBUG|INFO|WARNING|ERROR|CRITICAL]")
35         print("                   [-h] [--help]")
36         print("")
37         print("Command-line interface to runrapid")
38         print("")
39         print("optional arguments:")
40         print("  -v,  --version         Show program's version number and exit")
41         print("  --env ENVIRONMENT_NAME Parameters will be read from ENVIRONMENT_NAME. Default is %s."%test_params['environment_file'])
42         print("  --test TEST_NAME       Test cases will be read from TEST_NAME. Default is %s."%test_params['test_file'])
43         print("  --map MACHINE_MAP_FILE Machine mapping will be read from MACHINE_MAP_FILE. Default is %s."%test_params['machine_map_file'])
44         print("  --runtime              Specify time in seconds for 1 test run")
45         print("  --configonly           If this option is specified, only upload all config files to the VMs, do not run the tests")
46         print("  --log                  Specify logging level for log file output, default is DEBUG")
47         print("  --screenlog            Specify logging level for screen output, default is INFO")
48         print("  -h, --help             Show help message and exit.")
49         print("")
50
51     @staticmethod
52     def process_cli(test_params):
53         try:
54             opts, args = getopt.getopt(sys.argv[1:], "vh", ["version","help", "env=", "test=", "map=", "runtime=","configonly","log=","screenlog="])
55         except getopt.GetoptError as err:
56             print("===========================================")
57             print(str(err))
58             print("===========================================")
59             RapidCli.usage(test_params)
60             sys.exit(2)
61         if args:
62             RapidCli.usage(test_params)
63             sys.exit(2)
64         for opt, arg in opts:
65             if opt in ["-h", "--help"]:
66                 RapidCli.usage(test_params)
67                 sys.exit()
68             if opt in ["-v", "--version"]:
69                 print("Rapid Automated Performance Indication for Dataplane "+test_params['version'])
70                 sys.exit()
71             if opt in ["--env"]:
72                 test_params['environment_file'] = arg
73             if opt in ["--test"]:
74                 test_params['test_file'] = arg
75             if opt in ["--map"]:
76                 test_params['machine_map_file'] = arg
77             if opt in ["--runtime"]:
78                 test_params['runtime'] = int(arg)
79             if opt in ["--configonly"]:
80                 test_params['configonly'] = True
81                 print('No actual runs, only uploading configuration files')
82             if opt in ["--log"]:
83                 test_params['loglevel'] = arg
84                 print ("Log level: "+ test_params['loglevel'])
85             if opt in ["--screenlog"]:
86                 test_params['screenloglevel'] = arg
87                 print ("Screen Log level: "+ test_params['screenloglevel'])
88         print ("Using '"+test_params['environment_file']+"' as name for the environment")
89         print ("Using '"+test_params['test_file']+"' for test case definition")
90         print ("Using '"+test_params['machine_map_file']+"' for machine mapping")
91         print ("Runtime: "+ str(test_params['runtime']))
92         return(test_params)