blob: 80da7a13b42168d5de5151f06afe53ad52badd0e [file] [log] [blame]
bkopilov81aaae72015-05-15 23:46:25 +03001# 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
16from six import moves
bkopilov81aaae72015-05-15 23:46:25 +030017import testtools
18
19from tempest.api.image import base
20from tempest import config
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050021from tempest.lib.common.utils import data_utils
22from tempest.lib import exceptions as lib_exc
bkopilov81aaae72015-05-15 23:46:25 +030023from tempest import test
bkopilov81aaae72015-05-15 23:46:25 +030024
25CONF = config.CONF
26
27
28class BasicAdminOperationsImagesTest(base.BaseV2ImageAdminTest):
Ken'ichi Ohmichi9e3dac02015-11-19 07:01:07 +000029 """Here we test admin operations of images"""
bkopilov81aaae72015-05-15 23:46:25 +030030
bkopilov81aaae72015-05-15 23:46:25 +030031 @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
piyush110786413994a2015-08-21 10:52:39 +053044 content = data_utils.random_bytes()
45 image_file = moves.cStringIO(content)
Ken'ichi Ohmichi66494e92015-06-08 04:28:10 +000046 self.client.store_image_file(image_id, image_file)
bkopilov81aaae72015-05-15 23:46:25 +030047 # deactivate image
48 self.admin_client.deactivate_image(image_id)
49 body = self.client.show_image(image_id)
50 self.assertEqual("deactivated", body['status'])
piyush110786413994a2015-08-21 10:52:39 +053051 # non-admin user unable to download deactivated image
Ken'ichi Ohmichi6bd6f202015-11-20 05:29:38 +000052 self.assertRaises(lib_exc.Forbidden, self.client.show_image_file,
piyush110786413994a2015-08-21 10:52:39 +053053 image_id)
bkopilov81aaae72015-05-15 23:46:25 +030054 # reactivate image
55 self.admin_client.reactivate_image(image_id)
56 body = self.client.show_image(image_id)
57 self.assertEqual("active", body['status'])
piyush110786413994a2015-08-21 10:52:39 +053058 # non-admin user able to download image after reactivation by admin
Ken'ichi Ohmichi6bd6f202015-11-20 05:29:38 +000059 body = self.client.show_image_file(image_id)
piyush110786413994a2015-08-21 10:52:39 +053060 self.assertEqual(content, body.data)