def test_validate_port_info_neutron_interface(self, log_mock): self.node.network_interface = 'neutron' self.node.save() port = object_utils.create_test_port( self.context, node_id=self.node.id, uuid=uuidutils.generate_uuid(), address='52:54:00:cf:2d:33') res = neutron.validate_port_info(self.node, port) self.assertTrue(res) self.assertFalse(log_mock.warning.called)
def _get_free_portgroups_and_ports(task, vif_id, physnets): """Get free portgroups and ports. It only returns ports or portgroups that can be used for attachment of vif_id. :param task: a TaskManager instance. :param vif_id: Name or UUID of a VIF. :param physnets: Set of physical networks on which the VIF may be attached. This is governed by the segments of the VIF's network. An empty set indicates that the ports' physical networks should be ignored. :returns: list of free ports and portgroups. :raises: VifAlreadyAttached, if vif_id is attached to any of the node's ports or portgroups. """ # This list contains ports and portgroups selected as candidates for # attachment. free_port_like_objs = [] # This is a mapping of portgroup id to collection of its free ports ports_by_portgroup = collections.defaultdict(list) # This set contains IDs of portgroups that should be ignored, as they have # at least one port with vif already attached to it non_usable_portgroups = set() for p in task.ports: # Validate that port has needed information if not neutron.validate_port_info(task.node, p): continue if _vif_attached(p, vif_id): # Consider such portgroup unusable. The fact that we can have None # added in this set is not a problem non_usable_portgroups.add(p.portgroup_id) continue if not _is_port_physnet_allowed(p, physnets): continue if p.portgroup_id is None: # ports without portgroup_id are always considered candidates free_port_like_objs.append(p) else: ports_by_portgroup[p.portgroup_id].append(p) for pg in task.portgroups: if _vif_attached(pg, vif_id): continue if pg.id in non_usable_portgroups: # This portgroup has vifs attached to its ports, consider its # ports instead to avoid collisions free_port_like_objs.extend(ports_by_portgroup[pg.id]) # Also ignore empty portgroups elif ports_by_portgroup[pg.id]: free_port_like_objs.append(pg) return free_port_like_objs
def test_validate_port_info_flat_interface_with_client_id(self, log_mock): self.node.network_interface = 'flat' self.node.save() llc = {} port = object_utils.create_test_port( self.context, node_id=self.node.id, uuid=uuidutils.generate_uuid(), address='52:54:00:cf:2d:33', local_link_connection=llc, extra={'client-id': self._CLIENT_ID}) res = neutron.validate_port_info(self.node, port) self.assertTrue(res) self.assertFalse(log_mock.warning.called)