launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #10473
[Merge] lp:~rvb/maas/dns-hostname-update into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/dns-hostname-update into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~rvb/maas/dns-hostname-update/+merge/117580
Change a node's DNS zone file when the node gets updated. This is to cope with the fact that a node hostname can be changed. Note that the zone file will get re-written every time something is changed on a node (and not only when the hostname is changed). That is a little bit suboptimal but:
a) it will do for now ;)
b) writing zone files and reloading a zone is a very cheap operation
c) there is no proper support in Django yet to have signals fired only when a particular field is changed. We could workaround that problem by using pre_save and post_save signal but that's outside the scope of that branch.
Drive-by fix: change a test's name ('delete' is more in sync with Django's linguo than 'remove').
--
https://code.launchpad.net/~rvb/maas/dns-hostname-update/+merge/117580
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/dns-hostname-update into lp:maas.
=== modified file 'src/maasserver/dns.py'
--- src/maasserver/dns.py 2012-07-27 14:52:44 +0000
+++ src/maasserver/dns.py 2012-08-01 08:17:19 +0000
@@ -139,7 +139,16 @@
@receiver(post_delete, sender=Node)
def dns_post_delete_Node(sender, instance, **kwargs):
- """Update the Node's zone file."""
+ """When a Node is deleted, update the Node's zone file."""
+ if is_dns_enabled():
+ change_dns_zones(instance.nodegroup)
+
+
+@receiver(post_save, sender=Node)
+def dns_post_save_Node(sender, instance, created, **kwargs):
+ """When a Node is changed, update the Node's zone file."""
+ # This should only happen when the node's hostname is changed
+ # but Django doesn't provide an easy way to do this yet.
if is_dns_enabled():
change_dns_zones(instance.nodegroup)
=== modified file 'src/maasserver/tests/test_dns.py'
--- src/maasserver/tests/test_dns.py 2012-07-27 14:52:44 +0000
+++ src/maasserver/tests/test_dns.py 2012-08-01 08:17:19 +0000
@@ -327,13 +327,20 @@
nodegroup, node, lease = self.create_nodegroup_with_lease()
self.assertDNSMatches(node.hostname, nodegroup.name, lease.ip)
- def test_remove_node_updates_zone(self):
+ def test_delete_node_updates_zone(self):
self.patch(settings, "DNS_CONNECT", True)
nodegroup, node, lease = self.create_nodegroup_with_lease()
node.delete()
fqdn = "%s.%s" % (node.hostname, nodegroup.name)
self.assertEqual([''], self.dig_resolve(fqdn))
+ def test_change_hostname_node_updates_zone(self):
+ self.patch(settings, "DNS_CONNECT", True)
+ nodegroup, node, lease = self.create_nodegroup_with_lease()
+ node.hostname = factory.make_name('hostname')
+ node.save()
+ self.assertDNSMatches(node.hostname, nodegroup.name, lease.ip)
+
def test_change_config_enable_dns_enables_dns(self):
self.patch(settings, "DNS_CONNECT", False)
nodegroup, node, lease = self.create_nodegroup_with_lease()