← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~utlemming/cloud-init/lp1383794 into lp:cloud-init

 

Ben Howard has proposed merging lp:~utlemming/cloud-init/lp1383794 into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)
Related bugs:
  Bug #1383794 in cloud-init (Ubuntu): "[SRU] GCE datasource should use the short hostname"
  https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/1383794

For more details, see:
https://code.launchpad.net/~utlemming/cloud-init/lp1383794/+merge/246433

Use the GCE short hostname. 
-- 
Your team cloud init development team is requested to review the proposed merge of lp:~utlemming/cloud-init/lp1383794 into lp:cloud-init.
=== modified file 'cloudinit/sources/DataSourceGCE.py'
--- cloudinit/sources/DataSourceGCE.py	2015-01-06 16:41:05 +0000
+++ cloudinit/sources/DataSourceGCE.py	2015-01-14 14:53:06 +0000
@@ -124,7 +124,8 @@
         return self.metadata['public-keys']
 
     def get_hostname(self, fqdn=False, _resolve_ip=False):
-        return self.metadata['local-hostname']
+        # GCE has long FDQN's and has asked for short hostnames
+        return self.metadata['local-hostname'].split('.')[0]
 
     def get_userdata_raw(self):
         return self.metadata['user-data']

=== modified file 'tests/unittests/test_datasource/test_gce.py'
--- tests/unittests/test_datasource/test_gce.py	2015-01-06 17:09:00 +0000
+++ tests/unittests/test_datasource/test_gce.py	2015-01-14 14:53:06 +0000
@@ -99,7 +99,8 @@
             body=_new_request_callback())
         self.ds.get_data()
 
-        self.assertEqual(GCE_META.get('instance/hostname'),
+        shostname = GCE_META.get('instance/hostname').split('.')[0]
+        self.assertEqual(shostname,
                          self.ds.get_hostname())
 
         self.assertEqual(GCE_META.get('instance/id'),
@@ -126,8 +127,8 @@
         self.assertEqual(GCE_META_PARTIAL.get('instance/id'),
                          self.ds.get_instance_id())
 
-        self.assertEqual(GCE_META_PARTIAL.get('instance/hostname'),
-                         self.ds.get_hostname())
+        shostname = GCE_META_PARTIAL.get('instance/hostname').split('.')[0]
+        self.assertEqual(shostname, self.ds.get_hostname())
 
     @httpretty.activate
     def test_metadata_encoding(self):


Follow ups