← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~allenap/maas/node-tld into lp:maas

 

Gavin Panella has proposed merging lp:~allenap/maas/node-tld into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~allenap/maas/node-tld/+merge/99907

Nodes which have their hostname set with set_mac_based_hostname() get an enlistment domain appended. This is configurable.
-- 
https://code.launchpad.net/~allenap/maas/node-tld/+merge/99907
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/maas/node-tld into lp:maas.
=== modified file 'src/maasserver/forms.py'
--- src/maasserver/forms.py	2012-03-28 06:21:37 +0000
+++ src/maasserver/forms.py	2012-03-29 10:50:30 +0000
@@ -265,6 +265,10 @@
 class MAASAndNetworkForm(ConfigForm):
     """Settings page, MAAS and Network section."""
     maas_name = forms.CharField(label="MAAS name")
+    enlistment_domain = forms.CharField(
+        label="Default domain for new nodes", required=False, help_text=(
+            "If 'local' is chosen, nodes must be using mDNS. Leave empty to "
+            "use hostnames without a domain for newly enlisted nodes."))
 
 
 class CommissioningForm(ConfigForm):

=== modified file 'src/maasserver/models.py'
--- src/maasserver/models.py	2012-03-29 10:30:46 +0000
+++ src/maasserver/models.py	2012-03-29 10:50:30 +0000
@@ -34,6 +34,7 @@
 import os
 import re
 from socket import gethostname
+from string import whitespace
 import time
 from uuid import uuid1
 
@@ -474,7 +475,12 @@
 
     def set_mac_based_hostname(self, mac_address):
         mac_hostname = mac_address.replace(':', '').lower()
-        self.hostname = "node-%s" % mac_hostname
+        domain = Config.objects.get_config("enlistment_domain")
+        domain = domain.strip("." + whitespace)
+        if len(domain) > 0:
+            self.hostname = "node-%s.%s" % (mac_hostname, domain)
+        else:
+            self.hostname = "node-%s" % mac_hostname
         self.save()
 
     def get_effective_power_type(self):
@@ -918,6 +924,7 @@
             [['archive.ubuntu.com', 'archive.ubuntu.com']]),
         # Network section configuration.
         'maas_name': gethostname(),
+        'enlistment_domain': b'local',
         ## /settings
         }
 

=== modified file 'src/maasserver/tests/test_models.py'
--- src/maasserver/tests/test_models.py	2012-03-29 09:34:07 +0000
+++ src/maasserver/tests/test_models.py	2012-03-29 10:50:30 +0000
@@ -116,7 +116,34 @@
         self.assertRaises(
             MACAddress.DoesNotExist, MACAddress.objects.get, id=mac.id)
 
-    def test_set_mac_based_hostname(self):
+    def test_set_mac_based_hostname_default_enlistment_domain(self):
+        # The enlistment domain defaults to `local`.
+        node = factory.make_node()
+        node.set_mac_based_hostname('AA:BB:CC:DD:EE:FF')
+        hostname = 'node-aabbccddeeff.local'
+        self.assertEqual(hostname, node.hostname)
+
+    def test_set_mac_based_hostname_alt_enlistment_domain(self):
+        # A non-default enlistment domain can be specified.
+        Config.objects.set_config("enlistment_domain", "example.com")
+        node = factory.make_node()
+        node.set_mac_based_hostname('AA:BB:CC:DD:EE:FF')
+        hostname = 'node-aabbccddeeff.example.com'
+        self.assertEqual(hostname, node.hostname)
+
+    def test_set_mac_based_hostname_cleaning_enlistment_domain(self):
+        # Leading and trailing dots and whitespace are cleaned from the
+        # configured enlistment domain before it's joined to the hostname.
+        Config.objects.set_config("enlistment_domain", " .example.com. ")
+        node = factory.make_node()
+        node.set_mac_based_hostname('AA:BB:CC:DD:EE:FF')
+        hostname = 'node-aabbccddeeff.example.com'
+        self.assertEqual(hostname, node.hostname)
+
+    def test_set_mac_based_hostname_no_enlistment_domain(self):
+        # The enlistment domain can be unset and set_mac_based_hostname sets a
+        # hostname with no domain.
+        Config.objects.set_config("enlistment_domain", "")
         node = factory.make_node()
         node.set_mac_based_hostname('AA:BB:CC:DD:EE:FF')
         hostname = 'node-aabbccddeeff'

=== modified file 'src/maasserver/tests/test_views.py'
--- src/maasserver/tests/test_views.py	2012-03-28 06:21:37 +0000
+++ src/maasserver/tests/test_views.py	2012-03-29 10:50:30 +0000
@@ -515,16 +515,20 @@
 
     def test_settings_maas_and_network_POST(self):
         new_name = factory.getRandomString()
+        new_domain = factory.getRandomString()
         response = self.client.post(
             '/settings/',
             get_prefixed_form_data(
                 prefix='maas_and_network',
                 data={
                     'maas_name': new_name,
+                    'enlistment_domain': new_domain,
                 }))
 
         self.assertEqual(httplib.FOUND, response.status_code)
         self.assertEqual(new_name, Config.objects.get_config('maas_name'))
+        self.assertEqual(
+            new_domain, Config.objects.get_config('enlistment_domain'))
 
     def test_settings_commissioning_POST(self):
         new_after_commissioning = factory.getRandomEnum(