New PROX version, background traffic reporting
[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         for machine_params in test_params['machines']:
61             if 'gencores' in machine_params.keys():
62                 machine = RapidGeneratorMachine(test_params['key'],
63                         test_params['user'], test_params['vim_type'],
64                         test_params['rundir'], machine_params,
65                         test_params['ipv6'])
66                 if machine_params['monitor']:
67                     if monitor_gen:
68                         RapidLog.exception("Can only monitor 1 generator")
69                         raise Exception("Can only monitor 1 generator")
70                     else:
71                         monitor_gen = True
72                         gen_machine = machine
73                 else:
74                     background_machines.append(machine)
75             else:
76                 machine = RapidMachine(test_params['key'], test_params['user'],
77                         test_params['vim_type'], test_params['rundir'],
78                         machine_params)
79                 if machine_params['monitor']:
80                     if monitor_sut:
81                         RapidLog.exception("Can only monitor 1 sut")
82                         raise Exception("Can only monitor 1 sut")
83                     else:
84                         monitor_sut = True
85                         if machine_params['prox_socket']:
86                             sut_machine = machine
87             self.machines.append(machine)
88         prox_executor = concurrent.futures.ThreadPoolExecutor(max_workers=len(self.machines))
89         self.future_to_prox = {prox_executor.submit(machine.start_prox,test_params['configonly']): machine for machine in self.machines}
90         if test_params['configonly']:
91             concurrent.futures.wait(self.future_to_prox,return_when=ALL_COMPLETED)
92             sys.exit()
93         with concurrent.futures.ThreadPoolExecutor(max_workers=len(self.machines)) as executor:
94             future_to_connect_prox = {executor.submit(machine.connect_prox): machine for machine in self.machines}
95             concurrent.futures.wait(future_to_connect_prox,return_when=ALL_COMPLETED)
96         result = True
97         for test_param in test_params['tests']:
98             RapidLog.info(test_param['test'])
99             if test_param['test'] in ['flowsizetest', 'TST009test',
100                     'fixed_rate', 'increment_till_fail']:
101                 test = FlowSizeTest(test_param, test_params['lat_percentile'],
102                         test_params['runtime'], 
103                         test_params['TestName'], 
104                         test_params['environment_file'], gen_machine,
105                         sut_machine, background_machines)
106             elif test_param['test'] in ['corestats']:
107                 test = CoreStatsTest(test_param, test_params['runtime'],
108                         test_params['TestName'], 
109                         test_params['environment_file'], self.machines)
110             elif test_param['test'] in ['portstats']:
111                 test = PortStatsTest(test_param, test_params['runtime'],
112                         test_params['TestName'], 
113                         test_params['environment_file'], self.machines)
114             elif test_param['test'] in ['impairtest']:
115                 test = ImpairTest(test_param, test_params['lat_percentile'],
116                         test_params['runtime'],
117                         test_params['TestName'], 
118                         test_params['environment_file'], gen_machine,
119                         sut_machine)
120             elif test_param['test'] in ['irqtest']:
121                 test = IrqTest(test_param, test_params['runtime'],
122                         test_params['TestName'], 
123                         test_params['environment_file'], self.machines)
124             elif test_param['test'] in ['warmuptest']:
125                 test = WarmupTest(test_param, gen_machine)
126             else:
127                 RapidLog.debug('Test name ({}) is not valid:'.format(
128                     test_param['test']))
129             single_test_result = test.run()
130             if not single_test_result:
131                 result = False
132         return (result)
133
134 def main():
135     """Main function.
136     """
137     test_params = RapidTestManager.get_defaults()
138     # When no cli is used, the process_cli can be replaced by code modifying
139     # test_params
140     test_params = RapidCli.process_cli(test_params)
141     log_file = 'RUN{}.{}.log'.format(test_params['environment_file'],
142             test_params['test_file'])
143     RapidLog.log_init(log_file, test_params['loglevel'],
144             test_params['screenloglevel'] , test_params['version']  )
145     test_manager = RapidTestManager()
146     test_result = test_manager.run_tests(test_params)
147     RapidLog.info('Test result is : {}'.format(test_result))
148
149 if __name__ == "__main__":
150     main()