Move wait_for_resource_status()
wait_for_resource_status() is used in DeletableResource only,
and some arguments are not used at all.
So this patch moves the method into DeletableResource and removes
unsed arguments for the cleanup.
Partially implements blueprint consistent-service-method-names
Change-Id: I036822bfd689ed6d2ce23e7c519174cad8db2a7f
diff --git a/tempest/services/network/resources.py b/tempest/services/network/resources.py
index 5512075..e78fcfe 100644
--- a/tempest/services/network/resources.py
+++ b/tempest/services/network/resources.py
@@ -14,9 +14,13 @@
# under the License.
import abc
+import time
import six
+from tempest import exceptions
+from tempest.lib.common.utils import misc
+
class AttributeDict(dict):
"""Provide attribute access (dict.key) to dictionary values."""
@@ -67,7 +71,35 @@
self.refresh()
return self
- return self.client.wait_for_resource_status(helper_get, status)
+ return self.wait_for_resource_status(helper_get, status)
+
+ def wait_for_resource_status(self, fetch, status):
+ """Waits for a network resource to reach a status
+
+ @param fetch: the callable to be used to query the resource status
+ @type fecth: callable that takes no parameters and returns the resource
+ @param status: the status that the resource has to reach
+ @type status: String
+ """
+ interval = self.build_interval
+ timeout = self.build_timeout
+ start_time = time.time()
+
+ while time.time() - start_time <= timeout:
+ resource = fetch()
+ if resource['status'] == status:
+ return
+ time.sleep(interval)
+
+ # At this point, the wait has timed out
+ message = 'Resource %s' % (str(resource))
+ message += ' failed to reach status %s' % status
+ message += ' (current: %s)' % resource['status']
+ message += ' within the required time %s' % timeout
+ caller = misc.find_test_caller()
+ if caller:
+ message = '(%s) %s' % (caller, message)
+ raise exceptions.TimeoutException(message)
class DeletableNetwork(DeletableResource):