Fix cluster resize

There are two fixes included in this patch:

1. List nodes correctly. We have renamed minion to node, which
   cause the filter doesn't work correctly.
2. The response from magnumclient resize method is not a json,
   so we need to convert it to dict before return. Rolling upgrade
   has the same issue.

Task: 39810
Story: 2007697

Change-Id: I7a03dfea2c84a423f15cfbe4194a8492f72dbd35
(cherry picked from commit 96312eaf09)
This commit is contained in:
Feilong Wang 2020-05-20 16:43:39 +12:00 committed by Bharat Kunwar
parent 304866417d
commit 7f07bd31c9
1 changed files with 7 additions and 5 deletions

View File

@ -170,12 +170,14 @@ class ClusterResize(generic.View):
return HttpResponseNotFound() return HttpResponseNotFound()
stack = heat.stack_get(request, cluster["stack_id"]) stack = heat.stack_get(request, cluster["stack_id"])
search_opts = {"name": "%s-minion" % stack.stack_name} search_opts = {"name": "%s-" % stack.stack_name}
servers = api.nova.server_list(request, search_opts=search_opts)[0] servers = api.nova.server_list(request, search_opts=search_opts)[0]
worker_nodes = [] worker_nodes = []
for server in servers: for server in servers:
worker_nodes.append({"name": server.name, "id": server.id}) if (server.name.startswith("%s-minion" % stack.stack_name) or
server.name.startswith("%s-node" % stack.stack_name)):
worker_nodes.append({"name": server.name, "id": server.id})
return {"cluster": change_to_id(cluster), return {"cluster": change_to_id(cluster),
"worker_nodes": worker_nodes} "worker_nodes": worker_nodes}
@ -183,7 +185,6 @@ class ClusterResize(generic.View):
@rest_utils.ajax(data_required=True) @rest_utils.ajax(data_required=True)
def post(self, request, cluster_id): def post(self, request, cluster_id):
"""Resize a cluster""" """Resize a cluster"""
nodes_to_remove = request.DATA.get("nodes_to_remove", None) nodes_to_remove = request.DATA.get("nodes_to_remove", None)
nodegroup = request.DATA.get("nodegroup", None) nodegroup = request.DATA.get("nodegroup", None)
node_count = request.DATA.get("node_count") node_count = request.DATA.get("node_count")
@ -192,7 +193,8 @@ class ClusterResize(generic.View):
try: try:
return magnum.cluster_resize( return magnum.cluster_resize(
request, cluster_id, node_count, request, cluster_id, node_count,
nodes_to_remove=nodes_to_remove, nodegroup=nodegroup) nodes_to_remove=nodes_to_remove,
nodegroup=nodegroup).to_dict()
except AttributeError as e: except AttributeError as e:
# If cluster is not found magnum-client throws Attribute error # If cluster is not found magnum-client throws Attribute error
# catch and respond with 404 # catch and respond with 404
@ -214,7 +216,7 @@ class ClusterUpgrade(generic.View):
return magnum.cluster_upgrade( return magnum.cluster_upgrade(
request, cluster_id, cluster_template, request, cluster_id, cluster_template,
max_batch_size=max_batch_size, nodegroup=nodegroup) max_batch_size=max_batch_size, nodegroup=nodegroup).to_dict()
@urls.register @urls.register