def get_routing_table(self, neighbor_address, target_prefix, retry=3, interval=-1): if interval < 0: interval = self.wait_per_retry print "check route %s on quagga : %s" % (target_prefix, neighbor_address) retry_count = 0 # quagga cli doesn't show prefix's netmask quagga_prefix = target_prefix.split('/')[0] while True: tn = qaccess.login(neighbor_address) q_rib = qaccess.show_rib(tn) qaccess.logout(tn) for q_path in q_rib: if quagga_prefix == q_path['Network']: return q_path retry_count += 1 if retry_count > retry: break else: print "target_prefix %s is none" % target_prefix print "wait (" + str(interval) + " seconds)" time.sleep(interval) print "route : %s is none" % target_prefix return None
def check_func(): tn = qaccess.login(address) q_rib = qaccess.show_rib(tn, af) for quagga_config in self.quagga_configs: if quagga_config.peer_ip == address or quagga_config.ip_version != af: for c_dest in quagga_config.destinations.itervalues(): exist_n = 0 for c_path in c_dest.paths: # print "conf : ", c_path.network, c_path.nexthop, "my ip or different ip version!!!" for q_path in q_rib: # print "quag : ", q_path['Network'], q_path['Next Hop'] if "0.0.0.0" == q_path['Next Hop'] or "::" == q_path['Next Hop']: continue if c_path.network.split("/")[0] == q_path['Network']: exist_n += 1 if exist_n != 0: return False else: for c_dest in quagga_config.destinations.itervalues(): exist_n = 0 for c_path in c_dest.paths: # print "conf : ", c_path.network, c_path.nexthop for q_path in q_rib: # print "quag : ", q_path['Network'], q_path['Next Hop'] if quagga_config.ip_version != fab.IPv6: c_path.network = c_path.network.split("/")[0] if c_path.network == q_path['Network'] and c_path.nexthop == q_path['Next Hop']: exist_n += 1 if exist_n != 1: return False return True
def assert_quagga_rib(self, address): retry_count = 0 cmp_result = False while retry_count < self.dest_check_limit: tn = qaccess.login(address) q_rib = qaccess.show_rib(tn) cmp_result = self.compare_route_with_quagga_configs(address, q_rib, route_server=False) if cmp_result: print "compare OK" break else: retry_count += 1 print "compare NG -> retry ( %d / %d )" % (retry_count, self.dest_check_limit) time.sleep(self.wait_per_retry) self.assertTrue(cmp_result)
def assert_quagga_rib(self, address): retry_count = 0 cmp_result = False while retry_count < self.dest_check_limit: tn = qaccess.login(address) q_rib = qaccess.show_rib(tn) cmp_result = self.compare_route_with_quagga_configs( address, q_rib, route_server=False) if cmp_result: print "compare OK" break else: retry_count += 1 print "compare NG -> retry ( %d / %d )" % ( retry_count, self.dest_check_limit) time.sleep(self.wait_per_retry) self.assertTrue(cmp_result)
def test_09_advertising_route_when_quagga_removed(self): print "test_advertising_route_when_removed_quagga" if self.check_load_config() is False: return remove_quagga_address = "10.0.0." + str(self.remove_quagga) removed_prefix = "10.0.0.%d/24" % self.remove_quagga for address in self.get_neighbor_address(self.gobgp_config): if remove_quagga_address == address: continue print "check of [ " + address + " ]" retry_count = 0 cmp_result = False while retry_count < self.dest_check_limit: tn = qaccess.login(address) q_rib = qaccess.show_rib(tn) still_exists = False for q_path in q_rib: if q_path['Network'] == removed_prefix: still_exists = True #self.assertEqual(still_exists, False) cmp_result = self.compare_route_with_quagga_configs( address, q_rib, route_server=False) if cmp_result and not still_exists: print "compare OK" break else: retry_count += 1 print "compare NG -> retry ( %d / %d )" % ( retry_count, self.dest_check_limit) time.sleep(self.wait_per_retry) self.assertEqual(still_exists, False) self.assertEqual(cmp_result, True)
def check_func(): tn = qaccess.login(address) q_rib = qaccess.show_rib(tn, af) for quagga_config in self.quagga_configs: if quagga_config.peer_ip == address or quagga_config.ip_version != af: for c_dest in quagga_config.destinations.itervalues(): exist_n = 0 for c_path in c_dest.paths: # print "conf : ", c_path.network, c_path.nexthop, "my ip or different ip version!!!" for q_path in q_rib: # print "quag : ", q_path['Network'], q_path['Next Hop'] if "0.0.0.0" == q_path[ 'Next Hop'] or "::" == q_path[ 'Next Hop']: continue if c_path.network.split( "/")[0] == q_path['Network']: exist_n += 1 if exist_n != 0: return False else: for c_dest in quagga_config.destinations.itervalues(): exist_n = 0 for c_path in c_dest.paths: # print "conf : ", c_path.network, c_path.nexthop for q_path in q_rib: # print "quag : ", q_path['Network'], q_path['Next Hop'] if quagga_config.ip_version != fab.IPv6: c_path.network = c_path.network.split( "/")[0] if c_path.network == q_path[ 'Network'] and c_path.nexthop == q_path[ 'Next Hop']: exist_n += 1 if exist_n != 1: return False return True
def test_09_advertising_route_when_quagga_removed(self): print "test_advertising_route_when_removed_quagga" if self.check_load_config() is False: return remove_quagga_address = "10.0.0." + str(self.remove_quagga) removed_prefix = "10.0.0.%d/24" % self.remove_quagga for address in self.get_neighbor_address(self.gobgp_config): if remove_quagga_address == address: continue print "check of [ " + address + " ]" retry_count = 0 cmp_result = False while retry_count < self.dest_check_limit: tn = qaccess.login(address) q_rib = qaccess.show_rib(tn) still_exists = False for q_path in q_rib: if q_path['Network'] == removed_prefix: still_exists = True #self.assertEqual(still_exists, False) cmp_result = self.compare_route_with_quagga_configs(address, q_rib, route_server=False) if cmp_result and not still_exists: print "compare OK" break else: retry_count += 1 print "compare NG -> retry ( %d / %d )" % (retry_count, self.dest_check_limit) time.sleep(self.wait_per_retry) self.assertEqual(still_exists, False) self.assertEqual(cmp_result, True)