blob: 3e218156c58dffcece0abc0b706aca148a4a328f [file] [log] [blame]
YAMAMOTO Takashi5214b272018-01-16 13:58:41 +09001# Copyright (c) 2016 Midokura SARL
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.
15
16import netaddr
17
18from tempest.common import utils
19from tempest.common import waiters
20from tempest.lib.common.utils import data_utils
21from tempest.lib import decorators
22
23from neutron_tempest_plugin import config
24from neutron_tempest_plugin.scenario import base
25from neutron_tempest_plugin.scenario import constants
26
27
28CONF = config.CONF
29
30
31class Fip64(base.BaseTempestTestCase):
32 credentials = ['primary', 'admin']
33
34 _fip_ip_version = 6
35
36 @classmethod
37 @utils.requires_ext(extension="fip64", service="network")
38 def resource_setup(cls):
39 super(Fip64, cls).resource_setup()
40 cls.network = cls.create_network()
41 cls.subnet = cls.create_subnet(cls.network)
42 router = cls.create_router_by_client()
43 cls.create_router_interface(router['id'], cls.subnet['id'])
44 cls.keypair = cls.create_keypair()
45
46 cls.secgroup = cls.os_primary.network_client.create_security_group(
47 name=data_utils.rand_name('secgroup-'))['security_group']
48 cls.security_groups.append(cls.secgroup)
49 cls.create_loginable_secgroup_rule(secgroup_id=cls.secgroup['id'])
50
51 def _find_ipv6_subnet(self, network_id):
52 subnets = self.os_admin.network_client.list_subnets(
53 network_id=network_id)['subnets']
54 for subnet in subnets:
55 if subnet['ip_version'] == self._fip_ip_version:
56 return subnet['id']
57 msg = "No suitable subnets on public network"
58 raise self.skipException(msg)
59
60 def _create_and_associate_floatingip64(self, port_id):
61 network_id = CONF.network.public_network_id
62 subnet_id = self._find_ipv6_subnet(network_id)
63 fip = self.os_primary.network_client.create_floatingip(
64 floating_network_id=network_id,
65 subnet_id=subnet_id,
66 port_id=port_id)['floatingip']
67 self.floating_ips.append(fip)
68 self.assertEqual(
69 self._fip_ip_version,
70 netaddr.IPAddress(fip['floating_ip_address']).version)
71 return fip
72
73 def _create_server_with_fip64(self):
74 port = self.create_port(self.network, security_groups=[
75 self.secgroup['id']])
76 fip = self._create_and_associate_floatingip64(port['id'])
77 server = self.create_server(
78 flavor_ref=CONF.compute.flavor_ref,
79 image_ref=CONF.compute.image_ref,
80 key_name=self.keypair['name'],
81 networks=[{'port': port['id']}])['server']
82 waiters.wait_for_server_status(self.os_primary.servers_client,
83 server['id'],
84 constants.SERVER_STATUS_ACTIVE)
85 return {'port': port, 'fip': fip, 'server': server}
86
87 @decorators.idempotent_id('63f7da91-c7dd-449b-b50b-1c56853ce0ef')
88 def test_fip64(self):
89 server = self._create_server_with_fip64()
90 self.check_connectivity(server['fip']['floating_ip_address'],
91 CONF.validation.image_ssh_user,
92 self.keypair['private_key'])