Merge ~mpontillo/maas:add-vlan-info-to-pod-handler--bug-1795759 into maas:master

Proposed by Mike Pontillo
Status: Merged
Approved by: Mike Pontillo
Approved revision: e82896c77f78bdd10a550f697783b73b784980b6
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~mpontillo/maas:add-vlan-info-to-pod-handler--bug-1795759
Merge into: maas:master
Diff against target: 101 lines (+62/-2)
2 files modified
src/maasserver/websockets/handlers/pod.py (+18/-0)
src/maasserver/websockets/handlers/tests/test_pod.py (+44/-2)
Reviewer Review Type Date Requested Status
Newell Jensen (community) Approve
Review via email: mp+356027@code.launchpad.net

Commit message

LP: #1795759 - Provide pod host metadata using Pod websocket handler.

To post a comment you must log in.
Revision history for this message
Mike Pontillo (mpontillo) wrote :

A future branch will update the triggers.

Revision history for this message
Newell Jensen (newell-jensen) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/websockets/handlers/pod.py b/src/maasserver/websockets/handlers/pod.py
2index 5d3810b..462a053 100644
3--- a/src/maasserver/websockets/handlers/pod.py
4+++ b/src/maasserver/websockets/handlers/pod.py
5@@ -99,7 +99,25 @@ class PodHandler(TimestampedModelHandler):
6 data["composed_machines_count"] = obj.node_set.filter(
7 node_type=NODE_TYPE.MACHINE).count()
8 data["hints"] = self.dehydrate_hints(obj.hints)
9+ if obj.host is not None:
10+ data["host"] = obj.host.system_id
11+ else:
12+ data["host"] = None
13 if not for_list:
14+ if obj.host is not None:
15+ data["attached_vlans"] = list(
16+ obj.host.interface_set.all().values_list(
17+ 'vlan_id', flat=True))
18+ boot_vlans = []
19+ query = obj.host.interface_set.all().prefetch_related(
20+ 'vlan__relay_vlan')
21+ for interface in query:
22+ if interface.has_bootable_vlan():
23+ boot_vlans.append(interface.vlan_id)
24+ data["boot_vlans"] = boot_vlans
25+ else:
26+ data["attached_vlans"] = []
27+ data["boot_vlans"] = []
28 storage_pools = obj.storage_pools.all()
29 if len(storage_pools) > 0:
30 pools_data = []
31diff --git a/src/maasserver/websockets/handlers/tests/test_pod.py b/src/maasserver/websockets/handlers/tests/test_pod.py
32index 8e46925..ddf3a4c 100644
33--- a/src/maasserver/websockets/handlers/tests/test_pod.py
34+++ b/src/maasserver/websockets/handlers/tests/test_pod.py
35@@ -81,7 +81,7 @@ class TestPodHandler(MAASTransactionServerTestCase):
36 failed_rack.system_id: factory.make_exception(),
37 }))
38
39- def make_pod_with_hints(self):
40+ def make_pod_with_hints(self, ip_address=None):
41 architectures = [
42 "amd64/generic", "i386/generic", "arm64/generic",
43 "armhf/generic"
44@@ -89,7 +89,9 @@ class TestPodHandler(MAASTransactionServerTestCase):
45 pod = factory.make_Pod(
46 architectures=architectures, capabilities=[
47 Capabilities.FIXED_LOCAL_STORAGE, Capabilities.ISCSI_STORAGE,
48- Capabilities.COMPOSABLE, Capabilities.STORAGE_POOLS])
49+ Capabilities.COMPOSABLE, Capabilities.STORAGE_POOLS],
50+ ip_address=ip_address
51+ )
52 pod.hints.cores = random.randint(8, 16)
53 pod.hints.memory = random.randint(4096, 8192)
54 pod.hints.cpu_speed = random.randint(2000, 3000)
55@@ -121,6 +123,46 @@ class TestPodHandler(MAASTransactionServerTestCase):
56 for key in expected_data:
57 self.assertEqual(expected_data[key], result[key], key)
58 self.assertThat(result, Equals(expected_data))
59+ self.assertThat(result['host'], Equals(None))
60+ self.assertThat(result['attached_vlans'], Equals([]))
61+ self.assertThat(result['boot_vlans'], Equals([]))
62+
63+ def test_get_with_pod_host(self):
64+ admin = factory.make_admin()
65+ handler = PodHandler(admin, {}, None)
66+ vlan = factory.make_VLAN(dhcp_on=True)
67+ subnet = factory.make_Subnet(vlan=vlan)
68+ node = factory.make_Node_with_Interface_on_Subnet(subnet=subnet)
69+ ip = factory.make_StaticIPAddress(
70+ interface=node.boot_interface, subnet=subnet)
71+ pod = self.make_pod_with_hints(ip_address=ip)
72+ expected_data = handler.full_dehydrate(pod)
73+ result = handler.get({"id": pod.id})
74+ self.assertItemsEqual(expected_data.keys(), result.keys())
75+ for key in expected_data:
76+ self.assertEqual(expected_data[key], result[key], key)
77+ self.assertThat(result, Equals(expected_data))
78+ self.assertThat(result['host'], Equals(node.system_id))
79+ self.assertThat(result['attached_vlans'], Equals([subnet.vlan_id]))
80+ self.assertThat(result['boot_vlans'], Equals([subnet.vlan_id]))
81+
82+ def test_get_with_pod_host_determines_vlan_boot_status(self):
83+ admin = factory.make_admin()
84+ handler = PodHandler(admin, {}, None)
85+ vlan = factory.make_VLAN(dhcp_on=False)
86+ subnet = factory.make_Subnet(vlan=vlan)
87+ node = factory.make_Node_with_Interface_on_Subnet(subnet=subnet)
88+ ip = factory.make_StaticIPAddress(
89+ interface=node.boot_interface, subnet=subnet)
90+ pod = self.make_pod_with_hints(ip_address=ip)
91+ expected_data = handler.full_dehydrate(pod)
92+ result = handler.get({"id": pod.id})
93+ self.assertItemsEqual(expected_data.keys(), result.keys())
94+ for key in expected_data:
95+ self.assertEqual(expected_data[key], result[key], key)
96+ self.assertThat(result, Equals(expected_data))
97+ self.assertThat(result['attached_vlans'], Equals([subnet.vlan_id]))
98+ self.assertThat(result['boot_vlans'], Equals([]))
99
100 def test_get_as_standard_user(self):
101 user = factory.make_User()

Subscribers

People subscribed via source and target branches