Best Python code snippet using tempest_python
test_attach_volume.py
Source:test_attach_volume.py  
...164                servers_client=self.servers_client)165            linux_client.validate_authentication()166        # If validation went ok, or it was skipped, shelve the server167        compute.shelve_server(self.servers_client, server['id'])168    def _unshelve_server_and_check_volumes(self, server, number_of_volumes):169        # Unshelve the instance and check that there are expected volumes170        self.servers_client.unshelve_server(server['id'])171        waiters.wait_for_server_status(self.servers_client,172                                       server['id'],173                                       'ACTIVE')174        if CONF.validation.run_validation:175            counted_volumes = self._count_volumes(server)176            self.assertEqual(number_of_volumes, counted_volumes)177    @test.idempotent_id('13a940b6-3474-4c3c-b03f-29b89112bfee')178    @testtools.skipUnless(CONF.compute_feature_enabled.shelve,179                          'Shelve is not available.')180    def test_attach_volume_shelved_or_offload_server(self):181        # Create server, count number of volumes on it, shelve182        # server and attach pre-created volume to shelved server183        server = self._create_server()184        num_vol = self._count_volumes(server)185        self._shelve_server(server)186        self._create_and_attach_volume(server)187        # Unshelve the instance and check that attached volume exists188        self._unshelve_server_and_check_volumes(server, num_vol + 1)189        # Get Volume attachment of the server190        volume_attachment = self.servers_client.show_volume_attachment(191            server['id'],192            self.attachment['id'])['volumeAttachment']193        self.assertEqual(server['id'], volume_attachment['serverId'])194        self.assertEqual(self.attachment['id'], volume_attachment['id'])195        # Check the mountpoint is not None after unshelve server even in196        # case of shelved_offloaded.197        self.assertIsNotNone(volume_attachment['device'])198    @test.idempotent_id('b54e86dd-a070-49c4-9c07-59ae6dae15aa')199    @testtools.skipUnless(CONF.compute_feature_enabled.shelve,200                          'Shelve is not available.')201    def test_detach_volume_shelved_or_offload_server(self):202        # Create server, count number of volumes on it, shelve203        # server and attach pre-created volume to shelved server204        server = self._create_server()205        num_vol = self._count_volumes(server)206        self._shelve_server(server)207        volume = self._create_and_attach_volume(server)208        # Detach the volume209        self._detach(server['id'], volume['id'])210        self.attachment = None211        # Unshelve the instance and check that we have the expected number of212        # volume(s)...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!!
