blob: 83eb54d235271ef64e326f0777a0011a6018576a [file] [log] [blame]
Yaroslav Lobankov1b3c8242014-07-04 17:43:16 +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
Fei Long Wangd39431f2015-05-14 11:30:48 +120016from tempest.common.utils import data_utils
Yaroslav Lobankov1b3c8242014-07-04 17:43:16 +040017from tempest import test
18
19
20class 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 Frittoli581c3932014-09-15 13:14:53 +010025 def resource_setup(cls):
26 super(JobTest, cls).resource_setup()
Yaroslav Lobankov1b3c8242014-07-04 17:43:16 +040027 # 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 Hoge7579c1a2015-02-26 14:12:15 -080064 @test.idempotent_id('8cf785ca-adf4-473d-8281-fb9a5efa3073')
Yaroslav Lobankov1b3c8242014-07-04 17:43:16 +040065 def test_job_create(self):
66 self._create_job()
67
68 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080069 @test.idempotent_id('41e253fe-b02a-41a0-b186-5ff1f0463ba3')
Yaroslav Lobankov1b3c8242014-07-04 17:43:16 +040070 def test_job_list(self):
71 job_info = self._create_job()
72
73 # check for job in list
David Kranz77f57202015-02-09 14:10:04 -050074 jobs = self.client.list_jobs()
Yaroslav Lobankov1b3c8242014-07-04 17:43:16 +040075 jobs_info = [(job['id'], job['name']) for job in jobs]
76 self.assertIn(job_info, jobs_info)
77
78 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080079 @test.idempotent_id('3faf17fa-bc94-4a60-b1c3-79e53674c16c')
Yaroslav Lobankov1b3c8242014-07-04 17:43:16 +040080 def test_job_get(self):
81 job_id, job_name = self._create_job()
82
83 # check job fetch by id
David Kranz77f57202015-02-09 14:10:04 -050084 job = self.client.get_job(job_id)
Yaroslav Lobankov1b3c8242014-07-04 17:43:16 +040085 self.assertEqual(job_name, job['name'])
86
87 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080088 @test.idempotent_id('dff85e62-7dda-4ad8-b1ee-850adecb0c6e')
Yaroslav Lobankov1b3c8242014-07-04 17:43:16 +040089 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)