blob: 74444d7f8d78a0b81ce47a102c5f0c1f35aa957f [file] [log] [blame]
Sergey Lukjanov03c95c82013-12-10 16:42:37 +04001# Copyright (c) 2013 Mirantis Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12# implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from tempest import config
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040017from tempest import exceptions
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040018import tempest.test
19
20
21CONF = config.CONF
22
23
24class BaseDataProcessingTest(tempest.test.BaseTestCase):
25 _interface = 'json'
26
27 @classmethod
28 def setUpClass(cls):
29 super(BaseDataProcessingTest, cls).setUpClass()
Sergey Lukjanov9c95a252014-03-13 23:59:22 +040030 if not CONF.service_available.sahara:
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040031 raise cls.skipException('Sahara support is required')
Zhi Kun Liu2259c972014-03-27 02:11:10 -050032
33 os = cls.get_client_manager()
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040034 cls.client = os.data_processing_client
35
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040036 cls.flavor_ref = CONF.compute.flavor_ref
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040037
38 # add lists for watched resources
39 cls._node_group_templates = []
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040040 cls._cluster_templates = []
Yaroslav Lobankov4267bcc2014-04-25 13:25:03 +040041 cls._data_sources = []
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)
Matthew Treinish92dae932014-01-31 16:43:32 +000051 cls.clear_isolated_creds()
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040052 super(BaseDataProcessingTest, cls).tearDownClass()
53
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040054 @staticmethod
55 def cleanup_resources(resource_id_list, method):
56 for resource_id in resource_id_list:
57 try:
58 method(resource_id)
59 except exceptions.NotFound:
60 # ignore errors while auto removing created resource
61 pass
62
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040063 @classmethod
64 def create_node_group_template(cls, name, plugin_name, hadoop_version,
65 node_processes, flavor_id,
66 node_configs=None, **kwargs):
67 """Creates watched node group template with specified params.
68
69 It supports passing additional params using kwargs and returns created
70 object. All resources created in this method will be automatically
71 removed in tearDownClass method.
72 """
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040073 resp, body = cls.client.create_node_group_template(name, plugin_name,
74 hadoop_version,
75 node_processes,
76 flavor_id,
77 node_configs,
78 **kwargs)
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040079 # store id of created node group template
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040080 cls._node_group_templates.append(body['id'])
Sergey Lukjanov03c95c82013-12-10 16:42:37 +040081
Yaroslav Lobankov93aa8192014-04-01 20:03:25 +040082 return resp, body
83
84 @classmethod
85 def create_cluster_template(cls, name, plugin_name, hadoop_version,
86 node_groups, cluster_configs=None, **kwargs):
87 """Creates watched cluster template with specified params.
88
89 It supports passing additional params using kwargs and returns created
90 object. All resources created in this method will be automatically
91 removed in tearDownClass method.
92 """
93 resp, body = cls.client.create_cluster_template(name, plugin_name,
94 hadoop_version,
95 node_groups,
96 cluster_configs,
97 **kwargs)
98 # store id of created cluster template
99 cls._cluster_templates.append(body['id'])
100
101 return resp, body
Yaroslav Lobankov4267bcc2014-04-25 13:25:03 +0400102
103 @classmethod
104 def create_data_source(cls, name, type, url, **kwargs):
105 """Creates watched data source with specified params.
106
107 It supports passing additional params using kwargs and returns created
108 object. All resources created in this method will be automatically
109 removed in tearDownClass method.
110 """
111 resp, body = cls.client.create_data_source(name, type, url, **kwargs)
112 # store id of created data source
113 cls._data_sources.append(body['id'])
114
115 return resp, body