nova/nova/tests
Alvaro Lopez Garcia e5ba849437 Normalize the weights instead of using raw values
The weight system is being used by the scheduler and the cells code.
Currently this system is using the raw values instead of normalizing them.
This makes difficult to properly use multipliers for establishing the
relative importance between two wheighers (one big magnitude could
shade a smaller one). This change introduces weight normalization so
that:

- From an operator point of view we can prioritize the weighers that
  we are applying. The only way to do this is being sure that all the
  weighers will give a value in a known range, so that it is
  not needed to artificially use a huge multiplier to prioritize a
  weigher.

- From a weigher developer point of view, somebody willing to implement
  one has to care about 1) returning a list of values, 2) setting the
  minimum and maximum values where the weights can range, if they are
  needed and they are significant for the weighing. For a weigher
  developer there are two use cases:

    Case 1: Use of a percentage instead of absolute values (for example, %
    of free RAM). If we compare two nodes focusing on the percentage of free
    ram, the maximum value for the weigher is 100. If we have two nodes one
    with 2048 total/1024 free, and the second one 1024 total/512 free they
    will get both the same weight, since they have the same % of free RAM
    (that is, the 50%).

    Case 2: Use of absolute values. In this case, the maximum of the weigher
    will be the maximum of the values in the list (in the case above, 1024)
    or the maximum value that the magnitude could take (in the case above,
    2048). How this maximum is set, is a decision of the developer. He may
    let the operator choose the behaviour of the weigher though.

- From the point of view of the scheduler we ensure that it is using
  normalized values, and not leveraging the normalization mechanism to the
  weighers.

Changes introduced this commit:

1) it introduces weight normalization so that we can apply multipliers
   easily. All the weights for an object will be normalized between 0.0 and
   1.0 before being sumed up, so that the final weight for a host will be:

    weight = w1_multiplier * norm(w1) + w2_multiplier * norm(w2) + ...

2) weights.BaseWeigher has been changed into an ABC so that we enforce
   that all weighers have the expected methods.

3) weights.BaseWeigher.weigh_objects() does no longer sum up the
   computer weighs to the object, but it rather returns a list that will be
   then normalized and added to the existing weight by BaseWeightHandler

4) Adapt the existing weighers to the above changes. Namely
    - New 'offset_weight_multiplier' for the cell weigher
      nova.cells.weights.weight_offset.WeightOffsetWeigher
    - Changed the name of the existing multiplier methods.

5) unittests for all of the introduced changes.

Implements blueprint normalize-scheduler-weights

DocImpact: Now weights for an object are normalized before suming them
up. This means that each weigher will take a maximum value of 1. This
may have an impact for operators that are using more than one weigher
(currently there is only one weigher: RAMWeiger) and for operators using
cells (where we have several weighers). It is needed to review then the
multipliers used and adjust them properly in case they have been
modified.

Docimpact: There is a new configuration option 'offset_weight_multiplier'
in nova.cells.weights.weight_offset.WeightOffsetWeigher

Change-Id: I81bf90898d3cb81541f4390596823cc00106eb20
2013-12-11 20:24:16 +01:00
..
CA
api Merge "Fix HTTP response code for network APIs and improve error message" 2013-12-08 02:39:02 +00:00
bundle
cells Normalize the weights instead of using raw values 2013-12-11 20:24:16 +01:00
cert Add V2 rpc api for cert 2013-11-25 12:15:40 -05:00
compute Merge "Clean up test cases for compute.manager._check_instance_build_time" 2013-12-06 21:24:01 +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 "Remove traces of V3 personality extension from api samples" 2013-12-07 04:22:43 +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 Normalize the weights instead of using raw values 2013-12-11 20:24:16 +01:00
servicegroup Utilizes assertIn - tests/etc 2013-10-21 10:01:20 +08:00
ssl_cert
virt Merge "fakevirt: return hypervisor_version as an int instead of a string" 2013-12-08 14:16:35 +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 Add compatibility for InstanceMetadata and primitives 2013-10-31 17:15:22 +00: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_weights.py Normalize the weights instead of using raw values 2013-12-11 20:24:16 +01: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↩︎