Support dataplane subnet mask & latency histogram
[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 import concurrent.futures
27 from concurrent.futures import ALL_COMPLETED
28 from rapid_cli import RapidCli
29 from rapid_log import RapidLog
30 from rapid_parser import RapidConfigParser
31 from rapid_defaults import RapidDefaults
32 from rapid_machine import RapidMachine
33 from rapid_generator_machine import RapidGeneratorMachine
34 from rapid_flowsizetest import FlowSizeTest
35 from rapid_corestatstest import CoreStatsTest
36 from rapid_portstatstest import PortStatsTest
37 from rapid_impairtest import ImpairTest
38 from rapid_irqtest import IrqTest
39 from rapid_warmuptest import WarmupTest
40
41 class RapidTestManager(object):
42     """
43     RapidTestManager Class
44     """
45     def __del__(self):
46         for machine in self.machines:
47             machine.close_prox()
48
49     @staticmethod
50     def get_defaults():
51         return (RapidDefaults.test_params)
52
53     def run_tests(self, test_params):
54         test_params = RapidConfigParser.parse_config(test_params)
55         RapidLog.debug(test_params)
56         monitor_gen = monitor_sut = False
57         background_machines = []
58         sut_machine = gen_machine = None
59         self.machines = []
60         configonly = test_params['configonly']
61         for machine_params in test_params['machines']:
62             if 'gencores' in machine_params.keys():
63                 machine = RapidGeneratorMachine(test_params['key'],
64                         test_params['user'], test_params['vim_type'],
65                         test_params['rundir'], machine_params,
66                         configonly, test_params['ipv6'])
67                 if machine_params['monitor']:
68                     if monitor_gen:
69                         RapidLog.exception("Can only monitor 1 generator")
70                         raise Exception("Can only monitor 1 generator")
71                     else:
72                         monitor_gen = True
73                         gen_machine = machine
74                 else:
75                     background_machines.append(machine)
76             else:
77                 machine = RapidMachine(test_params['key'], test_params['user'],
78                         test_params['vim_type'], test_params['rundir'],
79                         machine_params, configonly)
80                 if machine_params['monitor']:
81                     if monitor_sut:
82                         RapidLog.exception("Can only monitor 1 sut")
83                         raise Exception("Can only monitor 1 sut")
84                     else:
85                         monitor_sut = True
86                         if machine_params['prox_socket']:
87                             sut_machine = machine
88             self.machines.append(machine)
89         prox_executor = concurrent.futures.ThreadPoolExecutor(max_workers=len(self.machines))
90         self.future_to_prox = {prox_executor.submit(machine.start_prox): machine for machine in self.machines}
91         if configonly:
92             concurrent.futures.wait(self.future_to_prox,return_when=ALL_COMPLETED)
93             sys.exit()
94         with concurrent.futures.ThreadPoolExecutor(max_workers=len(self.machines)) as executor:
95             future_to_connect_prox = {executor.submit(machine.connect_prox): machine for machine in self.machines}
96             concurrent.futures.wait(future_to_connect_prox,return_when=ALL_COMPLETED)
97         result = True
98         for test_param in test_params['tests']:
99             RapidLog.info(test_param['test'])
100             if test_param['test'] in ['flowsizetest', 'TST009test',
101                     'fixed_rate', 'increment_till_fail']:
102                 test = FlowSizeTest(test_param, test_params['lat_percentile'],
103                         test_params['runtime'], 
104                         test_params['TestName'], 
105                         test_params['environment_file'], gen_machine,
106                         sut_machine, background_machines)
107             elif test_param['test'] in ['corestats']:
108                 test = CoreStatsTest(test_param, test_params['runtime'],
109                         test_params['TestName'], 
110                         test_params['environment_file'], self.machines)
111             elif test_param['test'] in ['portstats']:
112                 test = PortStatsTest(test_param, test_params['runtime'],
113                         test_params['TestName'], 
114                         test_params['environment_file'], self.machines)
115             elif test_param['test'] in ['impairtest']:
116                 test = ImpairTest(test_param, test_params['lat_percentile'],
117                         test_params['runtime'],
118                         test_params['TestName'], 
119                         test_params['environment_file'], gen_machine,
120                         sut_machine)
121             elif test_param['test'] in ['irqtest']:
122                 test = IrqTest(test_param, test_params['runtime'],
123                         test_params['TestName'], 
124                         test_params['environment_file'], self.machines)
125             elif test_param['test'] in ['warmuptest']:
126                 test = WarmupTest(test_param, gen_machine)
127             else:
128                 RapidLog.debug('Test name ({}) is not valid:'.format(
129                     test_param['test']))
130             single_test_result = test.run()
131             if not single_test_result:
132                 result = False
133         return (result)
134
135 def main():
136     """Main function.
137     """
138     test_params = RapidTestManager.get_defaults()
139     # When no cli is used, the process_cli can be replaced by code modifying
140     # test_params
141     test_params = RapidCli.process_cli(test_params)
142     log_file = 'RUN{}.{}.log'.format(test_params['environment_file'],
143             test_params['test_file'])
144     RapidLog.log_init(log_file, test_params['loglevel'],
145             test_params['screenloglevel'] , test_params['version']  )
146     test_manager = RapidTestManager()
147     test_result = test_manager.run_tests(test_params)
148     RapidLog.info('Test result is : {}'.format(test_result))
149
150 if __name__ == "__main__":
151     main()