From e044dada336a8cd081598172d042fc5453792dd1 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Fri, 15 Jan 2021 12:45:16 -0800 Subject: [PATCH] Test glance reserved properties This verifies that glance enforces its reserved property namespace(s). Change-Id: I80b908d2b6483d1fa1ab7a505d4f4c062d3944ae Related-Bug: #1912001 Depends-On: https://review.opendev.org/c/openstack/devstack/+/771252 Depends-On: https://review.opendev.org/c/openstack/glance/+/771070 --- tempest/api/image/v2/test_images_negative.py | 42 ++++++++++++++++++++ tempest/config.py | 7 ++++ 2 files changed, 49 insertions(+) diff --git a/tempest/api/image/v2/test_images_negative.py b/tempest/api/image/v2/test_images_negative.py index dc2bb96758..810c37c205 100644 --- a/tempest/api/image/v2/test_images_negative.py +++ b/tempest/api/image/v2/test_images_negative.py @@ -15,10 +15,13 @@ # under the License. from tempest.api.image import base +from tempest import config from tempest.lib.common.utils import data_utils from tempest.lib import decorators from tempest.lib import exceptions as lib_exc +CONF = config.CONF + class ImagesNegativeTest(base.BaseV2ImageTest): @@ -114,3 +117,42 @@ class ImagesNegativeTest(base.BaseV2ImageTest): self.assertRaises(lib_exc.Forbidden, self.client.delete_image, image['id']) + + @decorators.attr(type=['negative']) + @decorators.idempotent_id('a0ae75d4-ce9c-4576-b823-aba04c8acabd') + def test_update_image_reserved_property(self): + """Attempt to add a reserved property to an image. + + Glance bans some internal-use-only properties such that they will + cause a PATCH to fail. Since os_glance_* is banned, we can use a + key in that namespace here. + """ + if not CONF.image_feature_enabled.os_glance_reserved: + raise self.skipException('os_glance_reserved is not enabled') + + image = self.create_image(name='test', + container_format='bare', + disk_format='raw') + self.assertRaises(lib_exc.Forbidden, + self.client.update_image, + image['id'], [{'add': '/os_glance_foo', + 'value': 'bar'}]) + + @decorators.attr(type=['negative']) + @decorators.idempotent_id('e3fb7df8-2742-4143-8976-f1b26870f0a0') + def test_create_image_reserved_property(self): + """Attempt to create an image with a reserved property. + + Glance bans some internal-use-only properties such that they will + cause an image create to fail. Since os_glance_* is banned, we can + use a key in that namespace here. + """ + if not CONF.image_feature_enabled.os_glance_reserved: + raise self.skipException('os_glance_reserved is not enabled') + + self.assertRaises(lib_exc.Forbidden, + self.create_image, + name='test', + container_format='bare', + disk_format='raw', + os_glance_foo='bar') diff --git a/tempest/config.py b/tempest/config.py index 382b80f11e..b36643a16a 100644 --- a/tempest/config.py +++ b/tempest/config.py @@ -689,6 +689,13 @@ ImageFeaturesGroup = [ cfg.BoolOpt('import_image', default=False, help="Is image import feature enabled"), + # NOTE(danms): Starting mid-Wallaby glance began enforcing the + # previously-informal requirement that os_glance_* properties are + # reserved for internal use. Thus, we can only run these checks + # if we know we are on a new enough glance. + cfg.BoolOpt('os_glance_reserved', + default=False, + help="Should we check that os_glance namespace is reserved"), ] network_group = cfg.OptGroup(name='network',