blob: fc33dd9dd50c2915f22c79f5a08ada9afa126718 [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
Kirill Shileev14113572014-11-21 16:58:02 +030020from tempest.scenario import manager
21from tempest import test
22
23
24CONF = config.CONF
Kirill Shileev14113572014-11-21 16:58:02 +030025
26
27class TestGettingAddress(manager.NetworkScenarioTest):
Yair Friede198e2f2015-07-28 14:43:47 +030028 """Test Summary:
29
30 1. Create network with subnets:
31 1.1. one IPv4 and
32 1.2. one or more IPv6 in a given address mode
33 2. Boot 2 VMs on this network
34 3. Allocate and assign 2 FIP4
35 4. Check that vNICs of all VMs gets all addresses actually assigned
36 5. Each VM will ping the other's v4 private address
37 6. If ping6 available in VM, each VM will ping all of the other's v6
38 addresses as well as the router's
Kirill Shileev14113572014-11-21 16:58:02 +030039 """
40
41 @classmethod
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000042 def skip_checks(cls):
43 super(TestGettingAddress, cls).skip_checks()
Kirill Shileev14113572014-11-21 16:58:02 +030044 if not (CONF.network_feature_enabled.ipv6
45 and CONF.network_feature_enabled.ipv6_subnet_attributes):
Kirill Shileev14113572014-11-21 16:58:02 +030046 raise cls.skipException('IPv6 or its attributes not supported')
47 if not (CONF.network.tenant_networks_reachable
48 or CONF.network.public_network_id):
49 msg = ('Either tenant_networks_reachable must be "true", or '
50 'public_network_id must be defined.')
Kirill Shileev14113572014-11-21 16:58:02 +030051 raise cls.skipException(msg)
Adam Gandelmanab6106d2014-12-12 10:38:23 -080052 if CONF.baremetal.driver_enabled:
53 msg = ('Baremetal does not currently support network isolation')
54 raise cls.skipException(msg)
Adam Gandelman721f80d2014-12-12 11:03:14 -080055
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000056 @classmethod
57 def setup_credentials(cls):
58 # Create no network resources for these tests.
59 cls.set_network_resources()
60 super(TestGettingAddress, cls).setup_credentials()
Kirill Shileev14113572014-11-21 16:58:02 +030061
62 def setUp(self):
63 super(TestGettingAddress, self).setUp()
64 self.keypair = self.create_keypair()
65 self.sec_grp = self._create_security_group(tenant_id=self.tenant_id)
Kirill Shileev14113572014-11-21 16:58:02 +030066
Daniel Mellado9e3e1062015-08-06 18:07:05 +020067 def prepare_network(self, address6_mode, n_subnets6=1, dualnet=False):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000068 """Prepare network
69
70 Creates network with given number of IPv6 subnets in the given mode and
71 one IPv4 subnet.
72 Creates router with ports on all subnets.
73 if dualnet - create IPv6 subnets on a different network
74 :return: list of created networks
Kirill Shileev14113572014-11-21 16:58:02 +030075 """
Matthew Treinish8e48ad62014-12-12 11:07:23 -050076 self.network = self._create_network(tenant_id=self.tenant_id)
Daniel Mellado9e3e1062015-08-06 18:07:05 +020077 if dualnet:
78 self.network_v6 = self._create_network(tenant_id=self.tenant_id)
79
Matthew Treinish8e48ad62014-12-12 11:07:23 -050080 sub4 = self._create_subnet(network=self.network,
Kirill Shileev14113572014-11-21 16:58:02 +030081 namestart='sub4',
Yair Friede198e2f2015-07-28 14:43:47 +030082 ip_version=4)
Kirill Shileev14113572014-11-21 16:58:02 +030083
84 router = self._get_router(tenant_id=self.tenant_id)
85 sub4.add_to_router(router_id=router['id'])
Kirill Shileev14113572014-11-21 16:58:02 +030086 self.addCleanup(sub4.delete)
Kirill Shileevb1f97522015-02-19 20:39:05 +030087
Yair Friede198e2f2015-07-28 14:43:47 +030088 self.subnets_v6 = []
Kirill Shileevb1f97522015-02-19 20:39:05 +030089 for _ in range(n_subnets6):
Daniel Mellado9e3e1062015-08-06 18:07:05 +020090 net6 = self.network_v6 if dualnet else self.network
91 sub6 = self._create_subnet(network=net6,
Kirill Shileevb1f97522015-02-19 20:39:05 +030092 namestart='sub6',
93 ip_version=6,
94 ipv6_ra_mode=address6_mode,
95 ipv6_address_mode=address6_mode)
96
97 sub6.add_to_router(router_id=router['id'])
98 self.addCleanup(sub6.delete)
Yair Friede198e2f2015-07-28 14:43:47 +030099 self.subnets_v6.append(sub6)
Kirill Shileev14113572014-11-21 16:58:02 +0300100
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200101 return [self.network, self.network_v6] if dualnet else [self.network]
102
Kirill Shileev14113572014-11-21 16:58:02 +0300103 @staticmethod
104 def define_server_ips(srv):
Kirill Shileevb1f97522015-02-19 20:39:05 +0300105 ips = {'4': None, '6': []}
Matthew Treinish71426682015-04-23 11:19:38 -0400106 for net_name, nics in six.iteritems(srv['addresses']):
Kirill Shileev14113572014-11-21 16:58:02 +0300107 for nic in nics:
108 if nic['version'] == 6:
Kirill Shileevb1f97522015-02-19 20:39:05 +0300109 ips['6'].append(nic['addr'])
Kirill Shileev14113572014-11-21 16:58:02 +0300110 else:
Kirill Shileevb1f97522015-02-19 20:39:05 +0300111 ips['4'] = nic['addr']
112 return ips
Kirill Shileev14113572014-11-21 16:58:02 +0300113
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200114 def prepare_server(self, networks=None):
lanoux283273b2015-12-04 03:01:54 -0800115 username = CONF.validation.image_ssh_user
Kirill Shileev14113572014-11-21 16:58:02 +0300116
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200117 networks = networks or [self.network]
Matthew Treinish8e48ad62014-12-12 11:07:23 -0500118
lanoux5fc14522015-09-21 08:17:35 +0000119 srv = self.create_server(
120 key_name=self.keypair['name'],
121 security_groups=[{'name': self.sec_grp['name']}],
122 networks=[{'uuid': n.id} for n in networks],
123 wait_until='ACTIVE')
Kirill Shileev14113572014-11-21 16:58:02 +0300124 fip = self.create_floating_ip(thing=srv)
Kirill Shileevb1f97522015-02-19 20:39:05 +0300125 ips = self.define_server_ips(srv=srv)
Kirill Shileev14113572014-11-21 16:58:02 +0300126 ssh = self.get_remote_client(
Sean Dague20e98612016-01-06 14:33:28 -0500127 ip_address=fip.floating_ip_address,
Kirill Shileev14113572014-11-21 16:58:02 +0300128 username=username)
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200129 return ssh, ips, srv["id"]
Kirill Shileev14113572014-11-21 16:58:02 +0300130
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200131 def turn_nic6_on(self, ssh, sid):
132 """Turns the IPv6 vNIC on
Kirill Shileev14113572014-11-21 16:58:02 +0300133
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200134 Required because guest images usually set only the first vNIC on boot.
135 Searches for the IPv6 vNIC's MAC and brings it up.
136
137 @param ssh: RemoteClient ssh instance to server
138 @param sid: server uuid
139 """
140 ports = [p["mac_address"] for p in
141 self._list_ports(device_id=sid,
142 network_id=self.network_v6.id)]
143 self.assertEqual(1, len(ports),
Ken'ichi Ohmichi695ac5c2015-10-13 03:07:17 +0000144 message=("Multiple IPv6 ports found on network %s. "
145 "ports: %s")
146 % (self.network_v6, ports))
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200147 mac6 = ports[0]
Yair Friedbc46f592015-11-18 16:29:34 +0200148 ssh.set_nic_state(ssh.get_nic_name(mac6))
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200149
150 def _prepare_and_test(self, address6_mode, n_subnets6=1, dualnet=False):
151 net_list = self.prepare_network(address6_mode=address6_mode,
152 n_subnets6=n_subnets6,
153 dualnet=dualnet)
154
155 sshv4_1, ips_from_api_1, sid1 = self.prepare_server(networks=net_list)
156 sshv4_2, ips_from_api_2, sid2 = self.prepare_server(networks=net_list)
Kirill Shileev14113572014-11-21 16:58:02 +0300157
Henry Gessau0efcfb92015-02-27 15:24:39 -0500158 def guest_has_address(ssh, addr):
159 return addr in ssh.get_ip_list()
160
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200161 # Turn on 2nd NIC for Cirros when dualnet
162 if dualnet:
163 self.turn_nic6_on(sshv4_1, sid1)
164 self.turn_nic6_on(sshv4_2, sid2)
165
Kirill Shileevb1f97522015-02-19 20:39:05 +0300166 # get addresses assigned to vNIC as reported by 'ip address' utility
167 ips_from_ip_1 = sshv4_1.get_ip_list()
168 ips_from_ip_2 = sshv4_2.get_ip_list()
169 self.assertIn(ips_from_api_1['4'], ips_from_ip_1)
170 self.assertIn(ips_from_api_2['4'], ips_from_ip_2)
171 for i in range(n_subnets6):
172 # v6 should be configured since the image supports it
173 # It can take time for ipv6 automatic address to get assigned
174 srv1_v6_addr_assigned = functools.partial(
175 guest_has_address, sshv4_1, ips_from_api_1['6'][i])
Henry Gessau0efcfb92015-02-27 15:24:39 -0500176
Kirill Shileevb1f97522015-02-19 20:39:05 +0300177 srv2_v6_addr_assigned = functools.partial(
178 guest_has_address, sshv4_2, ips_from_api_2['6'][i])
179
180 self.assertTrue(test.call_until_true(srv1_v6_addr_assigned,
lanoux5fc14522015-09-21 08:17:35 +0000181 CONF.validation.ping_timeout, 1))
Kirill Shileevb1f97522015-02-19 20:39:05 +0300182
183 self.assertTrue(test.call_until_true(srv2_v6_addr_assigned,
lanoux5fc14522015-09-21 08:17:35 +0000184 CONF.validation.ping_timeout, 1))
Kirill Shileevb1f97522015-02-19 20:39:05 +0300185
Yair Friede198e2f2015-07-28 14:43:47 +0300186 self._check_connectivity(sshv4_1, ips_from_api_2['4'])
187 self._check_connectivity(sshv4_2, ips_from_api_1['4'])
Kirill Shileev14113572014-11-21 16:58:02 +0300188
Sean M. Collinsc0378482015-10-26 12:59:47 +0900189 for i in range(n_subnets6):
190 self._check_connectivity(sshv4_1,
191 ips_from_api_2['6'][i])
192 self._check_connectivity(sshv4_1,
193 self.subnets_v6[i].gateway_ip)
194 self._check_connectivity(sshv4_2,
195 ips_from_api_1['6'][i])
196 self._check_connectivity(sshv4_2,
197 self.subnets_v6[i].gateway_ip)
Kirill Shileev14113572014-11-21 16:58:02 +0300198
Yair Friede198e2f2015-07-28 14:43:47 +0300199 def _check_connectivity(self, source, dest):
200 self.assertTrue(
201 self._check_remote_connectivity(source, dest),
202 "Timed out waiting for %s to become reachable from %s" %
203 (dest, source.ssh_client.host)
204 )
205
Brian Haley570527f2015-10-28 17:09:28 +0900206 @test.attr(type='slow')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800207 @test.idempotent_id('2c92df61-29f0-4eaa-bee3-7c65bef62a43')
Kirill Shileev14113572014-11-21 16:58:02 +0300208 @test.services('compute', 'network')
209 def test_slaac_from_os(self):
210 self._prepare_and_test(address6_mode='slaac')
211
Brian Haley570527f2015-10-28 17:09:28 +0900212 @test.attr(type='slow')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800213 @test.idempotent_id('d7e1f858-187c-45a6-89c9-bdafde619a9f')
Kirill Shileev14113572014-11-21 16:58:02 +0300214 @test.services('compute', 'network')
215 def test_dhcp6_stateless_from_os(self):
216 self._prepare_and_test(address6_mode='dhcpv6-stateless')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300217
Brian Haley570527f2015-10-28 17:09:28 +0900218 @test.attr(type='slow')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300219 @test.idempotent_id('7ab23f41-833b-4a16-a7c9-5b42fe6d4123')
220 @test.services('compute', 'network')
221 def test_multi_prefix_dhcpv6_stateless(self):
222 self._prepare_and_test(address6_mode='dhcpv6-stateless', n_subnets6=2)
223
Brian Haley570527f2015-10-28 17:09:28 +0900224 @test.attr(type='slow')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300225 @test.idempotent_id('dec222b1-180c-4098-b8c5-cc1b8342d611')
226 @test.services('compute', 'network')
227 def test_multi_prefix_slaac(self):
228 self._prepare_and_test(address6_mode='slaac', n_subnets6=2)
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200229
Brian Haley570527f2015-10-28 17:09:28 +0900230 @test.attr(type='slow')
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200231 @test.idempotent_id('b6399d76-4438-4658-bcf5-0d6c8584fde2')
232 @test.services('compute', 'network')
233 def test_dualnet_slaac_from_os(self):
234 self._prepare_and_test(address6_mode='slaac', dualnet=True)
235
Brian Haley570527f2015-10-28 17:09:28 +0900236 @test.attr(type='slow')
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200237 @test.idempotent_id('76f26acd-9688-42b4-bc3e-cd134c4cb09e')
238 @test.services('compute', 'network')
239 def test_dualnet_dhcp6_stateless_from_os(self):
240 self._prepare_and_test(address6_mode='dhcpv6-stateless', dualnet=True)
241
242 @test.idempotent_id('cf1c4425-766b-45b8-be35-e2959728eb00')
243 @test.services('compute', 'network')
244 def test_dualnet_multi_prefix_dhcpv6_stateless(self):
245 self._prepare_and_test(address6_mode='dhcpv6-stateless', n_subnets6=2,
246 dualnet=True)
247
248 @test.idempotent_id('9178ad42-10e4-47e9-8987-e02b170cc5cd')
249 @test.services('compute', 'network')
250 def test_dualnet_multi_prefix_slaac(self):
251 self._prepare_and_test(address6_mode='slaac', n_subnets6=2,
252 dualnet=True)