Merge branch 'master' of github.com:dotcloud/docker-py into yukw777-link

Fixed test_pull and test_pull_stream (don't assume headers content is empty)

Conflicts:
	tests/test.py
This commit is contained in:
shin- 2013-11-15 18:21:49 +01:00
commit 2828833607
4 changed files with 60 additions and 15 deletions

View File

@ -71,7 +71,7 @@ Identical to the `docker inspect` command, but only for containers.
* `c.inspect_image(image_id)` * `c.inspect_image(image_id)`
Identical to the `docker inspect` command, but only for images. Identical to the `docker inspect` command, but only for images.
* `c.kill(container)` * `c.kill(container, signal=None)`
Kill a container. Similar to the `docker kill` command. Kill a container. Similar to the `docker kill` command.
* `c.login(username, password=None, email=None)` * `c.login(username, password=None, email=None)`

View File

@ -408,11 +408,14 @@ class Client(requests.Session):
self._url("/images/{0}/json".format(image_id)) self._url("/images/{0}/json".format(image_id))
), True) ), True)
def kill(self, container): def kill(self, container, signal=None):
if isinstance(container, dict): if isinstance(container, dict):
container = container.get('Id') container = container.get('Id')
url = self._url("/containers/{0}/kill".format(container)) url = self._url("/containers/{0}/kill".format(container))
res = self.post(url, None) params = {}
if signal is not None:
params['signal'] = signal
res = self.post(url, None, params=params)
self._raise_for_status(res) self._raise_for_status(res)
def login(self, username, password=None, email=None, registry=None): def login(self, username, password=None, email=None, registry=None):

View File

@ -15,6 +15,7 @@
import base64 import base64
import io import io
import os import os
import signal
import tempfile import tempfile
import unittest import unittest
@ -369,6 +370,24 @@ class TestKillWithDictInsteadOfId(BaseTestCase):
self.assertEqual(state['Running'], False) self.assertEqual(state['Running'], False)
class TestKillWithSignal(BaseTestCase):
def runTest(self):
container = self.client.create_container('busybox', ['sleep', '60'])
id = container['Id']
self.client.start(id)
self.tmp_containers.append(id)
self.client.kill(id, signal=signal.SIGTERM)
exitcode = self.client.wait(id)
self.assertNotEqual(exitcode, 0)
container_info = self.client.inspect_container(id)
self.assertIn('State', container_info)
state = container_info['State']
self.assertIn('ExitCode', state)
self.assertNotEqual(state['ExitCode'], 0)
self.assertIn('Running', state)
self.assertEqual(state['Running'], False, state)
class TestRestart(BaseTestCase): class TestRestart(BaseTestCase):
def runTest(self): def runTest(self):
container = self.client.create_container('busybox', ['sleep', '9999']) container = self.client.create_container('busybox', ['sleep', '9999'])

View File

@ -17,6 +17,7 @@ import datetime
import io import io
import json import json
import os import os
import signal
import tempfile import tempfile
import unittest import unittest
@ -423,7 +424,8 @@ class DockerClientTest(unittest.TestCase):
fake_request.assert_called_with( fake_request.assert_called_with(
'unix://var/run/docker.sock/v1.6/containers/3cc2351ab11b/kill', 'unix://var/run/docker.sock/v1.6/containers/3cc2351ab11b/kill',
None None,
params={}
) )
def test_kill_container_with_dict_instead_of_id(self): def test_kill_container_with_dict_instead_of_id(self):
@ -434,7 +436,20 @@ class DockerClientTest(unittest.TestCase):
fake_request.assert_called_with( fake_request.assert_called_with(
'unix://var/run/docker.sock/v1.6/containers/3cc2351ab11b/kill', 'unix://var/run/docker.sock/v1.6/containers/3cc2351ab11b/kill',
None None,
params={}
)
def test_kill_container_with_signal(self):
try:
self.client.kill(fake_api.FAKE_CONTAINER_ID, signal=signal.SIGTERM)
except Exception as e:
self.fail('Command should not raise exception: {0}'.format(e))
fake_request.assert_called_with(
'unix://var/run/docker.sock/v1.6/containers/3cc2351ab11b/kill',
None,
params={'signal': signal.SIGTERM}
) )
def test_restart_container(self): def test_restart_container(self):
@ -504,12 +519,16 @@ class DockerClientTest(unittest.TestCase):
except Exception as e: except Exception as e:
self.fail('Command should not raise exception: {0}'.format(e)) self.fail('Command should not raise exception: {0}'.format(e))
fake_request.assert_called_with( args = fake_request.call_args
'unix://var/run/docker.sock/v1.6/images/create', self.assertEqual(
headers={}, args[0][0],
params={'tag': None, 'fromImage': 'joffrey/test001'}, 'unix://var/run/docker.sock/v1.6/images/create'
stream=False
) )
self.assertEqual(
args[1]['params'],
{'tag': None, 'fromImage': 'joffrey/test001'}
)
self.assertFalse(args[1]['stream'])
def test_pull_stream(self): def test_pull_stream(self):
try: try:
@ -517,12 +536,16 @@ class DockerClientTest(unittest.TestCase):
except Exception as e: except Exception as e:
self.fail('Command should not raise exception: {0}'.format(e)) self.fail('Command should not raise exception: {0}'.format(e))
fake_request.assert_called_with( args = fake_request.call_args
'unix://var/run/docker.sock/v1.6/images/create', self.assertEqual(
headers={}, args[0][0],
params={'tag': None, 'fromImage': 'joffrey/test001'}, 'unix://var/run/docker.sock/v1.6/images/create'
stream=True
) )
self.assertEqual(
args[1]['params'],
{'tag': None, 'fromImage': 'joffrey/test001'}
)
self.assertTrue(args[1]['stream'])
def test_commit(self): def test_commit(self):
try: try: