launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #06351
[Merge] lp:~allenap/maas/maas-pserv-mac-addresses into lp:maas
Gavin Panella has proposed merging lp:~allenap/maas/maas-pserv-mac-addresses into lp:maas with lp:~allenap/maas/pserv-modify-interfaces as a prerequisite.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~allenap/maas/maas-pserv-mac-addresses/+merge/92786
--
https://code.launchpad.net/~allenap/maas/maas-pserv-mac-addresses/+merge/92786
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/maas/maas-pserv-mac-addresses into lp:maas.
=== modified file 'src/maasserver/provisioning.py'
--- src/maasserver/provisioning.py 2012-02-10 12:34:24 +0000
+++ src/maasserver/provisioning.py 2012-02-13 15:49:36 +0000
@@ -58,10 +58,17 @@
papi.add_node(instance.system_id, profile)
+def set_node_mac_addresses(node):
+ """Update the Node's MAC addresses in the provisioning server."""
+ mac_addresses = [mac.mac_address for mac in node.macaddress_set.all()]
+ deltas = {node.system_id: {"mac_addresses": mac_addresses}}
+ get_provisioning_api_proxy().modify_nodes(deltas)
+
+
@receiver(post_save, sender=MACAddress)
def provision_post_save_MACAddress(sender, instance, created, **kwargs):
"""Create or update MACs in the provisioning server."""
- # TODO
+ set_node_mac_addresses(instance.node)
@receiver(post_delete, sender=Node)
@@ -74,4 +81,4 @@
@receiver(post_delete, sender=MACAddress)
def provision_post_delete_MACAddress(sender, instance, **kwargs):
"""Delete MACs in the provisioning server."""
- # TODO
+ set_node_mac_addresses(instance.node)
=== modified file 'src/maasserver/tests/test_provisioning.py'
--- src/maasserver/tests/test_provisioning.py 2012-02-10 17:19:39 +0000
+++ src/maasserver/tests/test_provisioning.py 2012-02-13 15:49:36 +0000
@@ -41,6 +41,15 @@
distros = self.papi.get_distros_by_name([distro_name])
self.assertEqual([distro_name], sorted(distros))
+ def test_provision_post_save_MACAddress_create(self):
+ # Creating and saving a MACAddress updates the Node with which it's
+ # associated.
+ node_model = Node(system_id="frank")
+ node_model.save()
+ node_model.add_mac_address("12:34:56:78:90:12")
+ node = self.papi.get_nodes_by_name(["frank"])["frank"]
+ self.assertEqual(["12:34:56:78:90:12"], node["mac_addresses"])
+
def test_provision_post_save_Node_update(self):
# Saving an existing node does not change the profile or distro
# associated with it.
@@ -58,6 +67,17 @@
profile_name2 = node["profile"]
self.assertEqual(profile_name1, profile_name2)
+ def test_provision_post_save_MACAddress_update(self):
+ # Saving an existing MACAddress updates the Node with which it's
+ # associated.
+ node_model = Node(system_id="frank")
+ node_model.save()
+ mac_model = node_model.add_mac_address("12:34:56:78:90:12")
+ mac_model.mac_address = "11:22:33:44:55:66"
+ mac_model.save()
+ node = self.papi.get_nodes_by_name(["frank"])["frank"]
+ self.assertEqual(["11:22:33:44:55:66"], node["mac_addresses"])
+
def test_provision_post_delete_Node(self):
node_model = Node(system_id="frank")
provisioning.provision_post_save_Node(
@@ -69,6 +89,15 @@
self.assertNotEqual({}, self.papi.get_profiles())
self.assertEqual({}, self.papi.get_nodes_by_name(["frank"]))
+ def test_provision_post_delete_MACAddress(self):
+ # Deleting a MACAddress updates the Node with which it's associated.
+ node_model = Node(system_id="frank")
+ node_model.save()
+ node_model.add_mac_address("12:34:56:78:90:12")
+ node_model.remove_mac_address("12:34:56:78:90:12")
+ node = self.papi.get_nodes_by_name(["frank"])["frank"]
+ self.assertEqual([], node["mac_addresses"])
+
def patch_in_fake_papi(test):
"""Patch in a fake Provisioning API for the duration of the test."""
Follow ups