Improved IRQ measurements and pushing results
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / rapid / runrapid.py
1 #!/usr/bin/python3
2
3 ##
4 ## Copyright (c) 2010-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 from __future__ import print_function
19 from __future__ import print_function
20 from __future__ import division
21
22 from future import standard_library
23 standard_library.install_aliases()
24 from builtins import object
25 import sys
26 from rapid_cli import RapidCli
27 from rapid_log import RapidLog
28 from rapid_parser import RapidConfigParser
29 from rapid_defaults import RapidDefaults
30 from rapid_machine import RapidMachine
31 from rapid_generator_machine import RapidGeneratorMachine
32 from rapid_flowsizetest import FlowSizeTest
33 from rapid_corestatstest import CoreStatsTest
34 from rapid_portstatstest import PortStatsTest
35 from rapid_impairtest import ImpairTest
36 from rapid_irqtest import IrqTest
37 from rapid_warmuptest import WarmupTest
38
39 class RapidTestManager(object):
40     """
41     RapidTestManager Class
42     """
43     @staticmethod
44     def get_defaults():
45         return (RapidDefaults.test_params)
46
47     @staticmethod
48     def run_tests(test_params):
49         test_params = RapidConfigParser.parse_config(test_params)
50         RapidLog.debug(test_params)
51         monitor_gen = monitor_sut = False
52         background_machines = []
53         sut_machine = gen_machine = None
54         machines = []
55         for machine_params in test_params['machines']:
56             if 'gencores' in machine_params.keys():
57                 machine = RapidGeneratorMachine(test_params['key'],
58                         test_params['user'], test_params['vim_type'],
59                         test_params['rundir'], machine_params)
60                 if machine_params['monitor']:
61                     if monitor_gen:
62                         RapidLog.exception("Can only monitor 1 generator")
63                         raise Exception("Can only monitor 1 generator")
64                     else:
65                         monitor_gen = True
66                         gen_machine = machine
67                 else:
68                     background_machines.append(machine)
69             else:
70                 machine = RapidMachine(test_params['key'], test_params['user'],
71                         test_params['vim_type'], test_params['rundir'],
72                         machine_params)
73                 if machine_params['monitor']:
74                     if monitor_sut:
75                         RapidLog.exception("Can only monitor 1 sut")
76                         raise Exception("Can only monitor 1 sut")
77                     else:
78                         monitor_sut = True
79                         sut_machine = machine
80             machines.append(machine)
81         if test_params['configonly']:
82             sys.exit()
83         for machine in machines:
84             machine.start_prox()
85         result = True
86         for test_param in test_params['tests']:
87             RapidLog.info(test_param['test'])
88             if test_param['test'] in ['flowsizetest', 'TST009test',
89                     'fixed_rate', 'increment_till_fail']:
90                 test = FlowSizeTest(test_param, test_params['lat_percentile'],
91                         test_params['runtime'], 
92                         test_params['TestName'], 
93                         test_params['environment_file'], gen_machine,
94                         sut_machine, background_machines)
95             elif test_param['test'] in ['corestats']:
96                 test = CoreStatsTest(test_param, test_params['runtime'],
97                         test_params['TestName'], 
98                         test_params['environment_file'], machines)
99             elif test_param['test'] in ['portstats']:
100                 test = PortStatsTest(test_param, test_params['runtime'],
101                         test_params['TestName'], 
102                         test_params['environment_file'], machines)
103             elif test_param['test'] in ['impairtest']:
104                 test = ImpairTest(test_param, test_params['lat_percentile'],
105                         test_params['runtime'],
106                         test_params['TestName'], 
107                         test_params['environment_file'], gen_machine,
108                         sut_machine)
109             elif test_param['test'] in ['irqtest']:
110                 test = IrqTest(test_param, test_params['runtime'],
111                         test_params['TestName'], 
112                         test_params['environment_file'], machines)
113             elif test_param['test'] in ['warmuptest']:
114                 test = WarmupTest(test_param, gen_machine)
115             else:
116                 RapidLog.debug('Test name ({}) is not valid:'.format(
117                     test_param['test']))
118             single_test_result = test.run()
119             if not single_test_result:
120                 result = False
121         return (result)
122
123 def main():
124     """Main function.
125     """
126     test_params = RapidTestManager.get_defaults()
127     # When no cli is used, the process_cli can be replaced by code modifying
128     # test_params
129     test_params = RapidCli.process_cli(test_params)
130     log_file = 'RUN{}.{}.log'.format(test_params['environment_file'],
131             test_params['test_file'])
132     RapidLog.log_init(log_file, test_params['loglevel'],
133             test_params['screenloglevel'] , test_params['version']  )
134     test_result = RapidTestManager.run_tests(test_params)
135     RapidLog.info('Test result is : {}'.format(test_result))
136
137 if __name__ == "__main__":
138     main()