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