blob: 59ebb7a89c9717d7049c13eae981d84c270d22c7 [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
Matthew Treinish71426682015-04-23 11:19:38 -040017import six
Doug Hellmann583ce2c2015-03-11 14:55:46 +000018
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
Kirill Shileev14113572014-11-21 16:58:02 +030021from tempest.scenario import manager
22from tempest import test
23
24
25CONF = config.CONF
Kirill Shileev14113572014-11-21 16:58:02 +030026
27
28class TestGettingAddress(manager.NetworkScenarioTest):
Yair Friede198e2f2015-07-28 14:43:47 +030029 """Test Summary:
30
31 1. Create network with subnets:
32 1.1. one IPv4 and
33 1.2. one or more IPv6 in a given address mode
34 2. Boot 2 VMs on this network
35 3. Allocate and assign 2 FIP4
36 4. Check that vNICs of all VMs gets all addresses actually assigned
37 5. Each VM will ping the other's v4 private address
38 6. If ping6 available in VM, each VM will ping all of the other's v6
39 addresses as well as the router's
Kirill Shileev14113572014-11-21 16:58:02 +030040 """
41
42 @classmethod
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000043 def skip_checks(cls):
44 super(TestGettingAddress, cls).skip_checks()
Kirill Shileev14113572014-11-21 16:58:02 +030045 if not (CONF.network_feature_enabled.ipv6
46 and CONF.network_feature_enabled.ipv6_subnet_attributes):
Kirill Shileev14113572014-11-21 16:58:02 +030047 raise cls.skipException('IPv6 or its attributes not supported')
Sean Dagueed6e5862016-04-04 10:49:13 -040048 if not (CONF.network.project_networks_reachable
Kirill Shileev14113572014-11-21 16:58:02 +030049 or CONF.network.public_network_id):
Sean Dagueed6e5862016-04-04 10:49:13 -040050 msg = ('Either project_networks_reachable must be "true", or '
Kirill Shileev14113572014-11-21 16:58:02 +030051 'public_network_id must be defined.')
Kirill Shileev14113572014-11-21 16:58:02 +030052 raise cls.skipException(msg)
Adam Gandelmanab6106d2014-12-12 10:38:23 -080053 if CONF.baremetal.driver_enabled:
54 msg = ('Baremetal does not currently support network isolation')
55 raise cls.skipException(msg)
Adam Gandelman721f80d2014-12-12 11:03:14 -080056
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000057 @classmethod
58 def setup_credentials(cls):
59 # Create no network resources for these tests.
60 cls.set_network_resources()
61 super(TestGettingAddress, cls).setup_credentials()
Kirill Shileev14113572014-11-21 16:58:02 +030062
63 def setUp(self):
64 super(TestGettingAddress, self).setUp()
65 self.keypair = self.create_keypair()
66 self.sec_grp = self._create_security_group(tenant_id=self.tenant_id)
Kirill Shileev14113572014-11-21 16:58:02 +030067
Daniel Mellado9e3e1062015-08-06 18:07:05 +020068 def prepare_network(self, address6_mode, n_subnets6=1, dualnet=False):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000069 """Prepare network
70
71 Creates network with given number of IPv6 subnets in the given mode and
72 one IPv4 subnet.
73 Creates router with ports on all subnets.
74 if dualnet - create IPv6 subnets on a different network
75 :return: list of created networks
Kirill Shileev14113572014-11-21 16:58:02 +030076 """
Matthew Treinish8e48ad62014-12-12 11:07:23 -050077 self.network = self._create_network(tenant_id=self.tenant_id)
Daniel Mellado9e3e1062015-08-06 18:07:05 +020078 if dualnet:
79 self.network_v6 = self._create_network(tenant_id=self.tenant_id)
80
Matthew Treinish8e48ad62014-12-12 11:07:23 -050081 sub4 = self._create_subnet(network=self.network,
Kirill Shileev14113572014-11-21 16:58:02 +030082 namestart='sub4',
Yair Friede198e2f2015-07-28 14:43:47 +030083 ip_version=4)
Kirill Shileev14113572014-11-21 16:58:02 +030084
85 router = self._get_router(tenant_id=self.tenant_id)
Steve Heyman33735f22016-05-24 09:28:08 -050086 self.routers_client.add_router_interface(router['id'],
87 subnet_id=sub4['id'])
88
89 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
90 self.routers_client.remove_router_interface,
91 router['id'], subnet_id=sub4['id'])
Kirill Shileevb1f97522015-02-19 20:39:05 +030092
Yair Friede198e2f2015-07-28 14:43:47 +030093 self.subnets_v6 = []
Kirill Shileevb1f97522015-02-19 20:39:05 +030094 for _ in range(n_subnets6):
Daniel Mellado9e3e1062015-08-06 18:07:05 +020095 net6 = self.network_v6 if dualnet else self.network
96 sub6 = self._create_subnet(network=net6,
Kirill Shileevb1f97522015-02-19 20:39:05 +030097 namestart='sub6',
98 ip_version=6,
99 ipv6_ra_mode=address6_mode,
100 ipv6_address_mode=address6_mode)
101
Steve Heyman33735f22016-05-24 09:28:08 -0500102 self.routers_client.add_router_interface(router['id'],
103 subnet_id=sub6['id'])
Kirill Shileev14113572014-11-21 16:58:02 +0300104
Steve Heyman33735f22016-05-24 09:28:08 -0500105 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
106 self.routers_client.remove_router_interface,
107 router['id'], subnet_id=sub6['id'])
108
109 self.subnets_v6.append(sub6)
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200110 return [self.network, self.network_v6] if dualnet else [self.network]
111
Kirill Shileev14113572014-11-21 16:58:02 +0300112 @staticmethod
113 def define_server_ips(srv):
Kirill Shileevb1f97522015-02-19 20:39:05 +0300114 ips = {'4': None, '6': []}
Matthew Treinish71426682015-04-23 11:19:38 -0400115 for net_name, nics in six.iteritems(srv['addresses']):
Kirill Shileev14113572014-11-21 16:58:02 +0300116 for nic in nics:
117 if nic['version'] == 6:
Kirill Shileevb1f97522015-02-19 20:39:05 +0300118 ips['6'].append(nic['addr'])
Kirill Shileev14113572014-11-21 16:58:02 +0300119 else:
Kirill Shileevb1f97522015-02-19 20:39:05 +0300120 ips['4'] = nic['addr']
121 return ips
Kirill Shileev14113572014-11-21 16:58:02 +0300122
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200123 def prepare_server(self, networks=None):
lanoux283273b2015-12-04 03:01:54 -0800124 username = CONF.validation.image_ssh_user
Kirill Shileev14113572014-11-21 16:58:02 +0300125
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200126 networks = networks or [self.network]
Matthew Treinish8e48ad62014-12-12 11:07:23 -0500127
lanoux5fc14522015-09-21 08:17:35 +0000128 srv = self.create_server(
129 key_name=self.keypair['name'],
130 security_groups=[{'name': self.sec_grp['name']}],
Steve Heyman33735f22016-05-24 09:28:08 -0500131 networks=[{'uuid': n['id']} for n in networks],
lanoux5fc14522015-09-21 08:17:35 +0000132 wait_until='ACTIVE')
Kirill Shileev14113572014-11-21 16:58:02 +0300133 fip = self.create_floating_ip(thing=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'],
Kirill Shileev14113572014-11-21 16:58:02 +0300137 username=username)
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200138 return ssh, ips, srv["id"]
Kirill Shileev14113572014-11-21 16:58:02 +0300139
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200140 def turn_nic6_on(self, ssh, sid):
141 """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
148 """
149 ports = [p["mac_address"] for p in
150 self._list_ports(device_id=sid,
Steve Heyman33735f22016-05-24 09:28:08 -0500151 network_id=self.network_v6['id'])]
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200152 self.assertEqual(1, len(ports),
Ken'ichi Ohmichi695ac5c2015-10-13 03:07:17 +0000153 message=("Multiple IPv6 ports found on network %s. "
154 "ports: %s")
155 % (self.network_v6, ports))
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200156 mac6 = ports[0]
Evgeny Antyshev9b77ae52016-02-16 09:48:57 +0000157 ssh.set_nic_state(ssh.get_nic_name_by_mac(mac6))
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
164 sshv4_1, ips_from_api_1, sid1 = self.prepare_server(networks=net_list)
165 sshv4_2, ips_from_api_2, sid2 = 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):
168 return addr in ssh.get_ip_list()
169
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200170 # Turn on 2nd NIC for Cirros when dualnet
171 if dualnet:
172 self.turn_nic6_on(sshv4_1, sid1)
173 self.turn_nic6_on(sshv4_2, sid2)
174
Kirill Shileevb1f97522015-02-19 20:39:05 +0300175 # get addresses assigned to vNIC as reported by 'ip address' utility
176 ips_from_ip_1 = sshv4_1.get_ip_list()
177 ips_from_ip_2 = sshv4_2.get_ip_list()
178 self.assertIn(ips_from_api_1['4'], ips_from_ip_1)
179 self.assertIn(ips_from_api_2['4'], ips_from_ip_2)
180 for i in range(n_subnets6):
181 # v6 should be configured since the image supports it
182 # It can take time for ipv6 automatic address to get assigned
183 srv1_v6_addr_assigned = functools.partial(
184 guest_has_address, sshv4_1, ips_from_api_1['6'][i])
Henry Gessau0efcfb92015-02-27 15:24:39 -0500185
Kirill Shileevb1f97522015-02-19 20:39:05 +0300186 srv2_v6_addr_assigned = functools.partial(
187 guest_has_address, sshv4_2, ips_from_api_2['6'][i])
188
189 self.assertTrue(test.call_until_true(srv1_v6_addr_assigned,
lanoux5fc14522015-09-21 08:17:35 +0000190 CONF.validation.ping_timeout, 1))
Kirill Shileevb1f97522015-02-19 20:39:05 +0300191
192 self.assertTrue(test.call_until_true(srv2_v6_addr_assigned,
lanoux5fc14522015-09-21 08:17:35 +0000193 CONF.validation.ping_timeout, 1))
Kirill Shileevb1f97522015-02-19 20:39:05 +0300194
Yair Friede198e2f2015-07-28 14:43:47 +0300195 self._check_connectivity(sshv4_1, ips_from_api_2['4'])
196 self._check_connectivity(sshv4_2, ips_from_api_1['4'])
Kirill Shileev14113572014-11-21 16:58:02 +0300197
Sean M. Collinsc0378482015-10-26 12:59:47 +0900198 for i in range(n_subnets6):
199 self._check_connectivity(sshv4_1,
200 ips_from_api_2['6'][i])
201 self._check_connectivity(sshv4_1,
Steve Heyman33735f22016-05-24 09:28:08 -0500202 self.subnets_v6[i]['gateway_ip'])
Sean M. Collinsc0378482015-10-26 12:59:47 +0900203 self._check_connectivity(sshv4_2,
204 ips_from_api_1['6'][i])
205 self._check_connectivity(sshv4_2,
Steve Heyman33735f22016-05-24 09:28:08 -0500206 self.subnets_v6[i]['gateway_ip'])
Kirill Shileev14113572014-11-21 16:58:02 +0300207
Yair Friede198e2f2015-07-28 14:43:47 +0300208 def _check_connectivity(self, source, dest):
209 self.assertTrue(
210 self._check_remote_connectivity(source, dest),
211 "Timed out waiting for %s to become reachable from %s" %
212 (dest, source.ssh_client.host)
213 )
214
Brian Haley570527f2015-10-28 17:09:28 +0900215 @test.attr(type='slow')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800216 @test.idempotent_id('2c92df61-29f0-4eaa-bee3-7c65bef62a43')
Kirill Shileev14113572014-11-21 16:58:02 +0300217 @test.services('compute', 'network')
218 def test_slaac_from_os(self):
219 self._prepare_and_test(address6_mode='slaac')
220
Brian Haley570527f2015-10-28 17:09:28 +0900221 @test.attr(type='slow')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800222 @test.idempotent_id('d7e1f858-187c-45a6-89c9-bdafde619a9f')
Kirill Shileev14113572014-11-21 16:58:02 +0300223 @test.services('compute', 'network')
224 def test_dhcp6_stateless_from_os(self):
225 self._prepare_and_test(address6_mode='dhcpv6-stateless')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300226
Brian Haley570527f2015-10-28 17:09:28 +0900227 @test.attr(type='slow')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300228 @test.idempotent_id('7ab23f41-833b-4a16-a7c9-5b42fe6d4123')
229 @test.services('compute', 'network')
230 def test_multi_prefix_dhcpv6_stateless(self):
231 self._prepare_and_test(address6_mode='dhcpv6-stateless', n_subnets6=2)
232
Brian Haley570527f2015-10-28 17:09:28 +0900233 @test.attr(type='slow')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300234 @test.idempotent_id('dec222b1-180c-4098-b8c5-cc1b8342d611')
235 @test.services('compute', 'network')
236 def test_multi_prefix_slaac(self):
237 self._prepare_and_test(address6_mode='slaac', n_subnets6=2)
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200238
Brian Haley570527f2015-10-28 17:09:28 +0900239 @test.attr(type='slow')
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200240 @test.idempotent_id('b6399d76-4438-4658-bcf5-0d6c8584fde2')
241 @test.services('compute', 'network')
242 def test_dualnet_slaac_from_os(self):
243 self._prepare_and_test(address6_mode='slaac', dualnet=True)
244
Brian Haley570527f2015-10-28 17:09:28 +0900245 @test.attr(type='slow')
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200246 @test.idempotent_id('76f26acd-9688-42b4-bc3e-cd134c4cb09e')
247 @test.services('compute', 'network')
248 def test_dualnet_dhcp6_stateless_from_os(self):
249 self._prepare_and_test(address6_mode='dhcpv6-stateless', dualnet=True)
250
251 @test.idempotent_id('cf1c4425-766b-45b8-be35-e2959728eb00')
252 @test.services('compute', 'network')
253 def test_dualnet_multi_prefix_dhcpv6_stateless(self):
254 self._prepare_and_test(address6_mode='dhcpv6-stateless', n_subnets6=2,
255 dualnet=True)
256
257 @test.idempotent_id('9178ad42-10e4-47e9-8987-e02b170cc5cd')
258 @test.services('compute', 'network')
259 def test_dualnet_multi_prefix_slaac(self):
260 self._prepare_and_test(address6_mode='slaac', n_subnets6=2,
261 dualnet=True)