blob: 9481e589b43dac6312fc0dbb2605d40e247d202b [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)
68 self.srv_kwargs = {
69 'key_name': self.keypair['name'],
ghanshyamfc5e0c72015-01-29 15:09:40 +090070 'security_groups': [{'name': self.sec_grp['name']}]}
Kirill Shileev14113572014-11-21 16:58:02 +030071
Kirill Shileevb1f97522015-02-19 20:39:05 +030072 def prepare_network(self, address6_mode, n_subnets6=1):
Kirill Shileev14113572014-11-21 16:58:02 +030073 """Creates network with
Kirill Shileevb1f97522015-02-19 20:39:05 +030074 given number of IPv6 subnets in the given mode and
Kirill Shileev14113572014-11-21 16:58:02 +030075 one IPv4 subnet
Kirill Shileevb1f97522015-02-19 20:39:05 +030076 Creates router with ports on all subnets
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)
79 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
83 router = self._get_router(tenant_id=self.tenant_id)
84 sub4.add_to_router(router_id=router['id'])
Kirill Shileev14113572014-11-21 16:58:02 +030085 self.addCleanup(sub4.delete)
Kirill Shileevb1f97522015-02-19 20:39:05 +030086
Yair Friede198e2f2015-07-28 14:43:47 +030087 self.subnets_v6 = []
Kirill Shileevb1f97522015-02-19 20:39:05 +030088 for _ in range(n_subnets6):
89 sub6 = self._create_subnet(network=self.network,
90 namestart='sub6',
91 ip_version=6,
92 ipv6_ra_mode=address6_mode,
93 ipv6_address_mode=address6_mode)
94
95 sub6.add_to_router(router_id=router['id'])
96 self.addCleanup(sub6.delete)
Yair Friede198e2f2015-07-28 14:43:47 +030097 self.subnets_v6.append(sub6)
Kirill Shileev14113572014-11-21 16:58:02 +030098
99 @staticmethod
100 def define_server_ips(srv):
Kirill Shileevb1f97522015-02-19 20:39:05 +0300101 ips = {'4': None, '6': []}
Matthew Treinish71426682015-04-23 11:19:38 -0400102 for net_name, nics in six.iteritems(srv['addresses']):
Kirill Shileev14113572014-11-21 16:58:02 +0300103 for nic in nics:
104 if nic['version'] == 6:
Kirill Shileevb1f97522015-02-19 20:39:05 +0300105 ips['6'].append(nic['addr'])
Kirill Shileev14113572014-11-21 16:58:02 +0300106 else:
Kirill Shileevb1f97522015-02-19 20:39:05 +0300107 ips['4'] = nic['addr']
108 return ips
Kirill Shileev14113572014-11-21 16:58:02 +0300109
110 def prepare_server(self):
111 username = CONF.compute.image_ssh_user
112
Matthew Treinish8e48ad62014-12-12 11:07:23 -0500113 create_kwargs = self.srv_kwargs
114 create_kwargs['networks'] = [{'uuid': self.network.id}]
115
116 srv = self.create_server(create_kwargs=create_kwargs)
Kirill Shileev14113572014-11-21 16:58:02 +0300117 fip = self.create_floating_ip(thing=srv)
Kirill Shileevb1f97522015-02-19 20:39:05 +0300118 ips = self.define_server_ips(srv=srv)
Kirill Shileev14113572014-11-21 16:58:02 +0300119 ssh = self.get_remote_client(
120 server_or_ip=fip.floating_ip_address,
121 username=username)
Kirill Shileevb1f97522015-02-19 20:39:05 +0300122 return ssh, ips
Kirill Shileev14113572014-11-21 16:58:02 +0300123
Kirill Shileevb1f97522015-02-19 20:39:05 +0300124 def _prepare_and_test(self, address6_mode, n_subnets6=1):
125 self.prepare_network(address6_mode=address6_mode,
126 n_subnets6=n_subnets6)
Kirill Shileev14113572014-11-21 16:58:02 +0300127
Kirill Shileevb1f97522015-02-19 20:39:05 +0300128 sshv4_1, ips_from_api_1 = self.prepare_server()
129 sshv4_2, ips_from_api_2 = self.prepare_server()
Kirill Shileev14113572014-11-21 16:58:02 +0300130
Henry Gessau0efcfb92015-02-27 15:24:39 -0500131 def guest_has_address(ssh, addr):
132 return addr in ssh.get_ip_list()
133
Kirill Shileevb1f97522015-02-19 20:39:05 +0300134 # get addresses assigned to vNIC as reported by 'ip address' utility
135 ips_from_ip_1 = sshv4_1.get_ip_list()
136 ips_from_ip_2 = sshv4_2.get_ip_list()
137 self.assertIn(ips_from_api_1['4'], ips_from_ip_1)
138 self.assertIn(ips_from_api_2['4'], ips_from_ip_2)
139 for i in range(n_subnets6):
140 # v6 should be configured since the image supports it
141 # It can take time for ipv6 automatic address to get assigned
142 srv1_v6_addr_assigned = functools.partial(
143 guest_has_address, sshv4_1, ips_from_api_1['6'][i])
Henry Gessau0efcfb92015-02-27 15:24:39 -0500144
Kirill Shileevb1f97522015-02-19 20:39:05 +0300145 srv2_v6_addr_assigned = functools.partial(
146 guest_has_address, sshv4_2, ips_from_api_2['6'][i])
147
148 self.assertTrue(test.call_until_true(srv1_v6_addr_assigned,
149 CONF.compute.ping_timeout, 1))
150
151 self.assertTrue(test.call_until_true(srv2_v6_addr_assigned,
152 CONF.compute.ping_timeout, 1))
153
Yair Friede198e2f2015-07-28 14:43:47 +0300154 self._check_connectivity(sshv4_1, ips_from_api_2['4'])
155 self._check_connectivity(sshv4_2, ips_from_api_1['4'])
Kirill Shileev14113572014-11-21 16:58:02 +0300156
157 # Some VM (like cirros) may not have ping6 utility
Kirill Shileevb1f97522015-02-19 20:39:05 +0300158 result = sshv4_1.exec_command('whereis ping6')
Kirill Shileev14113572014-11-21 16:58:02 +0300159 is_ping6 = False if result == 'ping6:\n' else True
160 if is_ping6:
Kirill Shileevb1f97522015-02-19 20:39:05 +0300161 for i in range(n_subnets6):
Yair Friede198e2f2015-07-28 14:43:47 +0300162 self._check_connectivity(sshv4_1,
163 ips_from_api_2['6'][i])
164 self._check_connectivity(sshv4_1,
165 self.subnets_v6[i].gateway_ip)
166 self._check_connectivity(sshv4_2,
167 ips_from_api_1['6'][i])
168 self._check_connectivity(sshv4_2,
169 self.subnets_v6[i].gateway_ip)
Kirill Shileev14113572014-11-21 16:58:02 +0300170 else:
171 LOG.warning('Ping6 is not available, skipping')
172
Yair Friede198e2f2015-07-28 14:43:47 +0300173 def _check_connectivity(self, source, dest):
174 self.assertTrue(
175 self._check_remote_connectivity(source, dest),
176 "Timed out waiting for %s to become reachable from %s" %
177 (dest, source.ssh_client.host)
178 )
179
Chris Hoge7579c1a2015-02-26 14:12:15 -0800180 @test.idempotent_id('2c92df61-29f0-4eaa-bee3-7c65bef62a43')
Kirill Shileev14113572014-11-21 16:58:02 +0300181 @test.services('compute', 'network')
182 def test_slaac_from_os(self):
183 self._prepare_and_test(address6_mode='slaac')
184
Chris Hoge7579c1a2015-02-26 14:12:15 -0800185 @test.idempotent_id('d7e1f858-187c-45a6-89c9-bdafde619a9f')
Kirill Shileev14113572014-11-21 16:58:02 +0300186 @test.services('compute', 'network')
187 def test_dhcp6_stateless_from_os(self):
188 self._prepare_and_test(address6_mode='dhcpv6-stateless')
Kirill Shileevb1f97522015-02-19 20:39:05 +0300189
190 @test.idempotent_id('7ab23f41-833b-4a16-a7c9-5b42fe6d4123')
191 @test.services('compute', 'network')
192 def test_multi_prefix_dhcpv6_stateless(self):
193 self._prepare_and_test(address6_mode='dhcpv6-stateless', n_subnets6=2)
194
195 @test.idempotent_id('dec222b1-180c-4098-b8c5-cc1b8342d611')
196 @test.services('compute', 'network')
197 def test_multi_prefix_slaac(self):
198 self._prepare_and_test(address6_mode='slaac', n_subnets6=2)