nova/nova/tests
Aaron Rosen af2f823107 Prevent spoofing instance_id from neutron to nova
Previously, one could update a port's device_id in neutron to be
that of another tenant's instance_id and then be able to retrieve
that instance's metadata. This patch prevents this from occurring by
checking that X-Tenant-ID received from the metadata request matches
the tenant_id in the nova database.

DocImpact - This patch is dependent on another patch in neutron
            which adds X-Tenant-ID to the request. Therefore to
            minimize downtime one should upgrade Neutron first (then
            restart neutron-metadata-agent) and lastly update nova.

Change-Id: I93bf662797c3986324ca2099b403833c2e990fb4
Closes-Bug: #1235450
2013-12-11 12:38:47 -08:00
..
CA
api Merge "Moved quota headroom calculations into quota_reserve" into stable/havana 2013-12-05 12:12:15 +00:00
bundle
cells Correct use of ConfigFilesNotFoundError 2013-10-10 10:25:01 -04:00
cert Convert TestCases to NoDBTestCase 2013-09-21 20:46:04 +10:00
compute Merge "Prevent rescheduling on block device failure" into stable/havana 2013-12-10 01:04:53 +00:00
conductor Fix conductor's object change detection 2013-10-10 15:49:18 -07:00
console Merge "Fix console db can't load attribute pool" 2013-09-29 02:22:19 +00:00
consoleauth Convert TestCases to NoDBTestCase 2013-09-21 06:57:49 +10:00
db Avoid clobbering {system_,}metadata dicts passed to instance update 2013-11-20 11:46:17 -08:00
fake_loadables
glance Added 'page_size' param to image list 2013-09-24 09:53:00 +05:30
image Merge "Remove exceptions.Duplicate" 2013-09-24 23:30:46 +00:00
integrated Merge "Update attach interface api to use new network model" 2013-10-01 19:19:13 +00:00
keymgr Convert TestCases to NoDBTestCase 2013-09-21 06:58:31 +10:00
monkey_patch_example
network Address infinite loop in nova compute when getting network info 2013-11-26 17:36:23 +08:00
objects Pull system_metadata for notifications on instance.save() 2013-10-31 19:29:11 -07:00
pci Check for None when cleaning PCI dev usage 2013-10-30 11:04:24 -04:00
scheduler Convert TestCases to NoDBTestCase 2013-09-21 06:58:31 +10:00
servicegroup Convert TestCases to NoDBTestCase 2013-09-21 06:57:49 +10:00
ssl_cert
virt Merge "VMware: Fix unhandled session failure issues" into stable/havana 2013-12-07 23:25:50 +00:00
volume Convert TestCases to NoDBTestCase 2013-09-21 20:46:04 +10: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
cast_as_call.py Add CastAsCall fixture 2013-08-22 15:38:06 +01:00
conf_fixture.py Remove use of fake_rabbit in Nova 2013-08-21 11:35:08 +01: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 Refactor test cases related to instance object 2013-09-30 07:45:52 -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 Remove deprecated legacy network info model in Hypervisor drivers 2013-08-23 10:19:37 +08: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 "Add V3 API samples for instance-actions,extenions" 2013-09-17 20:00:41 +00:00
fake_processutils.py Fix H501: Do not use locals() for string formatting 2013-08-10 13:53:00 +02: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 fix libguestfs mount order when inspecting 2013-08-10 19:13:59 +08:00
matchers.py Fix and gate on E125 2013-07-04 08:49:45 +02:00
policy_fixture.py
test_availability_zones.py Merge "Fix unicode key of azcache can't be stored to memcache" 2013-09-02 11:31:22 +00:00
test_baserpc.py
test_bdm.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_block_device.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_cinder.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_configdrive2.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_context.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_crypto.py
test_exception.py Make Exception.format_message aware of Messages 2013-10-01 13:58:29 +00:00
test_flavors.py Fixes inconsistency in flavors list with marker 2013-10-24 05:13:54 -07:00
test_hooks.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_instance_types_extra_specs.py Code dedup in class InstanceTypeExtraSpecsTestCase 2013-07-26 10:57:42 +04:00
test_iptables_network.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_ipv6.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10: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 Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10: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:38:47 -08:00
test_notifications.py Port to oslo.messaging.Notifier API 2013-09-05 06:26:01 +01: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 Add boto special casing for param changes in 2.14 2013-10-10 08:38:05 -07:00
test_pipelib.py
test_policy.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_quota.py Moved quota headroom calculations into quota_reserve 2013-11-13 13:32:37 +01:00
test_safeutils.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_service.py Don't pass RPC connection to pre_start_hook 2013-08-19 11:49:34 +01:00
test_test.py
test_test_utils.py
test_utils.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_versions.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_wsgi.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
utils.py Remove deprecated legacy network info model in Hypervisor drivers 2013-08-23 10:19:37 +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↩︎