summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>2019-05-30 10:12:36 +0200
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>2019-05-30 10:12:36 +0200
commitbca8435a16ae814dc7bf9adc0e287924b4d29da4 (patch)
treee38e2af52ff918fb2643ced373b7485635752688
parent8e9812a9dda6fff57c249e2179023c16bc061958 (diff)
Make healthcheck script output unbuffered
A subprocess.Popen object is created instead of convenience check_output() routine usage to allow unbuffered reading stdout from asynchronously running subprocess. Change-Id: I0dca13d6ac5d533d0ef19ddc5713830c57b37175 Issue-ID: OOM-1806 Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
-rwxr-xr-xhelm_deployment_status.py25
1 files changed, 11 insertions, 14 deletions
diff --git a/helm_deployment_status.py b/helm_deployment_status.py
index e92f64b1..8f9a931d 100755
--- a/helm_deployment_status.py
+++ b/helm_deployment_status.py
@@ -25,7 +25,7 @@ import sys
import argparse
import yaml
import requests
-import subprocess
+from subprocess import Popen,STDOUT,PIPE
import datetime
from time import sleep
from os.path import expanduser
@@ -102,13 +102,13 @@ def get_k8s_controllers(k8s):
return k8s_controllers, list(not_ready_controllers)
def exec_healthcheck(hp_script, namespace, hp_mode):
- try:
- hc = subprocess.check_output(
- ['sh', hp_script, namespace, hp_mode],
- stderr=subprocess.STDOUT)
- return 0, hc
- except subprocess.CalledProcessError as err:
- return err.returncode, err.output
+ # spawn healthcheck script and redirect it's stderr to stdout
+ hc = Popen(['sh',hp_script,namespace,hp_mode],stdout=PIPE,stderr=STDOUT)
+ # Trace the output of subprocess until it has finished
+ for line in iter(hc.stdout.readline, ''):
+ print(line.strip())
+ hc.poll() # set returncode in Popen object
+ return hc.returncode
def check_readiness(k8s, verbosity):
k8s_controllers, not_ready_controllers = get_k8s_controllers(k8s)
@@ -297,12 +297,9 @@ def main():
ready = check_readiness(k8s, 2)
if args.health_path is not None:
- try:
- hc_rc, hc_output = exec_healthcheck(args.health_path, args.namespace, args.health_mode)
- except IOError as err:
- sys.exit(err.strerror)
- print(hc_output.decode('utf-8'))
- sys.exit(hc_rc)
+ hc_rc = exec_healthcheck(args.health_path, args.namespace, args.health_mode)
+ if hc_rc:
+ sys.exit(hc_rc)
if not ready:
sys.exit('Deployment is not ready')