commit python-parallax for openSUSE:Factory
Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-parallax for openSUSE:Factory checked in at 2022-09-30 17:58:14 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-parallax (Old) and /work/SRC/openSUSE:Factory/.python-parallax.new.2275 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "python-parallax" Fri Sep 30 17:58:14 2022 rev:19 rq:1007131 version:1.0.6 Changes: -------- --- /work/SRC/openSUSE:Factory/python-parallax/python-parallax.changes 2022-07-28 20:59:26.931705108 +0200 +++ /work/SRC/openSUSE:Factory/.python-parallax.new.2275/python-parallax.changes 2022-09-30 17:58:31.773342896 +0200 @@ -1,0 +2,8 @@ +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 + +------------------------------------------------------------------- New: ---- 0004-Fix-Error-inherit-from-Exception-instead-of-BaseExce.patch 0005-Dev-add-parallax.run-to-return-non-zero-rc-without-r.patch ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-parallax.spec ++++++ --- /var/tmp/diff_new_pack.Q06HRN/_old 2022-09-30 17:58:32.257343931 +0200 +++ /var/tmp/diff_new_pack.Q06HRN/_new 2022-09-30 17:58:32.261343939 +0200 @@ -28,6 +28,8 @@ 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 @@ %patch1 -p1 %patch2 -p1 %patch3 -p1 +%patch4 -p1 +%patch5 -p1 %build %python_build ++++++ 0004-Fix-Error-inherit-from-Exception-instead-of-BaseExce.patch ++++++ 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 ++++++ 0005-Dev-add-parallax.run-to-return-non-zero-rc-without-r.patch ++++++ 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
participants (1)
-
Source-Sync