blob: 0d6773c0adc60e51b94c86aa9b5ccd305c3c8359 [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 = []
Yaroslav Lobankov74c923b2014-05-21 13:13:07 +040042 cls._job_binaries = []
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040043
44 @classmethod
45 def tearDownClass(cls):
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040046 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 Lobankov4267bcc2014-04-25 13:25:03 +040050 cls.cleanup_resources(getattr(cls, '_data_sources', []),
51 cls.client.delete_data_source)
Yaroslav Lobankovd5dcf192014-05-21 13:58:10 +040052 cls.cleanup_resources(getattr(cls, '_job_binary_internals', []),
53 cls.client.delete_job_binary_internal)
Yaroslav Lobankov74c923b2014-05-21 13:13:07 +040054 cls.cleanup_resources(getattr(cls, '_job_binaries', []),
55 cls.client.delete_job_binary)
Matthew Treinish92dae932014-01-31 16:43:32 +000056 cls.clear_isolated_creds()
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040057 super(BaseDataProcessingTest, cls).tearDownClass()
58
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040059 @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 Lukjanov03c95c82013-12-10 16:42:37 +040068 @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 Lukjanov03c95c82013-12-10 16:42:37 +040078 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 Lukjanov03c95c82013-12-10 16:42:37 +040084 # store id of created node group template
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040085 cls._node_group_templates.append(body['id'])
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040086
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040087 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 Lobankov4267bcc2014-04-25 13:25:03 +0400107
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 Lobankovd5dcf192014-05-21 13:58:10 +0400121
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 Lobankov74c923b2014-05-21 13:13:07 +0400134
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