Volans has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/366734 )
Change subject: CLI: simplify imports and introspection
......................................................................
CLI: simplify imports and introspection
Change-Id: I9747e64f5c3df42fc3017348de5ee5e15d4e96dd
---
M cumin/cli.py
M cumin/tests/unit/test_cli.py
2 files changed, 11 insertions(+), 13 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/software/cumin
refs/changes/34/366734/1
diff --git a/cumin/cli.py b/cumin/cli.py
index a318cbe..52d6c79 100644
--- a/cumin/cli.py
+++ b/cumin/cli.py
@@ -18,9 +18,8 @@
import cumin
-from cumin.query import QueryBuilder
-from cumin.transport import Transport
-from cumin.transports import Command
+from cumin import backends, query, transport, transports
+
logger = logging.getLogger(__name__) # pylint: disable=invalid-name
OUTPUT_FORMATS = ('txt', 'json')
@@ -63,9 +62,8 @@
async_mode = 'async'
# Get the list of existing backends and transports
- abs_path = os.path.dirname(os.path.abspath(__file__))
- backends = [name for _, name, _ in
pkgutil.iter_modules([os.path.join(abs_path, 'backends')])]
- transports = [name for _, name, _ in
pkgutil.iter_modules([os.path.join(abs_path, 'transports')])]
+ backends_names = [name for _, name, ispkg in
pkgutil.iter_modules(backends.__path__) if not ispkg]
+ transports_names = [name for _, name, ispkg in
pkgutil.iter_modules(transports.__path__) if not ispkg]
parser = argparse.ArgumentParser(
description='Cumin CLI - Automation and orchestration framework
written in Python',
@@ -99,11 +97,11 @@
parser.add_argument('-o', '--output', choices=OUTPUT_FORMATS,
help='Specify a different output format.')
parser.add_argument('--force', action='store_true',
help='USE WITH CAUTION! Force the execution without
confirmation of the affected hosts. ')
- parser.add_argument('--backend', choices=backends,
+ parser.add_argument('--backend', choices=backends_names,
help=('Override the default backend selected in the
configuration file for this execution. The '
'backend-specific configuration must be already
present in the configuration file. '
'[optional]'))
- parser.add_argument('--transport', choices=transports,
+ parser.add_argument('--transport', choices=transports_names,
help=('Override the default transport selected in the
configuration file for this execution. '
'The transport-specific configuration must
already be present in the configuration file. '
'[optional]'))
@@ -231,8 +229,8 @@
args -- ArgumentParser instance with parsed command line arguments
config -- a dictionary with the parsed configuration file
"""
- query = QueryBuilder(config, logger).build(args.hosts)
- hosts = query.execute()
+ backend_query = query.QueryBuilder(config, logger).build(args.hosts)
+ hosts = backend_query.execute()
if not hosts:
stderr('No hosts found that matches the query')
@@ -307,11 +305,11 @@
if not hosts:
return 0
- worker = Transport.new(config, logger)
+ worker = transport.Transport.new(config, logger)
worker.hosts = hosts
if args.timeout is not None:
- worker.commands = [Command(command, timeout=args.timeout) for command
in args.commands]
+ worker.commands = [transports.Command(command, timeout=args.timeout)
for command in args.commands]
else:
worker.commands = args.commands
diff --git a/cumin/tests/unit/test_cli.py b/cumin/tests/unit/test_cli.py
index d7606fd..fcee34d 100644
--- a/cumin/tests/unit/test_cli.py
+++ b/cumin/tests/unit/test_cli.py
@@ -187,7 +187,7 @@
assert stderr.called
[email protected]('cumin.cli.Transport')
[email protected]('cumin.cli.cumin.transport.Transport')
@mock.patch('cumin.cli.stderr')
def test_run(stderr, transport):
"""Calling run() should query the hosts and execute the commands on the
transport."""
--
To view, visit https://gerrit.wikimedia.org/r/366734
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9747e64f5c3df42fc3017348de5ee5e15d4e96dd
Gerrit-PatchSet: 1
Gerrit-Project: operations/software/cumin
Gerrit-Branch: master
Gerrit-Owner: Volans <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits