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
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
41 class RapidTestManager(object):
43 RapidTestManager Class
46 for machine in self.machines:
51 return (RapidDefaults.test_params)
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
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,
66 if machine_params['monitor']:
68 RapidLog.exception("Can only monitor 1 generator")
69 raise Exception("Can only monitor 1 generator")
74 background_machines.append(machine)
76 machine = RapidMachine(test_params['key'], test_params['user'],
77 test_params['vim_type'], test_params['rundir'],
79 if machine_params['monitor']:
81 RapidLog.exception("Can only monitor 1 sut")
82 raise Exception("Can only monitor 1 sut")
85 if machine_params['prox_socket']:
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)
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)
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,
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)
127 RapidLog.debug('Test name ({}) is not valid:'.format(
129 single_test_result = test.run()
130 if not single_test_result:
137 test_params = RapidTestManager.get_defaults()
138 # When no cli is used, the process_cli can be replaced by code modifying
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))
149 if __name__ == "__main__":