Merge "Drop duplicated exception handle code from docker driver"

This commit is contained in:
Jenkins 2016-09-29 07:47:25 +00:00 committed by Gerrit Code Review
commit a5a353ae93
2 changed files with 24 additions and 28 deletions

View File

@ -72,7 +72,7 @@ class Manager(object):
self._fail_container(container)
return
except Exception as e:
LOG.exception(_LE("Unexpected exception: %s"), str(e))
LOG.exception(_LE("Unexpected exception: %s"), six.text_type(e))
self._fail_container(container)
return
@ -83,10 +83,10 @@ class Manager(object):
except exception.DockerError as e:
LOG.error(_LE("Error occured while calling docker API: %s"),
six.text_type(e))
container.status = fields.ContainerStatus.ERROR
self._fail_container(container)
except Exception as e:
LOG.exception(_LE("Unexpected exception: %s"), str(e))
container.status = fields.ContainerStatus.ERROR
LOG.exception(_LE("Unexpected exception: %s"), six.text_type(e))
self._fail_container(container)
finally:
container.task_state = None
container.save()

View File

@ -45,33 +45,29 @@ class DockerDriver(driver.ContainerDriver):
image = container.image
LOG.debug('Creating container with image %s name %s'
% (image, name))
try:
kwargs = {
'hostname': container.hostname,
'command': container.command,
'environment': container.environment,
'working_dir': container.workdir,
'ports': container.ports,
'labels': container.labels,
}
host_config = {}
host_config['publish_all_ports'] = True
if container.memory is not None:
host_config['mem_limit'] = container.memory
if container.cpu is not None:
host_config['cpu_quota'] = int(100000 * container.cpu)
host_config['cpu_period'] = 100000
kwargs['host_config'] = \
docker.create_host_config(**host_config)
kwargs = {
'hostname': container.hostname,
'command': container.command,
'environment': container.environment,
'working_dir': container.workdir,
'ports': container.ports,
'labels': container.labels,
}
response = docker.create_container(image, **kwargs)
container.container_id = response['Id']
container.status = fields.ContainerStatus.STOPPED
except errors.APIError as e:
container.status = fields.ContainerStatus.ERROR
container.status_reason = six.text_type(e)
host_config = {}
host_config['publish_all_ports'] = True
if container.memory is not None:
host_config['mem_limit'] = container.memory
if container.cpu is not None:
host_config['cpu_quota'] = int(100000 * container.cpu)
host_config['cpu_period'] = 100000
kwargs['host_config'] = \
docker.create_host_config(**host_config)
response = docker.create_container(image, **kwargs)
container.container_id = response['Id']
container.status = fields.ContainerStatus.STOPPED
container.save()
return container