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.
19 from rapid_log import RapidLog
20 from past.utils import old_div
25 import ConfigParser as configparser
28 class RapidConfigParser(object):
30 Class to deal with rapid configuration files
33 def parse_config(test_params):
34 testconfig = configparser.RawConfigParser()
35 testconfig.read(test_params['test_file'])
36 test_params['required_number_of_test_machines'] = int(testconfig.get('TestParameters', 'total_number_of_test_machines'))
37 test_params['number_of_tests'] = int(testconfig.get('TestParameters', 'number_of_tests'))
38 test_params['TestName'] = testconfig.get('TestParameters', 'name')
39 if testconfig.has_option('TestParameters', 'lat_percentile'):
40 test_params['lat_percentile'] = old_div(float(testconfig.get('TestParameters', 'lat_percentile')),100.0)
42 test_params['lat_percentile'] = 0.99
43 RapidLog.info('Latency percentile measured at {:.0f}%'.format(test_params['lat_percentile']*100))
44 config = configparser.RawConfigParser()
45 config.read(test_params['environment_file'])
46 test_params['vim_type'] = config.get('Varia', 'vim')
47 test_params['key'] = config.get('ssh', 'key')
48 test_params['user'] = config.get('ssh', 'user')
49 test_params['total_number_of_machines'] = int(config.get('rapid', 'total_number_of_machines'))
50 if config.has_option('TestParameters', 'pushgateway'):
51 test_params['pushgateway'] = config.get('TestParameters', 'pushgateway')
52 RapidLog.info('Measurements will be pushed to %s'%test_params['pushgateway'])
54 test_params['pushgateway'] = None
57 for test_index in range(1, test_params['number_of_tests']+1):
59 section = 'test%d'%test_index
60 options = testconfig.options(section)
61 for option in options:
62 if option in ['packetsizes','flows']:
63 test[option] = ast.literal_eval(testconfig.get(section, option))
64 test[option] = [int(i) for i in test[option]]
65 elif option in ['maxframespersecondallingress','stepsize']:
66 test[option] = int(testconfig.get(section, option))
67 elif option in ['startspeed','drop_rate_threshold','lat_avg_threshold','lat_perc_threshold','lat_max_threshold','accuracy','maxr','maxz','pass_threshold']:
68 test[option] = float(testconfig.get(section, option))
70 test[option] = testconfig.get(section, option)
71 tests.append(dict(test))
73 if test['test'] in ['flowsizetest','TST009test']:
74 if 'drop_rate_threshold' not in test.keys():
75 test['drop_rate_threshold'] = 0
76 test_params['tests'] = tests
77 if test_params['required_number_of_test_machines'] > test_params['total_number_of_machines']:
78 RapidLog.exception("Not enough VMs for this test: %d needed and only %d available" % (required_number_of_test_machines,total_number_of_machines))
79 raise Exception("Not enough VMs for this test: %d needed and only %d available" % (required_number_of_test_machines,total_number_of_machines))
80 machine_map = configparser.RawConfigParser()
81 machine_map.read(test_params['machine_map_file'])
84 for test_machine in range(1, test_params['required_number_of_test_machines']+1):
86 if not(testconfig.has_option('TestM%d'%test_machine, 'prox_socket') and not testconfig.getboolean('TestM%d'%test_machine, 'prox_socket')):
87 section = 'TestM%d'%test_machine
88 options = testconfig.options(section)
89 for option in options:
90 if option in ['prox_socket','prox_launch_exit','monitor']:
91 machine[option] = testconfig.getboolean(section, option)
92 elif option in ['cores', 'gencores','latcores']:
93 machine[option] = ast.literal_eval(testconfig.get(section, option))
95 machine[option] = testconfig.get(section, option)
96 for key in ['prox_socket','prox_launch_exit']:
97 if key not in machine.keys():
99 if 'monitor' not in machine.keys():
100 machine['monitor'] = True
101 index = int(machine_map.get('TestM%d'%test_machine, 'machine_index'))
102 section = 'M%d'%index
103 options = config.options(section)
104 for option in options:
105 machine[option] = config.get(section, option)
106 machines.append(dict(machine))
107 for machine in machines:
109 if 'dest_vm' in machine.keys():
112 dp_ip_key = 'dp_ip{}'.format(index)
113 dp_mac_key = 'dp_mac{}'.format(index)
114 if dp_ip_key in machines[int(machine['dest_vm'])-1].keys() and \
115 dp_mac_key in machines[int(machine['dest_vm'])-1].keys():
116 dp_port = {'ip': machines[int(machine['dest_vm'])-1][dp_ip_key],
117 'mac' : machines[int(machine['dest_vm'])-1][dp_mac_key]}
118 dp_ports.append(dict(dp_port))
122 machine['dest_ports'] = list(dp_ports)
124 if 'gw_vm' in machine.keys():
127 gw_ip_key = 'dp_ip{}'.format(index)
128 if gw_ip_key in machines[int(machine['gw_vm'])-1].keys():
129 gw_ip = machines[int(machine['dest_vm'])-1][gw_ip_key]
134 machine['gw_ips'] = list(gw_ips)
135 test_params['machines'] = machines