forked from pool/python-parallax
Accepting request 991454 from home:XinLiang:branches:devel:languages:python
- Don't use ssh if command running on local (bsc#1200833) Add patch 0003-Fix-task-Don-t-use-ssh-if-command-running-on-local-b.patch OBS-URL: https://build.opensuse.org/request/show/991454 OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-parallax?expand=0&rev=39
This commit is contained in:
100
0003-Fix-task-Don-t-use-ssh-if-command-running-on-local-b.patch
Normal file
100
0003-Fix-task-Don-t-use-ssh-if-command-running-on-local-b.patch
Normal file
@@ -0,0 +1,100 @@
|
||||
From 22cd571ceb360c66279512af3690347e1d6a768d Mon Sep 17 00:00:00 2001
|
||||
From: liangxin1300 <XLiang@suse.com>
|
||||
Date: Tue, 12 Jul 2022 10:06:06 +0800
|
||||
Subject: [PATCH] Fix: task: Don't use ssh if command running on local
|
||||
(bsc#1200833)
|
||||
|
||||
** Problem
|
||||
When a command is running on local, it will failed if local ssh service stopped
|
||||
** Solution
|
||||
Run this command directly, without ssh
|
||||
---
|
||||
parallax/__init__.py | 22 ++++++++++++++++++++--
|
||||
parallax/task.py | 6 ++++--
|
||||
2 files changed, 24 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/parallax/__init__.py b/parallax/__init__.py
|
||||
index 50a2268..aa6ebd9 100644
|
||||
--- a/parallax/__init__.py
|
||||
+++ b/parallax/__init__.py
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
+import socket
|
||||
|
||||
DEFAULT_PARALLELISM = 32
|
||||
DEFAULT_TIMEOUT = 0 # "infinity" by default
|
||||
@@ -176,7 +177,11 @@ def call(hosts, cmdline, opts=Options()):
|
||||
warn_message=opts.warn_message,
|
||||
callbacks=_CallOutputBuilder())
|
||||
for host, port, user in _expand_host_port_user(hosts):
|
||||
- cmd = _build_call_cmd(host, port, user, cmdline, opts)
|
||||
+ 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,
|
||||
@@ -184,7 +189,8 @@ def call(hosts, cmdline, opts=Options()):
|
||||
print_out=opts.print_out,
|
||||
inline=opts.inline,
|
||||
inline_stdout=opts.inline_stdout,
|
||||
- default_user=opts.default_user)
|
||||
+ default_user=opts.default_user,
|
||||
+ is_local=is_local)
|
||||
manager.add_task(t)
|
||||
try:
|
||||
return manager.run()
|
||||
@@ -366,3 +372,15 @@ def slurp(hosts, src, dst, opts=Options()):
|
||||
return manager.run()
|
||||
except FatalError as err:
|
||||
raise IOError(str(err))
|
||||
+
|
||||
+
|
||||
+def is_local_host(host):
|
||||
+ """
|
||||
+ Check if the host is local
|
||||
+ """
|
||||
+ try:
|
||||
+ socket.inet_aton(host)
|
||||
+ hostname = socket.gethostbyaddr(host)[0]
|
||||
+ except:
|
||||
+ hostname = host
|
||||
+ return hostname == socket.gethostname()
|
||||
diff --git a/parallax/task.py b/parallax/task.py
|
||||
index 5e05f30..5307b06 100644
|
||||
--- a/parallax/task.py
|
||||
+++ b/parallax/task.py
|
||||
@@ -39,7 +39,8 @@ class Task(object):
|
||||
print_out=False,
|
||||
inline=False,
|
||||
inline_stdout=False,
|
||||
- default_user=None):
|
||||
+ default_user=None,
|
||||
+ is_local=False):
|
||||
|
||||
# Backwards compatibility:
|
||||
if not isinstance(verbose, bool):
|
||||
@@ -66,6 +67,7 @@ class Task(object):
|
||||
self.pretty_host = host
|
||||
self.port = port
|
||||
self.cmd = cmd
|
||||
+ self.is_local = is_local
|
||||
|
||||
if user and user != default_user:
|
||||
self.pretty_host = '@'.join((user, self.pretty_host))
|
||||
@@ -126,7 +128,7 @@ class Task(object):
|
||||
close_fds=False, preexec_fn=os.setsid, env=environ)
|
||||
else:
|
||||
self.proc = Popen(self.cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
|
||||
- close_fds=False, start_new_session=True, env=environ)
|
||||
+ close_fds=False, start_new_session=True, env=environ, shell=self.is_local)
|
||||
|
||||
self.timestamp = time.time()
|
||||
if self.inputbuffer:
|
||||
--
|
||||
2.34.1
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
-------------------------------------------------------------------
|
||||
Thu Jul 28 01:42:06 UTC 2022 - XinLiang <XLiang@suse.com>
|
||||
|
||||
- Don't use ssh if command running on local (bsc#1200833)
|
||||
Add patch 0003-Fix-task-Don-t-use-ssh-if-command-running-on-local-b.patch
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Wed Aug 5 07:43:16 UTC 2020 - XinLiang <XLiang@suse.com>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# spec file for package python-parallax
|
||||
#
|
||||
# Copyright (c) 2020 SUSE LLC
|
||||
# Copyright (c) 2022 SUSE LLC
|
||||
#
|
||||
# All modifications and additions to the file contributed by third parties
|
||||
# remain the property of their copyright owners, unless otherwise agreed
|
||||
@@ -27,6 +27,7 @@ URL: https://github.com/krig/parallax/
|
||||
Source: https://files.pythonhosted.org/packages/source/p/parallax/parallax-%{version}.tar.gz
|
||||
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
|
||||
|
||||
BuildRequires: %{python_module setuptools}
|
||||
BuildRequires: fdupes
|
||||
@@ -37,10 +38,10 @@ Requires: openssh
|
||||
BuildArch: noarch
|
||||
%if 0%{?suse_version}
|
||||
Requires(post): update-alternatives
|
||||
Requires(postun): update-alternatives
|
||||
Requires(postun):update-alternatives
|
||||
%else
|
||||
Requires(post): %{_sbindir}/update-alternatives
|
||||
Requires(postun): %{_sbindir}/update-alternatives
|
||||
Requires(postun):%{_sbindir}/update-alternatives
|
||||
%endif
|
||||
%python_subpackages
|
||||
|
||||
@@ -53,6 +54,7 @@ multiple nodes using SCP.
|
||||
%setup -q -n parallax-%{version}
|
||||
%patch1 -p1
|
||||
%patch2 -p1
|
||||
%patch3 -p1
|
||||
|
||||
%build
|
||||
%python_build
|
||||
|
||||
Reference in New Issue
Block a user