blob: 09877ba5d0e4ef4fb555949a9029aa590de6179d [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):
29
30 """
31 Here we test admin operations of images
32 """
33 @testtools.skipUnless(CONF.image_feature_enabled.deactivate_image,
34 'deactivate-image is not available.')
35 @test.idempotent_id('951ebe01-969f-4ea9-9898-8a3f1f442ab0')
36 def test_admin_deactivate_reactivate_image(self):
37 # Create image by non-admin tenant
38 image_name = data_utils.rand_name('image')
39 body = self.client.create_image(name=image_name,
40 container_format='bare',
41 disk_format='raw',
42 visibility='private')
43 image_id = body['id']
44 self.addCleanup(self.client.delete_image, image_id)
45 # upload an image file
piyush110786413994a2015-08-21 10:52:39 +053046 content = data_utils.random_bytes()
47 image_file = moves.cStringIO(content)
Ken'ichi Ohmichi66494e92015-06-08 04:28:10 +000048 self.client.store_image_file(image_id, image_file)
bkopilov81aaae72015-05-15 23:46:25 +030049 # deactivate image
50 self.admin_client.deactivate_image(image_id)
51 body = self.client.show_image(image_id)
52 self.assertEqual("deactivated", body['status'])
piyush110786413994a2015-08-21 10:52:39 +053053 # non-admin user unable to download deactivated image
54 self.assertRaises(lib_exc.Forbidden, self.client.load_image_file,
55 image_id)
bkopilov81aaae72015-05-15 23:46:25 +030056 # reactivate image
57 self.admin_client.reactivate_image(image_id)
58 body = self.client.show_image(image_id)
59 self.assertEqual("active", body['status'])
piyush110786413994a2015-08-21 10:52:39 +053060 # non-admin user able to download image after reactivation by admin
61 body = self.client.load_image_file(image_id)
62 self.assertEqual(content, body.data)