Merge "Fixed the file I/O issues on archive api"

This commit is contained in:
Jenkins 2017-03-06 03:23:58 +00:00 committed by Gerrit Code Review
commit 6748e5dbba
3 changed files with 9 additions and 8 deletions

View File

@ -477,8 +477,9 @@ class ContainersController(rest.RestController):
% (container.uuid, kw['path']))
context = pecan.request.context
compute_api = pecan.request.compute_api
return compute_api.container_get_archive(context,
container, kw['path'])
data, stat = compute_api.container_get_archive(
context, container, kw['path'])
return {"data": data, "stat": stat}
@pecan.expose('json')
@exception.wrap_pecan_controller_exception

View File

@ -354,7 +354,9 @@ class DockerDriver(driver.ContainerDriver):
def get_archive(self, container, path):
with docker_utils.docker_client() as docker:
try:
return docker.get_archive(container.container_id, path)
stream, stat = docker.get_archive(container.container_id, path)
filedata = stream.read()
return filedata, stat
except errors.APIError:
raise
@ -362,9 +364,7 @@ class DockerDriver(driver.ContainerDriver):
def put_archive(self, container, path, data):
with docker_utils.docker_client() as docker:
try:
f = open(data, 'rb')
filedata = f.read()
docker.put_archive(container.container_id, path, filedata)
docker.put_archive(container.container_id, path, data)
except errors.APIError:
raise

View File

@ -1356,7 +1356,7 @@ class TestContainerController(api_base.FunctionalTest):
mock_get_by_uuid,
container_get_archive,
mock_validate):
container_get_archive.return_value = ""
container_get_archive.return_value = ("", "")
test_container = utils.get_test_container()
test_container_obj = objects.Container(self.context, **test_container)
mock_get_by_uuid.return_value = test_container_obj
@ -1376,7 +1376,7 @@ class TestContainerController(api_base.FunctionalTest):
mock_get_by_name,
container_get_archive,
mock_validate):
container_get_archive.return_value = ""
container_get_archive.return_value = ("", "")
test_container = utils.get_test_container()
test_container_obj = objects.Container(self.context, **test_container)
mock_get_by_name.return_value = test_container_obj