def test_portgroup_by_id_no_such_portgroup(self): node = object_utils.create_test_node(self.context, driver='fake') object_utils.create_test_portgroup(self.context, node_id=node.id) with task_manager.acquire(self.context, node.uuid) as task: portgroup_id = 'invalid-portgroup-id' res = network.get_portgroup_by_id(task, portgroup_id) self.assertIsNone(res)
def test_portgroup_by_id_no_such_portgroup(self): node = object_utils.create_test_node(self.context) object_utils.create_test_portgroup(self.context, node_id=node.id) with task_manager.acquire(self.context, node.uuid) as task: portgroup_id = 'invalid-portgroup-id' res = network.get_portgroup_by_id(task, portgroup_id) self.assertIsNone(res)
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_physnets = network.get_physnets_by_portgroup_id(task, port_obj.portgroup_id, exclude_port=port_obj) if not pg_physnets: return # 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 test_portgroup_by_id(self): node = object_utils.create_test_node(self.context, driver='fake') portgroup = object_utils.create_test_portgroup(self.context, node_id=node.id) object_utils.create_test_portgroup(self.context, node_id=node.id, uuid=uuidutils.generate_uuid(), address='00:11:22:33:44:55', name='pg2') with task_manager.acquire(self.context, node.uuid) as task: res = network.get_portgroup_by_id(task, portgroup.id) self.assertEqual(portgroup.id, res.id)
def test_portgroup_by_id(self): node = object_utils.create_test_node(self.context) portgroup = object_utils.create_test_portgroup(self.context, node_id=node.id) object_utils.create_test_portgroup(self.context, node_id=node.id, uuid=uuidutils.generate_uuid(), address='00:11:22:33:44:55', name='pg2') with task_manager.acquire(self.context, node.uuid) as task: res = network.get_portgroup_by_id(task, portgroup.id) self.assertEqual(portgroup.id, res.id)