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 |
| 16 | from tempest.common.utils import data_utils |
| 17 | from tempest import test |
| 18 | |
| 19 | |
| 20 | class 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 Lobankov | fa5a36e | 2014-07-01 15:24:55 +0400 | [diff] [blame^] | 25 | @test.safe_setup |
Yaroslav Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 26 | 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 | } |
| 42 | resp_body = cls.create_node_group_template(**node_group_template)[1] |
Yaroslav Lobankov | fa5a36e | 2014-07-01 15:24:55 +0400 | [diff] [blame^] | 43 | node_group_template_id = resp_body['id'] |
Yaroslav Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 44 | |
| 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 Lobankov | fa5a36e | 2014-07-01 15:24:55 +0400 | [diff] [blame^] | 70 | 'node_group_template_id': node_group_template_id, |
Yaroslav Lobankov | 436605b | 2014-04-24 18:42:54 +0400 | [diff] [blame] | 71 | '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 | |
| 98 | It creates template and ensures response status, template name and |
| 99 | response body. Returns id and name of created template. |
| 100 | """ |
| 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 |
| 106 | resp, body = self.create_cluster_template(template_name, |
| 107 | **self.full_cluster_template) |
| 108 | |
| 109 | # ensure that template created successfully |
| 110 | self.assertEqual(202, resp.status) |
| 111 | self.assertEqual(template_name, body['name']) |
| 112 | self.assertDictContainsSubset(self.cluster_template, body) |
| 113 | |
| 114 | return body['id'], template_name |
| 115 | |
| 116 | @test.attr(type='smoke') |
| 117 | def test_cluster_template_create(self): |
| 118 | self._create_cluster_template() |
| 119 | |
| 120 | @test.attr(type='smoke') |
| 121 | def test_cluster_template_list(self): |
| 122 | template_info = self._create_cluster_template() |
| 123 | |
| 124 | # check for cluster template in list |
| 125 | resp, templates = self.client.list_cluster_templates() |
| 126 | self.assertEqual(200, resp.status) |
| 127 | templates_info = [(template['id'], template['name']) |
| 128 | for template in templates] |
| 129 | self.assertIn(template_info, templates_info) |
| 130 | |
| 131 | @test.attr(type='smoke') |
| 132 | def test_cluster_template_get(self): |
| 133 | template_id, template_name = self._create_cluster_template() |
| 134 | |
| 135 | # check cluster template fetch by id |
| 136 | resp, template = self.client.get_cluster_template(template_id) |
| 137 | self.assertEqual(200, resp.status) |
| 138 | self.assertEqual(template_name, template['name']) |
| 139 | self.assertDictContainsSubset(self.cluster_template, template) |
| 140 | |
| 141 | @test.attr(type='smoke') |
| 142 | def test_cluster_template_delete(self): |
| 143 | template_id = self._create_cluster_template()[0] |
| 144 | |
| 145 | # delete the cluster template by id |
| 146 | resp = self.client.delete_cluster_template(template_id)[0] |
| 147 | self.assertEqual(204, resp.status) |
Matthew Treinish | 5716058 | 2014-06-09 17:13:48 -0400 | [diff] [blame] | 148 | # TODO(ylobankov): check that cluster template is really deleted |