Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 1 | # 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 | |
| 17 | import cStringIO as StringIO |
| 18 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 19 | from tempest.api.image import base |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 20 | from tempest import clients |
Giampaolo Lauria | fd5f595 | 2013-05-15 09:44:24 -0400 | [diff] [blame] | 21 | from tempest.test import attr |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 22 | |
| 23 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 24 | class ImageMembersTests(base.BaseV1ImageTest): |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 25 | |
| 26 | @classmethod |
| 27 | def setUpClass(cls): |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 28 | super(ImageMembersTests, cls).setUpClass() |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 29 | admin = clients.AdminManager(interface='json') |
| 30 | cls.admin_client = admin.identity_client |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 31 | cls.tenants = cls._get_tenants() |
| 32 | |
| 33 | @classmethod |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 34 | def _get_tenants(cls): |
| 35 | resp, tenants = cls.admin_client.list_tenants() |
| 36 | tenants = map(lambda x: x['id'], tenants) |
| 37 | return tenants |
| 38 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 39 | def _create_image(self): |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 40 | image_file = StringIO.StringIO('*' * 1024) |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 41 | resp, image = self.create_image(container_format='bare', |
| 42 | disk_format='raw', |
| 43 | is_public=True, |
| 44 | data=image_file) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame^] | 45 | self.assertEqual(201, resp.status) |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 46 | image_id = image['id'] |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 47 | return image_id |
| 48 | |
Giampaolo Lauria | fd5f595 | 2013-05-15 09:44:24 -0400 | [diff] [blame] | 49 | @attr(type='gate') |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 50 | def test_add_image_member(self): |
| 51 | image = self._create_image() |
| 52 | resp = self.client.add_member(self.tenants[0], image) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame^] | 53 | self.assertEqual(204, resp.status) |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 54 | resp, body = self.client.get_image_membership(image) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame^] | 55 | self.assertEqual(200, resp.status) |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 56 | members = body['members'] |
| 57 | members = map(lambda x: x['member_id'], members) |
| 58 | self.assertIn(self.tenants[0], members) |
| 59 | |
Giampaolo Lauria | fd5f595 | 2013-05-15 09:44:24 -0400 | [diff] [blame] | 60 | @attr(type='gate') |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 61 | def test_get_shared_images(self): |
| 62 | image = self._create_image() |
| 63 | resp = self.client.add_member(self.tenants[0], image) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame^] | 64 | self.assertEqual(204, resp.status) |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 65 | share_image = self._create_image() |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 66 | resp = self.client.add_member(self.tenants[0], share_image) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame^] | 67 | self.assertEqual(204, resp.status) |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 68 | resp, body = self.client.get_shared_images(self.tenants[0]) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame^] | 69 | self.assertEqual(200, resp.status) |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 70 | images = body['shared_images'] |
| 71 | images = map(lambda x: x['image_id'], images) |
| 72 | self.assertIn(share_image, images) |
| 73 | self.assertIn(image, images) |
| 74 | |
Giampaolo Lauria | fd5f595 | 2013-05-15 09:44:24 -0400 | [diff] [blame] | 75 | @attr(type='gate') |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 76 | def test_remove_member(self): |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 77 | image_id = self._create_image() |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 78 | resp = self.client.add_member(self.tenants[0], image_id) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame^] | 79 | self.assertEqual(204, resp.status) |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 80 | resp = self.client.delete_member(self.tenants[0], image_id) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame^] | 81 | self.assertEqual(204, resp.status) |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 82 | resp, body = self.client.get_image_membership(image_id) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame^] | 83 | self.assertEqual(200, resp.status) |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 84 | members = body['members'] |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame^] | 85 | self.assertEqual(0, len(members)) |