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 = [] |
Yaroslav Lobankov | 4267bcc | 2014-04-25 13:25:03 +0400 | [diff] [blame] | 41 | cls._data_sources = [] |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 42 | |
| 43 | @classmethod |
| 44 | def tearDownClass(cls): |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 45 | cls.cleanup_resources(getattr(cls, '_cluster_templates', []), |
| 46 | cls.client.delete_cluster_template) |
| 47 | cls.cleanup_resources(getattr(cls, '_node_group_templates', []), |
| 48 | cls.client.delete_node_group_template) |
Yaroslav Lobankov | 4267bcc | 2014-04-25 13:25:03 +0400 | [diff] [blame] | 49 | cls.cleanup_resources(getattr(cls, '_data_sources', []), |
| 50 | cls.client.delete_data_source) |
Matthew Treinish | 92dae93 | 2014-01-31 16:43:32 +0000 | [diff] [blame] | 51 | cls.clear_isolated_creds() |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 52 | super(BaseDataProcessingTest, cls).tearDownClass() |
| 53 | |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 54 | @staticmethod |
| 55 | def cleanup_resources(resource_id_list, method): |
| 56 | for resource_id in resource_id_list: |
| 57 | try: |
| 58 | method(resource_id) |
| 59 | except exceptions.NotFound: |
| 60 | # ignore errors while auto removing created resource |
| 61 | pass |
| 62 | |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 63 | @classmethod |
| 64 | def create_node_group_template(cls, name, plugin_name, hadoop_version, |
| 65 | node_processes, flavor_id, |
| 66 | node_configs=None, **kwargs): |
| 67 | """Creates watched node group template with specified params. |
| 68 | |
| 69 | It supports passing additional params using kwargs and returns created |
| 70 | object. All resources created in this method will be automatically |
| 71 | removed in tearDownClass method. |
| 72 | """ |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 73 | resp, body = cls.client.create_node_group_template(name, plugin_name, |
| 74 | hadoop_version, |
| 75 | node_processes, |
| 76 | flavor_id, |
| 77 | node_configs, |
| 78 | **kwargs) |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 79 | # store id of created node group template |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 80 | cls._node_group_templates.append(body['id']) |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 81 | |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 82 | return resp, body |
| 83 | |
| 84 | @classmethod |
| 85 | def create_cluster_template(cls, name, plugin_name, hadoop_version, |
| 86 | node_groups, cluster_configs=None, **kwargs): |
| 87 | """Creates watched cluster template with specified params. |
| 88 | |
| 89 | It supports passing additional params using kwargs and returns created |
| 90 | object. All resources created in this method will be automatically |
| 91 | removed in tearDownClass method. |
| 92 | """ |
| 93 | resp, body = cls.client.create_cluster_template(name, plugin_name, |
| 94 | hadoop_version, |
| 95 | node_groups, |
| 96 | cluster_configs, |
| 97 | **kwargs) |
| 98 | # store id of created cluster template |
| 99 | cls._cluster_templates.append(body['id']) |
| 100 | |
| 101 | return resp, body |
Yaroslav Lobankov | 4267bcc | 2014-04-25 13:25:03 +0400 | [diff] [blame] | 102 | |
| 103 | @classmethod |
| 104 | def create_data_source(cls, name, type, url, **kwargs): |
| 105 | """Creates watched data source with specified params. |
| 106 | |
| 107 | It supports passing additional params using kwargs and returns created |
| 108 | object. All resources created in this method will be automatically |
| 109 | removed in tearDownClass method. |
| 110 | """ |
| 111 | resp, body = cls.client.create_data_source(name, type, url, **kwargs) |
| 112 | # store id of created data source |
| 113 | cls._data_sources.append(body['id']) |
| 114 | |
| 115 | return resp, body |