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
47 for machine in self.machines:
52 return (RapidDefaults.test_params)
54 def run_tests(self, test_params):
55 test_params = RapidConfigParser.parse_config(test_params)
56 RapidLog.debug(test_params)
57 monitor_gen = monitor_sut = False
58 background_machines = []
59 sut_machine = gen_machine = None
61 configonly = test_params['configonly']
62 for machine_params in test_params['machines']:
63 if 'gencores' in machine_params.keys():
64 machine = RapidGeneratorMachine(test_params['key'],
65 test_params['user'], test_params['vim_type'],
66 test_params['rundir'], test_params['resultsdir'],
67 machine_params, configonly, test_params['ipv6'])
68 if machine_params['monitor']:
70 RapidLog.exception("Can only monitor 1 generator")
71 raise Exception("Can only monitor 1 generator")
76 background_machines.append(machine)
78 machine = RapidMachine(test_params['key'], test_params['user'],
79 test_params['vim_type'], test_params['rundir'],
80 test_params['resultsdir'], machine_params, configonly)
81 if machine_params['monitor']:
83 RapidLog.exception("Can only monitor 1 sut")
84 raise Exception("Can only monitor 1 sut")
87 if machine_params['prox_socket']:
89 self.machines.append(machine)
90 prox_executor = concurrent.futures.ThreadPoolExecutor(max_workers=len(self.machines))
91 self.future_to_prox = {prox_executor.submit(machine.start_prox): machine for machine in self.machines}
93 concurrent.futures.wait(self.future_to_prox,return_when=ALL_COMPLETED)
95 with concurrent.futures.ThreadPoolExecutor(max_workers=len(self.machines)) as executor:
96 future_to_connect_prox = {executor.submit(machine.connect_prox): machine for machine in self.machines}
97 concurrent.futures.wait(future_to_connect_prox,return_when=ALL_COMPLETED)
99 for test_param in test_params['tests']:
100 RapidLog.info(test_param['test'])
101 if test_param['test'] in ['flowsizetest', 'TST009test',
102 'fixed_rate', 'increment_till_fail']:
103 test = FlowSizeTest(test_param, test_params['lat_percentile'],
104 test_params['runtime'],
105 test_params['TestName'],
106 test_params['environment_file'], gen_machine,
107 sut_machine, background_machines)
108 elif test_param['test'] in ['corestats']:
109 test = CoreStatsTest(test_param, test_params['runtime'],
110 test_params['TestName'],
111 test_params['environment_file'], self.machines)
112 elif test_param['test'] in ['portstats']:
113 test = PortStatsTest(test_param, test_params['runtime'],
114 test_params['TestName'],
115 test_params['environment_file'], self.machines)
116 elif test_param['test'] in ['impairtest']:
117 test = ImpairTest(test_param, test_params['lat_percentile'],
118 test_params['runtime'],
119 test_params['TestName'],
120 test_params['environment_file'], gen_machine,
122 elif test_param['test'] in ['irqtest']:
123 test = IrqTest(test_param, test_params['runtime'],
124 test_params['TestName'],
125 test_params['environment_file'], self.machines)
126 elif test_param['test'] in ['warmuptest']:
127 test = WarmupTest(test_param, gen_machine)
129 RapidLog.debug('Test name ({}) is not valid:'.format(
131 single_test_result, result_details = test.run()
132 result = result + single_test_result
133 for machine in self.machines:
135 concurrent.futures.wait(self.future_to_prox,return_when=ALL_COMPLETED)
136 return (result, result_details)
141 test_params = RapidTestManager.get_defaults()
142 # When no cli is used, the process_cli can be replaced by code modifying
144 test_params = RapidCli.process_cli(test_params)
145 _, test_file_name = os.path.split(test_params['test_file'])
146 _, environment_file_name = os.path.split(test_params['environment_file'])
147 log_file = 'RUN{}.{}.log'.format(environment_file_name, test_file_name)
148 RapidLog.log_init(log_file, test_params['loglevel'],
149 test_params['screenloglevel'] , test_params['version'] )
150 test_manager = RapidTestManager()
151 test_result, _ = test_manager.run_tests(test_params)
154 if __name__ == "__main__":