From b493dcce93418ed09f0e2b7e1dccc20270deb75c Mon Sep 17 00:00:00 2001 From: "Walter A. Boring IV" Date: Fri, 28 Feb 2014 11:02:19 -0800 Subject: [PATCH] change time.sleep to use loopingcall We don't want to block the volume manager from servicing requests. So this patch changes our use of time.sleep to use loopingcall wait, which uses eventlet greenthread sleep. Change-Id: I13a1e4932e24ff5f09e35b8baa7c0fd5410388b6 Closes-Bug: #1286285 --- .../volume/drivers/san/hp/hp_3par_common.py | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/cinder/volume/drivers/san/hp/hp_3par_common.py b/cinder/volume/drivers/san/hp/hp_3par_common.py index f3fb0bde8..b6441bb28 100644 --- a/cinder/volume/drivers/san/hp/hp_3par_common.py +++ b/cinder/volume/drivers/san/hp/hp_3par_common.py @@ -39,7 +39,6 @@ import base64 import json import pprint import re -import time import uuid import hp3parclient @@ -51,6 +50,7 @@ from cinder import context from cinder import exception from cinder.openstack.common import excutils from cinder.openstack.common import log as logging +from cinder.openstack.common import loopingcall from cinder import units from cinder.volume import qos_specs from cinder.volume import volume_types @@ -119,10 +119,11 @@ class HP3PARCommon(object): 2.0.3 - Allow deleting missing snapshots bug #1283233 2.0.4 - Allow volumes created from snapshots to be larger bug #1279478 2.0.5 - Fix extend volume units bug #1284368 + 2.0.6 - use loopingcall.wait instead of time.sleep """ - VERSION = "2.0.5" + VERSION = "2.0.6" stats = {} @@ -731,13 +732,6 @@ class HP3PARCommon(object): LOG.error(str(ex)) raise exception.CinderException(str(ex)) - def _wait_for_task(self, task_id, poll_interval_sec=1): - while True: - status = self.client.getTask(task_id) - if status['status'] is not self.client.TASK_ACTIVE: - return status - time.sleep(poll_interval_sec) - def _copy_volume(self, src_name, dest_name, cpg, snap_cpg=None, tpvv=True): # Virtual volume sets are not supported with the -online option @@ -1108,9 +1102,22 @@ class HP3PARCommon(object): 'id=%s.') % volume['id']) # Wait for the physical copy task to complete - status = self._wait_for_task(task_id) - if status['status'] is not self.client.TASK_DONE: - dbg = {'status': status, 'id': volume['id']} + def _wait_for_task(task_id): + status = self.client.getTask(task_id) + LOG.debug("3PAR Task id %(id)s status = %(status)s" % + {'id': task_id, + 'status': status['status']}) + if status['status'] is not self.client.TASK_ACTIVE: + self._task_status = status + raise loopingcall.LoopingCallDone() + + self._task_status = None + timer = loopingcall.FixedIntervalLoopingCall( + _wait_for_task, task_id) + timer.start(interval=1).wait() + + if self._task_status['status'] is not self.client.TASK_DONE: + dbg = {'status': self._task_status, 'id': volume['id']} msg = _('Copy volume task failed: convert_to_base_volume: ' 'id=%(id)s, status=%(status)s.') % dbg raise exception.CinderException(msg) -- 2.45.2