From 0ecba69df002a319ce30ae554dbf0182b2a01f98 Mon Sep 17 00:00:00 2001 From: Vincent Hou Date: Sun, 16 Nov 2014 22:33:35 -0800 Subject: [PATCH] Convert the DateTime into ISO8601 format for Ceilometer The fields of DateTime type should be converted to the time in ISO8601 format, when they are put in the usage information to be reported to Ceilometer. Change-Id: I67e9e3609291d0d835156dfd9cfda88deae119c1 closes-bug: #1372791 --- cinder/tests/api/v1/test_volumes.py | 26 +++++++++++++------------- cinder/tests/api/v2/stubs.py | 4 ++-- cinder/tests/api/v2/test_volumes.py | 26 +++++++++++++------------- cinder/volume/utils.py | 10 ++++++---- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/cinder/tests/api/v1/test_volumes.py b/cinder/tests/api/v1/test_volumes.py index 0a50c2b1e..a0e70bb25 100644 --- a/cinder/tests/api/v1/test_volumes.py +++ b/cinder/tests/api/v1/test_volumes.py @@ -96,7 +96,7 @@ class VolumeApiTest(test.TestCase): 'source_volid': None, 'metadata': {}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 100, 'encrypted': False}} @@ -188,7 +188,7 @@ class VolumeApiTest(test.TestCase): 'source_volid': None, 'metadata': {}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': '1'}} body = {"volume": vol} @@ -272,7 +272,7 @@ class VolumeApiTest(test.TestCase): 'metadata': {'attached_mode': 'rw', 'readonly': 'False'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1}} self.assertEqual(res_dict, expected) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2) @@ -309,7 +309,7 @@ class VolumeApiTest(test.TestCase): "readonly": "False", "attached_mode": "rw"}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1 }} self.assertEqual(res_dict, expected) @@ -358,7 +358,7 @@ class VolumeApiTest(test.TestCase): 'metadata': {'key': 'value', 'readonly': 'True'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1}} self.assertEqual(res_dict, expected) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2) @@ -412,7 +412,7 @@ class VolumeApiTest(test.TestCase): 'metadata': {'attached_mode': 'rw', 'readonly': 'False'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1}]} self.assertEqual(res_dict, expected) @@ -452,7 +452,7 @@ class VolumeApiTest(test.TestCase): 'metadata': {'key': 'value', 'readonly': 'True'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1}]} self.assertEqual(res_dict, expected) @@ -481,7 +481,7 @@ class VolumeApiTest(test.TestCase): 'metadata': {'attached_mode': 'rw', 'readonly': 'False'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1}]} self.assertEqual(res_dict, expected) @@ -521,7 +521,7 @@ class VolumeApiTest(test.TestCase): 'metadata': {'key': 'value', 'readonly': 'True'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1}]} self.assertEqual(res_dict, expected) @@ -548,7 +548,7 @@ class VolumeApiTest(test.TestCase): 'metadata': {'attached_mode': 'rw', 'readonly': 'False'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1}} self.assertEqual(res_dict, expected) @@ -575,7 +575,7 @@ class VolumeApiTest(test.TestCase): 'source_volid': None, 'metadata': {'readonly': 'False'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1}} self.assertEqual(res_dict, expected) @@ -606,7 +606,7 @@ class VolumeApiTest(test.TestCase): 'metadata': {'attached_mode': 'rw', 'readonly': 'False'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1}} self.assertEqual(res_dict, expected) @@ -683,7 +683,7 @@ class VolumeApiTest(test.TestCase): 'metadata': {'key': 'value', 'readonly': 'True'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1}} self.assertEqual(res_dict, expected) diff --git a/cinder/tests/api/v2/stubs.py b/cinder/tests/api/v2/stubs.py index bb4a8419e..242ac7242 100644 --- a/cinder/tests/api/v2/stubs.py +++ b/cinder/tests/api/v2/stubs.py @@ -41,7 +41,7 @@ def stub_volume(id, **kwargs): 'display_name': 'displayname', 'display_description': 'displaydesc', 'updated_at': datetime.datetime(1900, 1, 1, 1, 1, 1), - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'snapshot_id': None, 'source_volid': None, 'volume_type_id': '3e196c20-3c06-11e2-81c1-0800200c9a66', @@ -49,7 +49,7 @@ def stub_volume(id, **kwargs): 'volume_admin_metadata': [{'key': 'attached_mode', 'value': 'rw'}, {'key': 'readonly', 'value': 'False'}], 'bootable': False, - 'launched_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'launched_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'volume_type': {'name': 'vol_type_name'}, 'replication_status': 'disabled', 'replication_extended_status': None, diff --git a/cinder/tests/api/v2/test_volumes.py b/cinder/tests/api/v2/test_volumes.py index 91640f7b3..490245a93 100644 --- a/cinder/tests/api/v2/test_volumes.py +++ b/cinder/tests/api/v2/test_volumes.py @@ -96,7 +96,7 @@ class VolumeApiTest(test.TestCase): 'availability_zone': 'zone1:host1', 'bootable': 'false', 'consistencygroup_id': None, - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'description': 'Volume Test Desc', 'id': '1', 'links': @@ -230,7 +230,7 @@ class VolumeApiTest(test.TestCase): 'availability_zone': 'nova', 'bootable': 'false', 'consistencygroup_id': None, - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'description': 'Volume Test Desc', 'encrypted': False, 'id': '1', @@ -320,7 +320,7 @@ class VolumeApiTest(test.TestCase): 'availability_zone': 'nova', 'bootable': 'false', 'consistencygroup_id': None, - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'description': 'Volume Test Desc', 'encrypted': False, 'id': '1', @@ -428,7 +428,7 @@ class VolumeApiTest(test.TestCase): 'source_volid': None, 'metadata': {'attached_mode': 'rw', 'readonly': 'False'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1, 'links': [ { @@ -482,7 +482,7 @@ class VolumeApiTest(test.TestCase): 'source_volid': None, 'metadata': {'attached_mode': 'rw', 'readonly': 'False'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1, 'links': [ { @@ -539,7 +539,7 @@ class VolumeApiTest(test.TestCase): 'source_volid': None, 'metadata': {'attached_mode': 'rw', 'readonly': 'False'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1, 'links': [ { @@ -591,7 +591,7 @@ class VolumeApiTest(test.TestCase): "readonly": "False", "attached_mode": "rw"}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1, 'links': [ { @@ -653,7 +653,7 @@ class VolumeApiTest(test.TestCase): 'metadata': {'key': 'value', 'readonly': 'True'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1, 'links': [ { @@ -759,7 +759,7 @@ class VolumeApiTest(test.TestCase): 'source_volid': None, 'metadata': {'attached_mode': 'rw', 'readonly': 'False'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1, 'links': [ { @@ -821,7 +821,7 @@ class VolumeApiTest(test.TestCase): 'source_volid': None, 'metadata': {'key': 'value', 'readonly': 'True'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1, 'links': [ { @@ -1222,7 +1222,7 @@ class VolumeApiTest(test.TestCase): 'source_volid': None, 'metadata': {'attached_mode': 'rw', 'readonly': 'False'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1, 'links': [ { @@ -1265,7 +1265,7 @@ class VolumeApiTest(test.TestCase): 'source_volid': None, 'metadata': {'readonly': 'False'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1, 'links': [ { @@ -1333,7 +1333,7 @@ class VolumeApiTest(test.TestCase): 'metadata': {'key': 'value', 'readonly': 'True'}, 'id': '1', - 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1, 'links': [ { diff --git a/cinder/volume/utils.py b/cinder/volume/utils.py index 254cb5a61..9b7d915a6 100644 --- a/cinder/volume/utils.py +++ b/cinder/volume/utils.py @@ -50,8 +50,10 @@ def _usage_from_volume(context, volume_ref, **kw): volume_id=volume_ref['id'], volume_type=volume_ref['volume_type_id'], display_name=volume_ref['display_name'], - launched_at=null_safe_str(volume_ref['launched_at']), - created_at=null_safe_str(volume_ref['created_at']), + launched_at=timeutils.isotime(at= + volume_ref['launched_at']), + created_at=timeutils.isotime(at= + volume_ref['created_at']), status=volume_ref['status'], snapshot_id=volume_ref['snapshot_id'], size=volume_ref['size'], @@ -153,7 +155,7 @@ def _usage_from_consistencygroup(context, group_ref, **kw): availability_zone=group_ref['availability_zone'], consistencygroup_id=group_ref['id'], name=group_ref['name'], - created_at=null_safe_str(group_ref['created_at']), + created_at=timeutils.isotime(at=group_ref['created_at']), status=group_ref['status']) usage_info.update(kw) @@ -185,7 +187,7 @@ def _usage_from_cgsnapshot(context, cgsnapshot_ref, **kw): cgsnapshot_id=cgsnapshot_ref['id'], name=cgsnapshot_ref['name'], consistencygroup_id=cgsnapshot_ref['consistencygroup_id'], - created_at=null_safe_str(cgsnapshot_ref['created_at']), + created_at=timeutils.isotime(at=cgsnapshot_ref['created_at']), status=cgsnapshot_ref['status']) usage_info.update(kw) -- 2.45.2