Skip to content

Commit

Permalink
Merge pull request #17844 from LabNConsulting/chopps/munet-0-15-3
Browse files Browse the repository at this point in the history
tests: update munet to 0.15.3
  • Loading branch information
donaldsharp authored Jan 13, 2025
2 parents a962ff7 + 3366056 commit 0af26e1
Show file tree
Hide file tree
Showing 5 changed files with 353 additions and 14 deletions.
28 changes: 26 additions & 2 deletions tests/topotests/munet/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ def __init__(self, name, logger=None, unet=None, **kwargs):
self.last = None
self.exec_paths = {}

# For running commands one time only (deals with asyncio)
self.cmd_once_done = {}
self.cmd_once_locks = {}

if not logger:
logname = f"munet.{self.__class__.__name__.lower()}.{name}"
self.logger = logging.getLogger(logname)
Expand Down Expand Up @@ -1189,7 +1193,7 @@ def cmd_legacy(self, cmd, **kwargs):
return stdout

# Run a command in a new window (gnome-terminal, screen, tmux, xterm)
def run_in_window(
def run_in_window( # pylint: disable=too-many-positional-arguments
self,
cmd,
wait_for=False,
Expand All @@ -1205,7 +1209,7 @@ def run_in_window(
Args:
cmd: string to execute.
wait_for: True to wait for exit from command or `str` as channel neme to
wait_for: True to wait for exit from command or `str` as channel name to
signal on exit, otherwise False
background: Do not change focus to new window.
title: Title for new pane (tmux) or window (xterm).
Expand Down Expand Up @@ -1405,6 +1409,26 @@ def run_in_window(

return pane_info

async def async_cmd_raises_once(self, cmd, **kwargs):
if cmd in self.cmd_once_done:
return self.cmd_once_done[cmd]

if cmd not in self.cmd_once_locks:
self.cmd_once_locks[cmd] = asyncio.Lock()

async with self.cmd_once_locks[cmd]:
if cmd not in self.cmd_once_done:
self.logger.info("Running command once: %s", cmd)
self.cmd_once_done[cmd] = await commander.async_cmd_raises(
cmd, **kwargs
)
return self.cmd_once_done[cmd]

def cmd_raises_once(self, cmd, **kwargs):
if cmd not in self.cmd_once_done:
self.cmd_once_done[cmd] = commander.cmd_raises(cmd, **kwargs)
return self.cmd_once_done[cmd]

def delete(self):
"""Calls self.async_delete within an exec loop."""
asyncio.run(self.async_delete())
Expand Down
22 changes: 20 additions & 2 deletions tests/topotests/munet/munet-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
"bios": {
"type": "string"
},
"cloud-init": {
"type": "boolean"
},
"cloud-init-disk": {
"type": "string"
},
"disk": {
"type": "string"
},
Expand All @@ -129,7 +135,7 @@
"initial-cmd": {
"type": "string"
},
"kerenel": {
"kernel": {
"type": "string"
},
"initrd": {
Expand Down Expand Up @@ -373,6 +379,12 @@
"networks-autonumber": {
"type": "boolean"
},
"initial-setup-cmd": {
"type": "string"
},
"initial-setup-host-cmd": {
"type": "string"
},
"networks": {
"type": "array",
"items": {
Expand Down Expand Up @@ -452,6 +464,12 @@
"bios": {
"type": "string"
},
"cloud-init": {
"type": "boolean"
},
"cloud-init-disk": {
"type": "string"
},
"disk": {
"type": "string"
},
Expand All @@ -464,7 +482,7 @@
"initial-cmd": {
"type": "string"
},
"kerenel": {
"kernel": {
"type": "string"
},
"initrd": {
Expand Down
2 changes: 1 addition & 1 deletion tests/topotests/munet/mutest/userapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class TestCase:

# sum_hfmt = "{:5.5s} {:4.4s} {:>6.6s} {}"
# sum_dfmt = "{:5s} {:4.4s} {:^6.6s} {}"
sum_fmt = "%-8.8s %4.4s %{}s %6s %s"
sum_fmt = "%-10s %4.4s %{}s %6s %s"

def __init__(
self,
Expand Down
Loading

0 comments on commit 0af26e1

Please sign in to comment.