jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/375769 )
Change subject: Transports: better handling of empty list ...................................................................... Transports: better handling of empty list * BaseWorker: accept an empty list in the command setter. It's its default value, there is no point in forbidding a client to set it to the same value. * ClusterShellWorker: return immediately if there are no target hosts. Bug: T174911 Change-Id: I0d2bec28dd8381104fd56f22194dbeffb8b30570 --- M cumin/tests/unit/transports/test_clustershell.py M cumin/tests/unit/transports/test_init.py M cumin/transports/__init__.py M cumin/transports/clustershell.py 4 files changed, 18 insertions(+), 4 deletions(-) Approvals: jenkins-bot: Verified Gehel: Looks good to me, but someone else must approve Volans: Looks good to me, approved diff --git a/cumin/tests/unit/transports/test_clustershell.py b/cumin/tests/unit/transports/test_clustershell.py index 39c6112..5f770ad 100644 --- a/cumin/tests/unit/transports/test_clustershell.py +++ b/cumin/tests/unit/transports/test_clustershell.py @@ -95,9 +95,10 @@ assert kwargs['handler'] == self.worker._handler_instance def test_execute_no_commands(self): - """Calling execute() without commands should raise WorkerError.""" - with pytest.raises(WorkerError, match=r'commands must be a non-empty list'): - self.worker.commands = [] + """Calling execute() without commands should return immediately.""" + self.worker.handler = ConcreteBaseEventHandler + self.worker.commands = None + assert self.worker.execute() is None assert not self.worker.task.shell.called def test_execute_one_command_no_mode(self): @@ -106,6 +107,13 @@ with pytest.raises(RuntimeError, match=r'An EventHandler is mandatory\.'): self.worker.execute() + def test_execute_no_target_hosts(self): + """Calling execute() with a target without hosts should return immediately.""" + self.target.hosts = [] + self.worker.handler = ConcreteBaseEventHandler + assert self.worker.execute() is None + assert not self.worker.task.shell.called + def test_execute_wrong_mode(self): """Calling execute() without setting the mode with multiple commands should raise RuntimeError.""" with pytest.raises(RuntimeError, match=r'An EventHandler is mandatory\.'): diff --git a/cumin/tests/unit/transports/test_init.py b/cumin/tests/unit/transports/test_init.py index 8f75535..c40dfdc 100644 --- a/cumin/tests/unit/transports/test_init.py +++ b/cumin/tests/unit/transports/test_init.py @@ -427,6 +427,8 @@ assert self.worker._commands == self.commands self.worker.commands = None assert self.worker._commands is None + self.worker.commands = [] + assert self.worker._commands == [] self.worker.commands = ['command1', 'command2'] assert self.worker._commands == self.commands diff --git a/cumin/transports/__init__.py b/cumin/transports/__init__.py index 50d3a15..a51347b 100644 --- a/cumin/transports/__init__.py +++ b/cumin/transports/__init__.py @@ -347,7 +347,7 @@ self._commands = value return - validate_list('commands', value) + validate_list('commands', value, allow_empty=True) commands = [] for command in value: if isinstance(command, Command): diff --git a/cumin/transports/clustershell.py b/cumin/transports/clustershell.py index c2b5c30..441d44c 100644 --- a/cumin/transports/clustershell.py +++ b/cumin/transports/clustershell.py @@ -38,6 +38,10 @@ self.logger.warning('No commands provided') return + if not self.target.hosts: + self.logger.warning('No target hosts provided') + return + if self.handler is None: raise RuntimeError('An EventHandler is mandatory.') -- To view, visit https://gerrit.wikimedia.org/r/375769 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I0d2bec28dd8381104fd56f22194dbeffb8b30570 Gerrit-PatchSet: 2 Gerrit-Project: operations/software/cumin Gerrit-Branch: master Gerrit-Owner: Volans <rcocci...@wikimedia.org> Gerrit-Reviewer: Faidon Liambotis <fai...@wikimedia.org> Gerrit-Reviewer: Gehel <guillaume.leder...@wikimedia.org> Gerrit-Reviewer: Giuseppe Lavagetto <glavage...@wikimedia.org> Gerrit-Reviewer: Muehlenhoff <mmuhlenh...@wikimedia.org> Gerrit-Reviewer: Volans <rcocci...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits