blob: 481c7b44e03923b33a402c0138d6f66e7d61ea75 [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
ChetanGaonker2099d722016-10-07 15:16:58 -070017#copyright 2016-present Ciena Corporation
18#
19# Licensed under the Apache License, Version 2.0 (the "License");
20# you may not use this file except in compliance with the License.
21# You may obtain a copy of the License at
22#
23# http://www.apache.org/licenses/LICENSE-2.0
24#
25# Unless required by applicable law or agreed to in writing, software
26# distributed under the License is distributed on an "AS IS" BASIS,
27# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28# See the License for the specific language governing permissions and
29# limitations under the License.
30#
31import unittest
32from nose.tools import *
33from scapy.all import *
A.R Karthickbe7768c2017-03-17 11:39:41 -070034from OnosCtrl import OnosCtrl
ChetanGaonker2099d722016-10-07 15:16:58 -070035from OltConfig import OltConfig
A R Karthick76a497a2017-04-12 10:59:39 -070036from CordTestUtils import get_mac, get_controller, get_controllers, log_test
ChetanGaonker2099d722016-10-07 15:16:58 -070037from OnosFlowCtrl import OnosFlowCtrl
38from nose.twistedtools import reactor, deferred
39from twisted.internet import defer
40from onosclidriver import OnosCliDriver
41from CordContainer import Container, Onos, Quagga
A.R Karthick2560f042016-11-30 14:38:52 -080042from CordTestServer import cord_test_onos_restart, cord_test_onos_shutdown, cord_test_onos_add_cluster, cord_test_quagga_restart, cord_test_restart_cluster
ChetanGaonker2099d722016-10-07 15:16:58 -070043from portmaps import g_subscriber_port_map
44from scapy.all import *
45import time, monotonic
46import threading
47from threading import current_thread
48from Cluster import *
49from EapTLS import TLSAuthTest
50from ACL import ACLTest
A R Karthick1f908202016-11-16 17:32:20 -080051from OnosLog import OnosLog
52from CordLogger import CordLogger
A R Karthick9dc6e922017-07-12 14:40:16 -070053from CordTestConfig import setup_module, teardown_module
ChetanGaonker2099d722016-10-07 15:16:58 -070054import os
55import json
56import random
57import collections
A R Karthick76a497a2017-04-12 10:59:39 -070058log_test.setLevel('INFO')
ChetanGaonker2099d722016-10-07 15:16:58 -070059
A R Karthick1f908202016-11-16 17:32:20 -080060class cluster_exchange(CordLogger):
ChetanGaonker2099d722016-10-07 15:16:58 -070061 test_path = os.path.dirname(os.path.realpath(__file__))
62 onos_config_path = os.path.join(test_path, '..', 'setup/onos-config')
63 mac = RandMAC()._fix()
64 flows_eth = Ether(src = RandMAC()._fix(), dst = RandMAC()._fix())
65 igmp_eth = Ether(dst = '01:00:5e:00:00:16', type = ETH_P_IP)
66 igmp_ip = IP(dst = '224.0.0.22')
67 ONOS_INSTANCES = 3
68 V_INF1 = 'veth0'
69 TLS_TIMEOUT = 100
70 device_id = 'of:' + get_mac()
71 igmp = cluster_igmp()
72 igmp_groups = igmp.mcast_ip_range(start_ip = '224.1.8.10',end_ip = '224.1.10.49')
73 igmp_sources = igmp.source_ip_range(start_ip = '38.24.29.35',end_ip='38.24.35.56')
74 tls = cluster_tls()
75 flows = cluster_flows()
76 proxyarp = cluster_proxyarp()
77 vrouter = cluster_vrouter()
78 acl = cluster_acl()
79 dhcprelay = cluster_dhcprelay()
80 subscriber = cluster_subscriber()
A R Karthick3b2e0372016-12-14 17:37:43 -080081 testcaseLoggers = ('test_cluster_controller_restarts', 'test_cluster_graceful_controller_restarts',
82 'test_cluster_single_controller_restarts', 'test_cluster_restarts')
A.R Karthick99044822017-02-09 14:04:20 -080083 ITERATIONS = int(os.getenv('ITERATIONS', 10))
A.R Karthick53d92702017-03-13 10:10:38 -070084 ARCHIVE_PARTITION = False
A R Karthick1f908202016-11-16 17:32:20 -080085
86 def setUp(self):
87 if self._testMethodName not in self.testcaseLoggers:
88 super(cluster_exchange, self).setUp()
89
90 def tearDown(self):
91 if self._testMethodName not in self.testcaseLoggers:
92 super(cluster_exchange, self).tearDown()
ChetanGaonker2099d722016-10-07 15:16:58 -070093
A R Karthick6cc8b812016-12-09 10:24:40 -080094 def cliEnter(self, controller = None):
ChetanGaonker2099d722016-10-07 15:16:58 -070095 retries = 0
A R Karthick6cc8b812016-12-09 10:24:40 -080096 while retries < 30:
97 self.cli = OnosCliDriver(controller = controller, connect = True)
ChetanGaonker2099d722016-10-07 15:16:58 -070098 if self.cli.handle:
99 break
100 else:
101 retries += 1
102 time.sleep(2)
103
104 def cliExit(self):
105 self.cli.disconnect()
106
A R Karthick1f908202016-11-16 17:32:20 -0800107 def get_leader(self, controller = None):
108 self.cliEnter(controller = controller)
A R Karthickde6b9dc2016-11-29 17:46:16 -0800109 try:
110 result = json.loads(self.cli.leaders(jsonFormat = True))
111 except:
112 result = None
113
A R Karthick1f908202016-11-16 17:32:20 -0800114 if result is None:
A R Karthick76a497a2017-04-12 10:59:39 -0700115 log_test.info('Leaders command failure for controller %s' %controller)
A R Karthick1f908202016-11-16 17:32:20 -0800116 else:
A R Karthick76a497a2017-04-12 10:59:39 -0700117 log_test.info('Leaders returned: %s' %result)
A R Karthick1f908202016-11-16 17:32:20 -0800118 self.cliExit()
119 return result
120
A R Karthick3b2e0372016-12-14 17:37:43 -0800121 def onos_shutdown(self, controller = None):
122 status = True
123 self.cliEnter(controller = controller)
124 try:
125 self.cli.shutdown(timeout = 10)
126 except:
A R Karthick76a497a2017-04-12 10:59:39 -0700127 log_test.info('Graceful shutdown of ONOS failed for controller: %s' %controller)
A R Karthick3b2e0372016-12-14 17:37:43 -0800128 status = False
129
130 self.cliExit()
131 return status
132
A R Karthicke14fc022016-12-08 14:50:29 -0800133 def log_set(self, level = None, app = 'org.onosproject', controllers = None):
134 CordLogger.logSet(level = level, app = app, controllers = controllers, forced = True)
A R Karthickef1232d2016-12-07 09:18:15 -0800135
A R Karthick1f908202016-11-16 17:32:20 -0800136 def get_leaders(self, controller = None):
A.R Karthick45ab3e12016-11-30 11:25:51 -0800137 result_map = {}
138 if controller is None:
A.R Karthickbe7768c2017-03-17 11:39:41 -0700139 controller = get_controller()
A R Karthick1f908202016-11-16 17:32:20 -0800140 if type(controller) in [ list, tuple ]:
141 for c in controller:
142 leaders = self.get_leader(controller = c)
A.R Karthick45ab3e12016-11-30 11:25:51 -0800143 result_map[c] = leaders
A R Karthick1f908202016-11-16 17:32:20 -0800144 else:
145 leaders = self.get_leader(controller = controller)
A.R Karthick45ab3e12016-11-30 11:25:51 -0800146 result_map[controller] = leaders
147 return result_map
A R Karthick1f908202016-11-16 17:32:20 -0800148
A R Karthickec2db322016-11-17 15:06:01 -0800149 def verify_leaders(self, controller = None):
A.R Karthick45ab3e12016-11-30 11:25:51 -0800150 leaders_map = self.get_leaders(controller = controller)
151 failed = [ k for k,v in leaders_map.items() if v == None ]
A R Karthickec2db322016-11-17 15:06:01 -0800152 return failed
153
ChetanGaonker2099d722016-10-07 15:16:58 -0700154 def verify_cluster_status(self,controller = None,onos_instances=ONOS_INSTANCES,verify=False):
155 tries = 0
156 try:
157 self.cliEnter(controller = controller)
158 while tries <= 10:
159 cluster_summary = json.loads(self.cli.summary(jsonFormat = True))
160 if cluster_summary:
A R Karthick76a497a2017-04-12 10:59:39 -0700161 log_test.info("cluster 'summary' command output is %s"%cluster_summary)
ChetanGaonker2099d722016-10-07 15:16:58 -0700162 nodes = cluster_summary['nodes']
163 if verify:
164 if nodes == onos_instances:
165 self.cliExit()
166 return True
167 else:
168 tries += 1
169 time.sleep(1)
170 else:
171 if nodes >= onos_instances:
172 self.cliExit()
173 return True
174 else:
175 tries += 1
176 time.sleep(1)
177 else:
178 tries += 1
179 time.sleep(1)
180 self.cliExit()
181 return False
182 except:
ChetanGaonker689b3862016-10-17 16:25:01 -0700183 raise Exception('Failed to get cluster members')
184 return False
ChetanGaonker2099d722016-10-07 15:16:58 -0700185
A.R Karthick45ab3e12016-11-30 11:25:51 -0800186 def get_cluster_current_member_ips(self, controller = None, nodes_filter = None):
ChetanGaonker2099d722016-10-07 15:16:58 -0700187 tries = 0
188 cluster_ips = []
189 try:
190 self.cliEnter(controller = controller)
191 while tries <= 10:
192 cluster_nodes = json.loads(self.cli.nodes(jsonFormat = True))
193 if cluster_nodes:
A R Karthick76a497a2017-04-12 10:59:39 -0700194 log_test.info("cluster 'nodes' output is %s"%cluster_nodes)
A.R Karthick45ab3e12016-11-30 11:25:51 -0800195 if nodes_filter:
196 cluster_nodes = nodes_filter(cluster_nodes)
ChetanGaonker2099d722016-10-07 15:16:58 -0700197 cluster_ips = map(lambda c: c['id'], cluster_nodes)
198 self.cliExit()
199 cluster_ips.sort(lambda i1,i2: int(i1.split('.')[-1]) - int(i2.split('.')[-1]))
200 return cluster_ips
201 else:
202 tries += 1
203 self.cliExit()
204 return cluster_ips
205 except:
206 raise Exception('Failed to get cluster members')
207 return cluster_ips
208
ChetanGaonker689b3862016-10-17 16:25:01 -0700209 def get_cluster_container_names_ips(self,controller=None):
A R Karthick1f908202016-11-16 17:32:20 -0800210 onos_names_ips = {}
A.R Karthickbe7768c2017-03-17 11:39:41 -0700211 controllers = get_controllers()
A R Karthick0f3f25b2016-12-15 09:50:57 -0800212 i = 0
213 for controller in controllers:
214 if i == 0:
215 name = Onos.NAME
216 else:
217 name = '{}-{}'.format(Onos.NAME, i+1)
218 onos_names_ips[controller] = name
219 onos_names_ips[name] = controller
220 i += 1
ChetanGaonker2099d722016-10-07 15:16:58 -0700221 return onos_names_ips
A R Karthick0f3f25b2016-12-15 09:50:57 -0800222 # onos_ips = self.get_cluster_current_member_ips(controller=controller)
223 # onos_names_ips[onos_ips[0]] = Onos.NAME
224 # onos_names_ips[Onos.NAME] = onos_ips[0]
225 # for i in range(1,len(onos_ips)):
226 # name = '{0}-{1}'.format(Onos.NAME,i+1)
227 # onos_names_ips[onos_ips[i]] = name
228 # onos_names_ips[name] = onos_ips[i]
229
230 # return onos_names_ips
ChetanGaonker2099d722016-10-07 15:16:58 -0700231
232 #identifying current master of a connected device, not tested
233 def get_cluster_current_master_standbys(self,controller=None,device_id=device_id):
234 master = None
235 standbys = []
236 tries = 0
237 try:
238 cli = self.cliEnter(controller = controller)
239 while tries <= 10:
240 roles = json.loads(self.cli.roles(jsonFormat = True))
A R Karthick76a497a2017-04-12 10:59:39 -0700241 log_test.info("cluster 'roles' command output is %s"%roles)
ChetanGaonker2099d722016-10-07 15:16:58 -0700242 if roles:
243 for device in roles:
A R Karthick76a497a2017-04-12 10:59:39 -0700244 log_test.info('Verifying device info in line %s'%device)
ChetanGaonker2099d722016-10-07 15:16:58 -0700245 if device['id'] == device_id:
246 master = str(device['master'])
247 standbys = map(lambda d: str(d), device['standbys'])
A R Karthick76a497a2017-04-12 10:59:39 -0700248 log_test.info('Master and standbys for device %s are %s and %s'%(device_id, master, standbys))
ChetanGaonker2099d722016-10-07 15:16:58 -0700249 self.cliExit()
250 return master, standbys
251 self.cliExit()
252 return master, standbys
253 else:
254 tries += 1
ChetanGaonker689b3862016-10-17 16:25:01 -0700255 time.sleep(1)
256 self.cliExit()
257 return master,standbys
258 except:
259 raise Exception('Failed to get cluster members')
260 return master,standbys
261
262 def get_cluster_current_master_standbys_of_connected_devices(self,controller=None):
263 ''' returns master and standbys of all the connected devices to ONOS cluster instance'''
264 device_dict = {}
265 tries = 0
266 try:
267 cli = self.cliEnter(controller = controller)
268 while tries <= 10:
269 device_dict = {}
270 roles = json.loads(self.cli.roles(jsonFormat = True))
A R Karthick76a497a2017-04-12 10:59:39 -0700271 log_test.info("cluster 'roles' command output is %s"%roles)
ChetanGaonker689b3862016-10-17 16:25:01 -0700272 if roles:
273 for device in roles:
274 device_dict[str(device['id'])]= {'master':str(device['master']),'standbys':device['standbys']}
275 for i in range(len(device_dict[device['id']]['standbys'])):
276 device_dict[device['id']]['standbys'][i] = str(device_dict[device['id']]['standbys'][i])
A R Karthick76a497a2017-04-12 10:59:39 -0700277 log_test.info('master and standbys for device %s are %s and %s'%(device['id'],device_dict[device['id']]['master'],device_dict[device['id']]['standbys']))
ChetanGaonker689b3862016-10-17 16:25:01 -0700278 self.cliExit()
279 return device_dict
280 else:
281 tries += 1
ChetanGaonker2099d722016-10-07 15:16:58 -0700282 time.sleep(1)
283 self.cliExit()
ChetanGaonker689b3862016-10-17 16:25:01 -0700284 return device_dict
285 except:
286 raise Exception('Failed to get cluster members')
287 return device_dict
288
289 #identify current master of a connected device, not tested
290 def get_cluster_connected_devices(self,controller=None):
291 '''returns all the devices connected to ONOS cluster'''
292 device_list = []
293 tries = 0
294 try:
295 cli = self.cliEnter(controller = controller)
296 while tries <= 10:
297 device_list = []
298 devices = json.loads(self.cli.devices(jsonFormat = True))
A R Karthick76a497a2017-04-12 10:59:39 -0700299 log_test.info("cluster 'devices' command output is %s"%devices)
ChetanGaonker689b3862016-10-17 16:25:01 -0700300 if devices:
301 for device in devices:
A R Karthick76a497a2017-04-12 10:59:39 -0700302 log_test.info('device id is %s'%device['id'])
ChetanGaonker689b3862016-10-17 16:25:01 -0700303 device_list.append(str(device['id']))
304 self.cliExit()
305 return device_list
306 else:
307 tries += 1
308 time.sleep(1)
309 self.cliExit()
310 return device_list
311 except:
312 raise Exception('Failed to get cluster members')
313 return device_list
314
315 def get_number_of_devices_of_master(self,controller=None):
316 '''returns master-device pairs, which master having what devices'''
317 master_count = {}
318 try:
319 cli = self.cliEnter(controller = controller)
320 masters = json.loads(self.cli.masters(jsonFormat = True))
321 if masters:
322 for master in masters:
323 master_count[str(master['id'])] = {'size':int(master['size']),'devices':master['devices']}
324 return master_count
325 else:
326 return master_count
ChetanGaonker2099d722016-10-07 15:16:58 -0700327 except:
ChetanGaonker689b3862016-10-17 16:25:01 -0700328 raise Exception('Failed to get cluster members')
329 return master_count
ChetanGaonker2099d722016-10-07 15:16:58 -0700330
331 def change_master_current_cluster(self,new_master=None,device_id=device_id,controller=None):
332 if new_master is None: return False
ChetanGaonker689b3862016-10-17 16:25:01 -0700333 self.cliEnter(controller=controller)
ChetanGaonker2099d722016-10-07 15:16:58 -0700334 cmd = 'device-role' + ' ' + device_id + ' ' + new_master + ' ' + 'master'
335 command = self.cli.command(cmd = cmd, jsonFormat = False)
336 self.cliExit()
337 time.sleep(60)
338 master, standbys = self.get_cluster_current_master_standbys(controller=controller,device_id=device_id)
339 assert_equal(master,new_master)
A R Karthick76a497a2017-04-12 10:59:39 -0700340 log_test.info('Cluster master changed to %s successfully'%new_master)
ChetanGaonker2099d722016-10-07 15:16:58 -0700341
ChetanGaonker689b3862016-10-17 16:25:01 -0700342 def withdraw_cluster_current_mastership(self,master_ip=None,device_id=device_id,controller=None):
343 '''current master looses its mastership and hence new master will be elected'''
344 self.cliEnter(controller=controller)
345 cmd = 'device-role' + ' ' + device_id + ' ' + master_ip + ' ' + 'none'
346 command = self.cli.command(cmd = cmd, jsonFormat = False)
347 self.cliExit()
348 time.sleep(60)
349 new_master_ip, standbys = self.get_cluster_current_master_standbys(controller=controller,device_id=device_id)
350 assert_not_equal(new_master_ip,master_ip)
A R Karthick76a497a2017-04-12 10:59:39 -0700351 log_test.info('Device-role of device %s successfully changed to none for controller %s'%(device_id,master_ip))
352 log_test.info('Cluster new master is %s'%new_master_ip)
ChetanGaonker689b3862016-10-17 16:25:01 -0700353 return True
354
A R Karthick3b2e0372016-12-14 17:37:43 -0800355 def cluster_controller_restarts(self, graceful = False):
A.R Karthickbe7768c2017-03-17 11:39:41 -0700356 controllers = get_controllers()
A R Karthick1f908202016-11-16 17:32:20 -0800357 ctlr_len = len(controllers)
358 if ctlr_len <= 1:
A R Karthick76a497a2017-04-12 10:59:39 -0700359 log_test.info('ONOS is not running in cluster mode. This test only works for cluster mode')
A R Karthick1f908202016-11-16 17:32:20 -0800360 assert_greater(ctlr_len, 1)
361
362 #this call would verify the cluster for once
363 onos_map = self.get_cluster_container_names_ips()
364
A R Karthick2a70a2f2016-12-16 14:40:16 -0800365 def check_exception(iteration, controller = None):
A R Karthick1f908202016-11-16 17:32:20 -0800366 adjacent_controller = None
367 adjacent_controllers = None
368 if controller:
A.R Karthick45ab3e12016-11-30 11:25:51 -0800369 adjacent_controllers = list(set(controllers) - set([controller]))
370 adjacent_controller = adjacent_controllers[0]
A R Karthick1f908202016-11-16 17:32:20 -0800371 for node in controllers:
372 onosLog = OnosLog(host = node)
373 ##check the logs for storage exception
374 _, output = onosLog.get_log(('ERROR', 'Exception',))
A R Karthickec2db322016-11-17 15:06:01 -0800375 if output and output.find('StorageException$Timeout') >= 0:
A R Karthick76a497a2017-04-12 10:59:39 -0700376 log_test.info('\nStorage Exception Timeout found on node: %s\n' %node)
377 log_test.info('Dumping the ERROR and Exception logs for node: %s\n' %node)
378 log_test.info('\n' + '-' * 50 + '\n')
379 log_test.info('%s' %output)
380 log_test.info('\n' + '-' * 50 + '\n')
A R Karthickec2db322016-11-17 15:06:01 -0800381 failed = self.verify_leaders(controllers)
382 if failed:
A R Karthick76a497a2017-04-12 10:59:39 -0700383 log_test.info('Leaders command failed on nodes: %s' %failed)
384 log_test.error('Test failed on ITERATION %d' %iteration)
A R Karthick81ece152017-01-11 16:46:43 -0800385 CordLogger.archive_results(self._testMethodName,
386 controllers = controllers,
A.R Karthick53d92702017-03-13 10:10:38 -0700387 iteration = 'FAILED',
388 archive_partition = self.ARCHIVE_PARTITION)
A R Karthickec2db322016-11-17 15:06:01 -0800389 assert_equal(len(failed), 0)
A R Karthick1f908202016-11-16 17:32:20 -0800390 return controller
391
392 try:
A R Karthickec2db322016-11-17 15:06:01 -0800393 ips = self.get_cluster_current_member_ips(controller = adjacent_controller)
A R Karthick76a497a2017-04-12 10:59:39 -0700394 log_test.info('ONOS cluster formed with controllers: %s' %ips)
A R Karthick1f908202016-11-16 17:32:20 -0800395 st = True
396 except:
397 st = False
398
A R Karthickec2db322016-11-17 15:06:01 -0800399 failed = self.verify_leaders(controllers)
A R Karthick2a70a2f2016-12-16 14:40:16 -0800400 if failed:
A R Karthick76a497a2017-04-12 10:59:39 -0700401 log_test.error('Test failed on ITERATION %d' %iteration)
A R Karthick3396ec42017-01-11 17:12:13 -0800402 CordLogger.archive_results(self._testMethodName,
403 controllers = controllers,
A.R Karthick53d92702017-03-13 10:10:38 -0700404 iteration = 'FAILED',
405 archive_partition = self.ARCHIVE_PARTITION)
A R Karthick1f908202016-11-16 17:32:20 -0800406 assert_equal(len(failed), 0)
A R Karthick1f908202016-11-16 17:32:20 -0800407 if st is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700408 log_test.info('No storage exception and ONOS cluster was not formed successfully')
A R Karthick1f908202016-11-16 17:32:20 -0800409 else:
410 controller = None
411
412 return controller
413
414 next_controller = None
A.R Karthick99044822017-02-09 14:04:20 -0800415 tries = self.ITERATIONS
A R Karthick1f908202016-11-16 17:32:20 -0800416 for num in range(tries):
417 index = num % ctlr_len
418 #index = random.randrange(0, ctlr_len)
A.R Karthick45ab3e12016-11-30 11:25:51 -0800419 controller_name = onos_map[controllers[index]] if next_controller is None else onos_map[next_controller]
420 controller = onos_map[controller_name]
A R Karthick76a497a2017-04-12 10:59:39 -0700421 log_test.info('ITERATION: %d. Restarting Controller %s' %(num + 1, controller_name))
A R Karthick1f908202016-11-16 17:32:20 -0800422 try:
A R Karthickef1232d2016-12-07 09:18:15 -0800423 #enable debug log for the other controllers before restarting this controller
A R Karthicke14fc022016-12-08 14:50:29 -0800424 adjacent_controllers = list( set(controllers) - set([controller]) )
425 self.log_set(controllers = adjacent_controllers)
426 self.log_set(app = 'io.atomix', controllers = adjacent_controllers)
A R Karthick3b2e0372016-12-14 17:37:43 -0800427 if graceful is True:
A R Karthick76a497a2017-04-12 10:59:39 -0700428 log_test.info('Gracefully shutting down controller: %s' %controller)
A R Karthick3b2e0372016-12-14 17:37:43 -0800429 self.onos_shutdown(controller)
430 cord_test_onos_restart(node = controller, timeout = 0)
A R Karthicke14fc022016-12-08 14:50:29 -0800431 self.log_set(controllers = controller)
432 self.log_set(app = 'io.atomix', controllers = controller)
A R Karthickde6b9dc2016-11-29 17:46:16 -0800433 time.sleep(60)
A R Karthick1f908202016-11-16 17:32:20 -0800434 except:
435 time.sleep(5)
436 continue
A R Karthicke8935c62016-12-08 18:17:17 -0800437
438 #first archive the test case logs for this run
A R Karthick3b2e0372016-12-14 17:37:43 -0800439 CordLogger.archive_results(self._testMethodName,
A R Karthicke8935c62016-12-08 18:17:17 -0800440 controllers = controllers,
A.R Karthick53d92702017-03-13 10:10:38 -0700441 iteration = 'iteration_{}'.format(num+1),
442 archive_partition = self.ARCHIVE_PARTITION)
A R Karthick2a70a2f2016-12-16 14:40:16 -0800443 next_controller = check_exception(num, controller = controller)
A R Karthick1f908202016-11-16 17:32:20 -0800444
A R Karthick3b2e0372016-12-14 17:37:43 -0800445 def test_cluster_controller_restarts(self):
446 '''Test the cluster by repeatedly killing the controllers'''
447 self.cluster_controller_restarts()
448
449 def test_cluster_graceful_controller_restarts(self):
450 '''Test the cluster by repeatedly restarting the controllers gracefully'''
451 self.cluster_controller_restarts(graceful = True)
452
A.R Karthick45ab3e12016-11-30 11:25:51 -0800453 def test_cluster_single_controller_restarts(self):
454 '''Test the cluster by repeatedly restarting the same controller'''
A.R Karthickbe7768c2017-03-17 11:39:41 -0700455 controllers = get_controllers()
A.R Karthick45ab3e12016-11-30 11:25:51 -0800456 ctlr_len = len(controllers)
457 if ctlr_len <= 1:
A R Karthick76a497a2017-04-12 10:59:39 -0700458 log_test.info('ONOS is not running in cluster mode. This test only works for cluster mode')
A.R Karthick45ab3e12016-11-30 11:25:51 -0800459 assert_greater(ctlr_len, 1)
460
461 #this call would verify the cluster for once
462 onos_map = self.get_cluster_container_names_ips()
463
A R Karthick2a70a2f2016-12-16 14:40:16 -0800464 def check_exception(iteration, controller, inclusive = False):
A.R Karthick45ab3e12016-11-30 11:25:51 -0800465 adjacent_controllers = list(set(controllers) - set([controller]))
466 adjacent_controller = adjacent_controllers[0]
467 controller_list = adjacent_controllers if inclusive == False else controllers
468 storage_exceptions = []
469 for node in controller_list:
470 onosLog = OnosLog(host = node)
471 ##check the logs for storage exception
472 _, output = onosLog.get_log(('ERROR', 'Exception',))
473 if output and output.find('StorageException$Timeout') >= 0:
A R Karthick76a497a2017-04-12 10:59:39 -0700474 log_test.info('\nStorage Exception Timeout found on node: %s\n' %node)
475 log_test.info('Dumping the ERROR and Exception logs for node: %s\n' %node)
476 log_test.info('\n' + '-' * 50 + '\n')
477 log_test.info('%s' %output)
478 log_test.info('\n' + '-' * 50 + '\n')
A.R Karthick45ab3e12016-11-30 11:25:51 -0800479 storage_exceptions.append(node)
480
481 failed = self.verify_leaders(controller_list)
482 if failed:
A R Karthick76a497a2017-04-12 10:59:39 -0700483 log_test.info('Leaders command failed on nodes: %s' %failed)
A.R Karthick45ab3e12016-11-30 11:25:51 -0800484 if storage_exceptions:
A R Karthick76a497a2017-04-12 10:59:39 -0700485 log_test.info('Storage exception seen on nodes: %s' %storage_exceptions)
486 log_test.error('Test failed on ITERATION %d' %iteration)
A R Karthick81ece152017-01-11 16:46:43 -0800487 CordLogger.archive_results('test_cluster_single_controller_restarts',
488 controllers = controllers,
A.R Karthick53d92702017-03-13 10:10:38 -0700489 iteration = 'FAILED',
490 archive_partition = self.ARCHIVE_PARTITION)
A.R Karthick45ab3e12016-11-30 11:25:51 -0800491 assert_equal(len(failed), 0)
492 return controller
493
494 for ctlr in controller_list:
495 ips = self.get_cluster_current_member_ips(controller = ctlr,
496 nodes_filter = \
497 lambda nodes: [ n for n in nodes if n['state'] in [ 'ACTIVE', 'READY'] ])
A R Karthick76a497a2017-04-12 10:59:39 -0700498 log_test.info('ONOS cluster on node %s formed with controllers: %s' %(ctlr, ips))
A.R Karthick45ab3e12016-11-30 11:25:51 -0800499 if controller in ips and inclusive is False:
A R Karthick76a497a2017-04-12 10:59:39 -0700500 log_test.info('Controller %s still ACTIVE on Node %s after it was shutdown' %(controller, ctlr))
A.R Karthick45ab3e12016-11-30 11:25:51 -0800501 if controller not in ips and inclusive is True:
A R Karthick76a497a2017-04-12 10:59:39 -0700502 log_test.info('Controller %s still INACTIVE on Node %s after it was restarted' %(controller, ctlr))
A.R Karthick45ab3e12016-11-30 11:25:51 -0800503
504 return controller
505
A.R Karthick99044822017-02-09 14:04:20 -0800506 tries = self.ITERATIONS
A.R Karthick45ab3e12016-11-30 11:25:51 -0800507 #chose a random controller for shutdown/restarts
508 controller = controllers[random.randrange(0, ctlr_len)]
509 controller_name = onos_map[controller]
A R Karthick6cc8b812016-12-09 10:24:40 -0800510 ##enable the log level for the controllers
511 self.log_set(controllers = controllers)
512 self.log_set(app = 'io.atomix', controllers = controllers)
A.R Karthick45ab3e12016-11-30 11:25:51 -0800513 for num in range(tries):
A R Karthick76a497a2017-04-12 10:59:39 -0700514 log_test.info('ITERATION: %d. Shutting down Controller %s' %(num + 1, controller_name))
A.R Karthick45ab3e12016-11-30 11:25:51 -0800515 try:
A R Karthick3b2e0372016-12-14 17:37:43 -0800516 cord_test_onos_shutdown(node = controller)
A.R Karthick45ab3e12016-11-30 11:25:51 -0800517 time.sleep(20)
518 except:
519 time.sleep(5)
520 continue
521 #check for exceptions on the adjacent nodes
A R Karthick2a70a2f2016-12-16 14:40:16 -0800522 check_exception(num, controller)
A.R Karthick45ab3e12016-11-30 11:25:51 -0800523 #Now restart the controller back
A R Karthick76a497a2017-04-12 10:59:39 -0700524 log_test.info('Restarting back the controller %s' %controller_name)
A R Karthick3b2e0372016-12-14 17:37:43 -0800525 cord_test_onos_restart(node = controller)
A R Karthick6cc8b812016-12-09 10:24:40 -0800526 self.log_set(controllers = controller)
527 self.log_set(app = 'io.atomix', controllers = controller)
A.R Karthick45ab3e12016-11-30 11:25:51 -0800528 time.sleep(60)
A R Karthicke8935c62016-12-08 18:17:17 -0800529 #archive the logs for this run
530 CordLogger.archive_results('test_cluster_single_controller_restarts',
531 controllers = controllers,
A.R Karthick53d92702017-03-13 10:10:38 -0700532 iteration = 'iteration_{}'.format(num+1),
533 archive_partition = self.ARCHIVE_PARTITION)
A R Karthick2a70a2f2016-12-16 14:40:16 -0800534 check_exception(num, controller, inclusive = True)
A.R Karthick45ab3e12016-11-30 11:25:51 -0800535
A.R Karthick2560f042016-11-30 14:38:52 -0800536 def test_cluster_restarts(self):
537 '''Test the cluster by repeatedly restarting the entire cluster'''
A.R Karthickbe7768c2017-03-17 11:39:41 -0700538 controllers = get_controllers()
A.R Karthick2560f042016-11-30 14:38:52 -0800539 ctlr_len = len(controllers)
540 if ctlr_len <= 1:
A R Karthick76a497a2017-04-12 10:59:39 -0700541 log_test.info('ONOS is not running in cluster mode. This test only works for cluster mode')
A.R Karthick2560f042016-11-30 14:38:52 -0800542 assert_greater(ctlr_len, 1)
543
544 #this call would verify the cluster for once
545 onos_map = self.get_cluster_container_names_ips()
546
A R Karthick2a70a2f2016-12-16 14:40:16 -0800547 def check_exception(iteration):
A.R Karthick2560f042016-11-30 14:38:52 -0800548 controller_list = controllers
549 storage_exceptions = []
550 for node in controller_list:
551 onosLog = OnosLog(host = node)
552 ##check the logs for storage exception
553 _, output = onosLog.get_log(('ERROR', 'Exception',))
554 if output and output.find('StorageException$Timeout') >= 0:
A R Karthick76a497a2017-04-12 10:59:39 -0700555 log_test.info('\nStorage Exception Timeout found on node: %s\n' %node)
556 log_test.info('Dumping the ERROR and Exception logs for node: %s\n' %node)
557 log_test.info('\n' + '-' * 50 + '\n')
558 log_test.info('%s' %output)
559 log_test.info('\n' + '-' * 50 + '\n')
A.R Karthick2560f042016-11-30 14:38:52 -0800560 storage_exceptions.append(node)
561
562 failed = self.verify_leaders(controller_list)
563 if failed:
A R Karthick76a497a2017-04-12 10:59:39 -0700564 log_test.info('Leaders command failed on nodes: %s' %failed)
A.R Karthick2560f042016-11-30 14:38:52 -0800565 if storage_exceptions:
A R Karthick76a497a2017-04-12 10:59:39 -0700566 log_test.info('Storage exception seen on nodes: %s' %storage_exceptions)
567 log_test.error('Test failed on ITERATION %d' %iteration)
A R Karthick81ece152017-01-11 16:46:43 -0800568 CordLogger.archive_results('test_cluster_restarts',
569 controllers = controllers,
A.R Karthick53d92702017-03-13 10:10:38 -0700570 iteration = 'FAILED',
571 archive_partition = self.ARCHIVE_PARTITION)
A.R Karthick2560f042016-11-30 14:38:52 -0800572 assert_equal(len(failed), 0)
573 return
574
575 for ctlr in controller_list:
576 ips = self.get_cluster_current_member_ips(controller = ctlr,
577 nodes_filter = \
578 lambda nodes: [ n for n in nodes if n['state'] in [ 'ACTIVE', 'READY'] ])
A R Karthick76a497a2017-04-12 10:59:39 -0700579 log_test.info('ONOS cluster on node %s formed with controllers: %s' %(ctlr, ips))
A R Karthick2a70a2f2016-12-16 14:40:16 -0800580 if len(ips) != len(controllers):
A R Karthick76a497a2017-04-12 10:59:39 -0700581 log_test.error('Test failed on ITERATION %d' %iteration)
A R Karthick81ece152017-01-11 16:46:43 -0800582 CordLogger.archive_results('test_cluster_restarts',
583 controllers = controllers,
A.R Karthick53d92702017-03-13 10:10:38 -0700584 iteration = 'FAILED',
585 archive_partition = self.ARCHIVE_PARTITION)
A.R Karthick2560f042016-11-30 14:38:52 -0800586 assert_equal(len(ips), len(controllers))
587
A.R Karthick99044822017-02-09 14:04:20 -0800588 tries = self.ITERATIONS
A.R Karthick2560f042016-11-30 14:38:52 -0800589 for num in range(tries):
A R Karthick76a497a2017-04-12 10:59:39 -0700590 log_test.info('ITERATION: %d. Restarting cluster with controllers at %s' %(num+1, controllers))
A.R Karthick2560f042016-11-30 14:38:52 -0800591 try:
592 cord_test_restart_cluster()
A R Karthick6cc8b812016-12-09 10:24:40 -0800593 self.log_set(controllers = controllers)
594 self.log_set(app = 'io.atomix', controllers = controllers)
A R Karthick76a497a2017-04-12 10:59:39 -0700595 log_test.info('Delaying before verifying cluster status')
A.R Karthick2560f042016-11-30 14:38:52 -0800596 time.sleep(60)
597 except:
598 time.sleep(10)
599 continue
A R Karthicke8935c62016-12-08 18:17:17 -0800600
601 #archive the logs for this run before verification
602 CordLogger.archive_results('test_cluster_restarts',
603 controllers = controllers,
A.R Karthick53d92702017-03-13 10:10:38 -0700604 iteration = 'iteration_{}'.format(num+1),
605 archive_partition = self.ARCHIVE_PARTITION)
A.R Karthick2560f042016-11-30 14:38:52 -0800606 #check for exceptions on the adjacent nodes
A R Karthick2a70a2f2016-12-16 14:40:16 -0800607 check_exception(num)
A.R Karthick2560f042016-11-30 14:38:52 -0800608
ChetanGaonker2099d722016-10-07 15:16:58 -0700609 #pass
ChetanGaonker689b3862016-10-17 16:25:01 -0700610 def test_cluster_formation_and_verification(self,onos_instances = ONOS_INSTANCES):
611 status = self.verify_cluster_status(onos_instances = onos_instances)
612 assert_equal(status, True)
A R Karthick76a497a2017-04-12 10:59:39 -0700613 log_test.info('Cluster exists with %d ONOS instances'%onos_instances)
ChetanGaonker2099d722016-10-07 15:16:58 -0700614
615 #nottest cluster not coming up properly if member goes down
ChetanGaonker689b3862016-10-17 16:25:01 -0700616 def test_cluster_adding_members(self, add = 2, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700617 status = self.verify_cluster_status(onos_instances = onos_instances)
618 assert_equal(status, True)
619 onos_ips = self.get_cluster_current_member_ips()
620 onos_instances = len(onos_ips)+add
A R Karthick76a497a2017-04-12 10:59:39 -0700621 log_test.info('Adding %d nodes to the ONOS cluster' %add)
ChetanGaonker2099d722016-10-07 15:16:58 -0700622 cord_test_onos_add_cluster(count = add)
623 status = self.verify_cluster_status(onos_instances=onos_instances)
624 assert_equal(status, True)
625
ChetanGaonker689b3862016-10-17 16:25:01 -0700626 def test_cluster_removing_master(self, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700627 status = self.verify_cluster_status(onos_instances = onos_instances)
628 assert_equal(status, True)
629 master, standbys = self.get_cluster_current_master_standbys()
630 assert_equal(len(standbys),(onos_instances-1))
631 onos_names_ips = self.get_cluster_container_names_ips()
632 master_onos_name = onos_names_ips[master]
A R Karthick76a497a2017-04-12 10:59:39 -0700633 log_test.info('Removing cluster current master %s'%(master))
A R Karthick3b2e0372016-12-14 17:37:43 -0800634 cord_test_onos_shutdown(node = master)
ChetanGaonker2099d722016-10-07 15:16:58 -0700635 time.sleep(60)
636 onos_instances -= 1
637 status = self.verify_cluster_status(onos_instances = onos_instances,controller=standbys[0])
638 assert_equal(status, True)
639 new_master, standbys = self.get_cluster_current_master_standbys(controller=standbys[0])
640 assert_not_equal(master,new_master)
A R Karthick76a497a2017-04-12 10:59:39 -0700641 log_test.info('Successfully removed clusters master instance')
ChetanGaonker2099d722016-10-07 15:16:58 -0700642
ChetanGaonker689b3862016-10-17 16:25:01 -0700643 def test_cluster_removing_one_member(self, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700644 status = self.verify_cluster_status(onos_instances = onos_instances)
645 assert_equal(status, True)
646 master, standbys = self.get_cluster_current_master_standbys()
647 assert_equal(len(standbys),(onos_instances-1))
648 onos_names_ips = self.get_cluster_container_names_ips()
649 member_onos_name = onos_names_ips[standbys[0]]
A R Karthick76a497a2017-04-12 10:59:39 -0700650 log_test.info('Removing cluster member %s'%standbys[0])
A R Karthick3b2e0372016-12-14 17:37:43 -0800651 cord_test_onos_shutdown(node = standbys[0])
ChetanGaonker2099d722016-10-07 15:16:58 -0700652 time.sleep(60)
653 onos_instances -= 1
654 status = self.verify_cluster_status(onos_instances = onos_instances,controller=master)
655 assert_equal(status, True)
656
ChetanGaonker689b3862016-10-17 16:25:01 -0700657 def test_cluster_removing_two_members(self,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700658 status = self.verify_cluster_status(onos_instances = onos_instances)
659 assert_equal(status, True)
660 master, standbys = self.get_cluster_current_master_standbys()
661 assert_equal(len(standbys),(onos_instances-1))
662 onos_names_ips = self.get_cluster_container_names_ips()
663 member1_onos_name = onos_names_ips[standbys[0]]
664 member2_onos_name = onos_names_ips[standbys[1]]
A R Karthick76a497a2017-04-12 10:59:39 -0700665 log_test.info('Removing cluster member %s'%standbys[0])
A R Karthick3b2e0372016-12-14 17:37:43 -0800666 cord_test_onos_shutdown(node = standbys[0])
A R Karthick76a497a2017-04-12 10:59:39 -0700667 log_test.info('Removing cluster member %s'%standbys[1])
A R Karthick3b2e0372016-12-14 17:37:43 -0800668 cord_test_onos_shutdown(node = standbys[1])
ChetanGaonker2099d722016-10-07 15:16:58 -0700669 time.sleep(60)
670 onos_instances = onos_instances - 2
671 status = self.verify_cluster_status(onos_instances = onos_instances,controller=master)
672 assert_equal(status, True)
673
ChetanGaonker689b3862016-10-17 16:25:01 -0700674 def test_cluster_removing_N_members(self,remove = 2, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700675 status = self.verify_cluster_status(onos_instances = onos_instances)
676 assert_equal(status, True)
677 master, standbys = self.get_cluster_current_master_standbys()
678 assert_equal(len(standbys),(onos_instances-1))
679 onos_names_ips = self.get_cluster_container_names_ips()
680 for i in range(remove):
681 member_onos_name = onos_names_ips[standbys[i]]
A R Karthick76a497a2017-04-12 10:59:39 -0700682 log_test.info('Removing onos container with name %s'%standbys[i])
A R Karthick3b2e0372016-12-14 17:37:43 -0800683 cord_test_onos_shutdown(node = standbys[i])
ChetanGaonker2099d722016-10-07 15:16:58 -0700684 time.sleep(60)
685 onos_instances = onos_instances - remove
686 status = self.verify_cluster_status(onos_instances = onos_instances, controller=master)
687 assert_equal(status, True)
688
689 #nottest test cluster not coming up properly if member goes down
ChetanGaonker689b3862016-10-17 16:25:01 -0700690 def test_cluster_adding_and_removing_members(self,onos_instances = ONOS_INSTANCES , add = 2, remove = 2):
ChetanGaonker2099d722016-10-07 15:16:58 -0700691 status = self.verify_cluster_status(onos_instances = onos_instances)
692 assert_equal(status, True)
693 onos_ips = self.get_cluster_current_member_ips()
694 onos_instances = len(onos_ips)+add
A R Karthick76a497a2017-04-12 10:59:39 -0700695 log_test.info('Adding %d ONOS instances to the cluster'%add)
ChetanGaonker2099d722016-10-07 15:16:58 -0700696 cord_test_onos_add_cluster(count = add)
697 status = self.verify_cluster_status(onos_instances=onos_instances)
698 assert_equal(status, True)
A R Karthick76a497a2017-04-12 10:59:39 -0700699 log_test.info('Removing %d ONOS instances from the cluster'%remove)
ChetanGaonker2099d722016-10-07 15:16:58 -0700700 for i in range(remove):
701 name = '{}-{}'.format(Onos.NAME, onos_instances - i)
A R Karthick76a497a2017-04-12 10:59:39 -0700702 log_test.info('Removing onos container with name %s'%name)
ChetanGaonker2099d722016-10-07 15:16:58 -0700703 cord_test_onos_shutdown(node = name)
704 time.sleep(60)
705 onos_instances = onos_instances-remove
706 status = self.verify_cluster_status(onos_instances=onos_instances)
707 assert_equal(status, True)
708
709 #nottest cluster not coming up properly if member goes down
ChetanGaonker689b3862016-10-17 16:25:01 -0700710 def test_cluster_removing_and_adding_member(self,onos_instances = ONOS_INSTANCES,add = 1, remove = 1):
ChetanGaonker2099d722016-10-07 15:16:58 -0700711 status = self.verify_cluster_status(onos_instances = onos_instances)
712 assert_equal(status, True)
713 onos_ips = self.get_cluster_current_member_ips()
714 onos_instances = onos_instances-remove
A R Karthick76a497a2017-04-12 10:59:39 -0700715 log_test.info('Removing %d ONOS instances from the cluster'%remove)
ChetanGaonker2099d722016-10-07 15:16:58 -0700716 for i in range(remove):
717 name = '{}-{}'.format(Onos.NAME, len(onos_ips)-i)
A R Karthick76a497a2017-04-12 10:59:39 -0700718 log_test.info('Removing onos container with name %s'%name)
ChetanGaonker2099d722016-10-07 15:16:58 -0700719 cord_test_onos_shutdown(node = name)
720 time.sleep(60)
721 status = self.verify_cluster_status(onos_instances=onos_instances)
722 assert_equal(status, True)
A R Karthick76a497a2017-04-12 10:59:39 -0700723 log_test.info('Adding %d ONOS instances to the cluster'%add)
ChetanGaonker2099d722016-10-07 15:16:58 -0700724 cord_test_onos_add_cluster(count = add)
725 onos_instances = onos_instances+add
726 status = self.verify_cluster_status(onos_instances=onos_instances)
727 assert_equal(status, True)
728
ChetanGaonker689b3862016-10-17 16:25:01 -0700729 def test_cluster_restart(self, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700730 status = self.verify_cluster_status(onos_instances = onos_instances)
731 assert_equal(status, True)
A R Karthick76a497a2017-04-12 10:59:39 -0700732 log_test.info('Restarting cluster')
ChetanGaonker2099d722016-10-07 15:16:58 -0700733 cord_test_onos_restart()
734 status = self.verify_cluster_status(onos_instances = onos_instances)
735 assert_equal(status, True)
736
ChetanGaonker689b3862016-10-17 16:25:01 -0700737 def test_cluster_master_restart(self,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700738 status = self.verify_cluster_status(onos_instances = onos_instances)
739 assert_equal(status, True)
740 master, standbys = self.get_cluster_current_master_standbys()
741 onos_names_ips = self.get_cluster_container_names_ips()
742 master_onos_name = onos_names_ips[master]
A R Karthick76a497a2017-04-12 10:59:39 -0700743 log_test.info('Restarting cluster master %s'%master)
A R Karthick3b2e0372016-12-14 17:37:43 -0800744 cord_test_onos_restart(node = master)
ChetanGaonker2099d722016-10-07 15:16:58 -0700745 status = self.verify_cluster_status(onos_instances = onos_instances)
746 assert_equal(status, True)
A R Karthick76a497a2017-04-12 10:59:39 -0700747 log_test.info('Cluster came up after master restart as expected')
ChetanGaonker2099d722016-10-07 15:16:58 -0700748
749 #test fail. master changing after restart. Need to check correct behavior.
ChetanGaonker689b3862016-10-17 16:25:01 -0700750 def test_cluster_master_ip_after_master_restart(self,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700751 status = self.verify_cluster_status(onos_instances = onos_instances)
752 assert_equal(status, True)
753 master1, standbys = self.get_cluster_current_master_standbys()
754 onos_names_ips = self.get_cluster_container_names_ips()
755 master_onos_name = onos_names_ips[master1]
A R Karthick76a497a2017-04-12 10:59:39 -0700756 log_test.info('Restarting cluster master %s'%master1)
A R Karthick3b2e0372016-12-14 17:37:43 -0800757 cord_test_onos_restart(node = master1)
ChetanGaonker2099d722016-10-07 15:16:58 -0700758 status = self.verify_cluster_status(onos_instances = onos_instances)
759 assert_equal(status, True)
760 master2, standbys = self.get_cluster_current_master_standbys()
761 assert_equal(master1,master2)
A R Karthick76a497a2017-04-12 10:59:39 -0700762 log_test.info('Cluster master is same before and after cluster master restart as expected')
ChetanGaonker2099d722016-10-07 15:16:58 -0700763
ChetanGaonker689b3862016-10-17 16:25:01 -0700764 def test_cluster_one_member_restart(self,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700765 status = self.verify_cluster_status(onos_instances = onos_instances)
766 assert_equal(status, True)
767 master, standbys = self.get_cluster_current_master_standbys()
768 assert_equal(len(standbys),(onos_instances-1))
769 onos_names_ips = self.get_cluster_container_names_ips()
770 member_onos_name = onos_names_ips[standbys[0]]
A R Karthick76a497a2017-04-12 10:59:39 -0700771 log_test.info('Restarting cluster member %s'%standbys[0])
A R Karthick3b2e0372016-12-14 17:37:43 -0800772 cord_test_onos_restart(node = standbys[0])
ChetanGaonker2099d722016-10-07 15:16:58 -0700773 status = self.verify_cluster_status(onos_instances = onos_instances)
774 assert_equal(status, True)
A R Karthick76a497a2017-04-12 10:59:39 -0700775 log_test.info('Cluster came up as expected after restarting one member')
ChetanGaonker2099d722016-10-07 15:16:58 -0700776
ChetanGaonker689b3862016-10-17 16:25:01 -0700777 def test_cluster_two_members_restart(self,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700778 status = self.verify_cluster_status(onos_instances = onos_instances)
779 assert_equal(status, True)
780 master, standbys = self.get_cluster_current_master_standbys()
781 assert_equal(len(standbys),(onos_instances-1))
782 onos_names_ips = self.get_cluster_container_names_ips()
783 member1_onos_name = onos_names_ips[standbys[0]]
784 member2_onos_name = onos_names_ips[standbys[1]]
A R Karthick76a497a2017-04-12 10:59:39 -0700785 log_test.info('Restarting cluster members %s and %s'%(standbys[0],standbys[1]))
A R Karthick3b2e0372016-12-14 17:37:43 -0800786 cord_test_onos_restart(node = standbys[0])
787 cord_test_onos_restart(node = standbys[1])
ChetanGaonker2099d722016-10-07 15:16:58 -0700788 status = self.verify_cluster_status(onos_instances = onos_instances)
789 assert_equal(status, True)
A R Karthick76a497a2017-04-12 10:59:39 -0700790 log_test.info('Cluster came up as expected after restarting two members')
ChetanGaonker2099d722016-10-07 15:16:58 -0700791
ChetanGaonker689b3862016-10-17 16:25:01 -0700792 def test_cluster_state_with_N_members_restart(self, members = 2, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700793 status = self.verify_cluster_status(onos_instances = onos_instances)
794 assert_equal(status,True)
795 master, standbys = self.get_cluster_current_master_standbys()
796 assert_equal(len(standbys),(onos_instances-1))
797 onos_names_ips = self.get_cluster_container_names_ips()
798 for i in range(members):
799 member_onos_name = onos_names_ips[standbys[i]]
A R Karthick76a497a2017-04-12 10:59:39 -0700800 log_test.info('Restarting cluster member %s'%standbys[i])
A R Karthick3b2e0372016-12-14 17:37:43 -0800801 cord_test_onos_restart(node = standbys[i])
ChetanGaonker2099d722016-10-07 15:16:58 -0700802
803 status = self.verify_cluster_status(onos_instances = onos_instances)
804 assert_equal(status, True)
A R Karthick76a497a2017-04-12 10:59:39 -0700805 log_test.info('Cluster came up as expected after restarting %d members'%members)
ChetanGaonker2099d722016-10-07 15:16:58 -0700806
ChetanGaonker689b3862016-10-17 16:25:01 -0700807 def test_cluster_state_with_master_change(self,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700808 status = self.verify_cluster_status(onos_instances=onos_instances)
809 assert_equal(status, True)
810 master, standbys = self.get_cluster_current_master_standbys()
811 assert_equal(len(standbys),(onos_instances-1))
A R Karthick76a497a2017-04-12 10:59:39 -0700812 log_test.info('Cluster current master of devices is %s'%master)
ChetanGaonker2099d722016-10-07 15:16:58 -0700813 self.change_master_current_cluster(new_master=standbys[0])
A R Karthick76a497a2017-04-12 10:59:39 -0700814 log_test.info('Cluster master changed successfully')
ChetanGaonker2099d722016-10-07 15:16:58 -0700815
816 #tested on single onos setup.
ChetanGaonker689b3862016-10-17 16:25:01 -0700817 def test_cluster_with_vrouter_routes_in_cluster_members(self,networks = 5,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700818 status = self.verify_cluster_status(onos_instances = onos_instances)
819 assert_equal(status, True)
820 onos_ips = self.get_cluster_current_member_ips()
821 self.vrouter.setUpClass()
822 res = self.vrouter.vrouter_network_verify(networks, peers = 1)
823 assert_equal(res, True)
824 for onos_ip in onos_ips:
825 tries = 0
826 flag = False
827 try:
828 self.cliEnter(controller = onos_ip)
829 while tries <= 5:
830 routes = json.loads(self.cli.routes(jsonFormat = True))
831 if routes:
832 assert_equal(len(routes['routes4']), networks)
833 self.cliExit()
834 flag = True
835 break
836 else:
837 tries += 1
838 time.sleep(1)
839 assert_equal(flag, True)
840 except:
A R Karthick76a497a2017-04-12 10:59:39 -0700841 log_test.info('Exception occured while checking routes in onos instance %s'%onos_ip)
ChetanGaonker2099d722016-10-07 15:16:58 -0700842 raise
843
844 #tested on single onos setup.
ChetanGaonker689b3862016-10-17 16:25:01 -0700845 def test_cluster_with_vrouter_and_master_down(self,networks = 5, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700846 status = self.verify_cluster_status(onos_instances = onos_instances)
847 assert_equal(status, True)
848 onos_ips = self.get_cluster_current_member_ips()
849 master, standbys = self.get_cluster_current_master_standbys()
850 onos_names_ips = self.get_cluster_container_names_ips()
851 master_onos_name = onos_names_ips[master]
852 self.vrouter.setUpClass()
853 res = self.vrouter.vrouter_network_verify(networks, peers = 1)
854 assert_equal(res,True)
A R Karthick3b2e0372016-12-14 17:37:43 -0800855 cord_test_onos_shutdown(node = master)
ChetanGaonker2099d722016-10-07 15:16:58 -0700856 time.sleep(60)
A R Karthick76a497a2017-04-12 10:59:39 -0700857 log_test.info('Verifying vrouter traffic after cluster master is down')
ChetanGaonker2099d722016-10-07 15:16:58 -0700858 self.vrouter.vrouter_traffic_verify()
859
860 #tested on single onos setup.
ChetanGaonker689b3862016-10-17 16:25:01 -0700861 def test_cluster_with_vrouter_and_restarting_master(self,networks = 5,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700862 status = self.verify_cluster_status(onos_instances = onos_instances)
863 assert_equal(status, True)
864 onos_ips = self.get_cluster_current_member_ips()
865 master, standbys = self.get_cluster_current_master_standbys()
866 onos_names_ips = self.get_cluster_container_names_ips()
867 master_onos_name = onos_names_ips[master]
868 self.vrouter.setUpClass()
869 res = self.vrouter.vrouter_network_verify(networks, peers = 1)
870 assert_equal(res, True)
871 cord_test_onos_restart()
872 self.vrouter.vrouter_traffic_verify()
873
874 #tested on single onos setup.
ChetanGaonker689b3862016-10-17 16:25:01 -0700875 def test_cluster_deactivating_vrouter_app(self,networks = 5, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700876 status = self.verify_cluster_status(onos_instances = onos_instances)
877 assert_equal(status, True)
878 self.vrouter.setUpClass()
879 res = self.vrouter.vrouter_network_verify(networks, peers = 1)
880 assert_equal(res, True)
881 self.vrouter.vrouter_activate(deactivate=True)
882 time.sleep(15)
883 self.vrouter.vrouter_traffic_verify(positive_test=False)
884 self.vrouter.vrouter_activate(deactivate=False)
885
886 #tested on single onos setup.
ChetanGaonker689b3862016-10-17 16:25:01 -0700887 def test_cluster_deactivating_vrouter_app_and_making_master_down(self,networks = 5,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700888 status = self.verify_cluster_status(onos_instances = onos_instances)
889 assert_equal(status, True)
890 master, standbys = self.get_cluster_current_master_standbys()
891 onos_names_ips = self.get_cluster_container_names_ips()
892 master_onos_name = onos_names_ips[master]
893 self.vrouter.setUpClass()
A R Karthick76a497a2017-04-12 10:59:39 -0700894 log_test.info('Verifying vrouter before master down')
ChetanGaonker2099d722016-10-07 15:16:58 -0700895 res = self.vrouter.vrouter_network_verify(networks, peers = 1)
896 assert_equal(res, True)
897 self.vrouter.vrouter_activate(deactivate=True)
A R Karthick76a497a2017-04-12 10:59:39 -0700898 log_test.info('Verifying vrouter traffic after app deactivated')
ChetanGaonker2099d722016-10-07 15:16:58 -0700899 time.sleep(15) ## Expecting vrouter should work properly if master of cluster goes down
900 self.vrouter.vrouter_traffic_verify(positive_test=False)
A R Karthick76a497a2017-04-12 10:59:39 -0700901 log_test.info('Verifying vrouter traffic after master down')
A R Karthick3b2e0372016-12-14 17:37:43 -0800902 cord_test_onos_shutdown(node = master)
ChetanGaonker2099d722016-10-07 15:16:58 -0700903 time.sleep(60)
904 self.vrouter.vrouter_traffic_verify(positive_test=False)
905 self.vrouter.vrouter_activate(deactivate=False)
906
907 #tested on single onos setup.
ChetanGaonker689b3862016-10-17 16:25:01 -0700908 def test_cluster_for_vrouter_app_and_making_member_down(self, networks = 5,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700909 status = self.verify_cluster_status(onos_instances = onos_instances)
910 assert_equal(status, True)
911 master, standbys = self.get_cluster_current_master_standbys()
912 onos_names_ips = self.get_cluster_container_names_ips()
913 member_onos_name = onos_names_ips[standbys[0]]
914 self.vrouter.setUpClass()
A R Karthick76a497a2017-04-12 10:59:39 -0700915 log_test.info('Verifying vrouter before cluster member down')
ChetanGaonker2099d722016-10-07 15:16:58 -0700916 res = self.vrouter.vrouter_network_verify(networks, peers = 1)
917 assert_equal(res, True) # Expecting vrouter should work properly
A R Karthick76a497a2017-04-12 10:59:39 -0700918 log_test.info('Verifying vrouter after cluster member down')
A R Karthick3b2e0372016-12-14 17:37:43 -0800919 cord_test_onos_shutdown(node = standbys[0])
ChetanGaonker2099d722016-10-07 15:16:58 -0700920 time.sleep(60)
921 self.vrouter.vrouter_traffic_verify()# Expecting vrouter should work properly if member of cluster goes down
922
923 #tested on single onos setup.
ChetanGaonker689b3862016-10-17 16:25:01 -0700924 def test_cluster_for_vrouter_app_and_restarting_member(self,networks = 5, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700925 status = self.verify_cluster_status(onos_instances = onos_instances)
926 assert_equal(status, True)
927 master, standbys = self.get_cluster_current_master_standbys()
928 onos_names_ips = self.get_cluster_container_names_ips()
929 member_onos_name = onos_names_ips[standbys[1]]
930 self.vrouter.setUpClass()
A R Karthick76a497a2017-04-12 10:59:39 -0700931 log_test.info('Verifying vrouter traffic before cluster member restart')
ChetanGaonker2099d722016-10-07 15:16:58 -0700932 res = self.vrouter.vrouter_network_verify(networks, peers = 1)
933 assert_equal(res, True) # Expecting vrouter should work properly
A R Karthick3b2e0372016-12-14 17:37:43 -0800934 cord_test_onos_restart(node = standbys[1])
A R Karthick76a497a2017-04-12 10:59:39 -0700935 log_test.info('Verifying vrouter traffic after cluster member restart')
ChetanGaonker2099d722016-10-07 15:16:58 -0700936 self.vrouter.vrouter_traffic_verify()# Expecting vrouter should work properly if member of cluster restarts
937
938 #tested on single onos setup.
ChetanGaonker689b3862016-10-17 16:25:01 -0700939 def test_cluster_for_vrouter_app_restarting_cluster(self,networks = 5, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700940 status = self.verify_cluster_status(onos_instances = onos_instances)
941 assert_equal(status, True)
942 self.vrouter.setUpClass()
A R Karthick76a497a2017-04-12 10:59:39 -0700943 log_test.info('Verifying vrouter traffic before cluster restart')
ChetanGaonker2099d722016-10-07 15:16:58 -0700944 res = self.vrouter.vrouter_network_verify(networks, peers = 1)
945 assert_equal(res, True) # Expecting vrouter should work properly
946 cord_test_onos_restart()
A R Karthick76a497a2017-04-12 10:59:39 -0700947 log_test.info('Verifying vrouter traffic after cluster restart')
ChetanGaonker2099d722016-10-07 15:16:58 -0700948 self.vrouter.vrouter_traffic_verify()# Expecting vrouter should work properly if member of cluster restarts
949
950
951 #test fails because flow state is in pending_add in onos
ChetanGaonker689b3862016-10-17 16:25:01 -0700952 def test_cluster_for_flows_of_udp_port_and_making_master_down(self, onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -0700953 status = self.verify_cluster_status(onos_instances = onos_instances)
954 assert_equal(status, True)
955 master, standbys = self.get_cluster_current_master_standbys()
956 onos_names_ips = self.get_cluster_container_names_ips()
957 master_onos_name = onos_names_ips[master]
958 self.flows.setUpClass()
959 egress = 1
960 ingress = 2
961 egress_map = { 'ip': '192.168.30.1', 'udp_port': 9500 }
962 ingress_map = { 'ip': '192.168.40.1', 'udp_port': 9000 }
963 flow = OnosFlowCtrl(deviceId = self.device_id,
964 egressPort = egress,
965 ingressPort = ingress,
966 udpSrc = ingress_map['udp_port'],
967 udpDst = egress_map['udp_port'],
968 controller=master
969 )
970 result = flow.addFlow()
971 assert_equal(result, True)
972 time.sleep(1)
973 self.success = False
974 def mac_recv_task():
975 def recv_cb(pkt):
A R Karthick76a497a2017-04-12 10:59:39 -0700976 log_test.info('Pkt seen with ingress UDP port %s, egress UDP port %s' %(pkt[UDP].sport, pkt[UDP].dport))
ChetanGaonker2099d722016-10-07 15:16:58 -0700977 self.success = True
978 sniff(timeout=2,
979 lfilter = lambda p: UDP in p and p[UDP].dport == egress_map['udp_port']
980 and p[UDP].sport == ingress_map['udp_port'], prn = recv_cb, iface = self.flows.port_map[egress])
981
982 for i in [0,1]:
983 if i == 1:
A R Karthick3b2e0372016-12-14 17:37:43 -0800984 cord_test_onos_shutdown(node = master)
A R Karthick76a497a2017-04-12 10:59:39 -0700985 log_test.info('Verifying flows traffic after master killed')
ChetanGaonker2099d722016-10-07 15:16:58 -0700986 time.sleep(45)
987 else:
A R Karthick76a497a2017-04-12 10:59:39 -0700988 log_test.info('Verifying flows traffic before master killed')
ChetanGaonker2099d722016-10-07 15:16:58 -0700989 t = threading.Thread(target = mac_recv_task)
990 t.start()
991 L2 = self.flows_eth #Ether(src = ingress_map['ether'], dst = egress_map['ether'])
992 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'])
993 L4 = UDP(sport = ingress_map['udp_port'], dport = egress_map['udp_port'])
994 pkt = L2/L3/L4
A R Karthick76a497a2017-04-12 10:59:39 -0700995 log_test.info('Sending packets to verify if flows are correct')
ChetanGaonker2099d722016-10-07 15:16:58 -0700996 sendp(pkt, count=50, iface = self.flows.port_map[ingress])
997 t.join()
998 assert_equal(self.success, True)
999
ChetanGaonker689b3862016-10-17 16:25:01 -07001000 def test_cluster_state_changing_master_and_flows_of_ecn(self,onos_instances = ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -07001001 status = self.verify_cluster_status(onos_instances=onos_instances)
1002 assert_equal(status, True)
1003 master, standbys = self.get_cluster_current_master_standbys()
1004 self.flows.setUpClass()
1005 egress = 1
1006 ingress = 2
1007 egress_map = { 'ip': '192.168.30.1' }
1008 ingress_map = { 'ip': '192.168.40.1' }
1009 flow = OnosFlowCtrl(deviceId = self.device_id,
1010 egressPort = egress,
1011 ingressPort = ingress,
1012 ecn = 1,
1013 controller=master
1014 )
1015 result = flow.addFlow()
1016 assert_equal(result, True)
1017 ##wait for flows to be added to ONOS
1018 time.sleep(1)
1019 self.success = False
1020 def mac_recv_task():
1021 def recv_cb(pkt):
A R Karthick76a497a2017-04-12 10:59:39 -07001022 log_test.info('Pkt seen with ingress ip %s, egress ip %s and Type of Service %s' %(pkt[IP].src, pkt[IP].dst, pkt[IP].tos))
ChetanGaonker2099d722016-10-07 15:16:58 -07001023 self.success = True
1024 sniff(count=2, timeout=5,
1025 lfilter = lambda p: IP in p and p[IP].dst == egress_map['ip'] and p[IP].src == ingress_map['ip']
1026 and int(bin(p[IP].tos).split('b')[1][-2:],2) == 1,prn = recv_cb,
1027 iface = self.flows.port_map[egress])
1028 for i in [0,1]:
1029 if i == 1:
A R Karthick76a497a2017-04-12 10:59:39 -07001030 log_test.info('Changing cluster master to %s'%standbys[0])
ChetanGaonker2099d722016-10-07 15:16:58 -07001031 self.change_master_current_cluster(new_master=standbys[0])
A R Karthick76a497a2017-04-12 10:59:39 -07001032 log_test.info('Verifying flow traffic after cluster master chnaged')
ChetanGaonker2099d722016-10-07 15:16:58 -07001033 else:
A R Karthick76a497a2017-04-12 10:59:39 -07001034 log_test.info('Verifying flow traffic before cluster master changed')
ChetanGaonker2099d722016-10-07 15:16:58 -07001035 t = threading.Thread(target = mac_recv_task)
1036 t.start()
1037 L2 = self.flows_eth # Ether(src = ingress_map['ether'], dst = egress_map['ether'])
1038 L3 = IP(src = ingress_map['ip'], dst = egress_map['ip'], tos = 1)
1039 pkt = L2/L3
A R Karthick76a497a2017-04-12 10:59:39 -07001040 log_test.info('Sending a packet to verify if flows are correct')
ChetanGaonker2099d722016-10-07 15:16:58 -07001041 sendp(pkt, count=50, iface = self.flows.port_map[ingress])
1042 t.join()
1043 assert_equal(self.success, True)
1044
ChetanGaonker689b3862016-10-17 16:25:01 -07001045 #pass
1046 def test_cluster_flow_for_ipv6_extension_header_and_master_restart(self,onos_instances = ONOS_INSTANCES):
1047 status = self.verify_cluster_status(onos_instances=onos_instances)
1048 assert_equal(status, True)
1049 master,standbys = self.get_cluster_current_master_standbys()
1050 onos_names_ips = self.get_cluster_container_names_ips()
1051 master_onos_name = onos_names_ips[master]
1052 self.flows.setUpClass()
1053 egress = 1
1054 ingress = 2
1055 egress_map = { 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1001' }
1056 ingress_map = { 'ipv6': '2001:db8:a0b:12f0:1010:1010:1010:1002' }
1057 flow = OnosFlowCtrl(deviceId = self.device_id,
1058 egressPort = egress,
1059 ingressPort = ingress,
1060 ipv6_extension = 0,
1061 controller=master
1062 )
1063
1064 result = flow.addFlow()
1065 assert_equal(result, True)
1066 ##wait for flows to be added to ONOS
1067 time.sleep(1)
1068 self.success = False
1069 def mac_recv_task():
1070 def recv_cb(pkt):
A R Karthick76a497a2017-04-12 10:59:39 -07001071 log_test.info('Pkt seen with ingress ip %s, egress ip %s, Extension Header Type %s'%(pkt[IPv6].src, pkt[IPv6].dst, pkt[IPv6].nh))
ChetanGaonker689b3862016-10-17 16:25:01 -07001072 self.success = True
1073 sniff(timeout=2,count=5,
1074 lfilter = lambda p: IPv6 in p and p[IPv6].nh == 0, prn = recv_cb, iface = self.flows.port_map[egress])
1075 for i in [0,1]:
1076 if i == 1:
A R Karthick76a497a2017-04-12 10:59:39 -07001077 log_test.info('Restart cluster current master %s'%master)
ChetanGaonker689b3862016-10-17 16:25:01 -07001078 Container(master_onos_name,Onos.IMAGE).restart()
1079 time.sleep(45)
A R Karthick76a497a2017-04-12 10:59:39 -07001080 log_test.info('Verifying flow traffic after master restart')
ChetanGaonker689b3862016-10-17 16:25:01 -07001081 else:
A R Karthick76a497a2017-04-12 10:59:39 -07001082 log_test.info('Verifying flow traffic before master restart')
ChetanGaonker689b3862016-10-17 16:25:01 -07001083 t = threading.Thread(target = mac_recv_task)
1084 t.start()
1085 L2 = self.flows_eth
1086 L3 = IPv6(src = ingress_map['ipv6'] , dst = egress_map['ipv6'], nh = 0)
1087 pkt = L2/L3
A R Karthick76a497a2017-04-12 10:59:39 -07001088 log_test.info('Sending packets to verify if flows are correct')
ChetanGaonker689b3862016-10-17 16:25:01 -07001089 sendp(pkt, count=50, iface = self.flows.port_map[ingress])
1090 t.join()
1091 assert_equal(self.success, True)
1092
1093 def send_multicast_data_traffic(self, group, intf= 'veth2',source = '1.2.3.4'):
1094 dst_mac = self.igmp.iptomac(group)
1095 eth = Ether(dst= dst_mac)
1096 ip = IP(dst=group,src=source)
1097 data = repr(monotonic.monotonic())
1098 sendp(eth/ip/data,count=20, iface = intf)
1099 pkt = (eth/ip/data)
A R Karthick76a497a2017-04-12 10:59:39 -07001100 log_test.info('multicast traffic packet %s'%pkt.show())
ChetanGaonker689b3862016-10-17 16:25:01 -07001101
1102 def verify_igmp_data_traffic(self, group, intf='veth0', source='1.2.3.4' ):
A R Karthick76a497a2017-04-12 10:59:39 -07001103 log_test.info('verifying multicast traffic for group %s from source %s'%(group,source))
ChetanGaonker689b3862016-10-17 16:25:01 -07001104 self.success = False
1105 def recv_task():
1106 def igmp_recv_cb(pkt):
A R Karthick76a497a2017-04-12 10:59:39 -07001107 log_test.info('multicast data received for group %s from source %s'%(group,source))
ChetanGaonker689b3862016-10-17 16:25:01 -07001108 self.success = True
1109 sniff(prn = igmp_recv_cb,lfilter = lambda p: IP in p and p[IP].dst == group and p[IP].src == source, count=1,timeout = 2, iface='veth0')
1110 t = threading.Thread(target = recv_task)
1111 t.start()
1112 self.send_multicast_data_traffic(group,source=source)
1113 t.join()
1114 return self.success
1115
1116 #pass
1117 def test_cluster_with_igmp_include_exclude_modes_and_restarting_master(self, onos_instances=ONOS_INSTANCES):
1118 status = self.verify_cluster_status(onos_instances=onos_instances)
1119 assert_equal(status, True)
1120 master, standbys = self.get_cluster_current_master_standbys()
1121 assert_equal(len(standbys), (onos_instances-1))
1122 onos_names_ips = self.get_cluster_container_names_ips()
1123 master_onos_name = onos_names_ips[master]
1124 self.igmp.setUp(controller=master)
1125 groups = ['224.2.3.4','230.5.6.7']
1126 src_list = ['2.2.2.2','3.3.3.3']
1127 self.igmp.onos_ssm_table_load(groups, src_list=src_list, controller=master)
1128 self.igmp.send_igmp_join(groups = [groups[0]], src_list = src_list,record_type = IGMP_V3_GR_TYPE_INCLUDE,
1129 iface = self.V_INF1, delay = 2)
1130 self.igmp.send_igmp_join(groups = [groups[1]], src_list = src_list,record_type = IGMP_V3_GR_TYPE_EXCLUDE,
1131 iface = self.V_INF1, delay = 2)
1132 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1133 assert_equal(status,True)
1134 status = self.verify_igmp_data_traffic(groups[1],intf = self.V_INF1,source= src_list[1])
1135 assert_equal(status,False)
A R Karthick76a497a2017-04-12 10:59:39 -07001136 log_test.info('restarting cluster master %s'%master)
ChetanGaonker689b3862016-10-17 16:25:01 -07001137 Container(master_onos_name,Onos.IMAGE).restart()
1138 time.sleep(60)
A R Karthick76a497a2017-04-12 10:59:39 -07001139 log_test.info('verifying multicast data traffic after master restart')
ChetanGaonker689b3862016-10-17 16:25:01 -07001140 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1141 assert_equal(status,True)
1142 status = self.verify_igmp_data_traffic(groups[1],intf = self.V_INF1,source= src_list[1])
1143 assert_equal(status,False)
1144
1145 #pass
1146 def test_cluster_with_igmp_include_exclude_modes_and_making_master_down(self, onos_instances=ONOS_INSTANCES):
1147 status = self.verify_cluster_status(onos_instances=onos_instances)
1148 assert_equal(status, True)
1149 master, standbys = self.get_cluster_current_master_standbys()
1150 assert_equal(len(standbys), (onos_instances-1))
1151 onos_names_ips = self.get_cluster_container_names_ips()
1152 master_onos_name = onos_names_ips[master]
1153 self.igmp.setUp(controller=master)
1154 groups = [self.igmp.random_mcast_ip(),self.igmp.random_mcast_ip()]
1155 src_list = [self.igmp.randomsourceip()]
1156 self.igmp.onos_ssm_table_load(groups, src_list=src_list,controller=master)
1157 self.igmp.send_igmp_join(groups = [groups[0]], src_list = src_list,record_type = IGMP_V3_GR_TYPE_INCLUDE,
1158 iface = self.V_INF1, delay = 2)
1159 self.igmp.send_igmp_join(groups = [groups[1]], src_list = src_list,record_type = IGMP_V3_GR_TYPE_EXCLUDE,
1160 iface = self.V_INF1, delay = 2)
1161 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1162 assert_equal(status,True)
1163 status = self.verify_igmp_data_traffic(groups[1],intf = self.V_INF1,source= src_list[0])
1164 assert_equal(status,False)
A R Karthick76a497a2017-04-12 10:59:39 -07001165 log_test.info('Killing cluster master %s'%master)
ChetanGaonker689b3862016-10-17 16:25:01 -07001166 Container(master_onos_name,Onos.IMAGE).kill()
1167 time.sleep(60)
1168 status = self.verify_cluster_status(onos_instances=onos_instances-1,controller=standbys[0])
1169 assert_equal(status, True)
A R Karthick76a497a2017-04-12 10:59:39 -07001170 log_test.info('Verifying multicast data traffic after cluster master down')
ChetanGaonker689b3862016-10-17 16:25:01 -07001171 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1172 assert_equal(status,True)
1173 status = self.verify_igmp_data_traffic(groups[1],intf = self.V_INF1,source= src_list[0])
1174 assert_equal(status,False)
1175
1176 def test_cluster_with_igmp_include_mode_checking_traffic_recovery_time_after_master_is_down(self, onos_instances=ONOS_INSTANCES):
1177 status = self.verify_cluster_status(onos_instances=onos_instances)
1178 assert_equal(status, True)
1179 master, standbys = self.get_cluster_current_master_standbys()
1180 assert_equal(len(standbys), (onos_instances-1))
1181 onos_names_ips = self.get_cluster_container_names_ips()
1182 master_onos_name = onos_names_ips[master]
1183 self.igmp.setUp(controller=master)
1184 groups = [self.igmp.random_mcast_ip()]
1185 src_list = [self.igmp.randomsourceip()]
1186 self.igmp.onos_ssm_table_load(groups, src_list=src_list,controller=master)
1187 self.igmp.send_igmp_join(groups = [groups[0]], src_list = src_list,record_type = IGMP_V3_GR_TYPE_INCLUDE,
1188 iface = self.V_INF1, delay = 2)
1189 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1190 assert_equal(status,True)
A R Karthick76a497a2017-04-12 10:59:39 -07001191 log_test.info('Killing clusters master %s'%master)
ChetanGaonker689b3862016-10-17 16:25:01 -07001192 Container(master_onos_name,Onos.IMAGE).kill()
1193 count = 0
1194 for i in range(60):
A R Karthick76a497a2017-04-12 10:59:39 -07001195 log_test.info('Verifying multicast data traffic after cluster master down')
ChetanGaonker689b3862016-10-17 16:25:01 -07001196 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1197 if status:
1198 break
1199 else:
1200 count += 1
1201 time.sleep(1)
1202 assert_equal(status, True)
A R Karthick76a497a2017-04-12 10:59:39 -07001203 log_test.info('Time taken to recover traffic after clusters master down is %d seconds'%count)
ChetanGaonker689b3862016-10-17 16:25:01 -07001204
1205
1206 #pass
1207 def test_cluster_state_with_igmp_leave_group_after_master_change(self, onos_instances=ONOS_INSTANCES):
1208 status = self.verify_cluster_status(onos_instances=onos_instances)
1209 assert_equal(status, True)
1210 master, standbys = self.get_cluster_current_master_standbys()
1211 assert_equal(len(standbys), (onos_instances-1))
1212 self.igmp.setUp(controller=master)
1213 groups = [self.igmp.random_mcast_ip()]
1214 src_list = [self.igmp.randomsourceip()]
1215 self.igmp.onos_ssm_table_load(groups, src_list=src_list,controller=master)
1216 self.igmp.send_igmp_join(groups = [groups[0]], src_list = src_list,record_type = IGMP_V3_GR_TYPE_INCLUDE,
1217 iface = self.V_INF1, delay = 2)
1218 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1219 assert_equal(status,True)
A R Karthick76a497a2017-04-12 10:59:39 -07001220 log_test.info('Changing cluster master %s to %s'%(master,standbys[0]))
ChetanGaonker689b3862016-10-17 16:25:01 -07001221 self.change_cluster_current_master(new_master=standbys[0])
A R Karthick76a497a2017-04-12 10:59:39 -07001222 log_test.info('Verifying multicast traffic after cluster master change')
ChetanGaonker689b3862016-10-17 16:25:01 -07001223 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1224 assert_equal(status,True)
A R Karthick76a497a2017-04-12 10:59:39 -07001225 log_test.info('Sending igmp TO_EXCLUDE message to leave the group %s'%groups[0])
ChetanGaonker689b3862016-10-17 16:25:01 -07001226 self.igmp.send_igmp_join(groups = [groups[0]], src_list = src_list,record_type = IGMP_V3_GR_TYPE_CHANGE_TO_EXCLUDE,
1227 iface = self.V_INF1, delay = 1)
1228 time.sleep(10)
1229 status = self.verify_igmp_data_traffic(groups[0],intf = self.V_INF1,source= src_list[0])
1230 assert_equal(status,False)
1231
1232 #pass
1233 def test_cluster_state_with_igmp_join_before_and_after_master_change(self,onos_instances=ONOS_INSTANCES):
1234 status = self.verify_cluster_status(onos_instances=onos_instances)
1235 assert_equal(status, True)
1236 master,standbys = self.get_cluster_current_master_standbys()
1237 assert_equal(len(standbys), (onos_instances-1))
1238 self.igmp.setUp(controller=master)
1239 groups = [self.igmp.random_mcast_ip()]
1240 src_list = [self.igmp.randomsourceip()]
1241 self.igmp.onos_ssm_table_load(groups, src_list=src_list,controller=master)
A R Karthick76a497a2017-04-12 10:59:39 -07001242 log_test.info('Changing cluster master %s to %s'%(master,standbys[0]))
ChetanGaonker689b3862016-10-17 16:25:01 -07001243 self.change_cluster_current_master(new_master = standbys[0])
1244 self.igmp.send_igmp_join(groups = [groups[0]], src_list = src_list,record_type = IGMP_V3_GR_TYPE_INCLUDE,
1245 iface = self.V_INF1, delay = 2)
1246 time.sleep(1)
1247 self.change_cluster_current_master(new_master = master)
1248 status = self.verify_igmp_data_traffic(groups[0],intf=self.V_INF1,source=src_list[0])
1249 assert_equal(status,True)
1250
1251 #pass
ChetanGaonker2099d722016-10-07 15:16:58 -07001252 @deferred(TLS_TIMEOUT)
ChetanGaonker689b3862016-10-17 16:25:01 -07001253 def test_cluster_with_eap_tls_traffic(self,onos_instances=ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -07001254 status = self.verify_cluster_status(onos_instances=onos_instances)
1255 assert_equal(status, True)
1256 master, standbys = self.get_cluster_current_master_standbys()
1257 assert_equal(len(standbys), (onos_instances-1))
1258 self.tls.setUp(controller=master)
1259 df = defer.Deferred()
1260 def eap_tls_verify(df):
1261 tls = TLSAuthTest()
1262 tls.runTest()
1263 df.callback(0)
1264 reactor.callLater(0, eap_tls_verify, df)
1265 return df
1266
1267 @deferred(120)
ChetanGaonker689b3862016-10-17 16:25:01 -07001268 def test_cluster_for_eap_tls_traffic_before_and_after_master_change(self,onos_instances=ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -07001269 master, standbys = self.get_cluster_current_master_standbys()
1270 assert_equal(len(standbys), (onos_instances-1))
1271 self.tls.setUp()
1272 df = defer.Deferred()
1273 def eap_tls_verify2(df2):
1274 tls = TLSAuthTest()
1275 tls.runTest()
1276 df.callback(0)
1277 for i in [0,1]:
1278 if i == 1:
A R Karthick76a497a2017-04-12 10:59:39 -07001279 log_test.info('Changing cluster master %s to %s'%(master, standbys[0]))
ChetanGaonker2099d722016-10-07 15:16:58 -07001280 self.change_master_current_cluster(new_master=standbys[0])
A R Karthick76a497a2017-04-12 10:59:39 -07001281 log_test.info('Verifying tls authentication after cluster master changed to %s'%standbys[0])
ChetanGaonker2099d722016-10-07 15:16:58 -07001282 else:
A R Karthick76a497a2017-04-12 10:59:39 -07001283 log_test.info('Verifying tls authentication before cluster master change')
ChetanGaonker2099d722016-10-07 15:16:58 -07001284 reactor.callLater(0, eap_tls_verify, df)
1285 return df
1286
1287 @deferred(TLS_TIMEOUT)
ChetanGaonker689b3862016-10-17 16:25:01 -07001288 def test_cluster_for_eap_tls_traffic_before_and_after_making_master_down(self,onos_instances=ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -07001289 status = self.verify_cluster_status(onos_instances=onos_instances)
1290 assert_equal(status, True)
1291 master, standbys = self.get_cluster_current_master_standbys()
1292 assert_equal(len(standbys), (onos_instances-1))
1293 onos_names_ips = self.get_cluster_container_names_ips()
1294 master_onos_name = onos_names_ips[master]
1295 self.tls.setUp()
1296 df = defer.Deferred()
1297 def eap_tls_verify(df):
1298 tls = TLSAuthTest()
1299 tls.runTest()
1300 df.callback(0)
1301 for i in [0,1]:
1302 if i == 1:
A R Karthick76a497a2017-04-12 10:59:39 -07001303 log_test.info('Killing cluster current master %s'%master)
A R Karthick3b2e0372016-12-14 17:37:43 -08001304 cord_test_onos_shutdown(node = master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001305 time.sleep(20)
1306 status = self.verify_cluster_status(controller=standbys[0],onos_instances=onos_instances-1,verify=True)
1307 assert_equal(status, True)
A R Karthick76a497a2017-04-12 10:59:39 -07001308 log_test.info('Cluster came up with %d instances after killing master'%(onos_instances-1))
1309 log_test.info('Verifying tls authentication after killing cluster master')
ChetanGaonker2099d722016-10-07 15:16:58 -07001310 reactor.callLater(0, eap_tls_verify, df)
1311 return df
1312
1313 @deferred(TLS_TIMEOUT)
ChetanGaonker689b3862016-10-17 16:25:01 -07001314 def test_cluster_for_eap_tls_with_no_cert_before_and_after_member_is_restarted(self,onos_instances=ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -07001315 status = self.verify_cluster_status(onos_instances=onos_instances)
1316 assert_equal(status, True)
1317 master, standbys = self.get_cluster_current_master_standbys()
1318 assert_equal(len(standbys), (onos_instances-1))
1319 onos_names_ips = self.get_cluster_container_names_ips()
1320 member_onos_name = onos_names_ips[standbys[0]]
1321 self.tls.setUp()
1322 df = defer.Deferred()
1323 def eap_tls_no_cert(df):
1324 def tls_no_cert_cb():
A R Karthick76a497a2017-04-12 10:59:39 -07001325 log_test.info('TLS authentication failed with no certificate')
ChetanGaonker2099d722016-10-07 15:16:58 -07001326 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
1327 tls.runTest()
1328 assert_equal(tls.failTest, True)
1329 df.callback(0)
1330 for i in [0,1]:
1331 if i == 1:
A R Karthick76a497a2017-04-12 10:59:39 -07001332 log_test.info('Restart cluster member %s'%standbys[0])
ChetanGaonker2099d722016-10-07 15:16:58 -07001333 Container(member_onos_name,Onos.IMAGE).restart()
1334 time.sleep(20)
1335 status = self.verify_cluster_status(onos_instances=onos_instances)
1336 assert_equal(status, True)
A R Karthick76a497a2017-04-12 10:59:39 -07001337 log_test.info('Cluster came up with %d instances after member restart'%(onos_instances))
1338 log_test.info('Verifying tls authentication after member restart')
ChetanGaonker2099d722016-10-07 15:16:58 -07001339 reactor.callLater(0, eap_tls_no_cert, df)
1340 return df
1341
ChetanGaonker689b3862016-10-17 16:25:01 -07001342 #pass
1343 def test_cluster_proxyarp_master_change_and_app_deactivation(self,onos_instances=ONOS_INSTANCES,hosts = 3):
1344 status = self.verify_cluster_status(onos_instances=onos_instances)
1345 assert_equal(status,True)
1346 master,standbys = self.get_cluster_current_master_standbys()
1347 assert_equal(len(standbys),(onos_instances-1))
1348 self.proxyarp.setUpClass()
1349 ports_map, egress_map,hosts_config = self.proxyarp.proxyarp_config(hosts = hosts,controller=master)
1350 ingress = hosts+1
1351 for hostip, hostmac in hosts_config:
1352 self.proxyarp.proxyarp_arpreply_verify(ingress,hostip,hostmac,PositiveTest = True)
1353 time.sleep(1)
A R Karthick76a497a2017-04-12 10:59:39 -07001354 log_test.info('changing cluster current master from %s to %s'%(master,standbys[0]))
ChetanGaonker689b3862016-10-17 16:25:01 -07001355 self.change_cluster_current_master(new_master=standbys[0])
A R Karthick76a497a2017-04-12 10:59:39 -07001356 log_test.info('verifying proxyarp after master change')
ChetanGaonker689b3862016-10-17 16:25:01 -07001357 for hostip, hostmac in hosts_config:
1358 self.proxyarp.proxyarp_arpreply_verify(ingress,hostip,hostmac,PositiveTest = True)
1359 time.sleep(1)
A R Karthick76a497a2017-04-12 10:59:39 -07001360 log_test.info('Deactivating proxyarp app and expecting proxyarp functionality not to work')
ChetanGaonker689b3862016-10-17 16:25:01 -07001361 self.proxyarp.proxyarp_activate(deactivate = True,controller=standbys[0])
1362 time.sleep(3)
1363 for hostip, hostmac in hosts_config:
1364 self.proxyarp.proxyarp_arpreply_verify(ingress,hostip,hostmac,PositiveTest = False)
1365 time.sleep(1)
A R Karthick76a497a2017-04-12 10:59:39 -07001366 log_test.info('activating proxyarp app and expecting to get arp reply from ONOS')
ChetanGaonker689b3862016-10-17 16:25:01 -07001367 self.proxyarp.proxyarp_activate(deactivate = False,controller=standbys[0])
1368 time.sleep(3)
1369 for hostip, hostmac in hosts_config:
1370 self.proxyarp.proxyarp_arpreply_verify(ingress,hostip,hostmac,PositiveTest = True)
1371 time.sleep(1)
ChetanGaonker2099d722016-10-07 15:16:58 -07001372
ChetanGaonker689b3862016-10-17 16:25:01 -07001373 #pass
1374 def test_cluster_with_proxyarp_and_one_member_down(self,hosts=3,onos_instances=ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -07001375 status = self.verify_cluster_status(onos_instances=onos_instances)
1376 assert_equal(status, True)
1377 master, standbys = self.get_cluster_current_master_standbys()
ChetanGaonker689b3862016-10-17 16:25:01 -07001378 assert_equal(len(standbys), (onos_instances-1))
1379 onos_names_ips = self.get_cluster_container_names_ips()
1380 member_onos_name = onos_names_ips[standbys[1]]
1381 self.proxyarp.setUpClass()
1382 ports_map, egress_map,hosts_config = self.proxyarp.proxyarp_config(hosts = hosts,controller=master)
1383 ingress = hosts+1
1384 for hostip, hostmac in hosts_config:
1385 self.proxyarp.proxyarp_arpreply_verify(ingress,hostip,hostmac,PositiveTest = True)
1386 time.sleep(1)
A R Karthick76a497a2017-04-12 10:59:39 -07001387 log_test.info('killing cluster member %s'%standbys[1])
ChetanGaonker689b3862016-10-17 16:25:01 -07001388 Container(member_onos_name,Onos.IMAGE).kill()
1389 time.sleep(20)
1390 status = self.verify_cluster_status(onos_instances=onos_instances-1,controller=master,verify=True)
1391 assert_equal(status, True)
A R Karthick76a497a2017-04-12 10:59:39 -07001392 log_test.info('cluster came up with %d instances after member down'%(onos_instances-1))
1393 log_test.info('verifying proxy arp functionality after cluster member down')
ChetanGaonker689b3862016-10-17 16:25:01 -07001394 for hostip, hostmac in hosts_config:
1395 self.proxyarp.proxyarp_arpreply_verify(ingress,hostip,hostmac,PositiveTest = True)
1396 time.sleep(1)
1397
1398 #pass
1399 def test_cluster_with_proxyarp_and_concurrent_requests_with_multiple_host_and_different_interfaces(self,hosts=10,onos_instances=ONOS_INSTANCES):
1400 status = self.verify_cluster_status(onos_instances=onos_instances)
1401 assert_equal(status, True)
1402 self.proxyarp.setUpClass()
1403 master, standbys = self.get_cluster_current_master_standbys()
1404 assert_equal(len(standbys), (onos_instances-1))
1405 ports_map, egress_map, hosts_config = self.proxyarp.proxyarp_config(hosts = hosts, controller=master)
1406 self.success = True
1407 ingress = hosts+1
1408 ports = range(ingress,ingress+10)
1409 hostmac = []
1410 hostip = []
1411 for ip,mac in hosts_config:
1412 hostmac.append(mac)
1413 hostip.append(ip)
1414 success_dir = {}
1415 def verify_proxyarp(*r):
1416 ingress, hostmac, hostip = r[0],r[1],r[2]
1417 def mac_recv_task():
1418 def recv_cb(pkt):
A R Karthick76a497a2017-04-12 10:59:39 -07001419 log_test.info('Arp Reply seen with source Mac is %s' %(pkt[ARP].hwsrc))
ChetanGaonker689b3862016-10-17 16:25:01 -07001420 success_dir[current_thread().name] = True
1421 sniff(count=1, timeout=5,lfilter = lambda p: ARP in p and p[ARP].op == 2 and p[ARP].hwsrc == hostmac,
1422 prn = recv_cb, iface = self.proxyarp.port_map[ingress])
1423 t = threading.Thread(target = mac_recv_task)
1424 t.start()
1425 pkt = (Ether(dst = 'ff:ff:ff:ff:ff:ff')/ARP(op=1,pdst= hostip))
A R Karthick76a497a2017-04-12 10:59:39 -07001426 log_test.info('Sending arp request for dest ip %s on interface %s' %
ChetanGaonker689b3862016-10-17 16:25:01 -07001427 (hostip,self.proxyarp.port_map[ingress]))
1428 sendp(pkt, count = 10,iface = self.proxyarp.port_map[ingress])
1429 t.join()
1430 t = []
1431 for i in range(10):
1432 t.append(threading.Thread(target = verify_proxyarp, args = [ports[i],hostmac[i],hostip[i]]))
1433 for i in range(10):
1434 t[i].start()
1435 time.sleep(2)
1436 for i in range(10):
1437 t[i].join()
1438 if len(success_dir) != 10:
1439 self.success = False
1440 assert_equal(self.success, True)
1441
1442 #pass
1443 def test_cluster_with_acl_rule_before_master_change_and_remove_acl_rule_after_master_change(self,onos_instances=ONOS_INSTANCES):
1444 status = self.verify_cluster_status(onos_instances=onos_instances)
1445 assert_equal(status, True)
1446 master,standbys = self.get_cluster_current_master_standbys()
ChetanGaonker2099d722016-10-07 15:16:58 -07001447 assert_equal(len(standbys),(onos_instances-1))
ChetanGaonker689b3862016-10-17 16:25:01 -07001448 self.acl.setUp()
1449 acl_rule = ACLTest()
1450 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.acl.ACL_SRC_IP, dstIp =self.acl.ACL_DST_IP, action = 'allow',controller=master)
1451 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -07001452 log_test.info('JSON request returned status %d' %code)
ChetanGaonker689b3862016-10-17 16:25:01 -07001453 assert_equal(status, True)
1454 result = acl_rule.get_acl_rules(controller=master)
1455 aclRules1 = result.json()['aclRules']
A R Karthick76a497a2017-04-12 10:59:39 -07001456 log_test.info('Added acl rules is %s'%aclRules1)
ChetanGaonker689b3862016-10-17 16:25:01 -07001457 acl_Id = map(lambda d: d['id'], aclRules1)
A R Karthick76a497a2017-04-12 10:59:39 -07001458 log_test.info('Changing cluster current master from %s to %s'%(master,standbys[0]))
ChetanGaonker689b3862016-10-17 16:25:01 -07001459 self.change_cluster_current_master(new_master=standbys[0])
1460 status,code = acl_rule.remove_acl_rule(acl_Id[0],controller=standbys[0])
1461 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -07001462 log_test.info('JSON request returned status %d' %code)
ChetanGaonker689b3862016-10-17 16:25:01 -07001463 assert_equal(status, True)
1464
1465 #pass
1466 def test_cluster_verifying_acl_rule_in_new_master_after_current_master_is_down(self,onos_instances=ONOS_INSTANCES):
1467 status = self.verify_cluster_status(onos_instances=onos_instances)
1468 assert_equal(status, True)
1469 master,standbys = self.get_cluster_current_master_standbys()
1470 assert_equal(len(standbys),(onos_instances-1))
1471 onos_names_ips = self.get_cluster_container_names_ips()
1472 master_onos_name = onos_names_ips[master]
1473 self.acl.setUp()
1474 acl_rule = ACLTest()
1475 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.acl.ACL_SRC_IP, dstIp =self.acl.ACL_DST_IP, action = 'allow',controller=master)
1476 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -07001477 log_test.info('JSON request returned status %d' %code)
ChetanGaonker689b3862016-10-17 16:25:01 -07001478 assert_equal(status, True)
1479 result1 = acl_rule.get_acl_rules(controller=master)
1480 aclRules1 = result1.json()['aclRules']
A R Karthick76a497a2017-04-12 10:59:39 -07001481 log_test.info('Added acl rules is %s'%aclRules1)
ChetanGaonker689b3862016-10-17 16:25:01 -07001482 acl_Id1 = map(lambda d: d['id'], aclRules1)
A R Karthick76a497a2017-04-12 10:59:39 -07001483 log_test.info('Killing cluster current master %s'%master)
ChetanGaonker689b3862016-10-17 16:25:01 -07001484 Container(master_onos_name,Onos.IMAGE).kill()
1485 time.sleep(45)
1486 status = self.verify_cluster_status(onos_instances=onos_instances,controller=standbys[0])
1487 assert_equal(status, True)
1488 new_master,standbys = self.get_cluster_current_master_standbys(controller=standbys[0])
1489 assert_equal(len(standbys),(onos_instances-2))
1490 assert_not_equal(new_master,master)
1491 result2 = acl_rule.get_acl_rules(controller=new_master)
1492 aclRules2 = result2.json()['aclRules']
1493 acl_Id2 = map(lambda d: d['id'], aclRules2)
A R Karthick76a497a2017-04-12 10:59:39 -07001494 log_test.info('Acl Ids before and after master down are %s and %s'%(acl_Id1,acl_Id2))
ChetanGaonker689b3862016-10-17 16:25:01 -07001495 assert_equal(acl_Id2,acl_Id1)
1496
1497 #acl traffic scenario not working as acl rule is not getting added to onos
1498 def test_cluster_with_acl_traffic_before_and_after_two_members_down(self,onos_instances=ONOS_INSTANCES):
1499 status = self.verify_cluster_status(onos_instances=onos_instances)
1500 assert_equal(status, True)
1501 master,standbys = self.get_cluster_current_master_standbys()
1502 assert_equal(len(standbys),(onos_instances-1))
1503 onos_names_ips = self.get_cluster_container_names_ips()
1504 member1_onos_name = onos_names_ips[standbys[0]]
1505 member2_onos_name = onos_names_ips[standbys[1]]
1506 ingress = self.acl.ingress_iface
1507 egress = self.acl.CURRENT_PORT_NUM
1508 acl_rule = ACLTest()
1509 status, code, host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.acl.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.acl.HOST_DST_IP)
1510 self.acl.CURRENT_PORT_NUM += 1
1511 time.sleep(5)
1512 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -07001513 log_test.info('JSON request returned status %d' %code)
ChetanGaonker689b3862016-10-17 16:25:01 -07001514 assert_equal(status, True)
1515 srcMac = '00:00:00:00:00:11'
1516 dstMac = host_ip_mac[0][1]
1517 self.acl.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
1518 status, code = acl_rule.adding_acl_rule('v4', srcIp=self.acl.ACL_SRC_IP, dstIp =self.acl.ACL_DST_IP, action = 'deny',controller=master)
1519 time.sleep(10)
1520 if status is False:
A R Karthick76a497a2017-04-12 10:59:39 -07001521 log_test.info('JSON request returned status %d' %code)
ChetanGaonker689b3862016-10-17 16:25:01 -07001522 assert_equal(status, True)
1523 self.acl.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.acl.ACL_SRC_IP, dstIp = self.acl.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP', positive_test = False)
A R Karthick76a497a2017-04-12 10:59:39 -07001524 log_test.info('killing cluster members %s and %s'%(standbys[0],standbys[1]))
ChetanGaonker689b3862016-10-17 16:25:01 -07001525 Container(member1_onos_name, Onos.IMAGE).kill()
1526 Container(member2_onos_name, Onos.IMAGE).kill()
1527 time.sleep(40)
1528 status = self.verify_cluster_status(onos_instances=onos_instances-2,verify=True,controller=master)
1529 assert_equal(status, True)
1530 self.acl.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.acl.ACL_SRC_IP, dstIp = self.acl.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP', positive_test = False)
1531 self.acl.acl_hosts_remove(egress_iface_count = 1, egress_iface_num = egress)
1532
1533 #pass
1534 def test_cluster_with_dhcpRelay_releasing_dhcp_ip_after_master_change(self, iface = 'veth0',onos_instances=ONOS_INSTANCES):
1535 status = self.verify_cluster_status(onos_instances=onos_instances)
1536 assert_equal(status, True)
1537 master,standbys = self.get_cluster_current_master_standbys()
1538 assert_equal(len(standbys),(onos_instances-1))
1539 self.dhcprelay.setUpClass(controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001540 mac = self.dhcprelay.get_mac(iface)
1541 self.dhcprelay.host_load(iface)
1542 ##we use the defaults for this test that serves as an example for others
1543 ##You don't need to restart dhcpd server if retaining default config
1544 config = self.dhcprelay.default_config
1545 options = self.dhcprelay.default_options
1546 subnet = self.dhcprelay.default_subnet_config
1547 dhcpd_interface_list = self.dhcprelay.relay_interfaces
1548 self.dhcprelay.dhcpd_start(intf_list = dhcpd_interface_list,
1549 config = config,
1550 options = options,
ChetanGaonker689b3862016-10-17 16:25:01 -07001551 subnet = subnet,
1552 controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001553 self.dhcprelay.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
1554 cip, sip = self.dhcprelay.send_recv(mac)
A R Karthick76a497a2017-04-12 10:59:39 -07001555 log_test.info('Changing cluster current master from %s to %s'%(master, standbys[0]))
ChetanGaonker2099d722016-10-07 15:16:58 -07001556 self.change_master_current_cluster(new_master=standbys[0])
A R Karthick76a497a2017-04-12 10:59:39 -07001557 log_test.info('Releasing ip %s to server %s' %(cip, sip))
ChetanGaonker2099d722016-10-07 15:16:58 -07001558 assert_equal(self.dhcprelay.dhcp.release(cip), True)
A R Karthick76a497a2017-04-12 10:59:39 -07001559 log_test.info('Triggering DHCP discover again after release')
ChetanGaonker2099d722016-10-07 15:16:58 -07001560 cip2, sip2 = self.dhcprelay.send_recv(mac)
A R Karthick76a497a2017-04-12 10:59:39 -07001561 log_test.info('Verifying released IP was given back on rediscover')
ChetanGaonker2099d722016-10-07 15:16:58 -07001562 assert_equal(cip, cip2)
A R Karthick76a497a2017-04-12 10:59:39 -07001563 log_test.info('Test done. Releasing ip %s to server %s' %(cip2, sip2))
ChetanGaonker2099d722016-10-07 15:16:58 -07001564 assert_equal(self.dhcprelay.dhcp.release(cip2), True)
ChetanGaonker689b3862016-10-17 16:25:01 -07001565 self.dhcprelay.tearDownClass(controller=standbys[0])
ChetanGaonker2099d722016-10-07 15:16:58 -07001566
ChetanGaonker689b3862016-10-17 16:25:01 -07001567
1568 def test_cluster_with_dhcpRelay_and_verify_dhcp_ip_after_master_down(self, iface = 'veth0',onos_instances=ONOS_INSTANCES):
1569 status = self.verify_cluster_status(onos_instances=onos_instances)
1570 assert_equal(status, True)
1571 master,standbys = self.get_cluster_current_master_standbys()
ChetanGaonker2099d722016-10-07 15:16:58 -07001572 assert_equal(len(standbys),(onos_instances-1))
ChetanGaonker689b3862016-10-17 16:25:01 -07001573 onos_names_ips = self.get_cluster_container_names_ips()
1574 master_onos_name = onos_names_ips[master]
1575 self.dhcprelay.setUpClass(controller=master)
1576 mac = self.dhcprelay.get_mac(iface)
1577 self.dhcprelay.host_load(iface)
1578 ##we use the defaults for this test that serves as an example for others
1579 ##You don't need to restart dhcpd server if retaining default config
1580 config = self.dhcprelay.default_config
1581 options = self.dhcprelay.default_options
1582 subnet = self.dhcprelay.default_subnet_config
1583 dhcpd_interface_list = self.dhcprelay.relay_interfaces
1584 self.dhcprelay.dhcpd_start(intf_list = dhcpd_interface_list,
1585 config = config,
1586 options = options,
1587 subnet = subnet,
1588 controller=master)
1589 self.dhcprelay.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
A R Karthick76a497a2017-04-12 10:59:39 -07001590 log_test.info('Initiating dhcp process from client %s'%mac)
ChetanGaonker689b3862016-10-17 16:25:01 -07001591 cip, sip = self.dhcprelay.send_recv(mac)
A R Karthick76a497a2017-04-12 10:59:39 -07001592 log_test.info('Killing cluster current master %s'%master)
ChetanGaonker689b3862016-10-17 16:25:01 -07001593 Container(master_onos_name, Onos.IMAGE).kill()
1594 time.sleep(60)
1595 status = self.verify_cluster_status(onos_instances=onos_instances-1,verify=True,controller=standbys[0])
1596 assert_equal(status, True)
1597 mac = self.dhcprelay.dhcp.get_mac(cip)[0]
A R Karthick76a497a2017-04-12 10:59:39 -07001598 log_test.info("Verifying dhcp clients gets same IP after cluster master restarts")
ChetanGaonker689b3862016-10-17 16:25:01 -07001599 new_cip, new_sip = self.dhcprelay.dhcp.only_request(cip, mac)
1600 assert_equal(new_cip, cip)
1601 self.dhcprelay.tearDownClass(controller=standbys[0])
1602
1603 #pass
1604 def test_cluster_with_dhcpRelay_and_simulate_client_by_changing_master(self, iface = 'veth0',onos_instances=ONOS_INSTANCES):
1605 status = self.verify_cluster_status(onos_instances=onos_instances)
1606 assert_equal(status, True)
1607 master,standbys = self.get_cluster_current_master_standbys()
1608 assert_equal(len(standbys),(onos_instances-1))
1609 self.dhcprelay.setUpClass(controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001610 macs = ['e4:90:5e:a3:82:c1','e4:90:5e:a3:82:c2','e4:90:5e:a3:82:c3']
1611 self.dhcprelay.host_load(iface)
1612 ##we use the defaults for this test that serves as an example for others
1613 ##You don't need to restart dhcpd server if retaining default config
1614 config = self.dhcprelay.default_config
1615 options = self.dhcprelay.default_options
1616 subnet = self.dhcprelay.default_subnet_config
1617 dhcpd_interface_list = self.dhcprelay.relay_interfaces
1618 self.dhcprelay.dhcpd_start(intf_list = dhcpd_interface_list,
1619 config = config,
1620 options = options,
ChetanGaonker689b3862016-10-17 16:25:01 -07001621 subnet = subnet,
1622 controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001623 self.dhcprelay.dhcp = DHCPTest(seed_ip = '10.10.10.1', iface = iface)
1624 cip1, sip1 = self.dhcprelay.send_recv(macs[0])
1625 assert_not_equal(cip1,None)
A R Karthick76a497a2017-04-12 10:59:39 -07001626 log_test.info('Got dhcp client IP %s for mac %s when cluster master is %s'%(cip1,macs[0],master))
1627 log_test.info('Changing cluster master from %s to %s'%(master, standbys[0]))
ChetanGaonker2099d722016-10-07 15:16:58 -07001628 self.change_master_current_cluster(new_master=standbys[0])
1629 cip2, sip2 = self.dhcprelay.send_recv(macs[1])
1630 assert_not_equal(cip2,None)
A R Karthick76a497a2017-04-12 10:59:39 -07001631 log_test.info('Got dhcp client IP %s for mac %s when cluster master is %s'%(cip2,macs[1],standbys[0]))
ChetanGaonker2099d722016-10-07 15:16:58 -07001632 self.change_master_current_cluster(new_master=master)
A R Karthick76a497a2017-04-12 10:59:39 -07001633 log_test.info('Changing cluster master from %s to %s'%(standbys[0],master))
ChetanGaonker2099d722016-10-07 15:16:58 -07001634 cip3, sip3 = self.dhcprelay.send_recv(macs[2])
1635 assert_not_equal(cip3,None)
A R Karthick76a497a2017-04-12 10:59:39 -07001636 log_test.info('Got dhcp client IP %s for mac %s when cluster master is %s'%(cip2,macs[2],master))
ChetanGaonker689b3862016-10-17 16:25:01 -07001637 self.dhcprelay.tearDownClass(controller=standbys[0])
ChetanGaonker2099d722016-10-07 15:16:58 -07001638
ChetanGaonker689b3862016-10-17 16:25:01 -07001639 def test_cluster_with_cord_subscriber_joining_next_channel_before_and_after_cluster_restart(self,onos_instances=ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -07001640 status = self.verify_cluster_status(onos_instances=onos_instances)
1641 assert_equal(status, True)
ChetanGaonker689b3862016-10-17 16:25:01 -07001642 self.subscriber.setUpClass(controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001643 self.subscriber.num_subscribers = 5
1644 self.subscriber.num_channels = 10
1645 for i in [0,1]:
1646 if i == 1:
1647 cord_test_onos_restart()
1648 time.sleep(45)
1649 status = self.verify_cluster_status(onos_instances=onos_instances)
1650 assert_equal(status, True)
A R Karthick76a497a2017-04-12 10:59:39 -07001651 log_test.info('Verifying cord subscriber functionality after cluster restart')
ChetanGaonker2099d722016-10-07 15:16:58 -07001652 else:
A R Karthick76a497a2017-04-12 10:59:39 -07001653 log_test.info('Verifying cord subscriber functionality before cluster restart')
ChetanGaonker2099d722016-10-07 15:16:58 -07001654 test_status = self.subscriber.subscriber_join_verify(num_subscribers = self.subscriber.num_subscribers,
1655 num_channels = self.subscriber.num_channels,
1656 cbs = (self.subscriber.tls_verify, self.subscriber.dhcp_next_verify,
1657 self.subscriber.igmp_next_verify, self.subscriber.traffic_verify),
1658 port_list = self.subscriber.generate_port_list(self.subscriber.num_subscribers,
1659 self.subscriber.num_channels))
1660 assert_equal(test_status, True)
ChetanGaonker689b3862016-10-17 16:25:01 -07001661 self.subscriber.tearDownClass(controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001662
ChetanGaonker689b3862016-10-17 16:25:01 -07001663 #not validated on cluster setup because ciena-cordigmp-multitable-2.0 app installation fails on cluster
1664 def test_cluster_with_cord_subscriber_join_next_channel_before_and_after_cluster_mastership_is_withdrawn(self,onos_instances=ONOS_INSTANCES):
1665 status = self.verify_cluster_status(onos_instances=onos_instances)
1666 assert_equal(status, True)
1667 master,standbys = self.get_cluster_current_master_standbys()
1668 assert_equal(len(standbys),(onos_instances-1))
1669 self.subscriber.setUpClass(controller=master)
1670 self.subscriber.num_subscribers = 5
1671 self.subscriber.num_channels = 10
1672 for i in [0,1]:
1673 if i == 1:
1674 status=self.withdraw_cluster_current_mastership(master_ip=master)
1675 asser_equal(status, True)
1676 master,standbys = self.get_cluster_current_master_standbys()
A R Karthick76a497a2017-04-12 10:59:39 -07001677 log_test.info('verifying cord subscriber functionality after cluster current master withdraw mastership')
ChetanGaonker689b3862016-10-17 16:25:01 -07001678 else:
A R Karthick76a497a2017-04-12 10:59:39 -07001679 log_test.info('verifying cord subscriber functionality before cluster master withdraw mastership')
ChetanGaonker689b3862016-10-17 16:25:01 -07001680 test_status = self.subscriber.subscriber_join_verify(num_subscribers = self.subscriber.num_subscribers,
1681 num_channels = self.subscriber.num_channels,
1682 cbs = (self.subscriber.tls_verify, self.subscriber.dhcp_next_verify,
1683 self.subscriber.igmp_next_verify, self.subscriber.traffic_verify),
1684 port_list = self.subscriber.generate_port_list(self.subscriber.num_subscribers,
1685 self.subscriber.num_channels),controller=master)
1686 assert_equal(test_status, True)
1687 self.subscriber.tearDownClass(controller=master)
1688
1689 #not validated on cluster setup because ciena-cordigmp-multitable-2.0 app installation fails on cluster
1690 def test_cluster_with_cord_subscriber_join_recv_traffic_from_10channels_and_making_one_cluster_member_down(self,onos_instances=ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -07001691 status = self.verify_cluster_status(onos_instances=onos_instances)
1692 assert_equal(status, True)
1693 master, standbys = self.get_cluster_current_master_standbys()
1694 assert_equal(len(standbys),(onos_instances-1))
1695 onos_names_ips = self.get_cluster_container_names_ips()
1696 member_onos_name = onos_names_ips[standbys[0]]
ChetanGaonker689b3862016-10-17 16:25:01 -07001697 self.subscriber.setUpClass(controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001698 num_subscribers = 1
1699 num_channels = 10
1700 for i in [0,1]:
1701 if i == 1:
A R Karthick3b2e0372016-12-14 17:37:43 -08001702 cord_test_onos_shutdown(node = standbys[0])
ChetanGaonker2099d722016-10-07 15:16:58 -07001703 time.sleep(30)
ChetanGaonker689b3862016-10-17 16:25:01 -07001704 status = self.verify_cluster_status(onos_instances=onos_instances-1,verify=True,controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001705 assert_equal(status, True)
A R Karthick76a497a2017-04-12 10:59:39 -07001706 log_test.info('Verifying cord subscriber functionality after cluster member %s is down'%standbys[0])
ChetanGaonker2099d722016-10-07 15:16:58 -07001707 else:
A R Karthick76a497a2017-04-12 10:59:39 -07001708 log_test.info('Verifying cord subscriber functionality before cluster member %s is down'%standbys[0])
ChetanGaonker2099d722016-10-07 15:16:58 -07001709 test_status = self.subscriber.subscriber_join_verify(num_subscribers = num_subscribers,
1710 num_channels = num_channels,
1711 cbs = (self.subscriber.tls_verify, self.subscriber.dhcp_verify,
1712 self.subscriber.igmp_verify, self.subscriber.traffic_verify),
1713 port_list = self.subscriber.generate_port_list(num_subscribers, num_channels),
ChetanGaonker689b3862016-10-17 16:25:01 -07001714 negative_subscriber_auth = 'all',controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001715 assert_equal(test_status, True)
ChetanGaonker689b3862016-10-17 16:25:01 -07001716 self.subscriber.tearDownClass(controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001717
ChetanGaonker689b3862016-10-17 16:25:01 -07001718 def test_cluster_with_cord_subscriber_joining_next_10channels_making_two_cluster_members_down(self,onos_instances=ONOS_INSTANCES):
ChetanGaonker2099d722016-10-07 15:16:58 -07001719 status = self.verify_cluster_status(onos_instances=onos_instances)
1720 assert_equal(status, True)
1721 master, standbys = self.get_cluster_current_master_standbys()
1722 assert_equal(len(standbys),(onos_instances-1))
1723 onos_names_ips = self.get_cluster_container_names_ips()
1724 member1_onos_name = onos_names_ips[standbys[0]]
1725 member2_onos_name = onos_names_ips[standbys[1]]
ChetanGaonker689b3862016-10-17 16:25:01 -07001726 self.subscriber.setUpClass(controller=master)
ChetanGaonker2099d722016-10-07 15:16:58 -07001727 num_subscribers = 1
1728 num_channels = 10
1729 for i in [0,1]:
1730 if i == 1:
A R Karthick3b2e0372016-12-14 17:37:43 -08001731 cord_test_onos_shutdown(node = standbys[0])
1732 cord_test_onos_shutdown(node = standbys[1])
ChetanGaonker2099d722016-10-07 15:16:58 -07001733 time.sleep(60)
1734 status = self.verify_cluster_status(onos_instances=onos_instances-2)
1735 assert_equal(status, True)
A R Karthick76a497a2017-04-12 10:59:39 -07001736 log_test.info('Verifying cord subscriber funtionality after cluster two members %s and %s down'%(standbys[0],standbys[1]))
ChetanGaonker2099d722016-10-07 15:16:58 -07001737 else:
A R Karthick76a497a2017-04-12 10:59:39 -07001738 log_test.info('Verifying cord subscriber funtionality before cluster two members %s and %s down'%(standbys[0],standbys[1]))
ChetanGaonker2099d722016-10-07 15:16:58 -07001739 test_status = self.subscriber.subscriber_join_verify(num_subscribers = num_subscribers,
1740 num_channels = num_channels,
1741 cbs = (self.subscriber.tls_verify, self.subscriber.dhcp_next_verify,
1742 self.subscriber.igmp_next_verify, self.subscriber.traffic_verify),
1743 port_list = self.subscriber.generate_port_list(num_subscribers, num_channels),
1744 negative_subscriber_auth = 'all')
1745 assert_equal(test_status, True)
ChetanGaonker689b3862016-10-17 16:25:01 -07001746 self.subscriber.tearDownClass(controller=master)
1747
1748 #pass
1749 def test_cluster_with_multiple_ovs_switches(self,onos_instances = ONOS_INSTANCES):
1750 status = self.verify_cluster_status(onos_instances=onos_instances)
1751 assert_equal(status, True)
1752 device_dict = self.get_cluster_current_master_standbys_of_connected_devices()
1753 for device in device_dict.keys():
A R Karthick76a497a2017-04-12 10:59:39 -07001754 log_test.info("Device is %s"%device_dict[device])
ChetanGaonker689b3862016-10-17 16:25:01 -07001755 assert_not_equal(device_dict[device]['master'],'none')
A R Karthick76a497a2017-04-12 10:59:39 -07001756 log_test.info('Master and standbys for device %s are %s and %s'%(device,device_dict[device]['master'],device_dict[device]['standbys']))
ChetanGaonker689b3862016-10-17 16:25:01 -07001757 assert_equal(len(device_dict[device]['standbys']), onos_instances-1)
1758
1759 #pass
1760 def test_cluster_state_in_multiple_ovs_switches(self,onos_instances = ONOS_INSTANCES):
1761 status = self.verify_cluster_status(onos_instances=onos_instances)
1762 assert_equal(status, True)
1763 device_dict = self.get_cluster_current_master_standbys_of_connected_devices()
1764 cluster_ips = self.get_cluster_current_member_ips()
1765 for ip in cluster_ips:
1766 device_dict= self.get_cluster_current_master_standbys_of_connected_devices(controller = ip)
1767 assert_equal(len(device_dict.keys()),onos_instances)
1768 for device in device_dict.keys():
A R Karthick76a497a2017-04-12 10:59:39 -07001769 log_test.info("Device is %s"%device_dict[device])
ChetanGaonker689b3862016-10-17 16:25:01 -07001770 assert_not_equal(device_dict[device]['master'],'none')
A R Karthick76a497a2017-04-12 10:59:39 -07001771 log_test.info('Master and standbys for device %s are %s and %s'%(device,device_dict[device]['master'],device_dict[device]['standbys']))
ChetanGaonker689b3862016-10-17 16:25:01 -07001772 assert_equal(len(device_dict[device]['standbys']), onos_instances-1)
1773
1774 #pass
1775 def test_cluster_verifying_multiple_ovs_switches_after_master_is_restarted(self,onos_instances = ONOS_INSTANCES):
1776 status = self.verify_cluster_status(onos_instances=onos_instances)
1777 assert_equal(status, True)
1778 onos_names_ips = self.get_cluster_container_names_ips()
1779 master_count = self.get_number_of_devices_of_master()
A R Karthick76a497a2017-04-12 10:59:39 -07001780 log_test.info('Master count information is %s'%master_count)
ChetanGaonker689b3862016-10-17 16:25:01 -07001781 total_devices = 0
1782 for master in master_count.keys():
1783 total_devices += master_count[master]['size']
1784 if master_count[master]['size'] != 0:
1785 restart_ip = master
1786 assert_equal(total_devices,onos_instances)
1787 member_onos_name = onos_names_ips[restart_ip]
A R Karthick76a497a2017-04-12 10:59:39 -07001788 log_test.info('Restarting cluster member %s having ip %s'%(member_onos_name,restart_ip))
ChetanGaonker689b3862016-10-17 16:25:01 -07001789 Container(member_onos_name, Onos.IMAGE).restart()
1790 time.sleep(40)
1791 master_count = self.get_number_of_devices_of_master()
A R Karthick76a497a2017-04-12 10:59:39 -07001792 log_test.info('Master count information after restart is %s'%master_count)
ChetanGaonker689b3862016-10-17 16:25:01 -07001793 total_devices = 0
1794 for master in master_count.keys():
1795 total_devices += master_count[master]['size']
1796 if master == restart_ip:
1797 assert_equal(master_count[master]['size'], 0)
1798 assert_equal(total_devices,onos_instances)
1799
1800 #pass
1801 def test_cluster_verifying_multiple_ovs_switches_with_one_master_down(self,onos_instances = ONOS_INSTANCES):
1802 status = self.verify_cluster_status(onos_instances=onos_instances)
1803 assert_equal(status, True)
1804 onos_names_ips = self.get_cluster_container_names_ips()
1805 master_count = self.get_number_of_devices_of_master()
A R Karthick76a497a2017-04-12 10:59:39 -07001806 log_test.info('Master count information is %s'%master_count)
ChetanGaonker689b3862016-10-17 16:25:01 -07001807 total_devices = 0
1808 for master in master_count.keys():
1809 total_devices += master_count[master]['size']
1810 if master_count[master]['size'] != 0:
1811 restart_ip = master
1812 assert_equal(total_devices,onos_instances)
1813 master_onos_name = onos_names_ips[restart_ip]
A R Karthick76a497a2017-04-12 10:59:39 -07001814 log_test.info('Shutting down cluster member %s having ip %s'%(master_onos_name,restart_ip))
ChetanGaonker689b3862016-10-17 16:25:01 -07001815 Container(master_onos_name, Onos.IMAGE).kill()
1816 time.sleep(40)
1817 for ip in onos_names_ips.keys():
1818 if ip != restart_ip:
1819 controller_ip = ip
1820 status = self.verify_cluster_status(onos_instances=onos_instances-1,controller=controller_ip)
1821 assert_equal(status, True)
1822 master_count = self.get_number_of_devices_of_master(controller=controller_ip)
A R Karthick76a497a2017-04-12 10:59:39 -07001823 log_test.info('Master count information after restart is %s'%master_count)
ChetanGaonker689b3862016-10-17 16:25:01 -07001824 total_devices = 0
1825 for master in master_count.keys():
1826 total_devices += master_count[master]['size']
1827 if master == restart_ip:
1828 assert_equal(master_count[master]['size'], 0)
1829 assert_equal(total_devices,onos_instances)
1830
1831 #pass
1832 def test_cluster_verifying_multiple_ovs_switches_with_current_master_withdrawing_mastership(self,onos_instances = ONOS_INSTANCES):
1833 status = self.verify_cluster_status(onos_instances=onos_instances)
1834 assert_equal(status, True)
1835 master_count = self.get_number_of_devices_of_master()
A R Karthick76a497a2017-04-12 10:59:39 -07001836 log_test.info('Master count information is %s'%master_count)
ChetanGaonker689b3862016-10-17 16:25:01 -07001837 total_devices = 0
1838 for master in master_count.keys():
1839 total_devices += int(master_count[master]['size'])
1840 if master_count[master]['size'] != 0:
1841 master_ip = master
A R Karthick76a497a2017-04-12 10:59:39 -07001842 log_test.info('Devices of master %s are %s'%(master_count[master]['devices'],master))
ChetanGaonker689b3862016-10-17 16:25:01 -07001843 device_id = str(master_count[master]['devices'][0])
1844 device_count = master_count[master]['size']
1845 assert_equal(total_devices,onos_instances)
A R Karthick76a497a2017-04-12 10:59:39 -07001846 log_test.info('Withdrawing mastership of device %s for controller %s'%(device_id,master_ip))
ChetanGaonker689b3862016-10-17 16:25:01 -07001847 status=self.withdraw_cluster_current_mastership(master_ip=master_ip,device_id = device_id)
1848 assert_equal(status, True)
1849 master_count = self.get_number_of_devices_of_master()
A R Karthick76a497a2017-04-12 10:59:39 -07001850 log_test.info('Master count information after cluster mastership withdraw is %s'%master_count)
ChetanGaonker689b3862016-10-17 16:25:01 -07001851 total_devices = 0
1852 for master in master_count.keys():
1853 total_devices += int(master_count[master]['size'])
1854 if master == master_ip:
1855 assert_equal(master_count[master]['size'], device_count-1)
1856 assert_equal(total_devices,onos_instances)
1857
1858 #pass
1859 def test_cluster_verifying_multiple_ovs_switches_and_restarting_cluster(self,onos_instances = ONOS_INSTANCES):
1860 status = self.verify_cluster_status(onos_instances=onos_instances)
1861 assert_equal(status, True)
1862 master_count = self.get_number_of_devices_of_master()
A R Karthick76a497a2017-04-12 10:59:39 -07001863 log_test.info('Master count information is %s'%master_count)
ChetanGaonker689b3862016-10-17 16:25:01 -07001864 total_devices = 0
1865 for master in master_count.keys():
1866 total_devices += master_count[master]['size']
1867 assert_equal(total_devices,onos_instances)
A R Karthick76a497a2017-04-12 10:59:39 -07001868 log_test.info('Restarting cluster')
ChetanGaonker689b3862016-10-17 16:25:01 -07001869 cord_test_onos_restart()
1870 time.sleep(60)
1871 master_count = self.get_number_of_devices_of_master()
A R Karthick76a497a2017-04-12 10:59:39 -07001872 log_test.info('Master count information after restart is %s'%master_count)
ChetanGaonker689b3862016-10-17 16:25:01 -07001873 total_devices = 0
1874 for master in master_count.keys():
1875 total_devices += master_count[master]['size']
1876 assert_equal(total_devices,onos_instances)