From a51b110576d59a18eac2760d406423d8bb5aa144 Mon Sep 17 00:00:00 2001 From: Boris Pavlovic Date: Wed, 9 Jul 2014 03:29:01 +0400 Subject: [PATCH] Fix ceilometer parse notifications In case of empty notification list, started_at and finished_at are not changed and keep type int (== 0) that is passed to msec() func that expect datetime object. So just catch this situation. Change-Id: I2b2ade11fee2fb7fbe88bc8fd602007d342d78e9 --- osprofiler/parsers/ceilometer.py | 2 +- tests/parsers/test_ceilometer.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/osprofiler/parsers/ceilometer.py b/osprofiler/parsers/ceilometer.py index 9e59bac..a49bede 100644 --- a/osprofiler/parsers/ceilometer.py +++ b/osprofiler/parsers/ceilometer.py @@ -109,7 +109,7 @@ def parse_notifications(notifications): "info": { "name": "total", "started": 0, - "finished": msec(finished_at - started_at) + "finished": msec(finished_at - started_at) if started_at else 0 }, "children": _build_tree(result) } diff --git a/tests/parsers/test_ceilometer.py b/tests/parsers/test_ceilometer.py index 6653c7d..6442a17 100644 --- a/tests/parsers/test_ceilometer.py +++ b/tests/parsers/test_ceilometer.py @@ -76,6 +76,17 @@ class CeilometerParserTestCase(test.TestCase): self.assertEqual(ceilometer._build_tree(test_input), expected_output) + def test_parse_notifications_empty(self): + expected = { + "info": { + "name": "total", + "started": 0, + "finished": 0 + }, + "children": [] + } + self.assertEqual(ceilometer.parse_notifications([]), expected) + def test_parse_notifications(self): samples = [ {