gen_distribution_version_testcase.py should fail if ansible run fails (#17693)

Currently, "ansible localhost -m setup" can fail silently during the
run of gen_distribution_version_testcase.py, resulting in incorrect
output. Use check_output() rather than communicate() and handle
the exception if we get a nonzero return value.
pull/17768/head
cinerama70 8 years ago committed by Matt Clay
parent 362b682f1c
commit db276373e5

@ -12,6 +12,7 @@ import platform
import os.path
import subprocess
import json
import sys
filelist = [
'/etc/oracle-release',
@ -46,7 +47,15 @@ dist = platform.dist()
facts = ['distribution', 'distribution_version', 'distribution_release', 'distribution_major_version', 'os_family']
ansible_out = subprocess.Popen(['ansible', 'localhost', '-m', 'setup'], stdout=subprocess.PIPE).communicate()[0]
try:
ansible_out = subprocess.check_output(
['ansible', 'localhost', '-m', 'setup'])
except subprocess.CalledProcessError as e:
print("ERROR: ansible run failed, output was: \n")
print(e.output)
sys.exit(e.returncode)
parsed = json.loads(ansible_out[ansible_out.index('{'):])
ansible_facts = {}
for fact in facts:

Loading…
Cancel
Save