blob: 0febce27dbe78b1bc9426a1e7f57c588b3e74a54 [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
Brian Haleyba800452017-12-14 10:30:48 -050025from neutron_tempest_plugin.common import utils as common_utils
Chandan Kumar667d3d32017-09-22 12:24:06 +053026from neutron_tempest_plugin import config
27from neutron_tempest_plugin.scenario import base
28from neutron_tempest_plugin.scenario import constants
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090029
30
31CONF = config.CONF
32
33
34load_tests = testscenarios.load_tests_apply_scenarios
35
36
37class FloatingIpTestCasesMixin(object):
38 credentials = ['primary', 'admin']
39
40 @classmethod
Chandan Kumarc125fd12017-11-15 19:41:01 +053041 @utils.requires_ext(extension="router", service="network")
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090042 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
rajat294495c042017-06-28 15:37:16 +053050 cls.secgroup = cls.os_primary.network_client.create_security_group(
Chandan Kumarc125fd12017-11-15 19:41:01 +053051 name=data_utils.rand_name('secgroup'))['security_group']
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090052 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 Takashi25935722017-01-23 15:34:11 +090056 if cls.same_network:
57 cls._dest_network = cls.network
58 else:
59 cls._dest_network = cls._create_dest_network()
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090060
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 Chereshnya918dd0b2017-05-17 13:02:20 +000069 def _create_server(self, create_floating_ip=True, network=None):
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090070 if network is None:
Genadi Chereshnya918dd0b2017-05-17 13:02:20 +000071 network = self.network
72 port = self.create_port(network, security_groups=[self.secgroup['id']])
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090073 if create_floating_ip:
Genadi Chereshnya918dd0b2017-05-17 13:02:20 +000074 fip = self.create_and_associate_floatingip(port['id'])
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090075 else:
76 fip = None
Genadi Chereshnya918dd0b2017-05-17 13:02:20 +000077 server = self.create_server(
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090078 flavor_ref=CONF.compute.flavor_ref,
79 image_ref=CONF.compute.image_ref,
Genadi Chereshnya918dd0b2017-05-17 13:02:20 +000080 key_name=self.keypair['name'],
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090081 networks=[{'port': port['id']}])['server']
rajat294495c042017-06-28 15:37:16 +053082 waiters.wait_for_server_status(self.os_primary.servers_client,
YAMAMOTO Takashi25935722017-01-23 15:34:11 +090083 server['id'],
84 constants.SERVER_STATUS_ACTIVE)
85 return {'port': port, 'fip': fip, 'server': server}
86
87 def _test_east_west(self):
YAMAMOTO Takashi60faf4f2017-01-25 08:03:07 +090088 # 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 Takashi25935722017-01-23 15:34:11 +090099 # Source VM
YAMAMOTO Takashi60faf4f2017-01-25 08:03:07 +0900100 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 Takashi25935722017-01-23 15:34:11 +0900107 CONF.validation.image_ssh_user,
YAMAMOTO Takashi60faf4f2017-01-25 08:03:07 +0900108 pkey=self.keypair['private_key'],
109 proxy_client=proxy_client)
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900110
111 # Destination VM
112 if self.dest_has_fip:
Genadi Chereshnya918dd0b2017-05-17 13:02:20 +0000113 dest_server = self._create_server(network=self._dest_network)
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900114 else:
Genadi Chereshnya918dd0b2017-05-17 13:02:20 +0000115 dest_server = self._create_server(create_floating_ip=False,
116 network=self._dest_network)
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900117
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
126class FloatingIpSameNetwork(FloatingIpTestCasesMixin,
127 base.BaseTempestTestCase):
YAMAMOTO Takashi60faf4f2017-01-25 08:03:07 +0900128 scenarios = multiply_scenarios([
129 ('SRC with FIP', dict(src_has_fip=True)),
130 ('SRC without FIP', dict(src_has_fip=False)),
131 ], [
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900132 ('DEST with FIP', dict(dest_has_fip=True)),
133 ('DEST without FIP', dict(dest_has_fip=False)),
YAMAMOTO Takashi60faf4f2017-01-25 08:03:07 +0900134 ])
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900135
136 same_network = True
137
Brian Haleyba800452017-12-14 10:30:48 -0500138 @common_utils.unstable_test("bug 1717302")
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000139 @decorators.idempotent_id('05c4e3b3-7319-4052-90ad-e8916436c23b')
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900140 def test_east_west(self):
141 self._test_east_west()
142
143
144class FloatingIpSeparateNetwork(FloatingIpTestCasesMixin,
145 base.BaseTempestTestCase):
YAMAMOTO Takashi60faf4f2017-01-25 08:03:07 +0900146 scenarios = multiply_scenarios([
147 ('SRC with FIP', dict(src_has_fip=True)),
148 ('SRC without FIP', dict(src_has_fip=False)),
149 ], [
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900150 ('DEST with FIP', dict(dest_has_fip=True)),
151 ('DEST without FIP', dict(dest_has_fip=False)),
YAMAMOTO Takashi60faf4f2017-01-25 08:03:07 +0900152 ])
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900153
154 same_network = False
155
Brian Haleyba800452017-12-14 10:30:48 -0500156 @common_utils.unstable_test("bug 1717302")
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000157 @decorators.idempotent_id('f18f0090-3289-4783-b956-a0f8ac511e8b')
YAMAMOTO Takashi25935722017-01-23 15:34:11 +0900158 def test_east_west(self):
159 self._test_east_west()