Merge "Fix init container in capsule"

This commit is contained in:
Zuul 2019-04-10 02:14:08 +00:00 committed by Gerrit Code Review
commit 6aef076bb0
2 changed files with 27 additions and 0 deletions

View File

@ -33,5 +33,6 @@ SQLAlchemy!=1.1.5,!=1.1.6,!=1.1.7,!=1.1.8,>=1.0.10 # MIT
stevedore>=1.20.0 # Apache-2.0
docker>=2.4.2 # Apache-2.0
neutron-lib>=1.13.0 # Apache-2.0
tenacity>=4.9.0 # Apache-2.0
websockify>=0.8.0 # LGPLv3
websocket-client>=0.44.0 # LGPLv2+

View File

@ -24,6 +24,7 @@ from oslo_utils import timeutils
from oslo_utils import uuidutils
import psutil
import six
import tenacity
from zun.common import consts
from zun.common import exception
@ -1193,6 +1194,11 @@ class DockerDriver(driver.ContainerDriver):
capsule = self.create(context, capsule, image, requested_networks,
requested_volumes)
self.start(context, capsule)
for container in capsule.init_containers:
self._create_container_in_capsule(context, capsule, container,
requested_networks,
requested_volumes)
self._wait_for_init_container(context, container)
for container in capsule.containers:
self._create_container_in_capsule(context, capsule, container,
requested_networks,
@ -1284,6 +1290,26 @@ class DockerDriver(driver.ContainerDriver):
self._populate_container(container, response)
container.save(context)
def _wait_for_init_container(self, context, container, timeout=3600):
def retry_if_result_is_false(result):
return result is False
def check_init_container_stopped():
status = self.show(context, container).status
if status == consts.STOPPED:
return True
elif status == consts.RUNNING:
return False
else:
raise exception.ZunException(
_("Container has unexpected status: %s") % status)
r = tenacity.Retrying(
stop=tenacity.stop_after_delay(timeout),
wait=tenacity.wait_exponential(),
retry=tenacity.retry_if_result(retry_if_result_is_false))
r.call(check_init_container_stopped)
def delete_capsule(self, context, capsule, force):
for container in capsule.containers:
self._delete_container_in_capsule(context, capsule, container,