Best Python code snippet using tempest_python
test_minimum_basic.py
Source:test_minimum_basic.py  
...65    def check_partitions(self):66        # NOTE(andreaf) The device name may be different on different guest OS67        partitions = self.linux_client.get_partitions()68        self.assertEqual(1, partitions.count(CONF.compute.volume_device_name))69    def create_and_add_security_group_to_server(self, server):70        secgroup = self._create_security_group()71        self.servers_client.add_security_group(server['id'],72                                               name=secgroup['name'])73        self.addCleanup(self.servers_client.remove_security_group,74                        server['id'], name=secgroup['name'])75        def wait_for_secgroup_add():76            body = (self.servers_client.show_server(server['id'])77                    ['server'])78            return {'name': secgroup['name']} in body['security_groups']79        if not test.call_until_true(wait_for_secgroup_add,80                                    CONF.compute.build_timeout,81                                    CONF.compute.build_interval):82            msg = ('Timed out waiting for adding security group %s to server '83                   '%s' % (secgroup['id'], server['id']))84            raise exceptions.TimeoutException(msg)85    @test.idempotent_id('bdbb5441-9204-419d-a225-b4fdbfb1a1a8')86    @test.services('compute', 'volume', 'image', 'network')87    def test_minimum_basic_scenario(self):88        image = self.glance_image_create()89        keypair = self.create_keypair()90        server = self.create_server(image_id=image,91                                    key_name=keypair['name'],92                                    wait_until='ACTIVE')93        servers = self.nova_list()94        self.assertIn(server['id'], [x['id'] for x in servers])95        self.nova_show(server)96        volume = self.cinder_create()97        volumes = self.cinder_list()98        self.assertIn(volume['id'], [x['id'] for x in volumes])99        self.cinder_show(volume)100        volume = self.nova_volume_attach(server, volume)101        self.addCleanup(self.nova_volume_detach, server, volume)102        self.cinder_show(volume)103        floating_ip = self.create_floating_ip(server)104        self.create_and_add_security_group_to_server(server)105        # check that we can SSH to the server before reboot106        self.linux_client = self.get_remote_client(107            floating_ip['ip'], private_key=keypair['private_key'])108        self.nova_reboot(server)109        # check that we can SSH to the server after reboot110        # (both connections are part of the scenario)111        self.linux_client = self.get_remote_client(112            floating_ip['ip'], private_key=keypair['private_key'])...test1.py
Source:test1.py  
...31        # NOTE(andreaf) The device name may be different on different guest OS32        partitions = self.linux_client.get_partitions()33        self.assertEqual(1, partitions.count(CONF.compute.volume_device_name))3435    def create_and_add_security_group_to_server(self, server):36        secgroup = self._create_security_group()37        self.servers_client.add_security_group(server['id'],38                                               name=secgroup['name'])39        self.addCleanup(self.servers_client.remove_security_group,40                        server['id'], name=secgroup['name'])4142        def wait_for_secgroup_add():43            body = (self.servers_client.show_server(server['id'])44                    ['server'])45            return {'name': secgroup['name']} in body['security_groups']4647        if not test_utils.call_until_true(wait_for_secgroup_add,48                                          CONF.compute.build_timeout,49                                          CONF.compute.build_interval):50            msg = ('Timed out waiting for adding security group %s to server '51                   '%s' % (secgroup['id'], server['id']))52            raise exceptions.TimeoutException(msg)5354    def _get_floating_ip_in_server_addresses(self, floating_ip, server):55        for network_name, addresses in server['addresses'].items():56            for address in addresses:57                if (address['OS-EXT-IPS:type'] == 'floating' and58                        address['addr'] == floating_ip['ip']):59                    return address6061    @test.idempotent_id('bdbb5441-9204-419d-a225-b4fdbfb1a1a8')62    @test.services('compute', 'volume', 'image', 'network')63    def test_minimum_basic_scenario(self):64        image = self.glance_image_create()65        keypair = self.create_keypair()6667        server = self.create_server(image_id=image,68                                    key_name=keypair['name'],69                                    wait_until='ACTIVE')70        servers = self.servers_client.list_servers()['servers']71        self.assertIn(server['id'], [x['id'] for x in servers])7273		print("creating Instance")74        self.nova_show(server)7576        floating_ip = self.create_floating_ip(server)77        # fetch the server again to make sure the addresses were refreshed78        # after associating the floating IP79        server = self.servers_client.show_server(server['id'])['server']80        address = self._get_floating_ip_in_server_addresses(81            floating_ip, server)82        self.assertIsNotNone(83            address,84            "Failed to find floating IP '%s' in server addresses: %s" %85            (floating_ip['ip'], server['addresses']))8687        self.create_and_add_security_group_to_server(server)8889        # check that we can SSH to the server before reboot90        self.linux_client = self.get_remote_client(91            floating_ip['ip'], private_key=keypair['private_key'])9293        self.nova_reboot(server)9495        # check that we can SSH to the server after reboot96        # (both connections are part of the scenario)97        self.linux_client = self.get_remote_client(98            floating_ip['ip'], private_key=keypair['private_key'])99100        self.check_partitions()101
...test.py
Source:test.py  
...20        if self.image != "kvm" or self.image != "hyperv":21            raise exceptions.TempestException("no hyperv or kvm")22        self.image = CONF.compute.image_ref23        self.user = CONF.validation.image_ssh_user24    def create_and_add_security_group_to_server(self, server):25        secgroup = self._create_security_group()26        self.servers_client.add_security_group(server['id'],27                                               name=secgroup['name'])28        self.addCleanup(self.servers_client.remove_security_group,29                        server['id'], name=secgroup['name'])30        def wait_for_secgroup_add():31            body = (self.servers_client.show_server(server['id'])32                    ['server'])33            return {'name': secgroup['name']} in body['security_groups']34        if not test.call_until_true(wait_for_secgroup_add,35                                    CONF.compute.build_timeout,36                                    CONF.compute.build_interval):37            msg = ('Timed out waiting for adding security group %s to server '38                   '%s' % (secgroup['id'], server['id']))39            raise exceptions.TimeoutException(msg)40    @testtools.skipUnless(CONF.compute_feature_enabled.pause,41                          'Pause is not available.')42    @test.services('compute', 'network')43    def test_mizerie(self):44        keypair = self.create_keypair()45        vm1 = self.create_server(image_id=self.image,46                                 key_name=keypair['name'],47                                 wait_until='ACTIVE')48        self.addCleanup(self.servers_client.delete_server, vm1['id'])49        time.sleep(10)50        vm2 = self.create_server(image_id=self.image,51                                 key_name=keypair['name'],52                                 wait_until='ACTIVE')53        self.addCleanup(self.servers_client.delete_server, vm2['id'])54        time.sleep(10)55        floating_ip1 = self.create_floating_ip(vm1)56        floating_ip2 = self.create_floating_ip(vm2)57        self.create_and_add_security_group_to_server(vm1)58        self.create_and_add_security_group_to_server(vm2)59        self.linux_client = self.get_remote_client(60            floating_ip1['ip'], private_key=keypair['private_key'])61        try:62            self.linux_client.ping_host(floating_ip2['ip'], 5)63        except:64            raise exceptions.TempestException("cannot ping between vms")65        self.servers_client.pause_server(vm1['id'])66        waiters.wait_for_server_status(self.servers_client, vm1['id'],67                                       'PAUSED')68        self.servers_client.unpause_server(vm1['id'])69        waiters.wait_for_server_status(self.servers_client, vm1['id'],70                                       'ACTIVE')71        self.servers_client.reboot_server(vm2['id'], type='SOFT')72        waiters.wait_for_server_status(self.servers_client, vm2['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!!
