From b92f65ece3cd38365bdfe11a82780913adee8ddb Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Sat, 10 Jul 2021 05:41:12 +0200 Subject: storyboard: Allow run_command on multiple nodes It can now take a list of node names. Also fixes sudo in ssh_support, which I accidentally broke in the previous commit. --- rumba/ssh_support.py | 2 +- rumba/storyboard.py | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) (limited to 'rumba') diff --git a/rumba/ssh_support.py b/rumba/ssh_support.py index e23a18e..06e7699 100644 --- a/rumba/ssh_support.py +++ b/rumba/ssh_support.py @@ -406,7 +406,7 @@ def aptitude_install(testbed, node, packages): return s else: def sudo(s): - return 'sudo' + s + return 'sudo ' + s package_install = " DEBIAN_FRONTEND=noninteractive apt-get install " for package in packages: diff --git a/rumba/storyboard.py b/rumba/storyboard.py index c6da6cb..6d9739c 100644 --- a/rumba/storyboard.py +++ b/rumba/storyboard.py @@ -729,25 +729,30 @@ class StoryBoard(_SBEntity): action = functools.partial(self.run_command, node, command) self._script.add_event(Event(action, ev_time=t)) - def run_command(self, node, command): + def run_command(self, nodes, command): """ - Runs a command (or several) on a given node, immediately. + Runs a command (or several) on a given (set of) node(s), immediately. - :param node: the node on which the command should be run - :type node: `rumba.model.Node` or `str` + :param nodes: the nodes on which the command should be run + :type nodes: `rumba.model.Node` or `str` or a list of these :param command: the command(s) to be run :type command: `str` or `list` of `str` """ if self.experiment is None: raise ValueError("Experiment needed to run commands.") - if isinstance(node, str): - node = self.node_map[node] - if node not in self.experiment.nodes: - raise ValueError('Cannot run command on node %s, ' - 'not in experiment.' % (node.name,)) - if isinstance(command, str): - command = [command] - node.execute_commands(command) + if not isinstance(nodes, list): + _nodes = [nodes] + else: + _nodes = nodes + for _node in _nodes: + if isinstance(_node, str): + _node = self.node_map[_node] + if _node not in self.experiment.nodes: + raise ValueError('Cannot run command on node %s, ' + 'not in experiment.' % (_node.name,)) + if isinstance(command, str): + command = [command] + _node.execute_commands(command) def add_event(self, event): """ -- cgit v1.2.3