[hca] Restore deploy_{stdout,stderr,status_code}
In I5504c00efce89105d403722d583bb75f7bdea714, we removed
deploy_stderr from the output and instead piped everything into
deploy_stdout. Turns out that this is not backward compatible and
removes it from the ouptut of:
openstack software deployment output show <output_id> --long --all
This PS uses threading to write stdout and stderr live to a file and
correctly return deploy_status_code instead of None.
Story: 2007264
Task: 38983
Change-Id: I174e80c6982317f52150a4b255f3d1c592d9caaf
Signed-off-by: Bharat Kunwar <brtknr@bath.edu>
This commit is contained in:
@@ -15,9 +15,9 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import select
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import threading
|
||||||
|
|
||||||
WORKING_DIR = os.environ.get('HEAT_SCRIPT_WORKING',
|
WORKING_DIR = os.environ.get('HEAT_SCRIPT_WORKING',
|
||||||
'/var/lib/heat-config/heat-config-script')
|
'/var/lib/heat-config/heat-config-script')
|
||||||
@@ -69,19 +69,30 @@ def main(argv=sys.argv):
|
|||||||
f.write(c.get('config', ''))
|
f.write(c.get('config', ''))
|
||||||
|
|
||||||
log.debug('Running %s, logging to %s' % (fn, lp))
|
log.debug('Running %s, logging to %s' % (fn, lp))
|
||||||
subproc = subprocess.Popen([fn], stdout=subprocess.PIPE,
|
subproc = subprocess.Popen([fn], env=env,
|
||||||
stderr=subprocess.STDOUT, env=env)
|
stdout=subprocess.PIPE,
|
||||||
with open(lp, 'w') as f:
|
stderr=subprocess.PIPE)
|
||||||
while subproc.poll() is None:
|
|
||||||
read, _, _ = select.select([subproc.stdout], [], [])
|
|
||||||
for stream in read:
|
|
||||||
if stream:
|
|
||||||
line = stream.readline().decode('utf-8', 'replace')
|
|
||||||
f.write(line)
|
|
||||||
f.flush()
|
|
||||||
|
|
||||||
if subproc.returncode:
|
def consumer(label, fd):
|
||||||
log.error("Error running %s. [%s]\n" % (fn, subproc.returncode))
|
with feeder[label]:
|
||||||
|
# NOTE: workaround read-ahead bug
|
||||||
|
for line in iter(feeder[label].readline, b''):
|
||||||
|
line = line.decode('utf-8', 'replace')
|
||||||
|
logger[label](line.strip())
|
||||||
|
deploy[label] += line
|
||||||
|
fd.write(line)
|
||||||
|
|
||||||
|
feeder = dict(stdout=subproc.stdout, stderr=subproc.stderr)
|
||||||
|
deploy = dict(stdout='', stderr='')
|
||||||
|
logger = dict(stdout=lambda line: log.info(line),
|
||||||
|
stderr=lambda line: log.debug(line))
|
||||||
|
with open(lp, 'w') as fd:
|
||||||
|
for label in ['stdout', 'stderr']:
|
||||||
|
threading.Thread(target=consumer, args=[label, fd]).start()
|
||||||
|
deploy_status_code = subproc.wait()
|
||||||
|
|
||||||
|
if deploy_status_code:
|
||||||
|
log.error("Error running %s. [%s]\n" % (fn, deploy_status_code))
|
||||||
else:
|
else:
|
||||||
log.info('Completed %s' % fn)
|
log.info('Completed %s' % fn)
|
||||||
|
|
||||||
@@ -96,7 +107,9 @@ def main(argv=sys.argv):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
response.update({
|
response.update({
|
||||||
'deploy_status_code': subproc.returncode,
|
'deploy_stdout': deploy["stdout"],
|
||||||
|
'deploy_stderr': deploy["stderr"],
|
||||||
|
'deploy_status_code': deploy_status_code,
|
||||||
})
|
})
|
||||||
|
|
||||||
json.dump(response, sys.stdout)
|
json.dump(response, sys.stdout)
|
||||||
|
|||||||
Reference in New Issue
Block a user