Support for node replace in cluster service
This patch adds support for "cluster members replace" in cluster service: 1\ add cluster_replace_nodes in _proxy.py 2\ add replace_nodes in cluster.py 3\ add related unit tests partial-blueprint: support-cluster-replace-action https://blueprints.launchpad.net/senlin/+spec/support-cluster-replace-action Change-Id: I57bb835ae9ca31317b2ddd37958ddbdf64df20df
This commit is contained in:
parent
00526ee1a7
commit
cb0fc78117
|
@ -303,6 +303,20 @@ class Proxy(proxy2.BaseProxy):
|
|||
obj = self._find(_cluster.Cluster, cluster, ignore_missing=False)
|
||||
return obj.del_nodes(self.session, nodes)
|
||||
|
||||
def cluster_replace_nodes(self, cluster, nodes):
|
||||
"""Replace the nodes in a cluster with specified nodes.
|
||||
|
||||
: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 deleted/added to the cluster.
|
||||
: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.replace_nodes(self.session, nodes)
|
||||
|
||||
def cluster_scale_out(self, cluster, count=None):
|
||||
"""Inflate the size of a cluster.
|
||||
|
||||
|
|
|
@ -98,6 +98,14 @@ class Cluster(resource.Resource):
|
|||
}
|
||||
return self.action(session, body)
|
||||
|
||||
def replace_nodes(self, session, nodes):
|
||||
body = {
|
||||
'replace_nodes': {
|
||||
'nodes': nodes,
|
||||
}
|
||||
}
|
||||
return self.action(session, body)
|
||||
|
||||
def scale_out(self, session, count=None):
|
||||
body = {
|
||||
'scale_out': {
|
||||
|
|
|
@ -165,6 +165,19 @@ class TestCluster(testtools.TestCase):
|
|||
sess.post.assert_called_once_with(url, endpoint_filter=sot.service,
|
||||
json=body)
|
||||
|
||||
def test_replace_nodes(self):
|
||||
sot = cluster.Cluster(**FAKE)
|
||||
|
||||
resp = mock.Mock()
|
||||
resp.json = mock.Mock(return_value='')
|
||||
sess = mock.Mock()
|
||||
sess.post = mock.Mock(return_value=resp)
|
||||
self.assertEqual('', sot.replace_nodes(sess, {'node-22': 'node-44'}))
|
||||
url = 'clusters/%s/actions' % sot.id
|
||||
body = {'replace_nodes': {'nodes': {'node-22': 'node-44'}}}
|
||||
sess.post.assert_called_once_with(url, endpoint_filter=sot.service,
|
||||
json=body)
|
||||
|
||||
def test_policy_attach(self):
|
||||
sot = cluster.Cluster(**FAKE)
|
||||
|
||||
|
|
|
@ -143,6 +143,24 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase):
|
|||
method_args=[mock_cluster, ["node1"]],
|
||||
expected_args=[["node1"]])
|
||||
|
||||
@mock.patch.object(proxy_base.BaseProxy, '_find')
|
||||
def test_cluster_replace_nodes(self, mock_find):
|
||||
mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER')
|
||||
mock_find.return_value = mock_cluster
|
||||
self._verify("openstack.cluster.v1.cluster.Cluster.replace_nodes",
|
||||
self.proxy.cluster_replace_nodes,
|
||||
method_args=["FAKE_CLUSTER", {"node1": "node2"}],
|
||||
expected_args=[{"node1": "node2"}])
|
||||
mock_find.assert_called_once_with(cluster.Cluster, "FAKE_CLUSTER",
|
||||
ignore_missing=False)
|
||||
|
||||
def test_cluster_replace_nodes_with_obj(self):
|
||||
mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER')
|
||||
self._verify("openstack.cluster.v1.cluster.Cluster.replace_nodes",
|
||||
self.proxy.cluster_replace_nodes,
|
||||
method_args=[mock_cluster, {"node1": "node2"}],
|
||||
expected_args=[{"node1": "node2"}])
|
||||
|
||||
@mock.patch.object(proxy_base.BaseProxy, '_find')
|
||||
def test_cluster_scale_out(self, mock_find):
|
||||
mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER')
|
||||
|
|
Loading…
Reference in New Issue