Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions libcloud/container/drivers/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ def parse_body(self):
# an error, but response status could still be 200
content_type = self.headers.get('content-type', 'application/json')
if content_type == 'application/json' or content_type == '':
body = json.loads(self.body)
if self.headers.get('transfer-encoding') == 'chunked':
body = [json.loads(chunk) for chunk in
self.body.strip().replace('\r', '').split('\n')]
else:
body = json.loads(self.body)
else:
body = self.body
except ValueError:
Expand Down Expand Up @@ -210,14 +214,20 @@ def install_image(self, path):
method='POST')
if "errorDetail" in result.body:
raise DockerException(None, result.body)
try:
# get image id
image_id = re.findall(
r'{"status":"Download complete"'
r',"progressDetail":{},"id":"\w+"}',
result.body)[-1]
image_id = json.loads(image_id).get('id')
except:
image_id = None

# the response is slightly different if the image is already present
# and it's not downloaded. both messages below indicate that the image
# is available for use to the daemon
if re.search(r'Downloaded newer image', result.body) or \
re.search(r'"Status: Image is up to date', result.body):
if re.search(r'sha256:(?P<id>[a-z0-9]{64})', result.body):
image_id = re.findall(r'sha256:(?P<id>[a-z0-9]{64})',
result.body)[-1]

# if there is a failure message or if there is not an image id in the
# response then throw an exception.
if image_id is None:
raise DockerException(None, 'failed to install image')

