Before having the watcher cleanup down instances, the assumption was that if the instance data was contained in the watcher's state, then the number of restart attempts would definitely be present. This is not true anymore, because it might be the case that if the instance data is in the watcher's state, it is possible that only one of the keys is present (or both). This patch fixes this assumption.
Signed-off-by: Jose A. Lopes <[email protected]> --- lib/watcher/state.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/watcher/state.py b/lib/watcher/state.py index a724c16..e0df53a 100644 --- a/lib/watcher/state.py +++ b/lib/watcher/state.py @@ -158,11 +158,7 @@ class WatcherState(object): """ idata = self._data["instance"] - - if instance_name in idata: - return idata[instance_name][KEY_RESTART_COUNT] - - return 0 + return idata.get(instance_name, {}).get(KEY_RESTART_COUNT, 0) def NumberOfCleanupAttempts(self, instance_name): """Returns number of previous cleanup attempts. @@ -172,11 +168,7 @@ class WatcherState(object): """ idata = self._data["instance"] - - if instance_name in idata: - return idata[instance_name][KEY_CLEANUP_COUNT] - - return 0 + return idata.get(instance_name, {}).get(KEY_CLEANUP_COUNT, 0) def MaintainInstanceList(self, instances): """Perform maintenance on the recorded instances. -- 1.9.1.423.g4596e3a
