Fixing cluster scaling via CLI
If a cluster had a node group with a name different than a node group template name and you wanted to resize it via CLI, cluster wasn't able to be scaled. Change-Id: I554d9c07741dcb2077f9ecd0f6b5dbce65c6a464 Closes-bug: #1523455
This commit is contained in:
@@ -462,11 +462,11 @@ class ScaleCluster(show.ShowOne):
|
||||
help="Name or ID of the cluster",
|
||||
)
|
||||
parser.add_argument(
|
||||
'--node-groups',
|
||||
'--instances',
|
||||
nargs='+',
|
||||
metavar='<node-group:instances_count>',
|
||||
help='Node groups and number of their instances to be scale to '
|
||||
'[REQUIRED if JSON is not provided]'
|
||||
metavar='<node-group-template:instances_count>',
|
||||
help='Node group templates and number of their instances to be '
|
||||
'scale to [REQUIRED if JSON is not provided]'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--json',
|
||||
@@ -507,19 +507,21 @@ class ScaleCluster(show.ShowOne):
|
||||
"resize_node_groups": []
|
||||
}
|
||||
scale_node_groups = dict(
|
||||
map(lambda x: x.split(':', 1), parsed_args.node_groups))
|
||||
cluster_node_groups = [ng['name'] for ng in cluster.node_groups]
|
||||
map(lambda x: x.split(':', 1), parsed_args.instances))
|
||||
cluster_ng_map = {
|
||||
ng['node_group_template_id']: ng['name'] for ng
|
||||
in cluster.node_groups}
|
||||
for name, count in scale_node_groups.items():
|
||||
ng = utils.get_resource(client.node_group_templates, name)
|
||||
if ng.name in cluster_node_groups:
|
||||
ngt = utils.get_resource(client.node_group_templates, name)
|
||||
if ngt.id in cluster_ng_map:
|
||||
scale_object["resize_node_groups"].append({
|
||||
"name": ng.name,
|
||||
"name": cluster_ng_map[ngt.id],
|
||||
"count": int(count)
|
||||
})
|
||||
else:
|
||||
scale_object["add_node_groups"].append({
|
||||
"node_group_template_id": ng.id,
|
||||
"name": ng.name,
|
||||
"node_group_template_id": ngt.id,
|
||||
"name": ngt.name,
|
||||
"count": int(count)
|
||||
})
|
||||
if not scale_object['add_node_groups']:
|
||||
|
||||
@@ -35,7 +35,8 @@ CLUSTER_INFO = {
|
||||
"id": "ng_id",
|
||||
"name": "fakeng",
|
||||
"plugin_name": 'fake',
|
||||
"hadoop_version": '0.1'
|
||||
"hadoop_version": '0.1',
|
||||
"node_group_template_id": 'ngt_id'
|
||||
}
|
||||
],
|
||||
"hadoop_version": "0.1",
|
||||
@@ -59,6 +60,11 @@ CT_INFO = {
|
||||
"id": "ct_id"
|
||||
}
|
||||
|
||||
NGT_INFO = {
|
||||
'id': 'ngt_id',
|
||||
'name': 'fakeng'
|
||||
}
|
||||
|
||||
|
||||
class TestClusters(fakes.TestDataProcessing):
|
||||
def setUp(self):
|
||||
@@ -404,10 +410,11 @@ class TestScaleCluster(TestClusters):
|
||||
|
||||
def test_cluster_scale_resize(self):
|
||||
self.ngt_mock.find_unique.return_value = api_ngt.NodeGroupTemplate(
|
||||
None, CLUSTER_INFO['node_groups'][0])
|
||||
arglist = ['fake', '--node-groups', 'fakeng:1']
|
||||
None, NGT_INFO)
|
||||
arglist = ['fake', '--instances', 'fakeng:1']
|
||||
|
||||
verifylist = [('cluster', 'fake'), ('node_groups', ['fakeng:1'])]
|
||||
verifylist = [('cluster', 'fake'),
|
||||
('instances', ['fakeng:1'])]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
@@ -416,7 +423,10 @@ class TestScaleCluster(TestClusters):
|
||||
# Check that correct arguments were passed
|
||||
self.cl_mock.scale.assert_called_once_with(
|
||||
'cluster_id',
|
||||
{'resize_node_groups': [{'count': 1, 'name': 'fakeng'}]})
|
||||
{'resize_node_groups': [
|
||||
{'count': 1,
|
||||
'name': 'fakeng'}]}
|
||||
)
|
||||
|
||||
# Check that columns are correct
|
||||
expected_columns = ('Anti affinity', 'Cluster template id',
|
||||
@@ -438,18 +448,19 @@ class TestScaleCluster(TestClusters):
|
||||
new_ng = {'name': 'new', 'id': 'new_id'}
|
||||
self.ngt_mock.find_unique.return_value = api_ngt.NodeGroupTemplate(
|
||||
None, new_ng)
|
||||
arglist = ['fake', '--node-groups', 'fakeng:1']
|
||||
arglist = ['fake', '--instances', 'new:1']
|
||||
|
||||
verifylist = [('cluster', 'fake'), ('node_groups', ['fakeng:1'])]
|
||||
verifylist = [('cluster', 'fake'), ('instances', ['new:1'])]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
# Check that correct arguments were passed
|
||||
self.cl_mock.scale.assert_called_once_with(
|
||||
'cluster_id',
|
||||
{'add_node_groups': [
|
||||
{'count': 1, 'node_group_template_id': 'new_id',
|
||||
{'count': 1,
|
||||
'node_group_template_id': 'new_id',
|
||||
'name': 'new'}
|
||||
]})
|
||||
|
||||
Reference in New Issue
Block a user