Skip to content

Commit 31b9371

Browse files
author
whty0
committed
[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 <wangzhipengxlj@163.com>
1 parent 00f23e7 commit 31b9371

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/modules/host.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,21 @@ def refresh_status(self, id):
398398
if not host:
399399
logger.warning("No host found with id=" + id)
400400
return False
401-
if not self.host_agents[host.type]\
402-
.refresh_status(host.worker_api):
403-
logger.warning("Host {} is inactive".format(id))
404-
self.db_set_by_id(id, **{"status": "inactive"})
405-
return False
401+
if host.type == WORKER_TYPE_K8S:
402+
if not self.host_agents[host.type]\
403+
.refresh_status(host.k8s_param):
404+
logger.warning("Host {} is inactive".format(id))
405+
self.db_set_by_id(id, **{"status": "inactive"})
406+
return False
406407
else:
407-
self.db_set_by_id(id, **{"status": "active"})
408-
return True
408+
if not self.host_agents[host.type]\
409+
.refresh_status(host.worker_api):
410+
logger.warning("Host {} is inactive".format(id))
411+
self.db_set_by_id(id, **{"status": "inactive"})
412+
return False
413+
414+
self.db_set_by_id(id, **{"status": "active"})
415+
return True
409416

410417
def is_active(self, host_id):
411418
"""

src/watchdog.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
MONGODB_PORT = int(os.getenv('MONGODB_PORT', 27017))
1919
MONGODB_USERNAME = os.getenv('MONGODB_USERNAME', '')
2020
MONGODB_PASSWORD = os.getenv('MONGODB_PASSWORD', '')
21+
PERIOD_TIME = int(os.getenv('PERIOD_TIME', 15))
2122

2223
connect(MONGODB_DB, host=MONGODB_HOST, username=MONGODB_USERNAME,
2324
password=MONGODB_PASSWORD, connect=False, tz_aware=True)
@@ -133,4 +134,4 @@ def watch_run(period=15):
133134

134135

135136
if __name__ == '__main__':
136-
watch_run()
137+
watch_run(PERIOD_TIME)

0 commit comments

Comments
 (0)