blob: 01838b6bc8effc488f5fc208ec5361ffea0f6ed4 [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
17from tempest_lib.common.utils import data_utils
18import testtools
19
20from tempest.api.image import base
21from tempest import config
22from tempest import test
piyush110786413994a2015-08-21 10:52:39 +053023from tempest_lib import exceptions as lib_exc
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
52 self.assertRaises(lib_exc.Forbidden, self.client.load_image_file,
53 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
59 body = self.client.load_image_file(image_id)
60 self.assertEqual(content, body.data)