Skip to content

Tree: use set instead of NodeSet for gwtargets tracking #562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/ClusterShell/CLI/Clush.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,10 @@ def update(self):
gwcnt = len(self.task.gateways)
if gwcnt:
# tree mode
act_targets = NodeSet()
act_targets = set()
for gw, (chan, metaworkers) in self.task.gateways.items():
act_targets.updaten(mw.gwtargets[gw] for mw in metaworkers)
for mw in metaworkers:
act_targets.update(mw.gwtargets[gw])
cnt = len(act_targets) + len(self.task._engine.clients()) - gwcnt
gwinfo = ' gw %d' % gwcnt
else:
Expand Down Expand Up @@ -597,12 +598,14 @@ def ttyloop(task, nodeset, timeout, display, remote, trytree):
% (len(ns_reg), ns_reg, pending,
len(gws), NodeSet._fromlist1(gws)))
for gw, (chan, metaworkers) in task.gateways.items():
act_targets = NodeSet.fromlist(mw.gwtargets[gw]
for mw in metaworkers)
act_targets = set()
for mw in metaworkers:
act_targets.update(mw.gwtargets[gw])
if act_targets:
act_tgt_ns = NodeSet.fromlist(act_targets)
display.vprint_err(VERB_QUIET,
"clush: [tree] in progress(%d) on %s: %s"
% (len(act_targets), gw, act_targets))
% (len(act_targets), gw, act_tgt_ns))
else:
cmdl = cmd.lower()
try:
Expand Down
10 changes: 5 additions & 5 deletions lib/ClusterShell/Worker/Tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def _copy_remote(self, source, dest, targets, gateway, timeout, reverse):

self._target_count += len(targets)

self.gwtargets.setdefault(str(gateway), NodeSet()).add(targets)
self.gwtargets.setdefault(str(gateway), set()).update(targets)

# tar commands are built here and launched on targets
if reverse:
Expand All @@ -377,7 +377,8 @@ def _execute_remote(self, cmd, targets, gateway, timeout):

self._target_count += len(targets)

self.gwtargets.setdefault(str(gateway), NodeSet()).add(targets)
# GH#560: use set instead of NodeSet to keep track of active targets
self.gwtargets.setdefault(str(gateway), set()).update(targets)

pchan = self.task._pchannel(gateway, self)
pchan.shell(nodes=targets, command=cmd, worker=self, timeout=timeout,
Expand All @@ -392,12 +393,11 @@ def _relaunch(self, previous_gateway):
previous_gateway must be defined. However, it is not guaranteed that
the relaunch is going to be performed using gateways (that's a feature).
"""
targets = self.gwtargets[previous_gateway].copy()
targets = NodeSet.fromlist(self.gwtargets[previous_gateway])
self.logger.debug("_relaunch on targets %s from previous_gateway %s",
targets, previous_gateway)

for target in targets:
self.gwtargets[previous_gateway].remove(target)
self.gwtargets[previous_gateway].difference_update(targets)

self._check_fini(previous_gateway)
self._target_count -= len(targets)
Expand Down
25 changes: 25 additions & 0 deletions tests/CLIClushTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,3 +880,28 @@ def test_301_fifo_stdin(self):
s = "%s: ok\n" % HOSTNAME
self._clush_t(["-w", HOSTNAME, "-v", "echo ok"], None,
s.encode(), 0, b"")


class CLIClushTest_E_Topology(unittest.TestCase):
"""Unit test class for testing CLI/Clush.py with --topology"""

def setUp(self):
self.topofile = make_temp_file(dedent("""
[Main]
%s: localhost
localhost: remote-node"""% HOSTNAME).encode())

def tearDown(self):
self.topofile = None

def _clush_t(self, args, stdin, expected_stdout, expected_rc=0,
expected_stderr=None):
CLI_main(self, main, ['clush'] + args, stdin, expected_stdout,
expected_rc, expected_stderr)

@unittest.skipIf(HOSTNAME == 'localhost', "does not work with hostname set to 'localhost'")
def test_300_topology(self):
"""test clush --topology"""
# GH#560: to detect set!=NodeSet for gwtargets
self._clush_t(["--topology", self.topofile.name,
"-w", "remote-node", "-b", "-v", "sleep 1; echo ok"], None, b"", 0, b"")
Loading