def test_get_segmentation_ids_from_net_list(self): networks_list = [self.net_1_info, self.net_2_info] seg_ids = {'gre': [5], 'vlan': [10]} result = neutron.get_segmentation_ids_from_net_list(networks_list) self.assertEqual(seg_ids, result)
def test_get_segmentation_ids_from_net_list(self): networks_list = [self.net_1_info, self.net_2_info] seg_ids = {'gre': [5], 'vlan': [10]} result = neutron.get_segmentation_ids_from_net_list(networks_list) self.assertEqual(seg_ids, result)
def get_overlapping_networks(self, dst_info): """ Get lists of networks, that overlap with the DST. :param dst_info: NetworkInfo instance of DST cloud :return nets_with_overlapping_subnets, nets_with_overlapping_seg_ids: Tuple of lists with overlapping networks IDs. 1. List of networks IDs with overlapping subnets; 2. List of networks IDs with overlapping segmentation IDs. """ dst_net_info = dst_info.networks_info dst_seg_ids = neutron.get_segmentation_ids_from_net_list(dst_net_info) nets_with_overlapping_subnets = [] nets_with_overlapping_seg_ids = [] for network in self.get_networks(): dst_net = dst_info.by_hash.get(network.hash) if dst_net: if dst_net.external: # Skip external network due to it's checking later continue # Current network matches with network on DST # Have the same networks on SRC and DST LOG.debug("SRC network: '%s', DST network: '%s'", network.id, dst_net.id) try: network.check_network_overlapping(dst_net) except exception.AbortMigrationError: nets_with_overlapping_subnets.append(network.id) else: # Current network does not match with any network on DST # Check Segmentation ID overlapping with DST LOG.debug("Check segmentation ID for SRC network: '%s'", network.id) try: network.check_segmentation_id_overlapping(dst_seg_ids) except exception.AbortMigrationError: dst_network = dst_info.get_network_by_segmentation_id( network.network_type, network.seg_id) overlap = {'src_net_id': network.id, 'dst_net_id': dst_network.id} nets_with_overlapping_seg_ids.append(overlap) # remove duplicates, cause 1 net may have several overlapping subnets nets_with_overlapping_subnets = list( set(nets_with_overlapping_subnets)) return nets_with_overlapping_subnets, nets_with_overlapping_seg_ids
def missing_vlan_physnets(self, dst_info, dst_neutron_client): """ Get list of missing physical networks for VLAN network type. :param dst_info: NetworkInfo instance of DST cloud :param dst_neutron_client: DST neutron client :return: List of missing VLAN physnets. """ missing_vlan_physnets = [] dst_vlan_physnets = [net.physnet for net in dst_info.get_networks() if net.network_type == 'vlan'] # We need to specify segmentation ID in case of VLAN network creation # in OpenStack versions earlier than Juno (f.e. Icehouse, Grizzly etc.) dst_seg_ids = neutron.get_segmentation_ids_from_net_list( dst_info.networks_info) # We do not care about free segmentation ID on source cloud, we only # need to have destination one for checking purpose free_seg_id = neutron.generate_new_segmentation_id(dst_seg_ids, dst_seg_ids, 'vlan') for network in self.get_networks(): if network.network_type != 'vlan': continue if network.physnet in dst_vlan_physnets: continue try: network_info = { 'network': { 'provider:physical_network': network.physnet, 'provider:network_type': 'vlan', 'provider:segmentation_id': free_seg_id } } new_net = dst_neutron_client.create_network(network_info) except neutron_exc.NeutronClientException: missing_vlan_physnets.append(network.physnet) else: dst_neutron_client.delete_network(new_net['network']['id']) return missing_vlan_physnets