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): |
Soniya Vyas | 0860209 | 2021-03-04 18:52:59 +0530 | [diff] [blame] | 200 | access_sg = self.create_empty_security_group( |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 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 |
Soniya Vyas | 0860209 | 2021-03-04 18:52:59 +0530 | [diff] [blame] | 207 | def_sg = self.create_empty_security_group( |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 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 |
Soniya Vyas | 945f5a1 | 2021-02-02 23:49:12 +0530 | [diff] [blame] | 220 | self.create_security_group_rule( |
John Warren | 456d9ae | 2016-01-12 15:36:33 -0500 | [diff] [blame] | 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 | ) |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 303 | name = data_utils.rand_name( |
| 304 | prefix=CONF.resource_name_prefix, name=name) |
Markus Zoeller | 156b5da | 2016-07-11 18:10:31 +0200 | [diff] [blame] | 305 | server = self._create_server(name, tenant, |
| 306 | [tenant.security_groups['default']]) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 307 | tenant.servers.append(server) |
| 308 | |
| 309 | def _set_access_point(self, tenant): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 310 | # creates a server in a secgroup with rule allowing external ssh |
Sean Dague | ed6e586 | 2016-04-04 10:49:13 -0400 | [diff] [blame] | 311 | # in order to access project internal network |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 312 | # workaround ip namespace |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 313 | secgroups = tenant.security_groups.values() |
Ken'ichi Ohmichi | 6ded8df | 2015-03-23 02:00:19 +0000 | [diff] [blame] | 314 | name = 'server-{tenant}-access_point'.format( |
Andrea Frittoli | 86ad28d | 2014-03-20 10:09:12 +0000 | [diff] [blame] | 315 | tenant=tenant.creds.tenant_name) |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 316 | name = data_utils.rand_name( |
| 317 | prefix=CONF.resource_name_prefix, name=name) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 318 | server = self._create_server(name, tenant, |
| 319 | security_groups=secgroups) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 320 | tenant.access_point = server |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 321 | self._assign_floating_ips(tenant, server) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 322 | |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 323 | def _assign_floating_ips(self, tenant, server): |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 324 | public_network_id = CONF.network.public_network_id |
Yair Fried | ae0e73d | 2014-11-24 11:56:26 +0200 | [diff] [blame] | 325 | floating_ip = self.create_floating_ip( |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 326 | server, public_network_id, |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 327 | client=tenant.manager.floating_ips_client) |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 328 | self.floating_ips.setdefault(server['id'], floating_ip) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 329 | |
Markus Zoeller | 156b5da | 2016-07-11 18:10:31 +0200 | [diff] [blame] | 330 | def _create_tenant_network(self, tenant, port_security_enabled=True): |
Ghanshyam Mann | 071d154 | 2021-03-24 19:10:47 -0500 | [diff] [blame] | 331 | network, subnet, router = self.setup_network_subnet_with_router( |
John Warren | 3961acd | 2015-10-02 14:38:53 -0400 | [diff] [blame] | 332 | networks_client=tenant.manager.networks_client, |
Ken'ichi Ohmichi | e35f472 | 2015-12-22 04:57:11 +0000 | [diff] [blame] | 333 | routers_client=tenant.manager.routers_client, |
Markus Zoeller | 156b5da | 2016-07-11 18:10:31 +0200 | [diff] [blame] | 334 | subnets_client=tenant.manager.subnets_client, |
| 335 | port_security_enabled=port_security_enabled) |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 336 | tenant.set_network(network, subnet, router) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 337 | |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 338 | def _deploy_tenant(self, tenant_or_id): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 339 | """creates: |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 340 | |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 341 | network |
| 342 | subnet |
| 343 | router (if public not defined) |
| 344 | access security group |
| 345 | access-point server |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 346 | """ |
| 347 | if not isinstance(tenant_or_id, self.TenantProperties): |
| 348 | tenant = self.tenants[tenant_or_id] |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 349 | else: |
| 350 | tenant = tenant_or_id |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 351 | self._create_tenant_keypairs(tenant) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 352 | self._create_tenant_network(tenant) |
| 353 | self._create_tenant_security_groups(tenant) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 354 | self._set_access_point(tenant) |
| 355 | |
| 356 | def _get_server_ip(self, server, floating=False): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 357 | """returns the ip (floating/internal) of a server""" |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 358 | if floating: |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 359 | server_ip = self.floating_ips[server['id']]['floating_ip_address'] |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 360 | else: |
armando-migliaccio | d03f264 | 2014-02-21 19:55:50 -0800 | [diff] [blame] | 361 | server_ip = None |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 362 | network_name = self.tenants[server['tenant_id']].network['name'] |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 363 | if network_name in server['addresses']: |
| 364 | server_ip = server['addresses'][network_name][0]['addr'] |
armando-migliaccio | d03f264 | 2014-02-21 19:55:50 -0800 | [diff] [blame] | 365 | return server_ip |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 366 | |
| 367 | def _connect_to_access_point(self, tenant): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 368 | """create ssh connection to tenant access point""" |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 369 | access_point_ssh = \ |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 370 | self.floating_ips[tenant.access_point['id']]['floating_ip_address'] |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 371 | private_key = tenant.keypair['private_key'] |
Jordan Pittier | bbb1712 | 2016-01-26 17:10:55 +0100 | [diff] [blame] | 372 | access_point_ssh = self.get_remote_client( |
Slawek Kaplonski | ab7d790 | 2018-08-04 11:50:31 +0200 | [diff] [blame] | 373 | access_point_ssh, private_key=private_key, |
| 374 | server=tenant.access_point) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 375 | return access_point_ssh |
| 376 | |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 377 | def _test_in_tenant_block(self, tenant): |
| 378 | access_point_ssh = self._connect_to_access_point(tenant) |
| 379 | for server in tenant.servers: |
YAMAMOTO Takashi | 4c3ebb0 | 2017-01-25 16:04:30 +0900 | [diff] [blame] | 380 | self.check_remote_connectivity(source=access_point_ssh, |
| 381 | dest=self._get_server_ip(server), |
| 382 | should_succeed=False) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 383 | |
| 384 | def _test_in_tenant_allow(self, tenant): |
| 385 | ruleset = dict( |
| 386 | protocol='icmp', |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 387 | remote_group_id=tenant.security_groups['default']['id'], |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 388 | direction='ingress' |
| 389 | ) |
Soniya Vyas | 945f5a1 | 2021-02-02 23:49:12 +0530 | [diff] [blame] | 390 | self.create_security_group_rule( |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 391 | secgroup=tenant.security_groups['default'], |
Yair Fried | ca5cfb5 | 2016-01-04 15:41:55 +0200 | [diff] [blame] | 392 | security_groups_client=tenant.manager.security_groups_client, |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 393 | **ruleset |
| 394 | ) |
| 395 | access_point_ssh = self._connect_to_access_point(tenant) |
| 396 | for server in tenant.servers: |
YAMAMOTO Takashi | 4c3ebb0 | 2017-01-25 16:04:30 +0900 | [diff] [blame] | 397 | self.check_remote_connectivity(source=access_point_ssh, |
| 398 | dest=self._get_server_ip(server)) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 399 | |
Claudiu Belu | 33c3e60 | 2014-08-28 16:38:01 +0300 | [diff] [blame] | 400 | def _test_cross_tenant_block(self, source_tenant, dest_tenant, ruleset): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 401 | # if public router isn't defined, then dest_tenant access is via |
| 402 | # floating-ip |
Claudiu Belu | 33c3e60 | 2014-08-28 16:38:01 +0300 | [diff] [blame] | 403 | protocol = ruleset['protocol'] |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 404 | access_point_ssh = self._connect_to_access_point(source_tenant) |
| 405 | ip = self._get_server_ip(dest_tenant.access_point, |
| 406 | floating=self.floating_ip_access) |
YAMAMOTO Takashi | 4c3ebb0 | 2017-01-25 16:04:30 +0900 | [diff] [blame] | 407 | self.check_remote_connectivity(source=access_point_ssh, dest=ip, |
Claudiu Belu | 33c3e60 | 2014-08-28 16:38:01 +0300 | [diff] [blame] | 408 | should_succeed=False, protocol=protocol) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 409 | |
Claudiu Belu | 33c3e60 | 2014-08-28 16:38:01 +0300 | [diff] [blame] | 410 | def _test_cross_tenant_allow(self, source_tenant, dest_tenant, ruleset): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 411 | """check for each direction: |
| 412 | |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 413 | creating rule for tenant incoming traffic enables only 1way traffic |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 414 | """ |
Claudiu Belu | 33c3e60 | 2014-08-28 16:38:01 +0300 | [diff] [blame] | 415 | protocol = ruleset['protocol'] |
John Warren | 456d9ae | 2016-01-12 15:36:33 -0500 | [diff] [blame] | 416 | sec_group_rules_client = ( |
| 417 | dest_tenant.manager.security_group_rules_client) |
Soniya Vyas | 945f5a1 | 2021-02-02 23:49:12 +0530 | [diff] [blame] | 418 | self.create_security_group_rule( |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 419 | secgroup=dest_tenant.security_groups['default'], |
John Warren | 456d9ae | 2016-01-12 15:36:33 -0500 | [diff] [blame] | 420 | sec_group_rules_client=sec_group_rules_client, |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 421 | **ruleset |
| 422 | ) |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 423 | access_point_ssh = self._connect_to_access_point(source_tenant) |
| 424 | ip = self._get_server_ip(dest_tenant.access_point, |
| 425 | floating=self.floating_ip_access) |
Claudiu Belu | 33c3e60 | 2014-08-28 16:38:01 +0300 | [diff] [blame] | 426 | self.check_remote_connectivity(access_point_ssh, ip, protocol=protocol) |
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 | # test that reverse traffic is still blocked |
Claudiu Belu | 33c3e60 | 2014-08-28 16:38:01 +0300 | [diff] [blame] | 429 | self._test_cross_tenant_block(dest_tenant, source_tenant, ruleset) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 430 | |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 431 | # allow reverse traffic and check |
John Warren | 456d9ae | 2016-01-12 15:36:33 -0500 | [diff] [blame] | 432 | sec_group_rules_client = ( |
| 433 | source_tenant.manager.security_group_rules_client) |
Soniya Vyas | 945f5a1 | 2021-02-02 23:49:12 +0530 | [diff] [blame] | 434 | self.create_security_group_rule( |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 435 | secgroup=source_tenant.security_groups['default'], |
John Warren | 456d9ae | 2016-01-12 15:36:33 -0500 | [diff] [blame] | 436 | sec_group_rules_client=sec_group_rules_client, |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 437 | **ruleset |
| 438 | ) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 439 | |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 440 | access_point_ssh_2 = self._connect_to_access_point(dest_tenant) |
| 441 | ip = self._get_server_ip(source_tenant.access_point, |
| 442 | floating=self.floating_ip_access) |
Claudiu Belu | 33c3e60 | 2014-08-28 16:38:01 +0300 | [diff] [blame] | 443 | self.check_remote_connectivity(access_point_ssh_2, ip, |
| 444 | protocol=protocol) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 445 | |
| 446 | def _verify_mac_addr(self, tenant): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 447 | """Verify that VM has the same ip, mac as listed in port""" |
| 448 | |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 449 | access_point_ssh = self._connect_to_access_point(tenant) |
| 450 | mac_addr = access_point_ssh.get_mac_address() |
| 451 | mac_addr = mac_addr.strip().lower() |
Henry Gessau | 78ab4b0 | 2014-03-31 15:10:13 -0400 | [diff] [blame] | 452 | # Get the fixed_ips and mac_address fields of all ports. Select |
| 453 | # only those two columns to reduce the size of the response. |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 454 | port_list = self.os_admin.ports_client.list_ports( |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 455 | fields=['fixed_ips', 'mac_address'])['ports'] |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 456 | port_detail_list = [ |
| 457 | (port['fixed_ips'][0]['subnet_id'], |
| 458 | port['fixed_ips'][0]['ip_address'], |
Henry Gessau | 78ab4b0 | 2014-03-31 15:10:13 -0400 | [diff] [blame] | 459 | port['mac_address'].lower()) |
| 460 | for port in port_list if port['fixed_ips'] |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 461 | ] |
| 462 | server_ip = self._get_server_ip(tenant.access_point) |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 463 | subnet_id = tenant.subnet['id'] |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 464 | self.assertIn((subnet_id, server_ip, mac_addr), port_detail_list) |
| 465 | |
Ihar Hrachyshka | a9dca2b | 2017-04-04 14:17:11 -0700 | [diff] [blame] | 466 | def _log_console_output_for_all_tenants(self): |
| 467 | for tenant in self.tenants.values(): |
| 468 | client = tenant.manager.servers_client |
Soniya Vyas | 1b0cddc | 2021-01-29 17:28:19 +0530 | [diff] [blame] | 469 | self.log_console_output(servers=tenant.servers, client=client) |
Ihar Hrachyshka | a9dca2b | 2017-04-04 14:17:11 -0700 | [diff] [blame] | 470 | if tenant.access_point is not None: |
Soniya Vyas | 1b0cddc | 2021-01-29 17:28:19 +0530 | [diff] [blame] | 471 | self.log_console_output( |
Ihar Hrachyshka | a9dca2b | 2017-04-04 14:17:11 -0700 | [diff] [blame] | 472 | servers=[tenant.access_point], client=client) |
| 473 | |
Claudiu Belu | 33c3e60 | 2014-08-28 16:38:01 +0300 | [diff] [blame] | 474 | def _create_protocol_ruleset(self, protocol, port=80): |
| 475 | if protocol == 'icmp': |
| 476 | ruleset = dict(protocol='icmp', |
| 477 | direction='ingress') |
| 478 | else: |
| 479 | ruleset = dict(protocol=protocol, |
| 480 | port_range_min=port, |
| 481 | port_range_max=port, |
| 482 | direction='ingress') |
| 483 | return ruleset |
| 484 | |
Ghanshyam Mann | e2183ca | 2023-02-10 19:31:52 -0600 | [diff] [blame] | 485 | @decorators.attr(type='multinode') |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 486 | @decorators.idempotent_id('e79f879e-debb-440c-a7e4-efeda05b6848') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 487 | @utils.services('compute', 'network') |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 488 | def test_cross_tenant_traffic(self): |
Andrea Frittoli (andreaf) | 1f34241 | 2015-05-12 16:37:19 +0100 | [diff] [blame] | 489 | if not self.credentials_provider.is_multi_tenant(): |
Yair Fried | 79b0a91 | 2014-10-20 11:15:37 +0300 | [diff] [blame] | 490 | raise self.skipException("No secondary tenant defined") |
Nachi Ueno | 26b4c97 | 2014-01-17 06:15:13 -0800 | [diff] [blame] | 491 | try: |
Sean Dague | ed6e586 | 2016-04-04 10:49:13 -0400 | [diff] [blame] | 492 | # deploy new project |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 493 | self._deploy_tenant(self.alt_tenant) |
| 494 | self._verify_network_details(self.alt_tenant) |
| 495 | self._verify_mac_addr(self.alt_tenant) |
Yair Fried | 4d7efa6 | 2013-11-17 17:12:29 +0200 | [diff] [blame] | 496 | |
Nachi Ueno | 26b4c97 | 2014-01-17 06:15:13 -0800 | [diff] [blame] | 497 | # cross tenant check |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 498 | source_tenant = self.primary_tenant |
Nachi Ueno | 26b4c97 | 2014-01-17 06:15:13 -0800 | [diff] [blame] | 499 | dest_tenant = self.alt_tenant |
Claudiu Belu | 33c3e60 | 2014-08-28 16:38:01 +0300 | [diff] [blame] | 500 | |
| 501 | protocol = CONF.scenario.protocol |
| 502 | LOG.debug("Testing cross tenant traffic for %s protocol", |
| 503 | protocol) |
| 504 | if protocol in ['udp', 'tcp']: |
| 505 | for tenant in [source_tenant, dest_tenant]: |
| 506 | access_point = self._connect_to_access_point(tenant) |
| 507 | access_point.nc_listen_host(protocol=protocol) |
| 508 | |
| 509 | ruleset = self._create_protocol_ruleset(protocol) |
| 510 | self._test_cross_tenant_block(source_tenant, dest_tenant, ruleset) |
| 511 | self._test_cross_tenant_allow(source_tenant, dest_tenant, ruleset) |
Nachi Ueno | 26b4c97 | 2014-01-17 06:15:13 -0800 | [diff] [blame] | 512 | except Exception: |
Ihar Hrachyshka | a9dca2b | 2017-04-04 14:17:11 -0700 | [diff] [blame] | 513 | self._log_console_output_for_all_tenants() |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 514 | raise |
| 515 | |
Ghanshyam Mann | e2183ca | 2023-02-10 19:31:52 -0600 | [diff] [blame] | 516 | @decorators.attr(type='multinode') |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 517 | @decorators.idempotent_id('63163892-bbf6-4249-aa12-d5ea1f8f421b') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 518 | @utils.services('compute', 'network') |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 519 | def test_in_tenant_traffic(self): |
| 520 | try: |
| 521 | self._create_tenant_servers(self.primary_tenant, num=1) |
| 522 | |
| 523 | # in-tenant check |
| 524 | self._test_in_tenant_block(self.primary_tenant) |
| 525 | self._test_in_tenant_allow(self.primary_tenant) |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 526 | except Exception: |
Ihar Hrachyshka | a9dca2b | 2017-04-04 14:17:11 -0700 | [diff] [blame] | 527 | self._log_console_output_for_all_tenants() |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 528 | raise |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 529 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 530 | @decorators.idempotent_id('f4d556d7-1526-42ad-bafb-6bebf48568f6') |
Ghanshyam Mann | e2183ca | 2023-02-10 19:31:52 -0600 | [diff] [blame] | 531 | @decorators.attr(type=['slow', 'multinode']) |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 532 | @utils.services('compute', 'network') |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 533 | def test_port_update_new_security_group(self): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 534 | """Verifies the traffic after updating the vm port |
| 535 | |
| 536 | With new security group having appropriate rule. |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 537 | """ |
| 538 | new_tenant = self.primary_tenant |
| 539 | |
| 540 | # Create empty security group and add icmp rule in it |
Soniya Vyas | 0860209 | 2021-03-04 18:52:59 +0530 | [diff] [blame] | 541 | new_sg = self.create_empty_security_group( |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 542 | namestart='secgroup_new-', |
Rodolfo Alonso Hernandez | c1449d4 | 2020-02-15 13:24:28 +0000 | [diff] [blame] | 543 | project_id=new_tenant.creds.project_id, |
John Warren | f9606e9 | 2015-12-10 12:12:42 -0500 | [diff] [blame] | 544 | client=new_tenant.manager.security_groups_client) |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 545 | icmp_rule = dict( |
| 546 | protocol='icmp', |
| 547 | direction='ingress', |
| 548 | ) |
John Warren | 456d9ae | 2016-01-12 15:36:33 -0500 | [diff] [blame] | 549 | sec_group_rules_client = new_tenant.manager.security_group_rules_client |
Soniya Vyas | 945f5a1 | 2021-02-02 23:49:12 +0530 | [diff] [blame] | 550 | self.create_security_group_rule( |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 551 | secgroup=new_sg, |
John Warren | 456d9ae | 2016-01-12 15:36:33 -0500 | [diff] [blame] | 552 | sec_group_rules_client=sec_group_rules_client, |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 553 | **icmp_rule) |
| 554 | new_tenant.security_groups.update(new_sg=new_sg) |
| 555 | |
| 556 | # Create server with default security group |
Ken'ichi Ohmichi | 6ded8df | 2015-03-23 02:00:19 +0000 | [diff] [blame] | 557 | name = 'server-{tenant}-gen-1'.format( |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 558 | tenant=new_tenant.creds.tenant_name |
| 559 | ) |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 560 | name = data_utils.rand_name( |
| 561 | prefix=CONF.resource_name_prefix, name=name) |
Markus Zoeller | 156b5da | 2016-07-11 18:10:31 +0200 | [diff] [blame] | 562 | server = self._create_server(name, new_tenant, |
| 563 | [new_tenant.security_groups['default']]) |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 564 | |
| 565 | # Check connectivity failure with default security group |
| 566 | try: |
| 567 | access_point_ssh = self._connect_to_access_point(new_tenant) |
YAMAMOTO Takashi | 4c3ebb0 | 2017-01-25 16:04:30 +0900 | [diff] [blame] | 568 | self.check_remote_connectivity(source=access_point_ssh, |
| 569 | dest=self._get_server_ip(server), |
| 570 | should_succeed=False) |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 571 | server_id = server['id'] |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 572 | port_id = self.os_admin.ports_client.list_ports( |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 573 | device_id=server_id)['ports'][0]['id'] |
Rajkumar Thiyagarajan | d9e964a | 2014-12-17 01:55:52 -0800 | [diff] [blame] | 574 | |
| 575 | # update port with new security group and check connectivity |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 576 | self.ports_client.update_port(port_id, security_groups=[ |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 577 | new_tenant.security_groups['new_sg']['id']]) |
YAMAMOTO Takashi | 4c3ebb0 | 2017-01-25 16:04:30 +0900 | [diff] [blame] | 578 | self.check_remote_connectivity( |
| 579 | source=access_point_ssh, |
| 580 | dest=self._get_server_ip(server)) |
Yair Fried | bf2e2c4 | 2014-01-28 12:06:38 +0200 | [diff] [blame] | 581 | except Exception: |
Ihar Hrachyshka | a9dca2b | 2017-04-04 14:17:11 -0700 | [diff] [blame] | 582 | self._log_console_output_for_all_tenants() |
Nachi Ueno | 26b4c97 | 2014-01-17 06:15:13 -0800 | [diff] [blame] | 583 | raise |
prdsilva | 8b733ad | 2014-12-09 02:54:49 -0800 | [diff] [blame] | 584 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 585 | @decorators.idempotent_id('d2f77418-fcc4-439d-b935-72eca704e293') |
Ghanshyam Mann | e2183ca | 2023-02-10 19:31:52 -0600 | [diff] [blame] | 586 | @decorators.attr(type=['slow', 'multinode']) |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 587 | @utils.services('compute', 'network') |
prdsilva | 8b733ad | 2014-12-09 02:54:49 -0800 | [diff] [blame] | 588 | def test_multiple_security_groups(self): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 589 | """Verify multiple security groups and checks that rules |
| 590 | |
prdsilva | 8b733ad | 2014-12-09 02:54:49 -0800 | [diff] [blame] | 591 | provided in the both the groups is applied onto VM |
| 592 | """ |
| 593 | tenant = self.primary_tenant |
| 594 | ip = self._get_server_ip(tenant.access_point, |
| 595 | floating=self.floating_ip_access) |
lanoux | 283273b | 2015-12-04 03:01:54 -0800 | [diff] [blame] | 596 | ssh_login = CONF.validation.image_ssh_user |
prdsilva | 8b733ad | 2014-12-09 02:54:49 -0800 | [diff] [blame] | 597 | private_key = tenant.keypair['private_key'] |
| 598 | self.check_vm_connectivity(ip, |
| 599 | should_connect=False) |
| 600 | ruleset = dict( |
| 601 | protocol='icmp', |
| 602 | direction='ingress' |
| 603 | ) |
Soniya Vyas | 945f5a1 | 2021-02-02 23:49:12 +0530 | [diff] [blame] | 604 | self.create_security_group_rule( |
prdsilva | 8b733ad | 2014-12-09 02:54:49 -0800 | [diff] [blame] | 605 | secgroup=tenant.security_groups['default'], |
| 606 | **ruleset |
| 607 | ) |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 608 | # NOTE: Vm now has 2 security groups one with ssh rule( |
| 609 | # already added in setUp() method),and other with icmp rule |
| 610 | # (added in the above step).The check_vm_connectivity tests |
| 611 | # -that vm ping test is successful |
| 612 | # -ssh to vm is successful |
prdsilva | 8b733ad | 2014-12-09 02:54:49 -0800 | [diff] [blame] | 613 | self.check_vm_connectivity(ip, |
| 614 | username=ssh_login, |
| 615 | private_key=private_key, |
| 616 | should_connect=True) |
YAMAMOTO Takashi | 51e0408 | 2015-09-08 18:44:23 +0900 | [diff] [blame] | 617 | |
Ghanshyam Mann | e2183ca | 2023-02-10 19:31:52 -0600 | [diff] [blame] | 618 | @decorators.attr(type=['slow', 'multinode']) |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 619 | @utils.requires_ext(service='network', extension='port-security') |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 620 | @decorators.idempotent_id('7c811dcc-263b-49a3-92d2-1b4d8405f50c') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 621 | @utils.services('compute', 'network') |
YAMAMOTO Takashi | 51e0408 | 2015-09-08 18:44:23 +0900 | [diff] [blame] | 622 | def test_port_security_disable_security_group(self): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 623 | """Verify the default security group rules is disabled.""" |
YAMAMOTO Takashi | 51e0408 | 2015-09-08 18:44:23 +0900 | [diff] [blame] | 624 | new_tenant = self.primary_tenant |
| 625 | |
| 626 | # Create server |
| 627 | name = 'server-{tenant}-gen-1'.format( |
| 628 | tenant=new_tenant.creds.tenant_name |
| 629 | ) |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 630 | name = data_utils.rand_name( |
| 631 | prefix=CONF.resource_name_prefix, name=name) |
Markus Zoeller | 156b5da | 2016-07-11 18:10:31 +0200 | [diff] [blame] | 632 | server = self._create_server(name, new_tenant, |
| 633 | [new_tenant.security_groups['default']]) |
YAMAMOTO Takashi | 51e0408 | 2015-09-08 18:44:23 +0900 | [diff] [blame] | 634 | |
| 635 | access_point_ssh = self._connect_to_access_point(new_tenant) |
| 636 | server_id = server['id'] |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 637 | port_id = self.os_admin.ports_client.list_ports( |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 638 | device_id=server_id)['ports'][0]['id'] |
YAMAMOTO Takashi | 51e0408 | 2015-09-08 18:44:23 +0900 | [diff] [blame] | 639 | |
| 640 | # Flip the port's port security and check connectivity |
| 641 | try: |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 642 | self.ports_client.update_port(port_id, |
| 643 | port_security_enabled=True, |
| 644 | security_groups=[]) |
YAMAMOTO Takashi | 4c3ebb0 | 2017-01-25 16:04:30 +0900 | [diff] [blame] | 645 | self.check_remote_connectivity(source=access_point_ssh, |
| 646 | dest=self._get_server_ip(server), |
| 647 | should_succeed=False) |
YAMAMOTO Takashi | 51e0408 | 2015-09-08 18:44:23 +0900 | [diff] [blame] | 648 | |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 649 | self.ports_client.update_port(port_id, |
| 650 | port_security_enabled=False, |
| 651 | security_groups=[]) |
YAMAMOTO Takashi | 4c3ebb0 | 2017-01-25 16:04:30 +0900 | [diff] [blame] | 652 | self.check_remote_connectivity( |
| 653 | source=access_point_ssh, |
| 654 | dest=self._get_server_ip(server)) |
YAMAMOTO Takashi | 51e0408 | 2015-09-08 18:44:23 +0900 | [diff] [blame] | 655 | except Exception: |
Ihar Hrachyshka | a9dca2b | 2017-04-04 14:17:11 -0700 | [diff] [blame] | 656 | self._log_console_output_for_all_tenants() |
YAMAMOTO Takashi | 51e0408 | 2015-09-08 18:44:23 +0900 | [diff] [blame] | 657 | raise |
Markus Zoeller | 156b5da | 2016-07-11 18:10:31 +0200 | [diff] [blame] | 658 | |
Ghanshyam Mann | e2183ca | 2023-02-10 19:31:52 -0600 | [diff] [blame] | 659 | @decorators.attr(type=['slow', 'multinode']) |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 660 | @utils.requires_ext(service='network', extension='port-security') |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 661 | @decorators.idempotent_id('13ccf253-e5ad-424b-9c4a-97b88a026699') |
Matt Riedemann | 039b2fe | 2016-09-15 16:12:24 -0400 | [diff] [blame] | 662 | # TODO(mriedem): We shouldn't actually need to check this since neutron |
| 663 | # disables the port_security extension by default, but the problem is nova |
| 664 | # assumes port_security_enabled=True if it's not set on the network |
| 665 | # resource, which will mean nova may attempt to apply a security group on |
| 666 | # a port on that network which would fail. This is really a bug in nova. |
| 667 | @testtools.skipUnless( |
| 668 | CONF.network_feature_enabled.port_security, |
| 669 | 'Port security must be enabled.') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 670 | @utils.services('compute', 'network') |
Markus Zoeller | 156b5da | 2016-07-11 18:10:31 +0200 | [diff] [blame] | 671 | def test_boot_into_disabled_port_security_network_without_secgroup(self): |
| 672 | tenant = self.primary_tenant |
| 673 | self._create_tenant_network(tenant, port_security_enabled=False) |
| 674 | self.assertFalse(tenant.network['port_security_enabled']) |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 675 | name = data_utils.rand_name( |
| 676 | prefix=CONF.resource_name_prefix, name='server-smoke') |
Markus Zoeller | 156b5da | 2016-07-11 18:10:31 +0200 | [diff] [blame] | 677 | sec_groups = [] |
| 678 | server = self._create_server(name, tenant, sec_groups) |
| 679 | server_id = server['id'] |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 680 | ports = self.os_admin.ports_client.list_ports( |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 681 | device_id=server_id)['ports'] |
Markus Zoeller | 156b5da | 2016-07-11 18:10:31 +0200 | [diff] [blame] | 682 | self.assertEqual(1, len(ports)) |
| 683 | for port in ports: |
| 684 | self.assertEmpty(port['security_groups'], |
| 685 | "Neutron shouldn't even use it's default sec " |
| 686 | "group.") |