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 |
Andrea Frittoli | 581c393 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 27 | def resource_setup(cls): |
| 28 | super(BaseDataProcessingTest, cls).resource_setup() |
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 = [] |
Yaroslav Lobankov | c04ae23 | 2014-07-04 16:13:55 +0400 | [diff] [blame] | 43 | cls._jobs = [] |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 44 | |
| 45 | @classmethod |
Andrea Frittoli | 581c393 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 46 | def resource_cleanup(cls): |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 47 | cls.cleanup_resources(getattr(cls, '_cluster_templates', []), |
| 48 | cls.client.delete_cluster_template) |
| 49 | cls.cleanup_resources(getattr(cls, '_node_group_templates', []), |
| 50 | cls.client.delete_node_group_template) |
Yaroslav Lobankov | c04ae23 | 2014-07-04 16:13:55 +0400 | [diff] [blame] | 51 | cls.cleanup_resources(getattr(cls, '_jobs', []), cls.client.delete_job) |
Yaroslav Lobankov | 74c923b | 2014-05-21 13:13:07 +0400 | [diff] [blame] | 52 | cls.cleanup_resources(getattr(cls, '_job_binaries', []), |
| 53 | cls.client.delete_job_binary) |
Yaroslav Lobankov | c04ae23 | 2014-07-04 16:13:55 +0400 | [diff] [blame] | 54 | cls.cleanup_resources(getattr(cls, '_job_binary_internals', []), |
| 55 | cls.client.delete_job_binary_internal) |
| 56 | cls.cleanup_resources(getattr(cls, '_data_sources', []), |
| 57 | cls.client.delete_data_source) |
Matthew Treinish | 92dae93 | 2014-01-31 16:43:32 +0000 | [diff] [blame] | 58 | cls.clear_isolated_creds() |
Andrea Frittoli | 581c393 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 59 | super(BaseDataProcessingTest, cls).resource_cleanup() |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 60 | |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 61 | @staticmethod |
| 62 | def cleanup_resources(resource_id_list, method): |
| 63 | for resource_id in resource_id_list: |
| 64 | try: |
| 65 | method(resource_id) |
| 66 | except exceptions.NotFound: |
| 67 | # ignore errors while auto removing created resource |
| 68 | pass |
| 69 | |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 70 | @classmethod |
| 71 | def create_node_group_template(cls, name, plugin_name, hadoop_version, |
| 72 | node_processes, flavor_id, |
| 73 | node_configs=None, **kwargs): |
| 74 | """Creates watched node group template with specified params. |
| 75 | |
| 76 | It supports passing additional params using kwargs and returns created |
| 77 | object. All resources created in this method will be automatically |
| 78 | removed in tearDownClass method. |
| 79 | """ |
David Kranz | 77f5720 | 2015-02-09 14:10:04 -0500 | [diff] [blame^] | 80 | resp_body = cls.client.create_node_group_template(name, plugin_name, |
| 81 | hadoop_version, |
| 82 | node_processes, |
| 83 | flavor_id, |
| 84 | node_configs, |
| 85 | **kwargs) |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 86 | # store id of created node group template |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 87 | cls._node_group_templates.append(resp_body['id']) |
Sergey Lukjanov | 03c95c8 | 2013-12-10 16:42:37 +0400 | [diff] [blame] | 88 | |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 89 | return resp_body |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 90 | |
| 91 | @classmethod |
| 92 | def create_cluster_template(cls, name, plugin_name, hadoop_version, |
| 93 | node_groups, cluster_configs=None, **kwargs): |
| 94 | """Creates watched cluster template with specified params. |
| 95 | |
| 96 | It supports passing additional params using kwargs and returns created |
| 97 | object. All resources created in this method will be automatically |
| 98 | removed in tearDownClass method. |
| 99 | """ |
David Kranz | 77f5720 | 2015-02-09 14:10:04 -0500 | [diff] [blame^] | 100 | resp_body = cls.client.create_cluster_template(name, plugin_name, |
| 101 | hadoop_version, |
| 102 | node_groups, |
| 103 | cluster_configs, |
| 104 | **kwargs) |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 105 | # store id of created cluster template |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 106 | cls._cluster_templates.append(resp_body['id']) |
Yaroslav Lobankov | 93aa819 | 2014-04-01 20:03:25 +0400 | [diff] [blame] | 107 | |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 108 | return resp_body |
Yaroslav Lobankov | 4267bcc | 2014-04-25 13:25:03 +0400 | [diff] [blame] | 109 | |
| 110 | @classmethod |
| 111 | def create_data_source(cls, name, type, url, **kwargs): |
| 112 | """Creates watched data source with specified params. |
| 113 | |
| 114 | It supports passing additional params using kwargs and returns created |
| 115 | object. All resources created in this method will be automatically |
| 116 | removed in tearDownClass method. |
| 117 | """ |
David Kranz | 77f5720 | 2015-02-09 14:10:04 -0500 | [diff] [blame^] | 118 | resp_body = cls.client.create_data_source(name, type, url, **kwargs) |
Yaroslav Lobankov | 4267bcc | 2014-04-25 13:25:03 +0400 | [diff] [blame] | 119 | # store id of created data source |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 120 | cls._data_sources.append(resp_body['id']) |
Yaroslav Lobankov | 4267bcc | 2014-04-25 13:25:03 +0400 | [diff] [blame] | 121 | |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 122 | return resp_body |
Yaroslav Lobankov | d5dcf19 | 2014-05-21 13:58:10 +0400 | [diff] [blame] | 123 | |
| 124 | @classmethod |
| 125 | def create_job_binary_internal(cls, name, data): |
| 126 | """Creates watched job binary internal with specified params. |
| 127 | |
| 128 | It returns created object. All resources created in this method will |
| 129 | be automatically removed in tearDownClass method. |
| 130 | """ |
David Kranz | 77f5720 | 2015-02-09 14:10:04 -0500 | [diff] [blame^] | 131 | resp_body = cls.client.create_job_binary_internal(name, data) |
Yaroslav Lobankov | d5dcf19 | 2014-05-21 13:58:10 +0400 | [diff] [blame] | 132 | # store id of created job binary internal |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 133 | cls._job_binary_internals.append(resp_body['id']) |
Yaroslav Lobankov | d5dcf19 | 2014-05-21 13:58:10 +0400 | [diff] [blame] | 134 | |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 135 | return resp_body |
Yaroslav Lobankov | 74c923b | 2014-05-21 13:13:07 +0400 | [diff] [blame] | 136 | |
Yaroslav Lobankov | c04ae23 | 2014-07-04 16:13:55 +0400 | [diff] [blame] | 137 | @classmethod |
Yaroslav Lobankov | 74c923b | 2014-05-21 13:13:07 +0400 | [diff] [blame] | 138 | def create_job_binary(cls, name, url, extra=None, **kwargs): |
| 139 | """Creates watched job binary with specified params. |
| 140 | |
| 141 | It supports passing additional params using kwargs and returns created |
| 142 | object. All resources created in this method will be automatically |
| 143 | removed in tearDownClass method. |
| 144 | """ |
David Kranz | 77f5720 | 2015-02-09 14:10:04 -0500 | [diff] [blame^] | 145 | resp_body = cls.client.create_job_binary(name, url, extra, **kwargs) |
Yaroslav Lobankov | 74c923b | 2014-05-21 13:13:07 +0400 | [diff] [blame] | 146 | # store id of created job binary |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 147 | cls._job_binaries.append(resp_body['id']) |
Yaroslav Lobankov | 74c923b | 2014-05-21 13:13:07 +0400 | [diff] [blame] | 148 | |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 149 | return resp_body |
Yaroslav Lobankov | c04ae23 | 2014-07-04 16:13:55 +0400 | [diff] [blame] | 150 | |
| 151 | @classmethod |
| 152 | def create_job(cls, name, job_type, mains, libs=None, **kwargs): |
| 153 | """Creates watched job with specified params. |
| 154 | |
| 155 | It supports passing additional params using kwargs and returns created |
| 156 | object. All resources created in this method will be automatically |
| 157 | removed in tearDownClass method. |
| 158 | """ |
David Kranz | 77f5720 | 2015-02-09 14:10:04 -0500 | [diff] [blame^] | 159 | resp_body = cls.client.create_job(name, |
| 160 | job_type, mains, libs, **kwargs) |
Yaroslav Lobankov | c04ae23 | 2014-07-04 16:13:55 +0400 | [diff] [blame] | 161 | # store id of created job |
| 162 | cls._jobs.append(resp_body['id']) |
| 163 | |
| 164 | return resp_body |