diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-06-13 19:06:20 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-06-13 19:06:20 +0000 |
| commit | 2ebca96d40e98b138816289ef74fe683835953aa (patch) | |
| tree | 2a5807cb1f9a5526db4c0519bab3d99337977544 /nova/tests | |
| parent | 739e6137b8bcd43d991496cc397859b6d02569ac (diff) | |
| parent | 4aee80dd31131675ae0ab9f927b2d4aed0b8426a (diff) | |
Merge "Sending volume IO usage broken"
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/compute/test_compute.py | 4 | ||||
| -rw-r--r-- | nova/tests/conductor/test_conductor.py | 110 | ||||
| -rw-r--r-- | nova/tests/db/test_db_api.py | 35 |
3 files changed, 109 insertions, 40 deletions
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index bcf48ebb6..04da9b9dd 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -470,15 +470,13 @@ class ComputeVolumeTestCase(BaseTestCase): curr_time = time.time() self.mox.StubOutWithMock(utils, 'last_completed_audit_period') self.mox.StubOutWithMock(self.compute, '_get_host_volume_bdms') - self.mox.StubOutWithMock(timeutils, 'utcnow') self.mox.StubOutWithMock(self.compute, '_update_volume_usage_cache') self.stubs.Set(self.compute.driver, 'get_all_volume_usage', lambda x, y: [3, 4]) # All the mocks are called utils.last_completed_audit_period().AndReturn((10, 20)) self.compute._get_host_volume_bdms(ctxt, 'MockHost').AndReturn([1, 2]) - timeutils.utcnow().AndReturn(5) - self.compute._update_volume_usage_cache(ctxt, [3, 4], 5) + self.compute._update_volume_usage_cache(ctxt, [3, 4]) self.mox.ReplayAll() CONF.volume_usage_poll_interval = 10 self.compute._last_vol_usage_poll = 0 diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py index beb0d3b61..195890b75 100644 --- a/nova/tests/conductor/test_conductor.py +++ b/nova/tests/conductor/test_conductor.py @@ -14,6 +14,8 @@ """Tests for the conductor service.""" +import datetime + import mox from nova.api.ec2 import ec2utils @@ -376,35 +378,24 @@ class _BaseTestCase(object): def test_vol_usage_update(self): # the vol_usage_update method sends the volume usage notifications # as well as updating the database - self.mox.StubOutWithMock(db, 'vol_usage_update') + now = datetime.datetime(1, 1, 1) + self.mox.StubOutWithMock(timeutils, 'utcnow') + # nova.context + timeutils.utcnow().AndReturn(0) + # vol_usage_update 1 + timeutils.utcnow().AndReturn(now) + # openstack.common.notifier + timeutils.utcnow().AndReturn(now) + self.mox.ReplayAll() + inst = self._create_fake_instance({ 'project_id': 'fake-project_id', 'user_id': 'fake-user_id', }) - fake_usage = {'tot_last_refreshed': 20, - 'curr_last_refreshed': 10, - 'volume_id': 'fake-vol', - 'instance_uuid': inst['uuid'], - 'project_id': 'fake-project_id', - 'user_id': 'fake-user_id', - 'availability_zone': 'fake-az', - 'tot_reads': 11, - 'curr_reads': 22, - 'tot_read_bytes': 33, - 'curr_read_bytes': 44, - 'tot_writes': 55, - 'curr_writes': 66, - 'tot_write_bytes': 77, - 'curr_write_bytes': 88} - db.vol_usage_update(self.context, 'fake-vol', 'rd-req', 'rd-bytes', - 'wr-req', 'wr-bytes', inst['uuid'], - 'fake-project_id', 'fake-user_id', 'fake-az', - 'fake-refr', 'fake-bool', mox.IgnoreArg()).\ - AndReturn(fake_usage) - self.mox.ReplayAll() - self.conductor.vol_usage_update(self.context, 'fake-vol', 'rd-req', - 'rd-bytes', 'wr-req', 'wr-bytes', - inst, 'fake-refr', 'fake-bool') + + self.conductor.vol_usage_update(self.context, 'fake-vol', + 22, 33, 44, 55, inst, + '2013-06-05T16:53:27.0', False) self.assertEquals(len(test_notifier.NOTIFICATIONS), 1) msg = test_notifier.NOTIFICATIONS[0] @@ -412,11 +403,72 @@ class _BaseTestCase(object): self.assertEquals(payload['instance_id'], inst['uuid']) self.assertEquals(payload['user_id'], 'fake-user_id') self.assertEquals(payload['tenant_id'], 'fake-project_id') - self.assertEquals(payload['reads'], 33) - self.assertEquals(payload['read_bytes'], 77) - self.assertEquals(payload['writes'], 121) - self.assertEquals(payload['write_bytes'], 165) + self.assertEquals(payload['reads'], 22) + self.assertEquals(payload['read_bytes'], 33) + self.assertEquals(payload['writes'], 44) + self.assertEquals(payload['write_bytes'], 55) self.assertEquals(payload['availability_zone'], 'fake-az') + self.assertEquals(payload['last_refreshed'], '0001-01-01 00:00:00') + + # We need to unset and verify that we call the timutils.utcnow method + # correctly now, as this method gets called as part of the setup + # for the ConductorAPITestCase testcase. + self.mox.UnsetStubs() + self.mox.VerifyAll() + + def test_vol_usage_update_again(self): + # Test updating the volume usage a second time and make sure that + # the database queries to update and generate the volume usage + # event payload continue to work + now = datetime.datetime(1, 1, 1, 0, 0, 0) + self.mox.StubOutWithMock(timeutils, 'utcnow') + # nova.context + timeutils.utcnow().AndReturn(0) + + # vol_usage_update call + timeutils.utcnow().AndReturn(now) + # openstack.common.notifier + timeutils.utcnow().AndReturn(now) + + now2 = datetime.datetime(1, 1, 1, 0, 1, 0) + # vol_usage_update second call + timeutils.utcnow().AndReturn(now2) + # openstack.common.notifier + timeutils.utcnow().AndReturn(now2) + + self.mox.ReplayAll() + + inst = self._create_fake_instance({ + 'project_id': 'fake-project_id', + 'user_id': 'fake-user_id', + }) + + self.conductor.vol_usage_update(self.context, 'fake-vol', + 22, 33, 44, 55, inst, + '2013-06-05T16:53:27.0', False) + + self.conductor.vol_usage_update(self.context, 'fake-vol', + 122, 133, 144, 155, inst, + '2013-06-05T16:53:27.0', False) + + self.assertEquals(len(test_notifier.NOTIFICATIONS), 2) + msg = test_notifier.NOTIFICATIONS[1] + payload = msg['payload'] + self.assertEquals(payload['instance_id'], inst['uuid']) + self.assertEquals(payload['user_id'], 'fake-user_id') + self.assertEquals(payload['tenant_id'], 'fake-project_id') + self.assertEquals(payload['reads'], 122) + self.assertEquals(payload['read_bytes'], 133) + self.assertEquals(payload['writes'], 144) + self.assertEquals(payload['write_bytes'], 155) + self.assertEquals(payload['availability_zone'], 'fake-az') + self.assertEquals(payload['last_refreshed'], '0001-01-01 00:01:00') + + # We need to unset and verify that we call the timutils.utcnow method + # correctly now, as this method gets called as part of the setup + # for the ConductorAPITestCase testcase. + self.mox.UnsetStubs() + self.mox.VerifyAll() def test_compute_node_create(self): self.mox.StubOutWithMock(db, 'compute_node_create') diff --git a/nova/tests/db/test_db_api.py b/nova/tests/db/test_db_api.py index b57a708ce..4d01e8e0a 100644 --- a/nova/tests/db/test_db_api.py +++ b/nova/tests/db/test_db_api.py @@ -3455,7 +3455,12 @@ class VolumeUsageDBApiTestCase(test.TestCase): ctxt = context.get_admin_context() now = timeutils.utcnow() start_time = now - datetime.timedelta(seconds=10) - refreshed_time = now - datetime.timedelta(seconds=5) + + self.mox.StubOutWithMock(timeutils, 'utcnow') + timeutils.utcnow().AndReturn(now) + timeutils.utcnow().AndReturn(now) + timeutils.utcnow().AndReturn(now) + self.mox.ReplayAll() expected_vol_usages = [{'volume_id': u'1', 'instance_uuid': 'fake-instance-uuid1', @@ -3465,10 +3470,12 @@ class VolumeUsageDBApiTestCase(test.TestCase): 'curr_read_bytes': 2000, 'curr_writes': 3000, 'curr_write_bytes': 4000, + 'curr_last_refreshed': now, 'tot_reads': 0, 'tot_read_bytes': 0, 'tot_writes': 0, - 'tot_write_bytes': 0}, + 'tot_write_bytes': 0, + 'tot_last_refreshed': None}, {'volume_id': u'2', 'instance_uuid': 'fake-instance-uuid2', 'project_id': 'fake-project-uuid2', @@ -3480,7 +3487,8 @@ class VolumeUsageDBApiTestCase(test.TestCase): 'tot_reads': 0, 'tot_read_bytes': 0, 'tot_writes': 0, - 'tot_write_bytes': 0}] + 'tot_write_bytes': 0, + 'tot_last_refreshed': None}] def _compare(vol_usage, expected): for key, value in expected.items(): @@ -3506,8 +3514,7 @@ class VolumeUsageDBApiTestCase(test.TestCase): instance_id='fake-instance-uuid1', project_id='fake-project-uuid1', user_id='fake-user-uuid1', - availability_zone='fake-az', - last_refreshed=refreshed_time) + availability_zone='fake-az') vol_usages = db.vol_get_usage_by_time(ctxt, start_time) self.assertEqual(len(vol_usages), 2) @@ -3516,9 +3523,19 @@ class VolumeUsageDBApiTestCase(test.TestCase): def test_vol_usage_update_totals_update(self): ctxt = context.get_admin_context() - now = timeutils.utcnow() + now = datetime.datetime(1, 1, 1, 1, 0, 0) start_time = now - datetime.timedelta(seconds=10) + self.mox.StubOutWithMock(timeutils, 'utcnow') + timeutils.utcnow().AndReturn(now) + now1 = now + datetime.timedelta(minutes=1) + timeutils.utcnow().AndReturn(now1) + now2 = now + datetime.timedelta(minutes=2) + timeutils.utcnow().AndReturn(now2) + now3 = now + datetime.timedelta(minutes=3) + timeutils.utcnow().AndReturn(now3) + self.mox.ReplayAll() + vol_usage = db.vol_usage_update(ctxt, 1, rd_req=100, rd_bytes=200, wr_req=300, wr_bytes=400, instance_id='fake-instance-uuid', @@ -3569,14 +3586,16 @@ class VolumeUsageDBApiTestCase(test.TestCase): 'tot_read_bytes': 800, 'tot_writes': 1000, 'tot_write_bytes': 1200, + 'tot_last_refreshed': now3, 'curr_reads': 0, 'curr_read_bytes': 0, 'curr_writes': 0, - 'curr_write_bytes': 0} + 'curr_write_bytes': 0, + 'curr_last_refreshed': now2} self.assertEquals(1, len(vol_usages)) for key, value in expected_vol_usages.items(): - self.assertEqual(vol_usages[0][key], value) + self.assertEqual(vol_usages[0][key], value, key) def test_vol_usage_update_when_blockdevicestats_reset(self): ctxt = context.get_admin_context() |
