Best Python code snippet using tempest_python
test_attach_volume.py
Source:test_attach_volume.py  
...327            attachment = attachments[server['id']]328            self.assertDictEqual(attachment, vol_attachments[0])329            # Detach the volume from this server.330            self._detach_multiattach_volume(volume['id'], server['id'])331    def _boot_from_multiattach_volume(self):332        """Boots a server from a multiattach volume.333        The volume will not be deleted when the server is deleted.334        :returns: 2-item tuple of (server, volume)335        """336        volume = self._create_multiattach_volume(bootable=True)337        # Now create a server from the bootable volume.338        bdm = [{339            'uuid': volume['id'],340            'source_type': 'volume',341            'destination_type': 'volume',342            'boot_index': 0,343            'delete_on_termination': False}]344        server = self.create_test_server(345            image_id='', block_device_mapping_v2=bdm, wait_until='ACTIVE')346        # Assert the volume is attached to the server.347        attachments = self.servers_client.list_volume_attachments(348            server['id'])['volumeAttachments']349        self.assertEqual(1, len(attachments))350        self.assertEqual(volume['id'], attachments[0]['volumeId'])351        return server, volume352    @decorators.idempotent_id('65e33aa2-185b-44c8-b22e-e524973ed625')353    def test_boot_from_multiattach_volume(self):354        """Simple test to boot an instance from a multiattach volume."""355        self._boot_from_multiattach_volume()356    @utils.services('image')357    @decorators.idempotent_id('885ac48a-2d7a-40c5-ae8b-1993882d724c')358    def test_snapshot_volume_backed_multiattach(self):359        """Boots a server from a multiattach volume and snapshots the server.360        Creating the snapshot of the server will also create a snapshot of361        the volume.362        """363        server, volume = self._boot_from_multiattach_volume()364        # Create a snapshot of the server (and volume implicitly).365        self.create_image_from_server(366            server['id'], name='multiattach-snapshot',367            wait_until='active', wait_for_server=True)368        # TODO(mriedem): Make sure the volume snapshot exists. This requires369        # adding the volume snapshots client to BaseV2ComputeTest.370        # Delete the server, wait for it to be gone, and make sure the volume371        # still exists.372        self.servers_client.delete_server(server['id'])373        waiters.wait_for_server_termination(self.servers_client, server['id'])374        # Delete the volume and cascade the delete of the volume snapshot.375        self.volumes_client.delete_volume(volume['id'], cascade=True)376        # Now we have to wait for the volume to be gone otherwise the normal377        # teardown will fail since it will race with our call and the snapshot...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!!
