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/4420/head
parent
362b682f1c
commit
db276373e5
|
@ -12,6 +12,7 @@ import platform
|
||||||
import os.path
|
import os.path
|
||||||
import subprocess
|
import subprocess
|
||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
filelist = [
|
filelist = [
|
||||||
'/etc/oracle-release',
|
'/etc/oracle-release',
|
||||||
|
@ -46,7 +47,15 @@ dist = platform.dist()
|
||||||
|
|
||||||
|
|
||||||
facts = ['distribution', 'distribution_version', 'distribution_release', 'distribution_major_version', 'os_family']
|
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('{'):])
|
parsed = json.loads(ansible_out[ansible_out.index('{'):])
|
||||||
ansible_facts = {}
|
ansible_facts = {}
|
||||||
for fact in facts:
|
for fact in facts:
|
||||||
|
|
Loading…
Reference in New Issue