Merge ~cgrabowski/maas:fix_boot_params_on_deployment into maas:master

Proposed by Christian Grabowski
Status: Merged
Approved by: Christian Grabowski
Approved revision: 3e640b3eccb5e0185de52e54020e0d36b48e5e5b
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~cgrabowski/maas:fix_boot_params_on_deployment
Merge into: maas:master
Diff against target: 96 lines (+48/-11)
2 files modified
src/maasserver/rpc/boot.py (+11/-10)
src/maasserver/rpc/tests/test_boot.py (+37/-1)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Alberto Donato (community) Approve
Review via email: mp+438942@code.launchpad.net

Commit message

add units for get_node_from_mac_or_hardware_uuid

ensure MAC is properly formatted for boot config query

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b fix_boot_params_on_deployment lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 350887a8d9a6dfd659041a47b75bad330ce1a721

review: Approve
Revision history for this message
Alberto Donato (ack) wrote :

+1

A couple of suggestions inline

review: Approve
e89a5c2... by Christian Grabowski

use field function to format mac

3e640b3... by Christian Grabowski

simplify if-else by appending existing query

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b fix_boot_params_on_deployment lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 3e640b3eccb5e0185de52e54020e0d36b48e5e5b

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/rpc/boot.py b/src/maasserver/rpc/boot.py
2index 0f2636c..f489eaf 100644
3--- a/src/maasserver/rpc/boot.py
4+++ b/src/maasserver/rpc/boot.py
5@@ -13,6 +13,7 @@ from django.db.models import Q
6 from maasserver.compose_preseed import RSYSLOG_PORT
7 from maasserver.dns.config import get_resource_name_for_subnet
8 from maasserver.enum import BOOT_RESOURCE_FILE_TYPE, INTERFACE_TYPE
9+from maasserver.fields import normalise_macaddress
10 from maasserver.models import (
11 BootResource,
12 Config,
13@@ -49,19 +50,19 @@ def get_node_from_mac_or_hardware_uuid(mac=None, hardware_uuid=None):
14 Returns a Node object or None if no node with the given MAC address or
15 hardware UUID exists.
16 """
17- if mac and hardware_uuid:
18- node = Node.objects.filter(
19- Q(
20- current_config__interface__type=INTERFACE_TYPE.PHYSICAL,
21- current_config__interface__mac_address=mac,
22- )
23- | Q(hardware_uuid__iexact=hardware_uuid)
24- )
25- elif mac:
26- node = Node.objects.filter(
27+ if mac:
28+ if "-" in mac:
29+ mac = normalise_macaddress(mac)
30+
31+ q = Q(
32 current_config__interface__type=INTERFACE_TYPE.PHYSICAL,
33 current_config__interface__mac_address=mac,
34 )
35+
36+ if hardware_uuid:
37+ q |= Q(hardware_uuid__iexact=hardware_uuid)
38+
39+ node = Node.objects.filter(q)
40 elif hardware_uuid:
41 node = Node.objects.filter(hardware_uuid__iexact=hardware_uuid)
42 else:
43diff --git a/src/maasserver/rpc/tests/test_boot.py b/src/maasserver/rpc/tests/test_boot.py
44index 858d7bd..7dddaca 100644
45--- a/src/maasserver/rpc/tests/test_boot.py
46+++ b/src/maasserver/rpc/tests/test_boot.py
47@@ -29,8 +29,11 @@ from maasserver.rpc.boot import (
48 get_boot_config_for_machine,
49 get_boot_filenames,
50 )
51+from maasserver.rpc.boot import (
52+ get_node_from_mac_or_hardware_uuid,
53+ merge_kparams_with_extra,
54+)
55 from maasserver.rpc.boot import get_config as orig_get_config
56-from maasserver.rpc.boot import merge_kparams_with_extra
57 from maasserver.testing.architecture import make_usable_architecture
58 from maasserver.testing.config import RegionConfigurationFixture
59 from maasserver.testing.factory import factory
60@@ -1624,3 +1627,36 @@ class TestGetBootConfigForMachine(MAASServerTestCase):
61 self.assertEqual(osystem, configs["commissioning_osystem"])
62 self.assertEqual(series, configs["commissioning_distro_series"])
63 self.assertEqual(config_arch, "generic")
64+
65+
66+class TestGetNodeFromMacOrHardwareUUID(MAASServerTestCase):
67+ def test_get_node_from_mac_or_hardware_uuid_with_regular_mac(self):
68+ node = factory.make_Node_with_Interface_on_Subnet()
69+ iface = node.current_config.interface_set.first()
70+ result = get_node_from_mac_or_hardware_uuid(mac=iface.mac_address)
71+ self.assertEqual(node, result)
72+
73+ def test_get_node_from_mac_or_hardware_uuid_with_dash_mac(self):
74+ node = factory.make_Node_with_Interface_on_Subnet()
75+ iface = node.current_config.interface_set.first()
76+ result = get_node_from_mac_or_hardware_uuid(
77+ mac=iface.mac_address.replace(":", "-")
78+ )
79+ self.assertEqual(node, result)
80+
81+ def test_get_node_from_mac_or_hardware_uuid_with_mac_and_hardware_uuid(
82+ self,
83+ ):
84+ node = factory.make_Node_with_Interface_on_Subnet()
85+ iface = node.current_config.interface_set.first()
86+ result = get_node_from_mac_or_hardware_uuid(
87+ mac=iface.mac_address, hardware_uuid=node.hardware_uuid
88+ )
89+ self.assertEqual(node, result)
90+
91+ def test_get_node_from_mac_or_hardware_uuid_with_hardware_uuid(self):
92+ node = factory.make_Node_with_Interface_on_Subnet()
93+ result = get_node_from_mac_or_hardware_uuid(
94+ hardware_uuid=node.hardware_uuid
95+ )
96+ self.assertEqual(node, result)

Subscribers

People subscribed via source and target branches