nova/nova/tests
Dan Smith 8a13967f12 Make compute_api use InstanceAction object
This makes the compute_api instance action code use objects instead
of direct-to-database calls. This should open the door for deprecating
some conductor proxies for compute_api that help compute manager
avoid the database hit required for the instance action to complete.

Related to blueprint compute-api-objects

Change-Id: If622d8079ca2897b0d5094e9341e29cde7c1ff59
2013-08-10 12:00:50 -07:00
..
CA
api Make compute_api use InstanceAction object 2013-08-10 12:00:50 -07:00
bundle
cells Fix instance actions testing 2013-08-07 08:11:08 -07:00
cert Fix and Gate on H303 (no wildcard imports) 2013-07-30 14:34:31 -07:00
compute Add delete() operation to InstanceInfoCache 2013-08-10 12:00:50 -07:00
conductor Moves scheduler.rpcapi.prep_resize call on compute.api to conductor 2013-07-29 17:20:53 -03:00
console Fix and Gate on H303 (no wildcard imports) 2013-07-30 14:34:31 -07:00
consoleauth Fix and Gate on H303 (no wildcard imports) 2013-07-30 14:34:31 -07:00
db Pull out instance object handling for use by create also 2013-08-07 08:11:08 -07:00
fake_loadables Update OpenStack LLC to Foundation 2013-02-26 19:15:29 -05:00
glance Add identity headers while calling glanceclient 2013-08-01 18:55:21 +00:00
image Add plug-in modules for direct downloads of glance locations 2013-08-05 11:14:32 -10:00
integrated Merge "Check host exists before evacuate" 2013-08-09 09:59:01 +00:00
keymgr Create key manager interface 2013-07-17 16:44:42 -04:00
monkey_patch_example Update OpenStack LLC to Foundation 2013-02-26 19:15:29 -05:00
network Merge "Fix simultaneous timeout with smart iptables usage" 2013-08-10 00:00:31 +00:00
objects Add basic InstanceAction object 2013-08-10 12:00:50 -07:00
scheduler Merge "Fix and Gate on H303 (no wildcard imports)" 2013-08-04 12:23:14 +00:00
servicegroup Remove sleep from service group db and mc tests 2013-07-30 16:31:58 -07:00
ssl_cert Adds SSL support for API server. 2013-01-23 08:49:16 -05:00
virt Merge "Fix simultaneous timeout with smart iptables usage" 2013-08-10 00:00:31 +00:00
volume Refactor nova.volume.cinder.API to reduce roundtrips with Cinder 2013-05-14 09:55:23 +01:00
README.rst Mox should cleanup before stubs 2013-05-16 18:15:31 +00:00
__init__.py Remove the monkey patching of _ into the builtins 2013-07-26 07:31:17 -07:00
conf_fixture.py Add latest oslo DB support 2013-07-25 19:22:53 -07:00
fake_crypto.py
fake_hosts.py Update OpenStack LLC to Foundation 2013-02-26 19:15:29 -05:00
fake_instance.py Make fake_instance handle security groups 2013-08-07 08:11:08 -07:00
fake_instance_actions.py Make compute_api use InstanceAction object 2013-08-10 12:00:50 -07:00
fake_ldap.py Remove the monkey patching of _ into the builtins 2013-07-26 07:31:17 -07:00
fake_network.py Fix simultaneous timeout with smart iptables usage 2013-08-08 13:20:40 -07:00
fake_network_cache_model.py Update instance network info cache to include vif_type. 2013-03-21 22:27:28 +08:00
fake_policy.py Merge "Port server_usage API to v3 part 2" 2013-08-09 22:58:12 +00:00
fake_processutils.py Remove the monkey patching of _ into the builtins 2013-07-26 07:31:17 -07:00
fake_utils.py Call scheduler for run_instance from conductor 2013-06-04 13:42:04 -04:00
fake_volume.py Remove the monkey patching of _ into the builtins 2013-07-26 07:31:17 -07:00
fakeguestfs.py Use Python 3.x compatible octal literals 2013-06-12 22:12:22 +02:00
matchers.py Fix and gate on E125 2013-07-04 08:49:45 +02:00
policy_fixture.py Use oslo-config-2013.1b4 2013-02-19 21:16:32 -08:00
test_availability_zones.py Add validation of available_zone during instance create 2013-07-16 23:22:49 -07:00
test_baserpc.py Move get_backdoor_port to base rpc API. 2013-04-24 15:02:56 -04:00
test_bdm.py Removed print stmts in test cases 2013-01-29 12:55:14 -05:00
test_block_device.py Add basic BDM format validation in the API layer 2013-07-26 12:33:01 +02:00
test_cinder.py Remove trivial cases of unused variables (3) 2013-06-27 17:34:17 +00:00
test_configdrive2.py Replace functions in utils with oslo.fileutils 2013-06-11 13:28:29 +09:00
test_context.py Fix RequestContext crashes w/ no service catalog 2013-03-18 18:06:52 -04:00
test_crypto.py Convert to using oslo's execute() method. 2013-05-04 15:17:40 +10:00
test_exception.py Avoid shadowing Exception 'message' attribute 2013-07-16 16:31:27 +01:00
test_flavors.py Use db.flavor_ instead of db.instance_type_ 2013-07-16 12:42:52 -07:00
test_hooks.py Added functionality for nova hooks pass functions 2013-07-02 12:56:45 -05:00
test_instance_types_extra_specs.py Code dedup in class InstanceTypeExtraSpecsTestCase 2013-07-26 10:57:42 +04:00
test_iptables_network.py Fix simultaneous timeout with smart iptables usage 2013-08-08 13:20:40 -07:00
test_ipv6.py Remove unnecessary LOG initialisation 2013-04-10 13:26:12 +00:00
test_linuxscsi.py Fix dangling LUN issue under load with multipath 2013-06-10 14:10:03 -07:00
test_loadables.py Update OpenStack LLC to Foundation 2013-02-26 19:15:29 -05:00
test_manager.py Make it easier to add namespaced rpc APIs. 2013-05-21 18:09:01 -04:00
test_matchers.py
test_metadata.py add vendor_data to the md service and config drive 2013-07-31 12:13:13 -04:00
test_notifications.py Remove notify_on_any_change option 2013-07-03 10:47:45 +02:00
test_nova_manage.py Merge "Clarify instance_type vs flavor in nova-manage" 2013-07-29 22:07:33 +00:00
test_objectstore.py Use oslo-config-2013.1b4 2013-02-19 21:16:32 -08:00
test_pipelib.py Update OpenStack LLC to Foundation 2013-02-26 19:15:29 -05:00
test_policy.py
test_quota.py Code dedup in class QuotaReserveSqlAlchemyTestCase 2013-08-02 11:22:46 +04:00
test_safeutils.py Remove parameters containing passwords from Notifications. 2013-03-05 16:27:29 -04:00
test_service.py Skip ipv6 tests on system without ipv6 support 2013-06-07 00:16:27 +08:00
test_test.py Use oslo-config-2013.1b4 2013-02-19 21:16:32 -08:00
test_test_utils.py Update OpenStack LLC to Foundation 2013-02-26 19:15:29 -05:00
test_utils.py Move _validate_int_value controller func to utils 2013-07-22 11:40:59 +02:00
test_versions.py Use oslo-config-2013.1b4 2013-02-19 21:16:32 -08:00
test_wsgi.py Port missing bits from httplib2 to requests 2013-06-21 14:54:47 +02:00
utils.py Use db.flavor_ instead of db.instance_type_ 2013-07-16 12:42:52 -07: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↩︎