forked from pool/python-parallax
Accepting request 1006552 from home:nicholasyang:branches:devel:languages:python
- Dev: add parallax.run() to return non-zero rc without raising exceptions Add patch 0005-Dev-add-parallax.run-to-return-non-zero-rc-without-r.patch - Fix: Error: inherit from Exception instead of BaseExceptin Add patch 0004-Fix-Error-inherit-from-Exception-instead-of-BaseExce.patch OBS-URL: https://build.opensuse.org/request/show/1006552 OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-parallax?expand=0&rev=41
This commit is contained in:
committed by
Git OBS Bridge
parent
3f4d3122fd
commit
86165fbdba
@@ -0,0 +1,34 @@
|
||||
From 31024ba3eafebbf73b188b6a102c4d8f00669705 Mon Sep 17 00:00:00 2001
|
||||
From: nicholasyang <nicholas.yang@suse.com>
|
||||
Date: Tue, 27 Sep 2022 12:08:17 +0800
|
||||
Subject: [PATCH 4/5] Fix: Error: inherit from Exception instead of
|
||||
BaseExceptin
|
||||
|
||||
---
|
||||
parallax/__init__.py | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/parallax/__init__.py b/parallax/__init__.py
|
||||
index aa6ebd9..209c6f7 100644
|
||||
--- a/parallax/__init__.py
|
||||
+++ b/parallax/__init__.py
|
||||
@@ -55,14 +55,14 @@ def to_ascii(s):
|
||||
return s
|
||||
|
||||
|
||||
-class Error(BaseException):
|
||||
+class Error(Exception):
|
||||
"""
|
||||
Returned instead of a result for a host
|
||||
in case of an error during the processing for
|
||||
that host.
|
||||
"""
|
||||
def __init__(self, msg, task):
|
||||
- super(BaseException, self).__init__()
|
||||
+ super(Exception, self).__init__()
|
||||
self.msg = msg
|
||||
self.task = task
|
||||
|
||||
--
|
||||
2.37.3
|
||||
|
||||
115
0005-Dev-add-parallax.run-to-return-non-zero-rc-without-r.patch
Normal file
115
0005-Dev-add-parallax.run-to-return-non-zero-rc-without-r.patch
Normal file
@@ -0,0 +1,115 @@
|
||||
From 38bac0eb3cb20e9df8cbbf585cf9353793ffdba2 Mon Sep 17 00:00:00 2001
|
||||
From: nicholasyang <nicholas.yang@suse.com>
|
||||
Date: Tue, 27 Sep 2022 12:08:17 +0800
|
||||
Subject: [PATCH 5/5] Dev: add parallax.run() to return non-zero rc without
|
||||
raising exceptions
|
||||
|
||||
---
|
||||
README.md | 15 ++++++++---
|
||||
parallax/__init__.py | 60 +++++++++++++++++++++++++++++++++++++++++++-
|
||||
2 files changed, 70 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/README.md b/README.md
|
||||
index beb5620..268f6db 100644
|
||||
--- a/README.md
|
||||
+++ b/README.md
|
||||
@@ -32,10 +32,17 @@ Share and enjoy!
|
||||
|
||||
Executes the given command on a set of hosts, collecting the output.
|
||||
|
||||
- Returns a dict mapping the hostname of
|
||||
- each host either to a tuple containing a return code,
|
||||
- stdout and stderr, or an `parallax.Error` instance
|
||||
- describing the error.
|
||||
+ Returns a dict mapping the hostname of each host either to a tuple containing
|
||||
+ a return code, stdout and stderr when return code is 0, or an `parallax.Error`
|
||||
+ instance describing the error when return code is not 0.
|
||||
+
|
||||
+* `parallax.run(hosts, cmdline, opts)`
|
||||
+
|
||||
+ Executes the given command on a set of hosts, collecting the output.
|
||||
+
|
||||
+ Returns a dict mapping the hostname of each host either to a tuple containing
|
||||
+ a return code, stdout and stderr, or an `parallax.Error` instance describing
|
||||
+ the error when ssh error occurred.
|
||||
|
||||
* `parallax.copy(hosts, src, dst, opts)`
|
||||
|
||||
diff --git a/parallax/__init__.py b/parallax/__init__.py
|
||||
index 209c6f7..a3dc75e 100644
|
||||
--- a/parallax/__init__.py
|
||||
+++ b/parallax/__init__.py
|
||||
@@ -162,7 +162,7 @@ def _build_call_cmd(host, port, user, cmdline, opts):
|
||||
|
||||
def call(hosts, cmdline, opts=Options()):
|
||||
"""
|
||||
- Executes the given command on a set of hosts, collecting the output
|
||||
+ Executes the given command on a set of hosts, collecting the output. Return Error when exit status != 0.
|
||||
Returns {host: (rc, stdout, stdin) | Error}
|
||||
"""
|
||||
if opts.outdir and not os.path.exists(opts.outdir):
|
||||
@@ -384,3 +384,61 @@ def is_local_host(host):
|
||||
except:
|
||||
hostname = host
|
||||
return hostname == socket.gethostname()
|
||||
+
|
||||
+def run(hosts, cmdline, opts=Options()):
|
||||
+ """
|
||||
+ Executes the given command on a set of hosts, collecting the output. Return Error when ssh error occurred.
|
||||
+ Returns {host: (rc, stdout, stdin) | Error}
|
||||
+ """
|
||||
+ if opts.outdir and not os.path.exists(opts.outdir):
|
||||
+ os.makedirs(opts.outdir)
|
||||
+ if opts.errdir and not os.path.exists(opts.errdir):
|
||||
+ os.makedirs(opts.errdir)
|
||||
+ manager = Manager(limit=opts.limit,
|
||||
+ timeout=opts.timeout,
|
||||
+ askpass=opts.askpass,
|
||||
+ outdir=opts.outdir,
|
||||
+ errdir=opts.errdir,
|
||||
+ warn_message=opts.warn_message,
|
||||
+ callbacks=_RunOutputBuilder())
|
||||
+ for host, port, user in _expand_host_port_user(hosts):
|
||||
+ is_local = is_local_host(host)
|
||||
+ if is_local:
|
||||
+ cmd = [cmdline]
|
||||
+ else:
|
||||
+ cmd = _build_call_cmd(host, port, user, cmdline, opts)
|
||||
+ t = Task(host, port, user, cmd,
|
||||
+ stdin=opts.input_stream,
|
||||
+ verbose=opts.verbose,
|
||||
+ quiet=opts.quiet,
|
||||
+ print_out=opts.print_out,
|
||||
+ inline=opts.inline,
|
||||
+ inline_stdout=opts.inline_stdout,
|
||||
+ default_user=opts.default_user,
|
||||
+ is_local=is_local)
|
||||
+ manager.add_task(t)
|
||||
+ try:
|
||||
+ return manager.run()
|
||||
+ except FatalError as err:
|
||||
+ raise IOError(str(err))
|
||||
+
|
||||
+
|
||||
+class _RunOutputBuilder(object):
|
||||
+ def __init__(self):
|
||||
+ self.finished_tasks = []
|
||||
+
|
||||
+ def finished(self, task, n):
|
||||
+ """Called when Task is complete"""
|
||||
+ self.finished_tasks.append(task)
|
||||
+
|
||||
+ def result(self, manager):
|
||||
+ """Called when all Tasks are complete to generate result"""
|
||||
+ ret = {}
|
||||
+ for task in self.finished_tasks:
|
||||
+ if task.exitstatus == 255:
|
||||
+ ret[task.host] = Error(', '.join(task.failures), task)
|
||||
+ else:
|
||||
+ ret[task.host] = (task.exitstatus,
|
||||
+ task.outputbuffer or manager.outdir,
|
||||
+ task.errorbuffer or manager.errdir)
|
||||
+ return ret
|
||||
--
|
||||
2.37.3
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
-------------------------------------------------------------------
|
||||
Wed Sep 28 02:34:51 UTC 2022 - Nicholas Yang <nicholas.yang@suse.com>
|
||||
|
||||
- Dev: add parallax.run() to return non-zero rc without raising exceptions
|
||||
Add patch 0005-Dev-add-parallax.run-to-return-non-zero-rc-without-r.patch
|
||||
- Fix: Error: inherit from Exception instead of BaseExceptin
|
||||
Add patch 0004-Fix-Error-inherit-from-Exception-instead-of-BaseExce.patch
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Thu Jul 28 01:42:06 UTC 2022 - XinLiang <XLiang@suse.com>
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ Source: https://files.pythonhosted.org/packages/source/p/parallax/parall
|
||||
Patch1: 0001-Add-ssh_key-option-used-by-i-option-of-ssh-scp.patch
|
||||
Patch2: 0002-Change-format-of-scp-command-for-ipv6-compatible.patch
|
||||
Patch3: 0003-Fix-task-Don-t-use-ssh-if-command-running-on-local-b.patch
|
||||
Patch4: 0004-Fix-Error-inherit-from-Exception-instead-of-BaseExce.patch
|
||||
Patch5: 0005-Dev-add-parallax.run-to-return-non-zero-rc-without-r.patch
|
||||
|
||||
BuildRequires: %{python_module setuptools}
|
||||
BuildRequires: fdupes
|
||||
@@ -55,6 +57,8 @@ multiple nodes using SCP.
|
||||
%patch1 -p1
|
||||
%patch2 -p1
|
||||
%patch3 -p1
|
||||
%patch4 -p1
|
||||
%patch5 -p1
|
||||
|
||||
%build
|
||||
%python_build
|
||||
|
||||
Reference in New Issue
Block a user