summaryrefslogtreecommitdiff
path: root/cloudinit/sources/__init__.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-08-26 20:52:41 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-08-26 20:52:41 -0700
commit7994ac0b1924cf0cc3e3e99ea6f11842f56bc4c8 (patch)
treed16e2d5fcaa5bc5856bc9f2cab35a050add95167 /cloudinit/sources/__init__.py
parentddc50b7450d5defcd1e05732fb3502d230926731 (diff)
downloadvyos-cloud-init-7994ac0b1924cf0cc3e3e99ea6f11842f56bc4c8.tar.gz
vyos-cloud-init-7994ac0b1924cf0cc3e3e99ea6f11842f56bc4c8.zip
Fix tests running and add in a check on the content type
before we look into the payload as well as make the skip test a function that the datasource module can also use.
Diffstat (limited to 'cloudinit/sources/__init__.py')
-rw-r--r--cloudinit/sources/__init__.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
index a3f4af1e..d49b67b2 100644
--- a/cloudinit/sources/__init__.py
+++ b/cloudinit/sources/__init__.py
@@ -81,8 +81,7 @@ class DataSource(object):
# headers, if not just skip this....
launch_idxs = 0
for part in processed_ud.walk():
- # multipart/* are just containers
- if part.get_content_maintype() == 'multipart':
+ if ud.is_skippable(part):
continue
launch_idx_h = part.get('Launch-Index', None)
if launch_idx_h is not None:
@@ -94,17 +93,23 @@ class DataSource(object):
# that have some other garbage that we don't know what to do with
accumulating_msg = MIMEMultipart()
tot_attached = 0
+ tot_processed = 0
for part in processed_ud.walk():
- # multipart/* are just containers
- if part.get_content_maintype() == 'multipart':
+ if ud.is_skippable(part):
continue
try:
+ tot_processed += 1
launch_idx_h = part.get('Launch-Index', None)
if launch_idx_h is None or int(launch_idx_h) == int(idx):
accumulating_msg.attach(part)
tot_attached += 1
- except:
- # If any int conversion fails (or other error), keep the part
+ else:
+ LOG.debug(("Discarding multipart message %s, "
+ "launch-index provided destined for %s "
+ "and not %s"),
+ tot_processed, launch_idx_h, idx)
+ except (TypeError, ValueError):
+ # If any int conversion fails keep the message
accumulating_msg.attach(part)
tot_attached += 1
accumulating_msg[ud.ATTACHMENT_FIELD] = str(tot_attached)