Add wait_for_xxx methods to cluster proxy
The 'wait_for_status' and 'wait_for_delete' proxy methods are heavily used in the senlin code base. This patch revives the two proxy methods in case we may forget to add it back when the corresponding ones in ProxyBase are removed. Change-Id: I1de6fe031901cf5d319496b881815f0f757c6279
This commit is contained in:
parent
45dc2525e8
commit
02d7e1b311
@ -156,3 +156,12 @@ Event Operations
|
||||
|
||||
.. automethod:: openstack.cluster.v1._proxy.Proxy.get_event
|
||||
.. automethod:: openstack.cluster.v1._proxy.Proxy.events
|
||||
|
||||
|
||||
Helper Operations
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. autoclass:: openstack.cluster.v1._proxy.Proxy
|
||||
|
||||
.. automethod:: openstack.cluster.v1._proxy.Proxy.wait_for_delete
|
||||
.. automethod:: openstack.cluster.v1._proxy.Proxy.wait_for_status
|
||||
|
@ -1042,3 +1042,43 @@ class Proxy(proxy2.BaseProxy):
|
||||
:returns: A generator of event instances.
|
||||
"""
|
||||
return self._list(_event.Event, paginated=True, **query)
|
||||
|
||||
def wait_for_status(self, resource, status, failures=[], interval=2,
|
||||
wait=120):
|
||||
"""Wait for a resource to be in a particular status.
|
||||
|
||||
:param resource: The resource to wait on to reach the specified status.
|
||||
The resource must have a ``status`` attribute.
|
||||
:type resource: A :class:`~openstack.resource2.Resource` object.
|
||||
:param status: Desired status.
|
||||
:param list failures: Statuses that would be interpreted as failures.
|
||||
:param interval: Number of seconds to wait before to consecutive
|
||||
checks. Default to 2.
|
||||
:param wait: Maximum number of seconds to wait before the change.
|
||||
Default to 120.
|
||||
:returns: The resource is returned on success.
|
||||
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
|
||||
to the desired status failed to occur in specified seconds.
|
||||
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
|
||||
has transited to one of the failure statuses.
|
||||
:raises: :class:`~AttributeError` if the resource does not have a
|
||||
``status`` attribute.
|
||||
"""
|
||||
return resource2.wait_for_status(self._session, resource, status,
|
||||
failures, interval, wait)
|
||||
|
||||
def wait_for_delete(self, resource, interval=2, wait=120):
|
||||
"""Wait for a resource to be deleted.
|
||||
|
||||
:param resource: The resource to wait on to be deleted.
|
||||
:type resource: A :class:`~openstack.resource2.Resource` object.
|
||||
:param interval: Number of seconds to wait before to consecutive
|
||||
checks. Default to 2.
|
||||
:param wait: Maximum number of seconds to wait before the change.
|
||||
Default to 120.
|
||||
:returns: The resource is returned on success.
|
||||
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
|
||||
to delete failed to occur in the specified seconds.
|
||||
"""
|
||||
return resource2.wait_for_delete(self._session, resource, interval,
|
||||
wait)
|
||||
|
@ -497,3 +497,41 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase):
|
||||
paginated=True,
|
||||
method_kwargs={'limit': 2},
|
||||
expected_kwargs={'limit': 2})
|
||||
|
||||
@mock.patch("openstack.resource2.wait_for_status")
|
||||
def test_wait_for(self, mock_wait):
|
||||
mock_resource = mock.Mock()
|
||||
mock_wait.return_value = mock_resource
|
||||
|
||||
self.proxy.wait_for_status(mock_resource, 'ACTIVE')
|
||||
|
||||
mock_wait.assert_called_once_with(self.session, mock_resource,
|
||||
'ACTIVE', [], 2, 120)
|
||||
|
||||
@mock.patch("openstack.resource2.wait_for_status")
|
||||
def test_wait_for_params(self, mock_wait):
|
||||
mock_resource = mock.Mock()
|
||||
mock_wait.return_value = mock_resource
|
||||
|
||||
self.proxy.wait_for_status(mock_resource, 'ACTIVE', ['ERROR'], 1, 2)
|
||||
|
||||
mock_wait.assert_called_once_with(self.session, mock_resource,
|
||||
'ACTIVE', ['ERROR'], 1, 2)
|
||||
|
||||
@mock.patch("openstack.resource2.wait_for_delete")
|
||||
def test_wait_for_delete(self, mock_wait):
|
||||
mock_resource = mock.Mock()
|
||||
mock_wait.return_value = mock_resource
|
||||
|
||||
self.proxy.wait_for_delete(mock_resource)
|
||||
|
||||
mock_wait.assert_called_once_with(self.session, mock_resource, 2, 120)
|
||||
|
||||
@mock.patch("openstack.resource2.wait_for_delete")
|
||||
def test_wait_for_delete_params(self, mock_wait):
|
||||
mock_resource = mock.Mock()
|
||||
mock_wait.return_value = mock_resource
|
||||
|
||||
self.proxy.wait_for_delete(mock_resource, 1, 2)
|
||||
|
||||
mock_wait.assert_called_once_with(self.session, mock_resource, 1, 2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user