summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2018-03-09 04:22:24 +0100
committerChad Smith <chad.smith@canonical.com>2018-03-09 04:22:24 +0100
commitb7a790246e52520b47a467fe89b81199b9cf03f6 (patch)
treef39c712b38233faad1896ef6de50b9f7a3a6bb6d /cloudinit/util.py
parent1e2e810f3f7cb6a163a0229ac37037e8c6744d72 (diff)
downloadvyos-cloud-init-b7a790246e52520b47a467fe89b81199b9cf03f6.tar.gz
vyos-cloud-init-b7a790246e52520b47a467fe89b81199b9cf03f6.zip
shellify: raise TypeError on bad input.
This makes 2 changes to shellify's behavior: a.) raise a TypeError rather than a RuntimeError. b.) raise a TypeError if input is not a list or tuple.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 1d6cd1c5..083a8efe 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -1922,6 +1922,11 @@ def abs_join(*paths):
# if it is an array, shell protect it (with single ticks)
# if it is a string, do nothing
def shellify(cmdlist, add_header=True):
+ if not isinstance(cmdlist, (tuple, list)):
+ raise TypeError(
+ "Input to shellify was type '%s'. Expected list or tuple." %
+ (type_utils.obj_name(cmdlist)))
+
content = ''
if add_header:
content += "#!/bin/sh\n"
@@ -1930,7 +1935,7 @@ def shellify(cmdlist, add_header=True):
for args in cmdlist:
# If the item is a list, wrap all items in single tick.
# If its not, then just write it directly.
- if isinstance(args, list):
+ if isinstance(args, (list, tuple)):
fixed = []
for f in args:
fixed.append("'%s'" % (six.text_type(f).replace("'", escaped)))
@@ -1940,9 +1945,10 @@ def shellify(cmdlist, add_header=True):
content = "%s%s\n" % (content, args)
cmds_made += 1
else:
- raise RuntimeError(("Unable to shellify type %s"
- " which is not a list or string")
- % (type_utils.obj_name(args)))
+ raise TypeError(
+ "Unable to shellify type '%s'. Expected list, string, tuple. "
+ "Got: %s" % (type_utils.obj_name(args), args))
+
LOG.debug("Shellified %s commands.", cmds_made)
return content