nova/nova/tests
Davanum Srinivas dd3f96e915 Fix for qemu-nbd hang
NBD device once used seem to run into intermittent trouble when
used with mount repeatedly. Adding code to explicitly flush the
device buffers using 'blockdev --flushbufs'.

Closes-Bug: #973413
Partial-Bug: #1254890
Change-Id: I2b7053b9a069d6e82f6f6baf9ad480efa4388d91
2013-12-30 14:26:16 -05:00
..
CA
api Merge "Add apache2 license header to appropriate files for enabling H102" 2013-12-30 06:45:44 +00:00
bundle
cells Merge "Revert graceful shutdown patch" 2013-12-16 21:01:47 +00:00
cert Add V2 rpc api for cert 2013-11-25 12:15:40 -05:00
compute Merge "Object-ify build_and_run_instance" 2013-12-23 08:53:44 +00:00
conductor Remove unused variables in test_conductor.py 2013-12-23 04:28:18 -05:00
console Remove console 1.X rpc api 2013-11-25 12:15:40 -05:00
consoleauth Utilizes assertIsNone and assertIsNotNone - tests/etc 2013-10-31 06:06:02 +09:00
db Don't use deprecated module commands 2013-12-23 18:25:28 -08:00
fake_loadables
glance Added 'page_size' param to image list 2013-09-24 09:53:00 +05:30
image Comply with new hacking 0.8 release 2013-12-02 10:58:45 +09:00
integrated Remove middleware ratelimits from v3 api 2013-12-15 18:52:03 +08:00
keymgr Replace assertEquals with assertEqual - tests/etc 2013-11-12 14:51:29 +08:00
monkey_patch_example
network Merge "Check Neutron port quota during validate_networks in API" 2013-12-21 03:01:44 +00:00
objects Revert recent change to ComputeNode 2013-12-20 16:57:34 -08:00
pci Check for None when cleaning PCI dev usage 2013-10-13 20:31:18 -07:00
scheduler Serialize instance object while building request_spec 2013-12-17 18:17:28 -05:00
servicegroup Utilizes assertIn - tests/etc 2013-10-21 10:01:20 +08:00
ssl_cert
virt Fix for qemu-nbd hang 2013-12-30 14:26:16 -05:00
volume Convert TestCases to NoDBTestCase 2013-09-21 20:46:04 +10:00
README.rst
__init__.py
cast_as_call.py Add CastAsCall fixture 2013-08-22 15:38:06 +01:00
conf_fixture.py Fix interprocess locks when running unit-tests 2013-12-19 18:08:29 +02:00
fake_crypto.py
fake_hosts.py Make compute_api use Service and ComputeNode objects 2013-08-29 00:18:46 -07:00
fake_instance.py Update Instance from database after destroy 2013-12-04 13:01:46 -05:00
fake_instance_actions.py Make compute_api use InstanceAction object 2013-08-10 12:00:50 -07:00
fake_ldap.py
fake_network.py Extends V3 servers api for pci support 2013-12-04 10:01:40 +00:00
fake_network_cache_model.py
fake_notifier.py Port to oslo.messaging.Notifier API 2013-09-05 06:26:01 +01:00
fake_policy.py Merge "Extends V3 servers api for pci support" 2013-12-11 22:08:53 +00:00
fake_processutils.py Nova-all: Replace basestring by six for python3 compatability 2013-10-28 16:55:05 +08:00
fake_utils.py
fake_volume.py
fakeguestfs.py Don't change the default attach-method 2013-09-18 12:00:32 +10:00
matchers.py
policy_fixture.py
test_api_validation.py Add API input validation framework 2013-11-27 05:45:37 +09:00
test_availability_zones.py Replace assertEquals with assertEqual - tests/etc 2013-11-12 14:51:29 +08:00
test_baserpc.py
test_bdm.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_block_device.py Replace assertEquals with assertEqual - tests/etc 2013-11-12 14:51:29 +08:00
test_cinder.py Replace assertEquals with assertEqual - tests/etc 2013-11-12 14:51:29 +08:00
test_configdrive2.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_context.py Merge "Fixes RequestContext initialization failure." 2013-11-25 12:24:45 +00:00
test_crypto.py
test_exception.py Replace assertEquals with assertEqual - tests/etc 2013-11-12 14:51:29 +08:00
test_flavors.py Merge "Enable non-ascii characters in flavor names" 2013-11-26 01:33:23 +00:00
test_hooks.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_instance_types_extra_specs.py Replace assertEquals with assertEqual - tests/etc 2013-11-12 14:51:29 +08:00
test_iptables_network.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_ipv6.py Replace assertEquals with assertEqual - tests/etc 2013-11-12 14:51:29 +08:00
test_linuxscsi.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_loadables.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_manager.py Utilizes assertIn - tests/etc 2013-10-21 10:01:20 +08:00
test_matchers.py Change the duplicate class name TestDictMatches in test_matches.py 2013-09-11 13:57:04 +08:00
test_metadata.py Prevent spoofing instance_id from neutron to nova 2013-12-11 12:36:20 -08:00
test_notifications.py Replace assertEquals with assertEqual - tests/etc 2013-11-12 14:51:29 +08:00
test_nova_manage.py Replace assertEquals with assertEqual - tests/etc 2013-11-12 14:51:29 +08:00
test_objectstore.py Replace assertEquals with assertEqual - tests/etc 2013-11-12 14:51:29 +08:00
test_pipelib.py
test_policy.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_quota.py Comply with new hacking 0.8 release 2013-12-02 10:58:45 +09:00
test_safeutils.py Utilizes assertIsNone and assertIsNotNone - tests/etc 2013-10-31 06:06:02 +09:00
test_service.py replace assertNotEquals with assertNotEqual 2013-11-13 23:57:03 -08:00
test_test.py
test_test_utils.py Claim IPv6 is unsupported if no interface with IPv6 configured 2013-10-28 16:31:33 +01:00
test_unit.py Add byte unit constants 2013-10-22 18:47:00 -07:00
test_utils.py Setting the xen vm device id on vm record 2013-12-18 11:56:27 +05:30
test_versions.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_weights.py Normalize the weights instead of using raw values 2013-12-11 20:24:16 +01:00
test_wsgi.py Ensure api_paste_conf is an absolute path 2013-12-10 13:42:05 +01:00
utils.py Rename instance_type to flavor in test_utils and nova.tests.utils 2013-12-10 13:08:14 -08:00

