From: tierno Date: Tue, 11 Feb 2020 12:38:19 +0000 (+0000) Subject: fix 1015. move health check to other module to avoid import unneeded libraries X-Git-Tag: v7.1.0rc1~26 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F78%2F8578%2F1;p=osm%2FLCM.git fix 1015. move health check to other module to avoid import unneeded libraries Change-Id: I0430b95756bfa592ae5bc9d1d78e2dbeb8e4d357 Signed-off-by: tierno --- diff --git a/Dockerfile.local b/Dockerfile.local index cf18280..36c6710 100644 --- a/Dockerfile.local +++ b/Dockerfile.local @@ -116,5 +116,6 @@ ADD . /app/LCM # Run app.py when the container launches CMD python3 -m osm_lcm.lcm -# HEALTHCHECK --interval=120s --timeout=15s --retries=1 \ -# CMD python3 -m osm_lcm.lcm --health-check || exit 1 +# HEALTHCHECK --start-period=120s --interval=30s --timeout=30s --retries=1 \ +# CMD python3 -m osm_lcm.lcm_hc || exit 1 + diff --git a/osm_lcm/lcm.cfg b/osm_lcm/lcm.cfg index a0cac02..d100489 100644 --- a/osm_lcm/lcm.cfg +++ b/osm_lcm/lcm.cfg @@ -41,6 +41,9 @@ VCA: port: 17070 user: admin secret: secret + helmpath: /usr/local/bin/helm + kubectlpath: /usr/bin/kubectl + jujupath: /usr/local/bin/juju # pubkey: pubkey # cacert: cacert # apiproxy: apiproxy diff --git a/osm_lcm/lcm.py b/osm_lcm/lcm.py index 10156d3..b306720 100644 --- a/osm_lcm/lcm.py +++ b/osm_lcm/lcm.py @@ -34,7 +34,7 @@ from osm_lcm import vim_sdn from osm_lcm import netslice from osm_lcm import ROclient -from time import time, sleep +from time import time from osm_lcm.lcm_utils import versiontuple, LcmException, TaskRegistry, LcmExceptionExit from osm_lcm import version as lcm_version, version_date as lcm_version_date @@ -608,23 +608,6 @@ def usage(): # --log-socket-port PORT: send logs using this port (default: 9022)") -def health_check(): - retry = 2 - while retry: - retry -= 1 - try: - with open(health_check_file, "r") as f: - last_received_ping = f.read() - - if time() - float(last_received_ping) < 2 * Lcm.ping_interval_pace: # allow one ping not received every two - exit(0) - except Exception: - pass - if retry: - sleep(6) - exit(1) - - if __name__ == '__main__': try: @@ -645,7 +628,8 @@ if __name__ == '__main__': elif o in ("-c", "--config"): config_file = a elif o == "--health-check": - health_check() + from osm_lcm.lcm_hc import health_check + health_check(health_check_file, Lcm.ping_interval_pace) # elif o == "--log-socket-port": # log_socket_port = a # elif o == "--log-socket-host": diff --git a/osm_lcm/lcm_hc.py b/osm_lcm/lcm_hc.py new file mode 100644 index 0000000..701e5b6 --- /dev/null +++ b/osm_lcm/lcm_hc.py @@ -0,0 +1,48 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +## +# Copyright 2018 Telefonica S.A. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +## + +from os import path +from time import time, sleep +from sys import stderr + +""" This module is used for helth check. A file called time_last_ping is used +This contains the last time where something is received from kafka +""" + + +def health_check(health_check_file=None, ping_interval_pace=120): + health_check_file = health_check_file or path.expanduser("~") + "/time_last_ping" + retry = 2 + while retry: + retry -= 1 + try: + with open(health_check_file, "r") as f: + last_received_ping = f.read() + + if time() - float(last_received_ping) < 2 * ping_interval_pace: # allow one ping not received every two + exit(0) + except Exception as e: + print(e, file=stderr) + if retry: + sleep(6) + exit(1) + + +if __name__ == '__main__': + health_check()