Files
krkn/kraken/invoke/command.py
Naga Ravi Chaitanya Elluri c0b9cb46da Improve error handling
This commit:
- Adds timeout to avoid operations hanging for long durations.
- Improves exception handling and exits wherever needed.
- Sets KUBECONFIG env var globoally to access the cluster.
2021-07-21 12:48:06 -04:00

21 lines
521 B
Python

import subprocess
import logging
import sys
# Invokes a given command and returns the stdout
def invoke(command, timeout=None):
try:
output = subprocess.check_output(command, shell=True, universal_newlines=True, timeout=timeout)
except Exception as e:
logging.error("Failed to run %s, error: %s" % (command, e))
sys.exit(1)
return output
def run(command):
try:
subprocess.run(command, shell=True, universal_newlines=True, timeout=45)
except Exception:
pass