Merge ~mgerdts/cloud-init:lp1765085 into cloud-init:master

Proposed by Mike Gerdts
Status: Merged
Approved by: Scott Moser
Approved revision: dd43702069ddf8e34e2e50590f845a39287fa683
Merge reported by: Scott Moser
Merged at revision: 23479881f51bae7a3f5743ce677ed82317ea8b9f
Proposed branch: ~mgerdts/cloud-init:lp1765085
Merge into: cloud-init:master
Diff against target: 68 lines (+36/-2)
2 files modified
cloudinit/sources/ (+8/-2)
tests/unittests/test_datasource/ (+28/-0)
Reviewer Review Type Date Requested Status
Scott Moser Approve
Server Team CI bot continuous-integration Approve
Review via email:

Commit message

DataSourceSmartOS: sdc:hostname is ignored

There are three potential sources of the hostname, one of which is
documented SmartOS's vmadm(1M) via the hostname property. That
property's value is retrieved via the sdc:hostname key. The other
two sources for the hostname are a hostname key in customer_metadata
and the VM's uuid (sdc:uuid). Of these three, the sdc:hostname value
is not used in a meaningful way by DataSourceSmartOS.

This fix changes the fallback mechanism when hostname is not
specified in customer_metadata. The order of precedence for setting
the hostname is now 1) hostname in customer_metadata,
2) sdc:hostname, then 3) sdc:uuid.

LP: #1765085

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:

review: Approve (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

I'm interested in including info here on if sdc:hostname is a fully qualified hostname or just the short portion (ie, will it be <name>.domain or just <name>).

review: Needs Information
~mgerdts/cloud-init:lp1765085 updated
65650f3... by Mike Gerdts

smoser feedback: clarify hostname

dd43702... by Mike Gerdts

remove extraneous debug statements

Revision history for this message
Scott Moser (smoser) :
review: Approve
Revision history for this message
Scott Moser (smoser) wrote :

An upstream commit landed for this bug.

To view that commit see the following URL:

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/sources/ b/cloudinit/sources/
2index c8998b4..06410dd 100644
3--- a/cloudinit/sources/
4+++ b/cloudinit/sources/
5@@ -11,7 +11,7 @@
6 # SmartOS hosts use a serial console (/dev/ttyS1) on KVM Linux Guests
7 # The meta-data is transmitted via key/value pairs made by
8 # requests on the console. For example, to get the hostname, you
9-# would send "GET hostname" on /dev/ttyS1.
10+# would send "GET sdc:hostname" on /dev/ttyS1.
11 # For Linux Guests running in LX-Brand Zones on SmartOS hosts
12 # a socket (/native/.zonecontrol/metadata.sock) is used instead
13 # of a serial console.
14@@ -273,8 +273,14 @@ class DataSourceSmartOS(sources.DataSource):
15 write_boot_content(u_data, u_data_f)
17 # Handle the cloud-init regular meta
19+ # The hostname may or may not be qualified with the local domain name.
20+ # This follows section 3.14 of RFC 2132.
21 if not md['local-hostname']:
22- md['local-hostname'] = md['instance-id']
23+ if md['hostname']:
24+ md['local-hostname'] = md['hostname']
25+ else:
26+ md['local-hostname'] = md['instance-id']
28 ud = None
29 if md['user-data']:
30diff --git a/tests/unittests/test_datasource/ b/tests/unittests/test_datasource/
31index 2bea7a1..de2f7cb 100644
32--- a/tests/unittests/test_datasource/
33+++ b/tests/unittests/test_datasource/
34@@ -431,6 +431,34 @@ class TestSmartOSDataSource(FilesystemMockingTestCase):
35 self.assertEqual(MOCK_RETURNS['hostname'],
36 dsrc.metadata['local-hostname'])
38+ def test_hostname_if_no_sdc_hostname(self):
39+ my_returns = MOCK_RETURNS.copy()
40+ my_returns['sdc:hostname'] = 'sdc-' + my_returns['hostname']
41+ dsrc = self._get_ds(mockdata=my_returns)
42+ ret = dsrc.get_data()
43+ self.assertTrue(ret)
44+ self.assertEqual(my_returns['hostname'],
45+ dsrc.metadata['local-hostname'])
47+ def test_sdc_hostname_if_no_hostname(self):
48+ my_returns = MOCK_RETURNS.copy()
49+ my_returns['sdc:hostname'] = 'sdc-' + my_returns['hostname']
50+ del my_returns['hostname']
51+ dsrc = self._get_ds(mockdata=my_returns)
52+ ret = dsrc.get_data()
53+ self.assertTrue(ret)
54+ self.assertEqual(my_returns['sdc:hostname'],
55+ dsrc.metadata['local-hostname'])
57+ def test_sdc_uuid_if_no_hostname_or_sdc_hostname(self):
58+ my_returns = MOCK_RETURNS.copy()
59+ del my_returns['hostname']
60+ dsrc = self._get_ds(mockdata=my_returns)
61+ ret = dsrc.get_data()
62+ self.assertTrue(ret)
63+ self.assertEqual(my_returns['sdc:uuid'],
64+ dsrc.metadata['local-hostname'])
66 def test_userdata(self):
67 dsrc = self._get_ds(mockdata=MOCK_RETURNS)
68 ret = dsrc.get_data()


People subscribed via source and target branches