summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2018-03-15 11:40:13 -0600
committerChad Smith <chad.smith@canonical.com>2018-03-15 11:40:13 -0600
commit97012fbb5207ddf1d2dcbb1c5eae710c47ab8ec0 (patch)
treecbd8b3377e12763bf0c43657a7d3021fdda9fa89 /cloudinit/util.py
parent837021fd3ded8262ff7131efe6cfd4c7ce489e2b (diff)
downloadvyos-cloud-init-97012fbb5207ddf1d2dcbb1c5eae710c47ab8ec0.tar.gz
vyos-cloud-init-97012fbb5207ddf1d2dcbb1c5eae710c47ab8ec0.zip
util: Fix subp regression. Allow specifying subp command as a string.
The command provided to subp can either be a string or a list. This patch fixes a regression which raised CalledProcessError whenever providing a string to subp. LP: #1755965
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 4504f053..823d80bf 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -1874,8 +1874,14 @@ def subp(args, data=None, rcs=None, env=None, capture=True, shell=False,
# Popen converts entries in the arguments array from non-bytes to bytes.
# When locale is unset it may use ascii for that encoding which can
# cause UnicodeDecodeErrors. (LP: #1751051)
- bytes_args = [x if isinstance(x, six.binary_type) else x.encode("utf-8")
- for x in args]
+ if isinstance(args, six.binary_type):
+ bytes_args = args
+ elif isinstance(args, six.string_types):
+ bytes_args = args.encode("utf-8")
+ else:
+ bytes_args = [
+ x if isinstance(x, six.binary_type) else x.encode("utf-8")
+ for x in args]
try:
sp = subprocess.Popen(bytes_args, stdout=stdout,
stderr=stderr, stdin=stdin,