diff --git a/openstack/cluster/v1/_proxy.py b/openstack/cluster/v1/_proxy.py index 5b46a4ec2..b3c65123c 100644 --- a/openstack/cluster/v1/_proxy.py +++ b/openstack/cluster/v1/_proxy.py @@ -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. diff --git a/openstack/cluster/v1/cluster.py b/openstack/cluster/v1/cluster.py index 85545eb5e..622697a6f 100644 --- a/openstack/cluster/v1/cluster.py +++ b/openstack/cluster/v1/cluster.py @@ -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) diff --git a/openstack/tests/unit/cluster/v1/test_cluster.py b/openstack/tests/unit/cluster/v1/test_cluster.py index 2a44aa831..374bb82d6 100644 --- a/openstack/tests/unit/cluster/v1/test_cluster.py +++ b/openstack/tests/unit/cluster/v1/test_cluster.py @@ -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) diff --git a/openstack/tests/unit/cluster/v1/test_proxy.py b/openstack/tests/unit/cluster/v1/test_proxy.py index b6861a8bd..9a71bba2b 100644 --- a/openstack/tests/unit/cluster/v1/test_proxy.py +++ b/openstack/tests/unit/cluster/v1/test_proxy.py @@ -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)