blob: 364b6f5af20a8e01f455ceffcd9c1b6ef97d0015 [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
armando-migliaccio461c83d2016-02-02 16:42:15 -080021from tempest.lib import decorators
Kirill Shileev14113572014-11-21 16:58:02 +030022from tempest.scenario import manager
23from tempest import test
24
25
26CONF = config.CONF
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()
Kirill Shileev14113572014-11-21 16:58:02 +030046 if not (CONF.network_feature_enabled.ipv6
47 and CONF.network_feature_enabled.ipv6_subnet_attributes):
Kirill Shileev14113572014-11-21 16:58:02 +030048 raise cls.skipException('IPv6 or its attributes not supported')
Sean Dagueed6e5862016-04-04 10:49:13 -040049 if not (CONF.network.project_networks_reachable
Kirill Shileev14113572014-11-21 16:58:02 +030050 or 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)
Adam Gandelmanab6106d2014-12-12 10:38:23 -080054 if CONF.baremetal.driver_enabled:
55 msg = ('Baremetal does not currently support network isolation')
56 raise cls.skipException(msg)
Adam Gandelman721f80d2014-12-12 11:03:14 -080057
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000058 @classmethod
59 def setup_credentials(cls):
60 # Create no network resources for these tests.
61 cls.set_network_resources()
62 super(TestGettingAddress, cls).setup_credentials()
Kirill Shileev14113572014-11-21 16:58:02 +030063
64 def setUp(self):
65 super(TestGettingAddress, self).setUp()
66 self.keypair = self.create_keypair()
67 self.sec_grp = self._create_security_group(tenant_id=self.tenant_id)
Kirill Shileev14113572014-11-21 16:58:02 +030068
Daniel Mellado9e3e1062015-08-06 18:07:05 +020069 def prepare_network(self, address6_mode, n_subnets6=1, dualnet=False):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000070 """Prepare network
71
72 Creates network with given number of IPv6 subnets in the given mode and
73 one IPv4 subnet.
74 Creates router with ports on all subnets.
75 if dualnet - create IPv6 subnets on a different network
76 :return: list of created networks
Kirill Shileev14113572014-11-21 16:58:02 +030077 """
Matthew Treinish8e48ad62014-12-12 11:07:23 -050078 self.network = self._create_network(tenant_id=self.tenant_id)
Daniel Mellado9e3e1062015-08-06 18:07:05 +020079 if dualnet:
80 self.network_v6 = self._create_network(tenant_id=self.tenant_id)
81
Matthew Treinish8e48ad62014-12-12 11:07:23 -050082 sub4 = self._create_subnet(network=self.network,
Kirill Shileev14113572014-11-21 16:58:02 +030083 namestart='sub4',
Yair Friede198e2f2015-07-28 14:43:47 +030084 ip_version=4)
Kirill Shileev14113572014-11-21 16:58:02 +030085
86 router = self._get_router(tenant_id=self.tenant_id)
Steve Heyman33735f22016-05-24 09:28:08 -050087 self.routers_client.add_router_interface(router['id'],
88 subnet_id=sub4['id'])
89
90 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
91 self.routers_client.remove_router_interface,
92 router['id'], subnet_id=sub4['id'])
Kirill Shileevb1f97522015-02-19 20:39:05 +030093
Yair Friede198e2f2015-07-28 14:43:47 +030094 self.subnets_v6 = []
Kirill Shileevb1f97522015-02-19 20:39:05 +030095 for _ in range(n_subnets6):
Daniel Mellado9e3e1062015-08-06 18:07:05 +020096 net6 = self.network_v6 if dualnet else self.network
97 sub6 = self._create_subnet(network=net6,
Kirill Shileevb1f97522015-02-19 20:39:05 +030098 namestart='sub6',
99 ip_version=6,
100 ipv6_ra_mode=address6_mode,
101 ipv6_address_mode=address6_mode)
102
Steve Heyman33735f22016-05-24 09:28:08 -0500103 self.routers_client.add_router_interface(router['id'],
104 subnet_id=sub6['id'])
Kirill Shileev14113572014-11-21 16:58:02 +0300105
Steve Heyman33735f22016-05-24 09:28:08 -0500106 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
107 self.routers_client.remove_router_interface,
108 router['id'], subnet_id=sub6['id'])
109
110 self.subnets_v6.append(sub6)
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200111 return [self.network, self.network_v6] if dualnet else [self.network]
112
Kirill Shileev14113572014-11-21 16:58:02 +0300113 @staticmethod
114 def define_server_ips(srv):
Kirill Shileevb1f97522015-02-19 20:39:05 +0300115 ips = {'4': None, '6': []}
Matthew Treinish71426682015-04-23 11:19:38 -0400116 for net_name, nics in six.iteritems(srv['addresses']):
Kirill Shileev14113572014-11-21 16:58:02 +0300117 for nic in nics:
118 if nic['version'] == 6:
Kirill Shileevb1f97522015-02-19 20:39:05 +0300119 ips['6'].append(nic['addr'])
Kirill Shileev14113572014-11-21 16:58:02 +0300120 else:
Kirill Shileevb1f97522015-02-19 20:39:05 +0300121 ips['4'] = nic['addr']
122 return ips
Kirill Shileev14113572014-11-21 16:58:02 +0300123
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200124 def prepare_server(self, networks=None):
lanoux283273b2015-12-04 03:01:54 -0800125 username = CONF.validation.image_ssh_user
Kirill Shileev14113572014-11-21 16:58:02 +0300126
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200127 networks = networks or [self.network]
Matthew Treinish8e48ad62014-12-12 11:07:23 -0500128
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']}],
Steve Heyman33735f22016-05-24 09:28:08 -0500132 networks=[{'uuid': n['id']} for n in networks],
lanoux5fc14522015-09-21 08:17:35 +0000133 wait_until='ACTIVE')
Kirill Shileev14113572014-11-21 16:58:02 +0300134 fip = self.create_floating_ip(thing=srv)
Kirill Shileevb1f97522015-02-19 20:39:05 +0300135 ips = self.define_server_ips(srv=srv)
Kirill Shileev14113572014-11-21 16:58:02 +0300136 ssh = self.get_remote_client(
Steve Heyman33735f22016-05-24 09:28:08 -0500137 ip_address=fip['floating_ip_address'],
Kirill Shileev14113572014-11-21 16:58:02 +0300138 username=username)
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200139 return ssh, ips, srv["id"]
Kirill Shileev14113572014-11-21 16:58:02 +0300140
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200141 def turn_nic6_on(self, ssh, sid):
142 """Turns the IPv6 vNIC on
Kirill Shileev14113572014-11-21 16:58:02 +0300143
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200144 Required because guest images usually set only the first vNIC on boot.
145 Searches for the IPv6 vNIC's MAC and brings it up.
146
147 @param ssh: RemoteClient ssh instance to server
148 @param sid: server uuid
149 """
150 ports = [p["mac_address"] for p in
151 self._list_ports(device_id=sid,
Steve Heyman33735f22016-05-24 09:28:08 -0500152 network_id=self.network_v6['id'])]
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200153 self.assertEqual(1, len(ports),
Ken'ichi Ohmichi695ac5c2015-10-13 03:07:17 +0000154 message=("Multiple IPv6 ports found on network %s. "
155 "ports: %s")
156 % (self.network_v6, ports))
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200157 mac6 = ports[0]
Evgeny Antyshev9b77ae52016-02-16 09:48:57 +0000158 ssh.set_nic_state(ssh.get_nic_name_by_mac(mac6))
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200159
160 def _prepare_and_test(self, address6_mode, n_subnets6=1, dualnet=False):
161 net_list = self.prepare_network(address6_mode=address6_mode,
162 n_subnets6=n_subnets6,
163 dualnet=dualnet)
164
165 sshv4_1, ips_from_api_1, sid1 = self.prepare_server(networks=net_list)
166 sshv4_2, ips_from_api_2, sid2 = self.prepare_server(networks=net_list)
Kirill Shileev14113572014-11-21 16:58:02 +0300167
Henry Gessau0efcfb92015-02-27 15:24:39 -0500168 def guest_has_address(ssh, addr):
169 return addr in ssh.get_ip_list()
170
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200171 # Turn on 2nd NIC for Cirros when dualnet
172 if dualnet:
173 self.turn_nic6_on(sshv4_1, sid1)
174 self.turn_nic6_on(sshv4_2, sid2)
175
Kirill Shileevb1f97522015-02-19 20:39:05 +0300176 # get addresses assigned to vNIC as reported by 'ip address' utility
177 ips_from_ip_1 = sshv4_1.get_ip_list()
178 ips_from_ip_2 = sshv4_2.get_ip_list()
179 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
184 srv1_v6_addr_assigned = functools.partial(
185 guest_has_address, sshv4_1, ips_from_api_1['6'][i])
Henry Gessau0efcfb92015-02-27 15:24:39 -0500186
Kirill Shileevb1f97522015-02-19 20:39:05 +0300187 srv2_v6_addr_assigned = functools.partial(
188 guest_has_address, sshv4_2, ips_from_api_2['6'][i])
189
190 self.assertTrue(test.call_until_true(srv1_v6_addr_assigned,
lanoux5fc14522015-09-21 08:17:35 +0000191 CONF.validation.ping_timeout, 1))
Kirill Shileevb1f97522015-02-19 20:39:05 +0300192
193 self.assertTrue(test.call_until_true(srv2_v6_addr_assigned,
lanoux5fc14522015-09-21 08:17:35 +0000194 CONF.validation.ping_timeout, 1))
Kirill Shileevb1f97522015-02-19 20:39:05 +0300195
Yair Friede198e2f2015-07-28 14:43:47 +0300196 self._check_connectivity(sshv4_1, ips_from_api_2['4'])
197 self._check_connectivity(sshv4_2, ips_from_api_1['4'])
Kirill Shileev14113572014-11-21 16:58:02 +0300198
Sean M. Collinsc0378482015-10-26 12:59:47 +0900199 for i in range(n_subnets6):
200 self._check_connectivity(sshv4_1,
201 ips_from_api_2['6'][i])
202 self._check_connectivity(sshv4_1,
Steve Heyman33735f22016-05-24 09:28:08 -0500203 self.subnets_v6[i]['gateway_ip'])
Sean M. Collinsc0378482015-10-26 12:59:47 +0900204 self._check_connectivity(sshv4_2,
205 ips_from_api_1['6'][i])
206 self._check_connectivity(sshv4_2,
Steve Heyman33735f22016-05-24 09:28:08 -0500207 self.subnets_v6[i]['gateway_ip'])
Kirill Shileev14113572014-11-21 16:58:02 +0300208
Yair Friede198e2f2015-07-28 14:43:47 +0300209 def _check_connectivity(self, source, dest):
210 self.assertTrue(
211 self._check_remote_connectivity(source, dest),
212 "Timed out waiting for %s to become reachable from %s" %
213 (dest, source.ssh_client.host)
214 )
215
Brian Haley570527f2015-10-28 17:09:28 +0900216 @test.attr(type='slow')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800217 @test.idempotent_id('2c92df61-29f0-4eaa-bee3-7c65bef62a43')
Kirill Shileev14113572014-11-21 16:58:02 +0300218 @test.services('compute', 'network')
219 def test_slaac_from_os(self):
220 self._prepare_and_test(address6_mode='slaac')
221
Brian Haley570527f2015-10-28 17:09:28 +0900222 @test.attr(type='slow')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800223 @test.idempotent_id('d7e1f858-187c-45a6-89c9-bdafde619a9f')
Kirill Shileev14113572014-11-21 16:58:02 +0300224 @test.services('compute', 'network')
225 def test_dhcp6_stateless_from_os(self):
226 self._prepare_and_test(address6_mode='dhcpv6-stateless')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300227
Brian Haley570527f2015-10-28 17:09:28 +0900228 @test.attr(type='slow')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300229 @test.idempotent_id('7ab23f41-833b-4a16-a7c9-5b42fe6d4123')
230 @test.services('compute', 'network')
231 def test_multi_prefix_dhcpv6_stateless(self):
232 self._prepare_and_test(address6_mode='dhcpv6-stateless', n_subnets6=2)
233
Brian Haley570527f2015-10-28 17:09:28 +0900234 @test.attr(type='slow')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300235 @test.idempotent_id('dec222b1-180c-4098-b8c5-cc1b8342d611')
236 @test.services('compute', 'network')
237 def test_multi_prefix_slaac(self):
238 self._prepare_and_test(address6_mode='slaac', n_subnets6=2)
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200239
Brian Haley570527f2015-10-28 17:09:28 +0900240 @test.attr(type='slow')
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200241 @test.idempotent_id('b6399d76-4438-4658-bcf5-0d6c8584fde2')
242 @test.services('compute', 'network')
243 def test_dualnet_slaac_from_os(self):
244 self._prepare_and_test(address6_mode='slaac', dualnet=True)
245
Brian Haley570527f2015-10-28 17:09:28 +0900246 @test.attr(type='slow')
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200247 @test.idempotent_id('76f26acd-9688-42b4-bc3e-cd134c4cb09e')
248 @test.services('compute', 'network')
249 def test_dualnet_dhcp6_stateless_from_os(self):
250 self._prepare_and_test(address6_mode='dhcpv6-stateless', dualnet=True)
251
252 @test.idempotent_id('cf1c4425-766b-45b8-be35-e2959728eb00')
253 @test.services('compute', 'network')
254 def test_dualnet_multi_prefix_dhcpv6_stateless(self):
255 self._prepare_and_test(address6_mode='dhcpv6-stateless', n_subnets6=2,
256 dualnet=True)
257
armando-migliaccio461c83d2016-02-02 16:42:15 -0800258 @decorators.skip_because(bug="1540983")
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200259 @test.idempotent_id('9178ad42-10e4-47e9-8987-e02b170cc5cd')
260 @test.services('compute', 'network')
261 def test_dualnet_multi_prefix_slaac(self):
262 self._prepare_and_test(address6_mode='slaac', n_subnets6=2,
263 dualnet=True)