nova/nova/tests
Aaron Rosen bce36e9bdb 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:36:20 -08:00
..
CA
api Merge "Hide injected_file related quotas for V3 API" 2013-12-11 18:42:00 +00:00
bundle
cells Cells: check states on resize/rebuild updates 2013-12-06 20:17:01 +00:00
cert Add V2 rpc api for cert 2013-11-25 12:15:40 -05:00
compute Merge "Clean up unused variables" 2013-12-09 20:26:18 +00:00
conductor Merge "Change conductor live migrate task to use select_destinations()" 2013-12-05 17:59:26 +00: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 Merge "Fix changes-since filter for list-servers API" 2013-12-07 07:40:22 +00: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 Merge "Hide injected_file related quotas for V3 API" 2013-12-11 18:42:00 +00:00
keymgr Replace assertEquals with assertEqual - tests/etc 2013-11-12 14:51:29 +08:00
monkey_patch_example
network Merge "Fix AttributeError(s) from get_v4/6_ips_by_interface" 2013-12-05 18:01:14 +00:00
objects Add Flavor object 2013-12-05 07:29:36 -08:00
pci Check for None when cleaning PCI dev usage 2013-10-13 20:31:18 -07:00
scheduler Merge "Added a new scheduler metrics weight plugin" 2013-12-07 20:05:10 +00:00
servicegroup Utilizes assertIn - tests/etc 2013-10-21 10:01:20 +08:00
ssl_cert
virt Merge "baremetal: volume driver refactoring and tests" 2013-12-10 15:35:19 +00:00
volume Convert TestCases to NoDBTestCase 2013-09-21 20:46:04 +10:00
README.rst
__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 Use the oslo fixture module 2013-10-14 09:43:24 +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 Migrate some tests that were using callable fields 2013-10-11 21:13:53 -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 Make InstanceInfoCache load base attributes 2013-10-29 06:53:44 -07: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 "Remove used_limits extension from the V3 API" 2013-12-05 10:49:21 +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 Remove the monkey patching of _ into the builtins 2013-07-26 07:31:17 -07:00
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 Xenapi: Allow windows builds with xentools 6.1 and 6.2 2013-11-14 08:30:23 +11:00
test_versions.py Convert TestCases to NoDBTestCase 2013-09-19 19:53:04 +10:00
test_wsgi.py replace assertNotEquals with assertNotEqual 2013-11-13 23:57:03 -08:00
utils.py docker: access system_metadata as a dict 2013-12-02 14:56:32 -05: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↩︎