Merge ~troyanov/maas:parent-child-host-vm into maas:master

Proposed by Anton Troyanov
Status: Merged
Approved by: Anton Troyanov
Approved revision: f69641967ad21a66f1079197bdb9cf916afe7d6b
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~troyanov/maas:parent-child-host-vm
Merge into: maas:master
Diff against target: 70 lines (+42/-0)
3 files modified
src/maasserver/migrations/maasserver/0280_set_parent_for_existing_vms.py (+28/-0)
src/maasserver/models/bmc.py (+1/-0)
src/maasserver/models/tests/test_bmc.py (+13/-0)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Jack Lloyd-Walters Approve
Review via email: mp+429354@code.launchpad.net

Commit message

feat: add parent-child relation between vm and pod

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

UNIT TESTS
-b parent-child-host-vm lp:~troyanov/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 82db7632bab046e4ba802cc03e1be3d015ad5df7

review: Approve
Revision history for this message
Jack Lloyd-Walters (lloydwaltersj) wrote :

LGTM

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

UNIT TESTS
-b parent-child-host-vm lp:~troyanov/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 4a9edcab3c77e84f1d69de8b0e77b5417ec1baf8

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

UNIT TESTS
-b parent-child-host-vm lp:~troyanov/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 95fbe195a1f78003d2ae6575ed7a333056f83105

review: Approve
~troyanov/maas:parent-child-host-vm updated
f696419... by Anton Troyanov

fixup! feat: link machines that depend on each other

Add data migration step, to create parent-child relation for existing
VMs

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

UNIT TESTS
-b parent-child-host-vm lp:~troyanov/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/547/consoleText
COMMIT: f87eda5766f6a6c8159637cba84d12c26704ed02

review: Needs Fixing
Revision history for this message
Anton Troyanov (troyanov) wrote :

jenkins: !test

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

UNIT TESTS
-b parent-child-host-vm lp:~troyanov/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: f69641967ad21a66f1079197bdb9cf916afe7d6b

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/migrations/maasserver/0280_set_parent_for_existing_vms.py b/src/maasserver/migrations/maasserver/0280_set_parent_for_existing_vms.py
2new file mode 100644
3index 0000000..5ce9ea2
4--- /dev/null
5+++ b/src/maasserver/migrations/maasserver/0280_set_parent_for_existing_vms.py
6@@ -0,0 +1,28 @@
7+# Generated by Django 3.2.12 on 2022-09-06 12:00
8+
9+from django.db import migrations
10+
11+
12+class Migration(migrations.Migration):
13+
14+ dependencies = [
15+ ("maasserver", "0279_store_vpd_metadata_for_nodedevice"),
16+ ]
17+
18+ operations = [
19+ migrations.RunSQL(
20+ """
21+ UPDATE maasserver_node AS node
22+ SET parent_id = podhints_nodes.node_id
23+ FROM
24+ maasserver_bmc AS bmc,
25+ maasserver_podhints AS podhints,
26+ maasserver_podhints_nodes AS podhints_nodes
27+ WHERE
28+ node.bmc_id = bmc.id AND
29+ podhints.pod_id = bmc.id AND
30+ podhints_nodes.podhints_id = podhints.id AND
31+ node.parent_id is NULL;
32+ """
33+ )
34+ ]
35diff --git a/src/maasserver/models/bmc.py b/src/maasserver/models/bmc.py
36index 29e97dd..aab469c 100644
37--- a/src/maasserver/models/bmc.py
38+++ b/src/maasserver/models/bmc.py
39@@ -901,6 +901,7 @@ class Pod(BMC):
40 power_state=discovered_machine.power_state,
41 dynamic=dynamic,
42 pool=pool,
43+ parent=self.host,
44 zone=zone,
45 bios_boot_method=discovered_machine.bios_boot_method,
46 **kwargs,
47diff --git a/src/maasserver/models/tests/test_bmc.py b/src/maasserver/models/tests/test_bmc.py
48index a3e5547..05366ff 100644
49--- a/src/maasserver/models/tests/test_bmc.py
50+++ b/src/maasserver/models/tests/test_bmc.py
51@@ -2099,6 +2099,19 @@ class TestPod(MAASServerTestCase, PodTestMixin):
52 skip_commissioning=True,
53 )
54
55+ def test_create_machine_creates_machine_with_parent_child_relation(self):
56+ self.patch(Machine, "set_default_storage_layout")
57+ self.patch(Machine, "set_initial_networking_configuration")
58+ self.patch(Machine, "start_commissioning")
59+ project = factory.make_string()
60+ host = factory.make_Machine_with_Interface_on_Subnet()
61+ pod = factory.make_Pod(
62+ host=host, pod_type="lxd", parameters={"project": project}
63+ )
64+ discovered_machine = self.make_discovered_machine()
65+ machine = pod.create_machine(discovered_machine, factory.make_User())
66+ self.assertEqual(machine.parent, host)
67+
68 def test_sync_pod_deletes_missing_machines(self):
69 pod = factory.make_Pod()
70 machine = factory.make_Node()

Subscribers

People subscribed via source and target branches