Skip to content

Commit

Permalink
[CE-493] Check K8s Host Status failed
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
whty0 committed Nov 5, 2018
1 parent 00f23e7 commit 31b9371
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
21 changes: 14 additions & 7 deletions src/modules/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
3 changes: 2 additions & 1 deletion src/watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -133,4 +134,4 @@ def watch_run(period=15):


if __name__ == '__main__':
watch_run()
watch_run(PERIOD_TIME)

0 comments on commit 31b9371

Please sign in to comment.