← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~shane.davidson/cloud-init:update-openstack-datasource into cloud-init:master

 

Shane Davidson has proposed merging ~shane.davidson/cloud-init:update-openstack-datasource into cloud-init:master.

Commit message:
- Update openstack datasource to use vendor_data.json and vendor_data2.json
- Update openstack datasource unit tests
- Update openstack metadata versions

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~shane.davidson/cloud-init/+git/cloud-init/+merge/326050


-- 
Your team cloud-init commiters is requested to review the proposed merge of ~shane.davidson/cloud-init:update-openstack-datasource into cloud-init:master.
diff --git a/cloudinit/sources/DataSourceOpenStack.py b/cloudinit/sources/DataSourceOpenStack.py
index b64a7f2..1688bb2 100644
--- a/cloudinit/sources/DataSourceOpenStack.py
+++ b/cloudinit/sources/DataSourceOpenStack.py
@@ -132,7 +132,11 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource):
         self.version = results['version']
         self.files.update(results.get('files', {}))
 
-        vd = results.get('vendordata')
+        vd1 = results.get('vendordata')
+        vd2 = results.get('vendordata2')
+
+        vd = util.mergemanydict([vd2, vd1])
+
         self.vendordata_pure = vd
         try:
             self.vendordata_raw = sources.convert_vendordata(vd)
diff --git a/cloudinit/sources/helpers/openstack.py b/cloudinit/sources/helpers/openstack.py
index 26f3168..2aa2940 100644
--- a/cloudinit/sources/helpers/openstack.py
+++ b/cloudinit/sources/helpers/openstack.py
@@ -41,12 +41,18 @@ OS_FOLSOM = '2012-08-10'
 OS_GRIZZLY = '2013-04-04'
 OS_HAVANA = '2013-10-17'
 OS_LIBERTY = '2015-10-15'
+OS_MITAKA = '2016-06-30'
+OS_NEWTON = '2016-10-06'
+OS_OCATA = '2017-02-22'
 # keep this in chronological order. new supported versions go at the end.
 OS_VERSIONS = (
     OS_FOLSOM,
     OS_GRIZZLY,
     OS_HAVANA,
     OS_LIBERTY,
+    OS_MITAKA,
+    OS_NEWTON,
+    OS_OCATA,
 )
 
 PHYSICAL_TYPES = (
@@ -234,6 +240,11 @@ class BaseReader(object):
                 False,
                 load_json_anytype,
             )
+            files['vendordata2'] = (
+                self._path_join("openstack", version, 'vendor_data2.json'),
+                False,
+                load_json_anytype,
+            )
             files['networkdata'] = (
                 self._path_join("openstack", version, 'network_data.json'),
                 False,
diff --git a/tests/unittests/test_datasource/test_openstack.py b/tests/unittests/test_datasource/test_openstack.py
index c2905d1..270bb3e 100644
--- a/tests/unittests/test_datasource/test_openstack.py
+++ b/tests/unittests/test_datasource/test_openstack.py
@@ -39,7 +39,15 @@ EC2_META = {
 }
 USER_DATA = b'#!/bin/sh\necho This is user data\n'
 VENDOR_DATA = {
-    'magic': '',
+    'magic': 'vd-key',
+}
+VENDOR_DATA2 = {
+    'magic': 'vd-key2',
+    'vendor-data2': 'vd2-key',
+}
+VENDOR_DATA_MERGED = {
+    'magic': 'vd-key2',
+    'vendor-data2': 'vd2-key',
 }
 OSTACK_META = {
     'availability_zone': 'nova',
@@ -59,6 +67,7 @@ OS_FILES = {
     'openstack/latest/meta_data.json': json.dumps(OSTACK_META),
     'openstack/latest/user_data': USER_DATA,
     'openstack/latest/vendor_data.json': json.dumps(VENDOR_DATA),
+    'openstack/latest/vendor_data2.json': json.dumps(VENDOR_DATA2),
 }
 EC2_FILES = {
     'latest/user-data': USER_DATA,
@@ -133,6 +142,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase):
         _register_uris(self.VERSION, EC2_FILES, EC2_META, OS_FILES)
         f = _read_metadata_service()
         self.assertEqual(VENDOR_DATA, f.get('vendordata'))
+        self.assertEqual(VENDOR_DATA2, f.get('vendordata2'))
         self.assertEqual(CONTENT_0, f['files']['/etc/foo.cfg'])
         self.assertEqual(CONTENT_1, f['files']['/etc/bar/bar.cfg'])
         self.assertEqual(2, len(f['files']))
@@ -155,6 +165,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase):
         _register_uris(self.VERSION, {}, {}, OS_FILES)
         f = _read_metadata_service()
         self.assertEqual(VENDOR_DATA, f.get('vendordata'))
+       	self.assertEqual(VENDOR_DATA2, f.get('vendordata2'))
         self.assertEqual(CONTENT_0, f['files']['/etc/foo.cfg'])
         self.assertEqual(CONTENT_1, f['files']['/etc/bar/bar.cfg'])
         self.assertEqual(USER_DATA, f.get('userdata'))
@@ -190,6 +201,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase):
         _register_uris(self.VERSION, {}, {}, os_files)
         f = _read_metadata_service()
         self.assertEqual(VENDOR_DATA, f.get('vendordata'))
+       	self.assertEqual(VENDOR_DATA2, f.get('vendordata2'))
         self.assertEqual(CONTENT_0, f['files']['/etc/foo.cfg'])
         self.assertEqual(CONTENT_1, f['files']['/etc/bar/bar.cfg'])
         self.assertFalse(f.get('userdata'))
@@ -207,6 +219,18 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase):
         self.assertFalse(f.get('vendordata'))
 
     @hp.activate
+    def test_vendordata2_empty(self):
+        os_files = copy.deepcopy(OS_FILES)
+        for k in list(os_files.keys()):
+            if k.endswith('vendor_data2.json'):
+                os_files.pop(k, None)
+        _register_uris(self.VERSION, {}, {}, os_files)
+        f = _read_metadata_service()
+        self.assertEqual(CONTENT_0, f['files']['/etc/foo.cfg'])
+        self.assertEqual(CONTENT_1, f['files']['/etc/bar/bar.cfg'])
+        self.assertFalse(f.get('vendordata2'))
+
+    @hp.activate
     def test_vendordata_invalid(self):
         os_files = copy.deepcopy(OS_FILES)
         for k in list(os_files.keys()):
@@ -216,6 +240,15 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase):
         self.assertRaises(openstack.BrokenMetadata, _read_metadata_service)
 
     @hp.activate
+    def test_vendordata2_invalid(self):
+        os_files = copy.deepcopy(OS_FILES)
+        for k in list(os_files.keys()):
+            if k.endswith('vendor_data2.json'):
+                os_files[k] = '{'  # some invalid json
+        _register_uris(self.VERSION, {}, {}, os_files)
+        self.assertRaises(openstack.BrokenMetadata, _read_metadata_service)
+
+    @hp.activate
     def test_metadata_invalid(self):
         os_files = copy.deepcopy(OS_FILES)
         for k in list(os_files.keys()):
@@ -241,7 +274,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase):
         self.assertEqual(EC2_META, ds_os.ec2_metadata)
         self.assertEqual(USER_DATA, ds_os.userdata_raw)
         self.assertEqual(2, len(ds_os.files))
-        self.assertEqual(VENDOR_DATA, ds_os.vendordata_pure)
+        self.assertEqual(VENDOR_DATA_MERGED, ds_os.vendordata_pure)
         self.assertIsNone(ds_os.vendordata_raw)
 
     @hp.activate

References