Merge ~ack/maas:1943573-vmhost-interfaces-no-host into maas:master

Proposed by Alberto Donato
Status: Merged
Approved by: Alberto Donato
Approved revision: a0b3d14a3cc2dec200a15399e3c45fbeb2da71f4
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ack/maas:1943573-vmhost-interfaces-no-host
Merge into: maas:master
Diff against target: 107 lines (+48/-35)
2 files modified
src/maasserver/models/tests/test_virtualmachine.py (+8/-0)
src/maasserver/models/virtualmachine.py (+40/-35)
Reviewer Review Type Date Requested Status
Adam Collard (community) Approve
MAAS Lander Approve
Review via email: mp+408627@code.launchpad.net

Commit message

LP:1943573 only collect interfaces if a host is linked to the Pod

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

UNIT TESTS
-b 1943573-vmhost-interfaces-no-host lp:~ack/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: a0b3d14a3cc2dec200a15399e3c45fbeb2da71f4

review: Approve
Revision history for this message
Adam Collard (adam-collard) :
review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

LANDING
-b 1943573-vmhost-interfaces-no-host lp:~ack/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED BUILD
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10991/consoleText

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

LANDING
-b 1943573-vmhost-interfaces-no-host lp:~ack/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED BUILD
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10994/consoleText

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

LANDING
-b 1943573-vmhost-interfaces-no-host lp:~ack/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED BUILD
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10996/consoleText

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/models/tests/test_virtualmachine.py b/src/maasserver/models/tests/test_virtualmachine.py
2index ced2e59..6a9a230 100644
3--- a/src/maasserver/models/tests/test_virtualmachine.py
4+++ b/src/maasserver/models/tests/test_virtualmachine.py
5@@ -341,6 +341,14 @@ class TestGetVMHostResources(MAASServerTestCase):
6 ],
7 )
8
9+ def test_get_resources_interfaces_no_host(self):
10+ # regression test for LP:1943573, create at least an interface not
11+ # linked to any host to ensure it doesn't get picked up
12+ factory.make_Interface(INTERFACE_TYPE.UNKNOWN)
13+ pod = factory.make_Pod(pod_type="virsh")
14+ resources = get_vm_host_resources(pod)
15+ self.assertEqual(resources.interfaces, [])
16+
17 def test_get_resources_interfaces_no_vm_link(self):
18 node = factory.make_Node()
19 iface = factory.make_Interface(
20diff --git a/src/maasserver/models/virtualmachine.py b/src/maasserver/models/virtualmachine.py
21index 97770c4..70258a9 100644
22--- a/src/maasserver/models/virtualmachine.py
23+++ b/src/maasserver/models/virtualmachine.py
24@@ -459,43 +459,48 @@ def _get_global_vm_host_resources(pod):
25 )
26
27 host_interfaces = {}
28- interfaces = (
29- Interface.objects.filter(node=pod.host)
30- .values("id", "name", "sriov_max_vf")
31- .annotate(
32- numa_index=F("numa_node__index"),
33- allocated=Count("virtualmachineinterface"),
34- tracked=ExpressionWrapper(
35- Q(virtualmachineinterface__vm__project=pod.tracked_project),
36- output_field=BooleanField(),
37- ),
38- sriov_attached=ExpressionWrapper(
39- Q(
40- virtualmachineinterface__attachment_type=InterfaceAttachType.SRIOV
41+ if pod.host:
42+ interfaces = (
43+ Interface.objects.filter(node=pod.host)
44+ .values("id", "name", "sriov_max_vf")
45+ .annotate(
46+ numa_index=F("numa_node__index"),
47+ allocated=Count("virtualmachineinterface"),
48+ tracked=ExpressionWrapper(
49+ Q(
50+ virtualmachineinterface__vm__project=pod.tracked_project
51+ ),
52+ output_field=BooleanField(),
53+ ),
54+ sriov_attached=ExpressionWrapper(
55+ Q(
56+ virtualmachineinterface__attachment_type=InterfaceAttachType.SRIOV
57+ ),
58+ output_field=BooleanField(),
59 ),
60- output_field=BooleanField(),
61- ),
62- )
63- )
64- for entry in interfaces:
65- interface = host_interfaces.get(entry["id"])
66- if not interface:
67- interface = VMHostNetworkInterface(
68- id=entry["id"],
69- name=entry["name"],
70- numa_index=entry["numa_index"],
71- virtual_functions=VMHostResource(free=entry["sriov_max_vf"]),
72 )
73- host_interfaces[entry["id"]] = interface
74- if not entry["sriov_attached"]:
75- continue
76- vfs = interface.virtual_functions
77- allocated = entry["allocated"]
78- if entry["tracked"]:
79- vfs.allocated_tracked += allocated
80- else:
81- vfs.allocated_other += allocated
82- vfs.free -= allocated
83+ )
84+ for entry in interfaces:
85+ interface = host_interfaces.get(entry["id"])
86+ if not interface:
87+ interface = VMHostNetworkInterface(
88+ id=entry["id"],
89+ name=entry["name"],
90+ numa_index=entry["numa_index"],
91+ virtual_functions=VMHostResource(
92+ free=entry["sriov_max_vf"]
93+ ),
94+ )
95+ host_interfaces[entry["id"]] = interface
96+ if not entry["sriov_attached"]:
97+ continue
98+ vfs = interface.virtual_functions
99+ allocated = entry["allocated"]
100+ if entry["tracked"]:
101+ vfs.allocated_tracked += allocated
102+ else:
103+ vfs.allocated_other += allocated
104+ vfs.free -= allocated
105 resources.interfaces = list(host_interfaces.values())
106
107 return resources

Subscribers

People subscribed via source and target branches