blob: e6a078eebd92d8de88a2ecea2b782d11d4c4af7c [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
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040017from tempest.test import attr
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
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040022 @attr(type='gate')
Matthew Treinishfa23cf82013-03-06 14:23:02 -050023 def test_add_image_member(self):
24 image = self._create_image()
Attila Fazekase949cb72013-10-08 11:34:29 +020025 resp = self.client.add_member(self.alt_tenant_id, image)
Chang Bo Guofc77e932013-09-16 17:38:26 -070026 self.assertEqual(204, resp.status)
Matthew Treinishfa23cf82013-03-06 14:23:02 -050027 resp, body = self.client.get_image_membership(image)
Chang Bo Guofc77e932013-09-16 17:38:26 -070028 self.assertEqual(200, resp.status)
Matthew Treinishfa23cf82013-03-06 14:23:02 -050029 members = body['members']
30 members = map(lambda x: x['member_id'], members)
Attila Fazekase949cb72013-10-08 11:34:29 +020031 self.assertIn(self.alt_tenant_id, members)
Attila Fazekasa709b762013-10-08 11:52:44 +020032 # get image as alt user
33 resp, body = self.alt_img_cli.get_image(image)
34 self.assertEqual(200, resp.status)
Matthew Treinishfa23cf82013-03-06 14:23:02 -050035
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040036 @attr(type='gate')
Matthew Treinishfa23cf82013-03-06 14:23:02 -050037 def test_get_shared_images(self):
38 image = self._create_image()
Attila Fazekase949cb72013-10-08 11:34:29 +020039 resp = self.client.add_member(self.alt_tenant_id, image)
Chang Bo Guofc77e932013-09-16 17:38:26 -070040 self.assertEqual(204, resp.status)
Matthew Treinishce3ef922013-03-11 14:02:46 -040041 share_image = self._create_image()
Attila Fazekase949cb72013-10-08 11:34:29 +020042 resp = self.client.add_member(self.alt_tenant_id, share_image)
Chang Bo Guofc77e932013-09-16 17:38:26 -070043 self.assertEqual(204, resp.status)
Attila Fazekase949cb72013-10-08 11:34:29 +020044 resp, body = self.client.get_shared_images(self.alt_tenant_id)
Chang Bo Guofc77e932013-09-16 17:38:26 -070045 self.assertEqual(200, resp.status)
Matthew Treinishfa23cf82013-03-06 14:23:02 -050046 images = body['shared_images']
47 images = map(lambda x: x['image_id'], images)
48 self.assertIn(share_image, images)
49 self.assertIn(image, images)
50
Giampaolo Lauriafd5f5952013-05-15 09:44:24 -040051 @attr(type='gate')
Matthew Treinishfa23cf82013-03-06 14:23:02 -050052 def test_remove_member(self):
Matthew Treinishce3ef922013-03-11 14:02:46 -040053 image_id = self._create_image()
Attila Fazekase949cb72013-10-08 11:34:29 +020054 resp = self.client.add_member(self.alt_tenant_id, image_id)
Chang Bo Guofc77e932013-09-16 17:38:26 -070055 self.assertEqual(204, resp.status)
Attila Fazekase949cb72013-10-08 11:34:29 +020056 resp = self.client.delete_member(self.alt_tenant_id, image_id)
Chang Bo Guofc77e932013-09-16 17:38:26 -070057 self.assertEqual(204, resp.status)
Matthew Treinishfa23cf82013-03-06 14:23:02 -050058 resp, body = self.client.get_image_membership(image_id)
Chang Bo Guofc77e932013-09-16 17:38:26 -070059 self.assertEqual(200, resp.status)
Matthew Treinishfa23cf82013-03-06 14:23:02 -050060 members = body['members']
Attila Fazekase949cb72013-10-08 11:34:29 +020061 self.assertEqual(0, len(members), str(members))