1e6818e65443c4739f2eade2d523b91655469a43
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / rapid / runrapid.py
1 #!/usr/bin/python
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         RapidLog.log_init(test_params)
50         test_params = RapidConfigParser.parse_config(test_params)
51         RapidLog.debug(test_params)
52         monitor_gen = monitor_sut = False
53         background_machines = []
54         sut_machine = gen_machine = None
55         machines = []
56         for machine_params in test_params['machines']:
57             if 'gencores' in machine_params.keys():
58                 machine = RapidGeneratorMachine(test_params['key'], test_params['user'], test_params['vim_type'], test_params['rundir'], machine_params)
59                 if machine_params['monitor']:
60                     if monitor_gen:
61                         RapidLog.exception("Can only monitor 1 generator")
62                         raise Exception("Can only monitor 1 generator")
63                     else:
64                         monitor_gen = True
65                         gen_machine = machine
66                 else:
67                     background_machines.append(machine)
68             else:
69                 machine = RapidMachine(test_params['key'], test_params['user'], test_params['vim_type'], test_params['rundir'], machine_params)
70                 if machine_params['monitor']:
71                     if monitor_sut:
72                         RapidLog.exception("Can only monitor 1 sut")
73                         raise Exception("Can only monitor 1 sut")
74                     else:
75                         monitor_sut = True
76                         sut_machine = machine
77             machines.append(machine)
78         if test_params['configonly']:
79             sys.exit()
80         for machine in machines:
81             machine.start_prox()
82         result = True
83         for test_param in test_params['tests']:
84             RapidLog.info(test_param['test'])
85             if test_param['test'] in ['flowsizetest', 'TST009test', 'fixed_rate']:
86                 test = FlowSizeTest(test_param, test_params['lat_percentile'],
87                         test_params['runtime'], test_params['pushgateway'],
88                         test_params['environment_file'], gen_machine,
89                         sut_machine, background_machines)
90             elif test_param['test'] in ['corestats']:
91                 test = CoreStatsTest(test_params['runtime'],
92                         test_params['pushgateway'],
93                         test_params['environment_file'], machines)
94             elif test_param['test'] in ['portstats']:
95                 test = PortStatsTest(test_params['runtime'],
96                         test_params['pushgateway'],
97                         test_params['environment_file'], machines)
98             elif test_param['test'] in ['impairtest']:
99                 test = ImpairTest(test_param, test_params['lat_percentile'],
100                         test_params['runtime'], test_params['pushgateway'],
101                         test_params['environment_file'], gen_machine,
102                         sut_machine)
103             elif test_param['test'] in ['irqtest']:
104                 test = IrqTest(test_params['runtime'], machines)
105             elif test_param['test'] in ['warmuptest']:
106                 test = WarmupTest(test_param, gen_machine)
107             else:
108                 RapidLog.debug('Test name ({}) is not valid:'.format(
109                     test_param['test']))
110             single_test_result = test.run()
111             if not single_test_result:
112                 result = False
113         return (result)
114
115 def main():
116     """Main function.
117     """
118     test_params = RapidDefaults.test_params
119     # When no cli is used, the process_cli can be replaced by code modifying
120     # test_params
121     test_params = RapidCli.process_cli(test_params)
122     test_result = RapidTestManager.run_tests(test_params)
123     RapidLog.info('Test result is : {}'.format(test_result))
124
125 if __name__ == "__main__":
126     main()