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 |
Anju Tiwari | c2849f2 | 2013-09-18 19:26:47 +0530 | [diff] [blame] | 21 | from tempest.common.utils.data_utils import rand_name |
| 22 | from tempest import exceptions |
Giampaolo Lauria | fd5f595 | 2013-05-15 09:44:24 -0400 | [diff] [blame] | 23 | from tempest.test import attr |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 24 | |
| 25 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 26 | class ImageMembersTests(base.BaseV1ImageTest): |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 27 | |
| 28 | @classmethod |
| 29 | def setUpClass(cls): |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 30 | super(ImageMembersTests, cls).setUpClass() |
Attila Fazekas | e949cb7 | 2013-10-08 11:34:29 +0200 | [diff] [blame] | 31 | if cls.config.compute.allow_tenant_isolation: |
| 32 | creds = cls.isolated_creds.get_alt_creds() |
| 33 | username, tenant_name, password = creds |
| 34 | cls.os_alt = clients.Manager(username=username, |
| 35 | password=password, |
| 36 | tenant_name=tenant_name) |
| 37 | else: |
| 38 | cls.os_alt = clients.AltManager() |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 39 | |
Attila Fazekas | e949cb7 | 2013-10-08 11:34:29 +0200 | [diff] [blame] | 40 | alt_tenant_name = cls.os_alt.tenant_name |
| 41 | identity_client = cls._get_identity_admin_client() |
| 42 | _, tenants = identity_client.list_tenants() |
| 43 | cls.alt_tenant_id = [tnt['id'] for tnt in tenants if tnt['name'] == |
| 44 | alt_tenant_name][0] |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 45 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 46 | def _create_image(self): |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 47 | image_file = StringIO.StringIO('*' * 1024) |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 48 | resp, image = self.create_image(container_format='bare', |
| 49 | disk_format='raw', |
Attila Fazekas | e949cb7 | 2013-10-08 11:34:29 +0200 | [diff] [blame] | 50 | is_public=False, |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 51 | data=image_file) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 52 | self.assertEqual(201, resp.status) |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 53 | image_id = image['id'] |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 54 | return image_id |
| 55 | |
Giampaolo Lauria | fd5f595 | 2013-05-15 09:44:24 -0400 | [diff] [blame] | 56 | @attr(type='gate') |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 57 | def test_add_image_member(self): |
| 58 | image = self._create_image() |
Attila Fazekas | e949cb7 | 2013-10-08 11:34:29 +0200 | [diff] [blame] | 59 | resp = self.client.add_member(self.alt_tenant_id, image) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 60 | self.assertEqual(204, resp.status) |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 61 | resp, body = self.client.get_image_membership(image) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 62 | self.assertEqual(200, resp.status) |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 63 | members = body['members'] |
| 64 | members = map(lambda x: x['member_id'], members) |
Attila Fazekas | e949cb7 | 2013-10-08 11:34:29 +0200 | [diff] [blame] | 65 | self.assertIn(self.alt_tenant_id, members) |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 66 | |
Giampaolo Lauria | fd5f595 | 2013-05-15 09:44:24 -0400 | [diff] [blame] | 67 | @attr(type='gate') |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 68 | def test_get_shared_images(self): |
| 69 | image = self._create_image() |
Attila Fazekas | e949cb7 | 2013-10-08 11:34:29 +0200 | [diff] [blame] | 70 | resp = self.client.add_member(self.alt_tenant_id, image) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 71 | self.assertEqual(204, resp.status) |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 72 | share_image = self._create_image() |
Attila Fazekas | e949cb7 | 2013-10-08 11:34:29 +0200 | [diff] [blame] | 73 | resp = self.client.add_member(self.alt_tenant_id, share_image) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 74 | self.assertEqual(204, resp.status) |
Attila Fazekas | e949cb7 | 2013-10-08 11:34:29 +0200 | [diff] [blame] | 75 | resp, body = self.client.get_shared_images(self.alt_tenant_id) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 76 | self.assertEqual(200, resp.status) |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 77 | images = body['shared_images'] |
| 78 | images = map(lambda x: x['image_id'], images) |
| 79 | self.assertIn(share_image, images) |
| 80 | self.assertIn(image, images) |
| 81 | |
Giampaolo Lauria | fd5f595 | 2013-05-15 09:44:24 -0400 | [diff] [blame] | 82 | @attr(type='gate') |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 83 | def test_remove_member(self): |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 84 | image_id = self._create_image() |
Attila Fazekas | e949cb7 | 2013-10-08 11:34:29 +0200 | [diff] [blame] | 85 | resp = self.client.add_member(self.alt_tenant_id, image_id) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 86 | self.assertEqual(204, resp.status) |
Attila Fazekas | e949cb7 | 2013-10-08 11:34:29 +0200 | [diff] [blame] | 87 | resp = self.client.delete_member(self.alt_tenant_id, image_id) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 88 | self.assertEqual(204, resp.status) |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 89 | resp, body = self.client.get_image_membership(image_id) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 90 | self.assertEqual(200, resp.status) |
Matthew Treinish | fa23cf8 | 2013-03-06 14:23:02 -0500 | [diff] [blame] | 91 | members = body['members'] |
Attila Fazekas | e949cb7 | 2013-10-08 11:34:29 +0200 | [diff] [blame] | 92 | self.assertEqual(0, len(members), str(members)) |
Anju Tiwari | c2849f2 | 2013-09-18 19:26:47 +0530 | [diff] [blame] | 93 | |
| 94 | @attr(type=['negative', 'gate']) |
| 95 | def test_add_member_with_non_existing_image(self): |
| 96 | # Add member with non existing image. |
| 97 | non_exist_image = rand_name('image_') |
| 98 | self.assertRaises(exceptions.NotFound, self.client.add_member, |
Attila Fazekas | e949cb7 | 2013-10-08 11:34:29 +0200 | [diff] [blame] | 99 | self.alt_tenant_id, non_exist_image) |
Anju Tiwari | c2849f2 | 2013-09-18 19:26:47 +0530 | [diff] [blame] | 100 | |
| 101 | @attr(type=['negative', 'gate']) |
| 102 | def test_delete_member_with_non_existing_image(self): |
| 103 | # Delete member with non existing image. |
| 104 | non_exist_image = rand_name('image_') |
| 105 | self.assertRaises(exceptions.NotFound, self.client.delete_member, |
Attila Fazekas | e949cb7 | 2013-10-08 11:34:29 +0200 | [diff] [blame] | 106 | self.alt_tenant_id, non_exist_image) |
Anju Tiwari | c2849f2 | 2013-09-18 19:26:47 +0530 | [diff] [blame] | 107 | |
| 108 | @attr(type=['negative', 'gate']) |
| 109 | def test_delete_member_with_non_existing_tenant(self): |
| 110 | # Delete member with non existing tenant. |
| 111 | image_id = self._create_image() |
| 112 | non_exist_tenant = rand_name('tenant_') |
| 113 | self.assertRaises(exceptions.NotFound, self.client.delete_member, |
| 114 | non_exist_tenant, image_id) |