本文整理汇总了Python中sos.utilities.sos_get_command_output函数的典型用法代码示例。如果您正苦于以下问题:Python sos_get_command_output函数的具体用法?Python sos_get_command_output怎么用?Python sos_get_command_output使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sos_get_command_output函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_command_output
def get_command_output(self, prog, timeout=300, stderr=True,
chroot=True, runat=None):
if chroot or self.commons['cmdlineopts'].chroot == 'always':
root = self.sysroot
else:
root = None
result = sos_get_command_output(prog, timeout=timeout, stderr=stderr,
chroot=root, chdir=runat)
if result['status'] == 124:
self._log_warn("command '%s' timed out after %ds"
% (prog, timeout))
# command not found or not runnable
if result['status'] == 126 or result['status'] == 127:
# automatically retry chroot'ed commands in the host namespace
if chroot and self.commons['cmdlineopts'].chroot != 'always':
self._log_info("command '%s' not found in %s - "
"re-trying in host root"
% (prog.split()[0], root))
return self.get_command_output(prog, timeout=timeout,
chroot=False, runat=runat)
self._log_debug("could not run '%s': command not found" % prog)
return result
示例2: get_command_output
def get_command_output(self, prog, timeout=300):
(status, output, runtime) = sos_get_command_output(prog, timeout)
if status == 124:
self.soslog.warning("command '%s' timed out after %ds" % (prog, timeout))
if status == 127:
self.soslog.info("could not run '%s': command not found" % prog)
return (status, output, runtime)
示例3: get_cmd_output_now
def get_cmd_output_now(self, exe, suggest_filename=None, root_symlink=False, timeout=300):
"""Execute a command and save the output to a file for inclusion in the
report.
"""
if self.commons['cmdlineopts'].profiler:
start_time = time()
# pylint: disable-msg = W0612
status, shout, runtime = sos_get_command_output(exe, timeout=timeout)
if (status == 127):
self.soslog.debug("could not run '%s': command not found" % exe)
return None
if suggest_filename:
outfn = self.make_command_filename(suggest_filename)
else:
outfn = self.make_command_filename(exe)
outfn_strip = outfn[len(self.commons['cmddir'])+1:]
self.archive.add_string(shout, outfn)
if root_symlink:
self.archive.add_link(outfn, root_symlink)
# save info for later
self.executed_commands.append({'exe': exe, 'file':outfn_strip}) # save in our list
self.commons['xmlreport'].add_command(cmdline=exe,exitcode=status,f_stdout=outfn_strip,runtime=runtime)
if self.commons['cmdlineopts'].profiler:
time_passed = time() - start_time
self.proflog.debug("output: %-75s time: %f" % (exe, time_passed))
return outfn
示例4: _compress
def _compress(self):
methods = []
# Make sure that valid compression commands exist.
for method in ['xz', 'bzip2', 'gzip']:
if is_executable(method):
methods.append(method)
else:
self.log_info("\"%s\" compression method unavailable" % method)
if self.method in methods:
methods = [self.method]
exp_msg = "No compression utilities found."
last_error = Exception(exp_msg)
for cmd in methods:
suffix = "." + cmd.replace('ip', '')
cmd = self._policy.get_cmd_for_compress_method(cmd, self._threads)
try:
exec_cmd = "%s %s" % (cmd, self.name())
r = sos_get_command_output(exec_cmd, stderr=True, timeout=0)
if r['status']:
self.log_error(r['output'])
raise Exception("%s exited with %s" % (exec_cmd,
r['status']))
self._suffix += suffix
return self.name()
except Exception as e:
last_error = e
raise last_error
示例5: _compress
def _compress(self):
methods = []
# Make sure that valid compression commands exist.
for method in ['xz', 'bzip2', 'gzip']:
if is_executable(method):
methods.append(method)
else:
self.log_error("\"%s\" command not found." % method)
if self.method in methods:
methods = [self.method]
exp_msg = "No compression utilities found."
last_error = Exception(exp_msg)
for cmd in methods:
suffix = "." + cmd.replace('ip', '')
# use fast compression if using xz or bz2
if cmd != "gzip":
cmd = "%s -1" % cmd
try:
r = sos_get_command_output("%s %s" % (cmd, self.name()),
timeout=0)
if r['status']:
self.log_info(r['output'])
self._suffix += suffix
return self.name()
except Exception as e:
last_error = e
raise last_error
示例6: get_command_output
def get_command_output(self, prog, timeout=300, runat=None, stderr=True):
result = sos_get_command_output(prog, timeout=timeout, runat=runat, stderr=stderr)
if result["status"] == 124:
self._log_warn("command '%s' timed out after %ds" % (prog, timeout))
# 126 means 'found but not executable'
if result["status"] == 126 or result["status"] == 127:
self._log_debug("could not run '%s': command not found" % prog)
return result
示例7: get_command_output
def get_command_output(self, prog, timeout=300, runat=None):
result = sos_get_command_output(prog, timeout=timeout, runat=runat)
if result['status'] == 124:
self.log_warn("command '%s' timed out after %ds"
% (prog, timeout))
if result['status'] == 127:
self.log_debug("could not run '%s': command not found" % prog)
return result
示例8: _query_service
def _query_service(self, name):
"""Query an individual service"""
if self.query_cmd:
try:
return sos_get_command_output("%s %s" % (self.query_cmd, name))
except Exception:
return None
return None
示例9: _query_service
def _query_service(self, name):
"""Query an individual service"""
if self.query_cmd:
res = sos_get_command_output("%s %s" % (self.query_cmd, name))
if res['status'] == 0:
return res
else:
return None
return None
示例10: _encrypt
def _encrypt(self, archive):
"""Encrypts the compressed archive using GPG.
If encryption fails for any reason, it should be logged by sos but not
cause execution to stop. The assumption is that the unencrypted archive
would still be of use to the user, and/or that the end user has another
means of securing the archive.
Returns the name of the encrypted archive, or raises an exception to
signal that encryption failed and the unencrypted archive name should
be used.
"""
arc_name = archive.replace("sosreport-", "secured-sosreport-")
arc_name += ".gpg"
enc_cmd = "gpg --batch -o %s " % arc_name
env = None
if self.enc_opts["key"]:
# need to assume a trusted key here to be able to encrypt the
# archive non-interactively
enc_cmd += "--trust-model always -e -r %s " % self.enc_opts["key"]
enc_cmd += archive
if self.enc_opts["password"]:
# prevent change of gpg options using a long password, but also
# prevent the addition of quote characters to the passphrase
passwd = "%s" % self.enc_opts["password"].replace('\'"', '')
env = {"sos_gpg": passwd}
enc_cmd += "-c --passphrase-fd 0 "
enc_cmd = "/bin/bash -c \"echo $sos_gpg | %s\"" % enc_cmd
enc_cmd += archive
r = sos_get_command_output(enc_cmd, timeout=0, env=env)
if r["status"] == 0:
return arc_name
elif r["status"] == 2:
if self.enc_opts["key"]:
msg = "Specified key not in keyring"
else:
msg = "Could not read passphrase"
else:
# TODO: report the actual error from gpg. Currently, we cannot as
# sos_get_command_output() does not capture stderr
msg = "gpg exited with code %s" % r["status"]
raise Exception(msg)
示例11: _compress
def _compress(self):
methods = ['xz', 'bzip2', 'gzip']
if self.method in methods:
methods = [self.method]
last_error = Exception("compression failed")
for cmd in methods:
suffix = "." + cmd.replace('ip', '')
# use fast compression if using xz or bz2
if cmd != "gzip":
cmd = "%s -1" % cmd
try:
r = sos_get_command_output("%s %s" % (cmd, self.name()))
if r['status']:
self.log_info(r['output'])
self._suffix += suffix
return self.name()
except Exception as e:
last_error = e
raise last_error
示例12: test_output_non_exe
def test_output_non_exe(self):
path = os.path.join(TEST_DIR, "utility_tests.py")
result = sos_get_command_output(path)
self.assertEquals(result["status"], 127)
self.assertEquals(result["output"], "")
示例13: test_output
def test_output(self):
path = os.path.join(TEST_DIR, 'test_exe.py')
result = sos_get_command_output(path)
self.assertEquals(result['status'], 0)
self.assertEquals(result['output'], "executed\n")
示例14: test_output_non_exe
def test_output_non_exe(self):
path = os.path.join(TEST_DIR, 'utility_tests.py')
ret, out, junk = sos_get_command_output(path)
self.assertEquals(ret, 127)
self.assertEquals(out, "")
示例15: test_output
def test_output(self):
path = os.path.join(TEST_DIR, 'test_exe.py')
ret, out, junk = sos_get_command_output(path)
self.assertEquals(ret, 0)
self.assertEquals(out, "executed\n")