ensure timezone is included in timestamps

default to UTC timezone if not provided.
- safe to change ironic tests as the test notifications were
malformed[1]

[1] 99ba58172c/ironic/conductor/manager.py (L2159)

Closes-Bug: #1483564
Change-Id: I7c120fbc98698787c96533dbae6d5a683d6d4661
This commit is contained in:
gord chung 2017-07-07 12:04:40 -04:00
parent d85c36c7be
commit 232f8e9047
5 changed files with 44 additions and 15 deletions

View File

@ -126,6 +126,7 @@ class Sample(object):
metadata['event_type'] = message['event_type']
metadata['host'] = message['publisher_id']
ts = timestamp if timestamp else message['metadata']['timestamp']
ts = timeutils.parse_isotime(ts).isoformat() # add UTC if necessary
return cls(name=name,
type=type,
volume=volume,

View File

@ -654,7 +654,7 @@ SENSOR_DATA = {
'publisher_id': 'f23188ca-c068-47ce-a3e5-0e27ffe234c6',
'payload': {
'instance_uuid': 'f11251ax-c568-25ca-4582-0x27add644c6',
'timestamp': '20140223134852',
'timestamp': '2017-07-07 15:54:12.169510',
'node_uuid': 'f4982fd2-2f2b-4bb5-9aff-48aac801d1ad',
'event_type': 'hardware.ipmi.metrics.update',
'payload': {
@ -673,7 +673,7 @@ EMPTY_PAYLOAD = {
'publisher_id': 'f23188ca-c068-47ce-a3e5-0e27ffe234c6',
'payload': {
'instance_uuid': 'f11251ax-c568-25ca-4582-0x27add644c6',
'timestamp': '20140223134852',
'timestamp': '2017-07-07 15:54:12.169510',
'node_uuid': 'f4982fd2-2f2b-4bb5-9aff-48aac801d1ad',
'event_type': 'hardware.ipmi.metrics.update',
'payload': {
@ -688,7 +688,7 @@ MISSING_SENSOR = {
'publisher_id': 'f23188ca-c068-47ce-a3e5-0e27ffe234c6',
'payload': {
'instance_uuid': 'f11251ax-c568-25ca-4582-0x27add644c6',
'timestamp': '20140223134852',
'timestamp': '2017-07-07 15:54:12.169510',
'node_uuid': 'f4982fd2-2f2b-4bb5-9aff-48aac801d1ad',
'event_type': 'hardware.ipmi.metrics.update',
'payload': {
@ -727,7 +727,7 @@ BAD_SENSOR = {
'publisher_id': 'f23188ca-c068-47ce-a3e5-0e27ffe234c6',
'payload': {
'instance_uuid': 'f11251ax-c568-25ca-4582-0x27add644c6',
'timestamp': '20140223134852',
'timestamp': '2017-07-07 15:54:12.169510',
'node_uuid': 'f4982fd2-2f2b-4bb5-9aff-48aac801d1ad',
'event_type': 'hardware.ipmi.metrics.update',
'payload': {
@ -768,7 +768,7 @@ NO_SENSOR_ID = {
'publisher_id': 'f23188ca-c068-47ce-a3e5-0e27ffe234c6',
'payload': {
'instance_uuid': 'f11251ax-c568-25ca-4582-0x27add644c6',
'timestamp': '20140223134852',
'timestamp': '2017-07-07 15:54:12.169510',
'node_uuid': 'f4982fd2-2f2b-4bb5-9aff-48aac801d1ad',
'event_type': 'hardware.ipmi.metrics.update',
'payload': {
@ -788,7 +788,7 @@ NO_NODE_ID = {
'publisher_id': 'f23188ca-c068-47ce-a3e5-0e27ffe234c6',
'payload': {
'instance_uuid': 'f11251ax-c568-25ca-4582-0x27add644c6',
'timestamp': '20140223134852',
'timestamp': '2017-07-07 15:54:12.169510',
'event_type': 'hardware.ipmi.metrics.update',
'payload': {
'Temperature': {

View File

@ -28,7 +28,7 @@ from ceilometer.tests import base as test
NOTIFICATION = {
'event_type': u'test.create',
'metadata': {'timestamp': u'2015-06-1909: 19: 35.786893',
'metadata': {'timestamp': u'2015-06-19T09:19:35.786893',
'message_id': u'939823de-c242-45a2-a399-083f4d6a8c3e'},
'payload': {u'user_id': u'e1d870e51c7340cb9d555b15cbfcaec2',
u'resource_id': u'bea70e51c7340cb9d555b15cbfcaec23',
@ -49,7 +49,7 @@ NOTIFICATION = {
USER_META = {
'event_type': u'test.create',
'metadata': {'timestamp': u'2015-06-1909: 19: 35.786893',
'metadata': {'timestamp': u'2015-06-19T09:19:35.786893',
'message_id': u'939823de-c242-45a2-a399-083f4d6a8c3e'},
'payload': {u'user_id': u'e1d870e51c7340cb9d555b15cbfcaec2',
u'resource_id': u'bea70e51c7340cb9d555b15cbfcaec23',
@ -89,11 +89,11 @@ MIDDLEWARE_EVENT = {
u'event_type': u'objectstore.http.request',
u'publisher_id': u'ceilometermiddleware',
u'metadata': {u'message_id': u'6eccedba-120e-4db8-9735-2ad5f061e5ee',
u'timestamp': u'2013-07-29 06:51:34.474815',
u'timestamp': u'2013-07-29T06:51:34.474815+00:00',
u'_unique_id': u'0ee26117077648e18d88ac76e28a72e2'},
u'payload': {
'typeURI': 'http: //schemas.dmtf.org/cloud/audit/1.0/event',
'eventTime': '2015-01-30T16: 38: 43.233621',
'eventTime': '2013-07-29T06:51:34.474815+00:00',
'target': {
'action': 'get',
'typeURI': 'service/storage/object',
@ -172,7 +172,7 @@ FULL_MULTI_MSG = {
u'user_domain': None},
'publisher_id': u'ceilometer.api',
'metadata': {'message_id': u'939823de-c242-45a2-a399-083f4d6a8c3e',
'timestamp': u'2015-06-1909: 19: 35.786893'},
'timestamp': u'2015-06-19T09:19:35.786893'},
}
METRICS_UPDATE = {
@ -449,7 +449,7 @@ class TestMeterProcessing(test.BaseTestCase):
self.assertEqual(1, len(c))
s1 = c[0].as_dict()
self.assertEqual('compute.node.cpu.frequency', s1['name'])
self.assertEqual("2013-07-29T06:51:34.472416", s1['timestamp'])
self.assertEqual("2013-07-29T06:51:34.472416+00:00", s1['timestamp'])
def test_default_metadata(self):
cfg = yaml.dump(

View File

@ -18,7 +18,7 @@ NOTIFICATION = {
u'_context_domain': None,
u'_context_request_id': u'req-da91b4bf-d2b5-43ae-8b66-c7752e72726d',
'event_type': u'telemetry.api',
'timestamp': u'2015-06-1909: 19: 35.786893',
'timestamp': u'2015-06-19T09:19:35.786893',
u'_context_auth_token': None,
u'_context_read_only': False,
'payload': {'samples':

View File

@ -41,7 +41,7 @@ class TestSample(base.BaseTestCase):
msg = {
'event_type': u'sample.create',
'metadata': {
'timestamp': u'2015-06-1909: 19: 35.786893',
'timestamp': u'2015-06-19T09:19:35.786893',
'message_id': u'939823de-c242-45a2-a399-083f4d6a8c3e'},
'payload': [{u'counter_name': u'instance100'}],
'priority': 'info',
@ -57,7 +57,7 @@ class TestSample(base.BaseTestCase):
msg = {
'event_type': u'sample.create',
'metadata': {
'timestamp': u'2015-06-1909: 19: 35.786893',
'timestamp': u'2015-06-19T09:19:35.786893',
'message_id': u'939823de-c242-45a2-a399-083f4d6a8c3e'},
'payload': {u'counter_name': u'instance100'},
'priority': 'info',
@ -68,3 +68,31 @@ class TestSample(base.BaseTestCase):
msg['payload']['event_type'] = msg['event_type']
msg['payload']['host'] = msg['publisher_id']
self.assertEqual(msg['payload'], s.resource_metadata)
def test_sample_from_notifications_assume_utc(self):
msg = {
'event_type': u'sample.create',
'metadata': {
'timestamp': u'2015-06-19T09:19:35.786893',
'message_id': u'939823de-c242-45a2-a399-083f4d6a8c3e'},
'payload': {u'counter_name': u'instance100'},
'priority': 'info',
'publisher_id': u'ceilometer.api',
}
s = sample.Sample.from_notification(
'sample', 'type', 1.0, '%', 'user', 'project', 'res', msg)
self.assertEqual('2015-06-19T09:19:35.786893+00:00', s.timestamp)
def test_sample_from_notifications_keep_tz(self):
msg = {
'event_type': u'sample.create',
'metadata': {
'timestamp': u'2015-06-19T09:19:35.786893+01:00',
'message_id': u'939823de-c242-45a2-a399-083f4d6a8c3e'},
'payload': {u'counter_name': u'instance100'},
'priority': 'info',
'publisher_id': u'ceilometer.api',
}
s = sample.Sample.from_notification(
'sample', 'type', 1.0, '%', 'user', 'project', 'res', msg)
self.assertEqual('2015-06-19T09:19:35.786893+01:00', s.timestamp)