Skip to content

Tree: Allow alternate Local Workers in Tree Mode #439

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 1 commit into from
Jul 29, 2020
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
5 changes: 5 additions & 0 deletions lib/ClusterShell/Gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ def recv_ctl(self, msg):
task._info.update(taskinfo)
task.set_info('print_debug', _gw_print_debug)

for infokey in taskinfo:
if infokey.startswith('tree_default:'):
self.logger.debug('Setting default %s to %s', infokey[13:], taskinfo[infokey])
task.set_default(infokey[13:], taskinfo[infokey])

if task.info('debug'):
self.logger.setLevel(logging.DEBUG)

Expand Down
8 changes: 7 additions & 1 deletion lib/ClusterShell/Task.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
basestring = str

from ClusterShell.Defaults import config_paths, DEFAULTS
from ClusterShell.Defaults import _local_workerclass, _distant_workerclass
from ClusterShell.Defaults import _local_workerclass, _distant_workerclass, _load_workerclass
from ClusterShell.Engine.Engine import EngineAbortException
from ClusterShell.Engine.Engine import EngineTimeoutException
from ClusterShell.Engine.Engine import EngineAlreadyRunningError
Expand Down Expand Up @@ -470,6 +470,10 @@ def set_default(self, default_key, value):
self._default_lock.acquire()
try:
self._default[default_key] = value
if default_key == 'local_workername':
self._default['local_worker'] = _load_workerclass(value)
elif default_key == 'distant_workername':
self._default['distant_worker'] = _load_workerclass(value)
finally:
self._default_lock.release()

Expand Down Expand Up @@ -510,6 +514,8 @@ def set_info(self, info_key, value):
- "command_timeout": Time in seconds to wait for a command to
complete before aborting (default: 0, which means
unlimited).
- "tree_default:<key>": In tree mode, overrides the key <key>
in Defaults (settings normally set in defaults.conf)

Threading considerations
========================
Expand Down
11 changes: 6 additions & 5 deletions lib/ClusterShell/Worker/Tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,12 @@ def _launch(self, nodes):
tree=False)
else:
assert self.source is None
worker = ExecWorker(nodes=targets,
command=self.command,
handler=self.metahandler,
timeout=self.timeout,
stderr=self.stderr)
workerclass = self.task.default('local_worker')
worker = workerclass(nodes=targets,
command=self.command,
handler=self.metahandler,
timeout=self.timeout,
stderr=self.stderr)
self.task.schedule(worker)

self.workers.append(worker)
Expand Down
16 changes: 16 additions & 0 deletions tests/TreeWorkerTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ def test_tree_run_noremote(self):
self.assertEqual(teh.ev_close_cnt, 1)
self.assertEqual(teh.last_read, NODE_DISTANT.encode('ascii'))

def test_tree_run_noremote_alt_localworker(self):
"""test tree run with remote=False and a non-exec localworker"""
teh = TEventHandler()
self.task.set_info('tree_default:local_workername', 'ssh')
self.task.run('echo %h', nodes=NODE_DISTANT, handler=teh, remote=False)
self.assertEqual(teh.ev_start_cnt, 1)
self.assertEqual(teh.ev_pickup_cnt, 1)
self.assertEqual(teh.ev_read_cnt, 1)
self.assertEqual(teh.ev_written_cnt, 0)
self.assertEqual(teh.ev_hup_cnt, 1)
self.assertEqual(teh.ev_timedout_cnt, 0)
self.assertEqual(teh.ev_close_cnt, 1)
# The exec worker will expand %h to the host, but ssh will just echo '%h'
self.assertEqual(teh.last_read, '%h'.encode('ascii'))
del self.task._info['tree_default:local_workername']

def test_tree_run_direct(self):
"""test tree run with direct target, in topology"""
teh = TEventHandler()
Expand Down