blob: 5ccfd52cc850a1a96d8ac3b422c55eded77a707e [file] [log] [blame]
Maru Newby81f07a02012-09-05 20:21:19 -07001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
Gavin Brebner0f465a32013-03-14 13:26:09 +00004# Copyright 2013 Hewlett-Packard Development Company, L.P.
Maru Newby81f07a02012-09-05 20:21:19 -07005# All Rights Reserved.
6#
7# Licensed under the Apache License, Version 2.0 (the "License"); you may
8# not use this file except in compliance with the License. You may obtain
9# a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16# License for the specific language governing permissions and limitations
17# under the License.
18
Sean Dague1937d092013-05-17 16:36:38 -040019from tempest.api.network import common as net_common
Maru Newby81f07a02012-09-05 20:21:19 -070020from tempest.common.utils.data_utils import rand_name
Sean Dague6dbc6da2013-05-08 17:49:46 -040021from tempest.scenario import manager
Maru Newbybd360222013-04-08 22:48:50 +000022from tempest.test import attr
Maru Newby81f07a02012-09-05 20:21:19 -070023
24
Sean Dague6dbc6da2013-05-08 17:49:46 -040025class TestNetworkBasicOps(manager.NetworkScenarioTest):
Maru Newby81f07a02012-09-05 20:21:19 -070026
27 """
28 This smoke test suite assumes that Nova has been configured to
29 boot VM's with Quantum-managed networking, and attempts to
30 verify network connectivity as follows:
31
32 * For a freshly-booted VM with an IP address ("port") on a given network:
33
34 - the Tempest host can ping the IP address. This implies that
35 the VM has been assigned the correct IP address and has
36 connectivity to the Tempest host.
37
38 #TODO(mnewby) - Need to implement the following:
39 - the Tempest host can ssh into the VM via the IP address and
40 successfully execute the following:
41
42 - ping an external IP address, implying external connectivity.
43
44 - ping an external hostname, implying that dns is correctly
45 configured.
46
47 - ping an internal IP address, implying connectivity to another
48 VM on the same network.
49
50 There are presumed to be two types of networks: tenant and
51 public. A tenant network may or may not be reachable from the
52 Tempest host. A public network is assumed to be reachable from
53 the Tempest host, and it should be possible to associate a public
54 ('floating') IP address with a tenant ('fixed') IP address to
55 faciliate external connectivity to a potentially unroutable
56 tenant IP address.
57
58 This test suite can be configured to test network connectivity to
59 a VM via a tenant network, a public network, or both. If both
60 networking types are to be evaluated, tests that need to be
61 executed remotely on the VM (via ssh) will only be run against
62 one of the networks (to minimize test execution time).
63
64 Determine which types of networks to test as follows:
65
66 * Configure tenant network checks (via the
67 'tenant_networks_reachable' key) if the Tempest host should
68 have direct connectivity to tenant networks. This is likely to
69 be the case if Tempest is running on the same host as a
70 single-node devstack installation with IP namespaces disabled.
71
72 * Configure checks for a public network if a public network has
73 been configured prior to the test suite being run and if the
74 Tempest host should have connectivity to that public network.
75 Checking connectivity for a public network requires that a
76 value be provided for 'public_network_id'. A value can
77 optionally be provided for 'public_router_id' if tenants will
78 use a shared router to access a public network (as is likely to
79 be the case when IP namespaces are not enabled). If a value is
80 not provided for 'public_router_id', a router will be created
81 for each tenant and use the network identified by
82 'public_network_id' as its gateway.
83
84 """
85
86 @classmethod
87 def check_preconditions(cls):
Gavin Brebner0f465a32013-03-14 13:26:09 +000088 super(TestNetworkBasicOps, cls).check_preconditions()
Maru Newby81f07a02012-09-05 20:21:19 -070089 cfg = cls.config.network
Maru Newby81f07a02012-09-05 20:21:19 -070090 if not (cfg.tenant_networks_reachable or cfg.public_network_id):
91 msg = ('Either tenant_networks_reachable must be "true", or '
92 'public_network_id must be defined.')
Gavin Brebner0f465a32013-03-14 13:26:09 +000093 cls.enabled = False
ivan-zhu1feeb382013-01-24 10:14:39 +080094 raise cls.skipException(msg)
Maru Newby81f07a02012-09-05 20:21:19 -070095
96 @classmethod
97 def setUpClass(cls):
98 super(TestNetworkBasicOps, cls).setUpClass()
99 cls.check_preconditions()
Maru Newby81f07a02012-09-05 20:21:19 -0700100 cls.tenant_id = cls.manager._get_identity_client(
Gavin Brebnercb7faa32013-01-30 12:01:31 +0000101 cls.config.identity.username,
102 cls.config.identity.password,
103 cls.config.identity.tenant_name).tenant_id
Maru Newby81f07a02012-09-05 20:21:19 -0700104 # TODO(mnewby) Consider looking up entities as needed instead
105 # of storing them as collections on the class.
106 cls.keypairs = {}
107 cls.security_groups = {}
108 cls.networks = []
Gavin Brebner851c3502013-01-18 13:14:10 +0000109 cls.subnets = []
110 cls.routers = []
Maru Newby81f07a02012-09-05 20:21:19 -0700111 cls.servers = []
112 cls.floating_ips = {}
113
Maru Newby81f07a02012-09-05 20:21:19 -0700114 def _get_router(self, tenant_id):
115 """Retrieve a router for the given tenant id.
116
117 If a public router has been configured, it will be returned.
118
119 If a public router has not been configured, but a public
120 network has, a tenant router will be created and returned that
121 routes traffic to the public network.
122
123 """
124 router_id = self.config.network.public_router_id
125 network_id = self.config.network.public_network_id
126 if router_id:
127 result = self.network_client.show_router(router_id)
Maru Newby207d68c2013-04-09 01:06:03 +0000128 return net_common.AttributeDict(**result['router'])
Maru Newby81f07a02012-09-05 20:21:19 -0700129 elif network_id:
130 router = self._create_router(tenant_id)
131 router.add_gateway(network_id)
132 return router
133 else:
134 raise Exception("Neither of 'public_router_id' or "
135 "'public_network_id' has been defined.")
136
Gavin Brebner0f465a32013-03-14 13:26:09 +0000137 def _create_router(self, tenant_id, namestart='router-smoke-'):
138 name = rand_name(namestart)
Maru Newby81f07a02012-09-05 20:21:19 -0700139 body = dict(
140 router=dict(
141 name=name,
142 admin_state_up=True,
143 tenant_id=tenant_id,
144 ),
145 )
146 result = self.network_client.create_router(body=body)
Maru Newby207d68c2013-04-09 01:06:03 +0000147 router = net_common.DeletableRouter(client=self.network_client,
148 **result['router'])
Maru Newby81f07a02012-09-05 20:21:19 -0700149 self.assertEqual(router.name, name)
150 self.set_resource(name, router)
151 return router
152
Maru Newbybd360222013-04-08 22:48:50 +0000153 @attr(type='smoke')
Maru Newby81f07a02012-09-05 20:21:19 -0700154 def test_001_create_keypairs(self):
155 self.keypairs[self.tenant_id] = self._create_keypair(
156 self.compute_client)
157
Maru Newbybd360222013-04-08 22:48:50 +0000158 @attr(type='smoke')
Maru Newby81f07a02012-09-05 20:21:19 -0700159 def test_002_create_security_groups(self):
160 self.security_groups[self.tenant_id] = self._create_security_group(
161 self.compute_client)
162
Maru Newbybd360222013-04-08 22:48:50 +0000163 @attr(type='smoke')
Maru Newby81f07a02012-09-05 20:21:19 -0700164 def test_003_create_networks(self):
165 network = self._create_network(self.tenant_id)
166 router = self._get_router(self.tenant_id)
167 subnet = self._create_subnet(network)
168 subnet.add_to_router(router.id)
169 self.networks.append(network)
Gavin Brebner851c3502013-01-18 13:14:10 +0000170 self.subnets.append(subnet)
171 self.routers.append(router)
Maru Newby81f07a02012-09-05 20:21:19 -0700172
Maru Newbybd360222013-04-08 22:48:50 +0000173 @attr(type='smoke')
Gavin Brebner851c3502013-01-18 13:14:10 +0000174 def test_004_check_networks(self):
175 #Checks that we see the newly created network/subnet/router via
176 #checking the result of list_[networks,routers,subnets]
177 seen_nets = self._list_networks()
178 seen_names = [n['name'] for n in seen_nets]
179 seen_ids = [n['id'] for n in seen_nets]
180 for mynet in self.networks:
Gavin Brebner0f465a32013-03-14 13:26:09 +0000181 self.assertIn(mynet.name, seen_names)
182 self.assertIn(mynet.id, seen_ids)
Gavin Brebner851c3502013-01-18 13:14:10 +0000183 seen_subnets = self._list_subnets()
184 seen_net_ids = [n['network_id'] for n in seen_subnets]
185 seen_subnet_ids = [n['id'] for n in seen_subnets]
186 for mynet in self.networks:
Gavin Brebner0f465a32013-03-14 13:26:09 +0000187 self.assertIn(mynet.id, seen_net_ids)
Gavin Brebner851c3502013-01-18 13:14:10 +0000188 for mysubnet in self.subnets:
Gavin Brebner0f465a32013-03-14 13:26:09 +0000189 self.assertIn(mysubnet.id, seen_subnet_ids)
Gavin Brebner851c3502013-01-18 13:14:10 +0000190 seen_routers = self._list_routers()
191 seen_router_ids = [n['id'] for n in seen_routers]
192 seen_router_names = [n['name'] for n in seen_routers]
193 for myrouter in self.routers:
Gavin Brebner0f465a32013-03-14 13:26:09 +0000194 self.assertIn(myrouter.name, seen_router_names)
195 self.assertIn(myrouter.id, seen_router_ids)
Gavin Brebner851c3502013-01-18 13:14:10 +0000196
Maru Newbybd360222013-04-08 22:48:50 +0000197 @attr(type='smoke')
Gavin Brebner851c3502013-01-18 13:14:10 +0000198 def test_005_create_servers(self):
Maru Newby81f07a02012-09-05 20:21:19 -0700199 if not (self.keypairs or self.security_groups or self.networks):
ivan-zhu1feeb382013-01-24 10:14:39 +0800200 raise self.skipTest('Necessary resources have not been defined')
Maru Newby81f07a02012-09-05 20:21:19 -0700201 for i, network in enumerate(self.networks):
202 tenant_id = network.tenant_id
203 name = rand_name('server-smoke-%d-' % i)
204 keypair_name = self.keypairs[tenant_id].name
205 security_groups = [self.security_groups[tenant_id].name]
206 server = self._create_server(self.compute_client, network,
207 name, keypair_name, security_groups)
208 self.servers.append(server)
209
Maru Newbybd360222013-04-08 22:48:50 +0000210 @attr(type='smoke')
Gavin Brebner851c3502013-01-18 13:14:10 +0000211 def test_006_check_tenant_network_connectivity(self):
Maru Newby81f07a02012-09-05 20:21:19 -0700212 if not self.config.network.tenant_networks_reachable:
213 msg = 'Tenant networks not configured to be reachable.'
ivan-zhu1feeb382013-01-24 10:14:39 +0800214 raise self.skipTest(msg)
Maru Newby81f07a02012-09-05 20:21:19 -0700215 if not self.servers:
ivan-zhu1feeb382013-01-24 10:14:39 +0800216 raise self.skipTest("No VM's have been created")
Maru Newby81f07a02012-09-05 20:21:19 -0700217 for server in self.servers:
218 for net_name, ip_addresses in server.networks.iteritems():
219 for ip_address in ip_addresses:
220 self.assertTrue(self._ping_ip_address(ip_address),
221 "Timed out waiting for %s's ip to become "
222 "reachable" % server.name)
223
Maru Newbybd360222013-04-08 22:48:50 +0000224 @attr(type='smoke')
Gavin Brebner851c3502013-01-18 13:14:10 +0000225 def test_007_assign_floating_ips(self):
Maru Newby81f07a02012-09-05 20:21:19 -0700226 public_network_id = self.config.network.public_network_id
227 if not public_network_id:
ivan-zhu1feeb382013-01-24 10:14:39 +0800228 raise self.skipTest('Public network not configured')
Maru Newby81f07a02012-09-05 20:21:19 -0700229 if not self.servers:
ivan-zhu1feeb382013-01-24 10:14:39 +0800230 raise self.skipTest("No VM's have been created")
Maru Newby81f07a02012-09-05 20:21:19 -0700231 for server in self.servers:
232 floating_ip = self._create_floating_ip(server, public_network_id)
233 self.floating_ips.setdefault(server, [])
234 self.floating_ips[server].append(floating_ip)
235
Maru Newbybd360222013-04-08 22:48:50 +0000236 @attr(type='smoke')
Gavin Brebner851c3502013-01-18 13:14:10 +0000237 def test_008_check_public_network_connectivity(self):
Maru Newby81f07a02012-09-05 20:21:19 -0700238 if not self.floating_ips:
ivan-zhu1feeb382013-01-24 10:14:39 +0800239 raise self.skipTest('No floating ips have been allocated.')
Maru Newby81f07a02012-09-05 20:21:19 -0700240 for server, floating_ips in self.floating_ips.iteritems():
241 for floating_ip in floating_ips:
242 ip_address = floating_ip.floating_ip_address
243 self.assertTrue(self._ping_ip_address(ip_address),
244 "Timed out waiting for %s's ip to become "
245 "reachable" % server.name)