[MediaWiki-commits] [Gerrit] operations...cumin[master]: ClusterShell backend: fix execute() return code

2018-01-03 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/399829 )

Change subject: ClusterShell backend: fix execute() return code
..


ClusterShell backend: fix execute() return code

* The return code of the execute() method was not respecting the parent
  class contract for its return code when there are no commands set or
  no hosts to target.
* Breaking API change: make the Target class raise an WorkerError
  exception on instantiation if there are no target hosts.
* Breaking API change: make the execute() method raise a WorkerError
  exception if there are no commands to execute.

Change-Id: Idb59df41dac12d78803d560af3c22da9f1df4d1a
---
M cumin/tests/unit/test_transport.py
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
5 files changed, 25 insertions(+), 24 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/test_transport.py 
b/cumin/tests/unit/test_transport.py
index 52159b3..b821141 100644
--- a/cumin/tests/unit/test_transport.py
+++ b/cumin/tests/unit/test_transport.py
@@ -12,13 +12,13 @@
 def test_missing_transport():
 """Not passing a transport should raise CuminError."""
 with pytest.raises(CuminError, match=r"Missing required parameter 
'transport'"):
-Transport.new({}, transports.Target([]))
+Transport.new({}, transports.Target(['host1']))
 
 
 def test_invalid_transport():
 """Passing an invalid transport should raise CuminError."""
 with pytest.raises(ImportError, match=r'No module named 
non_existent_transport'):
-Transport.new({'transport': 'non_existent_transport'}, 
transports.Target([]))
+Transport.new({'transport': 'non_existent_transport'}, 
transports.Target(['host1']))
 
 
 def test_missing_worker_class():
@@ -27,11 +27,11 @@
 del module.worker_class
 with mock.patch('importlib.import_module', lambda _: module):
 with pytest.raises(AttributeError, match=r'worker_class'):
-Transport.new({'transport': 'invalid_transport'}, 
transports.Target([]))
+Transport.new({'transport': 'invalid_transport'}, 
transports.Target(['host1']))
 
 
 @pytest.mark.parametrize('transport', [name for _, name, ispkg in 
pkgutil.iter_modules(transports.__path__)
if not ispkg])
 def test_valid_transport(transport):
 """Passing a valid transport should return an instance of BaseWorker."""
-assert isinstance(Transport.new({'transport': transport}, 
transports.Target([])), transports.BaseWorker)
+assert isinstance(Transport.new({'transport': transport}, 
transports.Target(['host1'])), transports.BaseWorker)
diff --git a/cumin/tests/unit/transports/test_clustershell.py 
b/cumin/tests/unit/transports/test_clustershell.py
index ccaba3f..6387984 100644
--- a/cumin/tests/unit/transports/test_clustershell.py
+++ b/cumin/tests/unit/transports/test_clustershell.py
@@ -96,23 +96,18 @@
 assert kwargs['handler'] == self.worker._handler_instance
 
 def test_execute_no_commands(self):
-"""Calling execute() without commands should return immediately."""
+"""Calling execute() without commands should raise WorkerError."""
 self.worker.handler = ConcreteBaseEventHandler
 self.worker.commands = None
-assert self.worker.execute() is None
+with pytest.raises(WorkerError, match=r'No commands provided\.'):
+self.worker.execute()
 assert not self.worker.task.shell.called
 
 def test_execute_one_command_no_mode(self):
-"""Calling execute() with only one command without mode should raise 
CuminError."""
+"""Calling execute() with only one command without mode should raise 
WorkerError."""
 self.worker.commands = [self.commands[0]]
-with pytest.raises(CuminError, match=r'An EventHandler is 
mandatory\.'):
+with pytest.raises(WorkerError, 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):
diff --git a/cumin/tests/unit/transports/test_init.py 
b/cumin/tests/unit/transports/test_init.py
index c40dfdc..d326d0e 100644
--- a/cumin/tests/unit/transports/test_init.py
+++ b/cumin/tests/unit/transports/test_init.py
@@ -316,6 +316,11 @@
 self.hosts_list = ['host' + str(i) for i in xrange(10)]
 self.hosts = NodeSet.fromlist(self.hosts_list)
 
+def 

[MediaWiki-commits] [Gerrit] operations...cumin[master]: ClusterShell backend: fix execute() return code

2017-12-22 Thread Volans (Code Review)
Volans has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399829 )

Change subject: ClusterShell backend: fix execute() return code
..

ClusterShell backend: fix execute() return code

* The return code of the execute() method was not respecting the parent
  class contract for its return code when there are no commands set or
  no hosts to target.

Change-Id: Idb59df41dac12d78803d560af3c22da9f1df4d1a
---
M cumin/tests/unit/transports/test_clustershell.py
M cumin/transports/clustershell.py
2 files changed, 4 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/software/cumin 
refs/changes/29/399829/1

diff --git a/cumin/tests/unit/transports/test_clustershell.py 
b/cumin/tests/unit/transports/test_clustershell.py
index ccaba3f..5c32b0d 100644
--- a/cumin/tests/unit/transports/test_clustershell.py
+++ b/cumin/tests/unit/transports/test_clustershell.py
@@ -99,7 +99,7 @@
 """Calling execute() without commands should return immediately."""
 self.worker.handler = ConcreteBaseEventHandler
 self.worker.commands = None
-assert self.worker.execute() is None
+assert self.worker.execute() == 0
 assert not self.worker.task.shell.called
 
 def test_execute_one_command_no_mode(self):
@@ -112,7 +112,7 @@
 """Calling execute() with a target without hosts should return 
immediately."""
 self.target.hosts = []
 self.worker.handler = ConcreteBaseEventHandler
-assert self.worker.execute() is None
+assert self.worker.execute() == 0
 assert not self.worker.task.shell.called
 
 def test_execute_wrong_mode(self):
diff --git a/cumin/transports/clustershell.py b/cumin/transports/clustershell.py
index d5f20cf..bdc7252 100644
--- a/cumin/transports/clustershell.py
+++ b/cumin/transports/clustershell.py
@@ -57,11 +57,11 @@
 """
 if not self.commands:
 self.logger.warning('No commands provided')
-return
+return 0
 
 if not self.target.hosts:
 self.logger.warning('No target hosts provided')
-return
+return 0
 
 if self.handler is None:
 raise WorkerError('An EventHandler is mandatory.')

-- 
To view, visit https://gerrit.wikimedia.org/r/399829
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idb59df41dac12d78803d560af3c22da9f1df4d1a
Gerrit-PatchSet: 1
Gerrit-Project: operations/software/cumin
Gerrit-Branch: master
Gerrit-Owner: Volans 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits