4 ## Copyright (c) 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.
19 from rapid_log import RapidLog
20 from past.utils import old_div
25 import ConfigParser as configparser
29 class RapidConfigParser(object):
31 Class to deal with rapid configuration files
34 def parse_config(test_params):
35 testconfig = configparser.RawConfigParser()
36 testconfig.read(test_params['test_file'])
37 test_params['required_number_of_test_machines'] = int(testconfig.get(
38 'TestParameters', 'total_number_of_test_machines'))
39 test_params['number_of_tests'] = int(testconfig.get('TestParameters',
41 test_params['TestName'] = testconfig.get('TestParameters', 'name')
42 if testconfig.has_option('TestParameters', 'lat_percentile'):
43 test_params['lat_percentile'] = old_div(float(
44 testconfig.get('TestParameters', 'lat_percentile')),100.0)
46 test_params['lat_percentile'] = 0.99
47 RapidLog.info('Latency percentile at {:.0f}%'.format(
48 test_params['lat_percentile']*100))
49 if testconfig.has_option('TestParameters', 'ipv6'):
50 test_params['ipv6'] = testconfig.getboolean('TestParameters','ipv6')
52 test_params['ipv6'] = False
53 config = configparser.RawConfigParser()
54 config.read(test_params['environment_file'])
55 test_params['vim_type'] = config.get('Varia', 'vim')
56 test_params['key'] = config.get('ssh', 'key')
57 test_params['user'] = config.get('ssh', 'user')
58 test_params['total_number_of_machines'] = int(config.get('rapid',
59 'total_number_of_machines'))
62 for test_index in range(1, test_params['number_of_tests']+1):
64 section = 'test%d'%test_index
65 options = testconfig.options(section)
66 for option in options:
67 if option in ['imix','imixs','flows']:
68 test[option] = ast.literal_eval(testconfig.get(section,
70 elif option in ['maxframespersecondallingress','stepsize',
72 test[option] = int(testconfig.get(section, option))
73 elif option in ['startspeed', 'step', 'drop_rate_threshold',
74 'lat_avg_threshold','lat_perc_threshold',
75 'lat_max_threshold','accuracy','maxr','maxz',
77 test[option] = float(testconfig.get(section, option))
79 test[option] = testconfig.get(section, option)
80 tests.append(dict(test))
82 if test['test'] in ['flowsizetest','TST009test']:
83 if 'drop_rate_threshold' not in test.keys():
84 test['drop_rate_threshold'] = 0
85 latency_thresholds = ['lat_avg_threshold','lat_perc_threshold','lat_max_threshold']
86 for threshold in latency_thresholds:
87 if threshold not in test.keys():
89 test_params['tests'] = tests
90 if test_params['required_number_of_test_machines'] > test_params[
91 'total_number_of_machines']:
92 RapidLog.exception("Not enough VMs for this test: %d needed and only %d available" % (required_number_of_test_machines,total_number_of_machines))
93 raise Exception("Not enough VMs for this test: %d needed and only %d available" % (required_number_of_test_machines,total_number_of_machines))
94 map_info = test_params['machine_map_file'].strip('[]').split(',')
95 map_info_length = len(map_info)
96 if map_info_length > 1:
97 if map_info_length < test_params[
98 'required_number_of_test_machines']:
99 RapidLog.exception('Not enough machine indices in --map \
100 parameter: {}. Needing {} entries'.format(map_info,
101 test_params['required_number_of_test_machines']))
102 machine_index = list(map(int,map_info))
104 machine_map = configparser.RawConfigParser()
105 machine_map.read(test_params['machine_map_file'])
107 for test_machine in range(1,
108 test_params['required_number_of_test_machines']+1):
109 machine_index.append(int(machine_map.get(
110 'TestM%d'%test_machine, 'machine_index')))
111 machine_map = configparser.RawConfigParser()
112 machine_map.read(test_params['machine_map_file'])
115 for test_machine in range(1, test_params[
116 'required_number_of_test_machines']+1):
118 section = 'TestM%d'%test_machine
119 options = testconfig.options(section)
120 for option in options:
121 if option in ['prox_socket','prox_launch_exit','monitor']:
122 machine[option] = testconfig.getboolean(section, option)
123 elif option in ['mcore', 'cores', 'gencores','latcores']:
124 machine[option] = ast.literal_eval(testconfig.get(
126 elif option in ['bucket_size_exp']:
127 machine[option] = int(testconfig.get(section, option))
128 if machine[option] < 11:
130 "Minimum Value for bucket_size_exp is 11")
132 machine[option] = testconfig.get(section, option)
133 for key in ['prox_socket','prox_launch_exit']:
134 if key not in machine.keys():
136 if 'monitor' not in machine.keys():
137 machine['monitor'] = True
138 section = 'M%d'%machine_index[test_machine-1]
139 options = config.options(section)
140 for option in options:
141 machine[option] = config.get(section, option)
142 machines.append(dict(machine))
143 for machine in machines:
145 if 'dest_vm' in machine.keys():
148 dp_ip_key = 'dp_ip{}'.format(index)
149 dp_mac_key = 'dp_mac{}'.format(index)
150 if dp_ip_key in machines[int(machine['dest_vm'])-1].keys() and \
151 dp_mac_key in machines[int(machine['dest_vm'])-1].keys():
152 dp_port = {'ip': machines[int(machine['dest_vm'])-1][dp_ip_key],
153 'mac' : machines[int(machine['dest_vm'])-1][dp_mac_key]}
154 dp_ports.append(dict(dp_port))
158 machine['dest_ports'] = list(dp_ports)
160 if 'gw_vm' in machine.keys():
163 gw_ip_key = 'dp_ip{}'.format(index)
164 if gw_ip_key in machines[int(machine['gw_vm'])-1].keys():
165 gw_ip = machines[int(machine['gw_vm'])-1][gw_ip_key]
170 machine['gw_ips'] = list(gw_ips)
171 test_params['machines'] = machines