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

Proposed by Alberto Donato
Status: Merged
Approved by: Alberto Donato
Approved revision: 08b885871611384209c9791ba7ea65048ed40b91
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ack/maas:1943573-vmhost-interfaces-no-host-3.0
Merge into: maas:3.0
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
Alberto Donato (community) Approve
Review via email: mp+408720@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
Alberto Donato (ack) :
review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

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

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/maasserver/models/tests/test_virtualmachine.py b/src/maasserver/models/tests/test_virtualmachine.py
index ced2e59..6a9a230 100644
--- a/src/maasserver/models/tests/test_virtualmachine.py
+++ b/src/maasserver/models/tests/test_virtualmachine.py
@@ -341,6 +341,14 @@ class TestGetVMHostResources(MAASServerTestCase):
341 ],341 ],
342 )342 )
343343
344 def test_get_resources_interfaces_no_host(self):
345 # regression test for LP:1943573, create at least an interface not
346 # linked to any host to ensure it doesn't get picked up
347 factory.make_Interface(INTERFACE_TYPE.UNKNOWN)
348 pod = factory.make_Pod(pod_type="virsh")
349 resources = get_vm_host_resources(pod)
350 self.assertEqual(resources.interfaces, [])
351
344 def test_get_resources_interfaces_no_vm_link(self):352 def test_get_resources_interfaces_no_vm_link(self):
345 node = factory.make_Node()353 node = factory.make_Node()
346 iface = factory.make_Interface(354 iface = factory.make_Interface(
diff --git a/src/maasserver/models/virtualmachine.py b/src/maasserver/models/virtualmachine.py
index 5e12a30..593906c 100644
--- a/src/maasserver/models/virtualmachine.py
+++ b/src/maasserver/models/virtualmachine.py
@@ -459,43 +459,48 @@ def _get_global_vm_host_resources(pod):
459 )459 )
460460
461 host_interfaces = {}461 host_interfaces = {}
462 interfaces = (462 if pod.host:
463 Interface.objects.filter(node=pod.host)463 interfaces = (
464 .values("id", "name", "sriov_max_vf")464 Interface.objects.filter(node=pod.host)
465 .annotate(465 .values("id", "name", "sriov_max_vf")
466 numa_index=F("numa_node__index"),466 .annotate(
467 allocated=Count("virtualmachineinterface"),467 numa_index=F("numa_node__index"),
468 tracked=ExpressionWrapper(468 allocated=Count("virtualmachineinterface"),
469 Q(virtualmachineinterface__vm__project=pod.tracked_project),469 tracked=ExpressionWrapper(
470 output_field=BooleanField(),470 Q(
471 ),471 virtualmachineinterface__vm__project=pod.tracked_project
472 sriov_attached=ExpressionWrapper(472 ),
473 Q(473 output_field=BooleanField(),
474 virtualmachineinterface__attachment_type=InterfaceAttachType.SRIOV474 ),
475 sriov_attached=ExpressionWrapper(
476 Q(
477 virtualmachineinterface__attachment_type=InterfaceAttachType.SRIOV
478 ),
479 output_field=BooleanField(),
475 ),480 ),
476 output_field=BooleanField(),
477 ),
478 )
479 )
480 for entry in interfaces:
481 interface = host_interfaces.get(entry["id"])
482 if not interface:
483 interface = VMHostNetworkInterface(
484 id=entry["id"],
485 name=entry["name"],
486 numa_index=entry["numa_index"],
487 virtual_functions=VMHostResource(free=entry["sriov_max_vf"]),
488 )481 )
489 host_interfaces[entry["id"]] = interface482 )
490 if not entry["sriov_attached"]:483 for entry in interfaces:
491 continue484 interface = host_interfaces.get(entry["id"])
492 vfs = interface.virtual_functions485 if not interface:
493 allocated = entry["allocated"]486 interface = VMHostNetworkInterface(
494 if entry["tracked"]:487 id=entry["id"],
495 vfs.allocated_tracked += allocated488 name=entry["name"],
496 else:489 numa_index=entry["numa_index"],
497 vfs.allocated_other += allocated490 virtual_functions=VMHostResource(
498 vfs.free -= allocated491 free=entry["sriov_max_vf"]
492 ),
493 )
494 host_interfaces[entry["id"]] = interface
495 if not entry["sriov_attached"]:
496 continue
497 vfs = interface.virtual_functions
498 allocated = entry["allocated"]
499 if entry["tracked"]:
500 vfs.allocated_tracked += allocated
501 else:
502 vfs.allocated_other += allocated
503 vfs.free -= allocated
499 resources.interfaces = list(host_interfaces.values())504 resources.interfaces = list(host_interfaces.values())
500505
501 return resources506 return resources

Subscribers

People subscribed via source and target branches