blob: 4c2ebb17af2ad4da54d9afd199f09e8a389421a6 [file] [log] [blame]
YAMAMOTO Takashi25935722017-01-23 15:34:11 +09001# Copyright (c) 2017 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
17from tempest.common import waiters
18from tempest.lib.common import ssh
19from tempest.lib.common.utils import data_utils
20from tempest import test
21import testscenarios
22
23from neutron.tests.tempest import config
24from neutron.tests.tempest.scenario import base
25from neutron.tests.tempest.scenario import constants
26
27
28CONF = config.CONF
29
30
31load_tests = testscenarios.load_tests_apply_scenarios
32
33
34class FloatingIpTestCasesMixin(object):
35 credentials = ['primary', 'admin']
36
37 @classmethod
38 @test.requires_ext(extension="router", service="network")
39 def resource_setup(cls):
40 super(FloatingIpTestCasesMixin, cls).resource_setup()
41 cls.network = cls.create_network()
42 cls.subnet = cls.create_subnet(cls.network)
43 cls.router = cls.create_router_by_client()
44 cls.create_router_interface(cls.router['id'], cls.subnet['id'])
45 cls.keypair = cls.create_keypair()
46
47 cls.secgroup = cls.manager.network_client.create_security_group(
48 name=data_utils.rand_name('secgroup-'))['security_group']
49 cls.security_groups.append(cls.secgroup)
50 cls.create_loginable_secgroup_rule(secgroup_id=cls.secgroup['id'])
51 cls.create_pingable_secgroup_rule(secgroup_id=cls.secgroup['id'])
52
53 cls._src_server = cls._create_server()
54 if cls.same_network:
55 cls._dest_network = cls.network
56 else:
57 cls._dest_network = cls._create_dest_network()
58 cls._dest_server_with_fip = cls._create_server(
59 network=cls._dest_network)
60 cls._dest_server_without_fip = cls._create_server(
61 create_floating_ip=False, network=cls._dest_network)
62
63 @classmethod
64 def _create_dest_network(cls):
65 network = cls.create_network()
66 subnet = cls.create_subnet(network,
67 cidr=netaddr.IPNetwork('10.10.0.0/24'))
68 cls.create_router_interface(cls.router['id'], subnet['id'])
69 return network
70
71 @classmethod
72 def _create_server(cls, create_floating_ip=True, network=None):
73 if network is None:
74 network = cls.network
75 port = cls.create_port(network, security_groups=[cls.secgroup['id']])
76 if create_floating_ip:
77 fip = cls.create_and_associate_floatingip(port['id'])
78 else:
79 fip = None
80 server = cls.create_server(
81 flavor_ref=CONF.compute.flavor_ref,
82 image_ref=CONF.compute.image_ref,
83 key_name=cls.keypair['name'],
84 networks=[{'port': port['id']}])['server']
85 waiters.wait_for_server_status(cls.manager.servers_client,
86 server['id'],
87 constants.SERVER_STATUS_ACTIVE)
88 return {'port': port, 'fip': fip, 'server': server}
89
90 def _test_east_west(self):
91 # Source VM
92 server1 = self._src_server
93 server1_ip = server1['fip']['floating_ip_address']
94 ssh_client = ssh.Client(server1_ip,
95 CONF.validation.image_ssh_user,
96 pkey=self.keypair['private_key'])
97
98 # Destination VM
99 if self.dest_has_fip:
100 dest_server = self._dest_server_with_fip
101 else:
102 dest_server = self._dest_server_without_fip
103
104 # Check connectivity
105 self.check_remote_connectivity(ssh_client,
106 dest_server['port']['fixed_ips'][0]['ip_address'])
107 if self.dest_has_fip:
108 self.check_remote_connectivity(ssh_client,
109 dest_server['fip']['floating_ip_address'])
110
111
112class FloatingIpSameNetwork(FloatingIpTestCasesMixin,
113 base.BaseTempestTestCase):
114 # REVISIT(yamamoto): 'SRC without FIP' case is possible?
115 scenarios = [
116 ('DEST with FIP', dict(dest_has_fip=True)),
117 ('DEST without FIP', dict(dest_has_fip=False)),
118 ]
119
120 same_network = True
121
122 @test.idempotent_id('05c4e3b3-7319-4052-90ad-e8916436c23b')
123 def test_east_west(self):
124 self._test_east_west()
125
126
127class FloatingIpSeparateNetwork(FloatingIpTestCasesMixin,
128 base.BaseTempestTestCase):
129 # REVISIT(yamamoto): 'SRC without FIP' case is possible?
130 scenarios = [
131 ('DEST with FIP', dict(dest_has_fip=True)),
132 ('DEST without FIP', dict(dest_has_fip=False)),
133 ]
134
135 same_network = False
136
137 @test.idempotent_id('f18f0090-3289-4783-b956-a0f8ac511e8b')
138 def test_east_west(self):
139 self._test_east_west()