Best Python code snippet using tempest_python
test_minimum_basic.py
Source:test_minimum_basic.py  
...76                                          CONF.compute.build_interval):77            msg = ('Timed out waiting for adding security group %s to server '78                   '%s' % (secgroup['id'], server['id']))79            raise exceptions.TimeoutException(msg)80    def _get_floating_ip_in_server_addresses(self, floating_ip, server):81        for network_name, addresses in server['addresses'].items():82            for address in addresses:83                if (address['OS-EXT-IPS:type'] == 'floating' and84                        address['addr'] == floating_ip['ip']):85                    return address86    @decorators.idempotent_id('bdbb5441-9204-419d-a225-b4fdbfb1a1a8')87    @testtools.skipUnless(CONF.network.public_network_id,88                          'The public_network_id option must be specified.')89    @test.services('compute', 'volume', 'image', 'network')90    def test_minimum_basic_scenario(self):91        image = self.glance_image_create()92        keypair = self.create_keypair()93        server = self.create_server(image_id=image, key_name=keypair['name'])94        servers = self.servers_client.list_servers()['servers']95        self.assertIn(server['id'], [x['id'] for x in servers])96        self.nova_show(server)97        volume = self.create_volume()98        volumes = self.volumes_client.list_volumes()['volumes']99        self.assertIn(volume['id'], [x['id'] for x in volumes])100        self.cinder_show(volume)101        volume = self.nova_volume_attach(server, volume)102        self.addCleanup(self.nova_volume_detach, server, volume)103        self.cinder_show(volume)104        floating_ip = self.create_floating_ip(server)105        # fetch the server again to make sure the addresses were refreshed106        # after associating the floating IP107        server = self.servers_client.show_server(server['id'])['server']108        address = self._get_floating_ip_in_server_addresses(109            floating_ip, server)110        self.assertIsNotNone(111            address,112            "Failed to find floating IP '%s' in server addresses: %s" %113            (floating_ip['ip'], server['addresses']))114        self.create_and_add_security_group_to_server(server)115        # check that we can SSH to the server before reboot116        self.linux_client = self.get_remote_client(117            floating_ip['ip'], private_key=keypair['private_key'])118        self.nova_reboot(server)119        # check that we can SSH to the server after reboot120        # (both connections are part of the scenario)121        self.linux_client = self.get_remote_client(122            floating_ip['ip'], private_key=keypair['private_key'])123        self.check_disks()124        # delete the floating IP, this should refresh the server addresses125        self.compute_floating_ips_client.delete_floating_ip(floating_ip['id'])126        def is_floating_ip_detached_from_server():127            server_info = self.servers_client.show_server(128                server['id'])['server']129            address = self._get_floating_ip_in_server_addresses(130                floating_ip, server_info)131            return (not address)132        if not test_utils.call_until_true(133            is_floating_ip_detached_from_server,134            CONF.compute.build_timeout,135            CONF.compute.build_interval):136            msg = ("Floating IP '%s' should not be in server addresses: %s" %137                   (floating_ip['ip'], server['addresses']))...test1.py
Source:test1.py  
...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()101102        # delete the floating IP, this should refresh the server addresses103        self.compute_floating_ips_client.delete_floating_ip(floating_ip['id'])104105        def is_floating_ip_detached_from_server():106            server_info = self.servers_client.show_server(107                server['id'])['server']108            address = self._get_floating_ip_in_server_addresses(109                floating_ip, server_info)110            return (not address)111112        if not test_utils.call_until_true(113            is_floating_ip_detached_from_server,114            CONF.compute.build_timeout,115            CONF.compute.build_interval):116            msg = ("Floating IP '%s' should not be in server addresses: %s" %117                   (floating_ip['ip'], server['addresses']))
...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!!
