YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 1 | # Copyright (c) 2017 Midokura SARL |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
| 16 | import netaddr |
| 17 | from tempest.common import waiters |
| 18 | from tempest.lib.common import ssh |
| 19 | from tempest.lib.common.utils import data_utils |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 20 | from tempest.lib import decorators |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 21 | from tempest import test |
| 22 | import testscenarios |
| 23 | |
| 24 | from neutron.tests.tempest import config |
| 25 | from neutron.tests.tempest.scenario import base |
| 26 | from neutron.tests.tempest.scenario import constants |
| 27 | |
| 28 | |
| 29 | CONF = config.CONF |
| 30 | |
| 31 | |
| 32 | load_tests = testscenarios.load_tests_apply_scenarios |
| 33 | |
| 34 | |
| 35 | class FloatingIpTestCasesMixin(object): |
| 36 | credentials = ['primary', 'admin'] |
| 37 | |
| 38 | @classmethod |
| 39 | @test.requires_ext(extension="router", service="network") |
| 40 | def resource_setup(cls): |
| 41 | super(FloatingIpTestCasesMixin, cls).resource_setup() |
| 42 | cls.network = cls.create_network() |
| 43 | cls.subnet = cls.create_subnet(cls.network) |
| 44 | cls.router = cls.create_router_by_client() |
| 45 | cls.create_router_interface(cls.router['id'], cls.subnet['id']) |
| 46 | cls.keypair = cls.create_keypair() |
| 47 | |
| 48 | cls.secgroup = cls.manager.network_client.create_security_group( |
| 49 | name=data_utils.rand_name('secgroup-'))['security_group'] |
| 50 | cls.security_groups.append(cls.secgroup) |
| 51 | cls.create_loginable_secgroup_rule(secgroup_id=cls.secgroup['id']) |
| 52 | cls.create_pingable_secgroup_rule(secgroup_id=cls.secgroup['id']) |
| 53 | |
| 54 | cls._src_server = cls._create_server() |
| 55 | if cls.same_network: |
| 56 | cls._dest_network = cls.network |
| 57 | else: |
| 58 | cls._dest_network = cls._create_dest_network() |
| 59 | cls._dest_server_with_fip = cls._create_server( |
| 60 | network=cls._dest_network) |
| 61 | cls._dest_server_without_fip = cls._create_server( |
| 62 | create_floating_ip=False, network=cls._dest_network) |
| 63 | |
| 64 | @classmethod |
| 65 | def _create_dest_network(cls): |
| 66 | network = cls.create_network() |
| 67 | subnet = cls.create_subnet(network, |
| 68 | cidr=netaddr.IPNetwork('10.10.0.0/24')) |
| 69 | cls.create_router_interface(cls.router['id'], subnet['id']) |
| 70 | return network |
| 71 | |
| 72 | @classmethod |
| 73 | def _create_server(cls, create_floating_ip=True, network=None): |
| 74 | if network is None: |
| 75 | network = cls.network |
| 76 | port = cls.create_port(network, security_groups=[cls.secgroup['id']]) |
| 77 | if create_floating_ip: |
| 78 | fip = cls.create_and_associate_floatingip(port['id']) |
| 79 | else: |
| 80 | fip = None |
| 81 | server = cls.create_server( |
| 82 | flavor_ref=CONF.compute.flavor_ref, |
| 83 | image_ref=CONF.compute.image_ref, |
| 84 | key_name=cls.keypair['name'], |
| 85 | networks=[{'port': port['id']}])['server'] |
| 86 | waiters.wait_for_server_status(cls.manager.servers_client, |
| 87 | server['id'], |
| 88 | constants.SERVER_STATUS_ACTIVE) |
| 89 | return {'port': port, 'fip': fip, 'server': server} |
| 90 | |
| 91 | def _test_east_west(self): |
| 92 | # Source VM |
| 93 | server1 = self._src_server |
| 94 | server1_ip = server1['fip']['floating_ip_address'] |
| 95 | ssh_client = ssh.Client(server1_ip, |
| 96 | CONF.validation.image_ssh_user, |
| 97 | pkey=self.keypair['private_key']) |
| 98 | |
| 99 | # Destination VM |
| 100 | if self.dest_has_fip: |
| 101 | dest_server = self._dest_server_with_fip |
| 102 | else: |
| 103 | dest_server = self._dest_server_without_fip |
| 104 | |
| 105 | # Check connectivity |
| 106 | self.check_remote_connectivity(ssh_client, |
| 107 | dest_server['port']['fixed_ips'][0]['ip_address']) |
| 108 | if self.dest_has_fip: |
| 109 | self.check_remote_connectivity(ssh_client, |
| 110 | dest_server['fip']['floating_ip_address']) |
| 111 | |
| 112 | |
| 113 | class FloatingIpSameNetwork(FloatingIpTestCasesMixin, |
| 114 | base.BaseTempestTestCase): |
| 115 | # REVISIT(yamamoto): 'SRC without FIP' case is possible? |
| 116 | scenarios = [ |
| 117 | ('DEST with FIP', dict(dest_has_fip=True)), |
| 118 | ('DEST without FIP', dict(dest_has_fip=False)), |
| 119 | ] |
| 120 | |
| 121 | same_network = True |
| 122 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 123 | @decorators.idempotent_id('05c4e3b3-7319-4052-90ad-e8916436c23b') |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 124 | def test_east_west(self): |
| 125 | self._test_east_west() |
| 126 | |
| 127 | |
| 128 | class FloatingIpSeparateNetwork(FloatingIpTestCasesMixin, |
| 129 | base.BaseTempestTestCase): |
| 130 | # REVISIT(yamamoto): 'SRC without FIP' case is possible? |
| 131 | scenarios = [ |
| 132 | ('DEST with FIP', dict(dest_has_fip=True)), |
| 133 | ('DEST without FIP', dict(dest_has_fip=False)), |
| 134 | ] |
| 135 | |
| 136 | same_network = False |
| 137 | |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 138 | @decorators.idempotent_id('f18f0090-3289-4783-b956-a0f8ac511e8b') |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 139 | def test_east_west(self): |
| 140 | self._test_east_west() |