blob: 5fcbdc0537725616f832e7cb6ce5ddddbd9ba8b9 [file] [log] [blame]
YAMAMOTO Takashi25935722017-01-23 15:34:11 +09001# 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
16import netaddr
Chandan Kumarc125fd12017-11-15 19:41:01 +053017from tempest.common import utils
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090018from tempest.common import waiters
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090019from tempest.lib.common.utils import data_utils
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000020from tempest.lib import decorators
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090021import testscenarios
YAMAMOTO Takashi60faf4f2017-01-25 08:03:07 +090022from testscenarios.scenarios import multiply_scenarios
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090023
Chandan Kumar667d3d32017-09-22 12:24:06 +053024from neutron_tempest_plugin.common import ssh
25from neutron_tempest_plugin import config
26from neutron_tempest_plugin.scenario import base
27from neutron_tempest_plugin.scenario import constants
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090028
29
30CONF = config.CONF
31
32
33load_tests = testscenarios.load_tests_apply_scenarios
34
35
36class FloatingIpTestCasesMixin(object):
37 credentials = ['primary', 'admin']
38
39 @classmethod
Chandan Kumarc125fd12017-11-15 19:41:01 +053040 @utils.requires_ext(extension="router", service="network")
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090041 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
rajat294495c042017-06-28 15:37:16 +053049 cls.secgroup = cls.os_primary.network_client.create_security_group(
Chandan Kumarc125fd12017-11-15 19:41:01 +053050 name=data_utils.rand_name('secgroup'))['security_group']
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090051 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 Takashi25935722017-01-23 15:34:11 +090055 if cls.same_network:
56 cls._dest_network = cls.network
57 else:
58 cls._dest_network = cls._create_dest_network()
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090059
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 Chereshnya918dd0b2017-05-17 13:02:20 +000068 def _create_server(self, create_floating_ip=True, network=None):
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090069 if network is None:
Genadi Chereshnya918dd0b2017-05-17 13:02:20 +000070 network = self.network
71 port = self.create_port(network, security_groups=[self.secgroup['id']])
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090072 if create_floating_ip:
Genadi Chereshnya918dd0b2017-05-17 13:02:20 +000073 fip = self.create_and_associate_floatingip(port['id'])
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090074 else:
75 fip = None
Genadi Chereshnya918dd0b2017-05-17 13:02:20 +000076 server = self.create_server(
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090077 flavor_ref=CONF.compute.flavor_ref,
78 image_ref=CONF.compute.image_ref,
Genadi Chereshnya918dd0b2017-05-17 13:02:20 +000079 key_name=self.keypair['name'],
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090080 networks=[{'port': port['id']}])['server']
rajat294495c042017-06-28 15:37:16 +053081 waiters.wait_for_server_status(self.os_primary.servers_client,
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090082 server['id'],
83 constants.SERVER_STATUS_ACTIVE)
84 return {'port': port, 'fip': fip, 'server': server}
85
86 def _test_east_west(self):
YAMAMOTO Takashi60faf4f2017-01-25 08:03:07 +090087 # 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 Takashi25935722017-01-23 15:34:11 +090098 # Source VM
YAMAMOTO Takashi60faf4f2017-01-25 08:03:07 +090099 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 Takashi25935722017-01-23 15:34:11 +0900106 CONF.validation.image_ssh_user,
YAMAMOTO Takashi60faf4f2017-01-25 08:03:07 +0900107 pkey=self.keypair['private_key'],
108 proxy_client=proxy_client)
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900109
110 # Destination VM
111 if self.dest_has_fip:
Genadi Chereshnya918dd0b2017-05-17 13:02:20 +0000112 dest_server = self._create_server(network=self._dest_network)
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900113 else:
Genadi Chereshnya918dd0b2017-05-17 13:02:20 +0000114 dest_server = self._create_server(create_floating_ip=False,
115 network=self._dest_network)
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900116
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
125class FloatingIpSameNetwork(FloatingIpTestCasesMixin,
126 base.BaseTempestTestCase):
YAMAMOTO Takashi60faf4f2017-01-25 08:03:07 +0900127 scenarios = multiply_scenarios([
128 ('SRC with FIP', dict(src_has_fip=True)),
129 ('SRC without FIP', dict(src_has_fip=False)),
130 ], [
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900131 ('DEST with FIP', dict(dest_has_fip=True)),
132 ('DEST without FIP', dict(dest_has_fip=False)),
YAMAMOTO Takashi60faf4f2017-01-25 08:03:07 +0900133 ])
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900134
135 same_network = True
136
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000137 @decorators.idempotent_id('05c4e3b3-7319-4052-90ad-e8916436c23b')
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900138 def test_east_west(self):
139 self._test_east_west()
140
141
142class FloatingIpSeparateNetwork(FloatingIpTestCasesMixin,
143 base.BaseTempestTestCase):
YAMAMOTO Takashi60faf4f2017-01-25 08:03:07 +0900144 scenarios = multiply_scenarios([
145 ('SRC with FIP', dict(src_has_fip=True)),
146 ('SRC without FIP', dict(src_has_fip=False)),
147 ], [
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900148 ('DEST with FIP', dict(dest_has_fip=True)),
149 ('DEST without FIP', dict(dest_has_fip=False)),
YAMAMOTO Takashi60faf4f2017-01-25 08:03:07 +0900150 ])
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900151
152 same_network = False
153
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000154 @decorators.idempotent_id('f18f0090-3289-4783-b956-a0f8ac511e8b')
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900155 def test_east_west(self):
156 self._test_east_west()