README.rst

OpenStack Nova Testing Infrastructure

This README file attempts to provide current and prospective contributors with everything they need to know in order to start creating unit tests for nova.

Note: the content for the rest of this file will be added as the work items in the following blueprint are completed: https://blueprints.launchpad.net/nova/+spec/consolidate-testing-infrastructure

Test Types: Unit vs. Functional vs. Integration

TBD

Writing Unit Tests

TBD

Using Fakes

TBD

test.TestCase

The TestCase class from nova.test (generally imported as test) will automatically manage self.stubs using the stubout module and self.mox using the mox module during the setUp step. They will automatically verify and clean up during the tearDown step.

If using test.TestCase, calling the super class setUp is required and calling the super class tearDown is required to be last if tearDown is overriden.

Writing Functional Tests

TBD

Writing Integration Tests

TBD

Tests and Exceptions

A properly written test asserts that particular behavior occurs. This can be a success condition or a failure condition, including an exception. When asserting that a particular exception is raised, the most specific exception possible should be used.

In particular, testing for Exception being raised is almost always a mistake since it will match (almost) every exception, even those unrelated to the exception intended to be tested.

This applies to catching exceptions manually with a try/except block, or using assertRaises().

Example:

self.assertRaises(exception.InstanceNotFound, db.instance_get_by_uuid,
                  elevated, instance_uuid)

If a stubbed function/method needs a generic exception for testing purposes, test.TestingException is available.

Example:

def stubbed_method(self):
    raise test.TestingException()
self.stubs.Set(cls, 'inner_method', stubbed_method)

obj = cls()
self.assertRaises(test.TestingException, obj.outer_method)

Stubbing and Mocking

Whenever possible, tests SHOULD NOT stub and mock out the same function.

If it's unavoidable, tests SHOULD define stubs before mocks since the TestCase cleanup routine will un-mock before un-stubbing. Doing otherwise results in a test that leaks stubbed functions, causing hard-to-debug interference between tests1.

If a mock must take place before a stub, any stubs after the mock call MUST be manually unset using self.cleanUp calls within the test.


  1. https://bugs.launchpad.net/nova/+bug/1180671↩︎