From fd9c80208c00021a49df6907973bbbb3fa242069 Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Sat, 2 May 2015 12:00:52 +0000 Subject: [PATCH] Replace subprocess with run_local in _find_images In the DevStack caching script/element for Nodepool images, use run_local instead of subprocess.check_output in the _find_images function. The latter wasn't introduced until Python 2.7 and so won't work on CentOS 6. The script called from this function returns quickly and doesn't benefit from non-blocking I/O anyway. Change-Id: I3129f1f5b3fece321ae132ea1a52b0e156e58365 --- .../extra-data.d/55-cache-devstack-repos | 20 +++++++++---------- nodepool/scripts/cache_devstack.py | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/nodepool/elements/cache-devstack/extra-data.d/55-cache-devstack-repos b/nodepool/elements/cache-devstack/extra-data.d/55-cache-devstack-repos index d40f693266..ea4dae99b2 100755 --- a/nodepool/elements/cache-devstack/extra-data.d/55-cache-devstack-repos +++ b/nodepool/elements/cache-devstack/extra-data.d/55-cache-devstack-repos @@ -17,7 +17,6 @@ # limitations under the License. import os -import subprocess import sys # this is a bit weird; we want to get the filter to use on the @@ -113,15 +112,16 @@ def _legacy_find_images(basedir): def _find_images(basedir): images = [] - try: - image_tool = os.path.join(basedir, 'tools', 'image_list.sh') - if os.path.exists(image_tool): - images = subprocess.check_output(image_tool).split('\n') - except subprocess.CalledProcessError as ce: - print "image_list.sh failed" - print "Exit: %s, Output: %s" % (ce.returncode, ce.output) - # reset images so we'll fall back - images = [] + image_tool = os.path.join(basedir, 'tools', 'image_list.sh') + if os.path.exists(image_tool): + returncode, out = run_local(image_tool, status=True) + if returncode: + print "%s failed" % image_tool + print "Exit: %s, Output: %s" % (returncode, out) + # reset images so we'll fall back + images = [] + else: + images = out.split('\n') return images diff --git a/nodepool/scripts/cache_devstack.py b/nodepool/scripts/cache_devstack.py index f9c17a0b9a..41c50f113f 100755 --- a/nodepool/scripts/cache_devstack.py +++ b/nodepool/scripts/cache_devstack.py @@ -17,7 +17,6 @@ # limitations under the License. import os -import subprocess import sys from common import run_local @@ -82,15 +81,16 @@ def _legacy_find_images(basedir): def _find_images(basedir): images = [] - try: - image_tool = os.path.join(basedir, 'tools', 'image_list.sh') - if os.path.exists(image_tool): - images = subprocess.check_output(image_tool).split('\n') - except subprocess.CalledProcessError as ce: - print "image_list.sh failed" - print "Exit: %s, Output: %s" % (ce.returncode, ce.output) - # reset images so we'll fall back - images = [] + image_tool = os.path.join(basedir, 'tools', 'image_list.sh') + if os.path.exists(image_tool): + returncode, out = run_local(image_tool, status=True) + if returncode: + print "%s failed" % image_tool + print "Exit: %s, Output: %s" % (returncode, out) + # reset images so we'll fall back + images = [] + else: + images = out.split('\n') return images