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
This commit is contained in:
Steve Baker 2017-03-02 15:03:46 +13:00
parent 8b7af86908
commit 7ea3e3aec6
2 changed files with 13 additions and 5 deletions

View File

@ -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

View File

@ -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,