From 07848e761a13afaf44c58d99ceb6a133e6999470 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 10 Dec 2012 15:32:28 -0800 Subject: Fix bw_usage_update issue with conductor During a rebase, the tests for the conductor's implementation of bw_usage_*() were lost. This caused some later changes to go untested, and thus, introduce errors. This patch: 1. Fixes the calling order of bw_usage_get() from LocalAPI 2. Fixes the test used to determine if an update should be performed 3. Fixes the RPC API version number that should have been bumped 4. Adds the tests Yikes. Change-Id: I87c8ad19002d7cc420dc15f6ae21c6bfcbb0ee53 --- nova/conductor/api.py | 2 +- nova/conductor/manager.py | 4 ++-- nova/tests/conductor/test_conductor.py | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/nova/conductor/api.py b/nova/conductor/api.py index a55618bd6..fe4f6ca98 100644 --- a/nova/conductor/api.py +++ b/nova/conductor/api.py @@ -66,7 +66,7 @@ class LocalAPI(object): return self._manager.aggregate_host_delete(context, aggregate, host) def bw_usage_get(self, context, uuid, start_period, mac): - return self._manager.bw_usage_update(context, uuid, start_period, mac) + return self._manager.bw_usage_update(context, uuid, mac, start_period) def bw_usage_update(self, context, uuid, mac, start_period, bw_in, bw_out, last_ctr_in, last_ctr_out, diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py index 925edc29a..4a37b9dfb 100644 --- a/nova/conductor/manager.py +++ b/nova/conductor/manager.py @@ -41,7 +41,7 @@ datetime_fields = ['launched_at', 'terminated_at'] class ConductorManager(manager.SchedulerDependentManager): """Mission: TBD""" - RPC_API_VERSION = '1.4' + RPC_API_VERSION = '1.5' def __init__(self, *args, **kwargs): super(ConductorManager, self).__init__(service_name='conductor', @@ -94,7 +94,7 @@ class ConductorManager(manager.SchedulerDependentManager): bw_in=None, bw_out=None, last_ctr_in=None, last_ctr_out=None, last_refreshed=None): - if all((None, bw_in, bw_out, last_ctr_in, last_ctr_out)): + if [bw_in, bw_out, last_ctr_in, last_ctr_out].count(None) != 4: self.db.bw_usage_update(context, uuid, mac, start_period, bw_in, bw_out, last_ctr_in, last_ctr_out, last_refreshed) diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py index 8c97c4cdc..8805ac648 100644 --- a/nova/tests/conductor/test_conductor.py +++ b/nova/tests/conductor/test_conductor.py @@ -154,6 +154,20 @@ class ConductorTestCase(BaseTestCase): db.aggregate_delete(self.context.elevated(), aggregate_ref['id']) + def test_bw_usage_update(self): + self.mox.StubOutWithMock(db, 'bw_usage_update') + self.mox.StubOutWithMock(db, 'bw_usage_get') + + update_args = (self.context, 'uuid', 'mac', 0, 10, 20, 5, 10, 20) + get_args = (self.context, 'uuid', 0, 'mac') + + db.bw_usage_update(*update_args) + db.bw_usage_get(*get_args).AndReturn('foo') + + self.mox.ReplayAll() + result = self.conductor.bw_usage_update(*update_args) + self.assertEqual(result, 'foo') + class ConductorRPCAPITestCase(ConductorTestCase): """Conductor RPC API Tests""" @@ -177,6 +191,18 @@ class ConductorLocalAPITestCase(ConductorTestCase): return self.conductor.instance_update(self.context, instance_uuid, **updates) + def test_bw_usage_get(self): + self.mox.StubOutWithMock(db, 'bw_usage_update') + self.mox.StubOutWithMock(db, 'bw_usage_get') + + get_args = (self.context, 'uuid', 0, 'mac') + + db.bw_usage_get(*get_args).AndReturn('foo') + + self.mox.ReplayAll() + result = self.conductor.bw_usage_get(*get_args) + self.assertEqual(result, 'foo') + class ConductorAPITestCase(ConductorLocalAPITestCase): """Conductor API Tests""" -- cgit