blob: 40c76808bd1e17a03bdc44ad26df1a3e1a65f84a [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
17from oslo_log import log as logging
Matthew Treinish71426682015-04-23 11:19:38 -040018import six
Doug Hellmann583ce2c2015-03-11 14:55:46 +000019
Kirill Shileev14113572014-11-21 16:58:02 +030020from tempest import config
Kirill Shileev14113572014-11-21 16:58:02 +030021from tempest.scenario import manager
22from tempest import test
23
24
25CONF = config.CONF
26LOG = logging.getLogger(__name__)
27
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')
49 if not (CONF.network.tenant_networks_reachable
50 or CONF.network.public_network_id):
51 msg = ('Either tenant_networks_reachable must be "true", or '
52 '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)
87 sub4.add_to_router(router_id=router['id'])
Kirill Shileev14113572014-11-21 16:58:02 +030088 self.addCleanup(sub4.delete)
Kirill Shileevb1f97522015-02-19 20:39:05 +030089
Yair Friede198e2f2015-07-28 14:43:47 +030090 self.subnets_v6 = []
Kirill Shileevb1f97522015-02-19 20:39:05 +030091 for _ in range(n_subnets6):
Daniel Mellado9e3e1062015-08-06 18:07:05 +020092 net6 = self.network_v6 if dualnet else self.network
93 sub6 = self._create_subnet(network=net6,
Kirill Shileevb1f97522015-02-19 20:39:05 +030094 namestart='sub6',
95 ip_version=6,
96 ipv6_ra_mode=address6_mode,
97 ipv6_address_mode=address6_mode)
98
99 sub6.add_to_router(router_id=router['id'])
100 self.addCleanup(sub6.delete)
Yair Friede198e2f2015-07-28 14:43:47 +0300101 self.subnets_v6.append(sub6)
Kirill Shileev14113572014-11-21 16:58:02 +0300102
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200103 return [self.network, self.network_v6] if dualnet else [self.network]
104
Kirill Shileev14113572014-11-21 16:58:02 +0300105 @staticmethod
106 def define_server_ips(srv):
Kirill Shileevb1f97522015-02-19 20:39:05 +0300107 ips = {'4': None, '6': []}
Matthew Treinish71426682015-04-23 11:19:38 -0400108 for net_name, nics in six.iteritems(srv['addresses']):
Kirill Shileev14113572014-11-21 16:58:02 +0300109 for nic in nics:
110 if nic['version'] == 6:
Kirill Shileevb1f97522015-02-19 20:39:05 +0300111 ips['6'].append(nic['addr'])
Kirill Shileev14113572014-11-21 16:58:02 +0300112 else:
Kirill Shileevb1f97522015-02-19 20:39:05 +0300113 ips['4'] = nic['addr']
114 return ips
Kirill Shileev14113572014-11-21 16:58:02 +0300115
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200116 def prepare_server(self, networks=None):
lanoux283273b2015-12-04 03:01:54 -0800117 username = CONF.validation.image_ssh_user
Kirill Shileev14113572014-11-21 16:58:02 +0300118
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200119 networks = networks or [self.network]
Matthew Treinish8e48ad62014-12-12 11:07:23 -0500120
lanoux5fc14522015-09-21 08:17:35 +0000121 srv = self.create_server(
122 key_name=self.keypair['name'],
123 security_groups=[{'name': self.sec_grp['name']}],
124 networks=[{'uuid': n.id} for n in networks],
125 wait_until='ACTIVE')
Kirill Shileev14113572014-11-21 16:58:02 +0300126 fip = self.create_floating_ip(thing=srv)
Kirill Shileevb1f97522015-02-19 20:39:05 +0300127 ips = self.define_server_ips(srv=srv)
Kirill Shileev14113572014-11-21 16:58:02 +0300128 ssh = self.get_remote_client(
129 server_or_ip=fip.floating_ip_address,
130 username=username)
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200131 return ssh, ips, srv["id"]
Kirill Shileev14113572014-11-21 16:58:02 +0300132
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200133 def turn_nic6_on(self, ssh, sid):
134 """Turns the IPv6 vNIC on
Kirill Shileev14113572014-11-21 16:58:02 +0300135
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200136 Required because guest images usually set only the first vNIC on boot.
137 Searches for the IPv6 vNIC's MAC and brings it up.
138
139 @param ssh: RemoteClient ssh instance to server
140 @param sid: server uuid
141 """
142 ports = [p["mac_address"] for p in
143 self._list_ports(device_id=sid,
144 network_id=self.network_v6.id)]
145 self.assertEqual(1, len(ports),
Ken'ichi Ohmichi695ac5c2015-10-13 03:07:17 +0000146 message=("Multiple IPv6 ports found on network %s. "
147 "ports: %s")
148 % (self.network_v6, ports))
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200149 mac6 = ports[0]
Yair Friedbc46f592015-11-18 16:29:34 +0200150 ssh.set_nic_state(ssh.get_nic_name(mac6))
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200151
152 def _prepare_and_test(self, address6_mode, n_subnets6=1, dualnet=False):
153 net_list = self.prepare_network(address6_mode=address6_mode,
154 n_subnets6=n_subnets6,
155 dualnet=dualnet)
156
157 sshv4_1, ips_from_api_1, sid1 = self.prepare_server(networks=net_list)
158 sshv4_2, ips_from_api_2, sid2 = self.prepare_server(networks=net_list)
Kirill Shileev14113572014-11-21 16:58:02 +0300159
Henry Gessau0efcfb92015-02-27 15:24:39 -0500160 def guest_has_address(ssh, addr):
161 return addr in ssh.get_ip_list()
162
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200163 # Turn on 2nd NIC for Cirros when dualnet
164 if dualnet:
165 self.turn_nic6_on(sshv4_1, sid1)
166 self.turn_nic6_on(sshv4_2, sid2)
167
Kirill Shileevb1f97522015-02-19 20:39:05 +0300168 # get addresses assigned to vNIC as reported by 'ip address' utility
169 ips_from_ip_1 = sshv4_1.get_ip_list()
170 ips_from_ip_2 = sshv4_2.get_ip_list()
171 self.assertIn(ips_from_api_1['4'], ips_from_ip_1)
172 self.assertIn(ips_from_api_2['4'], ips_from_ip_2)
173 for i in range(n_subnets6):
174 # v6 should be configured since the image supports it
175 # It can take time for ipv6 automatic address to get assigned
176 srv1_v6_addr_assigned = functools.partial(
177 guest_has_address, sshv4_1, ips_from_api_1['6'][i])
Henry Gessau0efcfb92015-02-27 15:24:39 -0500178
Kirill Shileevb1f97522015-02-19 20:39:05 +0300179 srv2_v6_addr_assigned = functools.partial(
180 guest_has_address, sshv4_2, ips_from_api_2['6'][i])
181
182 self.assertTrue(test.call_until_true(srv1_v6_addr_assigned,
lanoux5fc14522015-09-21 08:17:35 +0000183 CONF.validation.ping_timeout, 1))
Kirill Shileevb1f97522015-02-19 20:39:05 +0300184
185 self.assertTrue(test.call_until_true(srv2_v6_addr_assigned,
lanoux5fc14522015-09-21 08:17:35 +0000186 CONF.validation.ping_timeout, 1))
Kirill Shileevb1f97522015-02-19 20:39:05 +0300187
Yair Friede198e2f2015-07-28 14:43:47 +0300188 self._check_connectivity(sshv4_1, ips_from_api_2['4'])
189 self._check_connectivity(sshv4_2, ips_from_api_1['4'])
Kirill Shileev14113572014-11-21 16:58:02 +0300190
Sean M. Collinsc0378482015-10-26 12:59:47 +0900191 for i in range(n_subnets6):
192 self._check_connectivity(sshv4_1,
193 ips_from_api_2['6'][i])
194 self._check_connectivity(sshv4_1,
195 self.subnets_v6[i].gateway_ip)
196 self._check_connectivity(sshv4_2,
197 ips_from_api_1['6'][i])
198 self._check_connectivity(sshv4_2,
199 self.subnets_v6[i].gateway_ip)
Kirill Shileev14113572014-11-21 16:58:02 +0300200
Yair Friede198e2f2015-07-28 14:43:47 +0300201 def _check_connectivity(self, source, dest):
202 self.assertTrue(
203 self._check_remote_connectivity(source, dest),
204 "Timed out waiting for %s to become reachable from %s" %
205 (dest, source.ssh_client.host)
206 )
207
Chris Hoge7579c1a2015-02-26 14:12:15 -0800208 @test.idempotent_id('2c92df61-29f0-4eaa-bee3-7c65bef62a43')
Kirill Shileev14113572014-11-21 16:58:02 +0300209 @test.services('compute', 'network')
210 def test_slaac_from_os(self):
211 self._prepare_and_test(address6_mode='slaac')
212
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
218 @test.idempotent_id('7ab23f41-833b-4a16-a7c9-5b42fe6d4123')
219 @test.services('compute', 'network')
220 def test_multi_prefix_dhcpv6_stateless(self):
221 self._prepare_and_test(address6_mode='dhcpv6-stateless', n_subnets6=2)
222
223 @test.idempotent_id('dec222b1-180c-4098-b8c5-cc1b8342d611')
224 @test.services('compute', 'network')
225 def test_multi_prefix_slaac(self):
226 self._prepare_and_test(address6_mode='slaac', n_subnets6=2)
Daniel Mellado9e3e1062015-08-06 18:07:05 +0200227
228 @test.idempotent_id('b6399d76-4438-4658-bcf5-0d6c8584fde2')
229 @test.services('compute', 'network')
230 def test_dualnet_slaac_from_os(self):
231 self._prepare_and_test(address6_mode='slaac', dualnet=True)
232
233 @test.idempotent_id('76f26acd-9688-42b4-bc3e-cd134c4cb09e')
234 @test.services('compute', 'network')
235 def test_dualnet_dhcp6_stateless_from_os(self):
236 self._prepare_and_test(address6_mode='dhcpv6-stateless', dualnet=True)
237
238 @test.idempotent_id('cf1c4425-766b-45b8-be35-e2959728eb00')
239 @test.services('compute', 'network')
240 def test_dualnet_multi_prefix_dhcpv6_stateless(self):
241 self._prepare_and_test(address6_mode='dhcpv6-stateless', n_subnets6=2,
242 dualnet=True)
243
244 @test.idempotent_id('9178ad42-10e4-47e9-8987-e02b170cc5cd')
245 @test.services('compute', 'network')
246 def test_dualnet_multi_prefix_slaac(self):
247 self._prepare_and_test(address6_mode='slaac', n_subnets6=2,
248 dualnet=True)