Drop duplicated exception handle code from docker driver
Currently in container creation workflow, both compute manager[1] and compute driver[2] has logic to handle docker APIError. Actually we only need the logic in compute manager and the logic in compute driver shall be dropped. [1]https://github.com/openstack/zun/blob/master/zun/compute/manager.py#L83 [2]https://github.com/openstack/zun/blob/master/zun/container/docker/driver.py#L71 Change-Id: Ie2decd12f45bb8a0774f4ccbaac0dfd306ebb62b Closes-bug: #1627653
This commit is contained in:
parent
8c8ca4e152
commit
917bf9d40d
@ -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()
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user