bkopilov | 81aaae7 | 2015-05-15 23:46:25 +0300 | [diff] [blame] | 1 | # Copyright 2015 Red Hat, Inc. |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
| 16 | from six import moves |
bkopilov | 81aaae7 | 2015-05-15 23:46:25 +0300 | [diff] [blame] | 17 | import testtools |
| 18 | |
| 19 | from tempest.api.image import base |
| 20 | from tempest import config |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 21 | from tempest.lib.common.utils import data_utils |
| 22 | from tempest.lib import exceptions as lib_exc |
bkopilov | 81aaae7 | 2015-05-15 23:46:25 +0300 | [diff] [blame] | 23 | from tempest import test |
bkopilov | 81aaae7 | 2015-05-15 23:46:25 +0300 | [diff] [blame] | 24 | |
| 25 | CONF = config.CONF |
| 26 | |
| 27 | |
| 28 | class BasicAdminOperationsImagesTest(base.BaseV2ImageAdminTest): |
Ken'ichi Ohmichi | 9e3dac0 | 2015-11-19 07:01:07 +0000 | [diff] [blame] | 29 | """Here we test admin operations of images""" |
bkopilov | 81aaae7 | 2015-05-15 23:46:25 +0300 | [diff] [blame] | 30 | |
bkopilov | 81aaae7 | 2015-05-15 23:46:25 +0300 | [diff] [blame] | 31 | @testtools.skipUnless(CONF.image_feature_enabled.deactivate_image, |
| 32 | 'deactivate-image is not available.') |
| 33 | @test.idempotent_id('951ebe01-969f-4ea9-9898-8a3f1f442ab0') |
| 34 | def test_admin_deactivate_reactivate_image(self): |
| 35 | # Create image by non-admin tenant |
| 36 | image_name = data_utils.rand_name('image') |
| 37 | body = self.client.create_image(name=image_name, |
| 38 | container_format='bare', |
| 39 | disk_format='raw', |
| 40 | visibility='private') |
| 41 | image_id = body['id'] |
| 42 | self.addCleanup(self.client.delete_image, image_id) |
| 43 | # upload an image file |
piyush110786 | 413994a | 2015-08-21 10:52:39 +0530 | [diff] [blame] | 44 | content = data_utils.random_bytes() |
| 45 | image_file = moves.cStringIO(content) |
Ken'ichi Ohmichi | 66494e9 | 2015-06-08 04:28:10 +0000 | [diff] [blame] | 46 | self.client.store_image_file(image_id, image_file) |
bkopilov | 81aaae7 | 2015-05-15 23:46:25 +0300 | [diff] [blame] | 47 | # deactivate image |
| 48 | self.admin_client.deactivate_image(image_id) |
| 49 | body = self.client.show_image(image_id) |
| 50 | self.assertEqual("deactivated", body['status']) |
piyush110786 | 413994a | 2015-08-21 10:52:39 +0530 | [diff] [blame] | 51 | # non-admin user unable to download deactivated image |
Ken'ichi Ohmichi | 6bd6f20 | 2015-11-20 05:29:38 +0000 | [diff] [blame] | 52 | self.assertRaises(lib_exc.Forbidden, self.client.show_image_file, |
piyush110786 | 413994a | 2015-08-21 10:52:39 +0530 | [diff] [blame] | 53 | image_id) |
bkopilov | 81aaae7 | 2015-05-15 23:46:25 +0300 | [diff] [blame] | 54 | # reactivate image |
| 55 | self.admin_client.reactivate_image(image_id) |
| 56 | body = self.client.show_image(image_id) |
| 57 | self.assertEqual("active", body['status']) |
piyush110786 | 413994a | 2015-08-21 10:52:39 +0530 | [diff] [blame] | 58 | # non-admin user able to download image after reactivation by admin |
Ken'ichi Ohmichi | 6bd6f20 | 2015-11-20 05:29:38 +0000 | [diff] [blame] | 59 | body = self.client.show_image_file(image_id) |
piyush110786 | 413994a | 2015-08-21 10:52:39 +0530 | [diff] [blame] | 60 | self.assertEqual(content, body.data) |