Merge "Adding Check/Recover Actions to Clusters"
This commit is contained in:
@@ -379,6 +379,32 @@ class Proxy(proxy.BaseProxy):
|
||||
obj = self._find(_cluster.Cluster, cluster, ignore_missing=False)
|
||||
return obj.policy_update(self.session, policy, **params)
|
||||
|
||||
def check_cluster(self, cluster, **params):
|
||||
"""check a cluster.
|
||||
|
||||
:param cluster: The value can be either the ID of a cluster or a
|
||||
:class:`~openstack.cluster.v1.cluster.Cluster` instance.
|
||||
:param dict \*\*params: A dictionary providing the parameters for the
|
||||
check action.
|
||||
|
||||
:returns: A dictionary containing the action ID.
|
||||
"""
|
||||
obj = self._get_resource(_cluster.Cluster, cluster)
|
||||
return obj.check(self.session, **params)
|
||||
|
||||
def recover_cluster(self, cluster, **params):
|
||||
"""recover a node.
|
||||
|
||||
:param cluster: The value can be either the ID of a cluster or a
|
||||
:class:`~openstack.cluster.v1.cluster.Cluster` instance.
|
||||
:param dict \*\*params: A dictionary providing the parameters for the
|
||||
check action.
|
||||
|
||||
:returns: A dictionary containing the action ID.
|
||||
"""
|
||||
obj = self._get_resource(_cluster.Cluster, cluster)
|
||||
return obj.recover(self.session, **params)
|
||||
|
||||
def create_node(self, **attrs):
|
||||
"""Create a new node from attributes.
|
||||
|
||||
|
@@ -137,3 +137,15 @@ class Cluster(resource.Resource):
|
||||
'policy_update': data
|
||||
}
|
||||
return self.action(session, body)
|
||||
|
||||
def check(self, session, **params):
|
||||
body = {
|
||||
'check': params
|
||||
}
|
||||
return self.action(session, body)
|
||||
|
||||
def recover(self, session, **params):
|
||||
body = {
|
||||
'recover': params
|
||||
}
|
||||
return self.action(session, body)
|
||||
|
@@ -220,3 +220,31 @@ class TestCluster(testtools.TestCase):
|
||||
}
|
||||
sess.post.assert_called_once_with(url, endpoint_filter=sot.service,
|
||||
json=body)
|
||||
|
||||
def test_check(self):
|
||||
sot = cluster.Cluster(FAKE)
|
||||
sot['id'] = 'IDENTIFIER'
|
||||
|
||||
resp = mock.Mock()
|
||||
resp.json = mock.Mock(return_value='')
|
||||
sess = mock.Mock()
|
||||
sess.post = mock.Mock(return_value=resp)
|
||||
self.assertEqual('', sot.check(sess))
|
||||
url = 'clusters/%s/actions' % sot.id
|
||||
body = {'check': {}}
|
||||
sess.post.assert_called_once_with(url, endpoint_filter=sot.service,
|
||||
json=body)
|
||||
|
||||
def test_recover(self):
|
||||
sot = cluster.Cluster(FAKE)
|
||||
sot['id'] = 'IDENTIFIER'
|
||||
|
||||
resp = mock.Mock()
|
||||
resp.json = mock.Mock(return_value='')
|
||||
sess = mock.Mock()
|
||||
sess.post = mock.Mock(return_value=resp)
|
||||
self.assertEqual('', sot.recover(sess))
|
||||
url = 'clusters/%s/actions' % sot.id
|
||||
body = {'recover': {}}
|
||||
sess.post.assert_called_once_with(url, endpoint_filter=sot.service,
|
||||
json=body)
|
||||
|
@@ -255,6 +255,24 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
|
||||
expected_args=["FAKE_POLICY"],
|
||||
expected_kwargs={"k1": "v1", 'k2': "v2"})
|
||||
|
||||
@mock.patch.object(proxy_base.BaseProxy, '_get_resource')
|
||||
def test_cluster_check(self, mock_get):
|
||||
mock_cluster = cluster.Cluster.from_id('FAKE_CLUSTER')
|
||||
mock_get.return_value = mock_cluster
|
||||
self._verify("openstack.cluster.v1.cluster.Cluster.check",
|
||||
self.proxy.check_cluster,
|
||||
method_args=["FAKE_CLUSTER"])
|
||||
mock_get.assert_called_once_with(cluster.Cluster, "FAKE_CLUSTER")
|
||||
|
||||
@mock.patch.object(proxy_base.BaseProxy, '_get_resource')
|
||||
def test_cluster_recover(self, mock_get):
|
||||
mock_cluster = cluster.Cluster.from_id('FAKE_CLUSTER')
|
||||
mock_get.return_value = mock_cluster
|
||||
self._verify("openstack.cluster.v1.cluster.Cluster.recover",
|
||||
self.proxy.recover_cluster,
|
||||
method_args=["FAKE_CLUSTER"])
|
||||
mock_get.assert_called_once_with(cluster.Cluster, "FAKE_CLUSTER")
|
||||
|
||||
def test_node_create(self):
|
||||
self.verify_create(self.proxy.create_node, node.Node)
|
||||
|
||||
|
Reference in New Issue
Block a user