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