From 847fda8353759e6eddee5a7478c9078b617a7837 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 8 Nov 2016 16:19:26 -0500 Subject: Ec2: protect against non-dictionary in block-device-mapping. Oracle public cloud has the string 'unavailable' in its metadata service for 'block-device-mapping'. The change here is to return None in device_name_to_device if that is the case. --- cloudinit/sources/DataSourceEc2.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'cloudinit/sources/DataSourceEc2.py') diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py index bc84ef5d..bb6d6fd7 100644 --- a/cloudinit/sources/DataSourceEc2.py +++ b/cloudinit/sources/DataSourceEc2.py @@ -151,6 +151,10 @@ class DataSourceEc2(sources.DataSource): # 'root': '/dev/sda1'} found = None bdm = self.metadata['block-device-mapping'] + if not isinstance(bdm, dict): + LOG.debug("block-device-mapping not a dictionary: '%s'", bdm) + return None + for (entname, device) in bdm.items(): if entname == name: found = device -- cgit v1.2.3 From 25c218e5659445ecf64febe03c08c6fd9ca016e6 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 9 Nov 2016 14:17:57 -0500 Subject: Ec2: fix syntax and tox in previous commit. Simply fix a commit that should not have been pushed. --- cloudinit/sources/DataSourceEc2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cloudinit/sources/DataSourceEc2.py') diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py index bb6d6fd7..c0b7ddd3 100644 --- a/cloudinit/sources/DataSourceEc2.py +++ b/cloudinit/sources/DataSourceEc2.py @@ -153,7 +153,7 @@ class DataSourceEc2(sources.DataSource): bdm = self.metadata['block-device-mapping'] if not isinstance(bdm, dict): LOG.debug("block-device-mapping not a dictionary: '%s'", bdm) - return None + return None for (entname, device) in bdm.items(): if entname == name: -- cgit v1.2.3 From 584b8434872322a9f617831742cc6b15977ecfbc Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 10 Nov 2016 21:01:12 -0500 Subject: pep8: fix style errors reported by pycodestyle 2.1.0 pycodestyle 2.1.0 is in Ubuntu zesty, and complained about the changes made here. Simple style changes. This makes 'make pep8' pass again when built in a zesty build system with proposed enabled. --- cloudinit/config/cc_ca_certs.py | 4 ++-- cloudinit/config/cc_growpart.py | 1 + cloudinit/config/cc_resizefs.py | 1 + cloudinit/handlers/upstart_job.py | 1 + cloudinit/safeyaml.py | 1 + cloudinit/sources/DataSourceAliYun.py | 1 + cloudinit/sources/DataSourceAltCloud.py | 1 + cloudinit/sources/DataSourceBigstep.py | 1 + cloudinit/sources/DataSourceEc2.py | 1 + cloudinit/sources/DataSourceGCE.py | 1 + cloudinit/util.py | 4 ++-- tools/hacking.py | 1 + 12 files changed, 14 insertions(+), 4 deletions(-) (limited to 'cloudinit/sources/DataSourceEc2.py') diff --git a/cloudinit/config/cc_ca_certs.py b/cloudinit/config/cc_ca_certs.py index 8d319e22..df77ba62 100644 --- a/cloudinit/config/cc_ca_certs.py +++ b/cloudinit/config/cc_ca_certs.py @@ -82,8 +82,8 @@ def add_ca_certs(certs): # We have to strip the content because blank lines in the file # causes subsequent entries to be ignored. (LP: #1077020) orig = util.load_file(CA_CERT_CONFIG) - cur_cont = '\n'.join([l for l in orig.splitlines() - if l != CA_CERT_FILENAME]) + cur_cont = '\n'.join([line for line in orig.splitlines() + if line != CA_CERT_FILENAME]) out = "%s\n%s\n" % (cur_cont.rstrip(), CA_CERT_FILENAME) util.write_file(CA_CERT_CONFIG, out, omode="wb") diff --git a/cloudinit/config/cc_growpart.py b/cloudinit/config/cc_growpart.py index a95e6c81..03df6047 100644 --- a/cloudinit/config/cc_growpart.py +++ b/cloudinit/config/cc_growpart.py @@ -354,4 +354,5 @@ def handle(_name, cfg, _cloud, log, _args): else: log.debug("'%s' %s: %s" % (entry, action, msg)) + RESIZERS = (('growpart', ResizeGrowPart), ('gpart', ResizeGpart)) diff --git a/cloudinit/config/cc_resizefs.py b/cloudinit/config/cc_resizefs.py index 1b917966..f3c36c9b 100644 --- a/cloudinit/config/cc_resizefs.py +++ b/cloudinit/config/cc_resizefs.py @@ -69,6 +69,7 @@ def _resize_xfs(mount_point, devpth): def _resize_ufs(mount_point, devpth): return ('growfs', devpth) + # Do not use a dictionary as these commands should be able to be used # for multiple filesystem types if possible, e.g. one command for # ext2, ext3 and ext4. diff --git a/cloudinit/handlers/upstart_job.py b/cloudinit/handlers/upstart_job.py index ab381e00..309af91e 100644 --- a/cloudinit/handlers/upstart_job.py +++ b/cloudinit/handlers/upstart_job.py @@ -116,4 +116,5 @@ def _has_suitable_upstart(): else: return True + SUITABLE_UPSTART = _has_suitable_upstart() diff --git a/cloudinit/safeyaml.py b/cloudinit/safeyaml.py index eba5d056..f6a3f765 100644 --- a/cloudinit/safeyaml.py +++ b/cloudinit/safeyaml.py @@ -23,6 +23,7 @@ class _CustomSafeLoader(yaml.SafeLoader): def construct_python_unicode(self, node): return self.construct_scalar(node) + _CustomSafeLoader.add_constructor( u'tag:yaml.org,2002:python/unicode', _CustomSafeLoader.construct_python_unicode) diff --git a/cloudinit/sources/DataSourceAliYun.py b/cloudinit/sources/DataSourceAliYun.py index 19957212..535813ab 100644 --- a/cloudinit/sources/DataSourceAliYun.py +++ b/cloudinit/sources/DataSourceAliYun.py @@ -38,6 +38,7 @@ def parse_public_keys(public_keys): keys.extend(key) return keys + # Used to match classes to dependencies datasources = [ (DataSourceAliYun, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)), diff --git a/cloudinit/sources/DataSourceAltCloud.py b/cloudinit/sources/DataSourceAltCloud.py index 20345389..fac7bbcc 100644 --- a/cloudinit/sources/DataSourceAltCloud.py +++ b/cloudinit/sources/DataSourceAltCloud.py @@ -270,6 +270,7 @@ class DataSourceAltCloud(sources.DataSource): else: return False + # Used to match classes to dependencies # Source DataSourceAltCloud does not really depend on networking. # In the future 'dsmode' like behavior can be added to offer user diff --git a/cloudinit/sources/DataSourceBigstep.py b/cloudinit/sources/DataSourceBigstep.py index f80956a5..e8fd0088 100644 --- a/cloudinit/sources/DataSourceBigstep.py +++ b/cloudinit/sources/DataSourceBigstep.py @@ -46,6 +46,7 @@ def get_url_from_file(): raise return content + # Used to match classes to dependencies datasources = [ (DataSourceBigstep, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)), diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py index c0b7ddd3..acbc2356 100644 --- a/cloudinit/sources/DataSourceEc2.py +++ b/cloudinit/sources/DataSourceEc2.py @@ -202,6 +202,7 @@ class DataSourceEc2(sources.DataSource): return az[:-1] return None + # Used to match classes to dependencies datasources = [ (DataSourceEc2, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)), diff --git a/cloudinit/sources/DataSourceGCE.py b/cloudinit/sources/DataSourceGCE.py index 6c12d703..5ed59559 100644 --- a/cloudinit/sources/DataSourceGCE.py +++ b/cloudinit/sources/DataSourceGCE.py @@ -156,6 +156,7 @@ class DataSourceGCE(sources.DataSource): def region(self): return self.availability_zone.rsplit('-', 1)[0] + # Used to match classes to dependencies datasources = [ (DataSourceGCE, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)), diff --git a/cloudinit/util.py b/cloudinit/util.py index 9a3d3cd7..ed2d93e5 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -2030,8 +2030,8 @@ def parse_mount_info(path, mountinfo_lines, log=LOG): continue # Ignore mounts where the common path is not the same. - l = min(len(mount_point_elements), len(path_elements)) - if mount_point_elements[0:l] != path_elements[0:l]: + x = min(len(mount_point_elements), len(path_elements)) + if mount_point_elements[0:x] != path_elements[0:x]: continue # Ignore mount points higher than an already seen mount diff --git a/tools/hacking.py b/tools/hacking.py index 716c1154..2d366a0a 100755 --- a/tools/hacking.py +++ b/tools/hacking.py @@ -156,6 +156,7 @@ def add_cloud(): if name.startswith("cloud_"): exec("pep8.%s = %s" % (name, name)) + if __name__ == "__main__": # NOVA based 'hacking.py' error codes start with an N pep8.ERRORCODE_REGEX = re.compile(r'[EWN]\d{3}') -- cgit v1.2.3