sts-sponsors team mailing list archive
-
sts-sponsors team
-
Mailing list archive
-
Message #05966
[Merge] ~cgrabowski/maas:fix_boot_params_on_deployment into maas:master
Christian Grabowski has proposed merging ~cgrabowski/maas:fix_boot_params_on_deployment into maas:master.
Commit message:
add units for get_node_from_mac_or_hardware_uuid
ensure MAC is properly sorts for boot config query
Requested reviews:
MAAS Maintainers (maas-maintainers)
For more details, see:
https://code.launchpad.net/~cgrabowski/maas/+git/maas/+merge/438942
--
Your team MAAS Maintainers is requested to review the proposed merge of ~cgrabowski/maas:fix_boot_params_on_deployment into maas:master.
diff --git a/src/maasserver/rpc/boot.py b/src/maasserver/rpc/boot.py
index 0f2636c..c55c9c2 100644
--- a/src/maasserver/rpc/boot.py
+++ b/src/maasserver/rpc/boot.py
@@ -49,19 +49,23 @@ def get_node_from_mac_or_hardware_uuid(mac=None, hardware_uuid=None):
Returns a Node object or None if no node with the given MAC address or
hardware UUID exists.
"""
- if mac and hardware_uuid:
- node = Node.objects.filter(
- Q(
+ if mac:
+ if "-" in mac:
+ mac = mac.replace("-", ":")
+
+ if hardware_uuid:
+ node = Node.objects.filter(
+ Q(
+ current_config__interface__type=INTERFACE_TYPE.PHYSICAL,
+ current_config__interface__mac_address=mac,
+ )
+ | Q(hardware_uuid__iexact=hardware_uuid)
+ )
+ else:
+ node = Node.objects.filter(
current_config__interface__type=INTERFACE_TYPE.PHYSICAL,
current_config__interface__mac_address=mac,
)
- | Q(hardware_uuid__iexact=hardware_uuid)
- )
- elif mac:
- node = Node.objects.filter(
- current_config__interface__type=INTERFACE_TYPE.PHYSICAL,
- current_config__interface__mac_address=mac,
- )
elif hardware_uuid:
node = Node.objects.filter(hardware_uuid__iexact=hardware_uuid)
else:
diff --git a/src/maasserver/rpc/tests/test_boot.py b/src/maasserver/rpc/tests/test_boot.py
index 858d7bd..7dddaca 100644
--- a/src/maasserver/rpc/tests/test_boot.py
+++ b/src/maasserver/rpc/tests/test_boot.py
@@ -29,8 +29,11 @@ from maasserver.rpc.boot import (
get_boot_config_for_machine,
get_boot_filenames,
)
+from maasserver.rpc.boot import (
+ get_node_from_mac_or_hardware_uuid,
+ merge_kparams_with_extra,
+)
from maasserver.rpc.boot import get_config as orig_get_config
-from maasserver.rpc.boot import merge_kparams_with_extra
from maasserver.testing.architecture import make_usable_architecture
from maasserver.testing.config import RegionConfigurationFixture
from maasserver.testing.factory import factory
@@ -1624,3 +1627,36 @@ class TestGetBootConfigForMachine(MAASServerTestCase):
self.assertEqual(osystem, configs["commissioning_osystem"])
self.assertEqual(series, configs["commissioning_distro_series"])
self.assertEqual(config_arch, "generic")
+
+
+class TestGetNodeFromMacOrHardwareUUID(MAASServerTestCase):
+ def test_get_node_from_mac_or_hardware_uuid_with_regular_mac(self):
+ node = factory.make_Node_with_Interface_on_Subnet()
+ iface = node.current_config.interface_set.first()
+ result = get_node_from_mac_or_hardware_uuid(mac=iface.mac_address)
+ self.assertEqual(node, result)
+
+ def test_get_node_from_mac_or_hardware_uuid_with_dash_mac(self):
+ node = factory.make_Node_with_Interface_on_Subnet()
+ iface = node.current_config.interface_set.first()
+ result = get_node_from_mac_or_hardware_uuid(
+ mac=iface.mac_address.replace(":", "-")
+ )
+ self.assertEqual(node, result)
+
+ def test_get_node_from_mac_or_hardware_uuid_with_mac_and_hardware_uuid(
+ self,
+ ):
+ node = factory.make_Node_with_Interface_on_Subnet()
+ iface = node.current_config.interface_set.first()
+ result = get_node_from_mac_or_hardware_uuid(
+ mac=iface.mac_address, hardware_uuid=node.hardware_uuid
+ )
+ self.assertEqual(node, result)
+
+ def test_get_node_from_mac_or_hardware_uuid_with_hardware_uuid(self):
+ node = factory.make_Node_with_Interface_on_Subnet()
+ result = get_node_from_mac_or_hardware_uuid(
+ hardware_uuid=node.hardware_uuid
+ )
+ self.assertEqual(node, result)
Follow ups