summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/sources/DataSourceConfigDrive.py16
-rw-r--r--tests/unittests/test_datasource/test_configdrive.py3
2 files changed, 10 insertions, 9 deletions
diff --git a/cloudinit/sources/DataSourceConfigDrive.py b/cloudinit/sources/DataSourceConfigDrive.py
index 677483d0..cba499e4 100644
--- a/cloudinit/sources/DataSourceConfigDrive.py
+++ b/cloudinit/sources/DataSourceConfigDrive.py
@@ -60,11 +60,11 @@ class DataSourceConfigDrive(sources.DataSource):
def get_data(self):
found = None
md = {}
- ud = ""
+ results = {}
if os.path.isdir(self.seed_dir):
try:
- (md, ud, files, ver) = read_config_drive_dir(self.seed_dir)
+ results = read_config_drive_dir(self.seed_dir)
found = self.seed_dir
except NonConfigDriveDir:
util.logexc(LOG, "Failed reading config drive from %s",
@@ -84,7 +84,7 @@ class DataSourceConfigDrive(sources.DataSource):
for dev in devlist:
try:
- (md, ud, files, ver) = util.mount_cb(dev, read_config_drive_dir)
+ results = util.mount_cb(dev, read_config_drive_dir)
found = dev
break
except (NonConfigDriveDir, util.MountFailedError):
@@ -106,9 +106,8 @@ class DataSourceConfigDrive(sources.DataSource):
self.distro.apply_network(md['network-interfaces'])
self.seed = found
- self.metadata = md
- self.userdata_raw = ud
- self.version = ver
+ self.metadata = results['metadata']
+ self.userdata_raw = results.get('userdata')
if md['dsmode'] == self.dsmode:
return True
@@ -137,6 +136,7 @@ class DataSourceConfigDriveNet(DataSourceConfigDrive):
class NonConfigDriveDir(Exception):
pass
+
class BrokenConfigDriveDir(Exception):
pass
@@ -181,6 +181,7 @@ def read_config_drive_dir(source_dir):
last_e = exc
raise last_e
+
def read_config_drive_dir_v2(source_dir, version="latest"):
datafiles = (
('metadata',
@@ -222,7 +223,7 @@ def read_config_drive_dir_v2(source_dir, version="latest"):
files = {}
try:
- for item in results['metadata'].get('files',{}):
+ for item in results['metadata'].get('files', {}):
files[item['path']] = read_content_path(item)
item = results['metadata'].get("network_config", None)
@@ -235,6 +236,7 @@ def read_config_drive_dir_v2(source_dir, version="latest"):
results['cfgdrive_ver'] = 2
return results
+
def read_config_drive_dir_v1(source_dir):
"""
read source_dir, and return a tuple with metadata dict, user-data,
diff --git a/tests/unittests/test_datasource/test_configdrive.py b/tests/unittests/test_datasource/test_configdrive.py
index f73200e5..a801826b 100644
--- a/tests/unittests/test_datasource/test_configdrive.py
+++ b/tests/unittests/test_datasource/test_configdrive.py
@@ -4,7 +4,6 @@ import os
import os.path
from cloudinit.sources import DataSourceConfigDrive
-from cloudinit import url_helper
from mocker import MockerTestCase
@@ -54,7 +53,7 @@ CFG_DRIVE_FILES_V2 = {
'openstack/2012-08-10/user_data': USER_DATA,
'openstack/content/0000': CONTENT_0,
'openstack/content/0001': CONTENT_1,
- 'openstack/latest/meta_data.json': json.dumps(OSTACK_META),
+ 'openstack/latest/meta_data.json': json.dumps(OSTACK_META),
'openstack/latest/user_data': USER_DATA}