connection: avoid failing on NoneType in _hostinfo

There is a potential race of a backend to be opened and being true on
self._backend.is_open but self._hostinfo not being set yet.

Avoid spurial bugs due to that by also checking against None before
accessing subelements ot self._hostinfo

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
This commit is contained in:
Christian Ehrhardt 2018-09-26 11:00:57 +02:00 committed by Cole Robinson
parent 760dc32bac
commit 92c610e782
1 changed files with 2 additions and 2 deletions

View File

@ -318,12 +318,12 @@ class vmmConnection(vmmGObject):
caps = property(lambda self: getattr(self, "_backend").caps)
def host_memory_size(self):
if not self._backend.is_open():
if not self._backend.is_open() or self._hostinfo is None:
return 0
return self._hostinfo[1] * 1024
def host_active_processor_count(self):
if not self._backend.is_open():
if not self._backend.is_open() or self._hostinfo is None:
return 0
return self._hostinfo[2]