How to use image_create_and_upload method in tempest

Best Python code snippet using tempest_python

test_image_caching.py

Source:test_image_caching.py Github

copy

Full Screen

...43 # Check to see if we should even be running these tests.44 if not CONF.image.image_caching_enabled:45 raise cls.skipException('Target system is not configured with '46 'glance caching')47 def image_create_and_upload(self, upload=True, **kwargs):48 """Wrapper that returns a test image."""49 if 'name' not in kwargs:50 name = data_utils.rand_name(self.__name__ + "-image")51 kwargs['name'] = name52 params = dict(kwargs)53 image = self.create_image(**params)54 self.assertEqual('queued', image['status'])55 if not upload:56 return image57 file_content = data_utils.random_bytes()58 image_file = io.BytesIO(file_content)59 self.client.store_image_file(image['id'], image_file)60 image = self.client.show_image(image['id'])61 return image62 def _assertCheckQueues(self, queued_images):63 for image in self.cached_info:64 if self.cached_info[image] == 'queued':65 self.assertIn(image, queued_images)66 def _assertCheckCache(self, cached_images):67 cached_list = []68 for image in cached_images:69 cached_list.append(image['image_id'])70 for image in self.cached_info:71 if self.cached_info[image] == 'cached':72 self.assertIn(image, cached_list)73 @decorators.idempotent_id('4bf6adba-2f9f-47e9-a6d5-37f21ad4387c')74 def test_image_caching_cycle(self):75 """Test image cache APIs"""76 # Ensure that non-admin user is not allowed to perform caching77 # operations78 self.assertRaises(lib_exc.Forbidden,79 self.os_primary.image_cache_client.list_cache)80 # Check there is nothing is queued for cached by us81 output = self.os_admin.image_cache_client.list_cache()82 self._assertCheckQueues(output['queued_images'])83 self._assertCheckCache(output['cached_images'])84 # Non-existing image should raise NotFound exception85 self.assertRaises(lib_exc.NotFound,86 self.os_admin.image_cache_client.cache_queue,87 'non-existing-image-id')88 # Verify that we can not use queued image for queueing89 image = self.image_create_and_upload(name='queued', upload=False)90 self.assertRaises(lib_exc.BadRequest,91 self.os_admin.image_cache_client.cache_queue,92 image['id'])93 # Create one image94 image = self.image_create_and_upload(name='first',95 container_format='bare',96 disk_format='raw',97 visibility='private')98 self.assertEqual('active', image['status'])99 # Queue image for caching100 self.os_admin.image_cache_client.cache_queue(image['id'])101 self.cached_info[image['id']] = 'queued'102 # Verify that we have 1 image for queueing and 0 for caching103 output = self.os_admin.image_cache_client.list_cache()104 self._assertCheckQueues(output['queued_images'])105 self._assertCheckCache(output['cached_images'])106 # Wait for image caching107 LOG.info("Waiting for image %s to get cached", image['id'])108 caching = waiters.wait_for_caching(...

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