Merge "Add params to ClusterDelNodes action"

This commit is contained in:
Jenkins 2017-01-28 04:17:07 +00:00 committed by Gerrit Code Review
commit b8a4d87dbf
4 changed files with 34 additions and 7 deletions

View File

@ -289,19 +289,23 @@ class Proxy(proxy2.BaseProxy):
obj = self._find(_cluster.Cluster, cluster, ignore_missing=False)
return obj.add_nodes(self.session, nodes)
def cluster_del_nodes(self, cluster, nodes):
def cluster_del_nodes(self, cluster, nodes, **params):
"""Remove nodes from a cluster.
:param cluster: Either the name or the ID of the cluster, or an
instance of :class:`~openstack.cluster.v1.cluster.Cluster`.
:param nodes: List of nodes to be removed from the cluster.
:param kwargs \*\*params: Optional query parameters to be sent to
restrict the nodes to be returned. Available parameters include:
* destroy_after_deletion: A boolean value indicating whether the
deleted nodes to be destroyed right away.
:returns: A dict containing the action initiated by this operation.
"""
if isinstance(cluster, _cluster.Cluster):
obj = cluster
else:
obj = self._find(_cluster.Cluster, cluster, ignore_missing=False)
return obj.del_nodes(self.session, nodes)
return obj.del_nodes(self.session, nodes, **params)
def cluster_replace_nodes(self, cluster, nodes):
"""Replace the nodes in a cluster with specified nodes.

View File

@ -90,11 +90,11 @@ class Cluster(resource.Resource):
}
return self.action(session, body)
def del_nodes(self, session, nodes):
def del_nodes(self, session, nodes, **params):
data = {'nodes': nodes}
data.update(params)
body = {
'del_nodes': {
'nodes': nodes,
}
'del_nodes': data
}
return self.action(session, body)

View File

@ -165,6 +165,27 @@ class TestCluster(testtools.TestCase):
sess.post.assert_called_once_with(url, endpoint_filter=sot.service,
json=body)
def test_del_nodes_with_params(self):
sot = cluster.Cluster(**FAKE)
resp = mock.Mock()
resp.json = mock.Mock(return_value='')
sess = mock.Mock()
sess.post = mock.Mock(return_value=resp)
params = {
'destroy_after_deletion': True,
}
self.assertEqual('', sot.del_nodes(sess, ['node-11'], **params))
url = 'clusters/%s/actions' % sot.id
body = {
'del_nodes': {
'nodes': ['node-11'],
'destroy_after_deletion': True,
}
}
sess.post.assert_called_once_with(url, endpoint_filter=sot.service,
json=body)
def test_replace_nodes(self):
sot = cluster.Cluster(**FAKE)

View File

@ -141,7 +141,9 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase):
self._verify("openstack.cluster.v1.cluster.Cluster.del_nodes",
self.proxy.cluster_del_nodes,
method_args=[mock_cluster, ["node1"]],
expected_args=[["node1"]])
method_kwargs={"key": "value"},
expected_args=[["node1"]],
expected_kwargs={"key": "value"})
@mock.patch.object(proxy_base.BaseProxy, '_find')
def test_cluster_replace_nodes(self, mock_find):