blob: e5c63038f0f0a1051dcfd0eaa1dd19574bd1276d [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
25 def setUpClass(cls):
26 super(ClusterTemplateTest, cls).setUpClass()
27 # 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 }
41 resp_body = cls.create_node_group_template(**node_group_template)[1]
42
43 cls.full_cluster_template = {
44 'description': 'Test cluster template',
45 'plugin_name': 'vanilla',
46 'hadoop_version': '1.2.1',
47 'cluster_configs': {
48 'HDFS': {
49 'dfs.replication': 2
50 },
51 'MapReduce': {
52 'mapred.map.tasks.speculative.execution': False,
53 'mapred.child.java.opts': '-Xmx500m'
54 },
55 'general': {
56 'Enable Swift': False
57 }
58 },
59 'node_groups': [
60 {
61 'name': 'master-node',
62 'flavor_id': cls.flavor_ref,
63 'node_processes': ['namenode'],
64 'count': 1
65 },
66 {
67 'name': 'worker-node',
68 'node_group_template_id': resp_body['id'],
69 'count': 3
70 }
71 ]
72 }
73 # create cls.cluster_template variable to use for comparison to cluster
74 # template response body. The 'node_groups' field in the response body
75 # has some extra info that post body does not have. The 'node_groups'
76 # field in the response body is something like this
77 #
78 # 'node_groups': [
79 # {
80 # 'count': 3,
81 # 'name': 'worker-node',
82 # 'volume_mount_prefix': '/volumes/disk',
83 # 'created_at': '2014-05-21 14:31:37',
84 # 'updated_at': None,
85 # 'floating_ip_pool': None,
86 # ...
87 # },
88 # ...
89 # ]
90 cls.cluster_template = cls.full_cluster_template.copy()
91 del cls.cluster_template['node_groups']
92
93 def _create_cluster_template(self, template_name=None):
94 """Creates Cluster Template with optional name specified.
95
96 It creates template and ensures response status, template name and
97 response body. Returns id and name of created template.
98 """
99 if not template_name:
100 # generate random name if it's not specified
101 template_name = data_utils.rand_name('sahara-cluster-template')
102
103 # create cluster template
104 resp, body = self.create_cluster_template(template_name,
105 **self.full_cluster_template)
106
107 # ensure that template created successfully
108 self.assertEqual(202, resp.status)
109 self.assertEqual(template_name, body['name'])
110 self.assertDictContainsSubset(self.cluster_template, body)
111
112 return body['id'], template_name
113
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
123 resp, templates = self.client.list_cluster_templates()
124 self.assertEqual(200, resp.status)
125 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
134 resp, template = self.client.get_cluster_template(template_id)
135 self.assertEqual(200, resp.status)
136 self.assertEqual(template_name, template['name'])
137 self.assertDictContainsSubset(self.cluster_template, template)
138
139 @test.attr(type='smoke')
140 def test_cluster_template_delete(self):
141 template_id = self._create_cluster_template()[0]
142
143 # delete the cluster template by id
144 resp = self.client.delete_cluster_template(template_id)[0]
145 self.assertEqual(204, resp.status)
Matthew Treinish57160582014-06-09 17:13:48 -0400146 # TODO(ylobankov): check that cluster template is really deleted