image = ContainerImage(
Expand Down

This file was deleted.

238 changes: 238 additions & 0 deletions libcloud/test/container/fixtures/docker/linux_124/create_image.txt

Large diffs are not rendered by default.

This file was deleted.

238 changes: 238 additions & 0 deletions libcloud/test/container/fixtures/docker/mac_124/create_image.txt

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions libcloud/test/container/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DockerContainerDriverTestCase(unittest.TestCase):

def setUp(self):
# Create a test driver for each version
versions = ('linux_121', 'mac_124')
versions = ('linux_124', 'mac_124')
self.drivers = []
for version in versions:
DockerContainerDriver.connectionCls.conn_classes = (
Expand All @@ -55,7 +55,7 @@ def test_install_image(self):
for driver in self.drivers:
image = driver.install_image('ubuntu:12.04')
self.assertTrue(image is not None)
self.assertEqual(image.id, 'cf55d61f5307b7a18a45980971d6cfd40b737dd661879c4a6b3f2aecc3bc37b0')
self.assertEqual(image.id, '992069aee4016783df6345315302fa59681aae51a8eeb2f889dea59290f21787')

def test_list_containers(self):
for driver in self.drivers:
Expand Down Expand Up @@ -124,108 +124,108 @@ class DockerMockHttp(MockHttp):
def _version(
self, method, url, body, headers):
if method == 'GET':
body = self.fixtures.load('linux_121/version.json')
body = self.fixtures.load('linux_124/version.json')
else:
raise AssertionError('Unsupported method')
return (httplib.OK, body, {}, httplib.responses[httplib.OK])

def _vlinux_121_images_search(
def _vlinux_124_images_search(
self, method, url, body, headers):
return (httplib.OK, self.fixtures.load('linux_121/search.json'), {}, httplib.responses[httplib.OK])
return (httplib.OK, self.fixtures.load('linux_124/search.json'), {}, httplib.responses[httplib.OK])

def _vmac_124_images_search(
self, method, url, body, headers):
return (httplib.OK, self.fixtures.load('mac_124/search.json'), {}, httplib.responses[httplib.OK])

def _vlinux_121_images_json(
def _vlinux_124_images_json(
self, method, url, body, headers):
return (httplib.OK, self.fixtures.load('linux_121/images.json'), {}, httplib.responses[httplib.OK])
return (httplib.OK, self.fixtures.load('linux_124/images.json'), {}, httplib.responses[httplib.OK])

def _vmac_124_images_json(
self, method, url, body, headers):
return (httplib.OK, self.fixtures.load('linux_121/images.json'), {}, httplib.responses[httplib.OK])
return (httplib.OK, self.fixtures.load('linux_124/images.json'), {}, httplib.responses[httplib.OK])

def _vlinux_121_images_create(
def _vlinux_124_images_create(
self, method, url, body, headers):
return (httplib.OK, self.fixtures.load('linux_121/create_image.json'), {'Content-Type': 'application/json'},
return (httplib.OK, self.fixtures.load('linux_124/create_image.txt'), {'Content-Type': 'application/json', 'transfer-encoding': 'chunked'},
httplib.responses[httplib.OK])

def _vmac_124_images_create(
self, method, url, body, headers):
return (httplib.OK, self.fixtures.load('mac_124/create_image.json'), {'Content-Type': 'application/json'},
return (httplib.OK, self.fixtures.load('mac_124/create_image.txt'), {'Content-Type': 'application/json', 'transfer-encoding': 'chunked'},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

httplib.responses[httplib.OK])

def _vlinux_121_containers_json(
def _vlinux_124_containers_json(
self, method, url, body, headers):
return (httplib.OK, self.fixtures.load('linux_121/containers.json'), {}, httplib.responses[httplib.OK])
return (httplib.OK, self.fixtures.load('linux_124/containers.json'), {}, httplib.responses[httplib.OK])

def _vmac_124_containers_json(
self, method, url, body, headers):
return (httplib.OK, self.fixtures.load('mac_124/containers.json'), {}, httplib.responses[httplib.OK])

def _vlinux_121_containers_create(
def _vlinux_124_containers_create(
self, method, url, body, headers):
return (httplib.OK, self.fixtures.load('linux_121/create_container.json'), {}, httplib.responses[httplib.OK])
return (httplib.OK, self.fixtures.load('linux_124/create_container.json'), {}, httplib.responses[httplib.OK])

def _vmac_124_containers_create(
self, method, url, body, headers):
return (httplib.OK, self.fixtures.load('mac_124/create_container.json'), {}, httplib.responses[httplib.OK])

def _vlinux_121_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303(
def _vlinux_124_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303(
self, method, url, body, headers):
return (httplib.NO_CONTENT, '', {}, httplib.responses[httplib.OK])

def _vmac_124_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303(
self, method, url, body, headers):
return (httplib.NO_CONTENT, '', {}, httplib.responses[httplib.OK])

def _vlinux_121_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_start(
def _vlinux_124_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_start(
self, method, url, body, headers):
return (httplib.NO_CONTENT, '', {}, httplib.responses[httplib.OK])

def _vmac_124_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_start(
self, method, url, body, headers):
return (httplib.NO_CONTENT, '', {}, httplib.responses[httplib.OK])

def _vlinux_121_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_restart(
def _vlinux_124_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_restart(
self, method, url, body, headers):
return (httplib.NO_CONTENT, '', {}, httplib.responses[httplib.OK])

def _vmac_124_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_restart(
self, method, url, body, headers):
return (httplib.NO_CONTENT, '', {}, httplib.responses[httplib.OK])

def _vlinux_121_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_rename(
def _vlinux_124_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_rename(
self, method, url, body, headers):
return (httplib.NO_CONTENT, '', {}, httplib.responses[httplib.OK])

def _vmac_124_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_rename(
self, method, url, body, headers):
return (httplib.NO_CONTENT, '', {}, httplib.responses[httplib.OK])

def _vlinux_121_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_stop(
def _vlinux_124_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_stop(
self, method, url, body, headers):
return (httplib.NO_CONTENT, '', {}, httplib.responses[httplib.OK])

def _vmac_124_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_stop(
self, method, url, body, headers):
return (httplib.NO_CONTENT, '', {}, httplib.responses[httplib.OK])

def _vlinux_121_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_json(
def _vlinux_124_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_json(
self, method, url, body, headers):
return (httplib.OK, self.fixtures.load('linux_121/container_a68.json'), {}, httplib.responses[httplib.OK])
return (httplib.OK, self.fixtures.load('linux_124/container_a68.json'), {}, httplib.responses[httplib.OK])

def _vmac_124_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_json(
self, method, url, body, headers):
return (httplib.OK, self.fixtures.load('linux_121/container_a68.json'), {}, httplib.responses[httplib.OK])
return (httplib.OK, self.fixtures.load('linux_124/container_a68.json'), {}, httplib.responses[httplib.OK])

def _vlinux_121_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_logs(
def _vlinux_124_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_logs(
self, method, url, body, headers):
return (httplib.OK, self.fixtures.load('linux_121/logs.txt'), {'content-type': 'text/plain'}, httplib.responses[httplib.OK])
return (httplib.OK, self.fixtures.load('linux_124/logs.txt'), {'content-type': 'text/plain'}, httplib.responses[httplib.OK])

def _vmac_124_containers_a68c1872c74630522c7aa74b85558b06824c5e672cee334296c50fb209825303_logs(
self, method, url, body, headers):
return (httplib.OK, self.fixtures.load('linux_121/logs.txt'), {'content-type': 'text/plain'}, httplib.responses[httplib.OK])
return (httplib.OK, self.fixtures.load('linux_124/logs.txt'), {'content-type': 'text/plain'}, httplib.responses[httplib.OK])

if __name__ == '__main__':
sys.exit(unittest.main())