Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 1 | # 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 | |
| 15 | from tempest.api.data_processing import base as dp_base |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 16 | from tempest.common.utils import data_utils |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 17 | from tempest import test |
| 18 | |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 19 | |
| 20 | class DataSourceTest(dp_base.BaseDataProcessingTest): |
| 21 | @classmethod |
Andrea Frittoli | 581c393 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 22 | def resource_setup(cls): |
| 23 | super(DataSourceTest, cls).resource_setup() |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 24 | cls.swift_data_source_with_creds = { |
| 25 | 'url': 'swift://sahara-container.sahara/input-source', |
| 26 | 'description': 'Test data source', |
| 27 | 'credentials': { |
Yaroslav Lobankov | fa5a36e | 2014-07-01 15:24:55 +0400 | [diff] [blame] | 28 | 'user': cls.os.credentials.username, |
| 29 | 'password': cls.os.credentials.password |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 30 | }, |
| 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 Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 51 | 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 Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 53 | """ |
| 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 Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 59 | resp_body = self.create_data_source(source_name, **source_body) |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 60 | |
| 61 | # ensure that source created successfully |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 62 | self.assertEqual(source_name, resp_body['name']) |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 63 | if source_body['type'] == 'swift': |
| 64 | source_body = self.swift_data_source |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 65 | self.assertDictContainsSubset(source_body, resp_body) |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 66 | |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 67 | return resp_body['id'], source_name |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 68 | |
| 69 | def _list_data_sources(self, source_info): |
| 70 | # check for data source in list |
Yaroslav Lobankov | 1662b0e | 2015-08-10 16:48:07 +0300 | [diff] [blame] | 71 | sources = self.client.list_data_sources()['data_sources'] |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 72 | 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 Lobankov | 1662b0e | 2015-08-10 16:48:07 +0300 | [diff] [blame] | 77 | source = self.client.get_data_source(source_id)['data_source'] |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 78 | self.assertEqual(source_name, source['name']) |
| 79 | self.assertDictContainsSubset(source_body, source) |
| 80 | |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 81 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 82 | @test.idempotent_id('9e0e836d-c372-4fca-91b7-b66c3e9646c8') |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 83 | def test_swift_data_source_create(self): |
| 84 | self._create_data_source(self.swift_data_source_with_creds) |
| 85 | |
| 86 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 87 | @test.idempotent_id('3cb87a4a-0534-4b97-9edc-8bbc822b68a0') |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 88 | def test_swift_data_source_list(self): |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 89 | source_info = ( |
| 90 | self._create_data_source(self.swift_data_source_with_creds)) |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 91 | self._list_data_sources(source_info) |
| 92 | |
| 93 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 94 | @test.idempotent_id('fc07409b-6477-4cb3-9168-e633c46b227f') |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 95 | def test_swift_data_source_get(self): |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 96 | source_id, source_name = ( |
| 97 | self._create_data_source(self.swift_data_source_with_creds)) |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 98 | self._get_data_source(source_id, source_name, self.swift_data_source) |
| 99 | |
| 100 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 101 | @test.idempotent_id('df53669c-0cd1-4cf7-b408-4cf215d8beb8') |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 102 | def test_swift_data_source_delete(self): |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 103 | source_id, _ = ( |
| 104 | self._create_data_source(self.swift_data_source_with_creds)) |
| 105 | |
| 106 | # delete the data source by id |
| 107 | self.client.delete_data_source(source_id) |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 108 | |
| 109 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 110 | @test.idempotent_id('88505d52-db01-4229-8f1d-a1137da5fe2d') |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 111 | def test_local_hdfs_data_source_create(self): |
| 112 | self._create_data_source(self.local_hdfs_data_source) |
| 113 | |
| 114 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 115 | @test.idempotent_id('81d7d42a-d7f6-4d9b-b38c-0801a4dfe3c2') |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 116 | def test_local_hdfs_data_source_list(self): |
| 117 | source_info = self._create_data_source(self.local_hdfs_data_source) |
| 118 | self._list_data_sources(source_info) |
| 119 | |
| 120 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 121 | @test.idempotent_id('ec0144c6-db1e-4169-bb06-7abae14a8443') |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 122 | def test_local_hdfs_data_source_get(self): |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 123 | source_id, source_name = ( |
| 124 | self._create_data_source(self.local_hdfs_data_source)) |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 125 | self._get_data_source( |
| 126 | source_id, source_name, self.local_hdfs_data_source) |
| 127 | |
| 128 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 129 | @test.idempotent_id('e398308b-4230-4f86-ba10-9b0b60a59c8d') |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 130 | def test_local_hdfs_data_source_delete(self): |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 131 | source_id, _ = self._create_data_source(self.local_hdfs_data_source) |
| 132 | |
| 133 | # delete the data source by id |
| 134 | self.client.delete_data_source(source_id) |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 135 | |
| 136 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 137 | @test.idempotent_id('bfd91128-e642-4d95-a973-3e536962180c') |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 138 | def test_external_hdfs_data_source_create(self): |
| 139 | self._create_data_source(self.external_hdfs_data_source) |
| 140 | |
| 141 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 142 | @test.idempotent_id('92e2be72-f7ab-499d-ae01-fb9943c90d8e') |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 143 | def test_external_hdfs_data_source_list(self): |
| 144 | source_info = self._create_data_source(self.external_hdfs_data_source) |
| 145 | self._list_data_sources(source_info) |
| 146 | |
| 147 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 148 | @test.idempotent_id('a31edb1b-6bc6-4f42-871f-70cd243184ac') |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 149 | def test_external_hdfs_data_source_get(self): |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 150 | source_id, source_name = ( |
| 151 | self._create_data_source(self.external_hdfs_data_source)) |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 152 | self._get_data_source( |
| 153 | source_id, source_name, self.external_hdfs_data_source) |
| 154 | |
| 155 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 156 | @test.idempotent_id('295924cd-a085-4b45-aea8-0707cdb2da7e') |
Yaroslav Lobankov | ee92a9d | 2014-05-12 17:15:17 +0400 | [diff] [blame] | 157 | def test_external_hdfs_data_source_delete(self): |
Yaroslav Lobankov | 2f8525e | 2014-07-21 16:40:23 +0400 | [diff] [blame] | 158 | source_id, _ = self._create_data_source(self.external_hdfs_data_source) |
| 159 | |
| 160 | # delete the data source by id |
| 161 | self.client.delete_data_source(source_id) |