mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-04-28 19:35:13 +00:00
Merge pull request #13592 from LabNConsulting/chopps/newmunet
munet: import 0.13.5 w/ nicer cmd logging
This commit is contained in:
commit
254feba0a5
@ -1100,7 +1100,7 @@ def _sysctl_atleast(commander, variable, min_value):
|
||||
else:
|
||||
valstr = str(min_value)
|
||||
logger.debug("Increasing sysctl %s from %s to %s", variable, cur_val, valstr)
|
||||
commander.cmd_raises('sysctl -w {}="{}"\n'.format(variable, valstr))
|
||||
commander.cmd_raises('sysctl -w {}="{}"'.format(variable, valstr))
|
||||
|
||||
|
||||
def _sysctl_assure(commander, variable, value):
|
||||
|
@ -47,6 +47,9 @@ root_hostname = subprocess.check_output("hostname")
|
||||
our_pid = os.getpid()
|
||||
|
||||
|
||||
detailed_cmd_logging = False
|
||||
|
||||
|
||||
class MunetError(Exception):
|
||||
"""A generic munet error."""
|
||||
|
||||
@ -119,6 +122,27 @@ def cmd_error(rc, o, e):
|
||||
return s + o + e
|
||||
|
||||
|
||||
def shorten(s):
|
||||
s = s.strip()
|
||||
i = s.find("\n")
|
||||
if i > 0:
|
||||
s = s[: i - 1]
|
||||
if not s.endswith("..."):
|
||||
s += "..."
|
||||
if len(s) > 72:
|
||||
s = s[:69]
|
||||
if not s.endswith("..."):
|
||||
s += "..."
|
||||
return s
|
||||
|
||||
|
||||
def comm_result(rc, o, e):
|
||||
s = f"\n\treturncode {rc}" if rc else ""
|
||||
o = "\n\tstdout: " + shorten(o) if o and o.strip() else ""
|
||||
e = "\n\tstderr: " + shorten(e) if e and e.strip() else ""
|
||||
return s + o + e
|
||||
|
||||
|
||||
def proc_str(p):
|
||||
if hasattr(p, "args"):
|
||||
args = p.args if isinstance(p.args, str) else " ".join(p.args)
|
||||
@ -477,6 +501,17 @@ class Commander: # pylint: disable=R0904
|
||||
defaults["preexec_fn"] = os.setsid
|
||||
defaults["env"]["PS1"] = "$ "
|
||||
|
||||
if not detailed_cmd_logging:
|
||||
pre_cmd_str = shlex.join(pre_cmd_list) if not skip_pre_cmd else ""
|
||||
if "nsenter" in pre_cmd_str:
|
||||
self.logger.debug('%s("%s")', method, shlex.join(cmd_list))
|
||||
elif pre_cmd_str:
|
||||
self.logger.debug(
|
||||
'%s("%s") [precmd: %s]', method, shlex.join(cmd_list), pre_cmd_str
|
||||
)
|
||||
else:
|
||||
self.logger.debug('%s("%s") [no precmd]', method, shlex.join(cmd_list))
|
||||
else:
|
||||
self.logger.debug(
|
||||
'%s: %s %s("%s", pre_cmd: "%s" use_pty: %s kwargs: %.120s)',
|
||||
self,
|
||||
@ -873,7 +908,11 @@ class Commander: # pylint: disable=R0904
|
||||
def _cmd_status_finish(self, p, c, ac, o, e, raises, warn):
|
||||
rc = p.returncode
|
||||
self.last = (rc, ac, c, o, e)
|
||||
if rc:
|
||||
if not rc:
|
||||
resstr = comm_result(rc, o, e)
|
||||
if resstr:
|
||||
self.logger.debug("%s", resstr)
|
||||
else:
|
||||
if warn:
|
||||
self.logger.warning("%s: proc failed: %s", self, proc_error(p, o, e))
|
||||
if raises:
|
||||
|
Loading…
Reference in New Issue
Block a user