blob: d006991709ec308e4672ffab0d68a249a8386fd0 [file] [log] [blame]
Yaroslav Lobankov72876772014-06-11 16:18:19 +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
17from tempest import test
18
19
20class JobBinaryTest(dp_base.BaseDataProcessingTest):
21 """Link to the API documentation is http://docs.openstack.org/developer/
22 sahara/restapi/rest_api_v1.1_EDP.html#job-binaries
23 """
24 @classmethod
Andrea Frittoli581c3932014-09-15 13:14:53 +010025 def resource_setup(cls):
26 super(JobBinaryTest, cls).resource_setup()
Yaroslav Lobankov72876772014-06-11 16:18:19 +040027 cls.swift_job_binary_with_extra = {
28 'url': 'swift://sahara-container.sahara/example.jar',
29 'description': 'Test job binary',
30 'extra': {
31 'user': cls.os.credentials.username,
32 'password': cls.os.credentials.password
33 }
34 }
35 # Create extra cls.swift_job_binary variable to use for comparison to
36 # job binary response body because response body has no 'extra' field.
37 cls.swift_job_binary = cls.swift_job_binary_with_extra.copy()
38 del cls.swift_job_binary['extra']
39
40 name = data_utils.rand_name('sahara-internal-job-binary')
41 cls.job_binary_data = 'Some script may be data'
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040042 job_binary_internal = (
43 cls.create_job_binary_internal(name, cls.job_binary_data))
Yaroslav Lobankov72876772014-06-11 16:18:19 +040044 cls.internal_db_job_binary = {
45 'url': 'internal-db://%s' % job_binary_internal['id'],
46 'description': 'Test job binary',
47 }
48
49 def _create_job_binary(self, binary_body, binary_name=None):
50 """Creates Job Binary with optional name specified.
51
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040052 It creates a link to data (jar, pig files, etc.), ensures job binary
53 name and response body. Returns id and name of created job binary.
54 Data may not exist when using Swift as data storage.
55 In other cases data must exist in storage.
Yaroslav Lobankov72876772014-06-11 16:18:19 +040056 """
57 if not binary_name:
58 # generate random name if it's not specified
59 binary_name = data_utils.rand_name('sahara-job-binary')
60
61 # create job binary
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040062 resp_body = self.create_job_binary(binary_name, **binary_body)
Yaroslav Lobankov72876772014-06-11 16:18:19 +040063
64 # ensure that binary created successfully
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040065 self.assertEqual(binary_name, resp_body['name'])
Yaroslav Lobankov72876772014-06-11 16:18:19 +040066 if 'swift' in binary_body['url']:
67 binary_body = self.swift_job_binary
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040068 self.assertDictContainsSubset(binary_body, resp_body)
Yaroslav Lobankov72876772014-06-11 16:18:19 +040069
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040070 return resp_body['id'], binary_name
Yaroslav Lobankov72876772014-06-11 16:18:19 +040071
72 @test.attr(type='smoke')
73 def test_swift_job_binary_create(self):
74 self._create_job_binary(self.swift_job_binary_with_extra)
75
76 @test.attr(type='smoke')
77 def test_swift_job_binary_list(self):
78 binary_info = self._create_job_binary(self.swift_job_binary_with_extra)
79
80 # check for job binary in list
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040081 _, binaries = self.client.list_job_binaries()
Yaroslav Lobankov72876772014-06-11 16:18:19 +040082 binaries_info = [(binary['id'], binary['name']) for binary in binaries]
83 self.assertIn(binary_info, binaries_info)
84
85 @test.attr(type='smoke')
86 def test_swift_job_binary_get(self):
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040087 binary_id, binary_name = (
88 self._create_job_binary(self.swift_job_binary_with_extra))
Yaroslav Lobankov72876772014-06-11 16:18:19 +040089
90 # check job binary fetch by id
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040091 _, binary = self.client.get_job_binary(binary_id)
Yaroslav Lobankov72876772014-06-11 16:18:19 +040092 self.assertEqual(binary_name, binary['name'])
93 self.assertDictContainsSubset(self.swift_job_binary, binary)
94
95 @test.attr(type='smoke')
96 def test_swift_job_binary_delete(self):
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +040097 binary_id, _ = (
98 self._create_job_binary(self.swift_job_binary_with_extra))
Yaroslav Lobankov72876772014-06-11 16:18:19 +040099
100 # delete the job binary by id
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400101 self.client.delete_job_binary(binary_id)
Yaroslav Lobankov72876772014-06-11 16:18:19 +0400102
103 @test.attr(type='smoke')
104 def test_internal_db_job_binary_create(self):
105 self._create_job_binary(self.internal_db_job_binary)
106
107 @test.attr(type='smoke')
108 def test_internal_db_job_binary_list(self):
109 binary_info = self._create_job_binary(self.internal_db_job_binary)
110
111 # check for job binary in list
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400112 _, binaries = self.client.list_job_binaries()
Yaroslav Lobankov72876772014-06-11 16:18:19 +0400113 binaries_info = [(binary['id'], binary['name']) for binary in binaries]
114 self.assertIn(binary_info, binaries_info)
115
116 @test.attr(type='smoke')
117 def test_internal_db_job_binary_get(self):
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400118 binary_id, binary_name = (
119 self._create_job_binary(self.internal_db_job_binary))
Yaroslav Lobankov72876772014-06-11 16:18:19 +0400120
121 # check job binary fetch by id
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400122 _, binary = self.client.get_job_binary(binary_id)
Yaroslav Lobankov72876772014-06-11 16:18:19 +0400123 self.assertEqual(binary_name, binary['name'])
124 self.assertDictContainsSubset(self.internal_db_job_binary, binary)
125
126 @test.attr(type='smoke')
127 def test_internal_db_job_binary_delete(self):
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400128 binary_id, _ = self._create_job_binary(self.internal_db_job_binary)
Yaroslav Lobankov72876772014-06-11 16:18:19 +0400129
130 # delete the job binary by id
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400131 self.client.delete_job_binary(binary_id)
Yaroslav Lobankov72876772014-06-11 16:18:19 +0400132
133 @test.attr(type='smoke')
134 def test_job_binary_get_data(self):
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400135 binary_id, _ = self._create_job_binary(self.internal_db_job_binary)
Yaroslav Lobankov72876772014-06-11 16:18:19 +0400136
137 # get data of job binary by id
Yaroslav Lobankov2f8525e2014-07-21 16:40:23 +0400138 _, data = self.client.get_job_binary_data(binary_id)
Yaroslav Lobankov72876772014-06-11 16:18:19 +0400139 self.assertEqual(data, self.job_binary_data)