Merge ~ack/maas:1992185-vmhost-find-addr-interface-children into maas:master

Proposed by Alberto Donato
Status: Merged
Approved by: Alberto Donato
Approved revision: 83619edd2db79380df3082ab5839cd099be5691c
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ack/maas:1992185-vmhost-find-addr-interface-children
Merge into: maas:master
Diff against target: 119 lines (+69/-7)
2 files modified
src/metadataserver/api_twisted.py (+27/-6)
src/metadataserver/tests/test_api_twisted.py (+42/-1)
Reviewer Review Type Date Requested Status
Adam Collard (community) Approve
MAAS Lander Approve
Review via email: mp+431806@code.launchpad.net

Commit message

LP:1992185 look at all children to find the VM host address

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

UNIT TESTS
-b 1992185-vmhost-find-addr-interface-children lp:~ack/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/1113/consoleText
COMMIT: 83619edd2db79380df3082ab5839cd099be5691c

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

jenkins: !test

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

UNIT TESTS
-b 1992185-vmhost-find-addr-interface-children lp:~ack/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 83619edd2db79380df3082ab5839cd099be5691c

review: Approve
Revision history for this message
Adam Collard (adam-collard) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/metadataserver/api_twisted.py b/src/metadataserver/api_twisted.py
index c5f3789..d71c03c 100644
--- a/src/metadataserver/api_twisted.py
+++ b/src/metadataserver/api_twisted.py
@@ -18,7 +18,7 @@ from twisted.web.server import NOT_DONE_YET
18from maasserver.api.utils import extract_oauth_key_from_auth_header18from maasserver.api.utils import extract_oauth_key_from_auth_header
19from maasserver.enum import NODE_STATUS, NODE_TYPE19from maasserver.enum import NODE_STATUS, NODE_TYPE
20from maasserver.forms.pods import PodForm20from maasserver.forms.pods import PodForm
21from maasserver.models import Node21from maasserver.models import Interface, Node, StaticIPAddress
22from maasserver.preseed import CURTIN_INSTALL_LOG22from maasserver.preseed import CURTIN_INSTALL_LOG
23from maasserver.secrets import SecretManager23from maasserver.secrets import SecretManager
24from maasserver.utils.orm import (24from maasserver.utils.orm import (
@@ -209,11 +209,7 @@ def _create_vmhost_for_deployment(node):
209209
210 # the IP is associated to the bridge the boot interface is in, not the210 # the IP is associated to the bridge the boot interface is in, not the
211 # interface itself211 # interface itself
212 boot_if = node.get_boot_interface()212 ip = _get_ip_address_for_vmhost(node)
213 ifaces = list(boot_if.children.all())
214 ip = node.ip_addresses(ifaces=ifaces + [boot_if])[0]
215 if ":" in ip:
216 ip = f"[{ip}]"
217213
218 for secret_key, secret_value in deploy_secrets.items():214 for secret_key, secret_value in deploy_secrets.items():
219 is_lxd = secret_key == DEPLOY_SECRETS_LXD_KEY215 is_lxd = secret_key == DEPLOY_SECRETS_LXD_KEY
@@ -275,6 +271,31 @@ def _create_vmhost_for_deployment(node):
275 node.update_status(NODE_STATUS.DEPLOYED)271 node.update_status(NODE_STATUS.DEPLOYED)
276272
277273
274def _get_ip_address_for_vmhost(node):
275 boot_interface = node.get_boot_interface()
276 interface_ids = {boot_interface.id}
277
278 # recursively find all children interface IDs
279 new_ids = {boot_interface.id}
280 while new_ids:
281 new_ids = set(
282 Interface.objects.filter(parents__in=new_ids).values_list(
283 "id", flat=True
284 )
285 )
286 interface_ids |= new_ids
287
288 ip = (
289 StaticIPAddress.objects.exclude(ip__isnull=True)
290 .filter(interface__in=interface_ids)
291 .values_list("ip", flat=True)
292 .first()
293 )
294 if ":" in ip:
295 ip = f"[{ip}]"
296 return ip
297
298
278class StatusWorkerService(TimerService):299class StatusWorkerService(TimerService):
279 """Service to update nodes from received status messages."""300 """Service to update nodes from received status messages."""
280301
diff --git a/src/metadataserver/tests/test_api_twisted.py b/src/metadataserver/tests/test_api_twisted.py
index 1689ed9..7b36e79 100644
--- a/src/metadataserver/tests/test_api_twisted.py
+++ b/src/metadataserver/tests/test_api_twisted.py
@@ -1210,7 +1210,7 @@ class TestCreateVMHostForDeployment(MAASServerTestCase):
1210 )1210 )
1211 )1211 )
12121212
1213 def test_creates_vmhost_pick_right_interface(self):1213 def test_creates_vmhost_pick_right_interface_address(self):
1214 user = factory.make_User()1214 user = factory.make_User()
1215 node = factory.make_Node_with_Interface_on_Subnet(1215 node = factory.make_Node_with_Interface_on_Subnet(
1216 owner=user,1216 owner=user,
@@ -1244,6 +1244,47 @@ class TestCreateVMHostForDeployment(MAASServerTestCase):
1244 f"qemu+ssh://virsh@{addr}/system",1244 f"qemu+ssh://virsh@{addr}/system",
1245 )1245 )
12461246
1247 def test_creates_vmhost_pick_right_interface_with_bond(self):
1248 user = factory.make_User()
1249 node = factory.make_Node_with_Interface_on_Subnet(
1250 owner=user,
1251 status=NODE_STATUS.DEPLOYING,
1252 agent_name="maas-kvm-pod",
1253 install_kvm=True,
1254 )
1255 iface = factory.make_Interface(node=node)
1256 bond = factory.make_Interface(
1257 iftype=INTERFACE_TYPE.BOND,
1258 node=node,
1259 parents=[node.get_boot_interface(), iface],
1260 )
1261 # deploying a machine as a VM host bridges the boot interface, which is
1262 # now the bond
1263 bridge = factory.make_Interface(
1264 iftype=INTERFACE_TYPE.BRIDGE,
1265 node=node,
1266 parents=[bond],
1267 )
1268 ip = factory.make_StaticIPAddress(interface=bridge)
1269 another_if = factory.make_Interface(INTERFACE_TYPE.PHYSICAL, node=node)
1270 factory.make_StaticIPAddress(interface=another_if)
1271 SecretManager().set_composite_secret(
1272 "deploy-metadata",
1273 {"virsh-password": "xyz123"},
1274 obj=node,
1275 )
1276 _create_vmhost_for_deployment(node)
1277 self.assertEqual(node.status, NODE_STATUS.DEPLOYED)
1278 virsh_vmhost = Pod.objects.get(power_type="virsh")
1279
1280 addr = ip.ip
1281 if IPAddress(addr).version == 6:
1282 addr = f"[{addr}]"
1283 self.assertEqual(
1284 virsh_vmhost.power_parameters.get("power_address"),
1285 f"qemu+ssh://virsh@{addr}/system",
1286 )
1287
1247 def test_marks_failed_if_form_invalid(self):1288 def test_marks_failed_if_form_invalid(self):
1248 mock_form = self.patch(api_twisted_module, "PodForm").return_value1289 mock_form = self.patch(api_twisted_module, "PodForm").return_value
1249 mock_form.is_valid.return_value = False1290 mock_form.is_valid.return_value = False

Subscribers

People subscribed via source and target branches