Always pass str to shlex.split for py26 compat

On python 2.6 shlex.split cannot handle unicode,
which can lead to TypeError exception.

Details can be seen in
http://bugs.python.org/issue6988
and
http://bugs.python.org/issue1548891

As best solution it seems to decode *cmd* to utf-8 str
before passing to shlex.split().

Change-Id: If56a6f16ab712691b26035d0cd3d7d70260a64c6
This commit is contained in:
Pavel Sedlák
2014-07-10 23:49:48 +02:00
parent 2663a5bcd9
commit a612e633d4
3 changed files with 4 additions and 4 deletions

View File

@@ -120,7 +120,7 @@ class ClientTestBase(tempest.test.BaseTestCase):
cmd = ' '.join([os.path.join(CONF.cli.cli_dir, cmd),
flags, action, params])
LOG.info("running: '%s'" % cmd)
cmd = shlex.split(cmd)
cmd = shlex.split(cmd.encode('utf-8'))
result = ''
result_err = ''
stdout = subprocess.PIPE

View File

@@ -25,7 +25,7 @@ LOG = logging.getLogger(__name__)
def sudo_cmd_call(cmd):
args = shlex.split(cmd)
args = shlex.split(cmd.encode('utf-8'))
subprocess_args = {'stdout': subprocess.PIPE,
'stderr': subprocess.STDOUT}
proc = subprocess.Popen(['/usr/bin/sudo', '-n'] + args,
@@ -84,7 +84,7 @@ def copy_file_to_host(file_from, dest, host, username, pkey):
"-i %(pkey)s %(file1)s %(dest)s" % {'pkey': pkey,
'file1': file_from,
'dest': dest}
args = shlex.split(cmd)
args = shlex.split(cmd.encode('utf-8'))
subprocess_args = {'stdout': subprocess.PIPE,
'stderr': subprocess.STDOUT}
proc = subprocess.Popen(args, **subprocess_args)

View File

@@ -32,7 +32,7 @@ class StressFrameworkTest(base.TestCase):
cmd = ' '.join([cmd, param])
LOG.info("running: '%s'" % cmd)
cmd_str = cmd
cmd = shlex.split(cmd)
cmd = shlex.split(cmd.encode('utf-8'))
result = ''
result_err = ''
try: