Best Python code snippet using tempest_python
base.py
Source:base.py
...40 """Wrapper that returns a test image."""41 if 'name' not in kwargs:42 name = data_utils.rand_name(cls.__name__ + "-image")43 kwargs['name'] = name44 params = cls._get_create_params(**kwargs)45 if data:46 # NOTE: On glance v1 API, the data should be passed on47 # a header. Then here handles the data separately.48 params['data'] = data49 image = cls.client.create_image(**params)50 # Image objects returned by the v1 client have the image51 # data inside a dict that is keyed against 'image'.52 if 'image' in image:53 image = image['image']54 cls.created_images.append(image['id'])55 cls.addClassResourceCleanup(cls.client.wait_for_resource_deletion,56 image['id'])57 cls.addClassResourceCleanup(test_utils.call_and_ignore_notfound_exc,58 cls.client.delete_image, image['id'])59 return image60 @classmethod61 def _get_create_params(cls, **kwargs):62 return kwargs63class BaseV1ImageTest(BaseImageTest):64 @classmethod65 def skip_checks(cls):66 super(BaseV1ImageTest, cls).skip_checks()67 if not CONF.image_feature_enabled.api_v1:68 msg = "Glance API v1 not supported"69 raise cls.skipException(msg)70 @classmethod71 def setup_clients(cls):72 super(BaseV1ImageTest, cls).setup_clients()73 cls.client = cls.os_primary.image_client74 @classmethod75 def _get_create_params(cls, **kwargs):76 return {'headers': common_image.image_meta_to_headers(**kwargs)}77class BaseV1ImageMembersTest(BaseV1ImageTest):78 credentials = ['primary', 'alt']79 @classmethod80 def setup_clients(cls):81 super(BaseV1ImageMembersTest, cls).setup_clients()82 cls.image_member_client = cls.os_primary.image_member_client83 cls.alt_image_member_client = cls.os_alt.image_member_client84 cls.alt_img_cli = cls.os_alt.image_client85 @classmethod86 def resource_setup(cls):87 super(BaseV1ImageMembersTest, cls).resource_setup()88 cls.alt_tenant_id = cls.alt_image_member_client.tenant_id89 def _create_image(self):...
linode.py
Source:linode.py
...31 def _get_linodes(self):32 """ Utility helper caching the linodes in a dictionary """33 linodes = self.client.linode.instances()34 return {i.label:i for i in linodes}35 def _get_create_params(self, template, ssh_pubkey):36 """37 Utility helper to aggregate common creation params like SSH keys and38 image name39 """40 params = {41 "sshkey": ssh_pubkey,42 "image": self.client.images(li.Image.label == template).first(),43 }44 return params45 def vm_start(self, name, sync=True):46 """ Start a machine with label '@name' """47 linode = self.linodes[name]48 if linode.status != "running":49 linode.boot()50 if sync:51 self._sync_wait(name, "running")52 def vm_stop(self, name, sync=True):53 """ Stop a machine with label '@name' """54 linode = self.linodes[name]55 if linode.status == "running":56 linode.shutdown()57 if sync:58 self._sync_wait(name, "offline")59 def vm_rebuild(self, name, template, ssh_pubkey=None, sync=True):60 """ Rebuild a machine with label '@name' from template '@template' """61 try:62 linode = self.linodes[name]63 except KeyError:64 sys.exit(f"Machine '{name} not found'")65 params = self._get_create_params(template, ssh_pubkey)66 self.vm_stop(name, sync)67 linode.rebuild(params["image"], authorized_keys=[params["sshkey"]])68 if sync:69 self._sync_wait(name, "running")70 def vm_new(self, name, template, ssh_pubkey=None, sync=True):71 """ Create a new machine with label '@name' from template '@template' """72 try:73 linode = self.linodes[name]74 sys.exit(f"Machine '{name}' already exists")75 except KeyError:76 pass77 # Linode currently doesn't support resize on boot disks instantiated78 # from custom images, so we need to hack around a bit.79 params = self._get_create_params(template, ssh_pubkey)80 print(f"Creating an empty instance '{name}'...", end="", flush=True)81 instance = self.client.linode.instance_create(LINODE_TYPE,82 LINODE_REGION,83 label=name)84 # Populate our internal instance cache85 self.linodes[name] = instance86 # Now we need to wait for an empty instance to be created87 # TODO: Once Linode supports boot disk resize with custom images, we88 # can drop the below code89 if sync:90 self._sync_wait(name, "offline")91 print("DONE")92 swap_disk_size = 102493 boot_disk_size = instance.specs.disk - swap_disk_size...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!