← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/maas/add-fqdn into lp:maas

 

Raphaël Badin has proposed merging lp:~rvb/maas/add-fqdn into lp:maas with lp:~rvb/maas/bug-1070765-hostname as a prerequisite.

Commit message:
Add a fqdn property on nodes.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~rvb/maas/add-fqdn/+merge/131540

Add a fqdn property on nodes.
-- 
https://code.launchpad.net/~rvb/maas/add-fqdn/+merge/131540
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/add-fqdn into lp:maas.
=== modified file 'src/maasserver/models/node.py'
--- src/maasserver/models/node.py	2012-10-19 13:55:51 +0000
+++ src/maasserver/models/node.py	2012-10-26 08:14:23 +0000
@@ -491,6 +491,17 @@
         else:
             return self.system_id
 
+    @property
+    def fqdn(self):
+        """Fully qualified domain name for this node."""
+        if '.' in self.hostname:
+            # If the hostname contains a domain, return this as is.
+            return self.hostname
+        else:
+            # Build the FQDN by using the hostname and nodegroup.name
+            # as the domain name.
+            return '%s.%s' % (self.hostname, self.nodegroup.name)
+
     def tag_names(self):
         # We don't use self.tags.values_list here because this does not
         # take advantage of the cache.

=== modified file 'src/maasserver/tests/test_node.py'
--- src/maasserver/tests/test_node.py	2012-10-19 13:55:51 +0000
+++ src/maasserver/tests/test_node.py	2012-10-26 08:14:23 +0000
@@ -570,6 +570,21 @@
         node = reload_object(node)
         self.assertEqual([], list(node.tags.all()))
 
+    def test_fqdn_returns_hostname_if_contain_domains(self):
+        hostname_with_domain = '%s.%s' % (
+            factory.getRandomString(),  factory.getRandomString())
+        node = factory.make_node(hostname=hostname_with_domain)
+        self.assertEqual(hostname_with_domain, node.fqdn)
+
+    def test_fqdn_concatenates_domain_to_hostname(self):
+        hostname_without_domain = factory.make_name('hostname')
+        domain = factory.make_name('domain')
+        nodegroup = factory.make_node_group(domain)
+        node = factory.make_node(
+            hostname=hostname_without_domain, nodegroup=nodegroup)
+        expected_hostname = '%s.%s' % (hostname_without_domain, domain)
+        self.assertEqual(expected_hostname, node.fqdn)
+
 
 class NodeTransitionsTests(TestCase):
     """Test the structure of NODE_TRANSITIONS."""