Skip to content

Commit

Permalink
Merge pull request #14934 from LabNConsulting/chopps/new-munet-0.13.10
Browse files Browse the repository at this point in the history
tests: import munet 0.13.10
  • Loading branch information
donaldsharp authored Dec 5, 2023
2 parents edb1cb8 + 6f64ebe commit 83018e2
Show file tree
Hide file tree
Showing 7 changed files with 449 additions and 106 deletions.
46 changes: 32 additions & 14 deletions tests/topotests/munet/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,8 @@ def _common_prologue(self, async_exec, method, cmd, skip_pre_cmd=False, **kwargs
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)',
'%s: %s("%s", pre_cmd: "%s" use_pty: %s kwargs: %.120s)',
self,
"XXX" if method == "_spawn" else "",
method,
cmd_list,
pre_cmd_list if not skip_pre_cmd else "",
Expand Down Expand Up @@ -566,7 +565,7 @@ def _fdspawn(self, fo, **kwargs):

def _spawn(self, cmd, skip_pre_cmd=False, use_pty=False, echo=False, **kwargs):
logging.debug(
'%s: XXX _spawn: cmd "%s" skip_pre_cmd %s use_pty %s echo %s kwargs %s',
'%s: _spawn: cmd "%s" skip_pre_cmd %s use_pty %s echo %s kwargs %s',
self,
cmd,
skip_pre_cmd,
Expand All @@ -579,7 +578,7 @@ def _spawn(self, cmd, skip_pre_cmd=False, use_pty=False, echo=False, **kwargs):
)

self.logger.debug(
'%s: XXX %s("%s", use_pty %s echo %s defaults: %s)',
'%s: %s("%s", use_pty %s echo %s defaults: %s)',
self,
"PopenSpawn" if not use_pty else "pexpect.spawn",
actual_cmd,
Expand Down Expand Up @@ -865,14 +864,18 @@ async def async_cleanup_proc(self, p, pid=None):
else:
o, e = await p.communicate()
self.logger.debug(
"%s: cmd_p already exited status: %s", self, proc_error(p, o, e)
"%s: [cleanup_proc] proc already exited status: %s",
self,
proc_error(p, o, e),
)
return None

if pid is None:
pid = p.pid

self.logger.debug("%s: terminate process: %s (pid %s)", self, proc_str(p), pid)
self.logger.debug(
"%s: [cleanup_proc] terminate process: %s (pid %s)", self, proc_str(p), pid
)
try:
# This will SIGHUP and wait a while then SIGKILL and return immediately
await self.cleanup_pid(p.pid, pid)
Expand All @@ -885,14 +888,19 @@ async def async_cleanup_proc(self, p, pid=None):
else:
o, e = await asyncio.wait_for(p.communicate(), timeout=wait_secs)
self.logger.debug(
"%s: cmd_p exited after kill, status: %s", self, proc_error(p, o, e)
"%s: [cleanup_proc] exited after kill, status: %s",
self,
proc_error(p, o, e),
)
except (asyncio.TimeoutError, subprocess.TimeoutExpired):
self.logger.warning("%s: SIGKILL timeout", self)
self.logger.warning("%s: [cleanup_proc] SIGKILL timeout", self)
return p
except Exception as error:
self.logger.warning(
"%s: kill unexpected exception: %s", self, error, exc_info=True
"%s: [cleanup_proc] kill unexpected exception: %s",
self,
error,
exc_info=True,
)
return p
return None
Expand Down Expand Up @@ -1206,7 +1214,7 @@ def run_in_window(
# XXX need to test ssh in Xterm
sudo_path = get_exec_path_host(["sudo"])
# This first test case seems same as last but using list instead of string?
if self.is_vm and self.use_ssh: # pylint: disable=E1101
if self.is_vm and self.use_ssh and not ns_only: # pylint: disable=E1101
if isinstance(cmd, str):
cmd = shlex.split(cmd)
cmd = ["/usr/bin/env", f"MUNET_NODENAME={self.name}"] + cmd
Expand Down Expand Up @@ -1332,6 +1340,14 @@ def run_in_window(

# Re-adjust the layout
if "TMUX" in os.environ:
cmd = [
get_exec_path_host("tmux"),
"select-layout",
"-t",
pane_info if not tmux_target else tmux_target,
"even-horizontal",
]
commander.cmd_status(cmd)
cmd = [
get_exec_path_host("tmux"),
"select-layout",
Expand Down Expand Up @@ -2005,8 +2021,10 @@ def __init__(
stdout=stdout,
stderr=stderr,
text=True,
start_new_session=not unet,
shell=False,
# start_new_session=not unet
# preexec_fn=os.setsid if not unet else None,
preexec_fn=os.setsid,
)

# The pid number returned is in the global pid namespace. For unshare_inline
Expand Down Expand Up @@ -2345,14 +2363,14 @@ async def _async_delete(self):
and self.pid != our_pid
):
self.logger.debug(
"cleanup pid on separate pid %s from proc pid %s",
"cleanup separate pid %s from namespace proc pid %s",
self.pid,
self.p.pid if self.p else None,
)
await self.cleanup_pid(self.pid)

if self.p is not None:
self.logger.debug("cleanup proc pid %s", self.p.pid)
self.logger.debug("cleanup namespace proc pid %s", self.p.pid)
await self.async_cleanup_proc(self.p)

# return to the previous namespace, need to do this in case anothe munet
Expand Down Expand Up @@ -2937,7 +2955,7 @@ def __init__(
)

logging.debug(
'ShellWraper: XXX prompt "%s" will_echo %s child.echo %s',
'ShellWraper: prompt "%s" will_echo %s child.echo %s',
prompt,
will_echo,
spawn.echo,
Expand Down
5 changes: 3 additions & 2 deletions tests/topotests/munet/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,14 @@ def get_shcmd(unet, host, kinds, execfmt, ucmd):
if not execfmt:
return ""

# Do substitutions for {} in string
# Do substitutions for {} and {N} in string
numfmt = len(re.findall(r"{\d*}", execfmt))
if numfmt > 1:
ucmd = execfmt.format(*shlex.split(ucmd))
elif numfmt:
ucmd = execfmt.format(ucmd)
elif len(re.findall(r"{[a-zA-Z_][0-9a-zA-Z_\.]*}", execfmt)):
# look for any pair of {}s but do not count escaped {{ or }}
elif len(re.findall(r"{[^}]+}", execfmt.replace("{{", "").replace("}}", ""))):
if execfmt.endswith('"'):
fstring = "f'''" + execfmt + "'''"
else:
Expand Down
Loading

0 comments on commit 83018e2

Please sign in to comment.