Simplify stdout/stderr handling

This commit is contained in:
Joshua Boniface 2023-08-30 09:47:45 -04:00
parent cac2e2a2b8
commit 6cfc75e321
1 changed files with 4 additions and 4 deletions

View File

@ -22,18 +22,16 @@
import os.path import os.path
import shutil import shutil
from subprocess import run from subprocess import run
from sys import stdout, stderr
import pvcbootstrapd.lib.notifications as notifications import pvcbootstrapd.lib.notifications as notifications
def build_tftp_repository(config): def build_tftp_repository(config):
# Generate an installer config # Generate an installer config
build_cmd = f"{config['ansible_path']}/pvc-installer/buildpxe.sh -o {config['tftp_root_path']} -u {config['deploy_username']}"
build_cmd = [ f"{config['ansible_path']}/pvc-installer/buildpxe.sh", "-o", config['tftp_root_path'], "-u", config['deploy_username'] ] build_cmd = [ f"{config['ansible_path']}/pvc-installer/buildpxe.sh", "-o", config['tftp_root_path'], "-u", config['deploy_username'] ]
print(f"Building TFTP contents via pvc-installer command: {build_cmd}") print(f"Building TFTP contents via pvc-installer command: {' '.join(build_cmd)}")
notifications.send_webhook(config, "begin", f"Building TFTP contents via pvc-installer command: {' '.join(build_cmd)}") notifications.send_webhook(config, "begin", f"Building TFTP contents via pvc-installer command: {' '.join(build_cmd)}")
retcode = run(build_cmd, stdout=stdout, stderr=stderr) retcode = run(build_cmd)
return True if retcode == 0 else False return True if retcode == 0 else False
@ -52,6 +50,8 @@ def init_tftp(config):
result = build_tftp_repository(config) result = build_tftp_repository(config)
if result: if result:
print("First run: successfully initialized TFTP root and contents")
notifications.send_webhook(config, "success", "First run: successfully initialized TFTP root and contents") notifications.send_webhook(config, "success", "First run: successfully initialized TFTP root and contents")
else: else:
print("First run: failed initialized TFTP root and contents; see logs above")
notifications.send_webhook(config, "failure", "First run: failed initialized TFTP root and contents; check pvcbootstrapd logs") notifications.send_webhook(config, "failure", "First run: failed initialized TFTP root and contents; check pvcbootstrapd logs")