Merge "Test image member is enforced"
diff --git a/tempest/api/image/base.py b/tempest/api/image/base.py
index ab0cb00..fcd895e 100644
--- a/tempest/api/image/base.py
+++ b/tempest/api/image/base.py
@@ -14,6 +14,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import cStringIO as StringIO
+
from tempest import clients
from tempest.common import isolated_creds
from tempest.common.utils.data_utils import rand_name
@@ -86,6 +88,36 @@
raise cls.skipException(msg)
+class BaseV1ImageMembersTest(BaseV1ImageTest):
+ @classmethod
+ def setUpClass(cls):
+ super(BaseV1ImageMembersTest, cls).setUpClass()
+ if cls.config.compute.allow_tenant_isolation:
+ creds = cls.isolated_creds.get_alt_creds()
+ username, tenant_name, password = creds
+ cls.os_alt = clients.Manager(username=username,
+ password=password,
+ tenant_name=tenant_name)
+ cls.alt_tenant_id = cls.isolated_creds.get_alt_tenant()['id']
+ else:
+ cls.os_alt = clients.AltManager()
+ identity_client = cls._get_identity_admin_client()
+ cls.alt_tenant_id = identity_client.get_tenant_by_name(
+ cls.os_alt.tenant_name)['id']
+
+ cls.alt_img_cli = cls.os_alt.image_client
+
+ def _create_image(self):
+ image_file = StringIO.StringIO('*' * 1024)
+ resp, image = self.create_image(container_format='bare',
+ disk_format='raw',
+ is_public=False,
+ data=image_file)
+ self.assertEqual(201, resp.status)
+ image_id = image['id']
+ return image_id
+
+
class BaseV2ImageTest(BaseImageTest):
@classmethod
diff --git a/tempest/api/image/v1/test_image_members.py b/tempest/api/image/v1/test_image_members.py
index 9ea9a3d..437527d 100644
--- a/tempest/api/image/v1/test_image_members.py
+++ b/tempest/api/image/v1/test_image_members.py
@@ -14,44 +14,12 @@
# License for the specific language governing permissions and limitations
# under the License.
-import cStringIO as StringIO
from tempest.api.image import base
-from tempest import clients
-from tempest.common.utils.data_utils import rand_name
-from tempest import exceptions
from tempest.test import attr
-class ImageMembersTests(base.BaseV1ImageTest):
-
- @classmethod
- def setUpClass(cls):
- super(ImageMembersTests, cls).setUpClass()
- if cls.config.compute.allow_tenant_isolation:
- creds = cls.isolated_creds.get_alt_creds()
- username, tenant_name, password = creds
- cls.os_alt = clients.Manager(username=username,
- password=password,
- tenant_name=tenant_name)
- else:
- cls.os_alt = clients.AltManager()
-
- alt_tenant_name = cls.os_alt.tenant_name
- identity_client = cls._get_identity_admin_client()
- _, tenants = identity_client.list_tenants()
- cls.alt_tenant_id = [tnt['id'] for tnt in tenants if tnt['name'] ==
- alt_tenant_name][0]
-
- def _create_image(self):
- image_file = StringIO.StringIO('*' * 1024)
- resp, image = self.create_image(container_format='bare',
- disk_format='raw',
- is_public=False,
- data=image_file)
- self.assertEqual(201, resp.status)
- image_id = image['id']
- return image_id
+class ImageMembersTest(base.BaseV1ImageMembersTest):
@attr(type='gate')
def test_add_image_member(self):
@@ -63,6 +31,9 @@
members = body['members']
members = map(lambda x: x['member_id'], members)
self.assertIn(self.alt_tenant_id, members)
+ # get image as alt user
+ resp, body = self.alt_img_cli.get_image(image)
+ self.assertEqual(200, resp.status)
@attr(type='gate')
def test_get_shared_images(self):
@@ -90,25 +61,3 @@
self.assertEqual(200, resp.status)
members = body['members']
self.assertEqual(0, len(members), str(members))
-
- @attr(type=['negative', 'gate'])
- def test_add_member_with_non_existing_image(self):
- # Add member with non existing image.
- non_exist_image = rand_name('image_')
- self.assertRaises(exceptions.NotFound, self.client.add_member,
- self.alt_tenant_id, non_exist_image)
-
- @attr(type=['negative', 'gate'])
- def test_delete_member_with_non_existing_image(self):
- # Delete member with non existing image.
- non_exist_image = rand_name('image_')
- self.assertRaises(exceptions.NotFound, self.client.delete_member,
- self.alt_tenant_id, non_exist_image)
-
- @attr(type=['negative', 'gate'])
- def test_delete_member_with_non_existing_tenant(self):
- # Delete member with non existing tenant.
- image_id = self._create_image()
- non_exist_tenant = rand_name('tenant_')
- self.assertRaises(exceptions.NotFound, self.client.delete_member,
- non_exist_tenant, image_id)
diff --git a/tempest/api/image/v1/test_image_members_negative.py b/tempest/api/image/v1/test_image_members_negative.py
new file mode 100644
index 0000000..83f7a0f
--- /dev/null
+++ b/tempest/api/image/v1/test_image_members_negative.py
@@ -0,0 +1,54 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2013 IBM Corp.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+
+from tempest.api.image import base
+from tempest.common.utils import data_utils
+from tempest import exceptions
+from tempest.test import attr
+
+
+class ImageMembersNegativeTest(base.BaseV1ImageMembersTest):
+
+ @attr(type=['negative', 'gate'])
+ def test_add_member_with_non_existing_image(self):
+ # Add member with non existing image.
+ non_exist_image = data_utils.rand_uuid()
+ self.assertRaises(exceptions.NotFound, self.client.add_member,
+ self.alt_tenant_id, non_exist_image)
+
+ @attr(type=['negative', 'gate'])
+ def test_delete_member_with_non_existing_image(self):
+ # Delete member with non existing image.
+ non_exist_image = data_utils.rand_uuid()
+ self.assertRaises(exceptions.NotFound, self.client.delete_member,
+ self.alt_tenant_id, non_exist_image)
+
+ @attr(type=['negative', 'gate'])
+ def test_delete_member_with_non_existing_tenant(self):
+ # Delete member with non existing tenant.
+ image_id = self._create_image()
+ non_exist_tenant = data_utils.rand_uuid_hex()
+ self.assertRaises(exceptions.NotFound, self.client.delete_member,
+ non_exist_tenant, image_id)
+
+ @attr(type=['negative', 'gate'])
+ def test_get_image_without_membership(self):
+ # Image is hidden from another tenants.
+ image_id = self._create_image()
+ self.assertRaises(exceptions.NotFound,
+ self.alt_img_cli.get_image,
+ image_id)
diff --git a/tempest/common/utils/data_utils.py b/tempest/common/utils/data_utils.py
index 3ab8fe0..4f93e1c 100644
--- a/tempest/common/utils/data_utils.py
+++ b/tempest/common/utils/data_utils.py
@@ -19,10 +19,19 @@
import random
import re
import urllib
+import uuid
from tempest import exceptions
+def rand_uuid():
+ return str(uuid.uuid4())
+
+
+def rand_uuid_hex():
+ return uuid.uuid4().hex
+
+
def rand_name(name='test'):
return name + "-tempest-" + str(random.randint(1, 0x7fffffff))