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