Fix display of host details when cpu_info is empty

If a Blazar host was created with an empty cpu_info value, displaying
host details would fail with the error:

    SyntaxError: unexpected EOF while parsing (<string>, line 0)

This is because calling eval() on an empty string raises a SyntaxError.
This patch ensures that if cpu_info is empty, it is set to an empty
dictionary instead.

Change-Id: I38d9f92fd7937de4ec1492d06ddea834b6c423ef
This commit is contained in:
Pierre Riteau 2017-11-14 15:52:36 +00:00
parent ee40700175
commit 8066409cda
1 changed files with 4 additions and 1 deletions

View File

@ -51,7 +51,10 @@ class Host(base.APIDictWrapper):
super(Host, self).__init__(apiresource)
def cpu_info_dict(self):
return eval(getattr(self, 'cpu_info', ""))
cpu_info_dict = getattr(self, 'cpu_info', '{}')
if not cpu_info_dict:
cpu_info_dict = '{}'
return eval(cpu_info_dict)
def extra_capabilities(self):
excaps = {}