Best Python code snippet using tempest_python
test_sf_volumes_attach.py
Source:test_sf_volumes_attach.py  
...48    @test.idempotent_id('e63b0859-c81c-47de-8929-1169100eb0b7')49    @test.stresstest(class_setup_per='process')50    @test.attr(type='smoke')51    @test.services('compute')52    def test_get_volume_attachment(self):53        # Verify that a volume's attachment information is retrieved54        mountpoint = '/dev/vdc'55        self.client.attach_volume(self.volume['id'],56                                  self.server['id'],57                                  mountpoint)58        self.client.wait_for_volume_status(self.volume['id'], 'in-use')59        # NOTE(gfidente): added in reverse order because functions will be60        # called in reverse order to the order they are added (LIFO)61        self.addCleanup(self.client.wait_for_volume_status,62                        self.volume['id'],63                        'available')64        self.addCleanup(self.client.detach_volume, self.volume['id'])65        volume = self.client.show_volume(self.volume['id'])66        self.assertIn('attachments', volume)67        attachment = self.client.get_attachment_from_volume(volume)68        self.assertEqual(mountpoint, attachment['device'])69        self.assertEqual(self.server['id'], attachment['server_id'])70        self.assertEqual(self.volume['id'], attachment['id'])71        self.assertEqual(self.volume['id'], attachment['volume_id'])72    @test.idempotent_id('0257f24e-f8c7-43b2-bd60-bcda77ea11b4')73    @test.stresstest(class_setup_per='process')74    @test.attr(type='smoke')75    @test.services('compute')76    def test_get_volume_detachment(self):77        # Volume is attached and detached successfully from an instance78        mountpoint = '/dev/vdc'79        self.client.attach_volume(self.volume['id'],80                                  self.server['id'],81                                  mountpoint)82        self.client.wait_for_volume_status(self.volume['id'], 'in-use')83        self.client.detach_volume(self.volume['id'])84        self.client.wait_for_volume_status(self.volume['id'], 'available')85        volume = self.client.show_volume(self.volume['id'])86        self.assertIn('attachments', volume)87        self.assertEqual(0, len(volume['attachments']))88class VolumesV2MultiAttachTest(base.BaseVolumeTest):89    @classmethod90    def setup_clients(cls):91        super(VolumesV2MultiAttachTest, cls).setup_clients()92        cls.client = cls.volumes_client93        cls.image_client = cls.os.image_client94    @classmethod95    def resource_setup(cls):96        super(VolumesV2MultiAttachTest, cls).resource_setup()97        # Create a test shared instance98        srv_name = data_utils.rand_name(cls.__name__ + '-Instance')99        cls.server = cls.create_server(srv_name)100        waiters.wait_for_server_status(cls.servers_client, cls.server['id'],101                                       'ACTIVE')102        # Create four test shared volumes for attach tests103        cls.metadata = {'Type': 'work'}104        for i in range(3):105            cls.volume = cls.create_volume(metadata=cls.metadata)106            cls.client.wait_for_volume_status(cls.volume['id'], 'available')107    @classmethod108    def resource_cleanup(cls):109        # Delete the test instance110        cls.servers_client.delete_server(cls.server['id'])111        cls.servers_client.wait_for_server_termination(cls.server['id'])112        super(VolumesV2MultiAttachTest, cls).resource_cleanup()113    @test.idempotent_id('714394dc-767c-4853-b43a-52b21ad77e5f')114    @test.stresstest(class_setup_per='process')115    @test.services('compute')116    def test_get_volume_attachment(self):117        # Verify that a volume's attachment information is retrieved118        i = 0119        for volume in self.volumes:120            flag = ['a', 'b', 'c', 'd']121            mountpoint = '/dev/vd%s' % flag[i]122            i += 1123            self.client.attach_volume(volume['id'],124                                      self.server['id'],125                                      mountpoint)126            self.client.wait_for_volume_status(volume['id'], 'in-use')127        # NOTE(gfidente): added in reverse order because functions will be128        # called in reverse order to the order they are added (LIFO)129            self.addCleanup(self.client.wait_for_volume_status,130                            volume['id'],...test_volumes_actions.py
Source:test_volumes_actions.py  
...54            # Detach the volume from the instance55            resp, body = self.client.detach_volume(self.volume['id'])56            self.assertEqual(202, resp.status)57            self.client.wait_for_volume_status(self.volume['id'], 'available')58    def test_get_volume_attachment(self):59        """Verify that a volume's attachment information is retrieved"""60        mountpoint = '/dev/vdc'61        resp, body = self.client.attach_volume(self.volume['id'],62                                               self.server['id'],63                                               mountpoint)64        self.client.wait_for_volume_status(self.volume['id'], 'in-use')65        self.assertEqual(202, resp.status)66        try:67            resp, volume = self.client.get_volume(self.volume['id'])68            self.assertEqual(200, resp.status)69            self.assertTrue('attachments' in volume)70            attachment = volume['attachments'][0]71            self.assertEqual(mountpoint, attachment['device'])72            self.assertEqual(self.server['id'], attachment['server_id'])...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!!
