Best Python code snippet using tempest_python
test_volume_boot_pattern.py
Source:test_volume_boot_pattern.py
...56 security_group = self._create_security_group()57 # create an instance from volume58 LOG.info("Booting instance 1 from volume")59 volume_origin = self.create_volume_from_image()60 instance_1st = self.boot_instance_from_resource(61 source_id=volume_origin['id'],62 source_type='volume',63 keypair=keypair,64 security_group=security_group)65 LOG.info("Booted first instance: %s", instance_1st)66 # write content to volume on instance67 LOG.info("Setting timestamp in instance %s", instance_1st)68 ip_instance_1st = self.get_server_ip(instance_1st)69 timestamp = self.create_timestamp(ip_instance_1st,70 private_key=keypair['private_key'],71 server=instance_1st)72 # delete instance73 LOG.info("Deleting first instance: %s", instance_1st)74 self._delete_server(instance_1st)75 # create a 2nd instance from volume76 instance_2nd = self.boot_instance_from_resource(77 source_id=volume_origin['id'],78 source_type='volume',79 keypair=keypair,80 security_group=security_group)81 LOG.info("Booted second instance %s", instance_2nd)82 # check the content of written file83 LOG.info("Getting timestamp in instance %s", instance_2nd)84 ip_instance_2nd = self.get_server_ip(instance_2nd)85 timestamp2 = self.get_timestamp(ip_instance_2nd,86 private_key=keypair['private_key'],87 server=instance_2nd)88 self.assertEqual(timestamp, timestamp2)89 # snapshot a volume90 LOG.info("Creating snapshot from volume: %s", volume_origin['id'])91 snapshot = self.create_volume_snapshot(volume_origin['id'], force=True)92 # create a 3rd instance from snapshot93 LOG.info("Creating third instance from snapshot: %s", snapshot['id'])94 volume = self.create_volume(snapshot_id=snapshot['id'],95 size=snapshot['size'])96 LOG.info("Booting third instance from snapshot")97 server_from_snapshot = (98 self.boot_instance_from_resource(source_id=volume['id'],99 source_type='volume',100 keypair=keypair,101 security_group=security_group))102 LOG.info("Booted third instance %s", server_from_snapshot)103 # check the content of written file104 LOG.info("Logging into third instance to get timestamp: %s",105 server_from_snapshot)106 server_from_snapshot_ip = self.get_server_ip(server_from_snapshot)107 timestamp3 = self.get_timestamp(server_from_snapshot_ip,108 private_key=keypair['private_key'],109 server=server_from_snapshot)110 self.assertEqual(timestamp, timestamp3)111 @decorators.idempotent_id('05795fb2-b2a7-4c9f-8fac-ff25aedb1489')112 @decorators.attr(type='slow')113 @testtools.skipUnless(CONF.volume_feature_enabled.snapshot,114 'Cinder volume snapshots are disabled')115 @utils.services('compute', 'image', 'volume')116 def test_create_server_from_volume_snapshot(self):117 # Create a volume from an image118 boot_volume = self.create_volume_from_image()119 # Create a snapshot120 boot_snapshot = self.create_volume_snapshot(boot_volume['id'])121 # Create a server from a volume snapshot122 server = self.boot_instance_from_resource(123 source_id=boot_snapshot['id'],124 source_type='snapshot',125 delete_on_termination=True)126 server_info = self.servers_client.show_server(server['id'])['server']127 # The created volume when creating a server from a snapshot128 created_volume = server_info['os-extended-volumes:volumes_attached']129 self.assertNotEmpty(created_volume, "No volume attachment found.")130 created_volume_info = self.volumes_client.show_volume(131 created_volume[0]['id'])['volume']132 # Verify the server was created from the snapshot133 self.assertEqual(134 boot_volume['volume_image_metadata']['image_id'],135 created_volume_info['volume_image_metadata']['image_id'])136 self.assertEqual(boot_snapshot['id'],137 created_volume_info['snapshot_id'])138 self.assertEqual(server['id'],139 created_volume_info['attachments'][0]['server_id'])140 self.assertEqual(created_volume[0]['id'],141 created_volume_info['attachments'][0]['volume_id'])142 # Delete the server and wait143 self._delete_server(server)144 # Assert that the underlying volume is gone before class tearDown145 # to prevent snapshot deletion from failing146 self.volumes_client.wait_for_resource_deletion(created_volume[0]['id'])147 @decorators.idempotent_id('36c34c67-7b54-4b59-b188-02a2f458a63b')148 @testtools.skipUnless(CONF.volume_feature_enabled.snapshot,149 'Cinder volume snapshots are disabled')150 @utils.services('compute', 'volume', 'image')151 def test_image_defined_boot_from_volume(self):152 # create an instance from image-backed volume153 volume_origin = self.create_volume_from_image()154 name = data_utils.rand_name(self.__class__.__name__ +155 '-volume-backed-server')156 instance1 = self.boot_instance_from_resource(157 source_id=volume_origin['id'],158 source_type='volume',159 delete_on_termination=True,160 name=name)161 # Create a snapshot image from the volume-backed server.162 # The compute service will have the block service create a snapshot of163 # the root volume and store its metadata in the image.164 image = self.create_server_snapshot(instance1)165 # Create a server from the image snapshot which has an166 # "image-defined block device mapping (BDM)" in it, i.e. the metadata167 # about the volume snapshot. The compute service will use this to168 # create a volume from the volume snapshot and use that as the root169 # disk for the server.170 name = data_utils.rand_name(self.__class__.__name__ +171 '-image-snapshot-server')172 instance2 = self.create_server(image_id=image['id'], name=name)173 # Verify the server was created from the image-defined BDM.174 volume_attachments = instance2['os-extended-volumes:volumes_attached']175 self.assertEqual(1, len(volume_attachments),176 "No volume attachment found.")177 created_volume = self.volumes_client.show_volume(178 volume_attachments[0]['id'])['volume']179 # Assert that the volume service also shows the server attachment.180 self.assertEqual(1, len(created_volume['attachments']),181 "No server attachment found for volume: %s" %182 created_volume)183 self.assertEqual(instance2['id'],184 created_volume['attachments'][0]['server_id'])185 self.assertEqual(volume_attachments[0]['id'],186 created_volume['attachments'][0]['volume_id'])187 self.assertEqual(188 volume_origin['volume_image_metadata']['image_id'],189 created_volume['volume_image_metadata']['image_id'])190 # Delete the second server which should also delete the second volume191 # created from the volume snapshot.192 self._delete_server(instance2)193 # Assert that the underlying volume is gone.194 self.volumes_client.wait_for_resource_deletion(created_volume['id'])195 # Delete the volume snapshot. We must do this before deleting the first196 # server created in this test because the snapshot depends on the first197 # instance's underlying volume (volume_origin).198 # In glance v2, the image properties are flattened and in glance v1,199 # the image properties are under the 'properties' key.200 bdms = image.get('block_device_mapping')201 if not bdms:202 bdms = image['properties']['block_device_mapping']203 bdms = json.loads(bdms)204 snapshot_id = bdms[0]['snapshot_id']205 self._delete_snapshot(snapshot_id)206 # Now, delete the first server which will also delete the first207 # image-backed volume.208 self._delete_server(instance1)209 # Assert that the underlying volume is gone.210 self.volumes_client.wait_for_resource_deletion(volume_origin['id'])211 @decorators.idempotent_id('cb78919a-e553-4bab-b73b-10cf4d2eb125')212 @testtools.skipUnless(CONF.compute_feature_enabled.attach_encrypted_volume,213 'Encrypted volume attach is not supported')214 @utils.services('compute', 'volume')215 def test_boot_server_from_encrypted_volume_luks(self):216 # Create an encrypted volume217 volume = self.create_encrypted_volume('luks',218 volume_type='luks')219 self.volumes_client.set_bootable_volume(volume['id'], bootable=True)220 # Boot a server from the encrypted volume221 server = self.boot_instance_from_resource(222 source_id=volume['id'],223 source_type='volume',224 delete_on_termination=False)225 server_info = self.servers_client.show_server(server['id'])['server']226 created_volume = server_info['os-extended-volumes:volumes_attached']...
test_volume_encrypted.py
Source:test_volume_encrypted.py
...109 keypair = self.create_keypair()110 security_group = self.create_security_group()111 volume = self.create_encrypted_volume_from_image('luks')112 # create an instance from volume113 instance_1st = self.boot_instance_from_resource(114 source_id=volume['id'],115 source_type='volume',116 keypair=keypair,117 security_group=security_group)118 # write content to volume on instance119 ip_instance_1st = self.get_server_ip(instance_1st)120 timestamp = self.create_timestamp(ip_instance_1st,121 private_key=keypair['private_key'],122 server=instance_1st)123 # delete instance124 self._delete_server(instance_1st)125 # create clone126 kwargs = {127 'display_name': data_utils.rand_name(self.__class__.__name__),128 'source_volid': volume['id'],129 'volume_type': volume['volume_type'],130 'size': volume['size']131 }132 volume_s = self.volumes_client.create_volume(**kwargs)['volume']133 self.addCleanup(self.volumes_client.wait_for_resource_deletion,134 volume_s['id'])135 self.addCleanup(self.volumes_client.delete_volume, volume_s['id'])136 waiters.wait_for_volume_resource_status(137 self.volumes_client, volume_s['id'], 'available')138 # create an instance from volume139 instance_2nd = self.boot_instance_from_resource(140 source_id=volume_s['id'],141 source_type='volume',142 keypair=keypair,143 security_group=security_group)144 # check the content of written file145 ip_instance_2nd = self.get_server_ip(instance_2nd)146 timestamp2 = self.get_timestamp(ip_instance_2nd,147 private_key=keypair['private_key'],148 server=instance_2nd)149 self.assertEqual(timestamp, timestamp2)150 # delete instance...
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!!