blob: 7acf107e4a95ec812ca60af495071d2282008a65 [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.
Henry Gessau0efcfb92015-02-27 15:24:39 -050015import functools
Doug Hellmann583ce2c2015-03-11 14:55:46 +000016
Kirill Shileev14113572014-11-21 16:58:02 +030017from tempest import config
Steve Heyman33735f22016-05-24 09:28:08 -050018from tempest.lib.common.utils import test_utils
Kirill Shileev14113572014-11-21 16:58:02 +030019from tempest.scenario import manager
20from tempest import test
21
22
23CONF = config.CONF
Kirill Shileev14113572014-11-21 16:58:02 +030024
25
26class TestGettingAddress(manager.NetworkScenarioTest):
Yair Friede198e2f2015-07-28 14:43:47 +030027 """Test Summary:
28
29 1. Create network with subnets:
30 1.1. one IPv4 and
31 1.2. one or more IPv6 in a given address mode
32 2. Boot 2 VMs on this network
33 3. Allocate and assign 2 FIP4
34 4. Check that vNICs of all VMs gets all addresses actually assigned
35 5. Each VM will ping the other's v4 private address
36 6. If ping6 available in VM, each VM will ping all of the other's v6
37 addresses as well as the router's
Kirill Shileev14113572014-11-21 16:58:02 +030038 """
39
40 @classmethod
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000041 def skip_checks(cls):
42 super(TestGettingAddress, cls).skip_checks()
Kirill Shileev14113572014-11-21 16:58:02 +030043 if not (CONF.network_feature_enabled.ipv6
44 and CONF.network_feature_enabled.ipv6_subnet_attributes):
Kirill Shileev14113572014-11-21 16:58:02 +030045 raise cls.skipException('IPv6 or its attributes not supported')
Sean Dagueed6e5862016-04-04 10:49:13 -040046 if not (CONF.network.project_networks_reachable
Kirill Shileev14113572014-11-21 16:58:02 +030047 or CONF.network.public_network_id):
Sean Dagueed6e5862016-04-04 10:49:13 -040048 msg = ('Either project_networks_reachable must be "true", or '
Kirill Shileev14113572014-11-21 16:58:02 +030049 'public_network_id must be defined.')
Kirill Shileev14113572014-11-21 16:58:02 +030050 raise cls.skipException(msg)
ghanshyam929b3482016-12-05 11:47:53 +090051 if CONF.network.shared_physical_network:
Thiago Paiva66cded22016-08-15 14:55:58 -030052 msg = 'Deployment uses a shared physical network'
Adam Gandelmanab6106d2014-12-12 10:38:23 -080053 raise cls.skipException(msg)
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 """
Marc Koderer410c7822016-11-08 11:47:00 +010075 self.network = self._create_network()
Daniel Mellado9e3e1062015-08-06 18:07:05 +020076 if dualnet:
Marc Koderer410c7822016-11-08 11:47:00 +010077 self.network_v6 = self._create_network()
Daniel Mellado9e3e1062015-08-06 18:07:05 +020078
Matthew Treinish8e48ad62014-12-12 11:07:23 -050079 sub4 = self._create_subnet(network=self.network,
Kirill Shileev14113572014-11-21 16:58:02 +030080 namestart='sub4',
Yair Friede198e2f2015-07-28 14:43:47 +030081 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):
Daniel Mellado9e3e1062015-08-06 18:07:05 +020093 net6 = self.network_v6 if dualnet else self.network
94 sub6 = self._create_subnet(network=net6,
Kirill Shileevb1f97522015-02-19 20:39:05 +030095 namestart='sub6',
96 ip_version=6,
97 ipv6_ra_mode=address6_mode,
98 ipv6_address_mode=address6_mode)
99
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)
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200108 return [self.network, self.network_v6] if dualnet else [self.network]
109
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': []}
guo yunxian7bbbec12016-08-21 20:03:10 +0800113 for net_name, nics in srv['addresses'].items():
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
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200124 networks = networks or [self.network]
Matthew Treinish8e48ad62014-12-12 11:07:23 -0500125
lanoux5fc14522015-09-21 08:17:35 +0000126 srv = self.create_server(
127 key_name=self.keypair['name'],
128 security_groups=[{'name': self.sec_grp['name']}],
Steve Heyman33735f22016-05-24 09:28:08 -0500129 networks=[{'uuid': n['id']} for n in networks],
lanoux5fc14522015-09-21 08:17:35 +0000130 wait_until='ACTIVE')
Kirill Shileev14113572014-11-21 16:58:02 +0300131 fip = self.create_floating_ip(thing=srv)
Kirill Shileevb1f97522015-02-19 20:39:05 +0300132 ips = self.define_server_ips(srv=srv)
Kirill Shileev14113572014-11-21 16:58:02 +0300133 ssh = self.get_remote_client(
Steve Heyman33735f22016-05-24 09:28:08 -0500134 ip_address=fip['floating_ip_address'],
Kirill Shileev14113572014-11-21 16:58:02 +0300135 username=username)
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200136 return ssh, ips, srv["id"]
Kirill Shileev14113572014-11-21 16:58:02 +0300137
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200138 def turn_nic6_on(self, ssh, sid):
139 """Turns the IPv6 vNIC on
Kirill Shileev14113572014-11-21 16:58:02 +0300140
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200141 Required because guest images usually set only the first vNIC on boot.
142 Searches for the IPv6 vNIC's MAC and brings it up.
143
144 @param ssh: RemoteClient ssh instance to server
145 @param sid: server uuid
146 """
147 ports = [p["mac_address"] for p in
148 self._list_ports(device_id=sid,
Steve Heyman33735f22016-05-24 09:28:08 -0500149 network_id=self.network_v6['id'])]
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200150 self.assertEqual(1, len(ports),
Ken'ichi Ohmichi695ac5c2015-10-13 03:07:17 +0000151 message=("Multiple IPv6 ports found on network %s. "
152 "ports: %s")
153 % (self.network_v6, ports))
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200154 mac6 = ports[0]
Evgeny Antyshev9b77ae52016-02-16 09:48:57 +0000155 ssh.set_nic_state(ssh.get_nic_name_by_mac(mac6))
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200156
157 def _prepare_and_test(self, address6_mode, n_subnets6=1, dualnet=False):
158 net_list = self.prepare_network(address6_mode=address6_mode,
159 n_subnets6=n_subnets6,
160 dualnet=dualnet)
161
162 sshv4_1, ips_from_api_1, sid1 = self.prepare_server(networks=net_list)
163 sshv4_2, ips_from_api_2, sid2 = self.prepare_server(networks=net_list)
Kirill Shileev14113572014-11-21 16:58:02 +0300164
Henry Gessau0efcfb92015-02-27 15:24:39 -0500165 def guest_has_address(ssh, addr):
166 return addr in ssh.get_ip_list()
167
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200168 # Turn on 2nd NIC for Cirros when dualnet
169 if dualnet:
170 self.turn_nic6_on(sshv4_1, sid1)
171 self.turn_nic6_on(sshv4_2, sid2)
172
Kirill Shileevb1f97522015-02-19 20:39:05 +0300173 # get addresses assigned to vNIC as reported by 'ip address' utility
174 ips_from_ip_1 = sshv4_1.get_ip_list()
175 ips_from_ip_2 = sshv4_2.get_ip_list()
176 self.assertIn(ips_from_api_1['4'], ips_from_ip_1)
177 self.assertIn(ips_from_api_2['4'], ips_from_ip_2)
178 for i in range(n_subnets6):
179 # v6 should be configured since the image supports it
180 # It can take time for ipv6 automatic address to get assigned
181 srv1_v6_addr_assigned = functools.partial(
182 guest_has_address, sshv4_1, ips_from_api_1['6'][i])
Henry Gessau0efcfb92015-02-27 15:24:39 -0500183
Kirill Shileevb1f97522015-02-19 20:39:05 +0300184 srv2_v6_addr_assigned = functools.partial(
185 guest_has_address, sshv4_2, ips_from_api_2['6'][i])
186
Jordan Pittier35a63752016-08-30 13:09:12 +0200187 self.assertTrue(test_utils.call_until_true(srv1_v6_addr_assigned,
lanoux5fc14522015-09-21 08:17:35 +0000188 CONF.validation.ping_timeout, 1))
Kirill Shileevb1f97522015-02-19 20:39:05 +0300189
Jordan Pittier35a63752016-08-30 13:09:12 +0200190 self.assertTrue(test_utils.call_until_true(srv2_v6_addr_assigned,
lanoux5fc14522015-09-21 08:17:35 +0000191 CONF.validation.ping_timeout, 1))
Kirill Shileevb1f97522015-02-19 20:39:05 +0300192
Yair Friede198e2f2015-07-28 14:43:47 +0300193 self._check_connectivity(sshv4_1, ips_from_api_2['4'])
194 self._check_connectivity(sshv4_2, ips_from_api_1['4'])
Kirill Shileev14113572014-11-21 16:58:02 +0300195
Sean M. Collinsc0378482015-10-26 12:59:47 +0900196 for i in range(n_subnets6):
197 self._check_connectivity(sshv4_1,
198 ips_from_api_2['6'][i])
199 self._check_connectivity(sshv4_1,
Steve Heyman33735f22016-05-24 09:28:08 -0500200 self.subnets_v6[i]['gateway_ip'])
Sean M. Collinsc0378482015-10-26 12:59:47 +0900201 self._check_connectivity(sshv4_2,
202 ips_from_api_1['6'][i])
203 self._check_connectivity(sshv4_2,
Steve Heyman33735f22016-05-24 09:28:08 -0500204 self.subnets_v6[i]['gateway_ip'])
Kirill Shileev14113572014-11-21 16:58:02 +0300205
Yair Friede198e2f2015-07-28 14:43:47 +0300206 def _check_connectivity(self, source, dest):
207 self.assertTrue(
208 self._check_remote_connectivity(source, dest),
209 "Timed out waiting for %s to become reachable from %s" %
210 (dest, source.ssh_client.host)
211 )
212
Brian Haley570527f2015-10-28 17:09:28 +0900213 @test.attr(type='slow')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800214 @test.idempotent_id('2c92df61-29f0-4eaa-bee3-7c65bef62a43')
Kirill Shileev14113572014-11-21 16:58:02 +0300215 @test.services('compute', 'network')
216 def test_slaac_from_os(self):
217 self._prepare_and_test(address6_mode='slaac')
218
Brian Haley570527f2015-10-28 17:09:28 +0900219 @test.attr(type='slow')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800220 @test.idempotent_id('d7e1f858-187c-45a6-89c9-bdafde619a9f')
Kirill Shileev14113572014-11-21 16:58:02 +0300221 @test.services('compute', 'network')
222 def test_dhcp6_stateless_from_os(self):
223 self._prepare_and_test(address6_mode='dhcpv6-stateless')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300224
Brian Haley570527f2015-10-28 17:09:28 +0900225 @test.attr(type='slow')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300226 @test.idempotent_id('7ab23f41-833b-4a16-a7c9-5b42fe6d4123')
227 @test.services('compute', 'network')
228 def test_multi_prefix_dhcpv6_stateless(self):
229 self._prepare_and_test(address6_mode='dhcpv6-stateless', n_subnets6=2)
230
Brian Haley570527f2015-10-28 17:09:28 +0900231 @test.attr(type='slow')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300232 @test.idempotent_id('dec222b1-180c-4098-b8c5-cc1b8342d611')
233 @test.services('compute', 'network')
234 def test_multi_prefix_slaac(self):
235 self._prepare_and_test(address6_mode='slaac', n_subnets6=2)
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200236
Brian Haley570527f2015-10-28 17:09:28 +0900237 @test.attr(type='slow')
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200238 @test.idempotent_id('b6399d76-4438-4658-bcf5-0d6c8584fde2')
239 @test.services('compute', 'network')
240 def test_dualnet_slaac_from_os(self):
241 self._prepare_and_test(address6_mode='slaac', dualnet=True)
242
Brian Haley570527f2015-10-28 17:09:28 +0900243 @test.attr(type='slow')
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200244 @test.idempotent_id('76f26acd-9688-42b4-bc3e-cd134c4cb09e')
245 @test.services('compute', 'network')
246 def test_dualnet_dhcp6_stateless_from_os(self):
247 self._prepare_and_test(address6_mode='dhcpv6-stateless', dualnet=True)
248
249 @test.idempotent_id('cf1c4425-766b-45b8-be35-e2959728eb00')
250 @test.services('compute', 'network')
251 def test_dualnet_multi_prefix_dhcpv6_stateless(self):
252 self._prepare_and_test(address6_mode='dhcpv6-stateless', n_subnets6=2,
253 dualnet=True)
254
255 @test.idempotent_id('9178ad42-10e4-47e9-8987-e02b170cc5cd')
256 @test.services('compute', 'network')
257 def test_dualnet_multi_prefix_slaac(self):
258 self._prepare_and_test(address6_mode='slaac', n_subnets6=2,
259 dualnet=True)