Return a list of nodes on reprovision=false

Unfortunetely, a type of response depends on inputs and that's what we
have right now. By spending more time we can split this handle on two
handlers to have more clear API for clients. But right now this patch
fixes the problem with the response in NodeReassignHandler.

Partial-bug: #1624920

Change-Id: I896636fd78502318cdbbf92dd312b87fc23a3c41
This commit is contained in:
Ilya Kharin 2016-11-29 00:17:00 +03:00 committed by Roman Sokolkov
parent 2ae96ec76f
commit 5b8392298a
2 changed files with 17 additions and 7 deletions

View File

@ -80,6 +80,7 @@ class NodeReassignHandler(base.BaseHandler):
@base.handle_errors
@base.validate
@base.serialize
def POST(self, cluster_id):
"""Reassign nodes to the given cluster.
@ -92,7 +93,9 @@ class NodeReassignHandler(base.BaseHandler):
:param cluster_id: ID of the cluster nodes should be assigned to.
:returns: None
:http: * 202 (OK)
:http: * 202 (OK, A task which was accepted to provision
successfully moved nodes)
* 200 (OK, A list of nodes which are successfully moved)
* 400 (Incorrect node state, problem with task execution,
conflicting or incorrect roles)
* 404 (Cluster or node not found)
@ -104,11 +107,11 @@ class NodeReassignHandler(base.BaseHandler):
reprovision = data.get('reprovision', True)
given_roles = data.get('roles', [])
nodes_to_provision = []
nodes = []
for node_id in data['nodes_ids']:
node = adapters.NailgunNodeAdapter(
self.get_object_or_404(objects.Node, node_id))
nodes_to_provision.append(node.node)
nodes.append(node.node)
roles, pending_roles = upgrade.UpgradeHelper.get_node_roles(
reprovision, node.roles, given_roles)
@ -116,7 +119,9 @@ class NodeReassignHandler(base.BaseHandler):
node, cluster, roles, pending_roles)
if reprovision:
self.handle_task(cluster_id, nodes_to_provision)
self.handle_task(cluster_id, nodes)
else:
return objects.NodeCollection.to_list(nodes)
class CopyVIPsHandler(base.BaseHandler):

View File

@ -127,12 +127,13 @@ class TestNodeReassignHandler(base.BaseIntegrationTest):
cluster_kwargs={'api': False},
nodes_kwargs=[{'status': consts.NODE_STATUSES.ready,
'roles': ['controller']}])
node = cluster.nodes[0]
seed_cluster = self.env.create_cluster(api=False)
data = {'nodes_ids': [node.id],
new_roles = ['compute']
nodes_ids = [node.id for node in cluster.nodes]
data = {'nodes_ids': nodes_ids,
'reprovision': False,
'roles': ['compute']}
'roles': new_roles}
resp = self.app.post(
reverse('NodeReassignHandler',
kwargs={'cluster_id': seed_cluster.id}),
@ -141,6 +142,10 @@ class TestNodeReassignHandler(base.BaseIntegrationTest):
self.assertEqual(200, resp.status_code)
self.assertFalse(mcast.called)
self.assertEqual(node.roles, ['compute'])
for node in resp.json_body:
self.assertEqual(node["cluster"], seed_cluster.id)
self.assertEqual(node["roles"], new_roles)
self.assertIn(node["id"], nodes_ids)
def test_node_reassign_handler_no_node(self):
cluster = self.env.create_cluster()