You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jichenjc 6abb88befe
Check flavor type before add tenant access
8 years ago
api Check flavor type before add tenant access 8 years ago
cells Cells: cell scheduler anti-affinity filter 8 years ago
cmd Switch to oslo.reports 8 years ago
compute Merge "Execute _poll_shelved_instances only if shelved_offload_time is > 0" 8 years ago
conductor Merge "Remove and deprecate conductor task_log methods" 8 years ago
console Fix noVNC console access for an IPv6 setup 8 years ago
consoleauth Use six.moves.range for Python 3 8 years ago
db Use utf8_bin collation on the flavor extra-specs table in MySQL 8 years ago
image Switch to oslo.service library 8 years ago
network Merge "Build Neutron network data for metadata service" 8 years ago
objects Merge "Add VersionPredicate type of field" 8 years ago
pci Add unit tests for PCI utils 8 years ago
scheduler Merge "Make NoValidHost exceptions clearer" 8 years ago
servicegroup fix "down" nova-compute service spuriously marked as "up" 8 years ago
virt Merge "libvirt: make unit tests concise by setup guest object" 8 years ago
README.rst Adds cleanup on v2.2 keypair api and tests 8 years ago Make resize api of compute manager to send flavor object 8 years ago Fix up instance flavor usage in compute and network tests 8 years ago Replace dict.iteritems() with six.iteritems(dict) 8 years ago Use six.moves.range for Python 3 8 years ago Add serialization of context to FakeNotifier 8 years ago Add numa_node field to PciDevicePool 8 years ago Remove db layer hard-code permission checks for quota_class_create/update 8 years ago Cleanup unused method fake_set_snapshot_id 8 years ago Fix Python 3 issues in nova.db.sqlalchemy 8 years ago Replace dict.iteritems() with six.iteritems(dict) 8 years ago Add json-schema for v2.1 fixed-ips 8 years ago Replace unicode with six.text_type 8 years ago snapshot: Add device_name to the snapshot bdms 8 years ago Revert "Add config drive support for Virtuozzo containers" 8 years ago Removed unused variables 8 years ago Port crypto to Python 3 8 years ago Port test_exception to Python 3 8 years ago Block subtractive operations in migrations for Kilo and beyond 8 years ago Support flavor object in migrate_disk_and_power_off 8 years ago Add a hacking rule for consistent HTTP501 message 8 years ago Replace dict.itervalues() with six.itervalues(dict) 8 years ago Fix multipath device discovery when UFN is enabled. 8 years ago fixed tests in test_matchers to pass with random PYTHONHASHSEED 8 years ago Include project_id in instance metadata. 8 years ago Handle InstanceNotFound when sending instance update notification 8 years ago Remove flavor migration from db_api and nova-manage 8 years ago Use six.moves.range for Python 3 8 years ago Avoid indexing into an empty list in getcallargs 8 years ago Switch to oslo.service library 8 years ago test: add MatchType helper class as equivalent of mox.IsA 8 years ago Fix Python 3 issues in nova.utils and nova.tests 8 years ago Fix version unit test on Python 3 8 years ago Skip only one host weight calculation 8 years ago Skip socket related unit tests on OSX 8 years ago Use six.moves.range for Python 3 8 years ago


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:

Test Types: Unit vs. Functional vs. Integration


Writing Unit Tests


Using Fakes



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 overridden.

Writing Functional Tests


Writing Integration Tests


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().


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.


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.