From 1e019cc001a8f31fa978d76b86fbe7813b2a076f Mon Sep 17 00:00:00 2001 From: Jay Faulkner Date: Tue, 26 Aug 2014 15:12:35 -0700 Subject: Refactor vendor_data handling vendor_data is guaranteed to be a dict if it exists; if it doesn't exist ensure it's represented by an empty dict to avoid checking it to see if it's a dict. --- cloudinit/sources/DataSourceConfigDrive.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cloudinit/sources/DataSourceConfigDrive.py b/cloudinit/sources/DataSourceConfigDrive.py index c55f7d4a..65477184 100644 --- a/cloudinit/sources/DataSourceConfigDrive.py +++ b/cloudinit/sources/DataSourceConfigDrive.py @@ -126,15 +126,12 @@ class DataSourceConfigDrive(openstack.SourceMixin, sources.DataSource): self.version = results['version'] self.files.update(results.get('files', {})) + # If there is no vendordata, set vd to an empty dict instead of None + vd = results.get('vendordata', {}) # if vendordata includes 'cloud-init', then read that explicitly # for cloud-init (for namespacing). - vd = results.get('vendordata') - if isinstance(vd, dict): - if 'cloud-init' in vd: - self.vendordata_raw = vd['cloud-init'] - else: - # TODO(pquerna): this is so wrong. - self.vendordata_raw = json.dumps(vd) + if 'cloud-init' in vd: + self.vendordata_raw = vd['cloud-init'] else: self.vendordata_raw = vd -- cgit v1.2.3