4 ## Copyright (c) 2010-2020 Intel Corporation
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
10 ## http://www.apache.org/licenses/LICENSE-2.0
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.
18 from __future__ import print_function
19 from __future__ import print_function
20 from __future__ import division
22 from future import standard_library
23 standard_library.install_aliases()
24 from builtins import object
27 import concurrent.futures
28 from concurrent.futures import ALL_COMPLETED
29 from rapid_cli import RapidCli
30 from rapid_log import RapidLog
31 from rapid_parser import RapidConfigParser
32 from rapid_defaults import RapidDefaults
33 from rapid_machine import RapidMachine
34 from rapid_generator_machine import RapidGeneratorMachine
35 from rapid_flowsizetest import FlowSizeTest
36 from rapid_corestatstest import CoreStatsTest
37 from rapid_portstatstest import PortStatsTest
38 from rapid_impairtest import ImpairTest
39 from rapid_irqtest import IrqTest
40 from rapid_warmuptest import WarmupTest
42 class RapidTestManager(object):
44 RapidTestManager Class
53 for machine in self.machines:
58 return (RapidDefaults.test_params)
60 def run_tests(self, test_params):
61 test_params = RapidConfigParser.parse_config(test_params)
62 RapidLog.debug(test_params)
63 monitor_gen = monitor_sut = False
64 background_machines = []
65 sut_machine = gen_machine = None
66 configonly = test_params['configonly']
69 for machine_params in test_params['machines']:
70 if machine_params['name'] not in machine_names:
71 machine_names.append(machine_params['name'])
72 machine_counter[machine_params['name']] = 1
74 machine_counter[machine_params['name']] += 1
75 machine_params['name'] = '{}_{}'.format(machine_params['name'],
76 machine_counter[machine_params['name']])
77 if 'gencores' in machine_params.keys():
78 machine = RapidGeneratorMachine(test_params['key'],
79 test_params['user'], test_params['password'],
80 test_params['vim_type'], test_params['rundir'],
81 test_params['resultsdir'], machine_params, configonly,
83 if machine_params['monitor']:
85 RapidLog.exception("Can only monitor 1 generator")
86 raise Exception("Can only monitor 1 generator")
91 background_machines.append(machine)
93 machine = RapidMachine(test_params['key'], test_params['user'],
94 test_params['password'], test_params['vim_type'],
95 test_params['rundir'], test_params['resultsdir'],
96 machine_params, configonly)
97 if machine_params['monitor']:
99 RapidLog.exception("Can only monitor 1 sut")
100 raise Exception("Can only monitor 1 sut")
103 if machine_params['prox_socket']:
104 sut_machine = machine
105 self.machines.append(machine)
107 prox_executor = concurrent.futures.ThreadPoolExecutor(max_workers=len(self.machines))
108 self.future_to_prox = {prox_executor.submit(machine.start_prox): machine for machine in self.machines}
110 concurrent.futures.wait(self.future_to_prox,return_when=ALL_COMPLETED)
112 socket_executor = concurrent.futures.ThreadPoolExecutor(max_workers=len(self.machines))
113 future_to_connect_prox = {socket_executor.submit(machine.connect_prox): machine for machine in self.machines}
114 concurrent.futures.wait(future_to_connect_prox,return_when=ALL_COMPLETED)
116 for test_param in test_params['tests']:
117 RapidLog.info(test_param['test'])
118 if test_param['test'] in ['flowsizetest', 'TST009test',
119 'fixed_rate', 'increment_till_fail']:
120 test = FlowSizeTest(test_param,
121 test_params['lat_percentile'],
122 test_params['runtime'],
123 test_params['TestName'],
124 test_params['environment_file'],
126 sut_machine, background_machines,
127 test_params['sleep_time'])
128 elif test_param['test'] in ['corestatstest']:
129 test = CoreStatsTest(test_param,
130 test_params['runtime'],
131 test_params['TestName'],
132 test_params['environment_file'],
134 elif test_param['test'] in ['portstatstest']:
135 test = PortStatsTest(test_param,
136 test_params['runtime'],
137 test_params['TestName'],
138 test_params['environment_file'],
140 elif test_param['test'] in ['impairtest']:
141 test = ImpairTest(test_param,
142 test_params['lat_percentile'],
143 test_params['runtime'],
144 test_params['TestName'],
145 test_params['environment_file'],
147 sut_machine, background_machines)
148 elif test_param['test'] in ['irqtest']:
149 test = IrqTest(test_param,
150 test_params['runtime'],
151 test_params['TestName'],
152 test_params['environment_file'],
154 elif test_param['test'] in ['warmuptest']:
155 test = WarmupTest(test_param,
158 RapidLog.debug('Test name ({}) is not valid:'.format(
160 single_test_result, result_details = test.run()
161 result = result + single_test_result
162 for machine in self.machines:
164 concurrent.futures.wait(self.future_to_prox,
165 return_when=ALL_COMPLETED)
166 except (ConnectionError, KeyboardInterrupt) as e:
167 result = result_details = None
168 socket_executor.shutdown(wait=False)
169 socket_executor._threads.clear()
170 prox_executor.shutdown(wait=False)
171 prox_executor._threads.clear()
172 concurrent.futures.thread._threads_queues.clear()
173 RapidLog.error("Test interrupted: {} {}".format(
175 return (result, result_details)
180 test_params = RapidTestManager.get_defaults()
181 # When no cli is used, the process_cli can be replaced by code modifying
183 test_params = RapidCli.process_cli(test_params)
184 _, test_file_name = os.path.split(test_params['test_file'])
185 _, environment_file_name = os.path.split(test_params['environment_file'])
186 if 'resultsdir' in test_params:
187 res_dir = test_params['resultsdir']
188 log_file = '{}/RUN{}.{}.log'.format(res_dir,environment_file_name,
191 log_file = 'RUN{}.{}.log'.format(environment_file_name, test_file_name)
192 RapidLog.log_init(log_file, test_params['loglevel'],
193 test_params['screenloglevel'] , test_params['version'] )
194 test_manager = RapidTestManager()
195 test_result, _ = test_manager.run_tests(test_params)
198 if __name__ == "__main__":