diff options
author | Dan Smith <danms@us.ibm.com> | 2013-02-05 12:36:52 -0500 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2013-02-06 01:27:49 +0000 |
commit | 1b65fb08f2845fe1ab525709d7a5d76f91985cea (patch) | |
tree | 2b9371a7138e0202f865c28f2e00859111a762a7 /nova/tests/conductor | |
parent | bfd295daed4b22cd0716973bee33cffdaaeae931 (diff) | |
download | nova-1b65fb08f2845fe1ab525709d7a5d76f91985cea.tar.gz nova-1b65fb08f2845fe1ab525709d7a5d76f91985cea.tar.xz nova-1b65fb08f2845fe1ab525709d7a5d76f91985cea.zip |
Refactor instance usage notifications for compute manager
This patch makes compute manager call notify_usage_exists() via the
conductor instead of directly, avoiding the direct database access
required to fetch bandwidth information. I initially just added
a notify_bw_usage() method to conductor, which just handled the
bandwidth part (which is the database hit). However, the metadata
payload part may be depended upon by custom stuff for periodic
notifications, so copying all that stuff as well made it a bunch
of duplicated stuff. Thus, I decided to just make it a direct proxy
for the compute_utils method.
Note that this is a bit of a departure from the previous pattern of
just proxying db interfaces in conductor, but I think the simplicity
gain is worth it.
Related to blueprint no-db-compute
Change-Id: I09f2652d4903f4d6036c6e3d74db063952341856
Diffstat (limited to 'nova/tests/conductor')
-rw-r--r-- | nova/tests/conductor/test_conductor.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py index f21e67845..d9d6f2db5 100644 --- a/nova/tests/conductor/test_conductor.py +++ b/nova/tests/conductor/test_conductor.py @@ -17,6 +17,7 @@ import mox from nova.compute import instance_types +from nova.compute import utils as compute_utils from nova.compute import vm_states from nova import conductor from nova.conductor import api as conductor_api @@ -26,6 +27,7 @@ from nova import context from nova import db from nova.db.sqlalchemy import models from nova import exception as exc +from nova import notifications from nova.openstack.common import jsonutils from nova.openstack.common.rpc import common as rpc_common from nova.openstack.common import timeutils @@ -463,6 +465,36 @@ class _BaseTestCase(object): self.context, 'task', 'begin', 'end', 'host', 'errors', 'message') self.assertEqual(result, 'result') + def test_notify_usage_exists(self): + info = { + 'audit_period_beginning': 'start', + 'audit_period_ending': 'end', + 'bandwidth': 'bw_usage', + 'image_meta': {}, + 'extra': 'info', + } + instance = { + 'system_metadata': [], + } + + self.mox.StubOutWithMock(notifications, 'audit_period_bounds') + self.mox.StubOutWithMock(notifications, 'bandwidth_usage') + self.mox.StubOutWithMock(compute_utils, 'notify_about_instance_usage') + + notifications.audit_period_bounds(False).AndReturn(('start', 'end')) + notifications.bandwidth_usage(instance, 'start', True).AndReturn( + 'bw_usage') + compute_utils.notify_about_instance_usage(self.context, instance, + 'exists', + system_metadata={}, + extra_usage_info=info) + + self.mox.ReplayAll() + + self.conductor.notify_usage_exists(self.context, instance, + system_metadata={}, + extra_usage_info=dict(extra='info')) + class ConductorTestCase(_BaseTestCase, test.TestCase): """Conductor Manager Tests.""" |