ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Gavin Brebner | 0f465a3 | 2013-03-14 13:26:09 +0000 | [diff] [blame] | 2 | # Copyright 2013 Hewlett-Packard Development Company, L.P. |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 3 | # All Rights Reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
Yair Fried | 2d2f3fe | 2014-02-24 16:19:20 +0200 | [diff] [blame] | 16 | import collections |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 17 | import re |
Matthew Treinish | 96e9e88 | 2014-06-09 18:37:19 -0400 | [diff] [blame] | 18 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 19 | from oslo_log import log as logging |
Adam Gandelman | 7186f7a | 2014-07-23 09:28:56 -0400 | [diff] [blame] | 20 | import testtools |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 21 | |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 22 | from tempest.common import utils |
Ken'ichi Ohmichi | e91a0c6 | 2015-08-13 02:09:16 +0000 | [diff] [blame] | 23 | from tempest.common import waiters |
Matthew Treinish | cb56994 | 2013-08-09 16:33:44 -0400 | [diff] [blame] | 24 | from tempest import config |
Jordan Pittier | 9e227c5 | 2016-02-09 14:35:18 +0100 | [diff] [blame] | 25 | from tempest.lib.common.utils import test_utils |
Sean Dague | 17487fb | 2016-08-08 10:44:20 -0400 | [diff] [blame] | 26 | from tempest.lib import decorators |
guo yunxian | ebb15f2 | 2016-11-01 21:03:35 +0800 | [diff] [blame] | 27 | from tempest.lib import exceptions |
Sean Dague | 6dbc6da | 2013-05-08 17:49:46 -0400 | [diff] [blame] | 28 | from tempest.scenario import manager |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 29 | |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 30 | CONF = config.CONF |
Matthew Treinish | 2b59f84 | 2013-09-09 20:32:51 +0000 | [diff] [blame] | 31 | LOG = logging.getLogger(__name__) |
| 32 | |
Yair Fried | 2d2f3fe | 2014-02-24 16:19:20 +0200 | [diff] [blame] | 33 | Floating_IP_tuple = collections.namedtuple('Floating_IP_tuple', |
| 34 | ['floating_ip', 'server']) |
| 35 | |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 36 | |
Andrea Frittoli | 4971fc8 | 2014-09-25 10:22:20 +0100 | [diff] [blame] | 37 | class TestNetworkBasicOps(manager.NetworkScenarioTest): |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 38 | |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 39 | """The test suite of network basic operations |
| 40 | |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 41 | This smoke test suite assumes that Nova has been configured to |
Mark McClain | f2982e8 | 2013-07-06 17:48:03 -0400 | [diff] [blame] | 42 | boot VM's with Neutron-managed networking, and attempts to |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 43 | verify network connectivity as follows: |
| 44 | |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 45 | There are presumed to be two types of networks: tenant and |
| 46 | public. A tenant network may or may not be reachable from the |
| 47 | Tempest host. A public network is assumed to be reachable from |
| 48 | the Tempest host, and it should be possible to associate a public |
| 49 | ('floating') IP address with a tenant ('fixed') IP address to |
Chang Bo Guo | cc1623c | 2013-09-13 20:11:27 -0700 | [diff] [blame] | 50 | facilitate external connectivity to a potentially unroutable |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 51 | tenant IP address. |
| 52 | |
| 53 | This test suite can be configured to test network connectivity to |
| 54 | a VM via a tenant network, a public network, or both. If both |
| 55 | networking types are to be evaluated, tests that need to be |
| 56 | executed remotely on the VM (via ssh) will only be run against |
| 57 | one of the networks (to minimize test execution time). |
| 58 | |
| 59 | Determine which types of networks to test as follows: |
| 60 | |
| 61 | * Configure tenant network checks (via the |
Sean Dague | ed6e586 | 2016-04-04 10:49:13 -0400 | [diff] [blame] | 62 | 'project_networks_reachable' key) if the Tempest host should |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 63 | have direct connectivity to tenant networks. This is likely to |
| 64 | be the case if Tempest is running on the same host as a |
| 65 | single-node devstack installation with IP namespaces disabled. |
| 66 | |
| 67 | * Configure checks for a public network if a public network has |
| 68 | been configured prior to the test suite being run and if the |
| 69 | Tempest host should have connectivity to that public network. |
| 70 | Checking connectivity for a public network requires that a |
| 71 | value be provided for 'public_network_id'. A value can |
| 72 | optionally be provided for 'public_router_id' if tenants will |
| 73 | use a shared router to access a public network (as is likely to |
| 74 | be the case when IP namespaces are not enabled). If a value is |
| 75 | not provided for 'public_router_id', a router will be created |
| 76 | for each tenant and use the network identified by |
| 77 | 'public_network_id' as its gateway. |
| 78 | |
| 79 | """ |
| 80 | |
| 81 | @classmethod |
Emily Hugenbruch | 5e2d2a2 | 2015-02-25 21:35:45 +0000 | [diff] [blame] | 82 | def skip_checks(cls): |
| 83 | super(TestNetworkBasicOps, cls).skip_checks() |
Federico Ressi | 2d6bcaa | 2018-04-11 12:37:36 +0200 | [diff] [blame] | 84 | if not (CONF.network.project_networks_reachable or |
| 85 | CONF.network.public_network_id): |
Sean Dague | ed6e586 | 2016-04-04 10:49:13 -0400 | [diff] [blame] | 86 | msg = ('Either project_networks_reachable must be "true", or ' |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 87 | 'public_network_id must be defined.') |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 88 | raise cls.skipException(msg) |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 89 | for ext in ['router', 'security-group']: |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 90 | if not utils.is_extension_enabled(ext, 'network'): |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 91 | msg = "%s extension not enabled." % ext |
| 92 | raise cls.skipException(msg) |
Matthew Treinish | 3312de3 | 2017-05-19 12:08:17 -0400 | [diff] [blame] | 93 | if not CONF.network_feature_enabled.floating_ips: |
| 94 | raise cls.skipException("Floating ips are not available") |
Emily Hugenbruch | 5e2d2a2 | 2015-02-25 21:35:45 +0000 | [diff] [blame] | 95 | |
| 96 | @classmethod |
| 97 | def setup_credentials(cls): |
Masayuki Igawa | 60ea6c5 | 2014-10-15 17:32:14 +0900 | [diff] [blame] | 98 | # Create no network resources for these tests. |
| 99 | cls.set_network_resources() |
Emily Hugenbruch | 5e2d2a2 | 2015-02-25 21:35:45 +0000 | [diff] [blame] | 100 | super(TestNetworkBasicOps, cls).setup_credentials() |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 101 | |
Yair Fried | ed8392f | 2014-01-15 17:21:35 +0200 | [diff] [blame] | 102 | def setUp(self): |
| 103 | super(TestNetworkBasicOps, self).setUp() |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 104 | self.keypairs = {} |
| 105 | self.servers = [] |
David Shrewsbury | 9bac366 | 2014-08-07 15:07:01 -0400 | [diff] [blame] | 106 | |
Yair Fried | 413bf2d | 2014-11-19 17:07:11 +0200 | [diff] [blame] | 107 | def _setup_network_and_servers(self, **kwargs): |
Matt Riedemann | 1794073 | 2015-03-13 14:18:19 +0000 | [diff] [blame] | 108 | boot_with_port = kwargs.pop('boot_with_port', False) |
Yair Fried | 413bf2d | 2014-11-19 17:07:11 +0200 | [diff] [blame] | 109 | self.network, self.subnet, self.router = self.create_networks(**kwargs) |
David Shrewsbury | 9bac366 | 2014-08-07 15:07:01 -0400 | [diff] [blame] | 110 | self.check_networks() |
| 111 | |
Shuquan Huang | b5c8beb | 2015-08-05 14:14:01 +0000 | [diff] [blame] | 112 | self.ports = [] |
zhufl | 7a8f29d | 2017-02-17 10:16:45 +0800 | [diff] [blame] | 113 | port_id = None |
Jordan Pittier | f72a1dc | 2015-08-04 12:50:33 +0000 | [diff] [blame] | 114 | if boot_with_port: |
Matt Riedemann | 1794073 | 2015-03-13 14:18:19 +0000 | [diff] [blame] | 115 | # create a port on the network and boot with that |
zhufl | 1e446b5 | 2017-10-16 16:54:57 +0800 | [diff] [blame] | 116 | port_id = self.create_port(self.network['id'])['id'] |
zhufl | 7a8f29d | 2017-02-17 10:16:45 +0800 | [diff] [blame] | 117 | self.ports.append({'port': port_id}) |
Matt Riedemann | 1794073 | 2015-03-13 14:18:19 +0000 | [diff] [blame] | 118 | |
zhufl | 7a8f29d | 2017-02-17 10:16:45 +0800 | [diff] [blame] | 119 | server = self._create_server(self.network, port_id) |
zhufl | 420a019 | 2017-09-28 11:04:50 +0800 | [diff] [blame] | 120 | ssh_login = CONF.validation.image_ssh_user |
| 121 | for server in self.servers: |
| 122 | # call the common method in the parent class |
| 123 | self.check_tenant_network_connectivity( |
| 124 | server, ssh_login, self._get_server_key(server), |
| 125 | servers_for_debug=self.servers) |
Yair Fried | 2d2f3fe | 2014-02-24 16:19:20 +0200 | [diff] [blame] | 126 | |
Yair Fried | ae0e73d | 2014-11-24 11:56:26 +0200 | [diff] [blame] | 127 | floating_ip = self.create_floating_ip(server) |
| 128 | self.floating_ip_tuple = Floating_IP_tuple(floating_ip, server) |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 129 | |
Yair Fried | ed8392f | 2014-01-15 17:21:35 +0200 | [diff] [blame] | 130 | def check_networks(self): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 131 | """Checks that we see the newly created network/subnet/router |
| 132 | |
| 133 | via checking the result of list_[networks,routers,subnets] |
Yair Fried | ed8392f | 2014-01-15 17:21:35 +0200 | [diff] [blame] | 134 | """ |
| 135 | |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 136 | seen_nets = self.os_admin.networks_client.list_networks() |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 137 | seen_names = [n['name'] for n in seen_nets['networks']] |
| 138 | seen_ids = [n['id'] for n in seen_nets['networks']] |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 139 | self.assertIn(self.network['name'], seen_names) |
| 140 | self.assertIn(self.network['id'], seen_ids) |
Yair Fried | ed8392f | 2014-01-15 17:21:35 +0200 | [diff] [blame] | 141 | |
David Shrewsbury | 9bac366 | 2014-08-07 15:07:01 -0400 | [diff] [blame] | 142 | if self.subnet: |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 143 | seen_subnets = self.os_admin.subnets_client.list_subnets() |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 144 | seen_net_ids = [n['network_id'] for n in seen_subnets['subnets']] |
| 145 | seen_subnet_ids = [n['id'] for n in seen_subnets['subnets']] |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 146 | self.assertIn(self.network['id'], seen_net_ids) |
| 147 | self.assertIn(self.subnet['id'], seen_subnet_ids) |
Yair Fried | ed8392f | 2014-01-15 17:21:35 +0200 | [diff] [blame] | 148 | |
David Shrewsbury | 9bac366 | 2014-08-07 15:07:01 -0400 | [diff] [blame] | 149 | if self.router: |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 150 | seen_routers = self.os_admin.routers_client.list_routers() |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 151 | seen_router_ids = [n['id'] for n in seen_routers['routers']] |
| 152 | seen_router_names = [n['name'] for n in seen_routers['routers']] |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 153 | self.assertIn(self.router['name'], |
David Shrewsbury | 9bac366 | 2014-08-07 15:07:01 -0400 | [diff] [blame] | 154 | seen_router_names) |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 155 | self.assertIn(self.router['id'], |
David Shrewsbury | 9bac366 | 2014-08-07 15:07:01 -0400 | [diff] [blame] | 156 | seen_router_ids) |
Gavin Brebner | 851c350 | 2013-01-18 13:14:10 +0000 | [diff] [blame] | 157 | |
zhufl | 24208c2 | 2016-10-25 15:23:48 +0800 | [diff] [blame] | 158 | def _create_server(self, network, port_id=None): |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 159 | keypair = self.create_keypair() |
| 160 | self.keypairs[keypair['name']] = keypair |
Jordan Pittier | 37b94a0 | 2017-02-21 18:11:55 +0100 | [diff] [blame] | 161 | security_groups = [ |
| 162 | {'name': self._create_security_group()['name']} |
| 163 | ] |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 164 | network = {'uuid': network['id']} |
Matt Riedemann | 1794073 | 2015-03-13 14:18:19 +0000 | [diff] [blame] | 165 | if port_id is not None: |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 166 | network['port'] = port_id |
| 167 | |
| 168 | server = self.create_server( |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 169 | networks=[network], |
| 170 | key_name=keypair['name'], |
zhufl | 13c9c89 | 2017-02-10 12:04:07 +0800 | [diff] [blame] | 171 | security_groups=security_groups) |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 172 | self.servers.append(server) |
| 173 | return server |
| 174 | |
| 175 | def _get_server_key(self, server): |
| 176 | return self.keypairs[server['key_name']]['private_key'] |
Salvatore Orlando | 5ed3b6e | 2013-09-17 01:27:26 -0700 | [diff] [blame] | 177 | |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 178 | def _check_public_network_connectivity( |
Alok Maurya | 6384bbb | 2014-07-13 06:44:29 -0700 | [diff] [blame] | 179 | self, should_connect=True, msg=None, |
Ihar Hrachyshka | f9227c0 | 2016-09-15 11:16:47 +0000 | [diff] [blame] | 180 | should_check_floating_ip_status=True, mtu=None): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 181 | """Verifies connectivty to a VM via public network and floating IP |
| 182 | |
Yair Fried | 45f9295 | 2014-06-26 05:19:19 +0300 | [diff] [blame] | 183 | and verifies floating IP has resource status is correct. |
| 184 | |
Yair Fried | 45f9295 | 2014-06-26 05:19:19 +0300 | [diff] [blame] | 185 | :param should_connect: bool. determines if connectivity check is |
| 186 | negative or positive. |
| 187 | :param msg: Failure message to add to Error message. Should describe |
| 188 | the place in the test scenario where the method was called, |
| 189 | to indicate the context of the failure |
Alok Maurya | 6384bbb | 2014-07-13 06:44:29 -0700 | [diff] [blame] | 190 | :param should_check_floating_ip_status: bool. should status of |
| 191 | floating_ip be checked or not |
Ihar Hrachyshka | f9227c0 | 2016-09-15 11:16:47 +0000 | [diff] [blame] | 192 | :param mtu: int. MTU network to use for connectivity validation |
Yair Fried | 45f9295 | 2014-06-26 05:19:19 +0300 | [diff] [blame] | 193 | """ |
lanoux | 283273b | 2015-12-04 03:01:54 -0800 | [diff] [blame] | 194 | ssh_login = CONF.validation.image_ssh_user |
Yair Fried | 2d2f3fe | 2014-02-24 16:19:20 +0200 | [diff] [blame] | 195 | floating_ip, server = self.floating_ip_tuple |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 196 | ip_address = floating_ip['floating_ip_address'] |
Yair Fried | 2d2f3fe | 2014-02-24 16:19:20 +0200 | [diff] [blame] | 197 | private_key = None |
Yair Fried | 45f9295 | 2014-06-26 05:19:19 +0300 | [diff] [blame] | 198 | floatingip_status = 'DOWN' |
Yair Fried | 2d2f3fe | 2014-02-24 16:19:20 +0200 | [diff] [blame] | 199 | if should_connect: |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 200 | private_key = self._get_server_key(server) |
Yair Fried | 45f9295 | 2014-06-26 05:19:19 +0300 | [diff] [blame] | 201 | floatingip_status = 'ACTIVE' |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 202 | |
Swaminathan Vasudevan | dc8bcdb | 2015-02-28 12:47:21 -0800 | [diff] [blame] | 203 | # Check FloatingIP Status before initiating a connection |
| 204 | if should_check_floating_ip_status: |
| 205 | self.check_floating_ip_status(floating_ip, floatingip_status) |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 206 | |
| 207 | message = 'Public network connectivity check failed' |
| 208 | if msg: |
| 209 | message += '. Reason: %s' % msg |
| 210 | |
| 211 | self.check_vm_connectivity( |
| 212 | ip_address, ssh_login, private_key, should_connect, |
| 213 | message, server, mtu=mtu) |
Matthew Treinish | 2b59f84 | 2013-09-09 20:32:51 +0000 | [diff] [blame] | 214 | |
Yair Fried | 9a551c4 | 2013-12-15 14:59:34 +0200 | [diff] [blame] | 215 | def _disassociate_floating_ips(self): |
Ferenc Horváth | bce1fcf | 2017-06-07 11:19:51 +0200 | [diff] [blame] | 216 | floating_ip, _ = self.floating_ip_tuple |
zhufl | afe96b8 | 2017-09-22 14:25:29 +0800 | [diff] [blame] | 217 | floating_ip = self.floating_ips_client.update_floatingip( |
| 218 | floating_ip['id'], port_id=None)['floatingip'] |
| 219 | self.assertIsNone(floating_ip['port_id']) |
| 220 | self.floating_ip_tuple = Floating_IP_tuple(floating_ip, None) |
Yair Fried | 9a551c4 | 2013-12-15 14:59:34 +0200 | [diff] [blame] | 221 | |
Yair Fried | 05db252 | 2013-11-18 11:02:10 +0200 | [diff] [blame] | 222 | def _reassociate_floating_ips(self): |
Yair Fried | 2d2f3fe | 2014-02-24 16:19:20 +0200 | [diff] [blame] | 223 | floating_ip, server = self.floating_ip_tuple |
Yair Fried | 2d2f3fe | 2014-02-24 16:19:20 +0200 | [diff] [blame] | 224 | # create a new server for the floating ip |
zhufl | 24208c2 | 2016-10-25 15:23:48 +0800 | [diff] [blame] | 225 | server = self._create_server(self.network) |
zhufl | afe96b8 | 2017-09-22 14:25:29 +0800 | [diff] [blame] | 226 | port_id, _ = self._get_server_port_id_and_ip4(server) |
| 227 | floating_ip = self.floating_ips_client.update_floatingip( |
| 228 | floating_ip['id'], port_id=port_id)['floatingip'] |
| 229 | self.assertEqual(port_id, floating_ip['port_id']) |
| 230 | self.floating_ip_tuple = Floating_IP_tuple(floating_ip, server) |
Yair Fried | 05db252 | 2013-11-18 11:02:10 +0200 | [diff] [blame] | 231 | |
Fei Long Wang | 05a1c4a | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 232 | def _create_new_network(self, create_gateway=False): |
Marc Koderer | 410c782 | 2016-11-08 11:47:00 +0100 | [diff] [blame] | 233 | self.new_net = self._create_network() |
Fei Long Wang | 05a1c4a | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 234 | if create_gateway: |
zhufl | 5b0a52f | 2017-10-24 15:48:20 +0800 | [diff] [blame] | 235 | self.new_subnet = self.create_subnet( |
Fei Long Wang | 05a1c4a | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 236 | network=self.new_net) |
| 237 | else: |
zhufl | 5b0a52f | 2017-10-24 15:48:20 +0800 | [diff] [blame] | 238 | self.new_subnet = self.create_subnet( |
Fei Long Wang | 05a1c4a | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 239 | network=self.new_net, |
| 240 | gateway_ip=None) |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 241 | |
| 242 | def _hotplug_server(self): |
| 243 | old_floating_ip, server = self.floating_ip_tuple |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 244 | ip_address = old_floating_ip['floating_ip_address'] |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 245 | private_key = self._get_server_key(server) |
Jordan Pittier | bbb1712 | 2016-01-26 17:10:55 +0100 | [diff] [blame] | 246 | ssh_client = self.get_remote_client( |
zhufl | f52c759 | 2017-05-25 13:55:24 +0800 | [diff] [blame] | 247 | ip_address, private_key=private_key, server=server) |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 248 | old_nic_list = self._get_server_nics(ssh_client) |
| 249 | # get a port from a list of one item |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 250 | port_list = self.os_admin.ports_client.list_ports( |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 251 | device_id=server['id'])['ports'] |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 252 | self.assertEqual(1, len(port_list)) |
| 253 | old_port = port_list[0] |
David Kranz | b2b0c18 | 2015-02-18 13:28:19 -0500 | [diff] [blame] | 254 | interface = self.interface_client.create_interface( |
Ken'ichi Ohmichi | 9509b96 | 2015-07-07 05:30:15 +0000 | [diff] [blame] | 255 | server_id=server['id'], |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 256 | net_id=self.new_net['id'])['interfaceAttachment'] |
Ken'ichi Ohmichi | 43e7fcf | 2016-04-04 11:59:13 -0700 | [diff] [blame] | 257 | self.addCleanup(self.ports_client.wait_for_resource_deletion, |
| 258 | interface['port_id']) |
Jordan Pittier | 9e227c5 | 2016-02-09 14:35:18 +0100 | [diff] [blame] | 259 | self.addCleanup(test_utils.call_and_ignore_notfound_exc, |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 260 | self.interface_client.delete_interface, |
| 261 | server['id'], interface['port_id']) |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 262 | |
| 263 | def check_ports(): |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 264 | self.new_port_list = [ |
| 265 | port for port in |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 266 | self.os_admin.ports_client.list_ports( |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 267 | device_id=server['id'])['ports'] |
| 268 | if port['id'] != old_port['id'] |
| 269 | ] |
Attila Fazekas | a8bb394 | 2014-08-19 09:06:30 +0200 | [diff] [blame] | 270 | return len(self.new_port_list) == 1 |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 271 | |
Jordan Pittier | 35a6375 | 2016-08-30 13:09:12 +0200 | [diff] [blame] | 272 | if not test_utils.call_until_true( |
| 273 | check_ports, CONF.network.build_timeout, |
| 274 | CONF.network.build_interval): |
Matt Riedemann | 892094e | 2015-02-05 07:24:02 -0800 | [diff] [blame] | 275 | raise exceptions.TimeoutException( |
| 276 | "No new port attached to the server in time (%s sec)! " |
| 277 | "Old port: %s. Number of new ports: %d" % ( |
| 278 | CONF.network.build_timeout, old_port, |
| 279 | len(self.new_port_list))) |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 280 | new_port = self.new_port_list[0] |
Attila Fazekas | a8bb394 | 2014-08-19 09:06:30 +0200 | [diff] [blame] | 281 | |
| 282 | def check_new_nic(): |
| 283 | new_nic_list = self._get_server_nics(ssh_client) |
| 284 | self.diff_list = [n for n in new_nic_list if n not in old_nic_list] |
| 285 | return len(self.diff_list) == 1 |
| 286 | |
Jordan Pittier | 35a6375 | 2016-08-30 13:09:12 +0200 | [diff] [blame] | 287 | if not test_utils.call_until_true( |
| 288 | check_new_nic, CONF.network.build_timeout, |
| 289 | CONF.network.build_interval): |
Attila Fazekas | a8bb394 | 2014-08-19 09:06:30 +0200 | [diff] [blame] | 290 | raise exceptions.TimeoutException("Interface not visible on the " |
| 291 | "guest after %s sec" |
| 292 | % CONF.network.build_timeout) |
| 293 | |
Ferenc Horváth | bce1fcf | 2017-06-07 11:19:51 +0200 | [diff] [blame] | 294 | _, new_nic = self.diff_list[0] |
Martin Kopec | 925188d | 2019-05-07 13:26:34 +0000 | [diff] [blame] | 295 | ip_output = ssh_client.exec_command('ip a') |
| 296 | ip_address = new_port['fixed_ips'][0]['ip_address'] |
| 297 | ip_mask = CONF.network.project_network_mask_bits |
| 298 | # check if the address is not already in use, if not, set it |
| 299 | if ' ' + ip_address + '/' + str(ip_mask) not in ip_output: |
| 300 | ssh_client.exec_command("sudo ip addr add %s/%s dev %s" % ( |
| 301 | ip_address, ip_mask, new_nic)) |
| 302 | ssh_client.exec_command("sudo ip link set %s up" % new_nic) |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 303 | |
| 304 | def _get_server_nics(self, ssh_client): |
James Page | a936627 | 2017-06-09 12:05:09 +0100 | [diff] [blame] | 305 | reg = re.compile(r'(?P<num>\d+): (?P<nic_name>\w+)[@]?.*:') |
Ken'ichi Ohmichi | 84aeba6 | 2017-03-01 18:31:20 -0800 | [diff] [blame] | 306 | ipatxt = ssh_client.exec_command("ip address") |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 307 | return reg.findall(ipatxt) |
| 308 | |
Fei Long Wang | 05a1c4a | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 309 | def _check_network_internal_connectivity(self, network, |
| 310 | should_connect=True): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 311 | """via ssh check VM internal connectivity: |
| 312 | |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 313 | - ping internal gateway and DHCP port, implying in-tenant connectivity |
| 314 | pinging both, because L3 and DHCP agents might be on different nodes |
Tong Liu | 589f315 | 2016-03-24 05:56:40 +0000 | [diff] [blame] | 315 | - ping internal compute port, implying connectivity to other VMs on |
| 316 | this network |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 317 | """ |
| 318 | floating_ip, server = self.floating_ip_tuple |
| 319 | # get internal ports' ips: |
Tong Liu | 589f315 | 2016-03-24 05:56:40 +0000 | [diff] [blame] | 320 | # get all network and compute ports in the new network |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 321 | internal_ips = ( |
| 322 | p['fixed_ips'][0]['ip_address'] for p in |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 323 | self.os_admin.ports_client.list_ports( |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 324 | tenant_id=server['tenant_id'], |
| 325 | network_id=network['id'])['ports'] |
Tong Liu | 589f315 | 2016-03-24 05:56:40 +0000 | [diff] [blame] | 326 | if p['device_owner'].startswith('network') or |
| 327 | p['device_owner'].startswith('compute') |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 328 | ) |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 329 | |
Fei Long Wang | 05a1c4a | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 330 | self._check_server_connectivity(floating_ip, |
| 331 | internal_ips, |
| 332 | should_connect) |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 333 | |
| 334 | def _check_network_external_connectivity(self): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 335 | """ping default gateway to imply external connectivity""" |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 336 | if not CONF.network.public_network_id: |
| 337 | msg = 'public network not defined.' |
| 338 | LOG.info(msg) |
| 339 | return |
| 340 | |
Andrew Boik | 4a3daf1 | 2015-03-27 01:59:31 -0400 | [diff] [blame] | 341 | # We ping the external IP from the instance using its floating IP |
| 342 | # which is always IPv4, so we must only test connectivity to |
| 343 | # external IPv4 IPs if the external network is dualstack. |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 344 | v4_subnets = [ |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 345 | s for s in self.os_admin.subnets_client.list_subnets( |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 346 | network_id=CONF.network.public_network_id)['subnets'] |
| 347 | if s['ip_version'] == 4 |
| 348 | ] |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 349 | |
Lukas Piwowarski | 2385e04 | 2020-01-31 12:28:20 +0000 | [diff] [blame^] | 350 | if len(v4_subnets) > 1: |
| 351 | self.assertTrue( |
| 352 | CONF.network.subnet_id, |
| 353 | "Found %d subnets. Specify subnet using configuration " |
| 354 | "option [network].subnet_id." |
| 355 | % len(v4_subnets)) |
| 356 | subnet = self.os_admin.subnets_client.show_subnet( |
| 357 | CONF.network.subnet_id)['subnet'] |
| 358 | external_ips = [subnet['gateway_ip']] |
| 359 | else: |
| 360 | external_ips = [v4_subnets[0]['gateway_ip']] |
| 361 | |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 362 | self._check_server_connectivity(self.floating_ip_tuple.floating_ip, |
| 363 | external_ips) |
| 364 | |
Fei Long Wang | 05a1c4a | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 365 | def _check_server_connectivity(self, floating_ip, address_list, |
| 366 | should_connect=True): |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 367 | ip_address = floating_ip['floating_ip_address'] |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 368 | private_key = self._get_server_key(self.floating_ip_tuple.server) |
Jordan Pittier | bbb1712 | 2016-01-26 17:10:55 +0100 | [diff] [blame] | 369 | ssh_source = self.get_remote_client( |
zhufl | f52c759 | 2017-05-25 13:55:24 +0800 | [diff] [blame] | 370 | ip_address, private_key=private_key, |
| 371 | server=self.floating_ip_tuple.server) |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 372 | |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 373 | for remote_ip in address_list: |
YAMAMOTO Takashi | 4c3ebb0 | 2017-01-25 16:04:30 +0900 | [diff] [blame] | 374 | self.check_remote_connectivity(ssh_source, remote_ip, |
| 375 | should_connect) |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 376 | |
zhufl | afe96b8 | 2017-09-22 14:25:29 +0800 | [diff] [blame] | 377 | def _update_router_admin_state(self, router, admin_state_up): |
| 378 | kwargs = dict(admin_state_up=admin_state_up) |
| 379 | router = self.routers_client.update_router( |
| 380 | router['id'], **kwargs)['router'] |
| 381 | self.assertEqual(admin_state_up, router['admin_state_up']) |
| 382 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 383 | @decorators.attr(type='smoke') |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 384 | @decorators.idempotent_id('f323b3ba-82f8-4db7-8ea6-6a895869ec49') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 385 | @utils.services('compute', 'network') |
Matthew Treinish | 2b59f84 | 2013-09-09 20:32:51 +0000 | [diff] [blame] | 386 | def test_network_basic_ops(self): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 387 | """Basic network operation test |
| 388 | |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 389 | For a freshly-booted VM with an IP address ("port") on a given network: |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 390 | |
| 391 | - the Tempest host can ping the IP address. This implies, but |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 392 | does not guarantee (see the ssh check that follows), that the |
| 393 | VM has been assigned the correct IP address and has |
| 394 | connectivity to the Tempest host. |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 395 | |
| 396 | - the Tempest host can perform key-based authentication to an |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 397 | ssh server hosted at the IP address. This check guarantees |
| 398 | that the IP address is associated with the target VM. |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 399 | |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 400 | - the Tempest host can ssh into the VM via the IP address and |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 401 | successfully execute the following: |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 402 | |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 403 | - ping an external IP address, implying external connectivity. |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 404 | |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 405 | - ping an external hostname, implying that dns is correctly |
| 406 | configured. |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 407 | |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 408 | - ping an internal IP address, implying connectivity to another |
| 409 | VM on the same network. |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 410 | |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 411 | - detach the floating-ip from the VM and verify that it becomes |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 412 | unreachable |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 413 | |
| 414 | - associate detached floating ip to a new VM and verify connectivity. |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 415 | VMs are created with unique keypair so connectivity also asserts |
| 416 | that floating IP is associated with the new VM instead of the old |
| 417 | one |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 418 | |
Yair Fried | 45f9295 | 2014-06-26 05:19:19 +0300 | [diff] [blame] | 419 | Verifies that floating IP status is updated correctly after each change |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 420 | """ |
David Shrewsbury | 9bac366 | 2014-08-07 15:07:01 -0400 | [diff] [blame] | 421 | self._setup_network_and_servers() |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 422 | self._check_public_network_connectivity(should_connect=True) |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 423 | self._check_network_internal_connectivity(network=self.network) |
| 424 | self._check_network_external_connectivity() |
Yair Fried | 9a551c4 | 2013-12-15 14:59:34 +0200 | [diff] [blame] | 425 | self._disassociate_floating_ips() |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 426 | self._check_public_network_connectivity(should_connect=False, |
| 427 | msg="after disassociate " |
| 428 | "floating ip") |
Yair Fried | 05db252 | 2013-11-18 11:02:10 +0200 | [diff] [blame] | 429 | self._reassociate_floating_ips() |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 430 | self._check_public_network_connectivity(should_connect=True, |
| 431 | msg="after re-associate " |
| 432 | "floating ip") |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 433 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 434 | @decorators.idempotent_id('b158ea55-472e-4086-8fa9-c64ac0c6c1d0') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 435 | @testtools.skipUnless(utils.is_extension_enabled('net-mtu', 'network'), |
Ihar Hrachyshka | f9227c0 | 2016-09-15 11:16:47 +0000 | [diff] [blame] | 436 | 'No way to calculate MTU for networks') |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 437 | @decorators.attr(type='slow') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 438 | @utils.services('compute', 'network') |
Ihar Hrachyshka | f9227c0 | 2016-09-15 11:16:47 +0000 | [diff] [blame] | 439 | def test_mtu_sized_frames(self): |
| 440 | """Validate that network MTU sized frames fit through.""" |
| 441 | self._setup_network_and_servers() |
Ihar Hrachyshka | aca29ed | 2017-09-25 12:13:53 -0700 | [diff] [blame] | 442 | # first check that connectivity works in general for the instance |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 443 | self._check_public_network_connectivity(should_connect=True) |
Ihar Hrachyshka | aca29ed | 2017-09-25 12:13:53 -0700 | [diff] [blame] | 444 | # now that we checked general connectivity, test that full size frames |
| 445 | # can also pass between nodes |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 446 | self._check_public_network_connectivity( |
Ihar Hrachyshka | f9227c0 | 2016-09-15 11:16:47 +0000 | [diff] [blame] | 447 | should_connect=True, mtu=self.network['mtu']) |
| 448 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 449 | @decorators.idempotent_id('1546850e-fbaa-42f5-8b5f-03d8a6a95f15') |
Thiago Paiva | 66cded2 | 2016-08-15 14:55:58 -0300 | [diff] [blame] | 450 | @testtools.skipIf(CONF.network.shared_physical_network, |
| 451 | 'Connectivity can only be tested when in a ' |
| 452 | 'multitenant network environment') |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 453 | @decorators.attr(type='slow') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 454 | @utils.services('compute', 'network') |
Fei Long Wang | 05a1c4a | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 455 | def test_connectivity_between_vms_on_different_networks(self): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 456 | """Test connectivity between VMs on different networks |
| 457 | |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 458 | For a freshly-booted VM with an IP address ("port") on a given network: |
Fei Long Wang | 05a1c4a | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 459 | |
| 460 | - the Tempest host can ping the IP address. |
Fei Long Wang | 05a1c4a | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 461 | - the Tempest host can ssh into the VM via the IP address and |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 462 | successfully execute the following: |
Fei Long Wang | 05a1c4a | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 463 | |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 464 | - ping an external IP address, implying external connectivity. |
| 465 | - ping an external hostname, implying that dns is correctly |
| 466 | configured. |
| 467 | - ping an internal IP address, implying connectivity to another |
| 468 | VM on the same network. |
Fei Long Wang | 05a1c4a | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 469 | |
| 470 | - Create another network on the same tenant with subnet, create |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 471 | an VM on the new network. |
Fei Long Wang | 05a1c4a | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 472 | |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 473 | - Ping the new VM from previous VM failed since the new network |
| 474 | was not attached to router yet. |
| 475 | - Attach the new network to the router, Ping the new VM from |
| 476 | previous VM succeed. |
Fei Long Wang | 05a1c4a | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 477 | |
| 478 | """ |
| 479 | self._setup_network_and_servers() |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 480 | self._check_public_network_connectivity(should_connect=True) |
Fei Long Wang | 05a1c4a | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 481 | self._check_network_internal_connectivity(network=self.network) |
| 482 | self._check_network_external_connectivity() |
| 483 | self._create_new_network(create_gateway=True) |
Lucas Alvares Gomes | d595c36 | 2018-10-16 14:38:11 +0100 | [diff] [blame] | 484 | new_server = self._create_server(self.new_net) |
| 485 | new_server_ips = [addr['addr'] for addr in |
| 486 | new_server['addresses'][self.new_net['name']]] |
| 487 | |
| 488 | # Assert that pinging the new VM fails since the new network is not |
| 489 | # connected to a router |
| 490 | self._check_server_connectivity(self.floating_ip_tuple.floating_ip, |
| 491 | new_server_ips, should_connect=False) |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 492 | router_id = self.router['id'] |
| 493 | self.routers_client.add_router_interface( |
| 494 | router_id, subnet_id=self.new_subnet['id']) |
| 495 | |
| 496 | self.addCleanup(test_utils.call_and_ignore_notfound_exc, |
| 497 | self.routers_client.remove_router_interface, |
| 498 | router_id, subnet_id=self.new_subnet['id']) |
Lucas Alvares Gomes | d595c36 | 2018-10-16 14:38:11 +0100 | [diff] [blame] | 499 | |
| 500 | self._check_server_connectivity(self.floating_ip_tuple.floating_ip, |
| 501 | new_server_ips, should_connect=True) |
Fei Long Wang | 05a1c4a | 2015-02-02 16:58:24 +1300 | [diff] [blame] | 502 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 503 | @decorators.idempotent_id('c5adff73-e961-41f1-b4a9-343614f18cfa') |
Adam Gandelman | 7186f7a | 2014-07-23 09:28:56 -0400 | [diff] [blame] | 504 | @testtools.skipUnless(CONF.compute_feature_enabled.interface_attach, |
| 505 | 'NIC hotplug not available') |
Itzik Brown | 2ca01cd | 2014-12-08 12:58:20 +0200 | [diff] [blame] | 506 | @testtools.skipIf(CONF.network.port_vnic_type in ['direct', 'macvtap'], |
| 507 | 'NIC hotplug not supported for ' |
| 508 | 'vnic_type direct or macvtap') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 509 | @utils.services('compute', 'network') |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 510 | def test_hotplug_nic(self): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 511 | """Test hotplug network interface |
| 512 | |
Arie | f3f6e81 | 2016-09-28 16:48:20 +0300 | [diff] [blame] | 513 | 1. Create a network and a VM. |
| 514 | 2. Check connectivity to the VM via a public network. |
| 515 | 3. Create a new network, with no gateway. |
| 516 | 4. Bring up a new interface |
| 517 | 5. check the VM reach the new network |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 518 | |
| 519 | """ |
David Shrewsbury | 9bac366 | 2014-08-07 15:07:01 -0400 | [diff] [blame] | 520 | self._setup_network_and_servers() |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 521 | self._check_public_network_connectivity(should_connect=True) |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 522 | self._create_new_network() |
| 523 | self._hotplug_server() |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 524 | self._check_network_internal_connectivity(network=self.new_net) |
Alok Maurya | 6384bbb | 2014-07-13 06:44:29 -0700 | [diff] [blame] | 525 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 526 | @decorators.idempotent_id('04b9fe4e-85e8-4aea-b937-ea93885ac59f') |
Thiago Paiva | 66cded2 | 2016-08-15 14:55:58 -0300 | [diff] [blame] | 527 | @testtools.skipIf(CONF.network.shared_physical_network, |
| 528 | 'Router state can be altered only with multitenant ' |
| 529 | 'networks capabilities') |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 530 | @decorators.attr(type='slow') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 531 | @utils.services('compute', 'network') |
Alok Maurya | 6384bbb | 2014-07-13 06:44:29 -0700 | [diff] [blame] | 532 | def test_update_router_admin_state(self): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 533 | """Test to update admin state up of router |
| 534 | |
Alok Maurya | 6384bbb | 2014-07-13 06:44:29 -0700 | [diff] [blame] | 535 | 1. Check public connectivity before updating |
| 536 | admin_state_up attribute of router to False |
| 537 | 2. Check public connectivity after updating |
| 538 | admin_state_up attribute of router to False |
| 539 | 3. Check public connectivity after updating |
| 540 | admin_state_up attribute of router to True |
| 541 | """ |
| 542 | self._setup_network_and_servers() |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 543 | self._check_public_network_connectivity( |
Alok Maurya | 6384bbb | 2014-07-13 06:44:29 -0700 | [diff] [blame] | 544 | should_connect=True, msg="before updating " |
| 545 | "admin_state_up of router to False") |
| 546 | self._update_router_admin_state(self.router, False) |
| 547 | # TODO(alokmaurya): Remove should_check_floating_ip_status=False check |
| 548 | # once bug 1396310 is fixed |
| 549 | |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 550 | self._check_public_network_connectivity( |
Alok Maurya | 6384bbb | 2014-07-13 06:44:29 -0700 | [diff] [blame] | 551 | should_connect=False, msg="after updating " |
| 552 | "admin_state_up of router to False", |
| 553 | should_check_floating_ip_status=False) |
| 554 | self._update_router_admin_state(self.router, True) |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 555 | self._check_public_network_connectivity( |
Alok Maurya | 6384bbb | 2014-07-13 06:44:29 -0700 | [diff] [blame] | 556 | should_connect=True, msg="after updating " |
| 557 | "admin_state_up of router to True") |
Yair Fried | 413bf2d | 2014-11-19 17:07:11 +0200 | [diff] [blame] | 558 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 559 | @decorators.idempotent_id('d8bb918e-e2df-48b2-97cd-b73c95450980') |
Thiago Paiva | 66cded2 | 2016-08-15 14:55:58 -0300 | [diff] [blame] | 560 | @testtools.skipIf(CONF.network.shared_physical_network, |
| 561 | 'network isolation not available') |
Yair Fried | 413bf2d | 2014-11-19 17:07:11 +0200 | [diff] [blame] | 562 | @testtools.skipUnless(CONF.scenario.dhcp_client, |
| 563 | "DHCP client is not available.") |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 564 | @decorators.attr(type='slow') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 565 | @utils.services('compute', 'network') |
Yair Fried | 413bf2d | 2014-11-19 17:07:11 +0200 | [diff] [blame] | 566 | def test_subnet_details(self): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 567 | """Tests that subnet's extra configuration details are affecting VMs. |
| 568 | |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 569 | This test relies on non-shared, isolated tenant networks. |
Yair Fried | 413bf2d | 2014-11-19 17:07:11 +0200 | [diff] [blame] | 570 | |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 571 | NOTE: Neutron subnets push data to servers via dhcp-agent, so any |
| 572 | update in subnet requires server to actively renew its DHCP lease. |
Yair Fried | 413bf2d | 2014-11-19 17:07:11 +0200 | [diff] [blame] | 573 | |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 574 | 1. Configure subnet with dns nameserver |
| 575 | 2. retrieve the VM's configured dns and verify it matches the one |
| 576 | configured for the subnet. |
| 577 | 3. update subnet's dns |
| 578 | 4. retrieve the VM's configured dns and verify it matches the new one |
| 579 | configured for the subnet. |
Yair Fried | 413bf2d | 2014-11-19 17:07:11 +0200 | [diff] [blame] | 580 | |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 581 | TODO(yfried): add host_routes |
Yair Fried | 413bf2d | 2014-11-19 17:07:11 +0200 | [diff] [blame] | 582 | |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 583 | any resolution check would be testing either: |
| 584 | |
| 585 | * l3 forwarding (tested in test_network_basic_ops) |
| 586 | * Name resolution of an external DNS nameserver - out of scope for |
| 587 | Tempest |
Yair Fried | 413bf2d | 2014-11-19 17:07:11 +0200 | [diff] [blame] | 588 | """ |
| 589 | # this test check only updates (no actual resolution) so using |
| 590 | # arbitrary ip addresses as nameservers, instead of parsing CONF |
| 591 | initial_dns_server = '1.2.3.4' |
| 592 | alt_dns_server = '9.8.7.6' |
Yair Fried | bb0ea39 | 2015-01-19 07:26:08 +0000 | [diff] [blame] | 593 | |
Bence Romsics | 199e022 | 2019-01-28 14:18:00 +0100 | [diff] [blame] | 594 | # Original timeouts are suggested by salvatore-orlando in |
Yair Fried | bb0ea39 | 2015-01-19 07:26:08 +0000 | [diff] [blame] | 595 | # https://bugs.launchpad.net/neutron/+bug/1412325/comments/3 |
Bence Romsics | 199e022 | 2019-01-28 14:18:00 +0100 | [diff] [blame] | 596 | # |
| 597 | # Compared to that renew_delay was increased, because |
| 598 | # busybox's udhcpc accepts SIGUSR1 as a renew request. Internally |
| 599 | # it goes into RENEW_REQUESTED state. If it receives a 2nd SIGUSR1 |
| 600 | # signal while in that state then it calls the deconfig script |
| 601 | # ("/sbin/cirros-dhcpc deconfig" in sufficiently new cirros versions) |
| 602 | # which leads to the address being transiently deconfigured which |
| 603 | # for our case is unwanted. |
| 604 | renew_delay = 3 * CONF.network.build_interval |
Yair Fried | bb0ea39 | 2015-01-19 07:26:08 +0000 | [diff] [blame] | 605 | renew_timeout = CONF.network.build_timeout |
| 606 | |
Yair Fried | 413bf2d | 2014-11-19 17:07:11 +0200 | [diff] [blame] | 607 | self._setup_network_and_servers(dns_nameservers=[initial_dns_server]) |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 608 | self._check_public_network_connectivity(should_connect=True) |
Yair Fried | 413bf2d | 2014-11-19 17:07:11 +0200 | [diff] [blame] | 609 | |
| 610 | floating_ip, server = self.floating_ip_tuple |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 611 | ip_address = floating_ip['floating_ip_address'] |
Yair Fried | 413bf2d | 2014-11-19 17:07:11 +0200 | [diff] [blame] | 612 | private_key = self._get_server_key(server) |
Jordan Pittier | bbb1712 | 2016-01-26 17:10:55 +0100 | [diff] [blame] | 613 | ssh_client = self.get_remote_client( |
zhufl | f52c759 | 2017-05-25 13:55:24 +0800 | [diff] [blame] | 614 | ip_address, private_key=private_key, server=server) |
Yair Fried | 413bf2d | 2014-11-19 17:07:11 +0200 | [diff] [blame] | 615 | |
armando-migliaccio | 424aa41 | 2015-02-22 17:55:17 -0800 | [diff] [blame] | 616 | dns_servers = [initial_dns_server] |
| 617 | servers = ssh_client.get_dns_servers() |
| 618 | self.assertEqual(set(dns_servers), set(servers), |
| 619 | 'Looking for servers: {trgt_serv}. ' |
| 620 | 'Retrieved DNS nameservers: {act_serv} ' |
| 621 | 'From host: {host}.' |
| 622 | .format(host=ssh_client.ssh_client.host, |
| 623 | act_serv=servers, |
| 624 | trgt_serv=dns_servers)) |
Yair Fried | 413bf2d | 2014-11-19 17:07:11 +0200 | [diff] [blame] | 625 | |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 626 | self.subnet = self.subnets_client.update_subnet( |
| 627 | self.subnet['id'], dns_nameservers=[alt_dns_server])['subnet'] |
| 628 | |
Yair Fried | 413bf2d | 2014-11-19 17:07:11 +0200 | [diff] [blame] | 629 | # asserts that Neutron DB has updated the nameservers |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 630 | self.assertEqual([alt_dns_server], self.subnet['dns_nameservers'], |
Yair Fried | 413bf2d | 2014-11-19 17:07:11 +0200 | [diff] [blame] | 631 | "Failed to update subnet's nameservers") |
| 632 | |
Yair Fried | bb0ea39 | 2015-01-19 07:26:08 +0000 | [diff] [blame] | 633 | def check_new_dns_server(): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 634 | # NOTE: Server needs to renew its dhcp lease in order to get new |
| 635 | # definitions from subnet |
| 636 | # NOTE(amuller): we are renewing the lease as part of the retry |
| 637 | # because Neutron updates dnsmasq asynchronously after the |
| 638 | # subnet-update API call returns. |
Ken'ichi Ohmichi | 4e33785 | 2017-03-01 12:04:23 -0800 | [diff] [blame] | 639 | ssh_client.renew_lease(fixed_ip=floating_ip['fixed_ip_address'], |
| 640 | dhcp_client=CONF.scenario.dhcp_client) |
armando-migliaccio | 424aa41 | 2015-02-22 17:55:17 -0800 | [diff] [blame] | 641 | if ssh_client.get_dns_servers() != [alt_dns_server]: |
Yair Fried | bb0ea39 | 2015-01-19 07:26:08 +0000 | [diff] [blame] | 642 | LOG.debug("Failed to update DNS nameservers") |
| 643 | return False |
| 644 | return True |
| 645 | |
Jordan Pittier | 35a6375 | 2016-08-30 13:09:12 +0200 | [diff] [blame] | 646 | self.assertTrue(test_utils.call_until_true(check_new_dns_server, |
| 647 | renew_timeout, |
| 648 | renew_delay), |
Yair Fried | bb0ea39 | 2015-01-19 07:26:08 +0000 | [diff] [blame] | 649 | msg="DHCP renewal failed to fetch " |
| 650 | "new DNS nameservers") |
Thalabathy Venkatesan | 76553d8 | 2015-01-07 22:54:39 -0800 | [diff] [blame] | 651 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 652 | @decorators.idempotent_id('f5dfcc22-45fd-409f-954c-5bd500d7890b') |
Itzik Brown | beb30d3 | 2015-03-29 09:42:54 +0300 | [diff] [blame] | 653 | @testtools.skipUnless(CONF.network_feature_enabled.port_admin_state_change, |
| 654 | "Changing a port's admin state is not supported " |
| 655 | "by the test environment") |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 656 | @decorators.attr(type='slow') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 657 | @utils.services('compute', 'network') |
Thalabathy Venkatesan | 76553d8 | 2015-01-07 22:54:39 -0800 | [diff] [blame] | 658 | def test_update_instance_port_admin_state(self): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 659 | """Test to update admin_state_up attribute of instance port |
| 660 | |
Carlos Goncalves | 539f836 | 2016-11-04 14:55:02 +0100 | [diff] [blame] | 661 | 1. Check public and project connectivity before updating |
Thalabathy Venkatesan | 76553d8 | 2015-01-07 22:54:39 -0800 | [diff] [blame] | 662 | admin_state_up attribute of instance port to False |
Carlos Goncalves | 539f836 | 2016-11-04 14:55:02 +0100 | [diff] [blame] | 663 | 2. Check public and project connectivity after updating |
Thalabathy Venkatesan | 76553d8 | 2015-01-07 22:54:39 -0800 | [diff] [blame] | 664 | admin_state_up attribute of instance port to False |
Carlos Goncalves | 539f836 | 2016-11-04 14:55:02 +0100 | [diff] [blame] | 665 | 3. Check public and project connectivity after updating |
Thalabathy Venkatesan | 76553d8 | 2015-01-07 22:54:39 -0800 | [diff] [blame] | 666 | admin_state_up attribute of instance port to True |
| 667 | """ |
| 668 | self._setup_network_and_servers() |
Ferenc Horváth | bce1fcf | 2017-06-07 11:19:51 +0200 | [diff] [blame] | 669 | _, server = self.floating_ip_tuple |
Thalabathy Venkatesan | 76553d8 | 2015-01-07 22:54:39 -0800 | [diff] [blame] | 670 | server_id = server['id'] |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 671 | port_id = self.os_admin.ports_client.list_ports( |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 672 | device_id=server_id)['ports'][0]['id'] |
Carlos Goncalves | 539f836 | 2016-11-04 14:55:02 +0100 | [diff] [blame] | 673 | server_pip = server['addresses'][self.network['name']][0]['addr'] |
| 674 | |
| 675 | server2 = self._create_server(self.network) |
| 676 | server2_fip = self.create_floating_ip(server2) |
| 677 | |
| 678 | private_key = self._get_server_key(server2) |
| 679 | ssh_client = self.get_remote_client(server2_fip['floating_ip_address'], |
zhufl | f52c759 | 2017-05-25 13:55:24 +0800 | [diff] [blame] | 680 | private_key=private_key, |
| 681 | server=server2) |
Carlos Goncalves | 539f836 | 2016-11-04 14:55:02 +0100 | [diff] [blame] | 682 | |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 683 | self._check_public_network_connectivity( |
Thalabathy Venkatesan | 76553d8 | 2015-01-07 22:54:39 -0800 | [diff] [blame] | 684 | should_connect=True, msg="before updating " |
| 685 | "admin_state_up of instance port to False") |
YAMAMOTO Takashi | 4c3ebb0 | 2017-01-25 16:04:30 +0900 | [diff] [blame] | 686 | self.check_remote_connectivity(ssh_client, dest=server_pip, |
| 687 | should_succeed=True) |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 688 | self.ports_client.update_port(port_id, admin_state_up=False) |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 689 | self._check_public_network_connectivity( |
Thalabathy Venkatesan | 76553d8 | 2015-01-07 22:54:39 -0800 | [diff] [blame] | 690 | should_connect=False, msg="after updating " |
| 691 | "admin_state_up of instance port to False", |
| 692 | should_check_floating_ip_status=False) |
YAMAMOTO Takashi | 4c3ebb0 | 2017-01-25 16:04:30 +0900 | [diff] [blame] | 693 | self.check_remote_connectivity(ssh_client, dest=server_pip, |
| 694 | should_succeed=False) |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 695 | self.ports_client.update_port(port_id, admin_state_up=True) |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 696 | self._check_public_network_connectivity( |
Thalabathy Venkatesan | 76553d8 | 2015-01-07 22:54:39 -0800 | [diff] [blame] | 697 | should_connect=True, msg="after updating " |
| 698 | "admin_state_up of instance port to True") |
YAMAMOTO Takashi | 4c3ebb0 | 2017-01-25 16:04:30 +0900 | [diff] [blame] | 699 | self.check_remote_connectivity(ssh_client, dest=server_pip, |
| 700 | should_succeed=True) |
Matt Riedemann | 1794073 | 2015-03-13 14:18:19 +0000 | [diff] [blame] | 701 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 702 | @decorators.idempotent_id('759462e1-8535-46b0-ab3a-33aa45c55aaa') |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 703 | @decorators.attr(type='slow') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 704 | @utils.services('compute', 'network') |
Matt Riedemann | 1794073 | 2015-03-13 14:18:19 +0000 | [diff] [blame] | 705 | def test_preserve_preexisting_port(self): |
Ken'ichi Ohmichi | 2e2ee19 | 2015-11-19 09:48:27 +0000 | [diff] [blame] | 706 | """Test preserve pre-existing port |
| 707 | |
| 708 | Tests that a pre-existing port provided on server boot is not deleted |
| 709 | if the server is deleted. |
Matt Riedemann | 1794073 | 2015-03-13 14:18:19 +0000 | [diff] [blame] | 710 | |
| 711 | Nova should unbind the port from the instance on delete if the port was |
| 712 | not created by Nova as part of the boot request. |
Matt Riedemann | a8c641a | 2016-07-12 17:07:33 -0400 | [diff] [blame] | 713 | |
| 714 | We should also be able to boot another server with the same port. |
Matt Riedemann | 1794073 | 2015-03-13 14:18:19 +0000 | [diff] [blame] | 715 | """ |
| 716 | # Setup the network, create a port and boot the server from that port. |
| 717 | self._setup_network_and_servers(boot_with_port=True) |
| 718 | _, server = self.floating_ip_tuple |
Shuquan Huang | b5c8beb | 2015-08-05 14:14:01 +0000 | [diff] [blame] | 719 | self.assertEqual(1, len(self.ports), |
| 720 | 'There should only be one port created for ' |
| 721 | 'server %s.' % server['id']) |
| 722 | port_id = self.ports[0]['port'] |
| 723 | self.assertIsNotNone(port_id, |
Matt Riedemann | 1794073 | 2015-03-13 14:18:19 +0000 | [diff] [blame] | 724 | 'Server should have been created from a ' |
| 725 | 'pre-existing port.') |
| 726 | # Assert the port is bound to the server. |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 727 | port_list = self.os_admin.ports_client.list_ports( |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 728 | device_id=server['id'], network_id=self.network['id'])['ports'] |
Matt Riedemann | 1794073 | 2015-03-13 14:18:19 +0000 | [diff] [blame] | 729 | self.assertEqual(1, len(port_list), |
| 730 | 'There should only be one port created for ' |
| 731 | 'server %s.' % server['id']) |
Shuquan Huang | b5c8beb | 2015-08-05 14:14:01 +0000 | [diff] [blame] | 732 | self.assertEqual(port_id, port_list[0]['id']) |
Matt Riedemann | 1794073 | 2015-03-13 14:18:19 +0000 | [diff] [blame] | 733 | # Delete the server. |
| 734 | self.servers_client.delete_server(server['id']) |
Ken'ichi Ohmichi | e91a0c6 | 2015-08-13 02:09:16 +0000 | [diff] [blame] | 735 | waiters.wait_for_server_termination(self.servers_client, server['id']) |
Matt Riedemann | 1794073 | 2015-03-13 14:18:19 +0000 | [diff] [blame] | 736 | # Assert the port still exists on the network but is unbound from |
| 737 | # the deleted server. |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 738 | port = self.ports_client.show_port(port_id)['port'] |
Matt Riedemann | 1794073 | 2015-03-13 14:18:19 +0000 | [diff] [blame] | 739 | self.assertEqual(self.network['id'], port['network_id']) |
| 740 | self.assertEqual('', port['device_id']) |
| 741 | self.assertEqual('', port['device_owner']) |
Yair Fried | 564d89d | 2015-08-06 17:02:12 +0300 | [diff] [blame] | 742 | |
Matt Riedemann | a8c641a | 2016-07-12 17:07:33 -0400 | [diff] [blame] | 743 | # Boot another server with the same port to make sure nothing was |
| 744 | # left around that could cause issues. |
zhufl | 24208c2 | 2016-10-25 15:23:48 +0800 | [diff] [blame] | 745 | server = self._create_server(self.network, port['id']) |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 746 | port_list = self.os_admin.ports_client.list_ports( |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 747 | device_id=server['id'], network_id=self.network['id'])['ports'] |
Matt Riedemann | a8c641a | 2016-07-12 17:07:33 -0400 | [diff] [blame] | 748 | self.assertEqual(1, len(port_list), |
| 749 | 'There should only be one port created for ' |
| 750 | 'server %s.' % server['id']) |
| 751 | self.assertEqual(port['id'], port_list[0]['id']) |
| 752 | |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 753 | @utils.requires_ext(service='network', extension='l3_agent_scheduler') |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 754 | @decorators.idempotent_id('2e788c46-fb3f-4ac9-8f82-0561555bea73') |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 755 | @decorators.attr(type='slow') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 756 | @utils.services('compute', 'network') |
Yair Fried | 564d89d | 2015-08-06 17:02:12 +0300 | [diff] [blame] | 757 | def test_router_rescheduling(self): |
| 758 | """Tests that router can be removed from agent and add to a new agent. |
| 759 | |
| 760 | 1. Verify connectivity |
| 761 | 2. Remove router from all l3-agents |
| 762 | 3. Verify connectivity is down |
| 763 | 4. Assign router to new l3-agent (or old one if no new agent is |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 764 | available) |
Yair Fried | 564d89d | 2015-08-06 17:02:12 +0300 | [diff] [blame] | 765 | 5. Verify connectivity |
| 766 | """ |
| 767 | |
| 768 | # TODO(yfried): refactor this test to be used for other agents (dhcp) |
| 769 | # as well |
| 770 | |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 771 | list_hosts = (self.os_admin.routers_client. |
Yair Fried | 564d89d | 2015-08-06 17:02:12 +0300 | [diff] [blame] | 772 | list_l3_agents_hosting_router) |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 773 | schedule_router = (self.os_admin.network_agents_client. |
Ken'ichi Ohmichi | 70a24e9 | 2016-01-06 01:08:27 +0000 | [diff] [blame] | 774 | create_router_on_l3_agent) |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 775 | unschedule_router = (self.os_admin.network_agents_client. |
Ken'ichi Ohmichi | 70a24e9 | 2016-01-06 01:08:27 +0000 | [diff] [blame] | 776 | delete_router_from_l3_agent) |
Yair Fried | 564d89d | 2015-08-06 17:02:12 +0300 | [diff] [blame] | 777 | |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 778 | agent_list_alive = set( |
| 779 | a["id"] for a in |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 780 | self.os_admin.network_agents_client.list_agents( |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 781 | agent_type="L3 agent")['agents'] if a["alive"] is True |
| 782 | ) |
Yair Fried | 564d89d | 2015-08-06 17:02:12 +0300 | [diff] [blame] | 783 | self._setup_network_and_servers() |
Kevin Benton | 3b63aa1 | 2015-08-27 17:15:44 -0700 | [diff] [blame] | 784 | |
| 785 | # NOTE(kevinbenton): we have to use the admin credentials to check |
Sean Dague | ed6e586 | 2016-04-04 10:49:13 -0400 | [diff] [blame] | 786 | # for the distributed flag because self.router only has a project view. |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 787 | admin = self.os_admin.routers_client.show_router( |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 788 | self.router['id']) |
Kevin Benton | 3b63aa1 | 2015-08-27 17:15:44 -0700 | [diff] [blame] | 789 | if admin['router'].get('distributed', False): |
| 790 | msg = "Rescheduling test does not apply to distributed routers." |
| 791 | raise self.skipException(msg) |
| 792 | |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 793 | self._check_public_network_connectivity(should_connect=True) |
Yair Fried | 564d89d | 2015-08-06 17:02:12 +0300 | [diff] [blame] | 794 | |
| 795 | # remove resource from agents |
| 796 | hosting_agents = set(a["id"] for a in |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 797 | list_hosts(self.router['id'])['agents']) |
shipeiqi | c9a4a10 | 2016-04-20 17:39:03 +0800 | [diff] [blame] | 798 | no_migration = agent_list_alive == hosting_agents |
Yair Fried | 564d89d | 2015-08-06 17:02:12 +0300 | [diff] [blame] | 799 | LOG.info("Router will be assigned to {mig} hosting agent". |
| 800 | format(mig="the same" if no_migration else "a new")) |
| 801 | |
| 802 | for hosting_agent in hosting_agents: |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 803 | unschedule_router(hosting_agent, self.router['id']) |
Yair Fried | 564d89d | 2015-08-06 17:02:12 +0300 | [diff] [blame] | 804 | self.assertNotIn(hosting_agent, |
| 805 | [a["id"] for a in |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 806 | list_hosts(self.router['id'])['agents']], |
Yair Fried | 564d89d | 2015-08-06 17:02:12 +0300 | [diff] [blame] | 807 | 'unscheduling router failed') |
| 808 | |
| 809 | # verify resource is un-functional |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 810 | self._check_public_network_connectivity( |
Yair Fried | 564d89d | 2015-08-06 17:02:12 +0300 | [diff] [blame] | 811 | should_connect=False, |
| 812 | msg='after router unscheduling', |
Yair Fried | 564d89d | 2015-08-06 17:02:12 +0300 | [diff] [blame] | 813 | ) |
| 814 | |
| 815 | # schedule resource to new agent |
| 816 | target_agent = list(hosting_agents if no_migration else |
shipeiqi | c9a4a10 | 2016-04-20 17:39:03 +0800 | [diff] [blame] | 817 | agent_list_alive - hosting_agents)[0] |
Yair Fried | 564d89d | 2015-08-06 17:02:12 +0300 | [diff] [blame] | 818 | schedule_router(target_agent, |
piyush110786 | bc0faa6 | 2015-12-03 14:54:48 +0530 | [diff] [blame] | 819 | router_id=self.router['id']) |
Yair Fried | 564d89d | 2015-08-06 17:02:12 +0300 | [diff] [blame] | 820 | self.assertEqual( |
| 821 | target_agent, |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 822 | list_hosts(self.router['id'])['agents'][0]['id'], |
Yair Fried | 564d89d | 2015-08-06 17:02:12 +0300 | [diff] [blame] | 823 | "Router failed to reschedule. Hosting agent doesn't match " |
| 824 | "target agent") |
| 825 | |
| 826 | # verify resource is functional |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 827 | self._check_public_network_connectivity( |
Yair Fried | 564d89d | 2015-08-06 17:02:12 +0300 | [diff] [blame] | 828 | should_connect=True, |
| 829 | msg='After router rescheduling') |
Yair Fried | bc46f59 | 2015-11-18 16:29:34 +0200 | [diff] [blame] | 830 | |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 831 | @utils.requires_ext(service='network', extension='port-security') |
Evgeny Antyshev | aaf3fc9 | 2016-02-15 11:49:22 +0000 | [diff] [blame] | 832 | @testtools.skipUnless(CONF.compute_feature_enabled.interface_attach, |
| 833 | 'NIC hotplug not available') |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 834 | @decorators.idempotent_id('7c0bb1a2-d053-49a4-98f9-ca1a1d849f63') |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 835 | @decorators.attr(type='slow') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 836 | @utils.services('compute', 'network') |
Yair Fried | bc46f59 | 2015-11-18 16:29:34 +0200 | [diff] [blame] | 837 | def test_port_security_macspoofing_port(self): |
| 838 | """Tests port_security extension enforces mac spoofing |
| 839 | |
Eran Kuris | 7969e80 | 2015-12-15 13:43:46 +0200 | [diff] [blame] | 840 | Neutron security groups always apply anti-spoof rules on the VMs. This |
| 841 | allows traffic to originate and terminate at the VM as expected, but |
| 842 | prevents traffic to pass through the VM. Anti-spoof rules are not |
| 843 | required in cases where the VM routes traffic through it. |
| 844 | |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 845 | The test steps are: |
| 846 | |
Eran Kuris | 7969e80 | 2015-12-15 13:43:46 +0200 | [diff] [blame] | 847 | 1. Create a new network. |
| 848 | 2. Connect (hotplug) the VM to a new network. |
YAMAMOTO Takashi | c397841 | 2015-11-30 23:55:56 +0900 | [diff] [blame] | 849 | 3. Check the VM can ping a server on the new network ("peer") |
Eran Kuris | 7969e80 | 2015-12-15 13:43:46 +0200 | [diff] [blame] | 850 | 4. Spoof the mac address of the new VM interface. |
| 851 | 5. Check the Security Group enforces mac spoofing and blocks pings via |
YAMAMOTO Takashi | c397841 | 2015-11-30 23:55:56 +0900 | [diff] [blame] | 852 | spoofed interface (VM cannot ping the peer). |
Eran Kuris | 7969e80 | 2015-12-15 13:43:46 +0200 | [diff] [blame] | 853 | 6. Disable port-security of the spoofed port- set the flag to false. |
| 854 | 7. Retest 3rd step and check that the Security Group allows pings via |
Sergey Vilgelm | eac094a | 2018-11-21 18:27:51 -0600 | [diff] [blame] | 855 | the spoofed interface. |
Yair Fried | bc46f59 | 2015-11-18 16:29:34 +0200 | [diff] [blame] | 856 | """ |
Eran Kuris | 7969e80 | 2015-12-15 13:43:46 +0200 | [diff] [blame] | 857 | |
Yair Fried | bc46f59 | 2015-11-18 16:29:34 +0200 | [diff] [blame] | 858 | spoof_mac = "00:00:00:00:00:01" |
| 859 | |
| 860 | # Create server |
| 861 | self._setup_network_and_servers() |
zhufl | 0ec74c4 | 2017-11-15 14:02:28 +0800 | [diff] [blame] | 862 | self._check_public_network_connectivity(should_connect=True) |
Yair Fried | bc46f59 | 2015-11-18 16:29:34 +0200 | [diff] [blame] | 863 | self._create_new_network() |
| 864 | self._hotplug_server() |
| 865 | fip, server = self.floating_ip_tuple |
jeremy.zhang | 5870ff1 | 2017-05-25 11:24:23 +0800 | [diff] [blame] | 866 | new_ports = self.os_admin.ports_client.list_ports( |
Jordan Pittier | 64e6b44 | 2017-02-20 19:29:02 +0100 | [diff] [blame] | 867 | device_id=server["id"], network_id=self.new_net["id"])['ports'] |
Yair Fried | bc46f59 | 2015-11-18 16:29:34 +0200 | [diff] [blame] | 868 | spoof_port = new_ports[0] |
| 869 | private_key = self._get_server_key(server) |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 870 | ssh_client = self.get_remote_client(fip['floating_ip_address'], |
zhufl | f52c759 | 2017-05-25 13:55:24 +0800 | [diff] [blame] | 871 | private_key=private_key, |
| 872 | server=server) |
Evgeny Antyshev | 9b77ae5 | 2016-02-16 09:48:57 +0000 | [diff] [blame] | 873 | spoof_nic = ssh_client.get_nic_name_by_mac(spoof_port["mac_address"]) |
zhufl | 24208c2 | 2016-10-25 15:23:48 +0800 | [diff] [blame] | 874 | peer = self._create_server(self.new_net) |
Steve Heyman | 33735f2 | 2016-05-24 09:28:08 -0500 | [diff] [blame] | 875 | peer_address = peer['addresses'][self.new_net['name']][0]['addr'] |
YAMAMOTO Takashi | 4c3ebb0 | 2017-01-25 16:04:30 +0900 | [diff] [blame] | 876 | self.check_remote_connectivity(ssh_client, dest=peer_address, |
| 877 | nic=spoof_nic, should_succeed=True) |
Ken'ichi Ohmichi | 5129c62 | 2017-03-22 11:18:42 -0700 | [diff] [blame] | 878 | # Set a mac address by making nic down temporary |
| 879 | cmd = ("sudo ip link set {nic} down;" |
| 880 | "sudo ip link set dev {nic} address {mac};" |
| 881 | "sudo ip link set {nic} up").format(nic=spoof_nic, |
| 882 | mac=spoof_mac) |
| 883 | ssh_client.exec_command(cmd) |
| 884 | |
Yair Fried | bc46f59 | 2015-11-18 16:29:34 +0200 | [diff] [blame] | 885 | new_mac = ssh_client.get_mac_address(nic=spoof_nic) |
| 886 | self.assertEqual(spoof_mac, new_mac) |
YAMAMOTO Takashi | 4c3ebb0 | 2017-01-25 16:04:30 +0900 | [diff] [blame] | 887 | self.check_remote_connectivity(ssh_client, dest=peer_address, |
| 888 | nic=spoof_nic, should_succeed=False) |
Yair Fried | bc46f59 | 2015-11-18 16:29:34 +0200 | [diff] [blame] | 889 | self.ports_client.update_port(spoof_port["id"], |
| 890 | port_security_enabled=False, |
| 891 | security_groups=[]) |
YAMAMOTO Takashi | 4c3ebb0 | 2017-01-25 16:04:30 +0900 | [diff] [blame] | 892 | self.check_remote_connectivity(ssh_client, dest=peer_address, |
| 893 | nic=spoof_nic, should_succeed=True) |