Use common "waiters.wait_for_snapshot_status" function everywhere

In Tempest we have the waiters.wait_for_snapshot_status function that
is already used in some places. So this commit replaces the use of the
wait_for_snapshot_status method defined in the base_snapshots_client.py
file with the use of the waiters.wait_for_snapshot_status function.

Change-Id: Ic017d468cc1478d8207ba482f161ed63c9b168fe
This commit is contained in:
Yaroslav Lobankov 2016-03-24 23:13:28 -05:00
parent ed3a35b3cc
commit 667aaa23d2
7 changed files with 13 additions and 52 deletions

View File

@ -51,8 +51,8 @@ class SnapshotsActionsV2Test(base.BaseVolumeAdminTest):
params = {cls.name_field: snap_name}
cls.snapshot = cls.client.create_snapshot(
volume_id=cls.volume['id'], **params)['snapshot']
cls.client.wait_for_snapshot_status(cls.snapshot['id'],
'available')
waiters.wait_for_snapshot_status(cls.client,
cls.snapshot['id'], 'available')
@classmethod
def resource_cleanup(cls):

View File

@ -123,8 +123,8 @@ class BaseVolumeTest(tempest.test.BaseTestCase):
snapshot = cls.snapshots_client.create_snapshot(
volume_id=volume_id, **kwargs)['snapshot']
cls.snapshots.append(snapshot)
cls.snapshots_client.wait_for_snapshot_status(snapshot['id'],
'available')
waiters.wait_for_snapshot_status(cls.snapshots_client,
snapshot['id'], 'available')
return snapshot
# NOTE(afazekas): these create_* and clean_* could be defined

View File

@ -479,8 +479,8 @@ class ScenarioTest(tempest.test.BaseTestCase):
self.addCleanup(
self.delete_wrapper, self.snapshots_client.delete_snapshot,
snapshot_id)
self.snapshots_client.wait_for_snapshot_status(snapshot_id,
'available')
waiters.wait_for_snapshot_status(self.snapshots_client,
snapshot_id, 'available')
image_name = snapshot_image['name']
self.assertEqual(name, image_name)

View File

@ -68,15 +68,15 @@ class TestStampPattern(manager.ScenarioTest):
self.snapshots_client.delete_snapshot(snapshot['id'])
try:
while self.snapshots_client.show_snapshot(
snapshot['id'])['snapshot']:
snapshot['id'])['snapshot']:
time.sleep(1)
except lib_exc.NotFound:
pass
self.addCleanup(cleaner)
waiters.wait_for_volume_status(self.volumes_client,
volume['id'], 'available')
self.snapshots_client.wait_for_snapshot_status(snapshot['id'],
'available')
waiters.wait_for_snapshot_status(self.snapshots_client,
snapshot['id'], 'available')
self.assertEqual(snapshot_name, snapshot['display_name'])
return snapshot

View File

@ -87,7 +87,8 @@ class TestVolumeBootPattern(manager.ScenarioTest):
self.addCleanup(
self.snapshots_client.wait_for_resource_deletion, snap['id'])
self.addCleanup(self.snapshots_client.delete_snapshot, snap['id'])
self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available')
waiters.wait_for_snapshot_status(self.snapshots_client,
snap['id'], 'available')
# NOTE(e0ne): Cinder API v2 uses name instead of display_name
if 'display_name' in snap:

View File

@ -10,13 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import time
from oslo_log import log as logging
from oslo_serialization import jsonutils as json
from six.moves.urllib import parse as urllib
from tempest import exceptions
from tempest.lib.common import rest_client
from tempest.lib import exceptions as lib_exc
@ -70,43 +67,6 @@ class BaseSnapshotsClient(rest_client.RestClient):
self.expected_success(200, resp.status)
return rest_client.ResponseBody(resp, body)
# NOTE(afazekas): just for the wait function
def _get_snapshot_status(self, snapshot_id):
body = self.show_snapshot(snapshot_id)['snapshot']
status = body['status']
# NOTE(afazekas): snapshot can reach an "error"
# state in a "normal" lifecycle
if (status == 'error'):
raise exceptions.SnapshotBuildErrorException(
snapshot_id=snapshot_id)
return status
# NOTE(afazkas): Wait reinvented again. It is not in the correct layer
def wait_for_snapshot_status(self, snapshot_id, status):
"""Waits for a Snapshot to reach a given status."""
start_time = time.time()
old_value = value = self._get_snapshot_status(snapshot_id)
while True:
dtime = time.time() - start_time
time.sleep(self.build_interval)
if value != old_value:
LOG.info('Value transition from "%s" to "%s"'
'in %d second(s).', old_value,
value, dtime)
if (value == status):
return value
if dtime > self.build_timeout:
message = ('Time Limit Exceeded! (%ds)'
'while waiting for %s, '
'but we got %s.' %
(self.build_timeout, status, value))
raise exceptions.TimeoutException(message)
time.sleep(self.build_interval)
old_value = value
value = self._get_snapshot_status(snapshot_id)
def delete_snapshot(self, snapshot_id):
"""Delete Snapshot."""
resp, body = self.delete("snapshots/%s" % str(snapshot_id))

View File

@ -88,8 +88,8 @@ def cleanup():
LOG.info("Cleanup::remove %s snapshots" % len(snaps))
for v in snaps:
try:
admin_manager.snapshots_client.\
wait_for_snapshot_status(v['id'], 'available')
waiters.wait_for_snapshot_status(
admin_manager.snapshots_client, v['id'], 'available')
admin_manager.snapshots_client.delete_snapshot(v['id'])
except Exception:
pass