blob: 437527dcef30aca93790ae9727665f3afd283279 [file] [log] [blame]
Matthew Treinishfa23cf82013-03-06 14:23:02 -05001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 IBM Corp.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
Matthew Treinishfa23cf82013-03-06 14:23:02 -050017
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.image import base
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040019from tempest.test import attr
Matthew Treinishfa23cf82013-03-06 14:23:02 -050020
21
Attila Fazekasa709b762013-10-08 11:52:44 +020022class ImageMembersTest(base.BaseV1ImageMembersTest):
Matthew Treinishfa23cf82013-03-06 14:23:02 -050023
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040024 @attr(type='gate')
Matthew Treinishfa23cf82013-03-06 14:23:02 -050025 def test_add_image_member(self):
26 image = self._create_image()
Attila Fazekase949cb72013-10-08 11:34:29 +020027 resp = self.client.add_member(self.alt_tenant_id, image)
Chang Bo Guofc77e932013-09-16 17:38:26 -070028 self.assertEqual(204, resp.status)
Matthew Treinishfa23cf82013-03-06 14:23:02 -050029 resp, body = self.client.get_image_membership(image)
Chang Bo Guofc77e932013-09-16 17:38:26 -070030 self.assertEqual(200, resp.status)
Matthew Treinishfa23cf82013-03-06 14:23:02 -050031 members = body['members']
32 members = map(lambda x: x['member_id'], members)
Attila Fazekase949cb72013-10-08 11:34:29 +020033 self.assertIn(self.alt_tenant_id, members)
Attila Fazekasa709b762013-10-08 11:52:44 +020034 # get image as alt user
35 resp, body = self.alt_img_cli.get_image(image)
36 self.assertEqual(200, resp.status)
Matthew Treinishfa23cf82013-03-06 14:23:02 -050037
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040038 @attr(type='gate')
Matthew Treinishfa23cf82013-03-06 14:23:02 -050039 def test_get_shared_images(self):
40 image = self._create_image()
Attila Fazekase949cb72013-10-08 11:34:29 +020041 resp = self.client.add_member(self.alt_tenant_id, image)
Chang Bo Guofc77e932013-09-16 17:38:26 -070042 self.assertEqual(204, resp.status)
Matthew Treinishce3ef922013-03-11 14:02:46 -040043 share_image = self._create_image()
Attila Fazekase949cb72013-10-08 11:34:29 +020044 resp = self.client.add_member(self.alt_tenant_id, share_image)
Chang Bo Guofc77e932013-09-16 17:38:26 -070045 self.assertEqual(204, resp.status)
Attila Fazekase949cb72013-10-08 11:34:29 +020046 resp, body = self.client.get_shared_images(self.alt_tenant_id)
Chang Bo Guofc77e932013-09-16 17:38:26 -070047 self.assertEqual(200, resp.status)
Matthew Treinishfa23cf82013-03-06 14:23:02 -050048 images = body['shared_images']
49 images = map(lambda x: x['image_id'], images)
50 self.assertIn(share_image, images)
51 self.assertIn(image, images)
52
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040053 @attr(type='gate')
Matthew Treinishfa23cf82013-03-06 14:23:02 -050054 def test_remove_member(self):
Matthew Treinishce3ef922013-03-11 14:02:46 -040055 image_id = self._create_image()
Attila Fazekase949cb72013-10-08 11:34:29 +020056 resp = self.client.add_member(self.alt_tenant_id, image_id)
Chang Bo Guofc77e932013-09-16 17:38:26 -070057 self.assertEqual(204, resp.status)
Attila Fazekase949cb72013-10-08 11:34:29 +020058 resp = self.client.delete_member(self.alt_tenant_id, image_id)
Chang Bo Guofc77e932013-09-16 17:38:26 -070059 self.assertEqual(204, resp.status)
Matthew Treinishfa23cf82013-03-06 14:23:02 -050060 resp, body = self.client.get_image_membership(image_id)
Chang Bo Guofc77e932013-09-16 17:38:26 -070061 self.assertEqual(200, resp.status)
Matthew Treinishfa23cf82013-03-06 14:23:02 -050062 members = body['members']
Attila Fazekase949cb72013-10-08 11:34:29 +020063 self.assertEqual(0, len(members), str(members))