blob: 16ff8485ab6201e7d1b0445cca6302de2f6731de [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
Kirill Shileev14113572014-11-21 16:58:02 +030016import netaddr
Doug Hellmann583ce2c2015-03-11 14:55:46 +000017
18from oslo_log import log as logging
19
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):
30 """Create network with 2 subnets: IPv4 and IPv6 in a given address mode
31 Boot 2 VMs on this network
32 Allocate and assign 2 FIP4
33 Check that vNIC of server matches port data from OpenStack DB
34 Ping4 tenant IPv4 of one VM from another one
35 Will do the same with ping6 when available in VM
36 """
37
38 @classmethod
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000039 def skip_checks(cls):
40 super(TestGettingAddress, cls).skip_checks()
Kirill Shileev14113572014-11-21 16:58:02 +030041 if not (CONF.network_feature_enabled.ipv6
42 and CONF.network_feature_enabled.ipv6_subnet_attributes):
Kirill Shileev14113572014-11-21 16:58:02 +030043 raise cls.skipException('IPv6 or its attributes not supported')
44 if not (CONF.network.tenant_networks_reachable
45 or CONF.network.public_network_id):
46 msg = ('Either tenant_networks_reachable must be "true", or '
47 'public_network_id must be defined.')
Kirill Shileev14113572014-11-21 16:58:02 +030048 raise cls.skipException(msg)
Adam Gandelmanab6106d2014-12-12 10:38:23 -080049 if CONF.baremetal.driver_enabled:
50 msg = ('Baremetal does not currently support network isolation')
51 raise cls.skipException(msg)
Adam Gandelman721f80d2014-12-12 11:03:14 -080052
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000053 @classmethod
54 def setup_credentials(cls):
55 # Create no network resources for these tests.
56 cls.set_network_resources()
57 super(TestGettingAddress, cls).setup_credentials()
Kirill Shileev14113572014-11-21 16:58:02 +030058
59 def setUp(self):
60 super(TestGettingAddress, self).setUp()
61 self.keypair = self.create_keypair()
62 self.sec_grp = self._create_security_group(tenant_id=self.tenant_id)
63 self.srv_kwargs = {
64 'key_name': self.keypair['name'],
ghanshyamfc5e0c72015-01-29 15:09:40 +090065 'security_groups': [{'name': self.sec_grp['name']}]}
Kirill Shileev14113572014-11-21 16:58:02 +030066
67 def prepare_network(self, address6_mode):
68 """Creates network with
69 one IPv6 subnet in the given mode and
70 one IPv4 subnet
71 Creates router with ports on both subnets
72 """
Matthew Treinish8e48ad62014-12-12 11:07:23 -050073 self.network = self._create_network(tenant_id=self.tenant_id)
74 sub4 = self._create_subnet(network=self.network,
Kirill Shileev14113572014-11-21 16:58:02 +030075 namestart='sub4',
76 ip_version=4,)
77 # since https://bugs.launchpad.net/neutron/+bug/1394112 we need
78 # to specify gateway_ip manually
79 net_range = netaddr.IPNetwork(CONF.network.tenant_network_v6_cidr)
80 gateway_ip = (netaddr.IPAddress(net_range) + 1).format()
Matthew Treinish8e48ad62014-12-12 11:07:23 -050081 sub6 = self._create_subnet(network=self.network,
Kirill Shileev14113572014-11-21 16:58:02 +030082 namestart='sub6',
83 ip_version=6,
84 gateway_ip=gateway_ip,
85 ipv6_ra_mode=address6_mode,
86 ipv6_address_mode=address6_mode)
87
88 router = self._get_router(tenant_id=self.tenant_id)
89 sub4.add_to_router(router_id=router['id'])
90 sub6.add_to_router(router_id=router['id'])
91 self.addCleanup(sub4.delete)
92 self.addCleanup(sub6.delete)
93
94 @staticmethod
95 def define_server_ips(srv):
96 for net_name, nics in srv['addresses'].iteritems():
97 for nic in nics:
98 if nic['version'] == 6:
99 srv['accessIPv6'] = nic['addr']
100 else:
101 srv['accessIPv4'] = nic['addr']
102
103 def prepare_server(self):
104 username = CONF.compute.image_ssh_user
105
Matthew Treinish8e48ad62014-12-12 11:07:23 -0500106 create_kwargs = self.srv_kwargs
107 create_kwargs['networks'] = [{'uuid': self.network.id}]
108
109 srv = self.create_server(create_kwargs=create_kwargs)
Kirill Shileev14113572014-11-21 16:58:02 +0300110 fip = self.create_floating_ip(thing=srv)
111 self.define_server_ips(srv=srv)
112 ssh = self.get_remote_client(
113 server_or_ip=fip.floating_ip_address,
114 username=username)
115 return ssh, srv
116
117 def _prepare_and_test(self, address6_mode):
118 self.prepare_network(address6_mode=address6_mode)
119
120 ssh1, srv1 = self.prepare_server()
121 ssh2, srv2 = self.prepare_server()
122
Henry Gessau0efcfb92015-02-27 15:24:39 -0500123 def guest_has_address(ssh, addr):
124 return addr in ssh.get_ip_list()
125
126 srv1_v6_addr_assigned = functools.partial(
127 guest_has_address, ssh1, srv1['accessIPv6'])
128 srv2_v6_addr_assigned = functools.partial(
129 guest_has_address, ssh2, srv2['accessIPv6'])
130
Kirill Shileev14113572014-11-21 16:58:02 +0300131 result = ssh1.get_ip_list()
132 self.assertIn(srv1['accessIPv4'], result)
133 # v6 should be configured since the image supports it
Henry Gessau0efcfb92015-02-27 15:24:39 -0500134 # It can take time for ipv6 automatic address to get assigned
135 self.assertTrue(
136 test.call_until_true(srv1_v6_addr_assigned,
137 CONF.compute.ping_timeout, 1))
Kirill Shileev14113572014-11-21 16:58:02 +0300138 result = ssh2.get_ip_list()
139 self.assertIn(srv2['accessIPv4'], result)
140 # v6 should be configured since the image supports it
Henry Gessau0efcfb92015-02-27 15:24:39 -0500141 # It can take time for ipv6 automatic address to get assigned
142 self.assertTrue(
143 test.call_until_true(srv2_v6_addr_assigned,
144 CONF.compute.ping_timeout, 1))
Kirill Shileev14113572014-11-21 16:58:02 +0300145 result = ssh1.ping_host(srv2['accessIPv4'])
146 self.assertIn('0% packet loss', result)
147 result = ssh2.ping_host(srv1['accessIPv4'])
148 self.assertIn('0% packet loss', result)
149
150 # Some VM (like cirros) may not have ping6 utility
151 result = ssh1.exec_command('whereis ping6')
152 is_ping6 = False if result == 'ping6:\n' else True
153 if is_ping6:
154 result = ssh1.ping_host(srv2['accessIPv6'])
155 self.assertIn('0% packet loss', result)
156 result = ssh2.ping_host(srv1['accessIPv6'])
157 self.assertIn('0% packet loss', result)
158 else:
159 LOG.warning('Ping6 is not available, skipping')
160
Chris Hoge7579c1a2015-02-26 14:12:15 -0800161 @test.idempotent_id('2c92df61-29f0-4eaa-bee3-7c65bef62a43')
Kirill Shileev14113572014-11-21 16:58:02 +0300162 @test.services('compute', 'network')
163 def test_slaac_from_os(self):
164 self._prepare_and_test(address6_mode='slaac')
165
Chris Hoge7579c1a2015-02-26 14:12:15 -0800166 @test.idempotent_id('d7e1f858-187c-45a6-89c9-bdafde619a9f')
Kirill Shileev14113572014-11-21 16:58:02 +0300167 @test.services('compute', 'network')
168 def test_dhcp6_stateless_from_os(self):
169 self._prepare_and_test(address6_mode='dhcpv6-stateless')