Yaroslav Lobankov | 1b3c824 | 2014-07-04 17:43:16 +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 | 1b3c824 | 2014-07-04 17:43:16 +0400 | [diff] [blame] | 17 | from tempest import test |
| 18 | |
| 19 | |
| 20 | class JobTest(dp_base.BaseDataProcessingTest): |
| 21 | """Link to the API documentation is http://docs.openstack.org/developer/ |
| 22 | sahara/restapi/rest_api_v1.1_EDP.html#jobs |
| 23 | """ |
| 24 | @classmethod |
Andrea Frittoli | 581c393 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 25 | def resource_setup(cls): |
| 26 | super(JobTest, cls).resource_setup() |
Yaroslav Lobankov | 1b3c824 | 2014-07-04 17:43:16 +0400 | [diff] [blame] | 27 | # create job binary |
| 28 | job_binary = { |
| 29 | 'name': data_utils.rand_name('sahara-job-binary'), |
| 30 | 'url': 'swift://sahara-container.sahara/example.jar', |
| 31 | 'description': 'Test job binary', |
| 32 | 'extra': { |
| 33 | 'user': cls.os.credentials.username, |
| 34 | 'password': cls.os.credentials.password |
| 35 | } |
| 36 | } |
| 37 | resp_body = cls.create_job_binary(**job_binary) |
| 38 | job_binary_id = resp_body['id'] |
| 39 | |
| 40 | cls.job = { |
| 41 | 'job_type': 'Pig', |
| 42 | 'mains': [job_binary_id] |
| 43 | } |
| 44 | |
| 45 | def _create_job(self, job_name=None): |
| 46 | """Creates Job with optional name specified. |
| 47 | |
| 48 | It creates job and ensures job name. Returns id and name of created |
| 49 | job. |
| 50 | """ |
| 51 | if not job_name: |
| 52 | # generate random name if it's not specified |
| 53 | job_name = data_utils.rand_name('sahara-job') |
| 54 | |
| 55 | # create job |
| 56 | resp_body = self.create_job(job_name, **self.job) |
| 57 | |
| 58 | # ensure that job created successfully |
| 59 | self.assertEqual(job_name, resp_body['name']) |
| 60 | |
| 61 | return resp_body['id'], job_name |
| 62 | |
| 63 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 64 | @test.idempotent_id('8cf785ca-adf4-473d-8281-fb9a5efa3073') |
Yaroslav Lobankov | 1b3c824 | 2014-07-04 17:43:16 +0400 | [diff] [blame] | 65 | def test_job_create(self): |
| 66 | self._create_job() |
| 67 | |
| 68 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 69 | @test.idempotent_id('41e253fe-b02a-41a0-b186-5ff1f0463ba3') |
Yaroslav Lobankov | 1b3c824 | 2014-07-04 17:43:16 +0400 | [diff] [blame] | 70 | def test_job_list(self): |
| 71 | job_info = self._create_job() |
| 72 | |
| 73 | # check for job in list |
David Kranz | 77f5720 | 2015-02-09 14:10:04 -0500 | [diff] [blame] | 74 | jobs = self.client.list_jobs() |
Yaroslav Lobankov | 1b3c824 | 2014-07-04 17:43:16 +0400 | [diff] [blame] | 75 | jobs_info = [(job['id'], job['name']) for job in jobs] |
| 76 | self.assertIn(job_info, jobs_info) |
| 77 | |
| 78 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 79 | @test.idempotent_id('3faf17fa-bc94-4a60-b1c3-79e53674c16c') |
Yaroslav Lobankov | 1b3c824 | 2014-07-04 17:43:16 +0400 | [diff] [blame] | 80 | def test_job_get(self): |
| 81 | job_id, job_name = self._create_job() |
| 82 | |
| 83 | # check job fetch by id |
David Kranz | 77f5720 | 2015-02-09 14:10:04 -0500 | [diff] [blame] | 84 | job = self.client.get_job(job_id) |
Yaroslav Lobankov | 1b3c824 | 2014-07-04 17:43:16 +0400 | [diff] [blame] | 85 | self.assertEqual(job_name, job['name']) |
| 86 | |
| 87 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 88 | @test.idempotent_id('dff85e62-7dda-4ad8-b1ee-850adecb0c6e') |
Yaroslav Lobankov | 1b3c824 | 2014-07-04 17:43:16 +0400 | [diff] [blame] | 89 | def test_job_delete(self): |
| 90 | job_id, _ = self._create_job() |
| 91 | |
| 92 | # delete the job by id |
| 93 | self.client.delete_job(job_id) |