blob: 20505eb0633106bb495c164ba477370409ffd521 [file] [log] [blame]
Yair Fried4d7efa62013-11-17 17:12:29 +02001# Copyright 2013 Red Hat, 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.
15
Andrea Frittolif9cde7e2014-02-18 09:57:04 +000016from tempest import clients
Yair Fried4d7efa62013-11-17 17:12:29 +020017from tempest.common import debug
18from tempest.common.utils import data_utils
Matthew Treinish6c072292014-01-29 19:15:52 +000019from tempest import config
Yair Fried4d7efa62013-11-17 17:12:29 +020020from tempest.openstack.common import log as logging
21from tempest.scenario import manager
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090022from tempest import test
Yair Fried4d7efa62013-11-17 17:12:29 +020023
Matthew Treinish6c072292014-01-29 19:15:52 +000024CONF = config.CONF
25
Yair Fried4d7efa62013-11-17 17:12:29 +020026LOG = logging.getLogger(__name__)
27
28
Yair Frieddb6c9e92014-08-06 08:53:13 +030029class TestSecurityGroupsBasicOps(manager.NeutronScenarioTest):
Yair Fried4d7efa62013-11-17 17:12:29 +020030
31 """
32 This test suite assumes that Nova has been configured to
33 boot VM's with Neutron-managed networking, and attempts to
34 verify cross tenant connectivity as follows
35
36 ssh:
37 in order to overcome "ip namespace", each tenant has an "access point"
38 VM with floating-ip open to incoming ssh connection allowing network
39 commands (ping/ssh) to be executed from within the
40 tenant-network-namespace
41 Tempest host performs key-based authentication to the ssh server via
42 floating IP address
43
44 connectivity test is done by pinging destination server via source server
45 ssh connection.
46 success - ping returns
47 failure - ping_timeout reached
48
49 setup:
Yair Friedbf2e2c42014-01-28 12:06:38 +020050 for primary tenant:
Yair Fried4d7efa62013-11-17 17:12:29 +020051 1. create a network&subnet
52 2. create a router (if public router isn't configured)
53 3. connect tenant network to public network via router
54 4. create an access point:
55 a. a security group open to incoming ssh connection
56 b. a VM with a floating ip
57 5. create a general empty security group (same as "default", but
58 without rules allowing in-tenant traffic)
Yair Fried4d7efa62013-11-17 17:12:29 +020059
60 tests:
61 1. _verify_network_details
62 2. _verify_mac_addr: for each access point verify that
63 (subnet, fix_ip, mac address) are as defined in the port list
64 3. _test_in_tenant_block: test that in-tenant traffic is disabled
65 without rules allowing it
66 4. _test_in_tenant_allow: test that in-tenant traffic is enabled
67 once an appropriate rule has been created
68 5. _test_cross_tenant_block: test that cross-tenant traffic is disabled
69 without a rule allowing it on destination tenant
70 6. _test_cross_tenant_allow:
71 * test that cross-tenant traffic is enabled once an appropriate
72 rule has been created on destination tenant.
73 * test that reverse traffic is still blocked
74 * test than revesre traffic is enabled once an appropriate rule has
75 been created on source tenant
76
77 assumptions:
Yair Friedbf2e2c42014-01-28 12:06:38 +020078 1. alt_tenant/user existed and is different from primary_tenant/user
Yair Fried4d7efa62013-11-17 17:12:29 +020079 2. Public network is defined and reachable from the Tempest host
80 3. Public router can either be:
81 * defined, in which case all tenants networks can connect directly
82 to it, and cross tenant check will be done on the private IP of the
83 destination tenant
84 or
85 * not defined (empty string), in which case each tanant will have
86 its own router connected to the public network
87 """
88
89 class TenantProperties():
Yair Friedbf2e2c42014-01-28 12:06:38 +020090 """
Yair Fried4d7efa62013-11-17 17:12:29 +020091 helper class to save tenant details
92 id
93 credentials
94 network
95 subnet
96 security groups
97 servers
98 access point
Yair Friedbf2e2c42014-01-28 12:06:38 +020099 """
Yair Fried4d7efa62013-11-17 17:12:29 +0200100
Andrea Frittoli422fbdf2014-03-20 10:05:18 +0000101 def __init__(self, credentials):
Yair Frieddb6c9e92014-08-06 08:53:13 +0300102 self.manager = clients.Manager(credentials)
Andrea Frittoli422fbdf2014-03-20 10:05:18 +0000103 # Credentials from manager are filled with both names and IDs
104 self.creds = self.manager.credentials
Yair Fried4d7efa62013-11-17 17:12:29 +0200105 self.network = None
106 self.subnet = None
107 self.router = None
108 self.security_groups = {}
109 self.servers = list()
110
Yair Friedbf2e2c42014-01-28 12:06:38 +0200111 def set_network(self, network, subnet, router):
Yair Fried4d7efa62013-11-17 17:12:29 +0200112 self.network = network
113 self.subnet = subnet
114 self.router = router
115
Yair Fried4d7efa62013-11-17 17:12:29 +0200116 @classmethod
117 def check_preconditions(cls):
Yair Frieddb6c9e92014-08-06 08:53:13 +0300118 if CONF.baremetal.driver_enabled:
119 msg = ('Not currently supported by baremetal.')
120 cls.enabled = False
121 raise cls.skipException(msg)
Yair Friedbf2e2c42014-01-28 12:06:38 +0200122 super(TestSecurityGroupsBasicOps, cls).check_preconditions()
Yair Frieddb6c9e92014-08-06 08:53:13 +0300123 # need alt_creds here to check preconditions
124 cls.alt_creds = cls.alt_credentials()
125 cls.alt_manager = clients.Manager(cls.alt_creds)
126 # Credentials from the manager are filled with both IDs and Names
127 cls.alt_creds = cls.alt_manager.credentials
Andrea Frittoli86ad28d2014-03-20 10:09:12 +0000128 if (cls.alt_creds is None) or \
129 (cls.tenant_id is cls.alt_creds.tenant_id):
Yair Fried4d7efa62013-11-17 17:12:29 +0200130 msg = 'No alt_tenant defined'
131 cls.enabled = False
132 raise cls.skipException(msg)
Matthew Treinish6c072292014-01-29 19:15:52 +0000133 if not (CONF.network.tenant_networks_reachable or
134 CONF.network.public_network_id):
Yair Fried4d7efa62013-11-17 17:12:29 +0200135 msg = ('Either tenant_networks_reachable must be "true", or '
136 'public_network_id must be defined.')
137 cls.enabled = False
138 raise cls.skipException(msg)
139
140 @classmethod
141 def setUpClass(cls):
Yair Fried764610a2014-04-07 12:17:05 +0300142 # Create no network resources for these tests.
143 cls.set_network_resources()
Yair Friedbf2e2c42014-01-28 12:06:38 +0200144 super(TestSecurityGroupsBasicOps, cls).setUpClass()
Yair Fried4d7efa62013-11-17 17:12:29 +0200145 # TODO(mnewby) Consider looking up entities as needed instead
146 # of storing them as collections on the class.
Yair Fried4d7efa62013-11-17 17:12:29 +0200147 cls.floating_ips = {}
148 cls.tenants = {}
Andrea Frittoli422fbdf2014-03-20 10:05:18 +0000149 creds = cls.credentials()
150 cls.primary_tenant = cls.TenantProperties(creds)
151 cls.alt_tenant = cls.TenantProperties(cls.alt_creds)
Yair Friedbf2e2c42014-01-28 12:06:38 +0200152 for tenant in [cls.primary_tenant, cls.alt_tenant]:
Andrea Frittoli86ad28d2014-03-20 10:09:12 +0000153 cls.tenants[tenant.creds.tenant_id] = tenant
Yair Friedbf2e2c42014-01-28 12:06:38 +0200154 cls.floating_ip_access = not CONF.network.public_router_id
Yair Fried4d7efa62013-11-17 17:12:29 +0200155
Yair Friedbf2e2c42014-01-28 12:06:38 +0200156 def cleanup_wrapper(self, resource):
157 self.cleanup_resource(resource, self.__class__.__name__)
158
159 def setUp(self):
160 super(TestSecurityGroupsBasicOps, self).setUp()
161 self._deploy_tenant(self.primary_tenant)
162 self._verify_network_details(self.primary_tenant)
163 self._verify_mac_addr(self.primary_tenant)
Yair Fried4d7efa62013-11-17 17:12:29 +0200164
Yair Frieddb6c9e92014-08-06 08:53:13 +0300165 def _create_tenant_keypairs(self, tenant):
166 keypair = self.create_keypair(tenant.manager.keypairs_client)
167 tenant.keypair = keypair
Yair Fried4d7efa62013-11-17 17:12:29 +0200168
169 def _create_tenant_security_groups(self, tenant):
Yair Fried4d7efa62013-11-17 17:12:29 +0200170 access_sg = self._create_empty_security_group(
171 namestart='secgroup_access-',
Yair Frieddb6c9e92014-08-06 08:53:13 +0300172 tenant_id=tenant.creds.tenant_id,
173 client=tenant.manager.network_client
Yair Fried4d7efa62013-11-17 17:12:29 +0200174 )
Yair Friedbf2e2c42014-01-28 12:06:38 +0200175
Yair Fried4d7efa62013-11-17 17:12:29 +0200176 # don't use default secgroup since it allows in-tenant traffic
177 def_sg = self._create_empty_security_group(
178 namestart='secgroup_general-',
Yair Frieddb6c9e92014-08-06 08:53:13 +0300179 tenant_id=tenant.creds.tenant_id,
180 client=tenant.manager.network_client
Yair Fried4d7efa62013-11-17 17:12:29 +0200181 )
182 tenant.security_groups.update(access=access_sg, default=def_sg)
183 ssh_rule = dict(
184 protocol='tcp',
185 port_range_min=22,
186 port_range_max=22,
187 direction='ingress',
188 )
Yair Frieddb6c9e92014-08-06 08:53:13 +0300189 self._create_security_group_rule(secgroup=access_sg,
190 client=tenant.manager.network_client,
191 **ssh_rule)
Yair Fried4d7efa62013-11-17 17:12:29 +0200192
193 def _verify_network_details(self, tenant):
194 # Checks that we see the newly created network/subnet/router via
195 # checking the result of list_[networks,routers,subnets]
196 # Check that (router, subnet) couple exist in port_list
197 seen_nets = self._list_networks()
198 seen_names = [n['name'] for n in seen_nets]
199 seen_ids = [n['id'] for n in seen_nets]
200
201 self.assertIn(tenant.network.name, seen_names)
202 self.assertIn(tenant.network.id, seen_ids)
203
204 seen_subnets = [(n['id'], n['cidr'], n['network_id'])
205 for n in self._list_subnets()]
206 mysubnet = (tenant.subnet.id, tenant.subnet.cidr, tenant.network.id)
207 self.assertIn(mysubnet, seen_subnets)
208
209 seen_routers = self._list_routers()
210 seen_router_ids = [n['id'] for n in seen_routers]
211 seen_router_names = [n['name'] for n in seen_routers]
212
213 self.assertIn(tenant.router.name, seen_router_names)
214 self.assertIn(tenant.router.id, seen_router_ids)
215
216 myport = (tenant.router.id, tenant.subnet.id)
217 router_ports = [(i['device_id'], i['fixed_ips'][0]['subnet_id']) for i
Yair Frieddb6c9e92014-08-06 08:53:13 +0300218 in self._list_ports()
armando-migliacciobcfbbeb2014-08-11 18:33:47 -0700219 if self._is_router_port(i)]
Yair Fried4d7efa62013-11-17 17:12:29 +0200220
221 self.assertIn(myport, router_ports)
222
armando-migliacciobcfbbeb2014-08-11 18:33:47 -0700223 def _is_router_port(self, port):
224 """Return True if port is a router interface."""
225 # NOTE(armando-migliaccio): match device owner for both centralized
226 # and distributed routers; 'device_owner' is "" by default.
227 return port['device_owner'].startswith('network:router_interface')
228
Yair Fried4d7efa62013-11-17 17:12:29 +0200229 def _create_server(self, name, tenant, security_groups=None):
230 """
231 creates a server and assigns to security group
232 """
233 self._set_compute_context(tenant)
234 if security_groups is None:
Yair Frieddb6c9e92014-08-06 08:53:13 +0300235 security_groups = [tenant.security_groups['default']]
Yair Fried4d7efa62013-11-17 17:12:29 +0200236 create_kwargs = {
Dirk Mueller8cf79722014-09-12 17:37:15 +0200237 'networks': [
238 {'uuid': tenant.network.id},
Yair Fried4d7efa62013-11-17 17:12:29 +0200239 ],
Yair Frieddb6c9e92014-08-06 08:53:13 +0300240 'key_name': tenant.keypair['name'],
Yair Fried4d7efa62013-11-17 17:12:29 +0200241 'security_groups': security_groups,
Andrea Frittoli86ad28d2014-03-20 10:09:12 +0000242 'tenant_id': tenant.creds.tenant_id
Yair Fried4d7efa62013-11-17 17:12:29 +0200243 }
Yair Frieddb6c9e92014-08-06 08:53:13 +0300244 return self.create_server(name=name, create_kwargs=create_kwargs)
Yair Fried4d7efa62013-11-17 17:12:29 +0200245
246 def _create_tenant_servers(self, tenant, num=1):
247 for i in range(num):
248 name = 'server-{tenant}-gen-{num}-'.format(
Andrea Frittoli86ad28d2014-03-20 10:09:12 +0000249 tenant=tenant.creds.tenant_name,
Yair Fried4d7efa62013-11-17 17:12:29 +0200250 num=i
251 )
252 name = data_utils.rand_name(name)
253 server = self._create_server(name, tenant)
Yair Fried4d7efa62013-11-17 17:12:29 +0200254 tenant.servers.append(server)
255
256 def _set_access_point(self, tenant):
257 """
258 creates a server in a secgroup with rule allowing external ssh
259 in order to access tenant internal network
260 workaround ip namespace
261 """
Yair Frieddb6c9e92014-08-06 08:53:13 +0300262 secgroups = tenant.security_groups.values()
Andrea Frittoli86ad28d2014-03-20 10:09:12 +0000263 name = 'server-{tenant}-access_point-'.format(
264 tenant=tenant.creds.tenant_name)
Yair Fried4d7efa62013-11-17 17:12:29 +0200265 name = data_utils.rand_name(name)
266 server = self._create_server(name, tenant,
267 security_groups=secgroups)
Yair Fried4d7efa62013-11-17 17:12:29 +0200268 tenant.access_point = server
Yair Frieddb6c9e92014-08-06 08:53:13 +0300269 self._assign_floating_ips(tenant, server)
Yair Fried4d7efa62013-11-17 17:12:29 +0200270
Yair Frieddb6c9e92014-08-06 08:53:13 +0300271 def _assign_floating_ips(self, tenant, server):
Matthew Treinish6c072292014-01-29 19:15:52 +0000272 public_network_id = CONF.network.public_network_id
Yair Frieddb6c9e92014-08-06 08:53:13 +0300273 floating_ip = self._create_floating_ip(
274 server, public_network_id,
275 client=tenant.manager.network_client)
276 self.floating_ips.setdefault(server['id'], floating_ip)
Yair Fried4d7efa62013-11-17 17:12:29 +0200277
278 def _create_tenant_network(self, tenant):
Yair Frieddb6c9e92014-08-06 08:53:13 +0300279 network, subnet, router = self.create_networks(
280 client=tenant.manager.network_client)
Yair Friedbf2e2c42014-01-28 12:06:38 +0200281 tenant.set_network(network, subnet, router)
Yair Fried4d7efa62013-11-17 17:12:29 +0200282
283 def _set_compute_context(self, tenant):
Yair Frieddb6c9e92014-08-06 08:53:13 +0300284 self.servers_client = tenant.manager.servers_client
285 return self.servers_client
Yair Fried4d7efa62013-11-17 17:12:29 +0200286
287 def _deploy_tenant(self, tenant_or_id):
288 """
289 creates:
290 network
291 subnet
292 router (if public not defined)
293 access security group
294 access-point server
Yair Fried4d7efa62013-11-17 17:12:29 +0200295 """
296 if not isinstance(tenant_or_id, self.TenantProperties):
297 tenant = self.tenants[tenant_or_id]
Yair Fried4d7efa62013-11-17 17:12:29 +0200298 else:
299 tenant = tenant_or_id
Yair Fried4d7efa62013-11-17 17:12:29 +0200300 self._set_compute_context(tenant)
Yair Frieddb6c9e92014-08-06 08:53:13 +0300301 self._create_tenant_keypairs(tenant)
Yair Fried4d7efa62013-11-17 17:12:29 +0200302 self._create_tenant_network(tenant)
303 self._create_tenant_security_groups(tenant)
Yair Fried4d7efa62013-11-17 17:12:29 +0200304 self._set_access_point(tenant)
305
306 def _get_server_ip(self, server, floating=False):
Yair Friedbf2e2c42014-01-28 12:06:38 +0200307 """
Yair Fried4d7efa62013-11-17 17:12:29 +0200308 returns the ip (floating/internal) of a server
Yair Friedbf2e2c42014-01-28 12:06:38 +0200309 """
Yair Fried4d7efa62013-11-17 17:12:29 +0200310 if floating:
Yair Frieddb6c9e92014-08-06 08:53:13 +0300311 server_ip = self.floating_ips[server['id']].floating_ip_address
Yair Fried4d7efa62013-11-17 17:12:29 +0200312 else:
armando-migliacciod03f2642014-02-21 19:55:50 -0800313 server_ip = None
Yair Frieddb6c9e92014-08-06 08:53:13 +0300314 network_name = self.tenants[server['tenant_id']].network.name
315 if network_name in server['addresses']:
316 server_ip = server['addresses'][network_name][0]['addr']
armando-migliacciod03f2642014-02-21 19:55:50 -0800317 return server_ip
Yair Fried4d7efa62013-11-17 17:12:29 +0200318
319 def _connect_to_access_point(self, tenant):
320 """
321 create ssh connection to tenant access point
322 """
323 access_point_ssh = \
Yair Frieddb6c9e92014-08-06 08:53:13 +0300324 self.floating_ips[tenant.access_point['id']].floating_ip_address
325 private_key = tenant.keypair['private_key']
Yair Fried4d7efa62013-11-17 17:12:29 +0200326 access_point_ssh = self._ssh_to_server(access_point_ssh,
327 private_key=private_key)
328 return access_point_ssh
329
Yair Fried4d7efa62013-11-17 17:12:29 +0200330 def _check_connectivity(self, access_point, ip, should_succeed=True):
331 if should_succeed:
332 msg = "Timed out waiting for %s to become reachable" % ip
333 else:
Yair Fried4d7efa62013-11-17 17:12:29 +0200334 msg = "%s is reachable" % ip
335 try:
Yair Fried3097dc12014-01-26 08:46:43 +0200336 self.assertTrue(self._check_remote_connectivity(access_point, ip,
337 should_succeed),
Yair Fried4d7efa62013-11-17 17:12:29 +0200338 msg)
Yair Fried3960c4d2014-05-07 15:20:30 +0300339 except test.exceptions.SSHTimeout:
340 raise
Yair Fried4d7efa62013-11-17 17:12:29 +0200341 except Exception:
Attila Fazekas6bfd6492014-02-26 21:25:53 +0100342 debug.log_net_debug()
Yair Fried4d7efa62013-11-17 17:12:29 +0200343 raise
344
345 def _test_in_tenant_block(self, tenant):
346 access_point_ssh = self._connect_to_access_point(tenant)
347 for server in tenant.servers:
348 self._check_connectivity(access_point=access_point_ssh,
349 ip=self._get_server_ip(server),
350 should_succeed=False)
351
352 def _test_in_tenant_allow(self, tenant):
353 ruleset = dict(
354 protocol='icmp',
355 remote_group_id=tenant.security_groups['default'].id,
356 direction='ingress'
357 )
Matthew Treinishb7144eb2013-12-13 22:57:35 +0000358 self._create_security_group_rule(
Yair Fried4d7efa62013-11-17 17:12:29 +0200359 secgroup=tenant.security_groups['default'],
360 **ruleset
361 )
362 access_point_ssh = self._connect_to_access_point(tenant)
363 for server in tenant.servers:
364 self._check_connectivity(access_point=access_point_ssh,
365 ip=self._get_server_ip(server))
Yair Fried4d7efa62013-11-17 17:12:29 +0200366
367 def _test_cross_tenant_block(self, source_tenant, dest_tenant):
Yair Friedbf2e2c42014-01-28 12:06:38 +0200368 """
Yair Fried4d7efa62013-11-17 17:12:29 +0200369 if public router isn't defined, then dest_tenant access is via
370 floating-ip
Yair Friedbf2e2c42014-01-28 12:06:38 +0200371 """
Yair Fried4d7efa62013-11-17 17:12:29 +0200372 access_point_ssh = self._connect_to_access_point(source_tenant)
373 ip = self._get_server_ip(dest_tenant.access_point,
374 floating=self.floating_ip_access)
375 self._check_connectivity(access_point=access_point_ssh, ip=ip,
376 should_succeed=False)
377
378 def _test_cross_tenant_allow(self, source_tenant, dest_tenant):
Yair Friedbf2e2c42014-01-28 12:06:38 +0200379 """
Yair Fried4d7efa62013-11-17 17:12:29 +0200380 check for each direction:
381 creating rule for tenant incoming traffic enables only 1way traffic
Yair Friedbf2e2c42014-01-28 12:06:38 +0200382 """
Yair Fried4d7efa62013-11-17 17:12:29 +0200383 ruleset = dict(
384 protocol='icmp',
385 direction='ingress'
386 )
Matthew Treinishb7144eb2013-12-13 22:57:35 +0000387 self._create_security_group_rule(
Yair Fried4d7efa62013-11-17 17:12:29 +0200388 secgroup=dest_tenant.security_groups['default'],
Yair Frieddb6c9e92014-08-06 08:53:13 +0300389 client=dest_tenant.manager.network_client,
Yair Fried4d7efa62013-11-17 17:12:29 +0200390 **ruleset
391 )
Yair Friedbf2e2c42014-01-28 12:06:38 +0200392 access_point_ssh = self._connect_to_access_point(source_tenant)
393 ip = self._get_server_ip(dest_tenant.access_point,
394 floating=self.floating_ip_access)
395 self._check_connectivity(access_point_ssh, ip)
Yair Fried4d7efa62013-11-17 17:12:29 +0200396
Yair Friedbf2e2c42014-01-28 12:06:38 +0200397 # test that reverse traffic is still blocked
398 self._test_cross_tenant_block(dest_tenant, source_tenant)
Yair Fried4d7efa62013-11-17 17:12:29 +0200399
Yair Friedbf2e2c42014-01-28 12:06:38 +0200400 # allow reverse traffic and check
Matthew Treinishb7144eb2013-12-13 22:57:35 +0000401 self._create_security_group_rule(
Yair Friedbf2e2c42014-01-28 12:06:38 +0200402 secgroup=source_tenant.security_groups['default'],
Yair Frieddb6c9e92014-08-06 08:53:13 +0300403 client=source_tenant.manager.network_client,
Yair Friedbf2e2c42014-01-28 12:06:38 +0200404 **ruleset
405 )
Yair Fried4d7efa62013-11-17 17:12:29 +0200406
Yair Friedbf2e2c42014-01-28 12:06:38 +0200407 access_point_ssh_2 = self._connect_to_access_point(dest_tenant)
408 ip = self._get_server_ip(source_tenant.access_point,
409 floating=self.floating_ip_access)
410 self._check_connectivity(access_point_ssh_2, ip)
Yair Fried4d7efa62013-11-17 17:12:29 +0200411
412 def _verify_mac_addr(self, tenant):
413 """
414 verify that VM (tenant's access point) has the same ip,mac as listed in
415 port list
416 """
417 access_point_ssh = self._connect_to_access_point(tenant)
418 mac_addr = access_point_ssh.get_mac_address()
419 mac_addr = mac_addr.strip().lower()
Henry Gessau78ab4b02014-03-31 15:10:13 -0400420 # Get the fixed_ips and mac_address fields of all ports. Select
421 # only those two columns to reduce the size of the response.
Yair Frieddb6c9e92014-08-06 08:53:13 +0300422 port_list = self._list_ports(fields=['fixed_ips', 'mac_address'])
Yair Fried4d7efa62013-11-17 17:12:29 +0200423 port_detail_list = [
424 (port['fixed_ips'][0]['subnet_id'],
425 port['fixed_ips'][0]['ip_address'],
Henry Gessau78ab4b02014-03-31 15:10:13 -0400426 port['mac_address'].lower())
427 for port in port_list if port['fixed_ips']
Yair Fried4d7efa62013-11-17 17:12:29 +0200428 ]
429 server_ip = self._get_server_ip(tenant.access_point)
430 subnet_id = tenant.subnet.id
431 self.assertIn((subnet_id, server_ip, mac_addr), port_detail_list)
432
Masayuki Igawa4ded9f02014-02-17 15:05:59 +0900433 @test.attr(type='smoke')
434 @test.services('compute', 'network')
Yair Fried4d7efa62013-11-17 17:12:29 +0200435 def test_cross_tenant_traffic(self):
Nachi Ueno26b4c972014-01-17 06:15:13 -0800436 try:
Yair Friedbf2e2c42014-01-28 12:06:38 +0200437 # deploy new tenant
438 self._deploy_tenant(self.alt_tenant)
439 self._verify_network_details(self.alt_tenant)
440 self._verify_mac_addr(self.alt_tenant)
Yair Fried4d7efa62013-11-17 17:12:29 +0200441
Nachi Ueno26b4c972014-01-17 06:15:13 -0800442 # cross tenant check
Yair Friedbf2e2c42014-01-28 12:06:38 +0200443 source_tenant = self.primary_tenant
Nachi Ueno26b4c972014-01-17 06:15:13 -0800444 dest_tenant = self.alt_tenant
445 self._test_cross_tenant_block(source_tenant, dest_tenant)
446 self._test_cross_tenant_allow(source_tenant, dest_tenant)
447 except Exception:
Yair Friedbf2e2c42014-01-28 12:06:38 +0200448 for tenant in self.tenants.values():
449 self._log_console_output(servers=tenant.servers)
450 raise
451
Masayuki Igawa4ded9f02014-02-17 15:05:59 +0900452 @test.attr(type='smoke')
453 @test.services('compute', 'network')
Yair Friedbf2e2c42014-01-28 12:06:38 +0200454 def test_in_tenant_traffic(self):
455 try:
456 self._create_tenant_servers(self.primary_tenant, num=1)
457
458 # in-tenant check
459 self._test_in_tenant_block(self.primary_tenant)
460 self._test_in_tenant_allow(self.primary_tenant)
461
462 except Exception:
463 for tenant in self.tenants.values():
464 self._log_console_output(servers=tenant.servers)
Nachi Ueno26b4c972014-01-17 06:15:13 -0800465 raise