Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 1 | # 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. |
Yair Fried | ca5cfb5 | 2016-01-04 15:41:55 +0200 | [diff] [blame] | 15 | from oslo_log import log |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 16 | |
Andrea Frittoli | f9cde7e | 2014-02-18 09:57:04 +0000 | [diff] [blame] | 17 | from tempest import clients |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 18 | from tempest.common.utils import data_utils |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 19 | from tempest import config |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 20 | from tempest.scenario import manager |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 21 | from tempest import test |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 22 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 23 | CONF = config.CONF |
Yair Fried | ca5cfb5 | 2016-01-04 15:41:55 +0200 | [diff] [blame] | 24 | LOG = log.getLogger(__name__) |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 25 | |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 26 | |
Andrea Frittoli | 4971fc8 | 2014-09-25 10:22:20 +0100 | [diff] [blame] | 27 | class TestSecurityGroupsBasicOps(manager.NetworkScenarioTest): |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 28 | |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 29 | """The test suite for security groups |
| 30 | |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 31 | This test suite assumes that Nova has been configured to |
| 32 | boot VM's with Neutron-managed networking, and attempts to |
| 33 | verify cross tenant connectivity as follows |
| 34 | |
| 35 | ssh: |
| 36 | in order to overcome "ip namespace", each tenant has an "access point" |
| 37 | VM with floating-ip open to incoming ssh connection allowing network |
| 38 | commands (ping/ssh) to be executed from within the |
| 39 | tenant-network-namespace |
| 40 | Tempest host performs key-based authentication to the ssh server via |
| 41 | floating IP address |
| 42 | |
| 43 | connectivity test is done by pinging destination server via source server |
| 44 | ssh connection. |
| 45 | success - ping returns |
| 46 | failure - ping_timeout reached |
| 47 | |
Eran Kuris | b5f6978 | 2016-04-10 11:48:28 +0300 | [diff] [blame] | 48 | multi-node: |
| 49 | Multi-Node mode is enabled when CONF.compute.min_compute_nodes > 1. |
| 50 | Tests connectivity between servers on different compute nodes. |
| 51 | When enabled, test will boot each new server to different |
| 52 | compute nodes. |
| 53 | |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 54 | setup: |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 55 | for primary tenant: |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 56 | 1. create a network&subnet |
| 57 | 2. create a router (if public router isn't configured) |
| 58 | 3. connect tenant network to public network via router |
| 59 | 4. create an access point: |
| 60 | a. a security group open to incoming ssh connection |
| 61 | b. a VM with a floating ip |
| 62 | 5. create a general empty security group (same as "default", but |
| 63 | without rules allowing in-tenant traffic) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 64 | |
| 65 | tests: |
| 66 | 1. _verify_network_details |
| 67 | 2. _verify_mac_addr: for each access point verify that |
| 68 | (subnet, fix_ip, mac address) are as defined in the port list |
| 69 | 3. _test_in_tenant_block: test that in-tenant traffic is disabled |
| 70 | without rules allowing it |
| 71 | 4. _test_in_tenant_allow: test that in-tenant traffic is enabled |
| 72 | once an appropriate rule has been created |
| 73 | 5. _test_cross_tenant_block: test that cross-tenant traffic is disabled |
| 74 | without a rule allowing it on destination tenant |
| 75 | 6. _test_cross_tenant_allow: |
| 76 | * test that cross-tenant traffic is enabled once an appropriate |
| 77 | rule has been created on destination tenant. |
| 78 | * test that reverse traffic is still blocked |
Fei Long Wang | 50131ee | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 79 | * test than reverse traffic is enabled once an appropriate rule has |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 80 | been created on source tenant |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 81 | 7._test_port_update_new_security_group: |
| 82 | * test that traffic is blocked with default security group |
| 83 | * test that traffic is enabled after updating port with new security |
| 84 | group having appropriate rule |
prdsilva | 8b733ad | 2014-12-09 02:54:49 -0800 | [diff] [blame] | 85 | 8. _test_multiple_security_groups: test multiple security groups can be |
| 86 | associated with the vm |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 87 | |
| 88 | assumptions: |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 89 | 1. alt_tenant/user existed and is different from primary_tenant/user |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 90 | 2. Public network is defined and reachable from the Tempest host |
| 91 | 3. Public router can either be: |
| 92 | * defined, in which case all tenants networks can connect directly |
| 93 | to it, and cross tenant check will be done on the private IP of the |
| 94 | destination tenant |
| 95 | or |
Fei Long Wang | 50131ee | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 96 | * not defined (empty string), in which case each tenant will have |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 97 | its own router connected to the public network |
| 98 | """ |
| 99 | |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 100 | credentials = ['primary', 'alt', 'admin'] |
| 101 | |
Joe Gordon | 28788b4 | 2015-02-25 12:42:37 -0800 | [diff] [blame] | 102 | class TenantProperties(object): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 103 | """helper class to save tenant details |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 104 | |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 105 | id |
| 106 | credentials |
| 107 | network |
| 108 | subnet |
| 109 | security groups |
| 110 | servers |
| 111 | access point |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 112 | """ |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 113 | |
Andrea Frittoli | 422fbdf | 2014-03-20 10:05:18 +0000 | [diff] [blame] | 114 | def __init__(self, credentials): |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 115 | self.manager = clients.Manager(credentials) |
Andrea Frittoli | 422fbdf | 2014-03-20 10:05:18 +0000 | [diff] [blame] | 116 | # Credentials from manager are filled with both names and IDs |
| 117 | self.creds = self.manager.credentials |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 118 | self.network = None |
| 119 | self.subnet = None |
| 120 | self.router = None |
| 121 | self.security_groups = {} |
| 122 | self.servers = list() |
| 123 | |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 124 | def set_network(self, network, subnet, router): |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 125 | self.network = network |
| 126 | self.subnet = subnet |
| 127 | self.router = router |
| 128 | |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 129 | @classmethod |
Emily Hugenbruch | 5e2d2a2 | 2015-02-25 21:35:45 +0000 | [diff] [blame] | 130 | def skip_checks(cls): |
| 131 | super(TestSecurityGroupsBasicOps, cls).skip_checks() |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 132 | if CONF.baremetal.driver_enabled: |
| 133 | msg = ('Not currently supported by baremetal.') |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 134 | raise cls.skipException(msg) |
Itzik Brown | 0695267 | 2015-03-29 12:38:58 +0300 | [diff] [blame] | 135 | if CONF.network.port_vnic_type in ['direct', 'macvtap']: |
| 136 | msg = ('Not currently supported when using vnic_type' |
| 137 | ' direct or macvtap') |
| 138 | raise cls.skipException(msg) |
Sean Dague | ed6e586 | 2016-04-04 10:49:13 -0400 | [diff] [blame] | 139 | if not (CONF.network.project_networks_reachable or |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 140 | CONF.network.public_network_id): |
Sean Dague | ed6e586 | 2016-04-04 10:49:13 -0400 | [diff] [blame] | 141 | msg = ('Either project_networks_reachable must be "true", or ' |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 142 | 'public_network_id must be defined.') |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 143 | raise cls.skipException(msg) |
Bence Romsics | 41f3f85 | 2016-01-11 13:48:23 +0100 | [diff] [blame] | 144 | if not test.is_extension_enabled('security-group', 'network'): |
| 145 | msg = "security-group extension not enabled." |
| 146 | raise cls.skipException(msg) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 147 | |
| 148 | @classmethod |
Emily Hugenbruch | 5e2d2a2 | 2015-02-25 21:35:45 +0000 | [diff] [blame] | 149 | def setup_credentials(cls): |
Yair Fried | 764610a | 2014-04-07 12:17:05 +0300 | [diff] [blame] | 150 | # Create no network resources for these tests. |
| 151 | cls.set_network_resources() |
Emily Hugenbruch | 5e2d2a2 | 2015-02-25 21:35:45 +0000 | [diff] [blame] | 152 | super(TestSecurityGroupsBasicOps, cls).setup_credentials() |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 153 | # TODO(mnewby) Consider looking up entities as needed instead |
| 154 | # of storing them as collections on the class. |
Yair Fried | 79b0a91 | 2014-10-20 11:15:37 +0300 | [diff] [blame] | 155 | |
Yair Fried | 79b0a91 | 2014-10-20 11:15:37 +0300 | [diff] [blame] | 156 | # Credentials from the manager are filled with both IDs and Names |
| 157 | cls.alt_creds = cls.alt_manager.credentials |
| 158 | |
Emily Hugenbruch | 5e2d2a2 | 2015-02-25 21:35:45 +0000 | [diff] [blame] | 159 | @classmethod |
| 160 | def resource_setup(cls): |
| 161 | super(TestSecurityGroupsBasicOps, cls).resource_setup() |
Yair Fried | ca5cfb5 | 2016-01-04 15:41:55 +0200 | [diff] [blame] | 162 | |
| 163 | cls.multi_node = CONF.compute.min_compute_nodes > 1 and \ |
Yair Fried | 9591412 | 2016-03-03 09:14:40 +0200 | [diff] [blame] | 164 | test.is_scheduler_filter_enabled("DifferentHostFilter") |
Yair Fried | ca5cfb5 | 2016-01-04 15:41:55 +0200 | [diff] [blame] | 165 | if cls.multi_node: |
| 166 | LOG.info("Working in Multi Node mode") |
| 167 | else: |
| 168 | LOG.info("Working in Single Node mode") |
| 169 | |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 170 | cls.floating_ips = {} |
| 171 | cls.tenants = {} |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 172 | creds = cls.manager.credentials |
Andrea Frittoli | 422fbdf | 2014-03-20 10:05:18 +0000 | [diff] [blame] | 173 | cls.primary_tenant = cls.TenantProperties(creds) |
| 174 | cls.alt_tenant = cls.TenantProperties(cls.alt_creds) |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 175 | for tenant in [cls.primary_tenant, cls.alt_tenant]: |
Andrea Frittoli | 86ad28d | 2014-03-20 10:09:12 +0000 | [diff] [blame] | 176 | cls.tenants[tenant.creds.tenant_id] = tenant |
Emily Hugenbruch | 5e2d2a2 | 2015-02-25 21:35:45 +0000 | [diff] [blame] | 177 | |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 178 | cls.floating_ip_access = not CONF.network.public_router_id |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 179 | |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 180 | def setUp(self): |
Yair Fried | ca5cfb5 | 2016-01-04 15:41:55 +0200 | [diff] [blame] | 181 | """Set up a single tenant with an accessible server. |
| 182 | |
| 183 | If multi-host is enabled, save created server uuids. |
| 184 | """ |
| 185 | self.servers = [] |
| 186 | |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 187 | super(TestSecurityGroupsBasicOps, self).setUp() |
| 188 | self._deploy_tenant(self.primary_tenant) |
| 189 | self._verify_network_details(self.primary_tenant) |
| 190 | self._verify_mac_addr(self.primary_tenant) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 191 | |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 192 | def _create_tenant_keypairs(self, tenant): |
| 193 | keypair = self.create_keypair(tenant.manager.keypairs_client) |
| 194 | tenant.keypair = keypair |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 195 | |
| 196 | def _create_tenant_security_groups(self, tenant): |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 197 | access_sg = self._create_empty_security_group( |
| 198 | namestart='secgroup_access-', |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 199 | tenant_id=tenant.creds.tenant_id, |
John Warren | f9606e9 | 2015-12-10 12:12:42 -0500 | [diff] [blame] | 200 | client=tenant.manager.security_groups_client |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 201 | ) |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 202 | |
Sean Dague | ed6e586 | 2016-04-04 10:49:13 -0400 | [diff] [blame] | 203 | # don't use default secgroup since it allows in-project traffic |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 204 | def_sg = self._create_empty_security_group( |
| 205 | namestart='secgroup_general-', |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 206 | tenant_id=tenant.creds.tenant_id, |
John Warren | f9606e9 | 2015-12-10 12:12:42 -0500 | [diff] [blame] | 207 | client=tenant.manager.security_groups_client |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 208 | ) |
| 209 | tenant.security_groups.update(access=access_sg, default=def_sg) |
| 210 | ssh_rule = dict( |
| 211 | protocol='tcp', |
| 212 | port_range_min=22, |
| 213 | port_range_max=22, |
| 214 | direction='ingress', |
| 215 | ) |
John Warren | 456d9ae | 2016-01-12 15:36:33 -0500 | [diff] [blame] | 216 | sec_group_rules_client = tenant.manager.security_group_rules_client |
| 217 | self._create_security_group_rule( |
| 218 | secgroup=access_sg, |
| 219 | sec_group_rules_client=sec_group_rules_client, |
| 220 | **ssh_rule) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 221 | |
| 222 | def _verify_network_details(self, tenant): |
| 223 | # Checks that we see the newly created network/subnet/router via |
| 224 | # checking the result of list_[networks,routers,subnets] |
| 225 | # Check that (router, subnet) couple exist in port_list |
| 226 | seen_nets = self._list_networks() |
| 227 | seen_names = [n['name'] for n in seen_nets] |
| 228 | seen_ids = [n['id'] for n in seen_nets] |
| 229 | |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 230 | self.assertIn(tenant.network['name'], seen_names) |
| 231 | self.assertIn(tenant.network['id'], seen_ids) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 232 | |
| 233 | seen_subnets = [(n['id'], n['cidr'], n['network_id']) |
| 234 | for n in self._list_subnets()] |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 235 | mysubnet = (tenant.subnet['id'], tenant.subnet['cidr'], |
| 236 | tenant.network['id']) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 237 | self.assertIn(mysubnet, seen_subnets) |
| 238 | |
| 239 | seen_routers = self._list_routers() |
| 240 | seen_router_ids = [n['id'] for n in seen_routers] |
| 241 | seen_router_names = [n['name'] for n in seen_routers] |
| 242 | |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 243 | self.assertIn(tenant.router['name'], seen_router_names) |
| 244 | self.assertIn(tenant.router['id'], seen_router_ids) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 245 | |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 246 | myport = (tenant.router['id'], tenant.subnet['id']) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 247 | router_ports = [(i['device_id'], i['fixed_ips'][0]['subnet_id']) for i |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 248 | in self._list_ports() |
armando-migliaccio | bcfbbeb | 2014-08-11 18:33:47 -0700 | [diff] [blame] | 249 | if self._is_router_port(i)] |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 250 | |
| 251 | self.assertIn(myport, router_ports) |
| 252 | |
armando-migliaccio | bcfbbeb | 2014-08-11 18:33:47 -0700 | [diff] [blame] | 253 | def _is_router_port(self, port): |
| 254 | """Return True if port is a router interface.""" |
| 255 | # NOTE(armando-migliaccio): match device owner for both centralized |
| 256 | # and distributed routers; 'device_owner' is "" by default. |
| 257 | return port['device_owner'].startswith('network:router_interface') |
| 258 | |
Yair Fried | ca5cfb5 | 2016-01-04 15:41:55 +0200 | [diff] [blame] | 259 | def _create_server(self, name, tenant, security_groups=None, **kwargs): |
| 260 | """Creates a server and assigns it to security group. |
| 261 | |
| 262 | If multi-host is enabled, Ensures servers are created on different |
| 263 | compute nodes, by storing created servers' ids and uses different_host |
| 264 | as scheduler_hints on creation. |
| 265 | Validates servers are created as requested, using admin client. |
| 266 | """ |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 267 | if security_groups is None: |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 268 | security_groups = [tenant.security_groups['default']] |
Ken'ichi Ohmichi | 1b3461e | 2014-12-02 03:41:07 +0000 | [diff] [blame] | 269 | security_groups_names = [{'name': s['name']} for s in security_groups] |
Yair Fried | ca5cfb5 | 2016-01-04 15:41:55 +0200 | [diff] [blame] | 270 | if self.multi_node: |
| 271 | kwargs["scheduler_hints"] = {'different_host': self.servers} |
Ken'ichi Ohmichi | f2d436e | 2015-09-03 01:13:16 +0000 | [diff] [blame] | 272 | server = self.create_server( |
| 273 | name=name, |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 274 | networks=[{'uuid': tenant.network["id"]}], |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 275 | key_name=tenant.keypair['name'], |
| 276 | security_groups=security_groups_names, |
| 277 | wait_until='ACTIVE', |
Yair Fried | ca5cfb5 | 2016-01-04 15:41:55 +0200 | [diff] [blame] | 278 | clients=tenant.manager, |
| 279 | **kwargs) |
Claudiu Belu | faa9891 | 2014-09-01 16:50:28 +0300 | [diff] [blame] | 280 | self.assertEqual( |
| 281 | sorted([s['name'] for s in security_groups]), |
| 282 | sorted([s['name'] for s in server['security_groups']])) |
Yair Fried | ca5cfb5 | 2016-01-04 15:41:55 +0200 | [diff] [blame] | 283 | |
| 284 | # Verify servers are on different compute nodes |
| 285 | if self.multi_node: |
| 286 | adm_get_server = self.admin_manager.servers_client.show_server |
| 287 | new_host = adm_get_server(server["id"])["server"][ |
| 288 | "OS-EXT-SRV-ATTR:host"] |
| 289 | host_list = [adm_get_server(s)["server"]["OS-EXT-SRV-ATTR:host"] |
| 290 | for s in self.servers] |
| 291 | self.assertNotIn(new_host, host_list, |
| 292 | message="Failed to boot servers on different " |
| 293 | "Compute nodes.") |
| 294 | |
| 295 | self.servers.append(server["id"]) |
| 296 | |
Claudiu Belu | faa9891 | 2014-09-01 16:50:28 +0300 | [diff] [blame] | 297 | return server |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 298 | |
| 299 | def _create_tenant_servers(self, tenant, num=1): |
| 300 | for i in range(num): |
Ken'ichi Ohmichi | 6ded8df | 2015-03-23 02:00:19 +0000 | [diff] [blame] | 301 | name = 'server-{tenant}-gen-{num}'.format( |
Andrea Frittoli | 86ad28d | 2014-03-20 10:09:12 +0000 | [diff] [blame] | 302 | tenant=tenant.creds.tenant_name, |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 303 | num=i |
| 304 | ) |
| 305 | name = data_utils.rand_name(name) |
| 306 | server = self._create_server(name, tenant) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 307 | tenant.servers.append(server) |
| 308 | |
| 309 | def _set_access_point(self, tenant): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 310 | # creates a server in a secgroup with rule allowing external ssh |
Sean Dague | ed6e586 | 2016-04-04 10:49:13 -0400 | [diff] [blame] | 311 | # in order to access project internal network |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 312 | # workaround ip namespace |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 313 | secgroups = tenant.security_groups.values() |
Ken'ichi Ohmichi | 6ded8df | 2015-03-23 02:00:19 +0000 | [diff] [blame] | 314 | name = 'server-{tenant}-access_point'.format( |
Andrea Frittoli | 86ad28d | 2014-03-20 10:09:12 +0000 | [diff] [blame] | 315 | tenant=tenant.creds.tenant_name) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 316 | name = data_utils.rand_name(name) |
| 317 | server = self._create_server(name, tenant, |
| 318 | security_groups=secgroups) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 319 | tenant.access_point = server |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 320 | self._assign_floating_ips(tenant, server) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 321 | |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 322 | def _assign_floating_ips(self, tenant, server): |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 323 | public_network_id = CONF.network.public_network_id |
Yair Fried | ae0e73d | 2014-11-24 11:56:26 +0200 | [diff] [blame] | 324 | floating_ip = self.create_floating_ip( |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 325 | server, public_network_id, |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 326 | client=tenant.manager.floating_ips_client) |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 327 | self.floating_ips.setdefault(server['id'], floating_ip) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 328 | |
| 329 | def _create_tenant_network(self, tenant): |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 330 | network, subnet, router = self.create_networks( |
John Warren | 3961acd | 2015-10-02 14:38:53 -0400 | [diff] [blame] | 331 | networks_client=tenant.manager.networks_client, |
Ken'ichi Ohmichi | e35f472 | 2015-12-22 04:57:11 +0000 | [diff] [blame] | 332 | routers_client=tenant.manager.routers_client, |
John Warren | 3961acd | 2015-10-02 14:38:53 -0400 | [diff] [blame] | 333 | subnets_client=tenant.manager.subnets_client) |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 334 | tenant.set_network(network, subnet, router) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 335 | |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 336 | def _deploy_tenant(self, tenant_or_id): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 337 | """creates: |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 338 | |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 339 | network |
| 340 | subnet |
| 341 | router (if public not defined) |
| 342 | access security group |
| 343 | access-point server |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 344 | """ |
| 345 | if not isinstance(tenant_or_id, self.TenantProperties): |
| 346 | tenant = self.tenants[tenant_or_id] |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 347 | else: |
| 348 | tenant = tenant_or_id |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 349 | self._create_tenant_keypairs(tenant) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 350 | self._create_tenant_network(tenant) |
| 351 | self._create_tenant_security_groups(tenant) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 352 | self._set_access_point(tenant) |
| 353 | |
| 354 | def _get_server_ip(self, server, floating=False): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 355 | """returns the ip (floating/internal) of a server""" |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 356 | if floating: |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 357 | server_ip = self.floating_ips[server['id']]['floating_ip_address'] |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 358 | else: |
armando-migliaccio | d03f264 | 2014-02-21 19:55:50 -0800 | [diff] [blame] | 359 | server_ip = None |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 360 | network_name = self.tenants[server['tenant_id']].network['name'] |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 361 | if network_name in server['addresses']: |
| 362 | server_ip = server['addresses'][network_name][0]['addr'] |
armando-migliaccio | d03f264 | 2014-02-21 19:55:50 -0800 | [diff] [blame] | 363 | return server_ip |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 364 | |
| 365 | def _connect_to_access_point(self, tenant): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 366 | """create ssh connection to tenant access point""" |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 367 | access_point_ssh = \ |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 368 | self.floating_ips[tenant.access_point['id']]['floating_ip_address'] |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 369 | private_key = tenant.keypair['private_key'] |
Jordan Pittier | bbb1712 | 2016-01-26 17:10:55 +0100 | [diff] [blame] | 370 | access_point_ssh = self.get_remote_client( |
| 371 | access_point_ssh, private_key=private_key) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 372 | return access_point_ssh |
| 373 | |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 374 | def _check_connectivity(self, access_point, ip, should_succeed=True): |
| 375 | if should_succeed: |
| 376 | msg = "Timed out waiting for %s to become reachable" % ip |
| 377 | else: |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 378 | msg = "%s is reachable" % ip |
Matthew Treinish | 5348313 | 2014-12-09 18:50:06 -0500 | [diff] [blame] | 379 | self.assertTrue(self._check_remote_connectivity(access_point, ip, |
| 380 | should_succeed), msg) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 381 | |
| 382 | def _test_in_tenant_block(self, tenant): |
| 383 | access_point_ssh = self._connect_to_access_point(tenant) |
| 384 | for server in tenant.servers: |
| 385 | self._check_connectivity(access_point=access_point_ssh, |
| 386 | ip=self._get_server_ip(server), |
| 387 | should_succeed=False) |
| 388 | |
| 389 | def _test_in_tenant_allow(self, tenant): |
| 390 | ruleset = dict( |
| 391 | protocol='icmp', |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 392 | remote_group_id=tenant.security_groups['default']['id'], |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 393 | direction='ingress' |
| 394 | ) |
Matthew Treinish | b7144eb | 2013-12-13 22:57:35 +0000 | [diff] [blame] | 395 | self._create_security_group_rule( |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 396 | secgroup=tenant.security_groups['default'], |
Yair Fried | ca5cfb5 | 2016-01-04 15:41:55 +0200 | [diff] [blame] | 397 | security_groups_client=tenant.manager.security_groups_client, |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 398 | **ruleset |
| 399 | ) |
| 400 | access_point_ssh = self._connect_to_access_point(tenant) |
| 401 | for server in tenant.servers: |
| 402 | self._check_connectivity(access_point=access_point_ssh, |
| 403 | ip=self._get_server_ip(server)) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 404 | |
| 405 | def _test_cross_tenant_block(self, source_tenant, dest_tenant): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 406 | # if public router isn't defined, then dest_tenant access is via |
| 407 | # floating-ip |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 408 | access_point_ssh = self._connect_to_access_point(source_tenant) |
| 409 | ip = self._get_server_ip(dest_tenant.access_point, |
| 410 | floating=self.floating_ip_access) |
| 411 | self._check_connectivity(access_point=access_point_ssh, ip=ip, |
| 412 | should_succeed=False) |
| 413 | |
| 414 | def _test_cross_tenant_allow(self, source_tenant, dest_tenant): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 415 | """check for each direction: |
| 416 | |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 417 | creating rule for tenant incoming traffic enables only 1way traffic |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 418 | """ |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 419 | ruleset = dict( |
| 420 | protocol='icmp', |
| 421 | direction='ingress' |
| 422 | ) |
John Warren | 456d9ae | 2016-01-12 15:36:33 -0500 | [diff] [blame] | 423 | sec_group_rules_client = ( |
| 424 | dest_tenant.manager.security_group_rules_client) |
Matthew Treinish | b7144eb | 2013-12-13 22:57:35 +0000 | [diff] [blame] | 425 | self._create_security_group_rule( |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 426 | secgroup=dest_tenant.security_groups['default'], |
John Warren | 456d9ae | 2016-01-12 15:36:33 -0500 | [diff] [blame] | 427 | sec_group_rules_client=sec_group_rules_client, |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 428 | **ruleset |
| 429 | ) |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 430 | access_point_ssh = self._connect_to_access_point(source_tenant) |
| 431 | ip = self._get_server_ip(dest_tenant.access_point, |
| 432 | floating=self.floating_ip_access) |
| 433 | self._check_connectivity(access_point_ssh, ip) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 434 | |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 435 | # test that reverse traffic is still blocked |
| 436 | self._test_cross_tenant_block(dest_tenant, source_tenant) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 437 | |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 438 | # allow reverse traffic and check |
John Warren | 456d9ae | 2016-01-12 15:36:33 -0500 | [diff] [blame] | 439 | sec_group_rules_client = ( |
| 440 | source_tenant.manager.security_group_rules_client) |
Matthew Treinish | b7144eb | 2013-12-13 22:57:35 +0000 | [diff] [blame] | 441 | self._create_security_group_rule( |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 442 | secgroup=source_tenant.security_groups['default'], |
John Warren | 456d9ae | 2016-01-12 15:36:33 -0500 | [diff] [blame] | 443 | sec_group_rules_client=sec_group_rules_client, |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 444 | **ruleset |
| 445 | ) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 446 | |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 447 | access_point_ssh_2 = self._connect_to_access_point(dest_tenant) |
| 448 | ip = self._get_server_ip(source_tenant.access_point, |
| 449 | floating=self.floating_ip_access) |
| 450 | self._check_connectivity(access_point_ssh_2, ip) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 451 | |
| 452 | def _verify_mac_addr(self, tenant): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 453 | """Verify that VM has the same ip, mac as listed in port""" |
| 454 | |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 455 | access_point_ssh = self._connect_to_access_point(tenant) |
| 456 | mac_addr = access_point_ssh.get_mac_address() |
| 457 | mac_addr = mac_addr.strip().lower() |
Henry Gessau | 78ab4b0 | 2014-03-31 15:10:13 -0400 | [diff] [blame] | 458 | # Get the fixed_ips and mac_address fields of all ports. Select |
| 459 | # only those two columns to reduce the size of the response. |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 460 | port_list = self._list_ports(fields=['fixed_ips', 'mac_address']) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 461 | port_detail_list = [ |
| 462 | (port['fixed_ips'][0]['subnet_id'], |
| 463 | port['fixed_ips'][0]['ip_address'], |
Henry Gessau | 78ab4b0 | 2014-03-31 15:10:13 -0400 | [diff] [blame] | 464 | port['mac_address'].lower()) |
| 465 | for port in port_list if port['fixed_ips'] |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 466 | ] |
| 467 | server_ip = self._get_server_ip(tenant.access_point) |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 468 | subnet_id = tenant.subnet['id'] |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 469 | self.assertIn((subnet_id, server_ip, mac_addr), port_detail_list) |
| 470 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 471 | @test.idempotent_id('e79f879e-debb-440c-a7e4-efeda05b6848') |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 472 | @test.services('compute', 'network') |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 473 | def test_cross_tenant_traffic(self): |
Andrea Frittoli (andreaf) | 1f34241 | 2015-05-12 16:37:19 +0100 | [diff] [blame] | 474 | if not self.credentials_provider.is_multi_tenant(): |
Yair Fried | 79b0a91 | 2014-10-20 11:15:37 +0300 | [diff] [blame] | 475 | raise self.skipException("No secondary tenant defined") |
Nachi Ueno | 26b4c97 | 2014-01-17 06:15:13 -0800 | [diff] [blame] | 476 | try: |
Sean Dague | ed6e586 | 2016-04-04 10:49:13 -0400 | [diff] [blame] | 477 | # deploy new project |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 478 | self._deploy_tenant(self.alt_tenant) |
| 479 | self._verify_network_details(self.alt_tenant) |
| 480 | self._verify_mac_addr(self.alt_tenant) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 481 | |
Nachi Ueno | 26b4c97 | 2014-01-17 06:15:13 -0800 | [diff] [blame] | 482 | # cross tenant check |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 483 | source_tenant = self.primary_tenant |
Nachi Ueno | 26b4c97 | 2014-01-17 06:15:13 -0800 | [diff] [blame] | 484 | dest_tenant = self.alt_tenant |
| 485 | self._test_cross_tenant_block(source_tenant, dest_tenant) |
| 486 | self._test_cross_tenant_allow(source_tenant, dest_tenant) |
| 487 | except Exception: |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 488 | for tenant in self.tenants.values(): |
| 489 | self._log_console_output(servers=tenant.servers) |
| 490 | raise |
| 491 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 492 | @test.idempotent_id('63163892-bbf6-4249-aa12-d5ea1f8f421b') |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 493 | @test.services('compute', 'network') |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 494 | def test_in_tenant_traffic(self): |
| 495 | try: |
| 496 | self._create_tenant_servers(self.primary_tenant, num=1) |
| 497 | |
| 498 | # in-tenant check |
| 499 | self._test_in_tenant_block(self.primary_tenant) |
| 500 | self._test_in_tenant_allow(self.primary_tenant) |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 501 | except Exception: |
| 502 | for tenant in self.tenants.values(): |
| 503 | self._log_console_output(servers=tenant.servers) |
| 504 | raise |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 505 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 506 | @test.idempotent_id('f4d556d7-1526-42ad-bafb-6bebf48568f6') |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 507 | @test.services('compute', 'network') |
| 508 | def test_port_update_new_security_group(self): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 509 | """Verifies the traffic after updating the vm port |
| 510 | |
| 511 | With new security group having appropriate rule. |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 512 | """ |
| 513 | new_tenant = self.primary_tenant |
| 514 | |
| 515 | # Create empty security group and add icmp rule in it |
| 516 | new_sg = self._create_empty_security_group( |
| 517 | namestart='secgroup_new-', |
| 518 | tenant_id=new_tenant.creds.tenant_id, |
John Warren | f9606e9 | 2015-12-10 12:12:42 -0500 | [diff] [blame] | 519 | client=new_tenant.manager.security_groups_client) |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 520 | icmp_rule = dict( |
| 521 | protocol='icmp', |
| 522 | direction='ingress', |
| 523 | ) |
John Warren | 456d9ae | 2016-01-12 15:36:33 -0500 | [diff] [blame] | 524 | sec_group_rules_client = new_tenant.manager.security_group_rules_client |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 525 | self._create_security_group_rule( |
| 526 | secgroup=new_sg, |
John Warren | 456d9ae | 2016-01-12 15:36:33 -0500 | [diff] [blame] | 527 | sec_group_rules_client=sec_group_rules_client, |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 528 | **icmp_rule) |
| 529 | new_tenant.security_groups.update(new_sg=new_sg) |
| 530 | |
| 531 | # Create server with default security group |
Ken'ichi Ohmichi | 6ded8df | 2015-03-23 02:00:19 +0000 | [diff] [blame] | 532 | name = 'server-{tenant}-gen-1'.format( |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 533 | tenant=new_tenant.creds.tenant_name |
| 534 | ) |
| 535 | name = data_utils.rand_name(name) |
| 536 | server = self._create_server(name, new_tenant) |
| 537 | |
| 538 | # Check connectivity failure with default security group |
| 539 | try: |
| 540 | access_point_ssh = self._connect_to_access_point(new_tenant) |
| 541 | self._check_connectivity(access_point=access_point_ssh, |
| 542 | ip=self._get_server_ip(server), |
| 543 | should_succeed=False) |
| 544 | server_id = server['id'] |
| 545 | port_id = self._list_ports(device_id=server_id)[0]['id'] |
| 546 | |
| 547 | # update port with new security group and check connectivity |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 548 | self.ports_client.update_port(port_id, security_groups=[ |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 549 | new_tenant.security_groups['new_sg']['id']]) |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 550 | self._check_connectivity( |
| 551 | access_point=access_point_ssh, |
| 552 | ip=self._get_server_ip(server)) |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 553 | except Exception: |
| 554 | for tenant in self.tenants.values(): |
| 555 | self._log_console_output(servers=tenant.servers) |
Nachi Ueno | 26b4c97 | 2014-01-17 06:15:13 -0800 | [diff] [blame] | 556 | raise |
prdsilva | 8b733ad | 2014-12-09 02:54:49 -0800 | [diff] [blame] | 557 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 558 | @test.idempotent_id('d2f77418-fcc4-439d-b935-72eca704e293') |
prdsilva | 8b733ad | 2014-12-09 02:54:49 -0800 | [diff] [blame] | 559 | @test.services('compute', 'network') |
| 560 | def test_multiple_security_groups(self): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 561 | """Verify multiple security groups and checks that rules |
| 562 | |
prdsilva | 8b733ad | 2014-12-09 02:54:49 -0800 | [diff] [blame] | 563 | provided in the both the groups is applied onto VM |
| 564 | """ |
| 565 | tenant = self.primary_tenant |
| 566 | ip = self._get_server_ip(tenant.access_point, |
| 567 | floating=self.floating_ip_access) |
lanoux | 283273b | 2015-12-04 03:01:54 -0800 | [diff] [blame] | 568 | ssh_login = CONF.validation.image_ssh_user |
prdsilva | 8b733ad | 2014-12-09 02:54:49 -0800 | [diff] [blame] | 569 | private_key = tenant.keypair['private_key'] |
| 570 | self.check_vm_connectivity(ip, |
| 571 | should_connect=False) |
| 572 | ruleset = dict( |
| 573 | protocol='icmp', |
| 574 | direction='ingress' |
| 575 | ) |
| 576 | self._create_security_group_rule( |
| 577 | secgroup=tenant.security_groups['default'], |
| 578 | **ruleset |
| 579 | ) |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 580 | # NOTE: Vm now has 2 security groups one with ssh rule( |
| 581 | # already added in setUp() method),and other with icmp rule |
| 582 | # (added in the above step).The check_vm_connectivity tests |
| 583 | # -that vm ping test is successful |
| 584 | # -ssh to vm is successful |
prdsilva | 8b733ad | 2014-12-09 02:54:49 -0800 | [diff] [blame] | 585 | self.check_vm_connectivity(ip, |
| 586 | username=ssh_login, |
| 587 | private_key=private_key, |
| 588 | should_connect=True) |
YAMAMOTO Takashi | 51e0408 | 2015-09-08 18:44:23 +0900 | [diff] [blame] | 589 | |
| 590 | @test.requires_ext(service='network', extension='port-security') |
| 591 | @test.idempotent_id('7c811dcc-263b-49a3-92d2-1b4d8405f50c') |
| 592 | @test.services('compute', 'network') |
| 593 | def test_port_security_disable_security_group(self): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 594 | """Verify the default security group rules is disabled.""" |
YAMAMOTO Takashi | 51e0408 | 2015-09-08 18:44:23 +0900 | [diff] [blame] | 595 | new_tenant = self.primary_tenant |
| 596 | |
| 597 | # Create server |
| 598 | name = 'server-{tenant}-gen-1'.format( |
| 599 | tenant=new_tenant.creds.tenant_name |
| 600 | ) |
| 601 | name = data_utils.rand_name(name) |
| 602 | server = self._create_server(name, new_tenant) |
| 603 | |
| 604 | access_point_ssh = self._connect_to_access_point(new_tenant) |
| 605 | server_id = server['id'] |
| 606 | port_id = self._list_ports(device_id=server_id)[0]['id'] |
| 607 | |
| 608 | # Flip the port's port security and check connectivity |
| 609 | try: |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 610 | self.ports_client.update_port(port_id, |
| 611 | port_security_enabled=True, |
| 612 | security_groups=[]) |
YAMAMOTO Takashi | 51e0408 | 2015-09-08 18:44:23 +0900 | [diff] [blame] | 613 | self._check_connectivity(access_point=access_point_ssh, |
| 614 | ip=self._get_server_ip(server), |
| 615 | should_succeed=False) |
| 616 | |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 617 | self.ports_client.update_port(port_id, |
| 618 | port_security_enabled=False, |
| 619 | security_groups=[]) |
YAMAMOTO Takashi | 51e0408 | 2015-09-08 18:44:23 +0900 | [diff] [blame] | 620 | self._check_connectivity( |
| 621 | access_point=access_point_ssh, |
| 622 | ip=self._get_server_ip(server)) |
| 623 | except Exception: |
| 624 | for tenant in self.tenants.values(): |
| 625 | self._log_console_output(servers=tenant.servers) |
| 626 | raise |