blob: d57cb93024913a5563984e89371f81b29ea17de2 [file] [log] [blame]
Matthew Treinishfa23cf82013-03-06 14:23:02 -05001# Copyright 2013 IBM Corp.
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
Matthew Treinishfa23cf82013-03-06 14:23:02 -050015
Sean Dague1937d092013-05-17 16:36:38 -040016from tempest.api.image import base
Eiichi Aikawa9012f462014-03-05 16:43:32 +090017from tempest import test
Matthew Treinishfa23cf82013-03-06 14:23:02 -050018
19
Attila Fazekasa709b762013-10-08 11:52:44 +020020class ImageMembersTest(base.BaseV1ImageMembersTest):
Matthew Treinishfa23cf82013-03-06 14:23:02 -050021
Chris Hoge7579c1a2015-02-26 14:12:15 -080022 @test.idempotent_id('1d6ef640-3a20-4c84-8710-d95828fdb6ad')
Matthew Treinishfa23cf82013-03-06 14:23:02 -050023 def test_add_image_member(self):
24 image = self._create_image()
David Kranz9c3b3b62014-06-19 16:05:53 -040025 self.client.add_member(self.alt_tenant_id, image)
David Kranz34f18782015-01-06 13:43:55 -050026 body = self.client.get_image_membership(image)
Matthew Treinishfa23cf82013-03-06 14:23:02 -050027 members = body['members']
28 members = map(lambda x: x['member_id'], members)
Attila Fazekase949cb72013-10-08 11:34:29 +020029 self.assertIn(self.alt_tenant_id, members)
Attila Fazekasa709b762013-10-08 11:52:44 +020030 # get image as alt user
David Kranz9c3b3b62014-06-19 16:05:53 -040031 self.alt_img_cli.get_image(image)
Matthew Treinishfa23cf82013-03-06 14:23:02 -050032
Chris Hoge7579c1a2015-02-26 14:12:15 -080033 @test.idempotent_id('6a5328a5-80e8-4b82-bd32-6c061f128da9')
Matthew Treinishfa23cf82013-03-06 14:23:02 -050034 def test_get_shared_images(self):
35 image = self._create_image()
David Kranz9c3b3b62014-06-19 16:05:53 -040036 self.client.add_member(self.alt_tenant_id, image)
Matthew Treinishce3ef922013-03-11 14:02:46 -040037 share_image = self._create_image()
David Kranz9c3b3b62014-06-19 16:05:53 -040038 self.client.add_member(self.alt_tenant_id, share_image)
David Kranz34f18782015-01-06 13:43:55 -050039 body = self.client.get_shared_images(self.alt_tenant_id)
Matthew Treinishfa23cf82013-03-06 14:23:02 -050040 images = body['shared_images']
41 images = map(lambda x: x['image_id'], images)
42 self.assertIn(share_image, images)
43 self.assertIn(image, images)
44
Chris Hoge7579c1a2015-02-26 14:12:15 -080045 @test.idempotent_id('a76a3191-8948-4b44-a9d6-4053e5f2b138')
Matthew Treinishfa23cf82013-03-06 14:23:02 -050046 def test_remove_member(self):
Matthew Treinishce3ef922013-03-11 14:02:46 -040047 image_id = self._create_image()
David Kranz9c3b3b62014-06-19 16:05:53 -040048 self.client.add_member(self.alt_tenant_id, image_id)
49 self.client.delete_member(self.alt_tenant_id, image_id)
David Kranz34f18782015-01-06 13:43:55 -050050 body = self.client.get_image_membership(image_id)
Matthew Treinishfa23cf82013-03-06 14:23:02 -050051 members = body['members']
Attila Fazekase949cb72013-10-08 11:34:29 +020052 self.assertEqual(0, len(members), str(members))