blob: 45c8488103fbaa7ff0ba9828e467415cf9882ea6 [file] [log] [blame]
Yaroslav Lobankov18544b02014-04-24 20:17:49 +04001# Copyright (c) 2014 Mirantis Inc.
Sergey Lukjanov03c95c82013-12-10 16:42:37 +04002#
Yaroslav Lobankov18544b02014-04-24 20:17:49 +04003# 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 Lukjanov03c95c82013-12-10 16:42:37 +04006#
Yaroslav Lobankov18544b02014-04-24 20:17:49 +04007# http://www.apache.org/licenses/LICENSE-2.0
Sergey Lukjanov03c95c82013-12-10 16:42:37 +04008#
Yaroslav Lobankov18544b02014-04-24 20:17:49 +04009# 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 Lukjanov03c95c82013-12-10 16:42:37 +040014
15from tempest import config
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040016from tempest import exceptions
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040017import tempest.test
18
19
20CONF = config.CONF
21
22
23class BaseDataProcessingTest(tempest.test.BaseTestCase):
24 _interface = 'json'
25
26 @classmethod
Andrea Frittoli581c3932014-09-15 13:14:53 +010027 def resource_setup(cls):
28 super(BaseDataProcessingTest, cls).resource_setup()
Sergey Lukjanov9c95a252014-03-13 23:59:22 +040029 if not CONF.service_available.sahara:
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040030 raise cls.skipException('Sahara support is required')
Zhi Kun Liu2259c972014-03-27 02:11:10 -050031
Yaroslav Lobankov72876772014-06-11 16:18:19 +040032 cls.os = cls.get_client_manager()
33 cls.client = cls.os.data_processing_client
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040034
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040035 cls.flavor_ref = CONF.compute.flavor_ref
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040036
37 # add lists for watched resources
38 cls._node_group_templates = []
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040039 cls._cluster_templates = []
Yaroslav Lobankov4267bcc2014-04-25 13:25:03 +040040 cls._data_sources = []
Yaroslav Lobankovd5dcf192014-05-21 13:58:10 +040041 cls._job_binary_internals = []
Yaroslav Lobankov74c923b2014-05-21 13:13:07 +040042 cls._job_binaries = []
Yaroslav Lobankovc04ae232014-07-04 16:13:55 +040043 cls._jobs = []
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040044
45 @classmethod
Andrea Frittoli581c3932014-09-15 13:14:53 +010046 def resource_cleanup(cls):
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040047 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 Lobankovc04ae232014-07-04 16:13:55 +040051 cls.cleanup_resources(getattr(cls, '_jobs', []), cls.client.delete_job)
Yaroslav Lobankov74c923b2014-05-21 13:13:07 +040052 cls.cleanup_resources(getattr(cls, '_job_binaries', []),
53 cls.client.delete_job_binary)
Yaroslav Lobankovc04ae232014-07-04 16:13:55 +040054 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 Treinish92dae932014-01-31 16:43:32 +000058 cls.clear_isolated_creds()
Andrea Frittoli581c3932014-09-15 13:14:53 +010059 super(BaseDataProcessingTest, cls).resource_cleanup()
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040060
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040061 @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 Lukjanov03c95c82013-12-10 16:42:37 +040070 @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 Kranz77f57202015-02-09 14:10:04 -050080 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 Lukjanov03c95c82013-12-10 16:42:37 +040086 # store id of created node group template
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040087 cls._node_group_templates.append(resp_body['id'])
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040088
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040089 return resp_body
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040090
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 Kranz77f57202015-02-09 14:10:04 -0500100 resp_body = cls.client.create_cluster_template(name, plugin_name,
101 hadoop_version,
102 node_groups,
103 cluster_configs,
104 **kwargs)
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +0400105 # store id of created cluster template
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400106 cls._cluster_templates.append(resp_body['id'])
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +0400107
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400108 return resp_body
Yaroslav Lobankov4267bcc2014-04-25 13:25:03 +0400109
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 Kranz77f57202015-02-09 14:10:04 -0500118 resp_body = cls.client.create_data_source(name, type, url, **kwargs)
Yaroslav Lobankov4267bcc2014-04-25 13:25:03 +0400119 # store id of created data source
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400120 cls._data_sources.append(resp_body['id'])
Yaroslav Lobankov4267bcc2014-04-25 13:25:03 +0400121
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400122 return resp_body
Yaroslav Lobankovd5dcf192014-05-21 13:58:10 +0400123
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 Kranz77f57202015-02-09 14:10:04 -0500131 resp_body = cls.client.create_job_binary_internal(name, data)
Yaroslav Lobankovd5dcf192014-05-21 13:58:10 +0400132 # store id of created job binary internal
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400133 cls._job_binary_internals.append(resp_body['id'])
Yaroslav Lobankovd5dcf192014-05-21 13:58:10 +0400134
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400135 return resp_body
Yaroslav Lobankov74c923b2014-05-21 13:13:07 +0400136
Yaroslav Lobankovc04ae232014-07-04 16:13:55 +0400137 @classmethod
Yaroslav Lobankov74c923b2014-05-21 13:13:07 +0400138 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 Kranz77f57202015-02-09 14:10:04 -0500145 resp_body = cls.client.create_job_binary(name, url, extra, **kwargs)
Yaroslav Lobankov74c923b2014-05-21 13:13:07 +0400146 # store id of created job binary
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400147 cls._job_binaries.append(resp_body['id'])
Yaroslav Lobankov74c923b2014-05-21 13:13:07 +0400148
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400149 return resp_body
Yaroslav Lobankovc04ae232014-07-04 16:13:55 +0400150
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 Kranz77f57202015-02-09 14:10:04 -0500159 resp_body = cls.client.create_job(name,
160 job_type, mains, libs, **kwargs)
Yaroslav Lobankovc04ae232014-07-04 16:13:55 +0400161 # store id of created job
162 cls._jobs.append(resp_body['id'])
163
164 return resp_body