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