blob: 3650751d93d6d4d7c7716a8f2fcf527222808a20 [file] [log] [blame]
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +04001# Copyright (c) 2014 Mirantis Inc.
2#
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
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, 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.
14
15from tempest.api.data_processing import base as dp_base
16from tempest.common.utils import data_utils
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +040017from tempest import test
18
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +040019
20class DataSourceTest(dp_base.BaseDataProcessingTest):
21 @classmethod
Andrea Frittoli581c3932014-09-15 13:14:53 +010022 def resource_setup(cls):
23 super(DataSourceTest, cls).resource_setup()
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +040024 cls.swift_data_source_with_creds = {
25 'url': 'swift://sahara-container.sahara/input-source',
26 'description': 'Test data source',
27 'credentials': {
Yaroslav Lobankovfa5a36e2014-07-01 15:24:55 +040028 'user': cls.os.credentials.username,
29 'password': cls.os.credentials.password
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +040030 },
31 'type': 'swift'
32 }
33 cls.swift_data_source = cls.swift_data_source_with_creds.copy()
34 del cls.swift_data_source['credentials']
35
36 cls.local_hdfs_data_source = {
37 'url': 'input-source',
38 'description': 'Test data source',
39 'type': 'hdfs'
40 }
41
42 cls.external_hdfs_data_source = {
43 'url': 'hdfs://172.18.168.2:8020/usr/hadoop/input-source',
44 'description': 'Test data source',
45 'type': 'hdfs'
46 }
47
48 def _create_data_source(self, source_body, source_name=None):
49 """Creates Data Source with optional name specified.
50
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040051 It creates a link to input-source file (it may not exist), ensures
52 source name and response body. Returns id and name of created source.
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +040053 """
54 if not source_name:
55 # generate random name if it's not specified
56 source_name = data_utils.rand_name('sahara-data-source')
57
58 # create data source
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040059 resp_body = self.create_data_source(source_name, **source_body)
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +040060
61 # ensure that source created successfully
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040062 self.assertEqual(source_name, resp_body['name'])
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +040063 if source_body['type'] == 'swift':
64 source_body = self.swift_data_source
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040065 self.assertDictContainsSubset(source_body, resp_body)
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +040066
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040067 return resp_body['id'], source_name
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +040068
69 def _list_data_sources(self, source_info):
70 # check for data source in list
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040071 _, sources = self.client.list_data_sources()
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +040072 sources_info = [(source['id'], source['name']) for source in sources]
73 self.assertIn(source_info, sources_info)
74
75 def _get_data_source(self, source_id, source_name, source_body):
76 # check data source fetch by id
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040077 _, source = self.client.get_data_source(source_id)
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +040078 self.assertEqual(source_name, source['name'])
79 self.assertDictContainsSubset(source_body, source)
80
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +040081 @test.attr(type='smoke')
82 def test_swift_data_source_create(self):
83 self._create_data_source(self.swift_data_source_with_creds)
84
85 @test.attr(type='smoke')
86 def test_swift_data_source_list(self):
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040087 source_info = (
88 self._create_data_source(self.swift_data_source_with_creds))
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +040089 self._list_data_sources(source_info)
90
91 @test.attr(type='smoke')
92 def test_swift_data_source_get(self):
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040093 source_id, source_name = (
94 self._create_data_source(self.swift_data_source_with_creds))
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +040095 self._get_data_source(source_id, source_name, self.swift_data_source)
96
97 @test.attr(type='smoke')
98 def test_swift_data_source_delete(self):
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040099 source_id, _ = (
100 self._create_data_source(self.swift_data_source_with_creds))
101
102 # delete the data source by id
103 self.client.delete_data_source(source_id)
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +0400104
105 @test.attr(type='smoke')
106 def test_local_hdfs_data_source_create(self):
107 self._create_data_source(self.local_hdfs_data_source)
108
109 @test.attr(type='smoke')
110 def test_local_hdfs_data_source_list(self):
111 source_info = self._create_data_source(self.local_hdfs_data_source)
112 self._list_data_sources(source_info)
113
114 @test.attr(type='smoke')
115 def test_local_hdfs_data_source_get(self):
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400116 source_id, source_name = (
117 self._create_data_source(self.local_hdfs_data_source))
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +0400118 self._get_data_source(
119 source_id, source_name, self.local_hdfs_data_source)
120
121 @test.attr(type='smoke')
122 def test_local_hdfs_data_source_delete(self):
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400123 source_id, _ = self._create_data_source(self.local_hdfs_data_source)
124
125 # delete the data source by id
126 self.client.delete_data_source(source_id)
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +0400127
128 @test.attr(type='smoke')
129 def test_external_hdfs_data_source_create(self):
130 self._create_data_source(self.external_hdfs_data_source)
131
132 @test.attr(type='smoke')
133 def test_external_hdfs_data_source_list(self):
134 source_info = self._create_data_source(self.external_hdfs_data_source)
135 self._list_data_sources(source_info)
136
137 @test.attr(type='smoke')
138 def test_external_hdfs_data_source_get(self):
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400139 source_id, source_name = (
140 self._create_data_source(self.external_hdfs_data_source))
Yaroslav Lobankovee92a9d2014-05-12 17:15:17 +0400141 self._get_data_source(
142 source_id, source_name, self.external_hdfs_data_source)
143
144 @test.attr(type='smoke')
145 def test_external_hdfs_data_source_delete(self):
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400146 source_id, _ = self._create_data_source(self.external_hdfs_data_source)
147
148 # delete the data source by id
149 self.client.delete_data_source(source_id)