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 |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 17 | from tempest.common import utils |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 18 | from tempest.common import waiters |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 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 | import testscenarios |
YAMAMOTO Takashi | 60faf4f | 2017-01-25 08:03:07 +0900 | [diff] [blame] | 22 | from testscenarios.scenarios import multiply_scenarios |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 23 | |
Chandan Kumar | 667d3d3 | 2017-09-22 12:24:06 +0530 | [diff] [blame] | 24 | from neutron_tempest_plugin.common import ssh |
Brian Haley | ba80045 | 2017-12-14 10:30:48 -0500 | [diff] [blame] | 25 | from neutron_tempest_plugin.common import utils as common_utils |
Chandan Kumar | 667d3d3 | 2017-09-22 12:24:06 +0530 | [diff] [blame] | 26 | from neutron_tempest_plugin import config |
| 27 | from neutron_tempest_plugin.scenario import base |
| 28 | from neutron_tempest_plugin.scenario import constants |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 29 | |
| 30 | |
| 31 | CONF = config.CONF |
| 32 | |
| 33 | |
| 34 | load_tests = testscenarios.load_tests_apply_scenarios |
| 35 | |
| 36 | |
| 37 | class FloatingIpTestCasesMixin(object): |
| 38 | credentials = ['primary', 'admin'] |
| 39 | |
| 40 | @classmethod |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 41 | @utils.requires_ext(extension="router", service="network") |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 42 | def resource_setup(cls): |
| 43 | super(FloatingIpTestCasesMixin, cls).resource_setup() |
| 44 | cls.network = cls.create_network() |
| 45 | cls.subnet = cls.create_subnet(cls.network) |
| 46 | cls.router = cls.create_router_by_client() |
| 47 | cls.create_router_interface(cls.router['id'], cls.subnet['id']) |
| 48 | cls.keypair = cls.create_keypair() |
| 49 | |
rajat29 | 4495c04 | 2017-06-28 15:37:16 +0530 | [diff] [blame] | 50 | cls.secgroup = cls.os_primary.network_client.create_security_group( |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 51 | name=data_utils.rand_name('secgroup'))['security_group'] |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 52 | cls.security_groups.append(cls.secgroup) |
| 53 | cls.create_loginable_secgroup_rule(secgroup_id=cls.secgroup['id']) |
| 54 | cls.create_pingable_secgroup_rule(secgroup_id=cls.secgroup['id']) |
| 55 | |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 56 | if cls.same_network: |
| 57 | cls._dest_network = cls.network |
| 58 | else: |
| 59 | cls._dest_network = cls._create_dest_network() |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 60 | |
| 61 | @classmethod |
| 62 | def _create_dest_network(cls): |
| 63 | network = cls.create_network() |
| 64 | subnet = cls.create_subnet(network, |
| 65 | cidr=netaddr.IPNetwork('10.10.0.0/24')) |
| 66 | cls.create_router_interface(cls.router['id'], subnet['id']) |
| 67 | return network |
| 68 | |
Genadi Chereshnya | 918dd0b | 2017-05-17 13:02:20 +0000 | [diff] [blame] | 69 | def _create_server(self, create_floating_ip=True, network=None): |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 70 | if network is None: |
Genadi Chereshnya | 918dd0b | 2017-05-17 13:02:20 +0000 | [diff] [blame] | 71 | network = self.network |
| 72 | port = self.create_port(network, security_groups=[self.secgroup['id']]) |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 73 | if create_floating_ip: |
Genadi Chereshnya | 918dd0b | 2017-05-17 13:02:20 +0000 | [diff] [blame] | 74 | fip = self.create_and_associate_floatingip(port['id']) |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 75 | else: |
| 76 | fip = None |
Genadi Chereshnya | 918dd0b | 2017-05-17 13:02:20 +0000 | [diff] [blame] | 77 | server = self.create_server( |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 78 | flavor_ref=CONF.compute.flavor_ref, |
| 79 | image_ref=CONF.compute.image_ref, |
Genadi Chereshnya | 918dd0b | 2017-05-17 13:02:20 +0000 | [diff] [blame] | 80 | key_name=self.keypair['name'], |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 81 | networks=[{'port': port['id']}])['server'] |
rajat29 | 4495c04 | 2017-06-28 15:37:16 +0530 | [diff] [blame] | 82 | waiters.wait_for_server_status(self.os_primary.servers_client, |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 83 | server['id'], |
| 84 | constants.SERVER_STATUS_ACTIVE) |
| 85 | return {'port': port, 'fip': fip, 'server': server} |
| 86 | |
| 87 | def _test_east_west(self): |
YAMAMOTO Takashi | 60faf4f | 2017-01-25 08:03:07 +0900 | [diff] [blame] | 88 | # The proxy VM is used to control the source VM when it doesn't |
| 89 | # have a floating-ip. |
| 90 | if self.src_has_fip: |
| 91 | proxy = None |
| 92 | proxy_client = None |
| 93 | else: |
| 94 | proxy = self._create_server() |
| 95 | proxy_client = ssh.Client(proxy['fip']['floating_ip_address'], |
| 96 | CONF.validation.image_ssh_user, |
| 97 | pkey=self.keypair['private_key']) |
| 98 | |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 99 | # Source VM |
YAMAMOTO Takashi | 60faf4f | 2017-01-25 08:03:07 +0900 | [diff] [blame] | 100 | if self.src_has_fip: |
| 101 | src_server = self._create_server() |
| 102 | src_server_ip = src_server['fip']['floating_ip_address'] |
| 103 | else: |
| 104 | src_server = self._create_server(create_floating_ip=False) |
| 105 | src_server_ip = src_server['port']['fixed_ips'][0]['ip_address'] |
| 106 | ssh_client = ssh.Client(src_server_ip, |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 107 | CONF.validation.image_ssh_user, |
YAMAMOTO Takashi | 60faf4f | 2017-01-25 08:03:07 +0900 | [diff] [blame] | 108 | pkey=self.keypair['private_key'], |
| 109 | proxy_client=proxy_client) |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 110 | |
| 111 | # Destination VM |
| 112 | if self.dest_has_fip: |
Genadi Chereshnya | 918dd0b | 2017-05-17 13:02:20 +0000 | [diff] [blame] | 113 | dest_server = self._create_server(network=self._dest_network) |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 114 | else: |
Genadi Chereshnya | 918dd0b | 2017-05-17 13:02:20 +0000 | [diff] [blame] | 115 | dest_server = self._create_server(create_floating_ip=False, |
| 116 | network=self._dest_network) |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 117 | |
| 118 | # Check connectivity |
| 119 | self.check_remote_connectivity(ssh_client, |
| 120 | dest_server['port']['fixed_ips'][0]['ip_address']) |
| 121 | if self.dest_has_fip: |
| 122 | self.check_remote_connectivity(ssh_client, |
| 123 | dest_server['fip']['floating_ip_address']) |
| 124 | |
| 125 | |
| 126 | class FloatingIpSameNetwork(FloatingIpTestCasesMixin, |
| 127 | base.BaseTempestTestCase): |
YAMAMOTO Takashi | 60faf4f | 2017-01-25 08:03:07 +0900 | [diff] [blame] | 128 | scenarios = multiply_scenarios([ |
| 129 | ('SRC with FIP', dict(src_has_fip=True)), |
| 130 | ('SRC without FIP', dict(src_has_fip=False)), |
| 131 | ], [ |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 132 | ('DEST with FIP', dict(dest_has_fip=True)), |
| 133 | ('DEST without FIP', dict(dest_has_fip=False)), |
YAMAMOTO Takashi | 60faf4f | 2017-01-25 08:03:07 +0900 | [diff] [blame] | 134 | ]) |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 135 | |
| 136 | same_network = True |
| 137 | |
Brian Haley | ba80045 | 2017-12-14 10:30:48 -0500 | [diff] [blame] | 138 | @common_utils.unstable_test("bug 1717302") |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 139 | @decorators.idempotent_id('05c4e3b3-7319-4052-90ad-e8916436c23b') |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 140 | def test_east_west(self): |
| 141 | self._test_east_west() |
| 142 | |
| 143 | |
| 144 | class FloatingIpSeparateNetwork(FloatingIpTestCasesMixin, |
| 145 | base.BaseTempestTestCase): |
YAMAMOTO Takashi | 60faf4f | 2017-01-25 08:03:07 +0900 | [diff] [blame] | 146 | scenarios = multiply_scenarios([ |
| 147 | ('SRC with FIP', dict(src_has_fip=True)), |
| 148 | ('SRC without FIP', dict(src_has_fip=False)), |
| 149 | ], [ |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 150 | ('DEST with FIP', dict(dest_has_fip=True)), |
| 151 | ('DEST without FIP', dict(dest_has_fip=False)), |
YAMAMOTO Takashi | 60faf4f | 2017-01-25 08:03:07 +0900 | [diff] [blame] | 152 | ]) |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 153 | |
| 154 | same_network = False |
| 155 | |
Brian Haley | ba80045 | 2017-12-14 10:30:48 -0500 | [diff] [blame] | 156 | @common_utils.unstable_test("bug 1717302") |
Sławek Kapłoński | c0caa2e | 2017-02-25 10:11:32 +0000 | [diff] [blame] | 157 | @decorators.idempotent_id('f18f0090-3289-4783-b956-a0f8ac511e8b') |
YAMAMOTO Takashi | 2593572 | 2017-01-23 15:34:11 +0900 | [diff] [blame] | 158 | def test_east_west(self): |
| 159 | self._test_east_west() |