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 | |
Adam Gandelman | 7186f7a | 2014-07-23 09:28:56 -0400 | [diff] [blame] | 19 | import testtools |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 20 | |
Attila Fazekas | aeeeefd | 2013-08-06 17:01:56 +0200 | [diff] [blame] | 21 | from tempest.common import debug |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 22 | from tempest.common.utils import data_utils |
Matthew Treinish | cb56994 | 2013-08-09 16:33:44 -0400 | [diff] [blame] | 23 | from tempest import config |
Attila Fazekas | a8bb394 | 2014-08-19 09:06:30 +0200 | [diff] [blame] | 24 | from tempest import exceptions |
Matthew Treinish | 2b59f84 | 2013-09-09 20:32:51 +0000 | [diff] [blame] | 25 | from tempest.openstack.common import log as logging |
Sean Dague | 6dbc6da | 2013-05-08 17:49:46 -0400 | [diff] [blame] | 26 | from tempest.scenario import manager |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 27 | from tempest.services.network import resources as net_resources |
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 | |
| 39 | """ |
| 40 | This smoke test suite assumes that Nova has been configured to |
Mark McClain | f2982e8 | 2013-07-06 17:48:03 -0400 | [diff] [blame] | 41 | boot VM's with Neutron-managed networking, and attempts to |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 42 | verify network connectivity as follows: |
| 43 | |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 44 | There are presumed to be two types of networks: tenant and |
| 45 | public. A tenant network may or may not be reachable from the |
| 46 | Tempest host. A public network is assumed to be reachable from |
| 47 | the Tempest host, and it should be possible to associate a public |
| 48 | ('floating') IP address with a tenant ('fixed') IP address to |
Chang Bo Guo | cc1623c | 2013-09-13 20:11:27 -0700 | [diff] [blame] | 49 | facilitate external connectivity to a potentially unroutable |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 50 | tenant IP address. |
| 51 | |
| 52 | This test suite can be configured to test network connectivity to |
| 53 | a VM via a tenant network, a public network, or both. If both |
| 54 | networking types are to be evaluated, tests that need to be |
| 55 | executed remotely on the VM (via ssh) will only be run against |
| 56 | one of the networks (to minimize test execution time). |
| 57 | |
| 58 | Determine which types of networks to test as follows: |
| 59 | |
| 60 | * Configure tenant network checks (via the |
| 61 | 'tenant_networks_reachable' key) if the Tempest host should |
| 62 | have direct connectivity to tenant networks. This is likely to |
| 63 | be the case if Tempest is running on the same host as a |
| 64 | single-node devstack installation with IP namespaces disabled. |
| 65 | |
| 66 | * Configure checks for a public network if a public network has |
| 67 | been configured prior to the test suite being run and if the |
| 68 | Tempest host should have connectivity to that public network. |
| 69 | Checking connectivity for a public network requires that a |
| 70 | value be provided for 'public_network_id'. A value can |
| 71 | optionally be provided for 'public_router_id' if tenants will |
| 72 | use a shared router to access a public network (as is likely to |
| 73 | be the case when IP namespaces are not enabled). If a value is |
| 74 | not provided for 'public_router_id', a router will be created |
| 75 | for each tenant and use the network identified by |
| 76 | 'public_network_id' as its gateway. |
| 77 | |
| 78 | """ |
| 79 | |
| 80 | @classmethod |
| 81 | def check_preconditions(cls): |
Gavin Brebner | 0f465a3 | 2013-03-14 13:26:09 +0000 | [diff] [blame] | 82 | super(TestNetworkBasicOps, cls).check_preconditions() |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 83 | if not (CONF.network.tenant_networks_reachable |
| 84 | or CONF.network.public_network_id): |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 85 | msg = ('Either tenant_networks_reachable must be "true", or ' |
| 86 | 'public_network_id must be defined.') |
Gavin Brebner | 0f465a3 | 2013-03-14 13:26:09 +0000 | [diff] [blame] | 87 | cls.enabled = False |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 88 | raise cls.skipException(msg) |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 89 | |
| 90 | @classmethod |
Andrea Frittoli | ac20b5e | 2014-09-15 13:31:14 +0100 | [diff] [blame] | 91 | def resource_setup(cls): |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 92 | for ext in ['router', 'security-group']: |
| 93 | if not test.is_extension_enabled(ext, 'network'): |
| 94 | msg = "%s extension not enabled." % ext |
| 95 | raise cls.skipException(msg) |
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() |
| 98 | super(TestNetworkBasicOps, cls).resource_setup() |
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 | |
| 105 | def _setup_network_and_servers(self): |
| 106 | self.security_group = \ |
| 107 | self._create_security_group(tenant_id=self.tenant_id) |
| 108 | self.network, self.subnet, self.router = self.create_networks() |
| 109 | self.check_networks() |
| 110 | |
Yair Fried | ed8392f | 2014-01-15 17:21:35 +0200 | [diff] [blame] | 111 | name = data_utils.rand_name('server-smoke') |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 112 | server = self._create_server(name, self.network) |
Yair Fried | ed8392f | 2014-01-15 17:21:35 +0200 | [diff] [blame] | 113 | self._check_tenant_network_connectivity() |
Yair Fried | 2d2f3fe | 2014-02-24 16:19:20 +0200 | [diff] [blame] | 114 | |
Yair Fried | ae0e73d | 2014-11-24 11:56:26 +0200 | [diff] [blame] | 115 | floating_ip = self.create_floating_ip(server) |
| 116 | self.floating_ip_tuple = Floating_IP_tuple(floating_ip, server) |
Maru Newby | 81f07a0 | 2012-09-05 20:21:19 -0700 | [diff] [blame] | 117 | |
Yair Fried | ed8392f | 2014-01-15 17:21:35 +0200 | [diff] [blame] | 118 | def check_networks(self): |
| 119 | """ |
| 120 | Checks that we see the newly created network/subnet/router via |
| 121 | checking the result of list_[networks,routers,subnets] |
| 122 | """ |
| 123 | |
Gavin Brebner | 851c350 | 2013-01-18 13:14:10 +0000 | [diff] [blame] | 124 | seen_nets = self._list_networks() |
| 125 | seen_names = [n['name'] for n in seen_nets] |
| 126 | seen_ids = [n['id'] for n in seen_nets] |
Yair Fried | ed8392f | 2014-01-15 17:21:35 +0200 | [diff] [blame] | 127 | self.assertIn(self.network.name, seen_names) |
| 128 | self.assertIn(self.network.id, seen_ids) |
| 129 | |
David Shrewsbury | 9bac366 | 2014-08-07 15:07:01 -0400 | [diff] [blame] | 130 | if self.subnet: |
| 131 | seen_subnets = self._list_subnets() |
| 132 | seen_net_ids = [n['network_id'] for n in seen_subnets] |
| 133 | seen_subnet_ids = [n['id'] for n in seen_subnets] |
| 134 | self.assertIn(self.network.id, seen_net_ids) |
| 135 | self.assertIn(self.subnet.id, seen_subnet_ids) |
Yair Fried | ed8392f | 2014-01-15 17:21:35 +0200 | [diff] [blame] | 136 | |
David Shrewsbury | 9bac366 | 2014-08-07 15:07:01 -0400 | [diff] [blame] | 137 | if self.router: |
| 138 | seen_routers = self._list_routers() |
| 139 | seen_router_ids = [n['id'] for n in seen_routers] |
| 140 | seen_router_names = [n['name'] for n in seen_routers] |
| 141 | self.assertIn(self.router.name, |
| 142 | seen_router_names) |
| 143 | self.assertIn(self.router.id, |
| 144 | seen_router_ids) |
Gavin Brebner | 851c350 | 2013-01-18 13:14:10 +0000 | [diff] [blame] | 145 | |
Salvatore Orlando | 5ed3b6e | 2013-09-17 01:27:26 -0700 | [diff] [blame] | 146 | def _create_server(self, name, network): |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 147 | keypair = self.create_keypair() |
| 148 | self.keypairs[keypair['name']] = keypair |
Ken'ichi Ohmichi | 1b3461e | 2014-12-02 03:41:07 +0000 | [diff] [blame] | 149 | security_groups = [{'name': self.security_group['name']}] |
Salvatore Orlando | 5ed3b6e | 2013-09-17 01:27:26 -0700 | [diff] [blame] | 150 | create_kwargs = { |
Dirk Mueller | 8cf7972 | 2014-09-12 17:37:15 +0200 | [diff] [blame] | 151 | 'networks': [ |
| 152 | {'uuid': network.id}, |
Salvatore Orlando | 5ed3b6e | 2013-09-17 01:27:26 -0700 | [diff] [blame] | 153 | ], |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 154 | 'key_name': keypair['name'], |
Salvatore Orlando | 5ed3b6e | 2013-09-17 01:27:26 -0700 | [diff] [blame] | 155 | 'security_groups': security_groups, |
| 156 | } |
Giulio Fidente | 61cadca | 2013-09-24 18:33:37 +0200 | [diff] [blame] | 157 | server = self.create_server(name=name, create_kwargs=create_kwargs) |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 158 | self.servers.append(server) |
| 159 | return server |
| 160 | |
| 161 | def _get_server_key(self, server): |
| 162 | return self.keypairs[server['key_name']]['private_key'] |
Salvatore Orlando | 5ed3b6e | 2013-09-17 01:27:26 -0700 | [diff] [blame] | 163 | |
Matthew Treinish | 2b59f84 | 2013-09-09 20:32:51 +0000 | [diff] [blame] | 164 | def _check_tenant_network_connectivity(self): |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 165 | ssh_login = CONF.compute.image_ssh_user |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 166 | for server in self.servers: |
Matt Riedemann | 2d005be | 2014-05-27 10:52:35 -0700 | [diff] [blame] | 167 | # call the common method in the parent class |
| 168 | super(TestNetworkBasicOps, self).\ |
| 169 | _check_tenant_network_connectivity( |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 170 | server, ssh_login, self._get_server_key(server), |
| 171 | servers_for_debug=self.servers) |
Brent Eagles | c26d452 | 2013-12-02 13:28:49 -0500 | [diff] [blame] | 172 | |
Yair Fried | ae0e73d | 2014-11-24 11:56:26 +0200 | [diff] [blame] | 173 | def check_public_network_connectivity(self, should_connect=True, |
| 174 | msg=None): |
Yair Fried | 45f9295 | 2014-06-26 05:19:19 +0300 | [diff] [blame] | 175 | """Verifies connectivty to a VM via public network and floating IP, |
| 176 | and verifies floating IP has resource status is correct. |
| 177 | |
Yair Fried | 45f9295 | 2014-06-26 05:19:19 +0300 | [diff] [blame] | 178 | :param should_connect: bool. determines if connectivity check is |
| 179 | negative or positive. |
| 180 | :param msg: Failure message to add to Error message. Should describe |
| 181 | the place in the test scenario where the method was called, |
| 182 | to indicate the context of the failure |
| 183 | """ |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 184 | ssh_login = CONF.compute.image_ssh_user |
Yair Fried | 2d2f3fe | 2014-02-24 16:19:20 +0200 | [diff] [blame] | 185 | floating_ip, server = self.floating_ip_tuple |
| 186 | ip_address = floating_ip.floating_ip_address |
| 187 | private_key = None |
Yair Fried | 45f9295 | 2014-06-26 05:19:19 +0300 | [diff] [blame] | 188 | floatingip_status = 'DOWN' |
Yair Fried | 2d2f3fe | 2014-02-24 16:19:20 +0200 | [diff] [blame] | 189 | if should_connect: |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 190 | private_key = self._get_server_key(server) |
Yair Fried | 45f9295 | 2014-06-26 05:19:19 +0300 | [diff] [blame] | 191 | floatingip_status = 'ACTIVE' |
Matt Riedemann | 343305f | 2014-05-27 09:55:03 -0700 | [diff] [blame] | 192 | # call the common method in the parent class |
Yair Fried | ae0e73d | 2014-11-24 11:56:26 +0200 | [diff] [blame] | 193 | super(TestNetworkBasicOps, self).check_public_network_connectivity( |
Matt Riedemann | 343305f | 2014-05-27 09:55:03 -0700 | [diff] [blame] | 194 | ip_address, ssh_login, private_key, should_connect, msg, |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 195 | self.servers) |
Yair Fried | 45f9295 | 2014-06-26 05:19:19 +0300 | [diff] [blame] | 196 | self.check_floating_ip_status(floating_ip, floatingip_status) |
Matthew Treinish | 2b59f84 | 2013-09-09 20:32:51 +0000 | [diff] [blame] | 197 | |
Yair Fried | 9a551c4 | 2013-12-15 14:59:34 +0200 | [diff] [blame] | 198 | def _disassociate_floating_ips(self): |
Yair Fried | 2d2f3fe | 2014-02-24 16:19:20 +0200 | [diff] [blame] | 199 | floating_ip, server = self.floating_ip_tuple |
| 200 | self._disassociate_floating_ip(floating_ip) |
| 201 | self.floating_ip_tuple = Floating_IP_tuple( |
| 202 | floating_ip, None) |
Yair Fried | 9a551c4 | 2013-12-15 14:59:34 +0200 | [diff] [blame] | 203 | |
Yair Fried | 05db252 | 2013-11-18 11:02:10 +0200 | [diff] [blame] | 204 | def _reassociate_floating_ips(self): |
Yair Fried | 2d2f3fe | 2014-02-24 16:19:20 +0200 | [diff] [blame] | 205 | floating_ip, server = self.floating_ip_tuple |
| 206 | name = data_utils.rand_name('new_server-smoke-') |
| 207 | # create a new server for the floating ip |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 208 | server = self._create_server(name, self.network) |
| 209 | self._associate_floating_ip(floating_ip, server) |
Yair Fried | 2d2f3fe | 2014-02-24 16:19:20 +0200 | [diff] [blame] | 210 | self.floating_ip_tuple = Floating_IP_tuple( |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 211 | floating_ip, server) |
Yair Fried | 05db252 | 2013-11-18 11:02:10 +0200 | [diff] [blame] | 212 | |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 213 | def _create_new_network(self): |
Yair Fried | db6c9e9 | 2014-08-06 08:53:13 +0300 | [diff] [blame] | 214 | self.new_net = self._create_network(tenant_id=self.tenant_id) |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 215 | self.new_subnet = self._create_subnet( |
| 216 | network=self.new_net, |
| 217 | gateway_ip=None) |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 218 | |
| 219 | def _hotplug_server(self): |
| 220 | old_floating_ip, server = self.floating_ip_tuple |
| 221 | ip_address = old_floating_ip.floating_ip_address |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 222 | private_key = self._get_server_key(server) |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 223 | ssh_client = self.get_remote_client(ip_address, |
| 224 | private_key=private_key) |
| 225 | old_nic_list = self._get_server_nics(ssh_client) |
| 226 | # get a port from a list of one item |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 227 | port_list = self._list_ports(device_id=server['id']) |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 228 | self.assertEqual(1, len(port_list)) |
| 229 | old_port = port_list[0] |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 230 | _, interface = self.interface_client.create_interface( |
| 231 | server=server['id'], |
| 232 | network_id=self.new_net.id) |
| 233 | self.addCleanup(self.network_client.wait_for_resource_deletion, |
| 234 | 'port', |
| 235 | interface['port_id']) |
| 236 | self.addCleanup(self.delete_wrapper, |
| 237 | self.interface_client.delete_interface, |
| 238 | server['id'], interface['port_id']) |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 239 | |
| 240 | def check_ports(): |
Attila Fazekas | a8bb394 | 2014-08-19 09:06:30 +0200 | [diff] [blame] | 241 | self.new_port_list = [port for port in |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 242 | self._list_ports(device_id=server['id']) |
Attila Fazekas | a8bb394 | 2014-08-19 09:06:30 +0200 | [diff] [blame] | 243 | if port != old_port] |
| 244 | return len(self.new_port_list) == 1 |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 245 | |
Attila Fazekas | a8bb394 | 2014-08-19 09:06:30 +0200 | [diff] [blame] | 246 | if not test.call_until_true(check_ports, CONF.network.build_timeout, |
| 247 | CONF.network.build_interval): |
| 248 | raise exceptions.TimeoutException("No new port attached to the " |
| 249 | "server in time (%s sec) !" |
| 250 | % CONF.network.build_timeout) |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 251 | new_port = net_resources.DeletablePort(client=self.network_client, |
| 252 | **self.new_port_list[0]) |
Attila Fazekas | a8bb394 | 2014-08-19 09:06:30 +0200 | [diff] [blame] | 253 | |
| 254 | def check_new_nic(): |
| 255 | new_nic_list = self._get_server_nics(ssh_client) |
| 256 | self.diff_list = [n for n in new_nic_list if n not in old_nic_list] |
| 257 | return len(self.diff_list) == 1 |
| 258 | |
| 259 | if not test.call_until_true(check_new_nic, CONF.network.build_timeout, |
| 260 | CONF.network.build_interval): |
| 261 | raise exceptions.TimeoutException("Interface not visible on the " |
| 262 | "guest after %s sec" |
| 263 | % CONF.network.build_timeout) |
| 264 | |
| 265 | num, new_nic = self.diff_list[0] |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 266 | ssh_client.assign_static_ip(nic=new_nic, |
| 267 | addr=new_port.fixed_ips[0]['ip_address']) |
| 268 | ssh_client.turn_nic_on(nic=new_nic) |
| 269 | |
| 270 | def _get_server_nics(self, ssh_client): |
| 271 | reg = re.compile(r'(?P<num>\d+): (?P<nic_name>\w+):') |
| 272 | ipatxt = ssh_client.get_ip_list() |
| 273 | return reg.findall(ipatxt) |
| 274 | |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 275 | def _check_network_internal_connectivity(self, network): |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 276 | """ |
| 277 | via ssh check VM internal connectivity: |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 278 | - ping internal gateway and DHCP port, implying in-tenant connectivity |
| 279 | pinging both, because L3 and DHCP agents might be on different nodes |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 280 | """ |
| 281 | floating_ip, server = self.floating_ip_tuple |
| 282 | # get internal ports' ips: |
| 283 | # get all network ports in the new network |
| 284 | internal_ips = (p['fixed_ips'][0]['ip_address'] for p in |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 285 | self._list_ports(tenant_id=server['tenant_id'], |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 286 | network_id=network.id) |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 287 | if p['device_owner'].startswith('network')) |
| 288 | |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 289 | self._check_server_connectivity(floating_ip, internal_ips) |
| 290 | |
| 291 | def _check_network_external_connectivity(self): |
| 292 | """ |
| 293 | ping public network default gateway to imply external connectivity |
| 294 | |
| 295 | """ |
| 296 | if not CONF.network.public_network_id: |
| 297 | msg = 'public network not defined.' |
| 298 | LOG.info(msg) |
| 299 | return |
| 300 | |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 301 | subnet = self._list_subnets( |
| 302 | network_id=CONF.network.public_network_id) |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 303 | self.assertEqual(1, len(subnet), "Found %d subnets" % len(subnet)) |
| 304 | |
| 305 | external_ips = [subnet[0]['gateway_ip']] |
| 306 | self._check_server_connectivity(self.floating_ip_tuple.floating_ip, |
| 307 | external_ips) |
| 308 | |
| 309 | def _check_server_connectivity(self, floating_ip, address_list): |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 310 | ip_address = floating_ip.floating_ip_address |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 311 | private_key = self._get_server_key(self.floating_ip_tuple.server) |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 312 | ssh_source = self._ssh_to_server(ip_address, private_key) |
| 313 | |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 314 | for remote_ip in address_list: |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 315 | try: |
| 316 | self.assertTrue(self._check_remote_connectivity(ssh_source, |
| 317 | remote_ip), |
| 318 | "Timed out waiting for %s to become " |
| 319 | "reachable" % remote_ip) |
| 320 | except Exception: |
| 321 | LOG.exception("Unable to access {dest} via ssh to " |
| 322 | "floating-ip {src}".format(dest=remote_ip, |
| 323 | src=floating_ip)) |
| 324 | debug.log_ip_ns() |
| 325 | raise |
| 326 | |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 327 | @test.attr(type='smoke') |
| 328 | @test.services('compute', 'network') |
Matthew Treinish | 2b59f84 | 2013-09-09 20:32:51 +0000 | [diff] [blame] | 329 | def test_network_basic_ops(self): |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 330 | """ |
| 331 | For a freshly-booted VM with an IP address ("port") on a given |
| 332 | network: |
| 333 | |
| 334 | - the Tempest host can ping the IP address. This implies, but |
| 335 | does not guarantee (see the ssh check that follows), that the |
| 336 | VM has been assigned the correct IP address and has |
| 337 | connectivity to the Tempest host. |
| 338 | |
| 339 | - the Tempest host can perform key-based authentication to an |
| 340 | ssh server hosted at the IP address. This check guarantees |
| 341 | that the IP address is associated with the target VM. |
| 342 | |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 343 | - the Tempest host can ssh into the VM via the IP address and |
| 344 | successfully execute the following: |
| 345 | |
| 346 | - ping an external IP address, implying external connectivity. |
| 347 | |
| 348 | - ping an external hostname, implying that dns is correctly |
| 349 | configured. |
| 350 | |
| 351 | - ping an internal IP address, implying connectivity to another |
| 352 | VM on the same network. |
| 353 | |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 354 | - detach the floating-ip from the VM and verify that it becomes |
| 355 | unreachable |
| 356 | |
| 357 | - associate detached floating ip to a new VM and verify connectivity. |
| 358 | VMs are created with unique keypair so connectivity also asserts that |
| 359 | floating IP is associated with the new VM instead of the old one |
| 360 | |
Yair Fried | 45f9295 | 2014-06-26 05:19:19 +0300 | [diff] [blame] | 361 | Verifies that floating IP status is updated correctly after each change |
| 362 | |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 363 | |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 364 | """ |
David Shrewsbury | 9bac366 | 2014-08-07 15:07:01 -0400 | [diff] [blame] | 365 | self._setup_network_and_servers() |
Yair Fried | ae0e73d | 2014-11-24 11:56:26 +0200 | [diff] [blame] | 366 | self.check_public_network_connectivity(should_connect=True) |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 367 | self._check_network_internal_connectivity(network=self.network) |
| 368 | self._check_network_external_connectivity() |
Yair Fried | 9a551c4 | 2013-12-15 14:59:34 +0200 | [diff] [blame] | 369 | self._disassociate_floating_ips() |
Yair Fried | ae0e73d | 2014-11-24 11:56:26 +0200 | [diff] [blame] | 370 | self.check_public_network_connectivity(should_connect=False, |
| 371 | msg="after disassociate " |
| 372 | "floating ip") |
Yair Fried | 05db252 | 2013-11-18 11:02:10 +0200 | [diff] [blame] | 373 | self._reassociate_floating_ips() |
Yair Fried | ae0e73d | 2014-11-24 11:56:26 +0200 | [diff] [blame] | 374 | self.check_public_network_connectivity(should_connect=True, |
| 375 | msg="after re-associate " |
| 376 | "floating ip") |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 377 | |
Adam Gandelman | 7186f7a | 2014-07-23 09:28:56 -0400 | [diff] [blame] | 378 | @testtools.skipUnless(CONF.compute_feature_enabled.interface_attach, |
| 379 | 'NIC hotplug not available') |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 380 | @test.attr(type='smoke') |
| 381 | @test.services('compute', 'network') |
| 382 | def test_hotplug_nic(self): |
| 383 | """ |
| 384 | 1. create a new network, with no gateway (to prevent overwriting VM's |
| 385 | gateway) |
| 386 | 2. connect VM to new network |
| 387 | 3. set static ip and bring new nic up |
| 388 | 4. check VM can ping new network dhcp port |
| 389 | |
| 390 | """ |
David Shrewsbury | 9bac366 | 2014-08-07 15:07:01 -0400 | [diff] [blame] | 391 | self._setup_network_and_servers() |
Yair Fried | ae0e73d | 2014-11-24 11:56:26 +0200 | [diff] [blame] | 392 | self.check_public_network_connectivity(should_connect=True) |
Yair Fried | 3097dc1 | 2014-01-26 08:46:43 +0200 | [diff] [blame] | 393 | self._create_new_network() |
| 394 | self._hotplug_server() |
Yair Fried | 0655229 | 2013-11-11 12:10:09 +0200 | [diff] [blame] | 395 | self._check_network_internal_connectivity(network=self.new_net) |