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