diff options
-rw-r--r-- | cloudinit/sources/DataSourceGCE.py | 3 | ||||
-rw-r--r-- | tests/unittests/test_datasource/test_gce.py | 7 |
2 files changed, 6 insertions, 4 deletions
diff --git a/cloudinit/sources/DataSourceGCE.py b/cloudinit/sources/DataSourceGCE.py index 92e5a28e..f877b3d1 100644 --- a/cloudinit/sources/DataSourceGCE.py +++ b/cloudinit/sources/DataSourceGCE.py @@ -124,7 +124,8 @@ class DataSourceGCE(sources.DataSource): 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'] diff --git a/tests/unittests/test_datasource/test_gce.py b/tests/unittests/test_datasource/test_gce.py index 89251b0e..06050bb1 100644 --- a/tests/unittests/test_datasource/test_gce.py +++ b/tests/unittests/test_datasource/test_gce.py @@ -99,7 +99,8 @@ class TestDataSourceGCE(test_helpers.HttprettyTestCase): 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 @@ class TestDataSourceGCE(test_helpers.HttprettyTestCase): 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): |