blob: e357a85df9b56d9605f77c0c12b17977aaae72a0 [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
Fei Long Wangd39431f2015-05-14 11:30:48 +120016from tempest.common.utils import data_utils
Luigi Toscanob61567a2015-03-11 18:35:33 +010017from tempest import exceptions
Yaroslav Lobankov436605b2014-04-24 18:42:54 +040018from tempest import test
19
20
21class ClusterTemplateTest(dp_base.BaseDataProcessingTest):
22 """Link to the API documentation is http://docs.openstack.org/developer/
23 sahara/restapi/rest_api_v1.0.html#cluster-templates
24 """
25 @classmethod
Luigi Toscanob61567a2015-03-11 18:35:33 +010026 def skip_checks(cls):
27 super(ClusterTemplateTest, cls).skip_checks()
28 if cls.default_plugin is None:
29 raise cls.skipException("No Sahara plugins configured")
30
31 @classmethod
Andrea Frittoli581c3932014-09-15 13:14:53 +010032 def resource_setup(cls):
33 super(ClusterTemplateTest, cls).resource_setup()
Yaroslav Lobankov436605b2014-04-24 18:42:54 +040034
Luigi Toscanob61567a2015-03-11 18:35:33 +010035 # pre-define a node group templates
36 node_group_template_w = cls.get_node_group_template('worker1')
37 if node_group_template_w is None:
38 raise exceptions.InvalidConfiguration(
39 message="No known Sahara plugin was found")
40
41 node_group_template_w['name'] = data_utils.rand_name(
42 'sahara-ng-template')
43 resp_body = cls.create_node_group_template(**node_group_template_w)
44 node_group_template_id = resp_body['id']
45 configured_node_group_templates = {'worker1': node_group_template_id}
46
47 cls.full_cluster_template = cls.get_cluster_template(
48 configured_node_group_templates)
49
Yaroslav Lobankov436605b2014-04-24 18:42:54 +040050 # create cls.cluster_template variable to use for comparison to cluster
51 # template response body. The 'node_groups' field in the response body
52 # has some extra info that post body does not have. The 'node_groups'
53 # field in the response body is something like this
54 #
55 # 'node_groups': [
56 # {
57 # 'count': 3,
58 # 'name': 'worker-node',
59 # 'volume_mount_prefix': '/volumes/disk',
60 # 'created_at': '2014-05-21 14:31:37',
61 # 'updated_at': None,
62 # 'floating_ip_pool': None,
63 # ...
64 # },
65 # ...
66 # ]
67 cls.cluster_template = cls.full_cluster_template.copy()
68 del cls.cluster_template['node_groups']
69
70 def _create_cluster_template(self, template_name=None):
71 """Creates Cluster Template with optional name specified.
72
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040073 It creates template, ensures template name and response body.
74 Returns id and name of created template.
Yaroslav Lobankov436605b2014-04-24 18:42:54 +040075 """
76 if not template_name:
77 # generate random name if it's not specified
78 template_name = data_utils.rand_name('sahara-cluster-template')
79
80 # create cluster template
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040081 resp_body = self.create_cluster_template(template_name,
82 **self.full_cluster_template)
Yaroslav Lobankov436605b2014-04-24 18:42:54 +040083
84 # ensure that template created successfully
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040085 self.assertEqual(template_name, resp_body['name'])
86 self.assertDictContainsSubset(self.cluster_template, resp_body)
Yaroslav Lobankov436605b2014-04-24 18:42:54 +040087
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040088 return resp_body['id'], template_name
Yaroslav Lobankov436605b2014-04-24 18:42:54 +040089
90 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080091 @test.idempotent_id('3525f1f1-3f9c-407d-891a-a996237e728b')
Yaroslav Lobankov436605b2014-04-24 18:42:54 +040092 def test_cluster_template_create(self):
93 self._create_cluster_template()
94
95 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080096 @test.idempotent_id('7a161882-e430-4840-a1c6-1d928201fab2')
Yaroslav Lobankov436605b2014-04-24 18:42:54 +040097 def test_cluster_template_list(self):
98 template_info = self._create_cluster_template()
99
100 # check for cluster template in list
David Kranz77f57202015-02-09 14:10:04 -0500101 templates = self.client.list_cluster_templates()
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400102 templates_info = [(template['id'], template['name'])
103 for template in templates]
104 self.assertIn(template_info, templates_info)
105
106 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800107 @test.idempotent_id('2b75fe22-f731-4b0f-84f1-89ab25f86637')
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400108 def test_cluster_template_get(self):
109 template_id, template_name = self._create_cluster_template()
110
111 # check cluster template fetch by id
David Kranz77f57202015-02-09 14:10:04 -0500112 template = self.client.get_cluster_template(template_id)
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400113 self.assertEqual(template_name, template['name'])
114 self.assertDictContainsSubset(self.cluster_template, template)
115
116 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800117 @test.idempotent_id('ff1fd989-171c-4dd7-91fd-9fbc71b09675')
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400118 def test_cluster_template_delete(self):
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400119 template_id, _ = self._create_cluster_template()
Yaroslav Lobankov436605b2014-04-24 18:42:54 +0400120
121 # delete the cluster template by id
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400122 self.client.delete_cluster_template(template_id)
Matthew Treinish57160582014-06-09 17:13:48 -0400123 # TODO(ylobankov): check that cluster template is really deleted