1
# Copyright (c) 2013 Mirantis Inc.
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
16
from oslo.utils import excutils
18
from sahara.tests.integration.tests import base
21
class ScalingTest(base.ITestCase):
22
def _change_node_info_while_ng_adding(self, ngt_id, count, cluster_info):
23
cluster_info['node_info']['node_count'] += count
24
node_processes = self.sahara.node_group_templates.get(
25
ngt_id).node_processes
26
if cluster_info['plugin_config'].PROCESS_NAMES['tt'] in node_processes:
27
cluster_info['node_info']['tasktracker_count'] += count
28
if cluster_info['plugin_config'].PROCESS_NAMES['dn'] in node_processes:
29
cluster_info['node_info']['datanode_count'] += count
31
def _change_node_info_while_ng_resizing(self, name, count, cluster_info):
32
node_groups = self.sahara.clusters.get(
33
cluster_info['cluster_id']).node_groups
34
for node_group in node_groups:
35
if node_group['name'] == name:
36
processes = node_group['node_processes']
37
old_count = node_group['count']
38
cluster_info['node_info']['node_count'] += -old_count + count
39
if cluster_info['plugin_config'].PROCESS_NAMES['tt'] in processes:
40
cluster_info['node_info']['tasktracker_count'] += (
43
if cluster_info['plugin_config'].PROCESS_NAMES['dn'] in processes:
44
cluster_info['node_info']['datanode_count'] += -old_count + count
47
def _add_new_field_to_scale_body_while_ng_resizing(
48
scale_body, name, count):
49
scale_body['resize_node_groups'].append(
57
def _add_new_field_to_scale_body_while_ng_adding(
58
scale_body, ngt_id, count, name):
59
scale_body['add_node_groups'].append(
61
'node_group_template_id': ngt_id,
67
@base.skip_test('SKIP_SCALING_TEST',
68
'Test for cluster scaling was skipped.')
69
def cluster_scaling(self, cluster_info, change_list):
70
scale_body = {'add_node_groups': [], 'resize_node_groups': []}
71
for change in change_list:
72
if change['operation'] == 'resize':
73
node_group_name = change['info'][0]
74
node_group_size = change['info'][1]
75
self._add_new_field_to_scale_body_while_ng_resizing(
76
scale_body, node_group_name, node_group_size
78
self._change_node_info_while_ng_resizing(
79
node_group_name, node_group_size, cluster_info
81
if change['operation'] == 'add':
82
node_group_name = change['info'][0]
83
node_group_size = change['info'][1]
84
node_group_id = change['info'][2]
85
self._add_new_field_to_scale_body_while_ng_adding(
86
scale_body, node_group_id, node_group_size, node_group_name
88
self._change_node_info_while_ng_adding(
89
node_group_id, node_group_size, cluster_info
91
self.sahara.clusters.scale(cluster_info['cluster_id'], scale_body)
92
self.poll_cluster_state(cluster_info['cluster_id'])
93
new_node_ip_list = self.get_cluster_node_ip_list_with_node_processes(
94
cluster_info['cluster_id']
97
new_node_info = self.get_node_info(new_node_ip_list,
98
cluster_info['plugin_config'])
100
except Exception as e:
101
with excutils.save_and_reraise_exception():
103
'\nFailure during check of node process deployment '
104
'on cluster node: ' + str(e)
106
expected_node_info = cluster_info['node_info']
108
expected_node_info, new_node_info,
109
'Failure while node info comparison.\n'
110
'Expected node info after cluster scaling: %s.\n'
111
'Actual node info after cluster scaling: %s.'
112
% (expected_node_info, new_node_info)
115
'cluster_id': cluster_info['cluster_id'],
116
'node_ip_list': new_node_ip_list,
117
'node_info': new_node_info,
118
'plugin_config': cluster_info['plugin_config']