def test_ports_by_portgroup_id_empty(self): node = object_utils.create_test_node(self.context, driver='fake') portgroup = object_utils.create_test_portgroup(self.context, node_id=node.id) with task_manager.acquire(self.context, node.uuid) as task: res = network.get_ports_by_portgroup_id(task, portgroup.id) self.assertEqual([], res)
def test_ports_by_portgroup_id_empty(self): node = object_utils.create_test_node(self.context) portgroup = object_utils.create_test_portgroup(self.context, node_id=node.id) with task_manager.acquire(self.context, node.uuid) as task: res = network.get_ports_by_portgroup_id(task, portgroup.id) self.assertEqual([], res)
def test_ports_by_portgroup_id(self): node = object_utils.create_test_node(self.context) portgroup = object_utils.create_test_portgroup(self.context, node_id=node.id) port = object_utils.create_test_port(self.context, node_id=node.id, portgroup_id=portgroup.id) object_utils.create_test_port(self.context, node_id=node.id, uuid=uuidutils.generate_uuid(), address='00:11:22:33:44:55') with task_manager.acquire(self.context, node.uuid) as task: res = network.get_ports_by_portgroup_id(task, portgroup.id) self.assertEqual([port.id], [p.id for p in res])
def _get_physnet_for_portgroup(task, portgroup): """Return the physical network associated with a portgroup. :param task: a TaskManager instance. :param portgroup: a Portgroup object. :returns: The physical network associated with the portgroup. :raises: PortgroupPhysnetInconsistent if the portgroup's ports are not assigned the same physical network. """ pg_ports = network.get_ports_by_portgroup_id(task, portgroup.id) pg_physnets = {port.physical_network for port in pg_ports} # Sanity check: there should be at least one port in the portgroup and # all ports should have the same physical network. if len(pg_physnets) != 1: raise exception.PortgroupPhysnetInconsistent( portgroup=portgroup.uuid, physical_networks=", ".join(pg_physnets)) return pg_physnets.pop()
def _get_physnet_for_portgroup(task, portgroup): """Return the physical network associated with a portgroup. :param task: a TaskManager instance. :param portgroup: a Portgroup object. :returns: The physical network associated with the portgroup. :raises: PortgroupPhysnetInconsistent if the portgroup's ports are not assigned the same physical network. """ pg_ports = network.get_ports_by_portgroup_id(task, portgroup.id) pg_physnets = {port.physical_network for port in pg_ports} # Sanity check: there should be at least one port in the portgroup and # all ports should have the same physical network. if len(pg_physnets) != 1: raise exception.PortgroupPhysnetInconsistent( portgroup=portgroup.uuid, physical_networks=", ".join(pg_physnets)) return pg_physnets.pop()
def validate_port_physnet(task, port_obj): """Validate the consistency of physical networks of ports in a portgroup. Validate the consistency of a port's physical network with other ports in the same portgroup. All ports in a portgroup should have the same value (which may be None) for their physical_network field. During creation or update of a port in a portgroup we apply the following validation criteria: - If the portgroup has existing ports with different physical networks, we raise PortgroupPhysnetInconsistent. This shouldn't ever happen. - If the port has a physical network that is inconsistent with other ports in the portgroup, we raise exception.Conflict. If a port's physical network is None, this indicates that ironic's VIF attachment mapping algorithm should operate in a legacy (physical network unaware) mode for this port or portgroup. This allows existing ironic nodes to continue to function after an upgrade to a release including physical network support. :param task: a TaskManager instance :param port_obj: a port object to be validated. :raises: Conflict if the port is a member of a portgroup which is on a different physical network. :raises: PortgroupPhysnetInconsistent if the port's portgroup has ports which are not all assigned the same physical network. """ if 'portgroup_id' not in port_obj or not port_obj.portgroup_id: return delta = port_obj.obj_what_changed() # We can skip this step if the port's portgroup membership or physical # network assignment is not being changed (during creation these will # appear changed). if not (delta & {'portgroup_id', 'physical_network'}): return # Determine the current physical network of the portgroup. pg_ports = network.get_ports_by_portgroup_id(task, port_obj.portgroup_id) port_obj_id = port_obj.id if 'id' in port_obj else None pg_physnets = { port.physical_network for port in pg_ports if port.id != port_obj_id } if not pg_physnets: return # Sanity check that all existing ports in the group have the same # physical network (should never happen). if len(pg_physnets) > 1: portgroup = network.get_portgroup_by_id(task, port_obj.portgroup_id) raise exception.PortgroupPhysnetInconsistent( portgroup=portgroup.uuid, physical_networks=", ".join(pg_physnets)) # Check that the port has the same physical network as any existing # member ports. pg_physnet = pg_physnets.pop() port_physnet = (port_obj.physical_network if 'physical_network' in port_obj else None) if port_physnet != pg_physnet: portgroup = network.get_portgroup_by_id(task, port_obj.portgroup_id) msg = _("Port with physical network %(physnet)s cannot become a " "member of port group %(portgroup)s which has ports in " "physical network %(pg_physnet)s.") raise exception.Conflict( msg % { 'portgroup': portgroup.uuid, 'physnet': port_physnet, 'pg_physnet': pg_physnet })
def validate_port_physnet(task, port_obj): """Validate the consistency of physical networks of ports in a portgroup. Validate the consistency of a port's physical network with other ports in the same portgroup. All ports in a portgroup should have the same value (which may be None) for their physical_network field. During creation or update of a port in a portgroup we apply the following validation criteria: - If the portgroup has existing ports with different physical networks, we raise PortgroupPhysnetInconsistent. This shouldn't ever happen. - If the port has a physical network that is inconsistent with other ports in the portgroup, we raise exception.Conflict. If a port's physical network is None, this indicates that ironic's VIF attachment mapping algorithm should operate in a legacy (physical network unaware) mode for this port or portgroup. This allows existing ironic nodes to continue to function after an upgrade to a release including physical network support. :param task: a TaskManager instance :param port_obj: a port object to be validated. :raises: Conflict if the port is a member of a portgroup which is on a different physical network. :raises: PortgroupPhysnetInconsistent if the port's portgroup has ports which are not all assigned the same physical network. """ if 'portgroup_id' not in port_obj or not port_obj.portgroup_id: return delta = port_obj.obj_what_changed() # We can skip this step if the port's portgroup membership or physical # network assignment is not being changed (during creation these will # appear changed). if not (delta & {'portgroup_id', 'physical_network'}): return # Determine the current physical network of the portgroup. pg_ports = network.get_ports_by_portgroup_id(task, port_obj.portgroup_id) port_obj_id = port_obj.id if 'id' in port_obj else None pg_physnets = {port.physical_network for port in pg_ports if port.id != port_obj_id} if not pg_physnets: return # Sanity check that all existing ports in the group have the same # physical network (should never happen). if len(pg_physnets) > 1: portgroup = network.get_portgroup_by_id(task, port_obj.portgroup_id) raise exception.PortgroupPhysnetInconsistent( portgroup=portgroup.uuid, physical_networks=", ".join(pg_physnets)) # Check that the port has the same physical network as any existing # member ports. pg_physnet = pg_physnets.pop() port_physnet = (port_obj.physical_network if 'physical_network' in port_obj else None) if port_physnet != pg_physnet: portgroup = network.get_portgroup_by_id(task, port_obj.portgroup_id) msg = _("Port with physical network %(physnet)s cannot become a " "member of port group %(portgroup)s which has ports in " "physical network %(pg_physnet)s.") raise exception.Conflict( msg % {'portgroup': portgroup.uuid, 'physnet': port_physnet, 'pg_physnet': pg_physnet})