Fix scaling validation error

Sahara will validate resources when running scale cluster.
But we shouldn't check all resources in node groups while scaling,
because there are some configurations for MapReduce like
'mapreduce.reduce.java.opts' in 'node_configs' which are
added after validation.
This patch changes to validate resource in "node group
template" other than "node groups".

Closes-Bug: #1736671
Change-Id: I564b07cc4db275d4a369ce8cbff87cd6bda368fa
This commit is contained in:
Shu Yingya 2017-12-06 15:07:06 +00:00 committed by Telles Mota Vidal Nóbrega
parent bc2f5f03e2
commit e1b78b2bc7
3 changed files with 19 additions and 6 deletions

View File

@ -364,9 +364,14 @@ def check_resize(cluster, r_node_groups):
raise ex.InvalidReferenceException(
_("Cluster doesn't contain node group with name '%s'")
% ng['name'])
check_node_group_basic_fields(cluster.plugin_name,
cluster.hadoop_version,
ng_map[ng['name']])
node_group = ng_map[ng['name']]
if node_group.get('node_group_template_id'):
ng_tmpl_id = node_group['node_group_template_id']
check_node_group_template_exists(ng_tmpl_id)
ng_tmp = api.get_node_group_template(ng_tmpl_id).to_wrapped_dict()
check_node_group_basic_fields(cluster.plugin_name,
cluster.hadoop_version,
ng_tmp['node_group_template'])
def check_add_node_groups(cluster, add_node_groups):

View File

@ -63,11 +63,15 @@ class TestScalingValidation(u.ValidationTestCase):
self.assertEqual(expected_message, message)
raise e
@mock.patch('sahara.service.api.v10.get_node_group_template')
@mock.patch('sahara.utils.openstack.nova.client')
@mock.patch("sahara.service.api.OPS")
def test_check_cluster_scaling_resize_ng(self, ops, nova_client):
def test_check_cluster_scaling_resize_ng(self, ops, nova_client, get_ngt):
ops.get_engine_type_and_version.return_value = "direct.1.1"
ng1 = tu.make_ng_dict('ng', '42', ['namenode'], 1)
ng1 = tu.make_ng_dict('ng', '42', ['namenode'], 1,
node_group_template_id='aaa')
ng2 = tu.make_ng_dict('ng', '42', ['namenode'], 1,
resource=True)
cluster = tu.create_cluster("cluster1", "tenant1", "fake", "0.1",
[ng1],
status=c_u.CLUSTER_STATUS_VALIDATING,
@ -122,6 +126,7 @@ class TestScalingValidation(u.ValidationTestCase):
client = mock.Mock()
nova_client.return_value = client
client.flavors.list.return_value = []
get_ngt.return_value = ng2
self._assert_check_scaling(
data=data, cluster=cluster,

View File

@ -31,7 +31,8 @@ def create_cluster(name, tenant, plugin, version, node_groups, **kwargs):
def make_ng_dict(name, flavor, processes, count, instances=None,
volumes_size=None, node_configs=None, **kwargs):
volumes_size=None, node_configs=None, resource=False,
**kwargs):
node_configs = node_configs or {}
instances = instances or []
dct = {'id': uuidutils.generate_uuid(), 'name': name,
@ -43,6 +44,8 @@ def make_ng_dict(name, flavor, processes, count, instances=None,
'open_ports': [], 'is_proxy_gateway': False,
'volume_local_to_instance': False}
dct.update(kwargs)
if resource:
return r.NodeGroupTemplateResource(dct)
return dct