blob: ff67c1c830687e2f91f1f6611e19edb8d8742e33 [file] [log] [blame]
Yaroslav Lobankov436605b2014-04-24 18:42:54 +04001# Copyright (c) 2014 Mirantis Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# 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, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15from tempest.api.data_processing import base as dp_base
16from tempest.common.utils import data_utils
17from tempest import test
18
19
20class ClusterTemplateTest(dp_base.BaseDataProcessingTest):
21 """Link to the API documentation is http://docs.openstack.org/developer/
22 sahara/restapi/rest_api_v1.0.html#cluster-templates
23 """
24 @classmethod
Yaroslav Lobankovfa5a36e2014-07-01 15:24:55 +040025 @test.safe_setup
Yaroslav Lobankov436605b2014-04-24 18:42:54 +040026 def setUpClass(cls):
27 super(ClusterTemplateTest, cls).setUpClass()
28 # create node group template
29 node_group_template = {
30 'name': data_utils.rand_name('sahara-ng-template'),
31 'description': 'Test node group template',
32 'plugin_name': 'vanilla',
33 'hadoop_version': '1.2.1',
34 'node_processes': ['datanode'],
35 'flavor_id': cls.flavor_ref,
36 'node_configs': {
37 'HDFS': {
38 'Data Node Heap Size': 1024
39 }
40 }
41 }
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040042 resp_body = cls.create_node_group_template(**node_group_template)
Yaroslav Lobankovfa5a36e2014-07-01 15:24:55 +040043 node_group_template_id = resp_body['id']
Yaroslav Lobankov436605b2014-04-24 18:42:54 +040044
45 cls.full_cluster_template = {
46 'description': 'Test cluster template',
47 'plugin_name': 'vanilla',
48 'hadoop_version': '1.2.1',
49 'cluster_configs': {
50 'HDFS': {
51 'dfs.replication': 2
52 },
53 'MapReduce': {
54 'mapred.map.tasks.speculative.execution': False,
55 'mapred.child.java.opts': '-Xmx500m'
56 },
57 'general': {
58 'Enable Swift': False
59 }
60 },
61 'node_groups': [
62 {
63 'name': 'master-node',
64 'flavor_id': cls.flavor_ref,
65 'node_processes': ['namenode'],
66 'count': 1
67 },
68 {
69 'name': 'worker-node',
Yaroslav Lobankovfa5a36e2014-07-01 15:24:55 +040070 'node_group_template_id': node_group_template_id,
Yaroslav Lobankov436605b2014-04-24 18:42:54 +040071 'count': 3
72 }
73 ]
74 }
75 # create cls.cluster_template variable to use for comparison to cluster
76 # template response body. The 'node_groups' field in the response body
77 # has some extra info that post body does not have. The 'node_groups'
78 # field in the response body is something like this
79 #
80 # 'node_groups': [
81 # {
82 # 'count': 3,
83 # 'name': 'worker-node',
84 # 'volume_mount_prefix': '/volumes/disk',
85 # 'created_at': '2014-05-21 14:31:37',
86 # 'updated_at': None,
87 # 'floating_ip_pool': None,
88 # ...
89 # },
90 # ...
91 # ]
92 cls.cluster_template = cls.full_cluster_template.copy()
93 del cls.cluster_template['node_groups']
94
95 def _create_cluster_template(self, template_name=None):
96 """Creates Cluster Template with optional name specified.
97
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040098 It creates template, ensures template name and response body.
99 Returns id and name of created template.
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400100 """
101 if not template_name:
102 # generate random name if it's not specified
103 template_name = data_utils.rand_name('sahara-cluster-template')
104
105 # create cluster template
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400106 resp_body = self.create_cluster_template(template_name,
107 **self.full_cluster_template)
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400108
109 # ensure that template created successfully
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400110 self.assertEqual(template_name, resp_body['name'])
111 self.assertDictContainsSubset(self.cluster_template, resp_body)
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400112
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400113 return resp_body['id'], template_name
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400114
115 @test.attr(type='smoke')
116 def test_cluster_template_create(self):
117 self._create_cluster_template()
118
119 @test.attr(type='smoke')
120 def test_cluster_template_list(self):
121 template_info = self._create_cluster_template()
122
123 # check for cluster template in list
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400124 _, templates = self.client.list_cluster_templates()
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400125 templates_info = [(template['id'], template['name'])
126 for template in templates]
127 self.assertIn(template_info, templates_info)
128
129 @test.attr(type='smoke')
130 def test_cluster_template_get(self):
131 template_id, template_name = self._create_cluster_template()
132
133 # check cluster template fetch by id
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400134 _, template = self.client.get_cluster_template(template_id)
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400135 self.assertEqual(template_name, template['name'])
136 self.assertDictContainsSubset(self.cluster_template, template)
137
138 @test.attr(type='smoke')
139 def test_cluster_template_delete(self):
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400140 template_id, _ = self._create_cluster_template()
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400141
142 # delete the cluster template by id
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400143 self.client.delete_cluster_template(template_id)
Matthew Treinish57160582014-06-09 17:13:48 -0400144 # TODO(ylobankov): check that cluster template is really deleted