Yaroslav Lobankov | 18544b0 | 2014-04-24 20:17:49 +0400 | [diff] [blame] | 1 | # Copyright (c) 2014 Mirantis Inc. |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 2 | # |
Yaroslav Lobankov | 18544b0 | 2014-04-24 20:17:49 +0400 | [diff] [blame] | 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 |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 6 | # |
Yaroslav Lobankov | 18544b0 | 2014-04-24 20:17:49 +0400 | [diff] [blame] | 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 8 | # |
Yaroslav Lobankov | 18544b0 | 2014-04-24 20:17:49 +0400 | [diff] [blame] | 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. |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 14 | |
| 15 | from tempest import config |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 16 | from tempest import exceptions |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 17 | import tempest.test |
| 18 | |
| 19 | |
| 20 | CONF = config.CONF |
| 21 | |
| 22 | |
| 23 | class BaseDataProcessingTest(tempest.test.BaseTestCase): |
| 24 | _interface = 'json' |
| 25 | |
| 26 | @classmethod |
| 27 | def setUpClass(cls): |
| 28 | super(BaseDataProcessingTest, cls).setUpClass() |
Sergey Lukjanov | 9c95a25 | 2014-03-13 23:59:22 +0400 | [diff] [blame] | 29 | if not CONF.service_available.sahara: |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 30 | raise cls.skipException('Sahara support is required') |
Zhi Kun Liu | 2259c97 | 2014-03-27 02:11:10 -0500 | [diff] [blame] | 31 | |
Yaroslav Lobankov | 7287677 | 2014-06-11 16:18:19 +0400 | [diff] [blame] | 32 | cls.os = cls.get_client_manager() |
| 33 | cls.client = cls.os.data_processing_client |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 34 | |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 35 | cls.flavor_ref = CONF.compute.flavor_ref |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 36 | |
| 37 | # add lists for watched resources |
| 38 | cls._node_group_templates = [] |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 39 | cls._cluster_templates = [] |
Yaroslav Lobankov | 4267bcc | 2014-04-25 13:25:03 +0400 | [diff] [blame] | 40 | cls._data_sources = [] |
Yaroslav Lobankov | d5dcf19 | 2014-05-21 13:58:10 +0400 | [diff] [blame] | 41 | cls._job_binary_internals = [] |
Yaroslav Lobankov | 74c923b | 2014-05-21 13:13:07 +0400 | [diff] [blame] | 42 | cls._job_binaries = [] |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 43 | |
| 44 | @classmethod |
| 45 | def tearDownClass(cls): |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 46 | cls.cleanup_resources(getattr(cls, '_cluster_templates', []), |
| 47 | cls.client.delete_cluster_template) |
| 48 | cls.cleanup_resources(getattr(cls, '_node_group_templates', []), |
| 49 | cls.client.delete_node_group_template) |
Yaroslav Lobankov | 4267bcc | 2014-04-25 13:25:03 +0400 | [diff] [blame] | 50 | cls.cleanup_resources(getattr(cls, '_data_sources', []), |
| 51 | cls.client.delete_data_source) |
Yaroslav Lobankov | d5dcf19 | 2014-05-21 13:58:10 +0400 | [diff] [blame] | 52 | cls.cleanup_resources(getattr(cls, '_job_binary_internals', []), |
| 53 | cls.client.delete_job_binary_internal) |
Yaroslav Lobankov | 74c923b | 2014-05-21 13:13:07 +0400 | [diff] [blame] | 54 | cls.cleanup_resources(getattr(cls, '_job_binaries', []), |
| 55 | cls.client.delete_job_binary) |
Matthew Treinish | 92dae93 | 2014-01-31 16:43:32 +0000 | [diff] [blame] | 56 | cls.clear_isolated_creds() |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 57 | super(BaseDataProcessingTest, cls).tearDownClass() |
| 58 | |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 59 | @staticmethod |
| 60 | def cleanup_resources(resource_id_list, method): |
| 61 | for resource_id in resource_id_list: |
| 62 | try: |
| 63 | method(resource_id) |
| 64 | except exceptions.NotFound: |
| 65 | # ignore errors while auto removing created resource |
| 66 | pass |
| 67 | |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 68 | @classmethod |
| 69 | def create_node_group_template(cls, name, plugin_name, hadoop_version, |
| 70 | node_processes, flavor_id, |
| 71 | node_configs=None, **kwargs): |
| 72 | """Creates watched node group template with specified params. |
| 73 | |
| 74 | It supports passing additional params using kwargs and returns created |
| 75 | object. All resources created in this method will be automatically |
| 76 | removed in tearDownClass method. |
| 77 | """ |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 78 | resp, body = cls.client.create_node_group_template(name, plugin_name, |
| 79 | hadoop_version, |
| 80 | node_processes, |
| 81 | flavor_id, |
| 82 | node_configs, |
| 83 | **kwargs) |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 84 | # store id of created node group template |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 85 | cls._node_group_templates.append(body['id']) |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 86 | |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 87 | return resp, body |
| 88 | |
| 89 | @classmethod |
| 90 | def create_cluster_template(cls, name, plugin_name, hadoop_version, |
| 91 | node_groups, cluster_configs=None, **kwargs): |
| 92 | """Creates watched cluster template with specified params. |
| 93 | |
| 94 | It supports passing additional params using kwargs and returns created |
| 95 | object. All resources created in this method will be automatically |
| 96 | removed in tearDownClass method. |
| 97 | """ |
| 98 | resp, body = cls.client.create_cluster_template(name, plugin_name, |
| 99 | hadoop_version, |
| 100 | node_groups, |
| 101 | cluster_configs, |
| 102 | **kwargs) |
| 103 | # store id of created cluster template |
| 104 | cls._cluster_templates.append(body['id']) |
| 105 | |
| 106 | return resp, body |
Yaroslav Lobankov | 4267bcc | 2014-04-25 13:25:03 +0400 | [diff] [blame] | 107 | |
| 108 | @classmethod |
| 109 | def create_data_source(cls, name, type, url, **kwargs): |
| 110 | """Creates watched data source with specified params. |
| 111 | |
| 112 | It supports passing additional params using kwargs and returns created |
| 113 | object. All resources created in this method will be automatically |
| 114 | removed in tearDownClass method. |
| 115 | """ |
| 116 | resp, body = cls.client.create_data_source(name, type, url, **kwargs) |
| 117 | # store id of created data source |
| 118 | cls._data_sources.append(body['id']) |
| 119 | |
| 120 | return resp, body |
Yaroslav Lobankov | d5dcf19 | 2014-05-21 13:58:10 +0400 | [diff] [blame] | 121 | |
| 122 | @classmethod |
| 123 | def create_job_binary_internal(cls, name, data): |
| 124 | """Creates watched job binary internal with specified params. |
| 125 | |
| 126 | It returns created object. All resources created in this method will |
| 127 | be automatically removed in tearDownClass method. |
| 128 | """ |
| 129 | resp, body = cls.client.create_job_binary_internal(name, data) |
| 130 | # store id of created job binary internal |
| 131 | cls._job_binary_internals.append(body['id']) |
| 132 | |
| 133 | return resp, body |
Yaroslav Lobankov | 74c923b | 2014-05-21 13:13:07 +0400 | [diff] [blame] | 134 | |
| 135 | def create_job_binary(cls, name, url, extra=None, **kwargs): |
| 136 | """Creates watched job binary with specified params. |
| 137 | |
| 138 | It supports passing additional params using kwargs and returns created |
| 139 | object. All resources created in this method will be automatically |
| 140 | removed in tearDownClass method. |
| 141 | """ |
| 142 | resp, body = cls.client.create_job_binary(name, url, extra, **kwargs) |
| 143 | # store id of created job binary |
| 144 | cls._job_binaries.append(body['id']) |
| 145 | |
| 146 | return resp, body |