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
This commit is contained in:
Boris Pavlovic 2014-07-09 03:29:01 +04:00
parent 785bda5705
commit a51b110576
2 changed files with 12 additions and 1 deletions

View File

@ -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)
}

View File

@ -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 = [
{