diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-06-17 12:29:54 +0100 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-06-17 12:39:24 +0100 |
commit | 17f7d8f2c807b3c419df8f0100aeb10585859ce0 (patch) | |
tree | a72bb24e9599dee37a5249dd0b6961588724e8eb | |
parent | 8aa1da46a85f8775889e8674f90b224430196c9e (diff) | |
download | sandboxlib-17f7d8f2c807b3c419df8f0100aeb10585859ce0.tar.gz |
Validate extra_mounts a bit more thoroughly
I thought that a typeerror was causing a crash in YBD, but realised
it was something else. This commit should still be an improvement,
though.
-rw-r--r-- | sandboxlib/__init__.py | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/sandboxlib/__init__.py b/sandboxlib/__init__.py index 11140b1..3571eb6 100644 --- a/sandboxlib/__init__.py +++ b/sandboxlib/__init__.py @@ -193,22 +193,29 @@ def validate_extra_mounts(extra_mounts): new_extra_mounts = [] for mount_entry in extra_mounts: + if mount_entry[1] is None: + raise AssertionError( + "Mount point empty in mount entry %s" % mount_entry) + if len(mount_entry) == 3: - new_mount_entry = list(mount_entry) + [''] + full_mount_entry = list(mount_entry) + [''] elif len(mount_entry) == 4: - new_mount_entry = list(mount_entry) + full_mount_entry = list(mount_entry) else: raise AssertionError( "Invalid mount entry in 'extra_mounts': %s" % mount_entry) - if new_mount_entry[0] is None: - new_mount_entry[0] = '' - #new_mount_entry[0] = 'none' - if new_mount_entry[2] is None: - new_mount_entry[2] = '' - if new_mount_entry[3] is None: - new_mount_entry[3] = '' - new_extra_mounts.append(new_mount_entry) + # Convert all the entries to strings to prevent type errors later + # on. None is special cased to the empty string, as str(None) is + # "None". It's valid for some parameters to be '' in some cases. + processed_mount_entry = [] + for item in full_mount_entry: + if item is None: + processed_mount_entry.append('') + else: + processed_mount_entry.append(str(item)) + + new_extra_mounts.append(processed_mount_entry) return new_extra_mounts |