blob: 9f4e62b6e1e3c34046bbeb18388ad2df5598f2ed [file] [log] [blame]
Kirill Shileev14113572014-11-21 16:58:02 +03001# Copyright 2014 Cisco Systems, Inc.
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.
Andrea Frittolicd368412017-08-14 21:37:56 +010015from tempest.common import utils
Kirill Shileev14113572014-11-21 16:58:02 +030016from tempest import config
Steve Heyman33735f22016-05-24 09:28:08 -050017from tempest.lib.common.utils import test_utils
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080018from tempest.lib import decorators
Kirill Shileev14113572014-11-21 16:58:02 +030019from tempest.scenario import manager
Kirill Shileev14113572014-11-21 16:58:02 +030020
Kirill Shileev14113572014-11-21 16:58:02 +030021CONF = config.CONF
Kirill Shileev14113572014-11-21 16:58:02 +030022
23
24class TestGettingAddress(manager.NetworkScenarioTest):
Yair Friede198e2f2015-07-28 14:43:47 +030025 """Test Summary:
26
27 1. Create network with subnets:
28 1.1. one IPv4 and
29 1.2. one or more IPv6 in a given address mode
30 2. Boot 2 VMs on this network
31 3. Allocate and assign 2 FIP4
32 4. Check that vNICs of all VMs gets all addresses actually assigned
33 5. Each VM will ping the other's v4 private address
34 6. If ping6 available in VM, each VM will ping all of the other's v6
35 addresses as well as the router's
Kirill Shileev14113572014-11-21 16:58:02 +030036 """
37
38 @classmethod
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000039 def skip_checks(cls):
40 super(TestGettingAddress, cls).skip_checks()
Kirill Shileev14113572014-11-21 16:58:02 +030041 if not (CONF.network_feature_enabled.ipv6
42 and CONF.network_feature_enabled.ipv6_subnet_attributes):
Kirill Shileev14113572014-11-21 16:58:02 +030043 raise cls.skipException('IPv6 or its attributes not supported')
Sean Dagueed6e5862016-04-04 10:49:13 -040044 if not (CONF.network.project_networks_reachable
Kirill Shileev14113572014-11-21 16:58:02 +030045 or CONF.network.public_network_id):
Sean Dagueed6e5862016-04-04 10:49:13 -040046 msg = ('Either project_networks_reachable must be "true", or '
Kirill Shileev14113572014-11-21 16:58:02 +030047 'public_network_id must be defined.')
Kirill Shileev14113572014-11-21 16:58:02 +030048 raise cls.skipException(msg)
ghanshyam929b3482016-12-05 11:47:53 +090049 if CONF.network.shared_physical_network:
Thiago Paiva66cded22016-08-15 14:55:58 -030050 msg = 'Deployment uses a shared physical network'
Adam Gandelmanab6106d2014-12-12 10:38:23 -080051 raise cls.skipException(msg)
Matthew Treinish3312de32017-05-19 12:08:17 -040052 if not CONF.network_feature_enabled.floating_ips:
53 raise cls.skipException("Floating ips are not available")
Adam Gandelman721f80d2014-12-12 11:03:14 -080054
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000055 @classmethod
56 def setup_credentials(cls):
57 # Create no network resources for these tests.
58 cls.set_network_resources()
59 super(TestGettingAddress, cls).setup_credentials()
Kirill Shileev14113572014-11-21 16:58:02 +030060
61 def setUp(self):
62 super(TestGettingAddress, self).setUp()
63 self.keypair = self.create_keypair()
Marc Koderer410c7822016-11-08 11:47:00 +010064 self.sec_grp = self._create_security_group()
Kirill Shileev14113572014-11-21 16:58:02 +030065
Daniel Mellado9e3e1062015-08-06 18:07:05 +020066 def prepare_network(self, address6_mode, n_subnets6=1, dualnet=False):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000067 """Prepare network
68
69 Creates network with given number of IPv6 subnets in the given mode and
70 one IPv4 subnet.
71 Creates router with ports on all subnets.
72 if dualnet - create IPv6 subnets on a different network
73 :return: list of created networks
Kirill Shileev14113572014-11-21 16:58:02 +030074 """
Jordan Pittier37b94a02017-02-21 18:11:55 +010075 network = self._create_network()
Daniel Mellado9e3e1062015-08-06 18:07:05 +020076 if dualnet:
Jordan Pittier37b94a02017-02-21 18:11:55 +010077 network_v6 = self._create_network()
Daniel Mellado9e3e1062015-08-06 18:07:05 +020078
zhufl5b0a52f2017-10-24 15:48:20 +080079 sub4 = self.create_subnet(network=network,
80 namestart='sub4',
81 ip_version=4)
Kirill Shileev14113572014-11-21 16:58:02 +030082
Marc Koderer410c7822016-11-08 11:47:00 +010083 router = self._get_router()
Steve Heyman33735f22016-05-24 09:28:08 -050084 self.routers_client.add_router_interface(router['id'],
85 subnet_id=sub4['id'])
86
87 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
88 self.routers_client.remove_router_interface,
89 router['id'], subnet_id=sub4['id'])
Kirill Shileevb1f97522015-02-19 20:39:05 +030090
Yair Friede198e2f2015-07-28 14:43:47 +030091 self.subnets_v6 = []
Kirill Shileevb1f97522015-02-19 20:39:05 +030092 for _ in range(n_subnets6):
Jordan Pittier37b94a02017-02-21 18:11:55 +010093 net6 = network_v6 if dualnet else network
zhufl5b0a52f2017-10-24 15:48:20 +080094 sub6 = self.create_subnet(network=net6,
95 namestart='sub6',
96 ip_version=6,
97 ipv6_ra_mode=address6_mode,
98 ipv6_address_mode=address6_mode)
Kirill Shileevb1f97522015-02-19 20:39:05 +030099
Steve Heyman33735f22016-05-24 09:28:08 -0500100 self.routers_client.add_router_interface(router['id'],
101 subnet_id=sub6['id'])
Kirill Shileev14113572014-11-21 16:58:02 +0300102
Steve Heyman33735f22016-05-24 09:28:08 -0500103 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
104 self.routers_client.remove_router_interface,
105 router['id'], subnet_id=sub6['id'])
106
107 self.subnets_v6.append(sub6)
Jordan Pittier37b94a02017-02-21 18:11:55 +0100108 return [network, network_v6] if dualnet else [network]
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200109
Kirill Shileev14113572014-11-21 16:58:02 +0300110 @staticmethod
111 def define_server_ips(srv):
Kirill Shileevb1f97522015-02-19 20:39:05 +0300112 ips = {'4': None, '6': []}
Béla Vancsicsb6dfa082017-03-01 10:44:58 +0100113 for nics in srv['addresses'].values():
Kirill Shileev14113572014-11-21 16:58:02 +0300114 for nic in nics:
115 if nic['version'] == 6:
Kirill Shileevb1f97522015-02-19 20:39:05 +0300116 ips['6'].append(nic['addr'])
Kirill Shileev14113572014-11-21 16:58:02 +0300117 else:
Kirill Shileevb1f97522015-02-19 20:39:05 +0300118 ips['4'] = nic['addr']
119 return ips
Kirill Shileev14113572014-11-21 16:58:02 +0300120
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200121 def prepare_server(self, networks=None):
lanoux283273b2015-12-04 03:01:54 -0800122 username = CONF.validation.image_ssh_user
Kirill Shileev14113572014-11-21 16:58:02 +0300123
lanoux5fc14522015-09-21 08:17:35 +0000124 srv = self.create_server(
125 key_name=self.keypair['name'],
126 security_groups=[{'name': self.sec_grp['name']}],
zhufl13c9c892017-02-10 12:04:07 +0800127 networks=[{'uuid': n['id']} for n in networks])
Kirill Shileev14113572014-11-21 16:58:02 +0300128 fip = self.create_floating_ip(thing=srv)
Kirill Shileevb1f97522015-02-19 20:39:05 +0300129 ips = self.define_server_ips(srv=srv)
Kirill Shileev14113572014-11-21 16:58:02 +0300130 ssh = self.get_remote_client(
Steve Heyman33735f22016-05-24 09:28:08 -0500131 ip_address=fip['floating_ip_address'],
zhuflf52c7592017-05-25 13:55:24 +0800132 username=username, server=srv)
Ihar Hrachyshkaf9fda2d2017-11-06 13:16:09 -0800133 return ssh, ips, srv
Kirill Shileev14113572014-11-21 16:58:02 +0300134
Jordan Pittier37b94a02017-02-21 18:11:55 +0100135 def turn_nic6_on(self, ssh, sid, network_id):
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200136 """Turns the IPv6 vNIC on
Kirill Shileev14113572014-11-21 16:58:02 +0300137
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200138 Required because guest images usually set only the first vNIC on boot.
139 Searches for the IPv6 vNIC's MAC and brings it up.
140
141 @param ssh: RemoteClient ssh instance to server
142 @param sid: server uuid
Jordan Pittier37b94a02017-02-21 18:11:55 +0100143 @param network_id: the network id the NIC is connected to
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200144 """
Jordan Pittier64e6b442017-02-20 19:29:02 +0100145 ports = [
146 p["mac_address"] for p in
jeremy.zhang5870ff12017-05-25 11:24:23 +0800147 self.os_admin.ports_client.list_ports(
Jordan Pittier37b94a02017-02-21 18:11:55 +0100148 device_id=sid, network_id=network_id)['ports']
Jordan Pittier64e6b442017-02-20 19:29:02 +0100149 ]
Jordan Pittier37b94a02017-02-21 18:11:55 +0100150
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200151 self.assertEqual(1, len(ports),
Ken'ichi Ohmichi695ac5c2015-10-13 03:07:17 +0000152 message=("Multiple IPv6 ports found on network %s. "
153 "ports: %s")
Jordan Pittier37b94a02017-02-21 18:11:55 +0100154 % (network_id, ports))
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200155 mac6 = ports[0]
Ken'ichi Ohmichi126fe982017-03-17 10:41:44 -0700156 nic = ssh.get_nic_name_by_mac(mac6)
157 ssh.exec_command("sudo ip link set %s up" % nic)
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200158
159 def _prepare_and_test(self, address6_mode, n_subnets6=1, dualnet=False):
160 net_list = self.prepare_network(address6_mode=address6_mode,
161 n_subnets6=n_subnets6,
162 dualnet=dualnet)
163
Ihar Hrachyshkaf9fda2d2017-11-06 13:16:09 -0800164 sshv4_1, ips_from_api_1, srv1 = self.prepare_server(networks=net_list)
165 sshv4_2, ips_from_api_2, srv2 = self.prepare_server(networks=net_list)
Kirill Shileev14113572014-11-21 16:58:02 +0300166
Henry Gessau0efcfb92015-02-27 15:24:39 -0500167 def guest_has_address(ssh, addr):
Ken'ichi Ohmichi84aeba62017-03-01 18:31:20 -0800168 return addr in ssh.exec_command("ip address")
Henry Gessau0efcfb92015-02-27 15:24:39 -0500169
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200170 # Turn on 2nd NIC for Cirros when dualnet
171 if dualnet:
Ferenc Horváthbce1fcf2017-06-07 11:19:51 +0200172 _, network_v6 = net_list
Ihar Hrachyshkaf9fda2d2017-11-06 13:16:09 -0800173 self.turn_nic6_on(sshv4_1, srv1['id'], network_v6['id'])
174 self.turn_nic6_on(sshv4_2, srv2['id'], network_v6['id'])
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200175
Kirill Shileevb1f97522015-02-19 20:39:05 +0300176 # get addresses assigned to vNIC as reported by 'ip address' utility
Ken'ichi Ohmichi84aeba62017-03-01 18:31:20 -0800177 ips_from_ip_1 = sshv4_1.exec_command("ip address")
178 ips_from_ip_2 = sshv4_2.exec_command("ip address")
Kirill Shileevb1f97522015-02-19 20:39:05 +0300179 self.assertIn(ips_from_api_1['4'], ips_from_ip_1)
180 self.assertIn(ips_from_api_2['4'], ips_from_ip_2)
181 for i in range(n_subnets6):
182 # v6 should be configured since the image supports it
183 # It can take time for ipv6 automatic address to get assigned
Ihar Hrachyshkaf9fda2d2017-11-06 13:16:09 -0800184 for srv, ssh, ips in (
185 (srv1, sshv4_1, ips_from_api_1),
186 (srv2, sshv4_2, ips_from_api_2)):
187 ip = ips['6'][i]
188 result = test_utils.call_until_true(
189 guest_has_address,
190 CONF.validation.ping_timeout, 1, ssh, ip)
191 if not result:
192 self._log_console_output(servers=[srv])
193 self.fail(
194 'Address %s not configured for instance %s, '
195 'ip address output is\n%s' %
196 (ip, srv['id'], ssh.exec_command("ip address")))
Kirill Shileevb1f97522015-02-19 20:39:05 +0300197
YAMAMOTO Takashi4c3ebb02017-01-25 16:04:30 +0900198 self.check_remote_connectivity(sshv4_1, ips_from_api_2['4'])
199 self.check_remote_connectivity(sshv4_2, ips_from_api_1['4'])
Kirill Shileev14113572014-11-21 16:58:02 +0300200
Sean M. Collinsc0378482015-10-26 12:59:47 +0900201 for i in range(n_subnets6):
YAMAMOTO Takashi4c3ebb02017-01-25 16:04:30 +0900202 self.check_remote_connectivity(sshv4_1,
203 ips_from_api_2['6'][i])
204 self.check_remote_connectivity(sshv4_1,
205 self.subnets_v6[i]['gateway_ip'])
206 self.check_remote_connectivity(sshv4_2,
207 ips_from_api_1['6'][i])
208 self.check_remote_connectivity(sshv4_2,
209 self.subnets_v6[i]['gateway_ip'])
Yair Friede198e2f2015-07-28 14:43:47 +0300210
Jordan Pittier3b46d272017-04-12 16:17:28 +0200211 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800212 @decorators.idempotent_id('2c92df61-29f0-4eaa-bee3-7c65bef62a43')
Andrea Frittolicd368412017-08-14 21:37:56 +0100213 @utils.services('compute', 'network')
Kirill Shileev14113572014-11-21 16:58:02 +0300214 def test_slaac_from_os(self):
215 self._prepare_and_test(address6_mode='slaac')
216
Jordan Pittier3b46d272017-04-12 16:17:28 +0200217 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800218 @decorators.idempotent_id('d7e1f858-187c-45a6-89c9-bdafde619a9f')
Andrea Frittolicd368412017-08-14 21:37:56 +0100219 @utils.services('compute', 'network')
Kirill Shileev14113572014-11-21 16:58:02 +0300220 def test_dhcp6_stateless_from_os(self):
221 self._prepare_and_test(address6_mode='dhcpv6-stateless')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300222
Jordan Pittier3b46d272017-04-12 16:17:28 +0200223 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800224 @decorators.idempotent_id('7ab23f41-833b-4a16-a7c9-5b42fe6d4123')
Andrea Frittolicd368412017-08-14 21:37:56 +0100225 @utils.services('compute', 'network')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300226 def test_multi_prefix_dhcpv6_stateless(self):
227 self._prepare_and_test(address6_mode='dhcpv6-stateless', n_subnets6=2)
228
Jordan Pittier3b46d272017-04-12 16:17:28 +0200229 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800230 @decorators.idempotent_id('dec222b1-180c-4098-b8c5-cc1b8342d611')
Andrea Frittolicd368412017-08-14 21:37:56 +0100231 @utils.services('compute', 'network')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300232 def test_multi_prefix_slaac(self):
233 self._prepare_and_test(address6_mode='slaac', n_subnets6=2)
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200234
Jordan Pittier3b46d272017-04-12 16:17:28 +0200235 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800236 @decorators.idempotent_id('b6399d76-4438-4658-bcf5-0d6c8584fde2')
Andrea Frittolicd368412017-08-14 21:37:56 +0100237 @utils.services('compute', 'network')
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200238 def test_dualnet_slaac_from_os(self):
239 self._prepare_and_test(address6_mode='slaac', dualnet=True)
240
Jordan Pittier3b46d272017-04-12 16:17:28 +0200241 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800242 @decorators.idempotent_id('76f26acd-9688-42b4-bc3e-cd134c4cb09e')
Andrea Frittolicd368412017-08-14 21:37:56 +0100243 @utils.services('compute', 'network')
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200244 def test_dualnet_dhcp6_stateless_from_os(self):
245 self._prepare_and_test(address6_mode='dhcpv6-stateless', dualnet=True)
246
Jordan Pittier3b46d272017-04-12 16:17:28 +0200247 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800248 @decorators.idempotent_id('cf1c4425-766b-45b8-be35-e2959728eb00')
Andrea Frittolicd368412017-08-14 21:37:56 +0100249 @utils.services('compute', 'network')
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200250 def test_dualnet_multi_prefix_dhcpv6_stateless(self):
251 self._prepare_and_test(address6_mode='dhcpv6-stateless', n_subnets6=2,
252 dualnet=True)
253
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800254 @decorators.idempotent_id('9178ad42-10e4-47e9-8987-e02b170cc5cd')
Andrea Frittolicd368412017-08-14 21:37:56 +0100255 @utils.services('compute', 'network')
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200256 def test_dualnet_multi_prefix_slaac(self):
257 self._prepare_and_test(address6_mode='slaac', n_subnets6=2,
258 dualnet=True)