From 2497c6f60137eda08fab76405e2f6ad646dff02b Mon Sep 17 00:00:00 2001 From: YAMADA Hideki Date: Mon, 5 Sep 2016 07:53:06 +0000 Subject: [PATCH] Sheepdog: fix command execution failure Sheepdog driver uses oslo_concurrency.processutils.execute to execute the collie command. Until the commit 79532ea599cd0226e7176c6c7d59e04ee3b1a8ff, the driver uses execute in shell=True mode. In this mode, the arguments of execute can be a string of command arguments. But in default shell=False mode, the arguments of execute should be a sequence of command arguments. A minimum example: >>> processutils.execute('echo hoge', shell=True) ('hoge\n', '') >>> processutils.execute('echo hoge') Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/ oslo_concurrency/processutils.py", line 363, in execute env=env_variables) File "/usr/lib/python2.7/subprocess.py", line 710, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory >>> processutils.execute('echo', 'hoge') ('hoge\n', '') Change-Id: I73c3f071f28ee5c7f5d8f7a692a233fbd19f9260 Closes-Bug: #1620214 --- glance_store/_drivers/sheepdog.py | 13 +++++-------- glance_store/tests/unit/test_sheepdog_store.py | 13 +++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/glance_store/_drivers/sheepdog.py b/glance_store/_drivers/sheepdog.py index d4295e45..b70d2d16 100644 --- a/glance_store/_drivers/sheepdog.py +++ b/glance_store/_drivers/sheepdog.py @@ -124,17 +124,14 @@ class SheepdogImage(object): self.chunk_size = chunk_size def _run_command(self, command, data, *params): - cmd = ("collie vdi %(command)s -a %(addr)s -p %(port)d %(name)s " - "%(params)s" % - {"command": command, - "addr": self.addr, - "port": self.port, - "name": self.name, - "params": " ".join(map(str, params))}) + cmd = ['collie', 'vdi'] + cmd.extend(command.split(' ')) + cmd.extend(['-a', self.addr, '-p', self.port, self.name]) + cmd.extend(params) try: return processutils.execute( - cmd, process_input=data)[0] + *cmd, process_input=data)[0] except processutils.ProcessExecutionError as exc: LOG.error(exc) raise glance_store.BackendException(exc) diff --git a/glance_store/tests/unit/test_sheepdog_store.py b/glance_store/tests/unit/test_sheepdog_store.py index 29e90217..35f9f254 100644 --- a/glance_store/tests/unit/test_sheepdog_store.py +++ b/glance_store/tests/unit/test_sheepdog_store.py @@ -58,14 +58,11 @@ class TestSheepdogImage(oslotest.base.BaseTestCase): sheepdog.DEFAULT_CHUNKSIZE, ) image._run_command('create', None) - expected_cmd = ('collie vdi %(command)s' - ' -a %(addr)s -p %(port)d %(name)s ') % { - 'command': 'create', - 'addr': '127.0.0.1', - 'port': 7000, - 'name': '6bd59e6e-c410-11e5-ab67-0a73f1fda51b', - } - actual_cmd = mock_execute.call_args[0][0] + expected_cmd = ( + 'collie', 'vdi', 'create', '-a', '127.0.0.1', '-p', 7000, + '6bd59e6e-c410-11e5-ab67-0a73f1fda51b', + ) + actual_cmd = mock_execute.call_args[0] self.assertEqual(expected_cmd, actual_cmd)