Support packets in flight
[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("  --map INDEX_LIST       This parameter can also be a list of indices, e.g. [2,3]")
45         print("  --runtime              Specify time in seconds for 1 test run")
46         print("  --configonly           If this option is specified, only upload all config files to the VMs, do not run the tests")
47         print("  --log                  Specify logging level for log file output, default is DEBUG")
48         print("  --screenlog            Specify logging level for screen output, default is INFO")
49         print("  -h, --help             Show help message and exit.")
50         print("")
51
52     @staticmethod
53     def process_cli(test_params):
54         try:
55             opts, args = getopt.getopt(sys.argv[1:], "vh", ["version","help", "env=", "test=", "map=", "runtime=","configonly","log=","screenlog="])
56         except getopt.GetoptError as err:
57             print("===========================================")
58             print(str(err))
59             print("===========================================")
60             RapidCli.usage(test_params)
61             sys.exit(2)
62         if args:
63             RapidCli.usage(test_params)
64             sys.exit(2)
65         for opt, arg in opts:
66             if opt in ["-h", "--help"]:
67                 RapidCli.usage(test_params)
68                 sys.exit()
69             if opt in ["-v", "--version"]:
70                 print("Rapid Automated Performance Indication for Dataplane "+test_params['version'])
71                 sys.exit()
72             if opt in ["--env"]:
73                 test_params['environment_file'] = arg
74             if opt in ["--test"]:
75                 test_params['test_file'] = arg
76             if opt in ["--map"]:
77                 test_params['machine_map_file'] = arg
78             if opt in ["--runtime"]:
79                 test_params['runtime'] = int(arg)
80             if opt in ["--configonly"]:
81                 test_params['configonly'] = True
82                 print('No actual runs, only uploading configuration files')
83             if opt in ["--log"]:
84                 test_params['loglevel'] = arg
85                 print ("Log level: "+ test_params['loglevel'])
86             if opt in ["--screenlog"]:
87                 test_params['screenloglevel'] = arg
88                 print ("Screen Log level: "+ test_params['screenloglevel'])
89         print ("Using '"+test_params['environment_file']+"' as name for the environment")
90         print ("Using '"+test_params['test_file']+"' for test case definition")
91         print ("Using '"+test_params['machine_map_file']+"' for machine mapping")
92         print ("Runtime: "+ str(test_params['runtime']))
93         return(test_params)