From 31b937118308828c058a023947d7ace55c86e3bd Mon Sep 17 00:00:00 2001 From: whty0 Date: Mon, 5 Nov 2018 11:44:22 +0800 Subject: [PATCH] [CE-493] Check K8s Host Status failed 1. Fix the bug that checking K8s Host Status failed 2. Add the env 'PERIOD_TIME' in 'watchdog' to set the period time Change-Id: I6b6cc3fe4ef2d5a8858e7c5cc2c5dcbbd0022199 Signed-off-by: whty0 --- src/modules/host.py | 21 ++++++++++++++------- src/watchdog.py | 3 ++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/modules/host.py b/src/modules/host.py index 3a81d439..7e058108 100644 --- a/src/modules/host.py +++ b/src/modules/host.py @@ -398,14 +398,21 @@ def refresh_status(self, id): if not host: logger.warning("No host found with id=" + id) return False - if not self.host_agents[host.type]\ - .refresh_status(host.worker_api): - logger.warning("Host {} is inactive".format(id)) - self.db_set_by_id(id, **{"status": "inactive"}) - return False + if host.type == WORKER_TYPE_K8S: + if not self.host_agents[host.type]\ + .refresh_status(host.k8s_param): + logger.warning("Host {} is inactive".format(id)) + self.db_set_by_id(id, **{"status": "inactive"}) + return False else: - self.db_set_by_id(id, **{"status": "active"}) - return True + if not self.host_agents[host.type]\ + .refresh_status(host.worker_api): + logger.warning("Host {} is inactive".format(id)) + self.db_set_by_id(id, **{"status": "inactive"}) + return False + + self.db_set_by_id(id, **{"status": "active"}) + return True def is_active(self, host_id): """ diff --git a/src/watchdog.py b/src/watchdog.py index f8ca9e02..f3d00d1b 100644 --- a/src/watchdog.py +++ b/src/watchdog.py @@ -18,6 +18,7 @@ MONGODB_PORT = int(os.getenv('MONGODB_PORT', 27017)) MONGODB_USERNAME = os.getenv('MONGODB_USERNAME', '') MONGODB_PASSWORD = os.getenv('MONGODB_PASSWORD', '') +PERIOD_TIME = int(os.getenv('PERIOD_TIME', 15)) connect(MONGODB_DB, host=MONGODB_HOST, username=MONGODB_USERNAME, password=MONGODB_PASSWORD, connect=False, tz_aware=True) @@ -133,4 +134,4 @@ def watch_run(period=15): if __name__ == '__main__': - watch_run() + watch_run(PERIOD_TIME)