blob: cc76880b94f5497110e99577fa8d8a581798ae1b [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
27 def setUpClass(cls):
28 super(BaseDataProcessingTest, cls).setUpClass()
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
32 os = cls.get_client_manager()
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040033 cls.client = os.data_processing_client
34
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 = []
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040042
43 @classmethod
44 def tearDownClass(cls):
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040045 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 Lobankov4267bcc2014-04-25 13:25:03 +040049 cls.cleanup_resources(getattr(cls, '_data_sources', []),
50 cls.client.delete_data_source)
Yaroslav Lobankovd5dcf192014-05-21 13:58:10 +040051 cls.cleanup_resources(getattr(cls, '_job_binary_internals', []),
52 cls.client.delete_job_binary_internal)
Matthew Treinish92dae932014-01-31 16:43:32 +000053 cls.clear_isolated_creds()
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040054 super(BaseDataProcessingTest, cls).tearDownClass()
55
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040056 @staticmethod
57 def cleanup_resources(resource_id_list, method):
58 for resource_id in resource_id_list:
59 try:
60 method(resource_id)
61 except exceptions.NotFound:
62 # ignore errors while auto removing created resource
63 pass
64
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040065 @classmethod
66 def create_node_group_template(cls, name, plugin_name, hadoop_version,
67 node_processes, flavor_id,
68 node_configs=None, **kwargs):
69 """Creates watched node group template with specified params.
70
71 It supports passing additional params using kwargs and returns created
72 object. All resources created in this method will be automatically
73 removed in tearDownClass method.
74 """
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040075 resp, body = cls.client.create_node_group_template(name, plugin_name,
76 hadoop_version,
77 node_processes,
78 flavor_id,
79 node_configs,
80 **kwargs)
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040081 # store id of created node group template
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040082 cls._node_group_templates.append(body['id'])
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040083
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040084 return resp, body
85
86 @classmethod
87 def create_cluster_template(cls, name, plugin_name, hadoop_version,
88 node_groups, cluster_configs=None, **kwargs):
89 """Creates watched cluster template with specified params.
90
91 It supports passing additional params using kwargs and returns created
92 object. All resources created in this method will be automatically
93 removed in tearDownClass method.
94 """
95 resp, body = cls.client.create_cluster_template(name, plugin_name,
96 hadoop_version,
97 node_groups,
98 cluster_configs,
99 **kwargs)
100 # store id of created cluster template
101 cls._cluster_templates.append(body['id'])
102
103 return resp, body
Yaroslav Lobankov4267bcc2014-04-25 13:25:03 +0400104
105 @classmethod
106 def create_data_source(cls, name, type, url, **kwargs):
107 """Creates watched data source with specified params.
108
109 It supports passing additional params using kwargs and returns created
110 object. All resources created in this method will be automatically
111 removed in tearDownClass method.
112 """
113 resp, body = cls.client.create_data_source(name, type, url, **kwargs)
114 # store id of created data source
115 cls._data_sources.append(body['id'])
116
117 return resp, body
Yaroslav Lobankovd5dcf192014-05-21 13:58:10 +0400118
119 @classmethod
120 def create_job_binary_internal(cls, name, data):
121 """Creates watched job binary internal with specified params.
122
123 It returns created object. All resources created in this method will
124 be automatically removed in tearDownClass method.
125 """
126 resp, body = cls.client.create_job_binary_internal(name, data)
127 # store id of created job binary internal
128 cls._job_binary_internals.append(body['id'])
129
130 return resp, body