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
47 return (RapidDefaults.test_params)
50 def run_tests(test_params):
51 test_params = RapidConfigParser.parse_config(test_params)
52 RapidLog.debug(test_params)
53 monitor_gen = monitor_sut = False
54 background_machines = []
55 sut_machine = gen_machine = None
57 for machine_params in test_params['machines']:
58 if 'gencores' in machine_params.keys():
59 machine = RapidGeneratorMachine(test_params['key'],
60 test_params['user'], test_params['vim_type'],
61 test_params['rundir'], machine_params,
63 if machine_params['monitor']:
65 RapidLog.exception("Can only monitor 1 generator")
66 raise Exception("Can only monitor 1 generator")
71 background_machines.append(machine)
73 machine = RapidMachine(test_params['key'], test_params['user'],
74 test_params['vim_type'], test_params['rundir'],
76 if machine_params['monitor']:
78 RapidLog.exception("Can only monitor 1 sut")
79 raise Exception("Can only monitor 1 sut")
83 machines.append(machine)
84 if test_params['configonly']:
86 prox_executor = concurrent.futures.ThreadPoolExecutor(max_workers=len(machines))
87 future_to_prox = {prox_executor.submit(machine.start_prox): machine for machine in machines}
88 with concurrent.futures.ThreadPoolExecutor(max_workers=len(machines)) as executor:
89 future_to_connect_prox = {executor.submit(machine.connect_prox): machine for machine in machines}
90 concurrent.futures.wait(future_to_connect_prox,return_when=ALL_COMPLETED)
92 for test_param in test_params['tests']:
93 RapidLog.info(test_param['test'])
94 if test_param['test'] in ['flowsizetest', 'TST009test',
95 'fixed_rate', 'increment_till_fail']:
96 test = FlowSizeTest(test_param, test_params['lat_percentile'],
97 test_params['runtime'],
98 test_params['TestName'],
99 test_params['environment_file'], gen_machine,
100 sut_machine, background_machines)
101 elif test_param['test'] in ['corestats']:
102 test = CoreStatsTest(test_param, test_params['runtime'],
103 test_params['TestName'],
104 test_params['environment_file'], machines)
105 elif test_param['test'] in ['portstats']:
106 test = PortStatsTest(test_param, test_params['runtime'],
107 test_params['TestName'],
108 test_params['environment_file'], machines)
109 elif test_param['test'] in ['impairtest']:
110 test = ImpairTest(test_param, test_params['lat_percentile'],
111 test_params['runtime'],
112 test_params['TestName'],
113 test_params['environment_file'], gen_machine,
115 elif test_param['test'] in ['irqtest']:
116 test = IrqTest(test_param, test_params['runtime'],
117 test_params['TestName'],
118 test_params['environment_file'], machines)
119 elif test_param['test'] in ['warmuptest']:
120 test = WarmupTest(test_param, gen_machine)
122 RapidLog.debug('Test name ({}) is not valid:'.format(
124 single_test_result = test.run()
125 if not single_test_result:
127 for machine in machines:
134 test_params = RapidTestManager.get_defaults()
135 # When no cli is used, the process_cli can be replaced by code modifying
137 test_params = RapidCli.process_cli(test_params)
138 log_file = 'RUN{}.{}.log'.format(test_params['environment_file'],
139 test_params['test_file'])
140 RapidLog.log_init(log_file, test_params['loglevel'],
141 test_params['screenloglevel'] , test_params['version'] )
142 test_result = RapidTestManager.run_tests(test_params)
143 RapidLog.info('Test result is : {}'.format(test_result))
145 if __name__ == "__main__":