Yaroslav Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 1 | # 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 | |
| 15 | from tempest.api.data_processing import base as dp_base |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 16 | from tempest.common.utils import data_utils |
Luigi Toscano | b61567a | 2015-03-11 18:35:33 +0100 | [diff] [blame] | 17 | from tempest import exceptions |
Yaroslav Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 18 | from tempest import test |
| 19 | |
| 20 | |
| 21 | class 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 Toscano | b61567a | 2015-03-11 18:35:33 +0100 | [diff] [blame] | 26 | 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 Frittoli | 581c393 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 32 | def resource_setup(cls): |
| 33 | super(ClusterTemplateTest, cls).resource_setup() |
Yaroslav Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 34 | |
Luigi Toscano | b61567a | 2015-03-11 18:35:33 +0100 | [diff] [blame] | 35 | # 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 Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 50 | # 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 Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 73 | It creates template, ensures template name and response body. |
| 74 | Returns id and name of created template. |
Yaroslav Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 75 | """ |
| 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 Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 81 | resp_body = self.create_cluster_template(template_name, |
| 82 | **self.full_cluster_template) |
Yaroslav Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 83 | |
| 84 | # ensure that template created successfully |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 85 | self.assertEqual(template_name, resp_body['name']) |
| 86 | self.assertDictContainsSubset(self.cluster_template, resp_body) |
Yaroslav Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 87 | |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 88 | return resp_body['id'], template_name |
Yaroslav Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 89 | |
| 90 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 91 | @test.idempotent_id('3525f1f1-3f9c-407d-891a-a996237e728b') |
Yaroslav Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 92 | def test_cluster_template_create(self): |
| 93 | self._create_cluster_template() |
| 94 | |
| 95 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 96 | @test.idempotent_id('7a161882-e430-4840-a1c6-1d928201fab2') |
Yaroslav Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 97 | def test_cluster_template_list(self): |
| 98 | template_info = self._create_cluster_template() |
| 99 | |
| 100 | # check for cluster template in list |
David Kranz | 77f5720 | 2015-02-09 14:10:04 -0500 | [diff] [blame] | 101 | templates = self.client.list_cluster_templates() |
Yaroslav Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 102 | 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 Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 107 | @test.idempotent_id('2b75fe22-f731-4b0f-84f1-89ab25f86637') |
Yaroslav Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 108 | def test_cluster_template_get(self): |
| 109 | template_id, template_name = self._create_cluster_template() |
| 110 | |
| 111 | # check cluster template fetch by id |
David Kranz | 77f5720 | 2015-02-09 14:10:04 -0500 | [diff] [blame] | 112 | template = self.client.get_cluster_template(template_id) |
Yaroslav Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 113 | self.assertEqual(template_name, template['name']) |
| 114 | self.assertDictContainsSubset(self.cluster_template, template) |
| 115 | |
| 116 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 117 | @test.idempotent_id('ff1fd989-171c-4dd7-91fd-9fbc71b09675') |
Yaroslav Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 118 | def test_cluster_template_delete(self): |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 119 | template_id, _ = self._create_cluster_template() |
Yaroslav Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 120 | |
| 121 | # delete the cluster template by id |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 122 | self.client.delete_cluster_template(template_id) |
Matthew Treinish | 5716058 | 2014-06-09 17:13:48 -0400 | [diff] [blame] | 123 | # TODO(ylobankov): check that cluster template is really deleted |