blob: 537f90c2f0a3e5514601e35ca599302f454ba285 [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
Andrea Frittoli581c3932014-09-15 13:14:53 +010025 def resource_setup(cls):
26 super(ClusterTemplateTest, cls).resource_setup()
Yaroslav Lobankov436605b2014-04-24 18:42:54 +040027 # create node group template
28 node_group_template = {
29 'name': data_utils.rand_name('sahara-ng-template'),
30 'description': 'Test node group template',
31 'plugin_name': 'vanilla',
32 'hadoop_version': '1.2.1',
33 'node_processes': ['datanode'],
34 'flavor_id': cls.flavor_ref,
35 'node_configs': {
36 'HDFS': {
37 'Data Node Heap Size': 1024
38 }
39 }
40 }
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040041 resp_body = cls.create_node_group_template(**node_group_template)
Yaroslav Lobankovfa5a36e2014-07-01 15:24:55 +040042 node_group_template_id = resp_body['id']
Yaroslav Lobankov436605b2014-04-24 18:42:54 +040043
44 cls.full_cluster_template = {
45 'description': 'Test cluster template',
46 'plugin_name': 'vanilla',
47 'hadoop_version': '1.2.1',
48 'cluster_configs': {
49 'HDFS': {
50 'dfs.replication': 2
51 },
52 'MapReduce': {
53 'mapred.map.tasks.speculative.execution': False,
54 'mapred.child.java.opts': '-Xmx500m'
55 },
56 'general': {
57 'Enable Swift': False
58 }
59 },
60 'node_groups': [
61 {
62 'name': 'master-node',
63 'flavor_id': cls.flavor_ref,
64 'node_processes': ['namenode'],
65 'count': 1
66 },
67 {
68 'name': 'worker-node',
Yaroslav Lobankovfa5a36e2014-07-01 15:24:55 +040069 'node_group_template_id': node_group_template_id,
Yaroslav Lobankov436605b2014-04-24 18:42:54 +040070 'count': 3
71 }
72 ]
73 }
74 # create cls.cluster_template variable to use for comparison to cluster
75 # template response body. The 'node_groups' field in the response body
76 # has some extra info that post body does not have. The 'node_groups'
77 # field in the response body is something like this
78 #
79 # 'node_groups': [
80 # {
81 # 'count': 3,
82 # 'name': 'worker-node',
83 # 'volume_mount_prefix': '/volumes/disk',
84 # 'created_at': '2014-05-21 14:31:37',
85 # 'updated_at': None,
86 # 'floating_ip_pool': None,
87 # ...
88 # },
89 # ...
90 # ]
91 cls.cluster_template = cls.full_cluster_template.copy()
92 del cls.cluster_template['node_groups']
93
94 def _create_cluster_template(self, template_name=None):
95 """Creates Cluster Template with optional name specified.
96
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040097 It creates template, ensures template name and response body.
98 Returns id and name of created template.
Yaroslav Lobankov436605b2014-04-24 18:42:54 +040099 """
100 if not template_name:
101 # generate random name if it's not specified
102 template_name = data_utils.rand_name('sahara-cluster-template')
103
104 # create cluster template
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400105 resp_body = self.create_cluster_template(template_name,
106 **self.full_cluster_template)
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400107
108 # ensure that template created successfully
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400109 self.assertEqual(template_name, resp_body['name'])
110 self.assertDictContainsSubset(self.cluster_template, resp_body)
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400111
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400112 return resp_body['id'], template_name
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400113
114 @test.attr(type='smoke')
115 def test_cluster_template_create(self):
116 self._create_cluster_template()
117
118 @test.attr(type='smoke')
119 def test_cluster_template_list(self):
120 template_info = self._create_cluster_template()
121
122 # check for cluster template in list
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400123 _, templates = self.client.list_cluster_templates()
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400124 templates_info = [(template['id'], template['name'])
125 for template in templates]
126 self.assertIn(template_info, templates_info)
127
128 @test.attr(type='smoke')
129 def test_cluster_template_get(self):
130 template_id, template_name = self._create_cluster_template()
131
132 # check cluster template fetch by id
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400133 _, template = self.client.get_cluster_template(template_id)
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400134 self.assertEqual(template_name, template['name'])
135 self.assertDictContainsSubset(self.cluster_template, template)
136
137 @test.attr(type='smoke')
138 def test_cluster_template_delete(self):
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400139 template_id, _ = self._create_cluster_template()
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400140
141 # delete the cluster template by id
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400142 self.client.delete_cluster_template(template_id)
Matthew Treinish57160582014-06-09 17:13:48 -0400143 # TODO(ylobankov): check that cluster template is really deleted