Use shlex for exec string cmd, added integration testcase.

This commit is contained in:
Patrick Hensley 2014-10-22 13:26:23 -04:00
parent 3ac4c78850
commit b365796439
2 changed files with 19 additions and 4 deletions

View File

@ -548,8 +548,8 @@ class Client(requests.Session):
raise Exception('Exec is not supported in API < 1.15!')
if isinstance(container, dict):
container = container.get('Id')
if not isinstance(cmd, (list, tuple)):
cmd = [cmd]
if isinstance(cmd, six.string_types):
cmd = shlex.split(str(cmd))
data = {
'Container': container,

View File

@ -630,7 +630,8 @@ class TestRestartingContainer(BaseTestCase):
class TestExecuteCommand(BaseTestCase):
def runTest(self):
container = self.client.create_container('busybox', ['false'])
container = self.client.create_container('busybox', 'cat',
detach=True, stdin_open=True)
id = container['Id']
self.client.start(id)
self.tmp_containers.append(id)
@ -640,9 +641,23 @@ class TestExecuteCommand(BaseTestCase):
self.assertEqual(res, expected)
class TestExecuteCommandString(BaseTestCase):
def runTest(self):
container = self.client.create_container('busybox', 'cat',
detach=True, stdin_open=True)
id = container['Id']
self.client.start(id)
self.tmp_containers.append(id)
res = self.client.execute(id, 'echo hello world', stdout=True)
expected = b'hello world\n' if six.PY3 else 'hello world\n'
self.assertEqual(res, expected)
class TestExecuteCommandStreaming(BaseTestCase):
def runTest(self):
container = self.client.create_container('busybox', ['false'])
container = self.client.create_container('busybox', 'cat',
detach=True, stdin_open=True)
id = container['Id']
self.client.start(id)
self.tmp_containers.append(id)