jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/373272 )
Change subject: Transports: fix target management improvement
......................................................................
Transports: fix target management improvement
Bug: T171684
Change-Id: If3f5cf8b76a8b5c042df69ef7603031d89265feb
---
M cumin/cli.py
M cumin/tests/unit/test_cli.py
M cumin/tests/unit/test_transport.py
M cumin/transport.py
4 files changed, 15 insertions(+), 12 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/cli.py b/cumin/cli.py
index 51e1b5c..148c948 100644
--- a/cumin/cli.py
+++ b/cumin/cli.py
@@ -238,7 +238,7 @@
args -- ArgumentParser instance with parsed command line arguments
config -- a dictionary with the parsed configuration file
"""
- hosts = query.Query(config, logger).execute(args.hosts)
+ hosts = query.Query(config, logger=logger).execute(args.hosts)
if not hosts:
stderr('No hosts found that matches the query')
@@ -313,8 +313,8 @@
if not hosts:
return 0
- worker = transport.Transport.new(config, logger)
- worker.target = transports.Target(hosts, batch_size=args.batch_size,
batch_sleep=args.batch_sleep, logger=logger)
+ target = transports.Target(hosts, batch_size=args.batch_size,
batch_sleep=args.batch_sleep, logger=logger)
+ worker = transport.Transport.new(config, target, logger=logger)
ok_codes = None
if args.ignore_exit_codes:
diff --git a/cumin/tests/unit/test_cli.py b/cumin/tests/unit/test_cli.py
index a24ab36..c839786 100644
--- a/cumin/tests/unit/test_cli.py
+++ b/cumin/tests/unit/test_cli.py
@@ -4,7 +4,7 @@
import mock
import pytest
-from cumin import cli, CuminError, LOGGING_TRACE_LEVEL_NUMBER
+from cumin import cli, CuminError, LOGGING_TRACE_LEVEL_NUMBER, transports
# Environment variables
_ENV = {'USER': 'root', 'SUDO_USER': 'user'}
@@ -198,5 +198,7 @@
args = cli.parse_args(argv=['--force', 'D{host1}', 'command1'])
config = {'backend': 'direct', 'transport': 'clustershell'}
cli.run(args, config)
- transport.new.assert_called_once_with(config, cli.logger)
+ assert transport.new.call_args[0][0] is config
+ assert isinstance(transport.new.call_args[0][1], transports.Target)
+ assert transport.new.call_args[1]['logger'] is cli.logger
assert stderr.called
diff --git a/cumin/tests/unit/test_transport.py
b/cumin/tests/unit/test_transport.py
index 16638c1..0b9f7d8 100644
--- a/cumin/tests/unit/test_transport.py
+++ b/cumin/tests/unit/test_transport.py
@@ -12,7 +12,7 @@
def test_invalid_transport():
"""Passing an invalid transport should raise RuntimeError."""
with pytest.raises(RuntimeError, match=r"ImportError\('No module named
non_existent_transport'"):
- Transport.new({'transport': 'non_existent_transport'})
+ Transport.new({'transport': 'non_existent_transport'},
transports.Target([]))
def test_missing_worker_class():
@@ -21,11 +21,11 @@
del module.worker_class
with mock.patch('importlib.import_module', lambda _: module):
with pytest.raises(RuntimeError,
match=r"AttributeError\('worker_class'"):
- Transport.new({'transport': 'invalid_transport'})
+ Transport.new({'transport': 'invalid_transport'},
transports.Target([]))
@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.BaseWorker)
+ assert isinstance(Transport.new({'transport': transport},
transports.Target([])), transports.BaseWorker)
diff --git a/cumin/transport.py b/cumin/transport.py
index 9ad8e66..32a8d2b 100644
--- a/cumin/transport.py
+++ b/cumin/transport.py
@@ -7,16 +7,17 @@
"""Transport factory class."""
@staticmethod
- def new(config, logger=None):
+ def new(config, target, logger=None):
"""Return an instance of the worker class for the configured transport.
Arguments:
- config - the configuration dictionary
- logger - an optional logging instance [optional, default: None]
+ config -- the configuration dictionary
+ target -- a Target instance
+ logger -- an optional logging instance [optional, default: None]
"""
try:
module =
importlib.import_module('cumin.transports.{transport}'.format(transport=config['transport']))
- return module.worker_class(config, logger)
+ return module.worker_class(config, target, logger=logger)
except (AttributeError, ImportError) as e:
raise RuntimeError("Unable to load worker class for transport
'{transport}': {msg}".format(
transport=config['transport'], msg=repr(e)))
--
To view, visit https://gerrit.wikimedia.org/r/373272
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If3f5cf8b76a8b5c042df69ef7603031d89265feb
Gerrit-PatchSet: 1
Gerrit-Project: operations/software/cumin
Gerrit-Branch: master
Gerrit-Owner: Volans <[email protected]>
Gerrit-Reviewer: Faidon Liambotis <[email protected]>
Gerrit-Reviewer: Gehel <[email protected]>
Gerrit-Reviewer: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: Volans <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits