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 |
| 16 | from tempest.common.utils import data_utils |
| 17 | from tempest import config |
| 18 | from tempest import test |
| 19 | |
| 20 | CONF = config.CONF |
| 21 | |
| 22 | |
| 23 | class DataSourceTest(dp_base.BaseDataProcessingTest): |
| 24 | @classmethod |
| 25 | def setUpClass(cls): |
| 26 | super(DataSourceTest, cls).setUpClass() |
| 27 | cls.swift_data_source_with_creds = { |
| 28 | 'url': 'swift://sahara-container.sahara/input-source', |
| 29 | 'description': 'Test data source', |
| 30 | 'credentials': { |
| 31 | 'user': CONF.identity.username, |
| 32 | 'password': CONF.identity.password |
| 33 | }, |
| 34 | 'type': 'swift' |
| 35 | } |
| 36 | cls.swift_data_source = cls.swift_data_source_with_creds.copy() |
| 37 | del cls.swift_data_source['credentials'] |
| 38 | |
| 39 | cls.local_hdfs_data_source = { |
| 40 | 'url': 'input-source', |
| 41 | 'description': 'Test data source', |
| 42 | 'type': 'hdfs' |
| 43 | } |
| 44 | |
| 45 | cls.external_hdfs_data_source = { |
| 46 | 'url': 'hdfs://172.18.168.2:8020/usr/hadoop/input-source', |
| 47 | 'description': 'Test data source', |
| 48 | 'type': 'hdfs' |
| 49 | } |
| 50 | |
| 51 | def _create_data_source(self, source_body, source_name=None): |
| 52 | """Creates Data Source with optional name specified. |
| 53 | |
| 54 | It creates a link to input-source file (it may not exist) and ensures |
| 55 | response status and source name. Returns id and name of created source. |
| 56 | """ |
| 57 | if not source_name: |
| 58 | # generate random name if it's not specified |
| 59 | source_name = data_utils.rand_name('sahara-data-source') |
| 60 | |
| 61 | # create data source |
| 62 | resp, body = self.create_data_source(source_name, **source_body) |
| 63 | |
| 64 | # ensure that source created successfully |
| 65 | self.assertEqual(202, resp.status) |
| 66 | self.assertEqual(source_name, body['name']) |
| 67 | if source_body['type'] == 'swift': |
| 68 | source_body = self.swift_data_source |
| 69 | self.assertDictContainsSubset(source_body, body) |
| 70 | |
| 71 | return body['id'], source_name |
| 72 | |
| 73 | def _list_data_sources(self, source_info): |
| 74 | # check for data source in list |
| 75 | resp, sources = self.client.list_data_sources() |
| 76 | self.assertEqual(200, resp.status) |
| 77 | sources_info = [(source['id'], source['name']) for source in sources] |
| 78 | self.assertIn(source_info, sources_info) |
| 79 | |
| 80 | def _get_data_source(self, source_id, source_name, source_body): |
| 81 | # check data source fetch by id |
| 82 | resp, source = self.client.get_data_source(source_id) |
| 83 | self.assertEqual(200, resp.status) |
| 84 | self.assertEqual(source_name, source['name']) |
| 85 | self.assertDictContainsSubset(source_body, source) |
| 86 | |
| 87 | def _delete_data_source(self, source_id): |
| 88 | # delete the data source by id |
| 89 | resp = self.client.delete_data_source(source_id)[0] |
| 90 | self.assertEqual(204, resp.status) |
| 91 | |
| 92 | @test.attr(type='smoke') |
| 93 | def test_swift_data_source_create(self): |
| 94 | self._create_data_source(self.swift_data_source_with_creds) |
| 95 | |
| 96 | @test.attr(type='smoke') |
| 97 | def test_swift_data_source_list(self): |
| 98 | source_info = self._create_data_source( |
| 99 | self.swift_data_source_with_creds) |
| 100 | self._list_data_sources(source_info) |
| 101 | |
| 102 | @test.attr(type='smoke') |
| 103 | def test_swift_data_source_get(self): |
| 104 | source_id, source_name = self._create_data_source( |
| 105 | self.swift_data_source_with_creds) |
| 106 | self._get_data_source(source_id, source_name, self.swift_data_source) |
| 107 | |
| 108 | @test.attr(type='smoke') |
| 109 | def test_swift_data_source_delete(self): |
| 110 | source_id = self._create_data_source( |
| 111 | self.swift_data_source_with_creds)[0] |
| 112 | self._delete_data_source(source_id) |
| 113 | |
| 114 | @test.attr(type='smoke') |
| 115 | def test_local_hdfs_data_source_create(self): |
| 116 | self._create_data_source(self.local_hdfs_data_source) |
| 117 | |
| 118 | @test.attr(type='smoke') |
| 119 | def test_local_hdfs_data_source_list(self): |
| 120 | source_info = self._create_data_source(self.local_hdfs_data_source) |
| 121 | self._list_data_sources(source_info) |
| 122 | |
| 123 | @test.attr(type='smoke') |
| 124 | def test_local_hdfs_data_source_get(self): |
| 125 | source_id, source_name = self._create_data_source( |
| 126 | self.local_hdfs_data_source) |
| 127 | self._get_data_source( |
| 128 | source_id, source_name, self.local_hdfs_data_source) |
| 129 | |
| 130 | @test.attr(type='smoke') |
| 131 | def test_local_hdfs_data_source_delete(self): |
| 132 | source_id = self._create_data_source(self.local_hdfs_data_source)[0] |
| 133 | self._delete_data_source(source_id) |
| 134 | |
| 135 | @test.attr(type='smoke') |
| 136 | def test_external_hdfs_data_source_create(self): |
| 137 | self._create_data_source(self.external_hdfs_data_source) |
| 138 | |
| 139 | @test.attr(type='smoke') |
| 140 | def test_external_hdfs_data_source_list(self): |
| 141 | source_info = self._create_data_source(self.external_hdfs_data_source) |
| 142 | self._list_data_sources(source_info) |
| 143 | |
| 144 | @test.attr(type='smoke') |
| 145 | def test_external_hdfs_data_source_get(self): |
| 146 | source_id, source_name = self._create_data_source( |
| 147 | self.external_hdfs_data_source) |
| 148 | self._get_data_source( |
| 149 | source_id, source_name, self.external_hdfs_data_source) |
| 150 | |
| 151 | @test.attr(type='smoke') |
| 152 | def test_external_hdfs_data_source_delete(self): |
| 153 | source_id = self._create_data_source(self.external_hdfs_data_source)[0] |
| 154 | self._delete_data_source(source_id) |