From e1b78b2bc7c152d7dc9ac7f010f3044365abd926 Mon Sep 17 00:00:00 2001 From: Shu Yingya Date: Wed, 6 Dec 2017 15:07:06 +0000 Subject: [PATCH] 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 --- sahara/service/validations/base.py | 11 ++++++++--- .../validation/test_cluster_scaling_validation.py | 9 +++++++-- sahara/tests/unit/testutils.py | 5 ++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/sahara/service/validations/base.py b/sahara/service/validations/base.py index e2ea989ec9..99d65d61c9 100644 --- a/sahara/service/validations/base.py +++ b/sahara/service/validations/base.py @@ -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): diff --git a/sahara/tests/unit/service/validation/test_cluster_scaling_validation.py b/sahara/tests/unit/service/validation/test_cluster_scaling_validation.py index 787f865574..bd634bb678 100644 --- a/sahara/tests/unit/service/validation/test_cluster_scaling_validation.py +++ b/sahara/tests/unit/service/validation/test_cluster_scaling_validation.py @@ -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, diff --git a/sahara/tests/unit/testutils.py b/sahara/tests/unit/testutils.py index 282ee72da4..1489c44082 100644 --- a/sahara/tests/unit/testutils.py +++ b/sahara/tests/unit/testutils.py @@ -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