Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 1 | # Copyright (c) 2013 Mirantis Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain 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, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 12 | # implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | from tempest import config |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 17 | from tempest import exceptions |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 18 | import tempest.test |
| 19 | |
| 20 | |
| 21 | CONF = config.CONF |
| 22 | |
| 23 | |
| 24 | class BaseDataProcessingTest(tempest.test.BaseTestCase): |
| 25 | _interface = 'json' |
| 26 | |
| 27 | @classmethod |
| 28 | def setUpClass(cls): |
| 29 | super(BaseDataProcessingTest, cls).setUpClass() |
Sergey Lukjanov | 9c95a25 | 2014-03-13 23:59:22 +0400 | [diff] [blame] | 30 | if not CONF.service_available.sahara: |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 31 | raise cls.skipException('Sahara support is required') |
Zhi Kun Liu | 2259c97 | 2014-03-27 02:11:10 -0500 | [diff] [blame] | 32 | |
| 33 | os = cls.get_client_manager() |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 34 | cls.client = os.data_processing_client |
| 35 | |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 36 | cls.flavor_ref = CONF.compute.flavor_ref |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 37 | |
| 38 | # add lists for watched resources |
| 39 | cls._node_group_templates = [] |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 40 | cls._cluster_templates = [] |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 41 | |
| 42 | @classmethod |
| 43 | def tearDownClass(cls): |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 44 | cls.cleanup_resources(getattr(cls, '_cluster_templates', []), |
| 45 | cls.client.delete_cluster_template) |
| 46 | cls.cleanup_resources(getattr(cls, '_node_group_templates', []), |
| 47 | cls.client.delete_node_group_template) |
Matthew Treinish | 92dae93 | 2014-01-31 16:43:32 +0000 | [diff] [blame] | 48 | cls.clear_isolated_creds() |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 49 | super(BaseDataProcessingTest, cls).tearDownClass() |
| 50 | |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 51 | @staticmethod |
| 52 | def cleanup_resources(resource_id_list, method): |
| 53 | for resource_id in resource_id_list: |
| 54 | try: |
| 55 | method(resource_id) |
| 56 | except exceptions.NotFound: |
| 57 | # ignore errors while auto removing created resource |
| 58 | pass |
| 59 | |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 60 | @classmethod |
| 61 | def create_node_group_template(cls, name, plugin_name, hadoop_version, |
| 62 | node_processes, flavor_id, |
| 63 | node_configs=None, **kwargs): |
| 64 | """Creates watched node group template with specified params. |
| 65 | |
| 66 | It supports passing additional params using kwargs and returns created |
| 67 | object. All resources created in this method will be automatically |
| 68 | removed in tearDownClass method. |
| 69 | """ |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 70 | resp, body = cls.client.create_node_group_template(name, plugin_name, |
| 71 | hadoop_version, |
| 72 | node_processes, |
| 73 | flavor_id, |
| 74 | node_configs, |
| 75 | **kwargs) |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 76 | # store id of created node group template |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 77 | cls._node_group_templates.append(body['id']) |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 78 | |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 79 | return resp, body |
| 80 | |
| 81 | @classmethod |
| 82 | def create_cluster_template(cls, name, plugin_name, hadoop_version, |
| 83 | node_groups, cluster_configs=None, **kwargs): |
| 84 | """Creates watched cluster template with specified params. |
| 85 | |
| 86 | It supports passing additional params using kwargs and returns created |
| 87 | object. All resources created in this method will be automatically |
| 88 | removed in tearDownClass method. |
| 89 | """ |
| 90 | resp, body = cls.client.create_cluster_template(name, plugin_name, |
| 91 | hadoop_version, |
| 92 | node_groups, |
| 93 | cluster_configs, |
| 94 | **kwargs) |
| 95 | # store id of created cluster template |
| 96 | cls._cluster_templates.append(body['id']) |
| 97 | |
| 98 | return resp, body |