Merge lp:~vishvananda/nova/tests-clean-db into lp:~hudson-openstack/nova/trunk
- tests-clean-db
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Todd Willey |
Approved revision: | 736 |
Merged at revision: | 738 |
Proposed branch: | lp:~vishvananda/nova/tests-clean-db |
Merge into: | lp:~hudson-openstack/nova/trunk |
Prerequisite: | lp:~vishvananda/nova/log-colors |
Diff against target: |
826 lines (+110/-113) 23 files modified
bin/nova-dhcpbridge (+1/-12) nova/flags.py (+2/-1) nova/test.py (+8/-24) nova/tests/__init__.py (+25/-0) nova/tests/api/openstack/__init__.py (+2/-2) nova/tests/api/openstack/test_adminapi.py (+5/-6) nova/tests/api/openstack/test_api.py (+2/-2) nova/tests/api/openstack/test_auth.py (+7/-7) nova/tests/api/openstack/test_common.py (+3/-2) nova/tests/api/openstack/test_faults.py (+2/-2) nova/tests/api/openstack/test_flavors.py (+4/-6) nova/tests/api/openstack/test_images.py (+14/-8) nova/tests/api/openstack/test_ratelimiting.py (+7/-8) nova/tests/api/openstack/test_servers.py (+4/-6) nova/tests/api/openstack/test_shared_ip_groups.py (+4/-3) nova/tests/api/openstack/test_zones.py (+4/-6) nova/tests/api/test_wsgi.py (+3/-3) nova/tests/fake_flags.py (+3/-3) nova/tests/objectstore_unittest.py (+1/-0) nova/tests/test_direct.py (+1/-0) nova/tests/test_network.py (+3/-5) nova/tests/test_virt.py (+3/-2) run_tests.py (+2/-5) |
To merge this branch: | bzr merge lp:~vishvananda/nova/tests-clean-db |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Todd Willey (community) | Approve | ||
Josh Kearney (community) | Approve | ||
Review via email: mp+50887@code.launchpad.net |
Commit message
Make tests start with a clean database for every test.
Description of the change
I got tired of cascading test failures, so I made tests snapshot the db after fixtures have been created. This should fix virtually all the cascading failures that we saw previously. Note that I changed all of the os api tests to inherit from our base test case and to call super.setUp and tearDown.
The snapshot is really fast, so it doesn't really affect the running time of the tests. In fact it may even be faster.
Vish Ishaya (vishvananda) wrote : | # |
Josh Kearney (jk0) wrote : | # |
This is great -- tests now run at around ~70s for me. I also like the pretty colors.
Jay Pipes (jaypipes) wrote : | # |
Changing all test cases to inherit from test.TestCase is not useful, IMHO. Many of the test cases have no need to touch the database nor do they need to go through all the code in test.TestCase.setUp and tearDown, which is why Gundlach and I changed many of them to inherit from unittest.TestCase if they had no need of the base test class methods.
The tests would run even faster than 80 seconds if they didn't all change to inherit from a base class they don't need to inherit from. This is why Gundlach and I spent so much time changing loads of test cases to inherit from unittest.TestCase in the first place.
I'd prefer we change the name of test.TestCase to something like test.FullEnviro
Vish Ishaya (vishvananda) wrote : | # |
Jay: I think all of our tests should inherit from the same base class and cleanup in between. That way if someone forgets to leak items into the db (as was happening in some of the openstack api tests), it still gets cleaned properly for the next test.
Now that the set up happens in fixtures, the time difference between the two is negligible. In fact they seem to be virtually the same speed, changing slightly based on system load:
[UNITEST VERSION]
vishvananda@
real 0m16.181s
user 0m5.600s
sys 0m0.590s
[TEST VERSION]
vishvananda@
vishvananda@
real 0m15.740s
user 0m5.350s
sys 0m0.780s
I understand why you went the unittest route before (setup of test.TestCase was SLOW!!!) but I don't think there is any reason for it now.
Vish
Todd Willey (xtoddx) : | # |
Preview Diff
1 | === modified file 'bin/nova-dhcpbridge' |
2 | --- bin/nova-dhcpbridge 2011-02-23 23:39:43 +0000 |
3 | +++ bin/nova-dhcpbridge 2011-02-23 23:39:43 +0000 |
4 | @@ -105,18 +105,7 @@ |
5 | logging.setup() |
6 | interface = os.environ.get('DNSMASQ_INTERFACE', 'br0') |
7 | if int(os.environ.get('TESTING', '0')): |
8 | - FLAGS.fake_rabbit = True |
9 | - FLAGS.network_size = 16 |
10 | - FLAGS.connection_type = 'fake' |
11 | - FLAGS.fake_network = True |
12 | - FLAGS.auth_driver = 'nova.auth.dbdriver.DbDriver' |
13 | - FLAGS.num_networks = 5 |
14 | - path = os.path.abspath(os.path.join(os.path.dirname(__file__), |
15 | - '..', |
16 | - 'nova', |
17 | - 'tests', |
18 | - 'tests.sqlite')) |
19 | - FLAGS.sql_connection = 'sqlite:///%s' % path |
20 | + from nova.tests import fake_flags |
21 | action = argv[1] |
22 | if action in ['add', 'del', 'old']: |
23 | mac = argv[2] |
24 | |
25 | === modified file 'nova/flags.py' |
26 | --- nova/flags.py 2011-02-21 21:59:46 +0000 |
27 | +++ nova/flags.py 2011-02-23 23:39:43 +0000 |
28 | @@ -285,8 +285,9 @@ |
29 | DEFINE_string('logdir', None, 'output to a per-service log file in named ' |
30 | 'directory') |
31 | |
32 | +DEFINE_string('sqlite_db', 'nova.sqlite', 'file name for sqlite') |
33 | DEFINE_string('sql_connection', |
34 | - 'sqlite:///$state_path/nova.sqlite', |
35 | + 'sqlite:///$state_path/$sqlite_db', |
36 | 'connection string for sql database') |
37 | DEFINE_integer('sql_idle_timeout', |
38 | 3600, |
39 | |
40 | === modified file 'nova/test.py' |
41 | --- nova/test.py 2011-02-22 09:59:53 +0000 |
42 | +++ nova/test.py 2011-02-23 23:39:43 +0000 |
43 | @@ -22,26 +22,28 @@ |
44 | and some black magic for inline callbacks. |
45 | """ |
46 | |
47 | + |
48 | import datetime |
49 | +import os |
50 | +import shutil |
51 | import uuid |
52 | import unittest |
53 | |
54 | import mox |
55 | +import shutil |
56 | import stubout |
57 | |
58 | from nova import context |
59 | from nova import db |
60 | from nova import fakerabbit |
61 | from nova import flags |
62 | -from nova import log as logging |
63 | from nova import rpc |
64 | from nova import service |
65 | -from nova.network import manager as network_manager |
66 | |
67 | |
68 | FLAGS = flags.FLAGS |
69 | -flags.DEFINE_bool('flush_db', True, |
70 | - 'Flush the database before running fake tests') |
71 | +flags.DEFINE_string('sqlite_clean_db', 'clean.sqlite', |
72 | + 'File name of clean sqlite db') |
73 | flags.DEFINE_bool('fake_tests', True, |
74 | 'should we use everything for testing') |
75 | |
76 | @@ -66,15 +68,8 @@ |
77 | # now that we have some required db setup for the system |
78 | # to work properly. |
79 | self.start = datetime.datetime.utcnow() |
80 | - ctxt = context.get_admin_context() |
81 | - if db.network_count(ctxt) != 5: |
82 | - network_manager.VlanManager().create_networks(ctxt, |
83 | - FLAGS.fixed_range, |
84 | - 5, 16, |
85 | - FLAGS.fixed_range_v6, |
86 | - FLAGS.vlan_start, |
87 | - FLAGS.vpn_start, |
88 | - ) |
89 | + shutil.copyfile(os.path.join(FLAGS.state_path, FLAGS.sqlite_clean_db), |
90 | + os.path.join(FLAGS.state_path, FLAGS.sqlite_db)) |
91 | |
92 | # emulate some of the mox stuff, we can't use the metaclass |
93 | # because it screws with our generators |
94 | @@ -96,17 +91,6 @@ |
95 | self.mox.VerifyAll() |
96 | super(TestCase, self).tearDown() |
97 | finally: |
98 | - try: |
99 | - # Clean up any ips associated during the test. |
100 | - ctxt = context.get_admin_context() |
101 | - db.fixed_ip_disassociate_all_by_timeout(ctxt, FLAGS.host, |
102 | - self.start) |
103 | - db.network_disassociate_all(ctxt) |
104 | - |
105 | - db.security_group_destroy_all(ctxt) |
106 | - except Exception: |
107 | - pass |
108 | - |
109 | # Clean out fake_rabbit's queue if we used it |
110 | if FLAGS.fake_rabbit: |
111 | fakerabbit.reset_all() |
112 | |
113 | === modified file 'nova/tests/__init__.py' |
114 | --- nova/tests/__init__.py 2011-01-19 01:32:54 +0000 |
115 | +++ nova/tests/__init__.py 2011-02-23 23:39:43 +0000 |
116 | @@ -37,5 +37,30 @@ |
117 | |
118 | |
119 | def setup(): |
120 | + import os |
121 | + import shutil |
122 | + |
123 | + from nova import context |
124 | + from nova import flags |
125 | from nova.db import migration |
126 | + from nova.network import manager as network_manager |
127 | + from nova.tests import fake_flags |
128 | + |
129 | + FLAGS = flags.FLAGS |
130 | + |
131 | + testdb = os.path.join(FLAGS.state_path, FLAGS.sqlite_db) |
132 | + if os.path.exists(testdb): |
133 | + os.unlink(testdb) |
134 | migration.db_sync() |
135 | + ctxt = context.get_admin_context() |
136 | + network_manager.VlanManager().create_networks(ctxt, |
137 | + FLAGS.fixed_range, |
138 | + FLAGS.num_networks, |
139 | + FLAGS.network_size, |
140 | + FLAGS.fixed_range_v6, |
141 | + FLAGS.vlan_start, |
142 | + FLAGS.vpn_start, |
143 | + ) |
144 | + |
145 | + cleandb = os.path.join(FLAGS.state_path, FLAGS.sqlite_clean_db) |
146 | + shutil.copyfile(testdb, cleandb) |
147 | |
148 | === modified file 'nova/tests/api/openstack/__init__.py' |
149 | --- nova/tests/api/openstack/__init__.py 2011-02-09 18:30:40 +0000 |
150 | +++ nova/tests/api/openstack/__init__.py 2011-02-23 23:39:43 +0000 |
151 | @@ -16,7 +16,7 @@ |
152 | # under the License. |
153 | |
154 | import webob.dec |
155 | -import unittest |
156 | +from nova import test |
157 | |
158 | from nova import context |
159 | from nova import flags |
160 | @@ -33,7 +33,7 @@ |
161 | return "" |
162 | |
163 | |
164 | -class RateLimitingMiddlewareTest(unittest.TestCase): |
165 | +class RateLimitingMiddlewareTest(test.TestCase): |
166 | |
167 | def test_get_action_name(self): |
168 | middleware = RateLimitingMiddleware(simple_wsgi) |
169 | |
170 | === modified file 'nova/tests/api/openstack/test_adminapi.py' |
171 | --- nova/tests/api/openstack/test_adminapi.py 2011-01-06 07:08:01 +0000 |
172 | +++ nova/tests/api/openstack/test_adminapi.py 2011-02-23 23:39:43 +0000 |
173 | @@ -15,13 +15,13 @@ |
174 | # License for the specific language governing permissions and limitations |
175 | # under the License. |
176 | |
177 | -import unittest |
178 | |
179 | import stubout |
180 | import webob |
181 | from paste import urlmap |
182 | |
183 | from nova import flags |
184 | +from nova import test |
185 | from nova.api import openstack |
186 | from nova.api.openstack import ratelimiting |
187 | from nova.api.openstack import auth |
188 | @@ -30,9 +30,10 @@ |
189 | FLAGS = flags.FLAGS |
190 | |
191 | |
192 | -class AdminAPITest(unittest.TestCase): |
193 | +class AdminAPITest(test.TestCase): |
194 | |
195 | def setUp(self): |
196 | + super(AdminAPITest, self).setUp() |
197 | self.stubs = stubout.StubOutForTesting() |
198 | fakes.FakeAuthManager.auth_data = {} |
199 | fakes.FakeAuthDatabase.data = {} |
200 | @@ -44,6 +45,7 @@ |
201 | def tearDown(self): |
202 | self.stubs.UnsetAll() |
203 | FLAGS.allow_admin_api = self.allow_admin |
204 | + super(AdminAPITest, self).tearDown() |
205 | |
206 | def test_admin_enabled(self): |
207 | FLAGS.allow_admin_api = True |
208 | @@ -58,8 +60,5 @@ |
209 | # We should still be able to access public operations. |
210 | req = webob.Request.blank('/v1.0/flavors') |
211 | res = req.get_response(fakes.wsgi_app()) |
212 | - self.assertEqual(res.status_int, 200) |
213 | # TODO: Confirm admin operations are unavailable. |
214 | - |
215 | -if __name__ == '__main__': |
216 | - unittest.main() |
217 | + self.assertEqual(res.status_int, 200) |
218 | |
219 | === modified file 'nova/tests/api/openstack/test_api.py' |
220 | --- nova/tests/api/openstack/test_api.py 2011-01-06 19:22:11 +0000 |
221 | +++ nova/tests/api/openstack/test_api.py 2011-02-23 23:39:43 +0000 |
222 | @@ -15,17 +15,17 @@ |
223 | # License for the specific language governing permissions and limitations |
224 | # under the License. |
225 | |
226 | -import unittest |
227 | import webob.exc |
228 | import webob.dec |
229 | |
230 | from webob import Request |
231 | |
232 | +from nova import test |
233 | from nova.api import openstack |
234 | from nova.api.openstack import faults |
235 | |
236 | |
237 | -class APITest(unittest.TestCase): |
238 | +class APITest(test.TestCase): |
239 | |
240 | def _wsgi_app(self, inner_app): |
241 | # simpler version of the app than fakes.wsgi_app |
242 | |
243 | === modified file 'nova/tests/api/openstack/test_auth.py' |
244 | --- nova/tests/api/openstack/test_auth.py 2011-02-19 07:33:06 +0000 |
245 | +++ nova/tests/api/openstack/test_auth.py 2011-02-23 23:39:43 +0000 |
246 | @@ -16,7 +16,6 @@ |
247 | # under the License. |
248 | |
249 | import datetime |
250 | -import unittest |
251 | |
252 | import stubout |
253 | import webob |
254 | @@ -27,12 +26,14 @@ |
255 | import nova.auth.manager |
256 | from nova import auth |
257 | from nova import context |
258 | +from nova import test |
259 | from nova.tests.api.openstack import fakes |
260 | |
261 | |
262 | -class Test(unittest.TestCase): |
263 | +class Test(test.TestCase): |
264 | |
265 | def setUp(self): |
266 | + super(Test, self).setUp() |
267 | self.stubs = stubout.StubOutForTesting() |
268 | self.stubs.Set(nova.api.openstack.auth.AuthMiddleware, |
269 | '__init__', fakes.fake_auth_init) |
270 | @@ -45,6 +46,7 @@ |
271 | def tearDown(self): |
272 | self.stubs.UnsetAll() |
273 | fakes.fake_data_store = {} |
274 | + super(Test, self).tearDown() |
275 | |
276 | def test_authorize_user(self): |
277 | f = fakes.FakeAuthManager() |
278 | @@ -128,8 +130,9 @@ |
279 | self.assertEqual(result.status, '401 Unauthorized') |
280 | |
281 | |
282 | -class TestLimiter(unittest.TestCase): |
283 | +class TestLimiter(test.TestCase): |
284 | def setUp(self): |
285 | + super(TestLimiter, self).setUp() |
286 | self.stubs = stubout.StubOutForTesting() |
287 | self.stubs.Set(nova.api.openstack.auth.AuthMiddleware, |
288 | '__init__', fakes.fake_auth_init) |
289 | @@ -141,6 +144,7 @@ |
290 | def tearDown(self): |
291 | self.stubs.UnsetAll() |
292 | fakes.fake_data_store = {} |
293 | + super(TestLimiter, self).tearDown() |
294 | |
295 | def test_authorize_token(self): |
296 | f = fakes.FakeAuthManager() |
297 | @@ -161,7 +165,3 @@ |
298 | result = req.get_response(fakes.wsgi_app()) |
299 | self.assertEqual(result.status, '200 OK') |
300 | self.assertEqual(result.headers['X-Test-Success'], 'True') |
301 | - |
302 | - |
303 | -if __name__ == '__main__': |
304 | - unittest.main() |
305 | |
306 | === modified file 'nova/tests/api/openstack/test_common.py' |
307 | --- nova/tests/api/openstack/test_common.py 2011-02-09 18:30:40 +0000 |
308 | +++ nova/tests/api/openstack/test_common.py 2011-02-23 23:39:43 +0000 |
309 | @@ -19,14 +19,14 @@ |
310 | Test suites for 'common' code used throughout the OpenStack HTTP API. |
311 | """ |
312 | |
313 | -import unittest |
314 | |
315 | from webob import Request |
316 | |
317 | +from nova import test |
318 | from nova.api.openstack.common import limited |
319 | |
320 | |
321 | -class LimiterTest(unittest.TestCase): |
322 | +class LimiterTest(test.TestCase): |
323 | """ |
324 | Unit tests for the `nova.api.openstack.common.limited` method which takes |
325 | in a list of items and, depending on the 'offset' and 'limit' GET params, |
326 | @@ -37,6 +37,7 @@ |
327 | """ |
328 | Run before each test. |
329 | """ |
330 | + super(LimiterTest, self).setUp() |
331 | self.tiny = range(1) |
332 | self.small = range(10) |
333 | self.medium = range(1000) |
334 | |
335 | === modified file 'nova/tests/api/openstack/test_faults.py' |
336 | --- nova/tests/api/openstack/test_faults.py 2010-10-22 07:48:27 +0000 |
337 | +++ nova/tests/api/openstack/test_faults.py 2011-02-23 23:39:43 +0000 |
338 | @@ -15,15 +15,15 @@ |
339 | # License for the specific language governing permissions and limitations |
340 | # under the License. |
341 | |
342 | -import unittest |
343 | import webob |
344 | import webob.dec |
345 | import webob.exc |
346 | |
347 | +from nova import test |
348 | from nova.api.openstack import faults |
349 | |
350 | |
351 | -class TestFaults(unittest.TestCase): |
352 | +class TestFaults(test.TestCase): |
353 | |
354 | def test_fault_parts(self): |
355 | req = webob.Request.blank('/.xml') |
356 | |
357 | === modified file 'nova/tests/api/openstack/test_flavors.py' |
358 | --- nova/tests/api/openstack/test_flavors.py 2011-01-06 07:08:01 +0000 |
359 | +++ nova/tests/api/openstack/test_flavors.py 2011-02-23 23:39:43 +0000 |
360 | @@ -15,18 +15,18 @@ |
361 | # License for the specific language governing permissions and limitations |
362 | # under the License. |
363 | |
364 | -import unittest |
365 | - |
366 | import stubout |
367 | import webob |
368 | |
369 | +from nova import test |
370 | import nova.api |
371 | from nova.api.openstack import flavors |
372 | from nova.tests.api.openstack import fakes |
373 | |
374 | |
375 | -class FlavorsTest(unittest.TestCase): |
376 | +class FlavorsTest(test.TestCase): |
377 | def setUp(self): |
378 | + super(FlavorsTest, self).setUp() |
379 | self.stubs = stubout.StubOutForTesting() |
380 | fakes.FakeAuthManager.auth_data = {} |
381 | fakes.FakeAuthDatabase.data = {} |
382 | @@ -36,6 +36,7 @@ |
383 | |
384 | def tearDown(self): |
385 | self.stubs.UnsetAll() |
386 | + super(FlavorsTest, self).tearDown() |
387 | |
388 | def test_get_flavor_list(self): |
389 | req = webob.Request.blank('/v1.0/flavors') |
390 | @@ -43,6 +44,3 @@ |
391 | |
392 | def test_get_flavor_by_id(self): |
393 | pass |
394 | - |
395 | -if __name__ == '__main__': |
396 | - unittest.main() |
397 | |
398 | === modified file 'nova/tests/api/openstack/test_images.py' |
399 | --- nova/tests/api/openstack/test_images.py 2011-01-26 01:22:16 +0000 |
400 | +++ nova/tests/api/openstack/test_images.py 2011-02-23 23:39:43 +0000 |
401 | @@ -22,7 +22,6 @@ |
402 | |
403 | import json |
404 | import datetime |
405 | -import unittest |
406 | |
407 | import stubout |
408 | import webob |
409 | @@ -30,6 +29,7 @@ |
410 | from nova import context |
411 | from nova import exception |
412 | from nova import flags |
413 | +from nova import test |
414 | from nova import utils |
415 | import nova.api.openstack |
416 | from nova.api.openstack import images |
417 | @@ -130,12 +130,13 @@ |
418 | self.assertEquals(1, num_images) |
419 | |
420 | |
421 | -class LocalImageServiceTest(unittest.TestCase, |
422 | +class LocalImageServiceTest(test.TestCase, |
423 | BaseImageServiceTests): |
424 | |
425 | """Tests the local image service""" |
426 | |
427 | def setUp(self): |
428 | + super(LocalImageServiceTest, self).setUp() |
429 | self.stubs = stubout.StubOutForTesting() |
430 | service_class = 'nova.image.local.LocalImageService' |
431 | self.service = utils.import_object(service_class) |
432 | @@ -145,14 +146,16 @@ |
433 | self.service.delete_all() |
434 | self.service.delete_imagedir() |
435 | self.stubs.UnsetAll() |
436 | - |
437 | - |
438 | -class GlanceImageServiceTest(unittest.TestCase, |
439 | + super(LocalImageServiceTest, self).tearDown() |
440 | + |
441 | + |
442 | +class GlanceImageServiceTest(test.TestCase, |
443 | BaseImageServiceTests): |
444 | |
445 | """Tests the local image service""" |
446 | |
447 | def setUp(self): |
448 | + super(GlanceImageServiceTest, self).setUp() |
449 | self.stubs = stubout.StubOutForTesting() |
450 | fakes.stub_out_glance(self.stubs) |
451 | fakes.stub_out_compute_api_snapshot(self.stubs) |
452 | @@ -163,9 +166,10 @@ |
453 | |
454 | def tearDown(self): |
455 | self.stubs.UnsetAll() |
456 | - |
457 | - |
458 | -class ImageControllerWithGlanceServiceTest(unittest.TestCase): |
459 | + super(GlanceImageServiceTest, self).tearDown() |
460 | + |
461 | + |
462 | +class ImageControllerWithGlanceServiceTest(test.TestCase): |
463 | |
464 | """Test of the OpenStack API /images application controller""" |
465 | |
466 | @@ -194,6 +198,7 @@ |
467 | 'image_type': 'ramdisk'}] |
468 | |
469 | def setUp(self): |
470 | + super(ImageControllerWithGlanceServiceTest, self).setUp() |
471 | self.orig_image_service = FLAGS.image_service |
472 | FLAGS.image_service = 'nova.image.glance.GlanceImageService' |
473 | self.stubs = stubout.StubOutForTesting() |
474 | @@ -208,6 +213,7 @@ |
475 | def tearDown(self): |
476 | self.stubs.UnsetAll() |
477 | FLAGS.image_service = self.orig_image_service |
478 | + super(ImageControllerWithGlanceServiceTest, self).tearDown() |
479 | |
480 | def test_get_image_index(self): |
481 | req = webob.Request.blank('/v1.0/images') |
482 | |
483 | === modified file 'nova/tests/api/openstack/test_ratelimiting.py' |
484 | --- nova/tests/api/openstack/test_ratelimiting.py 2010-10-22 07:48:27 +0000 |
485 | +++ nova/tests/api/openstack/test_ratelimiting.py 2011-02-23 23:39:43 +0000 |
486 | @@ -1,15 +1,16 @@ |
487 | import httplib |
488 | import StringIO |
489 | import time |
490 | -import unittest |
491 | import webob |
492 | |
493 | +from nova import test |
494 | import nova.api.openstack.ratelimiting as ratelimiting |
495 | |
496 | |
497 | -class LimiterTest(unittest.TestCase): |
498 | +class LimiterTest(test.TestCase): |
499 | |
500 | def setUp(self): |
501 | + super(LimiterTest, self).setUp() |
502 | self.limits = { |
503 | 'a': (5, ratelimiting.PER_SECOND), |
504 | 'b': (5, ratelimiting.PER_MINUTE), |
505 | @@ -83,9 +84,10 @@ |
506 | return self._delay |
507 | |
508 | |
509 | -class WSGIAppTest(unittest.TestCase): |
510 | +class WSGIAppTest(test.TestCase): |
511 | |
512 | def setUp(self): |
513 | + super(WSGIAppTest, self).setUp() |
514 | self.limiter = FakeLimiter(self) |
515 | self.app = ratelimiting.WSGIApp(self.limiter) |
516 | |
517 | @@ -206,7 +208,7 @@ |
518 | httplib.HTTPConnection = HTTPConnectionDecorator(httplib.HTTPConnection) |
519 | |
520 | |
521 | -class WSGIAppProxyTest(unittest.TestCase): |
522 | +class WSGIAppProxyTest(test.TestCase): |
523 | |
524 | def setUp(self): |
525 | """Our WSGIAppProxy is going to call across an HTTPConnection to a |
526 | @@ -218,6 +220,7 @@ |
527 | at the WSGIApp. And the limiter isn't real -- it's a fake that |
528 | behaves the way we tell it to. |
529 | """ |
530 | + super(WSGIAppProxyTest, self).setUp() |
531 | self.limiter = FakeLimiter(self) |
532 | app = ratelimiting.WSGIApp(self.limiter) |
533 | wire_HTTPConnection_to_WSGI('100.100.100.100:80', app) |
534 | @@ -238,7 +241,3 @@ |
535 | self.limiter.mock('murder', 'brutus', None) |
536 | self.proxy.perform('stab', 'brutus') |
537 | self.assertRaises(AssertionError, shouldRaise) |
538 | - |
539 | - |
540 | -if __name__ == '__main__': |
541 | - unittest.main() |
542 | |
543 | === modified file 'nova/tests/api/openstack/test_servers.py' |
544 | --- nova/tests/api/openstack/test_servers.py 2011-02-23 18:11:35 +0000 |
545 | +++ nova/tests/api/openstack/test_servers.py 2011-02-23 23:39:43 +0000 |
546 | @@ -17,13 +17,13 @@ |
547 | |
548 | import datetime |
549 | import json |
550 | -import unittest |
551 | |
552 | import stubout |
553 | import webob |
554 | |
555 | from nova import db |
556 | from nova import flags |
557 | +from nova import test |
558 | import nova.api.openstack |
559 | from nova.api.openstack import servers |
560 | import nova.db.api |
561 | @@ -113,9 +113,10 @@ |
562 | return True |
563 | |
564 | |
565 | -class ServersTest(unittest.TestCase): |
566 | +class ServersTest(test.TestCase): |
567 | |
568 | def setUp(self): |
569 | + super(ServersTest, self).setUp() |
570 | self.stubs = stubout.StubOutForTesting() |
571 | fakes.FakeAuthManager.auth_data = {} |
572 | fakes.FakeAuthDatabase.data = {} |
573 | @@ -146,6 +147,7 @@ |
574 | def tearDown(self): |
575 | self.stubs.UnsetAll() |
576 | FLAGS.allow_admin_api = self.allow_admin |
577 | + super(ServersTest, self).tearDown() |
578 | |
579 | def test_get_server_by_id(self): |
580 | req = webob.Request.blank('/v1.0/servers/1') |
581 | @@ -417,7 +419,3 @@ |
582 | res = req.get_response(fakes.wsgi_app()) |
583 | self.assertEqual(res.status, '202 Accepted') |
584 | self.assertEqual(self.server_delete_called, True) |
585 | - |
586 | - |
587 | -if __name__ == "__main__": |
588 | - unittest.main() |
589 | |
590 | === modified file 'nova/tests/api/openstack/test_shared_ip_groups.py' |
591 | --- nova/tests/api/openstack/test_shared_ip_groups.py 2011-01-06 08:55:16 +0000 |
592 | +++ nova/tests/api/openstack/test_shared_ip_groups.py 2011-02-23 23:39:43 +0000 |
593 | @@ -15,19 +15,20 @@ |
594 | # License for the specific language governing permissions and limitations |
595 | # under the License. |
596 | |
597 | -import unittest |
598 | - |
599 | import stubout |
600 | |
601 | +from nova import test |
602 | from nova.api.openstack import shared_ip_groups |
603 | |
604 | |
605 | -class SharedIpGroupsTest(unittest.TestCase): |
606 | +class SharedIpGroupsTest(test.TestCase): |
607 | def setUp(self): |
608 | + super(SharedIpGroupsTest, self).setUp() |
609 | self.stubs = stubout.StubOutForTesting() |
610 | |
611 | def tearDown(self): |
612 | self.stubs.UnsetAll() |
613 | + super(SharedIpGroupsTest, self).tearDown() |
614 | |
615 | def test_get_shared_ip_groups(self): |
616 | pass |
617 | |
618 | === modified file 'nova/tests/api/openstack/test_zones.py' |
619 | --- nova/tests/api/openstack/test_zones.py 2011-02-19 09:51:13 +0000 |
620 | +++ nova/tests/api/openstack/test_zones.py 2011-02-23 23:39:43 +0000 |
621 | @@ -13,7 +13,6 @@ |
622 | # License for the specific language governing permissions and limitations |
623 | # under the License. |
624 | |
625 | -import unittest |
626 | |
627 | import stubout |
628 | import webob |
629 | @@ -22,6 +21,7 @@ |
630 | import nova.db |
631 | from nova import context |
632 | from nova import flags |
633 | +from nova import test |
634 | from nova.api.openstack import zones |
635 | from nova.tests.api.openstack import fakes |
636 | |
637 | @@ -60,8 +60,9 @@ |
638 | password='qwerty')] |
639 | |
640 | |
641 | -class ZonesTest(unittest.TestCase): |
642 | +class ZonesTest(test.TestCase): |
643 | def setUp(self): |
644 | + super(ZonesTest, self).setUp() |
645 | self.stubs = stubout.StubOutForTesting() |
646 | fakes.FakeAuthManager.auth_data = {} |
647 | fakes.FakeAuthDatabase.data = {} |
648 | @@ -81,6 +82,7 @@ |
649 | def tearDown(self): |
650 | self.stubs.UnsetAll() |
651 | FLAGS.allow_admin_api = self.allow_admin |
652 | + super(ZonesTest, self).tearDown() |
653 | |
654 | def test_get_zone_list(self): |
655 | req = webob.Request.blank('/v1.0/zones') |
656 | @@ -134,7 +136,3 @@ |
657 | self.assertEqual(res_dict['zone']['id'], 1) |
658 | self.assertEqual(res_dict['zone']['api_url'], 'http://foo.com') |
659 | self.assertFalse('username' in res_dict['zone']) |
660 | - |
661 | - |
662 | -if __name__ == '__main__': |
663 | - unittest.main() |
664 | |
665 | === modified file 'nova/tests/api/test_wsgi.py' |
666 | --- nova/tests/api/test_wsgi.py 2010-10-25 16:25:50 +0000 |
667 | +++ nova/tests/api/test_wsgi.py 2011-02-23 23:39:43 +0000 |
668 | @@ -21,7 +21,7 @@ |
669 | Test WSGI basics and provide some helper functions for other WSGI tests. |
670 | """ |
671 | |
672 | -import unittest |
673 | +from nova import test |
674 | |
675 | import routes |
676 | import webob |
677 | @@ -29,7 +29,7 @@ |
678 | from nova import wsgi |
679 | |
680 | |
681 | -class Test(unittest.TestCase): |
682 | +class Test(test.TestCase): |
683 | |
684 | def test_debug(self): |
685 | |
686 | @@ -92,7 +92,7 @@ |
687 | self.assertNotEqual(result.body, "123") |
688 | |
689 | |
690 | -class SerializerTest(unittest.TestCase): |
691 | +class SerializerTest(test.TestCase): |
692 | |
693 | def match(self, url, accept, expect): |
694 | input_dict = dict(servers=dict(a=(2, 3))) |
695 | |
696 | === modified file 'nova/tests/fake_flags.py' |
697 | --- nova/tests/fake_flags.py 2011-02-23 23:39:43 +0000 |
698 | +++ nova/tests/fake_flags.py 2011-02-23 23:39:43 +0000 |
699 | @@ -29,8 +29,8 @@ |
700 | flags.DECLARE('network_size', 'nova.network.manager') |
701 | flags.DECLARE('num_networks', 'nova.network.manager') |
702 | flags.DECLARE('fake_network', 'nova.network.manager') |
703 | -FLAGS.network_size = 16 |
704 | -FLAGS.num_networks = 5 |
705 | +FLAGS.network_size = 8 |
706 | +FLAGS.num_networks = 2 |
707 | FLAGS.fake_network = True |
708 | flags.DECLARE('num_shelves', 'nova.volume.driver') |
709 | flags.DECLARE('blades_per_shelf', 'nova.volume.driver') |
710 | @@ -39,5 +39,5 @@ |
711 | FLAGS.blades_per_shelf = 4 |
712 | FLAGS.iscsi_num_targets = 8 |
713 | FLAGS.verbose = True |
714 | -FLAGS.sql_connection = 'sqlite:///tests.sqlite' |
715 | +FLAGS.sqlite_db = "tests.sqlite" |
716 | FLAGS.use_ipv6 = True |
717 | |
718 | === modified file 'nova/tests/objectstore_unittest.py' |
719 | --- nova/tests/objectstore_unittest.py 2011-01-04 05:23:35 +0000 |
720 | +++ nova/tests/objectstore_unittest.py 2011-02-23 23:39:43 +0000 |
721 | @@ -311,4 +311,5 @@ |
722 | self.auth_manager.delete_user('admin') |
723 | self.auth_manager.delete_project('admin') |
724 | stop_listening = defer.maybeDeferred(self.listening_port.stopListening) |
725 | + super(S3APITestCase, self).tearDown() |
726 | return defer.DeferredList([stop_listening]) |
727 | |
728 | === modified file 'nova/tests/test_direct.py' |
729 | --- nova/tests/test_direct.py 2011-02-21 07:16:10 +0000 |
730 | +++ nova/tests/test_direct.py 2011-02-23 23:39:43 +0000 |
731 | @@ -52,6 +52,7 @@ |
732 | |
733 | def tearDown(self): |
734 | direct.ROUTES = {} |
735 | + super(DirectTestCase, self).tearDown() |
736 | |
737 | def test_delegated_auth(self): |
738 | req = webob.Request.blank('/fake/context') |
739 | |
740 | === modified file 'nova/tests/test_network.py' |
741 | --- nova/tests/test_network.py 2011-02-23 07:21:01 +0000 |
742 | +++ nova/tests/test_network.py 2011-02-23 23:39:43 +0000 |
743 | @@ -42,15 +42,13 @@ |
744 | # flags in the corresponding section in nova-dhcpbridge |
745 | self.flags(connection_type='fake', |
746 | fake_call=True, |
747 | - fake_network=True, |
748 | - network_size=16, |
749 | - num_networks=5) |
750 | + fake_network=True) |
751 | self.manager = manager.AuthManager() |
752 | self.user = self.manager.create_user('netuser', 'netuser', 'netuser') |
753 | self.projects = [] |
754 | self.network = utils.import_object(FLAGS.network_manager) |
755 | self.context = context.RequestContext(project=None, user=self.user) |
756 | - for i in range(5): |
757 | + for i in range(FLAGS.num_networks): |
758 | name = 'project%s' % i |
759 | project = self.manager.create_project(name, 'netuser', name) |
760 | self.projects.append(project) |
761 | @@ -195,7 +193,7 @@ |
762 | first = self._create_address(0) |
763 | lease_ip(first) |
764 | instance_ids = [] |
765 | - for i in range(1, 5): |
766 | + for i in range(1, FLAGS.num_networks): |
767 | instance_ref = self._create_instance(i, mac=utils.generate_mac()) |
768 | instance_ids.append(instance_ref['id']) |
769 | address = self._create_address(i, instance_ref['id']) |
770 | |
771 | === modified file 'nova/tests/test_virt.py' |
772 | --- nova/tests/test_virt.py 2011-02-23 07:21:01 +0000 |
773 | +++ nova/tests/test_virt.py 2011-02-23 23:39:43 +0000 |
774 | @@ -207,9 +207,9 @@ |
775 | db.instance_destroy(user_context, instance_ref['id']) |
776 | |
777 | def tearDown(self): |
778 | + self.manager.delete_project(self.project) |
779 | + self.manager.delete_user(self.user) |
780 | super(LibvirtConnTestCase, self).tearDown() |
781 | - self.manager.delete_project(self.project) |
782 | - self.manager.delete_user(self.user) |
783 | |
784 | |
785 | class IptablesFirewallTestCase(test.TestCase): |
786 | @@ -390,6 +390,7 @@ |
787 | def tearDown(self): |
788 | self.manager.delete_project(self.project) |
789 | self.manager.delete_user(self.user) |
790 | + super(NWFilterTestCase, self).tearDown() |
791 | |
792 | def test_cidr_rule_nwfilter_xml(self): |
793 | cloud_controller = cloud.CloudController() |
794 | |
795 | === modified file 'run_tests.py' |
796 | --- run_tests.py 2011-02-23 23:39:43 +0000 |
797 | +++ run_tests.py 2011-02-23 23:39:43 +0000 |
798 | @@ -61,8 +61,8 @@ |
799 | import sys |
800 | |
801 | from nose import config |
802 | +from nose import core |
803 | from nose import result |
804 | -from nose import core |
805 | |
806 | from nova import log as logging |
807 | from nova.tests import fake_flags |
808 | @@ -277,10 +277,6 @@ |
809 | |
810 | if __name__ == '__main__': |
811 | logging.setup() |
812 | - testdir = os.path.abspath(os.path.join("nova", "tests")) |
813 | - testdb = os.path.join(testdir, "tests.sqlite") |
814 | - if os.path.exists(testdb): |
815 | - os.unlink(testdb) |
816 | # If any argument looks like a test name but doesn't have "nova.tests" in |
817 | # front of it, automatically add that so we don't have to type as much |
818 | argv = [] |
819 | @@ -290,6 +286,7 @@ |
820 | else: |
821 | argv.append(x) |
822 | |
823 | + testdir = os.path.abspath(os.path.join("nova", "tests")) |
824 | c = config.Config(stream=sys.stdout, |
825 | env=os.environ, |
826 | verbosity=3, |
Tests run in < 80 seconds on my dev box, which is much faster.