blob: f4db8780f21ac868a94679b017367f1b1cd37a7a [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Gavin Brebner0f465a32013-03-14 13:26:09 +00002# Copyright 2013 Hewlett-Packard Development Company, L.P.
Maru Newby81f07a02012-09-05 20:21:19 -07003# 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 Fried2d2f3fe2014-02-24 16:19:20 +020016import collections
Yair Fried3097dc12014-01-26 08:46:43 +020017import re
Matthew Treinish96e9e882014-06-09 18:37:19 -040018
Adam Gandelman7186f7a2014-07-23 09:28:56 -040019import testtools
Yair Fried3097dc12014-01-26 08:46:43 +020020
Masayuki Igawa259c1132013-10-31 17:48:44 +090021from tempest.common.utils import data_utils
Matthew Treinishcb569942013-08-09 16:33:44 -040022from tempest import config
Attila Fazekasa8bb3942014-08-19 09:06:30 +020023from tempest import exceptions
Matthew Treinish2b59f842013-09-09 20:32:51 +000024from tempest.openstack.common import log as logging
Sean Dague6dbc6da2013-05-08 17:49:46 -040025from tempest.scenario import manager
Yair Fried1fc32a12014-08-04 09:11:30 +030026from tempest.services.network import resources as net_resources
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090027from tempest import test
Maru Newby81f07a02012-09-05 20:21:19 -070028
Sean Dague86bd8422013-12-20 09:56:44 -050029CONF = config.CONF
Matthew Treinish2b59f842013-09-09 20:32:51 +000030LOG = logging.getLogger(__name__)
31
Yair Fried2d2f3fe2014-02-24 16:19:20 +020032Floating_IP_tuple = collections.namedtuple('Floating_IP_tuple',
33 ['floating_ip', 'server'])
34
Maru Newby81f07a02012-09-05 20:21:19 -070035
Andrea Frittoli4971fc82014-09-25 10:22:20 +010036class TestNetworkBasicOps(manager.NetworkScenarioTest):
Maru Newby81f07a02012-09-05 20:21:19 -070037
38 """
39 This smoke test suite assumes that Nova has been configured to
Mark McClainf2982e82013-07-06 17:48:03 -040040 boot VM's with Neutron-managed networking, and attempts to
Maru Newby81f07a02012-09-05 20:21:19 -070041 verify network connectivity as follows:
42
Maru Newby81f07a02012-09-05 20:21:19 -070043 There are presumed to be two types of networks: tenant and
44 public. A tenant network may or may not be reachable from the
45 Tempest host. A public network is assumed to be reachable from
46 the Tempest host, and it should be possible to associate a public
47 ('floating') IP address with a tenant ('fixed') IP address to
Chang Bo Guocc1623c2013-09-13 20:11:27 -070048 facilitate external connectivity to a potentially unroutable
Maru Newby81f07a02012-09-05 20:21:19 -070049 tenant IP address.
50
51 This test suite can be configured to test network connectivity to
52 a VM via a tenant network, a public network, or both. If both
53 networking types are to be evaluated, tests that need to be
54 executed remotely on the VM (via ssh) will only be run against
55 one of the networks (to minimize test execution time).
56
57 Determine which types of networks to test as follows:
58
59 * Configure tenant network checks (via the
60 'tenant_networks_reachable' key) if the Tempest host should
61 have direct connectivity to tenant networks. This is likely to
62 be the case if Tempest is running on the same host as a
63 single-node devstack installation with IP namespaces disabled.
64
65 * Configure checks for a public network if a public network has
66 been configured prior to the test suite being run and if the
67 Tempest host should have connectivity to that public network.
68 Checking connectivity for a public network requires that a
69 value be provided for 'public_network_id'. A value can
70 optionally be provided for 'public_router_id' if tenants will
71 use a shared router to access a public network (as is likely to
72 be the case when IP namespaces are not enabled). If a value is
73 not provided for 'public_router_id', a router will be created
74 for each tenant and use the network identified by
75 'public_network_id' as its gateway.
76
77 """
78
79 @classmethod
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000080 def skip_checks(cls):
81 super(TestNetworkBasicOps, cls).skip_checks()
Matthew Treinish6c072292014-01-29 19:15:52 +000082 if not (CONF.network.tenant_networks_reachable
83 or CONF.network.public_network_id):
Maru Newby81f07a02012-09-05 20:21:19 -070084 msg = ('Either tenant_networks_reachable must be "true", or '
85 'public_network_id must be defined.')
ivan-zhu1feeb382013-01-24 10:14:39 +080086 raise cls.skipException(msg)
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090087 for ext in ['router', 'security-group']:
88 if not test.is_extension_enabled(ext, 'network'):
89 msg = "%s extension not enabled." % ext
90 raise cls.skipException(msg)
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000091
92 @classmethod
93 def setup_credentials(cls):
Masayuki Igawa60ea6c52014-10-15 17:32:14 +090094 # Create no network resources for these tests.
95 cls.set_network_resources()
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000096 super(TestNetworkBasicOps, cls).setup_credentials()
Maru Newby81f07a02012-09-05 20:21:19 -070097
Yair Frieded8392f2014-01-15 17:21:35 +020098 def setUp(self):
99 super(TestNetworkBasicOps, self).setUp()
Yair Fried1fc32a12014-08-04 09:11:30 +0300100 self.keypairs = {}
101 self.servers = []
David Shrewsbury9bac3662014-08-07 15:07:01 -0400102
Yair Fried413bf2d2014-11-19 17:07:11 +0200103 def _setup_network_and_servers(self, **kwargs):
David Shrewsbury9bac3662014-08-07 15:07:01 -0400104 self.security_group = \
105 self._create_security_group(tenant_id=self.tenant_id)
Yair Fried413bf2d2014-11-19 17:07:11 +0200106 self.network, self.subnet, self.router = self.create_networks(**kwargs)
David Shrewsbury9bac3662014-08-07 15:07:01 -0400107 self.check_networks()
108
Yair Frieded8392f2014-01-15 17:21:35 +0200109 name = data_utils.rand_name('server-smoke')
Yair Fried1fc32a12014-08-04 09:11:30 +0300110 server = self._create_server(name, self.network)
Yair Frieded8392f2014-01-15 17:21:35 +0200111 self._check_tenant_network_connectivity()
Yair Fried2d2f3fe2014-02-24 16:19:20 +0200112
Yair Friedae0e73d2014-11-24 11:56:26 +0200113 floating_ip = self.create_floating_ip(server)
114 self.floating_ip_tuple = Floating_IP_tuple(floating_ip, server)
Maru Newby81f07a02012-09-05 20:21:19 -0700115
Yair Frieded8392f2014-01-15 17:21:35 +0200116 def check_networks(self):
117 """
118 Checks that we see the newly created network/subnet/router via
119 checking the result of list_[networks,routers,subnets]
120 """
121
Gavin Brebner851c3502013-01-18 13:14:10 +0000122 seen_nets = self._list_networks()
123 seen_names = [n['name'] for n in seen_nets]
124 seen_ids = [n['id'] for n in seen_nets]
Yair Frieded8392f2014-01-15 17:21:35 +0200125 self.assertIn(self.network.name, seen_names)
126 self.assertIn(self.network.id, seen_ids)
127
David Shrewsbury9bac3662014-08-07 15:07:01 -0400128 if self.subnet:
129 seen_subnets = self._list_subnets()
130 seen_net_ids = [n['network_id'] for n in seen_subnets]
131 seen_subnet_ids = [n['id'] for n in seen_subnets]
132 self.assertIn(self.network.id, seen_net_ids)
133 self.assertIn(self.subnet.id, seen_subnet_ids)
Yair Frieded8392f2014-01-15 17:21:35 +0200134
David Shrewsbury9bac3662014-08-07 15:07:01 -0400135 if self.router:
136 seen_routers = self._list_routers()
137 seen_router_ids = [n['id'] for n in seen_routers]
138 seen_router_names = [n['name'] for n in seen_routers]
139 self.assertIn(self.router.name,
140 seen_router_names)
141 self.assertIn(self.router.id,
142 seen_router_ids)
Gavin Brebner851c3502013-01-18 13:14:10 +0000143
Salvatore Orlando5ed3b6e2013-09-17 01:27:26 -0700144 def _create_server(self, name, network):
Yair Fried1fc32a12014-08-04 09:11:30 +0300145 keypair = self.create_keypair()
146 self.keypairs[keypair['name']] = keypair
Ken'ichi Ohmichi1b3461e2014-12-02 03:41:07 +0000147 security_groups = [{'name': self.security_group['name']}]
Salvatore Orlando5ed3b6e2013-09-17 01:27:26 -0700148 create_kwargs = {
Dirk Mueller8cf79722014-09-12 17:37:15 +0200149 'networks': [
150 {'uuid': network.id},
Salvatore Orlando5ed3b6e2013-09-17 01:27:26 -0700151 ],
Yair Fried1fc32a12014-08-04 09:11:30 +0300152 'key_name': keypair['name'],
Salvatore Orlando5ed3b6e2013-09-17 01:27:26 -0700153 'security_groups': security_groups,
154 }
Giulio Fidente61cadca2013-09-24 18:33:37 +0200155 server = self.create_server(name=name, create_kwargs=create_kwargs)
Yair Fried1fc32a12014-08-04 09:11:30 +0300156 self.servers.append(server)
157 return server
158
159 def _get_server_key(self, server):
160 return self.keypairs[server['key_name']]['private_key']
Salvatore Orlando5ed3b6e2013-09-17 01:27:26 -0700161
Matthew Treinish2b59f842013-09-09 20:32:51 +0000162 def _check_tenant_network_connectivity(self):
Sean Dague86bd8422013-12-20 09:56:44 -0500163 ssh_login = CONF.compute.image_ssh_user
Yair Fried1fc32a12014-08-04 09:11:30 +0300164 for server in self.servers:
Matt Riedemann2d005be2014-05-27 10:52:35 -0700165 # call the common method in the parent class
166 super(TestNetworkBasicOps, self).\
167 _check_tenant_network_connectivity(
Yair Fried1fc32a12014-08-04 09:11:30 +0300168 server, ssh_login, self._get_server_key(server),
169 servers_for_debug=self.servers)
Brent Eaglesc26d4522013-12-02 13:28:49 -0500170
Alok Maurya6384bbb2014-07-13 06:44:29 -0700171 def check_public_network_connectivity(
172 self, should_connect=True, msg=None,
173 should_check_floating_ip_status=True):
Yair Fried45f92952014-06-26 05:19:19 +0300174 """Verifies connectivty to a VM via public network and floating IP,
175 and verifies floating IP has resource status is correct.
176
Yair Fried45f92952014-06-26 05:19:19 +0300177 :param should_connect: bool. determines if connectivity check is
178 negative or positive.
179 :param msg: Failure message to add to Error message. Should describe
180 the place in the test scenario where the method was called,
181 to indicate the context of the failure
Alok Maurya6384bbb2014-07-13 06:44:29 -0700182 :param should_check_floating_ip_status: bool. should status of
183 floating_ip be checked or not
Yair Fried45f92952014-06-26 05:19:19 +0300184 """
Sean Dague86bd8422013-12-20 09:56:44 -0500185 ssh_login = CONF.compute.image_ssh_user
Yair Fried2d2f3fe2014-02-24 16:19:20 +0200186 floating_ip, server = self.floating_ip_tuple
187 ip_address = floating_ip.floating_ip_address
188 private_key = None
Yair Fried45f92952014-06-26 05:19:19 +0300189 floatingip_status = 'DOWN'
Yair Fried2d2f3fe2014-02-24 16:19:20 +0200190 if should_connect:
Yair Fried1fc32a12014-08-04 09:11:30 +0300191 private_key = self._get_server_key(server)
Yair Fried45f92952014-06-26 05:19:19 +0300192 floatingip_status = 'ACTIVE'
Swaminathan Vasudevandc8bcdb2015-02-28 12:47:21 -0800193 # Check FloatingIP Status before initiating a connection
194 if should_check_floating_ip_status:
195 self.check_floating_ip_status(floating_ip, floatingip_status)
Matt Riedemann343305f2014-05-27 09:55:03 -0700196 # call the common method in the parent class
Yair Friedae0e73d2014-11-24 11:56:26 +0200197 super(TestNetworkBasicOps, self).check_public_network_connectivity(
Matt Riedemann343305f2014-05-27 09:55:03 -0700198 ip_address, ssh_login, private_key, should_connect, msg,
Yair Fried1fc32a12014-08-04 09:11:30 +0300199 self.servers)
Matthew Treinish2b59f842013-09-09 20:32:51 +0000200
Yair Fried9a551c42013-12-15 14:59:34 +0200201 def _disassociate_floating_ips(self):
Yair Fried2d2f3fe2014-02-24 16:19:20 +0200202 floating_ip, server = self.floating_ip_tuple
203 self._disassociate_floating_ip(floating_ip)
204 self.floating_ip_tuple = Floating_IP_tuple(
205 floating_ip, None)
Yair Fried9a551c42013-12-15 14:59:34 +0200206
Yair Fried05db2522013-11-18 11:02:10 +0200207 def _reassociate_floating_ips(self):
Yair Fried2d2f3fe2014-02-24 16:19:20 +0200208 floating_ip, server = self.floating_ip_tuple
209 name = data_utils.rand_name('new_server-smoke-')
210 # create a new server for the floating ip
Yair Fried1fc32a12014-08-04 09:11:30 +0300211 server = self._create_server(name, self.network)
212 self._associate_floating_ip(floating_ip, server)
Yair Fried2d2f3fe2014-02-24 16:19:20 +0200213 self.floating_ip_tuple = Floating_IP_tuple(
Yair Fried1fc32a12014-08-04 09:11:30 +0300214 floating_ip, server)
Yair Fried05db2522013-11-18 11:02:10 +0200215
Yair Fried3097dc12014-01-26 08:46:43 +0200216 def _create_new_network(self):
Yair Frieddb6c9e92014-08-06 08:53:13 +0300217 self.new_net = self._create_network(tenant_id=self.tenant_id)
Yair Fried3097dc12014-01-26 08:46:43 +0200218 self.new_subnet = self._create_subnet(
219 network=self.new_net,
220 gateway_ip=None)
Yair Fried3097dc12014-01-26 08:46:43 +0200221
222 def _hotplug_server(self):
223 old_floating_ip, server = self.floating_ip_tuple
224 ip_address = old_floating_ip.floating_ip_address
Yair Fried1fc32a12014-08-04 09:11:30 +0300225 private_key = self._get_server_key(server)
Yair Fried3097dc12014-01-26 08:46:43 +0200226 ssh_client = self.get_remote_client(ip_address,
227 private_key=private_key)
228 old_nic_list = self._get_server_nics(ssh_client)
229 # get a port from a list of one item
Yair Fried1fc32a12014-08-04 09:11:30 +0300230 port_list = self._list_ports(device_id=server['id'])
Yair Fried3097dc12014-01-26 08:46:43 +0200231 self.assertEqual(1, len(port_list))
232 old_port = port_list[0]
David Kranzb2b0c182015-02-18 13:28:19 -0500233 interface = self.interface_client.create_interface(
Yair Fried1fc32a12014-08-04 09:11:30 +0300234 server=server['id'],
235 network_id=self.new_net.id)
236 self.addCleanup(self.network_client.wait_for_resource_deletion,
237 'port',
238 interface['port_id'])
239 self.addCleanup(self.delete_wrapper,
240 self.interface_client.delete_interface,
241 server['id'], interface['port_id'])
Yair Fried3097dc12014-01-26 08:46:43 +0200242
243 def check_ports():
Attila Fazekasa8bb3942014-08-19 09:06:30 +0200244 self.new_port_list = [port for port in
Yair Fried1fc32a12014-08-04 09:11:30 +0300245 self._list_ports(device_id=server['id'])
armando-migliaccio3820a062015-02-12 19:31:54 -0800246 if port['id'] != old_port['id']]
Attila Fazekasa8bb3942014-08-19 09:06:30 +0200247 return len(self.new_port_list) == 1
Yair Fried3097dc12014-01-26 08:46:43 +0200248
Attila Fazekasa8bb3942014-08-19 09:06:30 +0200249 if not test.call_until_true(check_ports, CONF.network.build_timeout,
250 CONF.network.build_interval):
Matt Riedemann892094e2015-02-05 07:24:02 -0800251 raise exceptions.TimeoutException(
252 "No new port attached to the server in time (%s sec)! "
253 "Old port: %s. Number of new ports: %d" % (
254 CONF.network.build_timeout, old_port,
255 len(self.new_port_list)))
Yair Fried1fc32a12014-08-04 09:11:30 +0300256 new_port = net_resources.DeletablePort(client=self.network_client,
257 **self.new_port_list[0])
Attila Fazekasa8bb3942014-08-19 09:06:30 +0200258
259 def check_new_nic():
260 new_nic_list = self._get_server_nics(ssh_client)
261 self.diff_list = [n for n in new_nic_list if n not in old_nic_list]
262 return len(self.diff_list) == 1
263
264 if not test.call_until_true(check_new_nic, CONF.network.build_timeout,
265 CONF.network.build_interval):
266 raise exceptions.TimeoutException("Interface not visible on the "
267 "guest after %s sec"
268 % CONF.network.build_timeout)
269
270 num, new_nic = self.diff_list[0]
Yair Fried3097dc12014-01-26 08:46:43 +0200271 ssh_client.assign_static_ip(nic=new_nic,
272 addr=new_port.fixed_ips[0]['ip_address'])
273 ssh_client.turn_nic_on(nic=new_nic)
274
275 def _get_server_nics(self, ssh_client):
276 reg = re.compile(r'(?P<num>\d+): (?P<nic_name>\w+):')
277 ipatxt = ssh_client.get_ip_list()
278 return reg.findall(ipatxt)
279
Yair Fried06552292013-11-11 12:10:09 +0200280 def _check_network_internal_connectivity(self, network):
Yair Fried3097dc12014-01-26 08:46:43 +0200281 """
282 via ssh check VM internal connectivity:
Yair Fried06552292013-11-11 12:10:09 +0200283 - ping internal gateway and DHCP port, implying in-tenant connectivity
284 pinging both, because L3 and DHCP agents might be on different nodes
Yair Fried3097dc12014-01-26 08:46:43 +0200285 """
286 floating_ip, server = self.floating_ip_tuple
287 # get internal ports' ips:
288 # get all network ports in the new network
289 internal_ips = (p['fixed_ips'][0]['ip_address'] for p in
Yair Fried1fc32a12014-08-04 09:11:30 +0300290 self._list_ports(tenant_id=server['tenant_id'],
Yair Fried06552292013-11-11 12:10:09 +0200291 network_id=network.id)
Yair Fried3097dc12014-01-26 08:46:43 +0200292 if p['device_owner'].startswith('network'))
293
Yair Fried06552292013-11-11 12:10:09 +0200294 self._check_server_connectivity(floating_ip, internal_ips)
295
296 def _check_network_external_connectivity(self):
297 """
298 ping public network default gateway to imply external connectivity
299
300 """
301 if not CONF.network.public_network_id:
302 msg = 'public network not defined.'
303 LOG.info(msg)
304 return
305
Yair Fried1fc32a12014-08-04 09:11:30 +0300306 subnet = self._list_subnets(
307 network_id=CONF.network.public_network_id)
Yair Fried06552292013-11-11 12:10:09 +0200308 self.assertEqual(1, len(subnet), "Found %d subnets" % len(subnet))
309
310 external_ips = [subnet[0]['gateway_ip']]
311 self._check_server_connectivity(self.floating_ip_tuple.floating_ip,
312 external_ips)
313
314 def _check_server_connectivity(self, floating_ip, address_list):
Yair Fried3097dc12014-01-26 08:46:43 +0200315 ip_address = floating_ip.floating_ip_address
Yair Fried1fc32a12014-08-04 09:11:30 +0300316 private_key = self._get_server_key(self.floating_ip_tuple.server)
Yair Fried3097dc12014-01-26 08:46:43 +0200317 ssh_source = self._ssh_to_server(ip_address, private_key)
318
Yair Fried06552292013-11-11 12:10:09 +0200319 for remote_ip in address_list:
Yair Fried3097dc12014-01-26 08:46:43 +0200320 try:
321 self.assertTrue(self._check_remote_connectivity(ssh_source,
322 remote_ip),
323 "Timed out waiting for %s to become "
324 "reachable" % remote_ip)
325 except Exception:
326 LOG.exception("Unable to access {dest} via ssh to "
327 "floating-ip {src}".format(dest=remote_ip,
328 src=floating_ip))
Yair Fried3097dc12014-01-26 08:46:43 +0200329 raise
330
Yoshihiro Kaneko05670262014-01-18 19:22:44 +0900331 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800332 @test.idempotent_id('f323b3ba-82f8-4db7-8ea6-6a895869ec49')
Yoshihiro Kaneko05670262014-01-18 19:22:44 +0900333 @test.services('compute', 'network')
Matthew Treinish2b59f842013-09-09 20:32:51 +0000334 def test_network_basic_ops(self):
Yair Fried3097dc12014-01-26 08:46:43 +0200335 """
336 For a freshly-booted VM with an IP address ("port") on a given
337 network:
338
339 - the Tempest host can ping the IP address. This implies, but
340 does not guarantee (see the ssh check that follows), that the
341 VM has been assigned the correct IP address and has
342 connectivity to the Tempest host.
343
344 - the Tempest host can perform key-based authentication to an
345 ssh server hosted at the IP address. This check guarantees
346 that the IP address is associated with the target VM.
347
Yair Fried3097dc12014-01-26 08:46:43 +0200348 - the Tempest host can ssh into the VM via the IP address and
349 successfully execute the following:
350
351 - ping an external IP address, implying external connectivity.
352
353 - ping an external hostname, implying that dns is correctly
354 configured.
355
356 - ping an internal IP address, implying connectivity to another
357 VM on the same network.
358
Yair Fried06552292013-11-11 12:10:09 +0200359 - detach the floating-ip from the VM and verify that it becomes
360 unreachable
361
362 - associate detached floating ip to a new VM and verify connectivity.
363 VMs are created with unique keypair so connectivity also asserts that
364 floating IP is associated with the new VM instead of the old one
365
Yair Fried45f92952014-06-26 05:19:19 +0300366 Verifies that floating IP status is updated correctly after each change
367
Yair Fried06552292013-11-11 12:10:09 +0200368
Yair Fried3097dc12014-01-26 08:46:43 +0200369 """
David Shrewsbury9bac3662014-08-07 15:07:01 -0400370 self._setup_network_and_servers()
Yair Friedae0e73d2014-11-24 11:56:26 +0200371 self.check_public_network_connectivity(should_connect=True)
Yair Fried06552292013-11-11 12:10:09 +0200372 self._check_network_internal_connectivity(network=self.network)
373 self._check_network_external_connectivity()
Yair Fried9a551c42013-12-15 14:59:34 +0200374 self._disassociate_floating_ips()
Yair Friedae0e73d2014-11-24 11:56:26 +0200375 self.check_public_network_connectivity(should_connect=False,
376 msg="after disassociate "
377 "floating ip")
Yair Fried05db2522013-11-18 11:02:10 +0200378 self._reassociate_floating_ips()
Yair Friedae0e73d2014-11-24 11:56:26 +0200379 self.check_public_network_connectivity(should_connect=True,
380 msg="after re-associate "
381 "floating ip")
Yair Fried3097dc12014-01-26 08:46:43 +0200382
Chris Hoge7579c1a2015-02-26 14:12:15 -0800383 @test.idempotent_id('c5adff73-e961-41f1-b4a9-343614f18cfa')
Adam Gandelman7186f7a2014-07-23 09:28:56 -0400384 @testtools.skipUnless(CONF.compute_feature_enabled.interface_attach,
385 'NIC hotplug not available')
Itzik Brown2ca01cd2014-12-08 12:58:20 +0200386 @testtools.skipIf(CONF.network.port_vnic_type in ['direct', 'macvtap'],
387 'NIC hotplug not supported for '
388 'vnic_type direct or macvtap')
Yair Fried3097dc12014-01-26 08:46:43 +0200389 @test.attr(type='smoke')
390 @test.services('compute', 'network')
391 def test_hotplug_nic(self):
392 """
393 1. create a new network, with no gateway (to prevent overwriting VM's
394 gateway)
395 2. connect VM to new network
396 3. set static ip and bring new nic up
397 4. check VM can ping new network dhcp port
398
399 """
David Shrewsbury9bac3662014-08-07 15:07:01 -0400400 self._setup_network_and_servers()
Yair Friedae0e73d2014-11-24 11:56:26 +0200401 self.check_public_network_connectivity(should_connect=True)
Yair Fried3097dc12014-01-26 08:46:43 +0200402 self._create_new_network()
403 self._hotplug_server()
Yair Fried06552292013-11-11 12:10:09 +0200404 self._check_network_internal_connectivity(network=self.new_net)
Alok Maurya6384bbb2014-07-13 06:44:29 -0700405
Chris Hoge7579c1a2015-02-26 14:12:15 -0800406 @test.idempotent_id('04b9fe4e-85e8-4aea-b937-ea93885ac59f')
Adam Gandelmancf611212014-12-09 14:13:28 -0800407 @testtools.skipIf(CONF.baremetal.driver_enabled,
408 'Router state cannot be altered on a shared baremetal '
409 'network')
Alok Maurya6384bbb2014-07-13 06:44:29 -0700410 @test.attr(type='smoke')
411 @test.services('compute', 'network')
412 def test_update_router_admin_state(self):
413 """
414 1. Check public connectivity before updating
415 admin_state_up attribute of router to False
416 2. Check public connectivity after updating
417 admin_state_up attribute of router to False
418 3. Check public connectivity after updating
419 admin_state_up attribute of router to True
420 """
421 self._setup_network_and_servers()
422 self.check_public_network_connectivity(
423 should_connect=True, msg="before updating "
424 "admin_state_up of router to False")
425 self._update_router_admin_state(self.router, False)
426 # TODO(alokmaurya): Remove should_check_floating_ip_status=False check
427 # once bug 1396310 is fixed
428
429 self.check_public_network_connectivity(
430 should_connect=False, msg="after updating "
431 "admin_state_up of router to False",
432 should_check_floating_ip_status=False)
433 self._update_router_admin_state(self.router, True)
434 self.check_public_network_connectivity(
435 should_connect=True, msg="after updating "
436 "admin_state_up of router to True")
Yair Fried413bf2d2014-11-19 17:07:11 +0200437
Chris Hoge7579c1a2015-02-26 14:12:15 -0800438 @test.idempotent_id('d8bb918e-e2df-48b2-97cd-b73c95450980')
Adam Gandelman40371682015-03-03 11:27:03 -0800439 @testtools.skipIf(CONF.baremetal.driver_enabled,
440 'network isolation not available for baremetal nodes')
Yair Fried413bf2d2014-11-19 17:07:11 +0200441 @testtools.skipUnless(CONF.scenario.dhcp_client,
442 "DHCP client is not available.")
443 @test.attr(type='smoke')
444 @test.services('compute', 'network')
445 def test_subnet_details(self):
446 """Tests that subnet's extra configuration details are affecting
Adam Gandelman40371682015-03-03 11:27:03 -0800447 the VMs. This test relies on non-shared, isolated tenant networks.
Yair Fried413bf2d2014-11-19 17:07:11 +0200448
449 NOTE: Neutron subnets push data to servers via dhcp-agent, so any
450 update in subnet requires server to actively renew its DHCP lease.
451
452 1. Configure subnet with dns nameserver
453 2. retrieve the VM's configured dns and verify it matches the one
454 configured for the subnet.
455 3. update subnet's dns
456 4. retrieve the VM's configured dns and verify it matches the new one
457 configured for the subnet.
458
459 TODO(yfried): add host_routes
460
461 any resolution check would be testing either:
462 * l3 forwarding (tested in test_network_basic_ops)
463 * Name resolution of an external DNS nameserver - out of scope for
464 Tempest
465 """
466 # this test check only updates (no actual resolution) so using
467 # arbitrary ip addresses as nameservers, instead of parsing CONF
468 initial_dns_server = '1.2.3.4'
469 alt_dns_server = '9.8.7.6'
Yair Friedbb0ea392015-01-19 07:26:08 +0000470
471 # renewal should be immediate.
472 # Timeouts are suggested by salvatore-orlando in
473 # https://bugs.launchpad.net/neutron/+bug/1412325/comments/3
474 renew_delay = CONF.network.build_interval
475 renew_timeout = CONF.network.build_timeout
476
Yair Fried413bf2d2014-11-19 17:07:11 +0200477 self._setup_network_and_servers(dns_nameservers=[initial_dns_server])
478 self.check_public_network_connectivity(should_connect=True)
479
480 floating_ip, server = self.floating_ip_tuple
481 ip_address = floating_ip.floating_ip_address
482 private_key = self._get_server_key(server)
483 ssh_client = self._ssh_to_server(ip_address, private_key)
484
armando-migliaccio424aa412015-02-22 17:55:17 -0800485 dns_servers = [initial_dns_server]
486 servers = ssh_client.get_dns_servers()
487 self.assertEqual(set(dns_servers), set(servers),
488 'Looking for servers: {trgt_serv}. '
489 'Retrieved DNS nameservers: {act_serv} '
490 'From host: {host}.'
491 .format(host=ssh_client.ssh_client.host,
492 act_serv=servers,
493 trgt_serv=dns_servers))
Yair Fried413bf2d2014-11-19 17:07:11 +0200494
495 self.subnet.update(dns_nameservers=[alt_dns_server])
496 # asserts that Neutron DB has updated the nameservers
497 self.assertEqual([alt_dns_server], self.subnet.dns_nameservers,
498 "Failed to update subnet's nameservers")
499
Yair Friedbb0ea392015-01-19 07:26:08 +0000500 def check_new_dns_server():
501 """Server needs to renew its dhcp lease in order to get the new dns
502 definitions from subnet
503 NOTE(amuller): we are renewing the lease as part of the retry
504 because Neutron updates dnsmasq asynchronously after the
505 subnet-update API call returns.
506 """
507 ssh_client.renew_lease(fixed_ip=floating_ip['fixed_ip_address'])
armando-migliaccio424aa412015-02-22 17:55:17 -0800508 if ssh_client.get_dns_servers() != [alt_dns_server]:
Yair Friedbb0ea392015-01-19 07:26:08 +0000509 LOG.debug("Failed to update DNS nameservers")
510 return False
511 return True
512
513 self.assertTrue(test.call_until_true(check_new_dns_server,
514 renew_timeout,
515 renew_delay),
516 msg="DHCP renewal failed to fetch "
517 "new DNS nameservers")
Thalabathy Venkatesan76553d82015-01-07 22:54:39 -0800518
Chris Hoge7579c1a2015-02-26 14:12:15 -0800519 @test.idempotent_id('f5dfcc22-45fd-409f-954c-5bd500d7890b')
Adam Gandelman0a7948e2015-02-16 15:13:50 -0800520 @testtools.skipIf(CONF.baremetal.driver_enabled,
521 'admin_state of instance ports cannot be altered '
522 'for baremetal nodes')
Thalabathy Venkatesan76553d82015-01-07 22:54:39 -0800523 @test.attr(type='smoke')
524 @test.services('compute', 'network')
525 def test_update_instance_port_admin_state(self):
526 """
527 1. Check public connectivity before updating
528 admin_state_up attribute of instance port to False
529 2. Check public connectivity after updating
530 admin_state_up attribute of instance port to False
531 3. Check public connectivity after updating
532 admin_state_up attribute of instance port to True
533 """
534 self._setup_network_and_servers()
535 floating_ip, server = self.floating_ip_tuple
536 server_id = server['id']
537 port_id = self._list_ports(device_id=server_id)[0]['id']
538 self.check_public_network_connectivity(
539 should_connect=True, msg="before updating "
540 "admin_state_up of instance port to False")
541 self.network_client.update_port(port_id, admin_state_up=False)
542 self.check_public_network_connectivity(
543 should_connect=False, msg="after updating "
544 "admin_state_up of instance port to False",
545 should_check_floating_ip_status=False)
546 self.network_client.update_port(port_id, admin_state_up=True)
547 self.check_public_network_connectivity(
548 should_connect=True, msg="after updating "
549 "admin_state_up of instance port to True")