IMPALA-9157: Make helper function exec_local_command python 2.6 compatible
Change-Id: I928a4df9dc883e8e801a42ead14ec7875169d4ae
Reviewed-on: http://gerrit.cloudera.org:8080/14788
Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
diff --git a/lib/python/impala_py_lib/helpers.py b/lib/python/impala_py_lib/helpers.py
index 93a868f..a6c68d8 100644
--- a/lib/python/impala_py_lib/helpers.py
+++ b/lib/python/impala_py_lib/helpers.py
@@ -16,22 +16,35 @@
# under the License.
import fnmatch
+import logging
import os
import re
import subprocess
+logging.basicConfig()
+LOG = logging.getLogger('impala_lib_python_helpers')
+
def exec_local_command(cmd):
"""
Executes a command for the local bash shell and return stdout as a string.
+ Raise CalledProcessError in case of non-zero return code.
+
Args:
cmd: command as a string
Return:
STDOUT
"""
- return subprocess.check_output(cmd.split())
+ proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ output, error = proc.communicate()
+ retcode = proc.poll()
+ if retcode:
+ LOG.error("{0} returned status {1}: {2}".format(cmd, retcode, error))
+ raise subprocess.CalledProcessError()
+ else:
+ return output
def find_all_files(fname_pattern, base_dir=os.getenv('IMPALA_HOME', '.')):