refactor 'wait_for_volumes_available' when create/run a container

Change-Id: I08c09aaeca9965f9af0bd95606e58142ad999291
This commit is contained in:
WangChangyu 2018-02-03 16:16:43 +08:00
parent 138281905e
commit 25e432270a
2 changed files with 14 additions and 16 deletions

View File

@ -364,7 +364,6 @@ class ContainersController(base.Controller):
return result.get('port') return result.get('port')
def _get_phynet_info(self, context, net_id): def _get_phynet_info(self, context, net_id):
phynet_name = None
# NOTE(hongbin): Use admin context here because non-admin users are # NOTE(hongbin): Use admin context here because non-admin users are
# unable to retrieve provider:* attributes. # unable to retrieve provider:* attributes.
admin_context = zun_context.get_admin_context() admin_context = zun_context.get_admin_context()

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import itertools
import six import six
import time import time
@ -153,21 +154,19 @@ class Manager(periodic_task.PeriodicTasks):
def _wait_for_volumes_available(self, context, volumes, container, def _wait_for_volumes_available(self, context, volumes, container,
timeout=60, poll_interval=1): timeout=60, poll_interval=1):
start_time = time.time() start_time = time.time()
while time.time() - start_time < timeout: try:
count = 0 volumes = itertools.chain(volumes)
for vol in volumes: volume = next(volumes)
if self.driver.is_volume_available(context, vol): while time.time() - start_time < timeout:
count = count + 1 if self.driver.is_volume_available(context, volume):
else: volume = next(volumes)
break time.sleep(poll_interval)
if count == len(volumes): except StopIteration:
break return
time.sleep(poll_interval) msg = _("Volumes did not reach available status after"
else: "%d seconds") % (timeout)
msg = _("Volumes did not reach available status after" self._fail_container(context, container, msg, unset_host=True)
"%d seconds") % (timeout) raise exception.Conflict(msg)
self._fail_container(context, container, msg, unset_host=True)
raise exception.Conflict(msg)
def container_create(self, context, limits, requested_networks, def container_create(self, context, limits, requested_networks,
requested_volumes, container, run, pci_requests=None): requested_volumes, container, run, pci_requests=None):