summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/sources/DataSourceNoCloud.py3
-rw-r--r--cloudinit/sources/DataSourceOVF.py4
-rw-r--r--cloudinit/util.py19
-rw-r--r--tests/unittests/test_util.py24
4 files changed, 45 insertions, 5 deletions
diff --git a/cloudinit/sources/DataSourceNoCloud.py b/cloudinit/sources/DataSourceNoCloud.py
index e408d730..d4a175e8 100644
--- a/cloudinit/sources/DataSourceNoCloud.py
+++ b/cloudinit/sources/DataSourceNoCloud.py
@@ -157,13 +157,14 @@ class DataSourceNoCloud(sources.DataSource):
# This could throw errors, but the user told us to do it
# so if errors are raised, let them raise
- (md_seed, ud) = util.read_seeded(seedfrom, timeout=None)
+ (md_seed, ud, vd) = util.read_seeded(seedfrom, timeout=None)
LOG.debug("Using seeded cache data from %s", seedfrom)
# Values in the command line override those from the seed
mydata['meta-data'] = util.mergemanydict([mydata['meta-data'],
md_seed])
mydata['user-data'] = ud
+ mydata['vendor-data'] = vd
found.append(seedfrom)
# Now that we have exhausted any other places merge in the defaults
diff --git a/cloudinit/sources/DataSourceOVF.py b/cloudinit/sources/DataSourceOVF.py
index e53d2eb1..a5ccb8f6 100644
--- a/cloudinit/sources/DataSourceOVF.py
+++ b/cloudinit/sources/DataSourceOVF.py
@@ -73,6 +73,7 @@ class DataSourceOVF(sources.DataSource):
found = []
md = {}
ud = ""
+ vd = ""
vmwareImcConfigFilePath = None
nicspath = None
@@ -304,7 +305,7 @@ class DataSourceOVF(sources.DataSource):
seedfrom, self)
return False
- (md_seed, ud) = util.read_seeded(seedfrom, timeout=None)
+ (md_seed, ud, vd) = util.read_seeded(seedfrom, timeout=None)
LOG.debug("Using seeded cache data from %s", seedfrom)
md = util.mergemanydict([md, md_seed])
@@ -316,6 +317,7 @@ class DataSourceOVF(sources.DataSource):
self.seed = ",".join(found)
self.metadata = md
self.userdata_raw = ud
+ self.vendordata_raw = vd
self.cfg = cfg
return True
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 64142f23..e47f1cf6 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -761,8 +761,9 @@ def del_dir(path):
# 'meta-data' entries
def read_optional_seed(fill, base="", ext="", timeout=5):
try:
- (md, ud) = read_seeded(base, ext, timeout)
+ (md, ud, vd) = read_seeded(base, ext, timeout)
fill['user-data'] = ud
+ fill['vendor-data'] = vd
fill['meta-data'] = md
return True
except url_helper.UrlError as e:
@@ -840,9 +841,11 @@ def load_yaml(blob, default=None, allowed=(dict,)):
def read_seeded(base="", ext="", timeout=5, retries=10, file_retries=0):
if base.find("%s") >= 0:
ud_url = base % ("user-data" + ext)
+ vd_url = base % ("vendor-data" + ext)
md_url = base % ("meta-data" + ext)
else:
ud_url = "%s%s%s" % (base, "user-data", ext)
+ vd_url = "%s%s%s" % (base, "vendor-data", ext)
md_url = "%s%s%s" % (base, "meta-data", ext)
md_resp = url_helper.read_file_or_url(md_url, timeout=timeout,
@@ -857,7 +860,19 @@ def read_seeded(base="", ext="", timeout=5, retries=10, file_retries=0):
if ud_resp.ok():
ud = ud_resp.contents
- return (md, ud)
+ vd = None
+ try:
+ vd_resp = url_helper.read_file_or_url(vd_url, timeout=timeout,
+ retries=retries)
+ except url_helper.UrlError as e:
+ LOG.debug("Error in vendor-data response: %s", e)
+ else:
+ if vd_resp.ok():
+ vd = vd_resp.contents
+ else:
+ LOG.debug("Error in vendor-data response")
+
+ return (md, ud, vd)
def read_conf_d(confd):
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
index fc557469..cca53123 100644
--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -735,13 +735,35 @@ class TestReadSeeded(helpers.TestCase):
def test_unicode_not_messed_up(self):
ud = b"userdatablob"
+ vd = b"vendordatablob"
+ helpers.populate_dir(
+ self.tmp, {'meta-data': "key1: val1", 'user-data': ud,
+ 'vendor-data': vd})
+ sdir = self.tmp + os.path.sep
+ (found_md, found_ud, found_vd) = util.read_seeded(sdir)
+
+ self.assertEqual(found_md, {'key1': 'val1'})
+ self.assertEqual(found_ud, ud)
+ self.assertEqual(found_vd, vd)
+
+
+class TestReadSeededWithoutVendorData(helpers.TestCase):
+ def setUp(self):
+ super(TestReadSeededWithoutVendorData, self).setUp()
+ self.tmp = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, self.tmp)
+
+ def test_unicode_not_messed_up(self):
+ ud = b"userdatablob"
+ vd = None
helpers.populate_dir(
self.tmp, {'meta-data': "key1: val1", 'user-data': ud})
sdir = self.tmp + os.path.sep
- (found_md, found_ud) = util.read_seeded(sdir)
+ (found_md, found_ud, found_vd) = util.read_seeded(sdir)
self.assertEqual(found_md, {'key1': 'val1'})
self.assertEqual(found_ud, ud)
+ self.assertEqual(found_vd, vd)
class TestEncode(helpers.TestCase):