How to use create_floating_ip method in tempest

Best Python code snippet using tempest_python

test_floatingip.py

Source:test_floatingip.py Github

copy

Full Screen

1# Copyright (c) 2017 Midokura SARL2# All Rights Reserved.3#4# Licensed under the Apache License, Version 2.0 (the "License"); you may5# not use this file except in compliance with the License. You may obtain6# a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13# License for the specific language governing permissions and limitations14# under the License.15import netaddr16from tempest.common import utils17from tempest.common import waiters18from tempest.lib.common.utils import data_utils19from tempest.lib import decorators20import testscenarios21from testscenarios.scenarios import multiply_scenarios22from neutron.tests.tempest.common import ssh23from neutron.tests.tempest import config24from neutron.tests.tempest.scenario import base25from neutron.tests.tempest.scenario import constants26CONF = config.CONF27load_tests = testscenarios.load_tests_apply_scenarios28class FloatingIpTestCasesMixin(object):29 credentials = ['primary', 'admin']30 @classmethod31 @utils.requires_ext(extension="router", service="network")32 def resource_setup(cls):33 super(FloatingIpTestCasesMixin, cls).resource_setup()34 cls.network = cls.create_network()35 cls.subnet = cls.create_subnet(cls.network)36 cls.router = cls.create_router_by_client()37 cls.create_router_interface(cls.router['id'], cls.subnet['id'])38 cls.keypair = cls.create_keypair()39 cls.secgroup = cls.os_primary.network_client.create_security_group(40 name=data_utils.rand_name('secgroup'))['security_group']41 cls.security_groups.append(cls.secgroup)42 cls.create_loginable_secgroup_rule(secgroup_id=cls.secgroup['id'])43 cls.create_pingable_secgroup_rule(secgroup_id=cls.secgroup['id'])44 if cls.same_network:45 cls._dest_network = cls.network46 else:47 cls._dest_network = cls._create_dest_network()48 @classmethod49 def _create_dest_network(cls):50 network = cls.create_network()51 subnet = cls.create_subnet(network,52 cidr=netaddr.IPNetwork('10.10.0.0/24'))53 cls.create_router_interface(cls.router['id'], subnet['id'])54 return network55 def _create_server(self, create_floating_ip=True, network=None):56 if network is None:57 network = self.network58 port = self.create_port(network, security_groups=[self.secgroup['id']])59 if create_floating_ip:60 fip = self.create_and_associate_floatingip(port['id'])61 else:62 fip = None63 server = self.create_server(64 flavor_ref=CONF.compute.flavor_ref,65 image_ref=CONF.compute.image_ref,66 key_name=self.keypair['name'],67 networks=[{'port': port['id']}])['server']68 waiters.wait_for_server_status(self.os_primary.servers_client,69 server['id'],70 constants.SERVER_STATUS_ACTIVE)71 return {'port': port, 'fip': fip, 'server': server}72 def _test_east_west(self):73 # The proxy VM is used to control the source VM when it doesn't74 # have a floating-ip.75 if self.src_has_fip:76 proxy = None77 proxy_client = None78 else:79 proxy = self._create_server()80 proxy_client = ssh.Client(proxy['fip']['floating_ip_address'],81 CONF.validation.image_ssh_user,82 pkey=self.keypair['private_key'])83 # Source VM84 if self.src_has_fip:85 src_server = self._create_server()86 src_server_ip = src_server['fip']['floating_ip_address']87 else:88 src_server = self._create_server(create_floating_ip=False)89 src_server_ip = src_server['port']['fixed_ips'][0]['ip_address']90 ssh_client = ssh.Client(src_server_ip,91 CONF.validation.image_ssh_user,92 pkey=self.keypair['private_key'],93 proxy_client=proxy_client)94 # Destination VM95 if self.dest_has_fip:96 dest_server = self._create_server(network=self._dest_network)97 else:98 dest_server = self._create_server(create_floating_ip=False,99 network=self._dest_network)100 # Check connectivity101 self.check_remote_connectivity(ssh_client,102 dest_server['port']['fixed_ips'][0]['ip_address'])103 if self.dest_has_fip:104 self.check_remote_connectivity(ssh_client,105 dest_server['fip']['floating_ip_address'])106class FloatingIpSameNetwork(FloatingIpTestCasesMixin,107 base.BaseTempestTestCase):108 scenarios = multiply_scenarios([109 ('SRC with FIP', dict(src_has_fip=True)),110 ('SRC without FIP', dict(src_has_fip=False)),111 ], [112 ('DEST with FIP', dict(dest_has_fip=True)),113 ('DEST without FIP', dict(dest_has_fip=False)),114 ])115 same_network = True116 @decorators.idempotent_id('05c4e3b3-7319-4052-90ad-e8916436c23b')117 def test_east_west(self):118 self._test_east_west()119class FloatingIpSeparateNetwork(FloatingIpTestCasesMixin,120 base.BaseTempestTestCase):121 scenarios = multiply_scenarios([122 ('SRC with FIP', dict(src_has_fip=True)),123 ('SRC without FIP', dict(src_has_fip=False)),124 ], [125 ('DEST with FIP', dict(dest_has_fip=True)),126 ('DEST without FIP', dict(dest_has_fip=False)),127 ])128 same_network = False129 @decorators.idempotent_id('f18f0090-3289-4783-b956-a0f8ac511e8b')130 def test_east_west(self):...

Full Screen

Full Screen

test_floating_ips.py

Source:test_floating_ips.py Github

copy

Full Screen

...345class TestFloatingIps(BaseHetznerTest):6 def test_can_create_a_floating_ip(self):7 floating_ip = self.create_floating_ip("Test description")89 self.assertIsNotNone(floating_ip)10 self.assertEqual(floating_ip.description, "Test description")1112 def test_can_assign_and_unassign_a_floating_ip_to_a_server(self):13 server, _ = self.create_server("test-assign-and-unassign-floating-ips")14 server.wait_until_status_is(SERVER_STATUS_RUNNING)15 16 floating_ip = self.create_floating_ip("Test description")1718 floating_ip.assign_to_server(server.id)19 self.assertEqual(floating_ip.server, server.id)2021 floating_ip.unassign_from_server()22 self.assertEqual(floating_ip.server, 0)2324 def test_can_change_description_of_a_floating_ip(self):25 floating_ip = self.create_floating_ip("Test description")26 floating_ip.change_description("My new description")2728 self.assertEqual(floating_ip.description, "My new description")2930 def test_can_change_reverse_dns_record(self):31 floating_ip = self.create_floating_ip("Test description") ...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful