|
@@ -23,6 +23,8 @@ Ambari Agent
|
|
|
import os
|
|
|
import tempfile
|
|
|
from resource_management.core import shell
|
|
|
+from resource_management.core.logger import Logger
|
|
|
+from resource_management.core.exceptions import Fail
|
|
|
|
|
|
def get_user_call_output(command, user, quiet=False, is_checked_call=True, **call_kwargs):
|
|
|
"""
|
|
@@ -45,14 +47,22 @@ def get_user_call_output(command, user, quiet=False, is_checked_call=True, **cal
|
|
|
command_string += " 1>" + out_files[0].name
|
|
|
command_string += " 2>" + out_files[1].name
|
|
|
|
|
|
- func = shell.checked_call if is_checked_call else shell.call
|
|
|
- func_result = func(shell.as_user(command_string, user), quiet=quiet, **call_kwargs)
|
|
|
+ code, _ = shell.call(shell.as_user(command_string, user), quiet=quiet, **call_kwargs)
|
|
|
|
|
|
files_output = []
|
|
|
for f in out_files:
|
|
|
files_output.append(f.read().strip('\n'))
|
|
|
+
|
|
|
+ if code:
|
|
|
+ all_output = files_output[1] + '\n' + files_output[0]
|
|
|
+ err_msg = Logger.filter_text(("Execution of '%s' returned %d. %s") % (command_string, code, all_output))
|
|
|
+
|
|
|
+ if is_checked_call:
|
|
|
+ raise Fail(err_msg)
|
|
|
+ else:
|
|
|
+ Logger.warning(err_msg)
|
|
|
|
|
|
- return func_result[0], files_output[0], files_output[1]
|
|
|
+ return code, files_output[0], files_output[1]
|
|
|
finally:
|
|
|
for f in out_files:
|
|
|
f.close()
|