How to use image_meta_to_headers method in tempest

Best Python code snippet using tempest_python

test_images_rbac.py

Source:test_images_rbac.py Github

copy

Full Screen

...55 def resource_setup(cls):56 super(ImagesRbacTest, cls).resource_setup()57 params = {'name': data_utils.rand_name(cls.__name__ + '-image')}58 if CONF.image_feature_enabled.api_v1:59 params = {'headers': common_image.image_meta_to_headers(**params)}60 cls.image = cls.glance_image_client.create_image(**params)61 cls.addClassResourceCleanup(62 cls.glance_image_client.wait_for_resource_deletion,63 cls.image['id'])64 cls.addClassResourceCleanup(65 cls.glance_image_client.delete_image, cls.image['id'])66 @decorators.idempotent_id('b861f302-b72b-4055-81db-c62ff30b136d')67 @rbac_rule_validation.action(68 service="glance",69 rules=["get_images"])70 def test_list_images(self):71 with self.override_role():72 self.compute_images_client.list_images()73 @decorators.idempotent_id('4365ae0f-15ee-4b54-a527-1679faaed140')74 @rbac_rule_validation.action(75 service="glance",76 rules=["get_images"])77 def test_list_images_with_details(self):78 with self.override_role():79 self.compute_images_client.list_images(detail=True)80 @decorators.idempotent_id('886dfcae-51bf-4610-9e52-82d7189524c2')81 @rbac_rule_validation.action(82 service="glance",83 rules=["get_image"])84 def test_show_image_details(self):85 with self.override_role():86 self.compute_images_client.show_image(self.image['id'])87 @decorators.idempotent_id('5888c7aa-0803-46d4-a3fb-5d4729465cd5')88 @rbac_rule_validation.action(89 service="glance",90 rules=["delete_image"])91 def test_delete_image(self):92 image = self.glance_image_client.create_image(93 name=data_utils.rand_name(self.__class__.__name__ + '-image'))94 self.addCleanup(test_utils.call_and_ignore_notfound_exc,95 self.glance_image_client.delete_image, image['id'])96 with self.override_role():97 self.compute_images_client.delete_image(image['id'])98class ImagesMetadataRbacTest(rbac_base.BaseV2ComputeRbacTest):99 """RBAC tests for the Nova metadata images API.100 These APIs are proxy calls to the Image service. Consequently, no Nova101 policy actions are enforced; instead, only Glance policy actions are102 enforced. As such, these tests check that only Glance policy actions are103 executed.104 """105 # These tests will fail with a 404 starting from microversion 2.39.106 # See the following link for details:107 # https://docs.openstack.org/api-ref/compute/#images-deprecated108 max_microversion = '2.38'109 @classmethod110 def skip_checks(cls):111 super(ImagesMetadataRbacTest, cls).skip_checks()112 if not CONF.service_available.glance:113 skip_msg = ("%s skipped as glance is not available" % cls.__name__)114 raise cls.skipException(skip_msg)115 @classmethod116 def setup_clients(cls):117 super(ImagesMetadataRbacTest, cls).setup_clients()118 if CONF.image_feature_enabled.api_v2:119 cls.glance_image_client = cls.os_primary.image_client_v2120 elif CONF.image_feature_enabled.api_v1:121 cls.glance_image_client = cls.os_primary.image_client122 else:123 raise lib_exc.InvalidConfiguration(124 'Either api_v1 or api_v2 must be True in '125 '[image-feature-enabled].')126 @classmethod127 def resource_setup(cls):128 super(ImagesMetadataRbacTest, cls).resource_setup()129 params = {'name': data_utils.rand_name(cls.__name__ + '-image')}130 if CONF.image_feature_enabled.api_v1:131 params = {'headers': common_image.image_meta_to_headers(**params)}132 cls.image = cls.glance_image_client.create_image(**params)133 cls.addClassResourceCleanup(134 cls.glance_image_client.wait_for_resource_deletion,135 cls.image['id'])136 cls.addClassResourceCleanup(137 cls.glance_image_client.delete_image, cls.image['id'])138 @decorators.idempotent_id('dbe09d4c-e615-48cb-b908-a06a0f410a8e')139 @rbac_rule_validation.action(140 service="glance",141 rules=["get_image"])142 def test_show_image_metadata_item(self):143 self.compute_images_client.set_image_metadata(self.image['id'],144 meta={'foo': 'bar'})145 self.addCleanup(self.compute_images_client.delete_image_metadata_item,146 self.image['id'], key='foo')147 with self.override_role():148 self.compute_images_client.show_image_metadata_item(149 self.image['id'], key='foo')150 @decorators.idempotent_id('59f66079-d564-47e8-81b0-03c2e84d339e')151 @rbac_rule_validation.action(152 service="glance",153 rules=["get_image"])154 def test_list_image_metadata(self):155 with self.override_role():156 self.compute_images_client.list_image_metadata(self.image['id'])157 @decorators.idempotent_id('575604aa-909f-4b1b-a5a5-cfae1f63044b')158 @rbac_rule_validation.action(159 service="glance",160 rules=["modify_image"])161 def test_create_image_metadata(self):162 with self.override_role():163 # NOTE(felipemonteiro): Although the name of the client function164 # appears wrong, it's actually correct: update_image_metadata does165 # an http post.166 self.compute_images_client.update_image_metadata(167 self.image['id'], meta={'foo': 'bar'})168 self.addCleanup(self.compute_images_client.delete_image_metadata_item,169 self.image['id'], key='foo')170 @decorators.idempotent_id('fb8c4eb6-00e5-454c-b8bc-0e801ec369f1')171 @rbac_rule_validation.action(172 service="glance",173 rules=["modify_image"])174 def test_update_image_metadata(self):175 with self.override_role():176 self.compute_images_client.set_image_metadata(self.image['id'],177 meta={'foo': 'bar'})178 self.addCleanup(self.compute_images_client.delete_image_metadata_item,179 self.image['id'], key='foo')180 @decorators.idempotent_id('9c7c2036-af9b-49a8-8ba1-09b027ee5def')181 @rbac_rule_validation.action(182 service="glance",183 rules=["modify_image"])184 def test_update_image_metadata_item(self):185 with self.override_role():186 self.compute_images_client.set_image_metadata_item(187 self.image['id'], meta={'foo': 'bar'}, key='foo')188 self.addCleanup(self.compute_images_client.delete_image_metadata_item,189 self.image['id'], key='foo')190 @decorators.idempotent_id('5f0dc4e6-0761-4613-9bde-0a6acdc78f46')191 @rbac_rule_validation.action(192 service="glance",193 rules=["modify_image"])194 def test_delete_image_metadata_item(self):195 self.compute_images_client.set_image_metadata(self.image['id'],196 meta={'foo': 'bar'})197 self.addCleanup(test_utils.call_and_ignore_notfound_exc,198 self.compute_images_client.delete_image_metadata_item,199 self.image['id'], key='foo')200 with self.override_role():201 self.compute_images_client.delete_image_metadata_item(202 self.image['id'], key='foo')203class ImageSizeRbacTest(rbac_base.BaseV2ComputeRbacTest):204 """Tests the ``image_size`` compute policies.205 NOTE(felipemonteiro): If Patrole is enhanced to test multiple policies206 simultaneously, these policy actions can be combined with the related207 tests from ``ImagesRbacTest`` above.208 """209 # These tests will fail with a 404 starting from microversion 2.36.210 # See the following link for details:211 # https://docs.openstack.org/api-ref/compute/#images-deprecated212 max_microversion = '2.35'213 @classmethod214 def skip_checks(cls):215 super(ImageSizeRbacTest, cls).skip_checks()216 if not CONF.service_available.glance:217 skip_msg = ("%s skipped as glance is not available" % cls.__name__)218 raise cls.skipException(skip_msg)219 @classmethod220 def setup_clients(cls):221 super(ImageSizeRbacTest, cls).setup_clients()222 if CONF.image_feature_enabled.api_v2:223 cls.glance_image_client = cls.os_primary.image_client_v2224 elif CONF.image_feature_enabled.api_v1:225 cls.glance_image_client = cls.os_primary.image_client226 else:227 raise lib_exc.InvalidConfiguration(228 'Either api_v1 or api_v2 must be True in '229 '[image-feature-enabled].')230 @classmethod231 def resource_setup(cls):232 super(ImageSizeRbacTest, cls).resource_setup()233 params = {'name': data_utils.rand_name(cls.__name__ + '-image')}234 if CONF.image_feature_enabled.api_v1:235 params = {'headers': common_image.image_meta_to_headers(**params)}236 cls.image = cls.glance_image_client.create_image(**params)237 cls.addClassResourceCleanup(238 cls.glance_image_client.wait_for_resource_deletion,239 cls.image['id'])240 cls.addClassResourceCleanup(241 cls.glance_image_client.delete_image, cls.image['id'])242 @testtools.skipIf(CONF.policy_feature_enabled.removed_nova_policies_stein,243 "This API extension policy was removed in Stein")244 @decorators.idempotent_id('fe34d2a6-5743-45bf-8f92-a1d703d7c7ab')245 @rbac_rule_validation.action(246 service="nova",247 rules=["os_compute_api:image-size"])248 def test_show_image_includes_image_size(self):249 with self.override_role():...

Full Screen

Full Screen

test_image.py

Source:test_image.py Github

copy

Full Screen

...32 'status': 'queued',33 'name': 'New Http Image'34 }35 self.assertEqual(expected, observed)36 def test_image_meta_to_headers(self):37 observed = image.image_meta_to_headers(38 name='test',39 container_format='wrong',40 disk_format='vhd',41 copy_from='http://localhost/images/10',42 properties={'foo': 'bar'},43 api={'abc': 'def'},44 purge_props=True)45 expected = {46 'x-image-meta-name': 'test',47 'x-image-meta-container_format': 'wrong',48 'x-image-meta-disk_format': 'vhd',49 'x-glance-api-copy-from': 'http://localhost/images/10',50 'x-image-meta-property-foo': 'bar',51 'x-glance-api-property-abc': 'def',...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful