~ubuntu-branches/ubuntu/vivid/sahara/vivid-proposed

« back to all changes in this revision

Viewing changes to sahara/tests/integration/tests/scaling.py

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2014-09-24 16:34:46 UTC
  • Revision ID: package-import@ubuntu.com-20140924163446-8gu3zscu5e3n9lr2
Tags: upstream-2014.2~b3
ImportĀ upstreamĀ versionĀ 2014.2~b3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2013 Mirantis Inc.
 
2
#
 
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
 
6
#
 
7
#    http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
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
 
12
# implied.
 
13
# See the License for the specific language governing permissions and
 
14
# limitations under the License.
 
15
 
 
16
from oslo.utils import excutils
 
17
 
 
18
from sahara.tests.integration.tests import base
 
19
 
 
20
 
 
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
 
30
 
 
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'] += (
 
41
                -old_count + count
 
42
            )
 
43
        if cluster_info['plugin_config'].PROCESS_NAMES['dn'] in processes:
 
44
            cluster_info['node_info']['datanode_count'] += -old_count + count
 
45
 
 
46
    @staticmethod
 
47
    def _add_new_field_to_scale_body_while_ng_resizing(
 
48
            scale_body, name, count):
 
49
        scale_body['resize_node_groups'].append(
 
50
            {
 
51
                'name': name,
 
52
                'count': count
 
53
            }
 
54
        )
 
55
 
 
56
    @staticmethod
 
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(
 
60
            {
 
61
                'node_group_template_id': ngt_id,
 
62
                'count': count,
 
63
                'name': name
 
64
            }
 
65
        )
 
66
 
 
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
 
77
                )
 
78
                self._change_node_info_while_ng_resizing(
 
79
                    node_group_name, node_group_size, cluster_info
 
80
                )
 
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
 
87
                )
 
88
                self._change_node_info_while_ng_adding(
 
89
                    node_group_id, node_group_size, cluster_info
 
90
                )
 
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']
 
95
        )
 
96
        try:
 
97
            new_node_info = self.get_node_info(new_node_ip_list,
 
98
                                               cluster_info['plugin_config'])
 
99
 
 
100
        except Exception as e:
 
101
            with excutils.save_and_reraise_exception():
 
102
                print(
 
103
                    '\nFailure during check of node process deployment '
 
104
                    'on cluster node: ' + str(e)
 
105
                )
 
106
        expected_node_info = cluster_info['node_info']
 
107
        self.assertEqual(
 
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)
 
113
        )
 
114
        return {
 
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']
 
119
        }