blob: 14f24c79e1f0e20b72fefdd0beddec2fb7fea61b [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.
Slawek Kaplonskic5c7ba92018-10-04 15:21:45 +020015
16from oslo_log import log as logging
17
Andrea Frittolicd368412017-08-14 21:37:56 +010018from tempest.common import utils
Kirill Shileev14113572014-11-21 16:58:02 +030019from tempest import config
Steve Heyman33735f22016-05-24 09:28:08 -050020from tempest.lib.common.utils import test_utils
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080021from tempest.lib import decorators
Slawek Kaplonskic5c7ba92018-10-04 15:21:45 +020022from tempest.lib import exceptions
Kirill Shileev14113572014-11-21 16:58:02 +030023from tempest.scenario import manager
Kirill Shileev14113572014-11-21 16:58:02 +030024
Kirill Shileev14113572014-11-21 16:58:02 +030025CONF = config.CONF
Slawek Kaplonskic5c7ba92018-10-04 15:21:45 +020026LOG = logging.getLogger(__name__)
Kirill Shileev14113572014-11-21 16:58:02 +030027
28
29class TestGettingAddress(manager.NetworkScenarioTest):
Yair Friede198e2f2015-07-28 14:43:47 +030030 """Test Summary:
31
32 1. Create network with subnets:
33 1.1. one IPv4 and
34 1.2. one or more IPv6 in a given address mode
35 2. Boot 2 VMs on this network
36 3. Allocate and assign 2 FIP4
37 4. Check that vNICs of all VMs gets all addresses actually assigned
38 5. Each VM will ping the other's v4 private address
39 6. If ping6 available in VM, each VM will ping all of the other's v6
40 addresses as well as the router's
Kirill Shileev14113572014-11-21 16:58:02 +030041 """
42
43 @classmethod
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000044 def skip_checks(cls):
45 super(TestGettingAddress, cls).skip_checks()
Federico Ressi2d6bcaa2018-04-11 12:37:36 +020046 if not (CONF.network_feature_enabled.ipv6 and
47 CONF.network_feature_enabled.ipv6_subnet_attributes):
Kirill Shileev14113572014-11-21 16:58:02 +030048 raise cls.skipException('IPv6 or its attributes not supported')
Federico Ressi2d6bcaa2018-04-11 12:37:36 +020049 if not (CONF.network.project_networks_reachable or
50 CONF.network.public_network_id):
Sean Dagueed6e5862016-04-04 10:49:13 -040051 msg = ('Either project_networks_reachable must be "true", or '
Kirill Shileev14113572014-11-21 16:58:02 +030052 'public_network_id must be defined.')
Kirill Shileev14113572014-11-21 16:58:02 +030053 raise cls.skipException(msg)
ghanshyam929b3482016-12-05 11:47:53 +090054 if CONF.network.shared_physical_network:
Thiago Paiva66cded22016-08-15 14:55:58 -030055 msg = 'Deployment uses a shared physical network'
Adam Gandelmanab6106d2014-12-12 10:38:23 -080056 raise cls.skipException(msg)
Matthew Treinish3312de32017-05-19 12:08:17 -040057 if not CONF.network_feature_enabled.floating_ips:
58 raise cls.skipException("Floating ips are not available")
Adam Gandelman721f80d2014-12-12 11:03:14 -080059
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000060 @classmethod
61 def setup_credentials(cls):
62 # Create no network resources for these tests.
63 cls.set_network_resources()
64 super(TestGettingAddress, cls).setup_credentials()
Kirill Shileev14113572014-11-21 16:58:02 +030065
66 def setUp(self):
67 super(TestGettingAddress, self).setUp()
68 self.keypair = self.create_keypair()
Marc Koderer410c7822016-11-08 11:47:00 +010069 self.sec_grp = self._create_security_group()
Kirill Shileev14113572014-11-21 16:58:02 +030070
Daniel Mellado9e3e1062015-08-06 18:07:05 +020071 def prepare_network(self, address6_mode, n_subnets6=1, dualnet=False):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000072 """Prepare network
73
74 Creates network with given number of IPv6 subnets in the given mode and
75 one IPv4 subnet.
76 Creates router with ports on all subnets.
77 if dualnet - create IPv6 subnets on a different network
78 :return: list of created networks
Kirill Shileev14113572014-11-21 16:58:02 +030079 """
Jordan Pittier37b94a02017-02-21 18:11:55 +010080 network = self._create_network()
Daniel Mellado9e3e1062015-08-06 18:07:05 +020081 if dualnet:
Jordan Pittier37b94a02017-02-21 18:11:55 +010082 network_v6 = self._create_network()
Daniel Mellado9e3e1062015-08-06 18:07:05 +020083
zhufl5b0a52f2017-10-24 15:48:20 +080084 sub4 = self.create_subnet(network=network,
85 namestart='sub4',
86 ip_version=4)
Kirill Shileev14113572014-11-21 16:58:02 +030087
Marc Koderer410c7822016-11-08 11:47:00 +010088 router = self._get_router()
Steve Heyman33735f22016-05-24 09:28:08 -050089 self.routers_client.add_router_interface(router['id'],
90 subnet_id=sub4['id'])
91
92 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
93 self.routers_client.remove_router_interface,
94 router['id'], subnet_id=sub4['id'])
Kirill Shileevb1f97522015-02-19 20:39:05 +030095
Yair Friede198e2f2015-07-28 14:43:47 +030096 self.subnets_v6 = []
Kirill Shileevb1f97522015-02-19 20:39:05 +030097 for _ in range(n_subnets6):
Jordan Pittier37b94a02017-02-21 18:11:55 +010098 net6 = network_v6 if dualnet else network
zhufl5b0a52f2017-10-24 15:48:20 +080099 sub6 = self.create_subnet(network=net6,
100 namestart='sub6',
101 ip_version=6,
102 ipv6_ra_mode=address6_mode,
103 ipv6_address_mode=address6_mode)
Kirill Shileevb1f97522015-02-19 20:39:05 +0300104
Steve Heyman33735f22016-05-24 09:28:08 -0500105 self.routers_client.add_router_interface(router['id'],
106 subnet_id=sub6['id'])
Kirill Shileev14113572014-11-21 16:58:02 +0300107
Steve Heyman33735f22016-05-24 09:28:08 -0500108 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
109 self.routers_client.remove_router_interface,
110 router['id'], subnet_id=sub6['id'])
111
112 self.subnets_v6.append(sub6)
Jordan Pittier37b94a02017-02-21 18:11:55 +0100113 return [network, network_v6] if dualnet else [network]
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200114
Kirill Shileev14113572014-11-21 16:58:02 +0300115 @staticmethod
116 def define_server_ips(srv):
Kirill Shileevb1f97522015-02-19 20:39:05 +0300117 ips = {'4': None, '6': []}
Béla Vancsicsb6dfa082017-03-01 10:44:58 +0100118 for nics in srv['addresses'].values():
Kirill Shileev14113572014-11-21 16:58:02 +0300119 for nic in nics:
120 if nic['version'] == 6:
Kirill Shileevb1f97522015-02-19 20:39:05 +0300121 ips['6'].append(nic['addr'])
Kirill Shileev14113572014-11-21 16:58:02 +0300122 else:
Kirill Shileevb1f97522015-02-19 20:39:05 +0300123 ips['4'] = nic['addr']
124 return ips
Kirill Shileev14113572014-11-21 16:58:02 +0300125
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200126 def prepare_server(self, networks=None):
lanoux283273b2015-12-04 03:01:54 -0800127 username = CONF.validation.image_ssh_user
Kirill Shileev14113572014-11-21 16:58:02 +0300128
lanoux5fc14522015-09-21 08:17:35 +0000129 srv = self.create_server(
130 key_name=self.keypair['name'],
131 security_groups=[{'name': self.sec_grp['name']}],
zhufl13c9c892017-02-10 12:04:07 +0800132 networks=[{'uuid': n['id']} for n in networks])
Soniya Vyas0c84f3e2020-07-15 15:20:59 +0530133 fip = self.create_floating_ip(server=srv)
Kirill Shileevb1f97522015-02-19 20:39:05 +0300134 ips = self.define_server_ips(srv=srv)
Kirill Shileev14113572014-11-21 16:58:02 +0300135 ssh = self.get_remote_client(
Steve Heyman33735f22016-05-24 09:28:08 -0500136 ip_address=fip['floating_ip_address'],
zhuflf52c7592017-05-25 13:55:24 +0800137 username=username, server=srv)
Ihar Hrachyshkaf9fda2d2017-11-06 13:16:09 -0800138 return ssh, ips, srv
Kirill Shileev14113572014-11-21 16:58:02 +0300139
Jordan Pittier37b94a02017-02-21 18:11:55 +0100140 def turn_nic6_on(self, ssh, sid, network_id):
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200141 """Turns the IPv6 vNIC on
Kirill Shileev14113572014-11-21 16:58:02 +0300142
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200143 Required because guest images usually set only the first vNIC on boot.
144 Searches for the IPv6 vNIC's MAC and brings it up.
145
146 @param ssh: RemoteClient ssh instance to server
147 @param sid: server uuid
Jordan Pittier37b94a02017-02-21 18:11:55 +0100148 @param network_id: the network id the NIC is connected to
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200149 """
Jordan Pittier64e6b442017-02-20 19:29:02 +0100150 ports = [
151 p["mac_address"] for p in
jeremy.zhang5870ff12017-05-25 11:24:23 +0800152 self.os_admin.ports_client.list_ports(
Jordan Pittier37b94a02017-02-21 18:11:55 +0100153 device_id=sid, network_id=network_id)['ports']
Jordan Pittier64e6b442017-02-20 19:29:02 +0100154 ]
Jordan Pittier37b94a02017-02-21 18:11:55 +0100155
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200156 self.assertEqual(1, len(ports),
Ken'ichi Ohmichi695ac5c2015-10-13 03:07:17 +0000157 message=("Multiple IPv6 ports found on network %s. "
158 "ports: %s")
Jordan Pittier37b94a02017-02-21 18:11:55 +0100159 % (network_id, ports))
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200160 mac6 = ports[0]
Ken'ichi Ohmichi126fe982017-03-17 10:41:44 -0700161 nic = ssh.get_nic_name_by_mac(mac6)
Slawek Kaplonskic5c7ba92018-10-04 15:21:45 +0200162 # NOTE(slaweq): on RHEL based OS ifcfg file for new interface is
163 # needed to make IPv6 working on it, so if
164 # /etc/sysconfig/network-scripts directory exists ifcfg-%(nic)s file
165 # should be added in it
166 if self._sysconfig_network_scripts_dir_exists(ssh):
167 try:
168 ssh.exec_command(
Martin Kopec65c89112019-05-03 18:46:17 +0000169 'echo -e "DEVICE=%(nic)s\\nNAME=%(nic)s\\nIPV6INIT=yes" | '
Slawek Kaplonskic5c7ba92018-10-04 15:21:45 +0200170 'sudo tee /etc/sysconfig/network-scripts/ifcfg-%(nic)s; '
Martin Kopec65c89112019-05-03 18:46:17 +0000171 'sudo nmcli connection reload' % {'nic': nic})
172 ssh.exec_command('sudo nmcli connection up %s' % nic)
Slawek Kaplonskic5c7ba92018-10-04 15:21:45 +0200173 except exceptions.SSHExecCommandFailed as e:
174 # NOTE(slaweq): Sometimes it can happen that this SSH command
175 # will fail because of some error from network manager in
176 # guest os.
177 # But even then doing ip link set up below is fine and
178 # IP address should be configured properly.
179 LOG.debug("Error during restarting %(nic)s interface on "
180 "instance. Error message: %(error)s",
181 {'nic': nic, 'error': e})
Ken'ichi Ohmichi126fe982017-03-17 10:41:44 -0700182 ssh.exec_command("sudo ip link set %s up" % nic)
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200183
Slawek Kaplonskic5c7ba92018-10-04 15:21:45 +0200184 def _sysconfig_network_scripts_dir_exists(self, ssh):
185 return "False" not in ssh.exec_command(
186 'test -d /etc/sysconfig/network-scripts/ || echo "False"')
187
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200188 def _prepare_and_test(self, address6_mode, n_subnets6=1, dualnet=False):
189 net_list = self.prepare_network(address6_mode=address6_mode,
190 n_subnets6=n_subnets6,
191 dualnet=dualnet)
192
Ihar Hrachyshkaf9fda2d2017-11-06 13:16:09 -0800193 sshv4_1, ips_from_api_1, srv1 = self.prepare_server(networks=net_list)
194 sshv4_2, ips_from_api_2, srv2 = self.prepare_server(networks=net_list)
Kirill Shileev14113572014-11-21 16:58:02 +0300195
Henry Gessau0efcfb92015-02-27 15:24:39 -0500196 def guest_has_address(ssh, addr):
Ken'ichi Ohmichi84aeba62017-03-01 18:31:20 -0800197 return addr in ssh.exec_command("ip address")
Henry Gessau0efcfb92015-02-27 15:24:39 -0500198
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200199 # Turn on 2nd NIC for Cirros when dualnet
200 if dualnet:
Ferenc Horváthbce1fcf2017-06-07 11:19:51 +0200201 _, network_v6 = net_list
Ihar Hrachyshkaf9fda2d2017-11-06 13:16:09 -0800202 self.turn_nic6_on(sshv4_1, srv1['id'], network_v6['id'])
203 self.turn_nic6_on(sshv4_2, srv2['id'], network_v6['id'])
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200204
Kirill Shileevb1f97522015-02-19 20:39:05 +0300205 # get addresses assigned to vNIC as reported by 'ip address' utility
Ken'ichi Ohmichi84aeba62017-03-01 18:31:20 -0800206 ips_from_ip_1 = sshv4_1.exec_command("ip address")
207 ips_from_ip_2 = sshv4_2.exec_command("ip address")
Kirill Shileevb1f97522015-02-19 20:39:05 +0300208 self.assertIn(ips_from_api_1['4'], ips_from_ip_1)
209 self.assertIn(ips_from_api_2['4'], ips_from_ip_2)
210 for i in range(n_subnets6):
211 # v6 should be configured since the image supports it
212 # It can take time for ipv6 automatic address to get assigned
Ihar Hrachyshkaf9fda2d2017-11-06 13:16:09 -0800213 for srv, ssh, ips in (
214 (srv1, sshv4_1, ips_from_api_1),
215 (srv2, sshv4_2, ips_from_api_2)):
216 ip = ips['6'][i]
217 result = test_utils.call_until_true(
218 guest_has_address,
219 CONF.validation.ping_timeout, 1, ssh, ip)
220 if not result:
221 self._log_console_output(servers=[srv])
222 self.fail(
223 'Address %s not configured for instance %s, '
224 'ip address output is\n%s' %
225 (ip, srv['id'], ssh.exec_command("ip address")))
Kirill Shileevb1f97522015-02-19 20:39:05 +0300226
YAMAMOTO Takashi4c3ebb02017-01-25 16:04:30 +0900227 self.check_remote_connectivity(sshv4_1, ips_from_api_2['4'])
228 self.check_remote_connectivity(sshv4_2, ips_from_api_1['4'])
Kirill Shileev14113572014-11-21 16:58:02 +0300229
Sean M. Collinsc0378482015-10-26 12:59:47 +0900230 for i in range(n_subnets6):
YAMAMOTO Takashi4c3ebb02017-01-25 16:04:30 +0900231 self.check_remote_connectivity(sshv4_1,
232 ips_from_api_2['6'][i])
233 self.check_remote_connectivity(sshv4_1,
234 self.subnets_v6[i]['gateway_ip'])
235 self.check_remote_connectivity(sshv4_2,
236 ips_from_api_1['6'][i])
237 self.check_remote_connectivity(sshv4_2,
238 self.subnets_v6[i]['gateway_ip'])
Yair Friede198e2f2015-07-28 14:43:47 +0300239
Jordan Pittier3b46d272017-04-12 16:17:28 +0200240 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800241 @decorators.idempotent_id('2c92df61-29f0-4eaa-bee3-7c65bef62a43')
Andrea Frittolicd368412017-08-14 21:37:56 +0100242 @utils.services('compute', 'network')
Kirill Shileev14113572014-11-21 16:58:02 +0300243 def test_slaac_from_os(self):
244 self._prepare_and_test(address6_mode='slaac')
245
Jordan Pittier3b46d272017-04-12 16:17:28 +0200246 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800247 @decorators.idempotent_id('d7e1f858-187c-45a6-89c9-bdafde619a9f')
Andrea Frittolicd368412017-08-14 21:37:56 +0100248 @utils.services('compute', 'network')
Kirill Shileev14113572014-11-21 16:58:02 +0300249 def test_dhcp6_stateless_from_os(self):
250 self._prepare_and_test(address6_mode='dhcpv6-stateless')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300251
Jordan Pittier3b46d272017-04-12 16:17:28 +0200252 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800253 @decorators.idempotent_id('7ab23f41-833b-4a16-a7c9-5b42fe6d4123')
Andrea Frittolicd368412017-08-14 21:37:56 +0100254 @utils.services('compute', 'network')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300255 def test_multi_prefix_dhcpv6_stateless(self):
256 self._prepare_and_test(address6_mode='dhcpv6-stateless', n_subnets6=2)
257
Jordan Pittier3b46d272017-04-12 16:17:28 +0200258 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800259 @decorators.idempotent_id('dec222b1-180c-4098-b8c5-cc1b8342d611')
Andrea Frittolicd368412017-08-14 21:37:56 +0100260 @utils.services('compute', 'network')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300261 def test_multi_prefix_slaac(self):
262 self._prepare_and_test(address6_mode='slaac', n_subnets6=2)
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200263
Jordan Pittier3b46d272017-04-12 16:17:28 +0200264 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800265 @decorators.idempotent_id('b6399d76-4438-4658-bcf5-0d6c8584fde2')
Andrea Frittolicd368412017-08-14 21:37:56 +0100266 @utils.services('compute', 'network')
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200267 def test_dualnet_slaac_from_os(self):
268 self._prepare_and_test(address6_mode='slaac', dualnet=True)
269
Jordan Pittier3b46d272017-04-12 16:17:28 +0200270 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800271 @decorators.idempotent_id('76f26acd-9688-42b4-bc3e-cd134c4cb09e')
Andrea Frittolicd368412017-08-14 21:37:56 +0100272 @utils.services('compute', 'network')
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200273 def test_dualnet_dhcp6_stateless_from_os(self):
274 self._prepare_and_test(address6_mode='dhcpv6-stateless', dualnet=True)
275
Jordan Pittier3b46d272017-04-12 16:17:28 +0200276 @decorators.attr(type='slow')
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800277 @decorators.idempotent_id('cf1c4425-766b-45b8-be35-e2959728eb00')
Andrea Frittolicd368412017-08-14 21:37:56 +0100278 @utils.services('compute', 'network')
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200279 def test_dualnet_multi_prefix_dhcpv6_stateless(self):
280 self._prepare_and_test(address6_mode='dhcpv6-stateless', n_subnets6=2,
281 dualnet=True)
282
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800283 @decorators.idempotent_id('9178ad42-10e4-47e9-8987-e02b170cc5cd')
ghanshyambd8cc592018-11-02 08:00:21 +0000284 @decorators.attr(type='slow')
Andrea Frittolicd368412017-08-14 21:37:56 +0100285 @utils.services('compute', 'network')
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200286 def test_dualnet_multi_prefix_slaac(self):
287 self._prepare_and_test(address6_mode='slaac', n_subnets6=2,
288 dualnet=True)