def test_osvif_to_neutron_fixed_ips(self): ip11 = '1.1.1.1' ip12 = '2.2.2.2' ip3 = '3.3.3.3' subnet_id_1 = uuidutils.generate_uuid() subnet_id_2 = uuidutils.generate_uuid() subnet_id_3 = uuidutils.generate_uuid() subnet_1 = osv_subnet.Subnet(ips=osv_fixed_ip.FixedIPList(objects=[ osv_fixed_ip.FixedIP(address=ip11), osv_fixed_ip.FixedIP(address=ip12) ])) subnet_2 = osv_subnet.Subnet() subnet_3 = osv_subnet.Subnet(ips=osv_fixed_ip.FixedIPList( objects=[osv_fixed_ip.FixedIP(address=ip3)])) net1 = osv_network.Network(subnets=osv_subnet.SubnetList( objects=[subnet_1])) net2 = osv_network.Network(subnets=osv_subnet.SubnetList( objects=[subnet_2])) net3 = osv_network.Network(subnets=osv_subnet.SubnetList( objects=[subnet_3])) subnets = {subnet_id_1: net1, subnet_id_2: net2, subnet_id_3: net3} expected = [{ 'subnet_id': subnet_id_1, 'ip_address': ip11 }, { 'subnet_id': subnet_id_1, 'ip_address': ip12 }, { 'subnet_id': subnet_id_2 }, { 'subnet_id': subnet_id_3, 'ip_address': ip3 }] ret = ovu.osvif_to_neutron_fixed_ips(subnets) def _sort_key(e): return (e.get('subnet_id'), e.get('ip_address')) self.assertEqual(sorted(expected, key=_sort_key), sorted(ret, key=_sort_key))
def _make_vif_subnet(subnets, subnet_id): """Makes a copy of an os-vif Subnet from subnets mapping. :param subnets: subnet mapping :param subnet_id: ID of the subnet to extract from 'subnets' mapping :return: a copy of an os-vif Subnet object matching 'subnet_id' """ subnet = subnets[subnet_id] vif_subnet = _neutron_to_osvif_subnet(subnet) vif_subnet.ips = osv_fixed_ip.FixedIPList(objects=[]) return vif_subnet
def _make_vif_subnet(subnets, subnet_id): """Makes a copy of an os-vif Subnet from subnets mapping. :param subnets: subnet mapping as returned by PodSubnetsDriver.get_subnets :param subnet_id: ID of the subnet to extract from 'subnets' mapping :return: a copy of an os-vif Subnet object matching 'subnet_id' """ network = subnets[subnet_id] if len(network.subnets.objects) != 1: raise k_exc.IntegrityError(_( "Network object for subnet %(subnet_id)s is invalid, " "must contain a single subnet, but %(num_subnets)s found") % { 'subnet_id': subnet_id, 'num_subnets': len(network.subnets.objects)}) subnet = network.subnets.objects[0].obj_clone() subnet.ips = osv_fixed_ip.FixedIPList(objects=[]) return subnet