SHA256
1
0
forked from pool/salt
salt/update-target-fix-for-salt-ssh-to-process-targets-li.patch
Yeray Gutiérrez Cedrés d52b2fc4b1 - Fix few failing tests to work with both Salt and Salt bundle
- Skip testing unsupported OpenSSL crypto algorithms
- Added:
  * make-tests-compatible-with-venv-bundle.patch
  * skip-more-tests-related-to-old-openssl-algorithms.patch

OBS-URL: https://build.opensuse.org/package/show/systemsmanagement:saltstack/salt?expand=0&rev=251
2024-08-07 10:08:58 +00:00

99 lines
3.8 KiB
Diff

From b6bf7e1cb3efedbb651b7d6c5f36b73d88cfa1c0 Mon Sep 17 00:00:00 2001
From: Victor Zhestkov <35733135+vzhestkov@users.noreply.github.com>
Date: Fri, 9 Apr 2021 16:01:32 +0300
Subject: [PATCH] Update target fix for salt-ssh to process targets list
(bsc#1179831) (#336)
* Update target fix for salt-ssh to process targets list (bsc#1179831)
* Improvement for fixing (bsc#1179831)
Regression fix of salt-ssh on processing targets (#353)
---
salt/client/ssh/__init__.py | 46 +++++++++++++++++++++++--------------
1 file changed, 29 insertions(+), 17 deletions(-)
diff --git a/salt/client/ssh/__init__.py b/salt/client/ssh/__init__.py
index 049baff51a..19089ce8ad 100644
--- a/salt/client/ssh/__init__.py
+++ b/salt/client/ssh/__init__.py
@@ -338,7 +338,7 @@ class SSH(MultiprocessingStateMixin):
if not self.opts.get("ssh_cli_tgt"):
self.opts["ssh_cli_tgt"] = self.opts.get("tgt", "")
hostname = self.opts.get("ssh_cli_tgt", "")
- if "@" in hostname:
+ if isinstance(hostname, str) and "@" in hostname:
user, hostname = hostname.split("@", 1)
else:
user = self.opts.get("ssh_user")
@@ -393,7 +393,7 @@ class SSH(MultiprocessingStateMixin):
self.__parsed_rosters[self.ROSTER_UPDATE_FLAG] = False
return
- def _update_roster(self):
+ def _update_roster(self, hostname=None, user=None):
"""
Update default flat roster with the passed in information.
:return:
@@ -407,8 +407,8 @@ class SSH(MultiprocessingStateMixin):
" host: {hostname}\n user: {user}\n passwd: {passwd}\n".format(
s_user=getpass.getuser(),
s_time=datetime.datetime.utcnow().isoformat(),
- hostname=self.opts.get("tgt", ""),
- user=self.opts.get("ssh_user", ""),
+ hostname=hostname if hostname else self.opts.get("tgt", ""),
+ user=user if user else self.opts.get("ssh_user", ""),
passwd=self.opts.get("ssh_passwd", ""),
)
)
@@ -425,20 +425,32 @@ class SSH(MultiprocessingStateMixin):
Uptade targets in case hostname was directly passed without the roster.
:return:
"""
- hostname = self.parse_tgt["hostname"]
+ hosts = self.parse_tgt["hostname"]
user = self.parse_tgt["user"]
- if hostname == "*":
- hostname = ""
-
- if salt.utils.network.is_reachable_host(hostname):
- self.opts["tgt"] = hostname
- self.targets[hostname] = {
- "passwd": self.opts.get("ssh_passwd", ""),
- "host": hostname,
- "user": user,
- }
- if self.opts.get("ssh_update_roster"):
- self._update_roster()
+
+ if not isinstance(hosts, (list, tuple)):
+ hosts = list([hosts])
+ _hosts = list()
+ for hostname in hosts:
+ _user = user
+ if "@" in hostname:
+ _user, hostname = hostname.split("@", 1)
+ if hostname == "*":
+ continue
+ if salt.utils.network.is_reachable_host(hostname):
+ _hosts.append(hostname)
+ self.targets[hostname] = {
+ "passwd": self.opts.get("ssh_passwd", ""),
+ "host": hostname,
+ "user": _user,
+ }
+ if self.opts.get("ssh_update_roster"):
+ self._update_roster(hostname=hostname, user=_user)
+
+ if self.tgt_type == "list":
+ self.opts["tgt"] = _hosts
+ elif _hosts:
+ self.opts["tgt"] = _hosts[0]
def get_pubkey(self):
"""
--
2.39.2