From 7ea3e3aec619034a324dd4dd43680e26cacd33bc Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Thu, 2 Mar 2017 15:03:46 +1300 Subject: [PATCH] Split string commands on whitespace This change supports specifying commands as strings by spliting the string into a list using python's default whitespace string split(). This will handle simple string commands but not cases like quoted/escaped spaces. Other cases can be handled by specifying the command as a list instead. Change-Id: Icc4eebe324a4e6a7dd06f697ef16d38777f90861 --- .../install.d/hook-docker-cmd.py | 2 +- tests/test_hook_docker_cmd.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/heat-config-docker-cmd/install.d/hook-docker-cmd.py b/heat-config-docker-cmd/install.d/hook-docker-cmd.py index a14fe69..4235454 100755 --- a/heat-config-docker-cmd/install.d/hook-docker-cmd.py +++ b/heat-config-docker-cmd/install.d/hook-docker-cmd.py @@ -81,7 +81,7 @@ def command_argument(cmd, command): if not command: return [] if not isinstance(command, list): - return [command] + return command.split() return command diff --git a/tests/test_hook_docker_cmd.py b/tests/test_hook_docker_cmd.py index c8f80f5..78eff35 100644 --- a/tests/test_hook_docker_cmd.py +++ b/tests/test_hook_docker_cmd.py @@ -48,11 +48,12 @@ class HookDockerCmdTest(common.RunScriptTest): "web": { "name": "y", "start_order": 1, - "image": "xxx", + "image": "yyy", "net": "host", "restart": "always", "privileged": True, "user": "root", + "command": "/bin/webserver start", "volumes": [ "/run:/run", "db:/var/lib/db" @@ -168,6 +169,7 @@ class HookDockerCmdTest(common.RunScriptTest): '--detach=true', '--privileged=false', 'xxx' + '' ], state[1]['args']) self.assertEqual([ self.fake_tool_path, @@ -200,7 +202,9 @@ class HookDockerCmdTest(common.RunScriptTest): '--user=root', '--volume=/run:/run', '--volume=db:/var/lib/db', - 'xxx' + 'yyy', + '/bin/webserver', + 'start' ], state[3]['args']) self.assertEqual([ self.fake_tool_path, @@ -353,7 +357,9 @@ class HookDockerCmdTest(common.RunScriptTest): '--user=root', '--volume=/run:/run', '--volume=db:/var/lib/db', - 'xxx' + 'yyy', + '/bin/webserver', + 'start' ], state[3]['args']) self.assertEqual([ self.fake_tool_path, @@ -491,7 +497,9 @@ class HookDockerCmdTest(common.RunScriptTest): '--user=root', '--volume=/run:/run', '--volume=db:/var/lib/db', - 'xxx' + 'yyy', + '/bin/webserver', + 'start' ], state[5]['args']) self.assertEqual([ self.fake_tool_path,