Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Step:FrontRunner
salt.28025
prevent-affection-of-ssh.opts-with-lazyloader-b...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File prevent-affection-of-ssh.opts-with-lazyloader-bsc-11.patch of Package salt.28025
From c86432645863a21da589346ad587b610ab51a2a9 Mon Sep 17 00:00:00 2001 From: Victor Zhestkov <vzhestkov@suse.com> Date: Tue, 12 Apr 2022 10:06:43 +0300 Subject: [PATCH] Prevent affection of SSH.opts with LazyLoader (bsc#1197637) * Prevent affection SSH.opts with LazyLoader * Restore parsed targets * Fix test_ssh unit tests --- salt/client/ssh/__init__.py | 19 +++++++++++-------- tests/unit/client/test_ssh.py | 16 ++++++++-------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/salt/client/ssh/__init__.py b/salt/client/ssh/__init__.py index bc77eb700e..6d24d8d716 100644 --- a/salt/client/ssh/__init__.py +++ b/salt/client/ssh/__init__.py @@ -225,15 +225,16 @@ class SSH: ROSTER_UPDATE_FLAG = "#__needs_update" def __init__(self, opts, context=None): + self.opts = copy.deepcopy(opts) + self.sopts = copy.deepcopy(self.opts) self.__parsed_rosters = {SSH.ROSTER_UPDATE_FLAG: True} - pull_sock = os.path.join(opts["sock_dir"], "master_event_pull.ipc") + pull_sock = os.path.join(self.opts["sock_dir"], "master_event_pull.ipc") if os.path.exists(pull_sock) and zmq: self.event = salt.utils.event.get_event( - "master", opts["sock_dir"], opts["transport"], opts=opts, listen=False + "master", self.opts["sock_dir"], self.opts["transport"], opts=self.opts, listen=False ) else: self.event = None - self.opts = opts if self.opts["regen_thin"]: self.opts["ssh_wipe"] = True if not salt.utils.path.which("ssh"): @@ -244,7 +245,7 @@ class SSH: " to run. Exiting." ), ) - self.opts["_ssh_version"] = ssh_version() + self.sopts["_ssh_version"] = ssh_version() self.tgt_type = ( self.opts["selected_target_option"] if self.opts["selected_target_option"] @@ -341,6 +342,9 @@ class SSH: self.opts["cachedir"], "salt-ssh.session.lock" ) self.ssh_session_grace_time = int(self.opts.get("ssh_session_grace_time", 1)) + self.sopts["tgt"] = copy.deepcopy(self.opts["tgt"]) + self.sopts["ssh_cli_tgt"] = copy.deepcopy(self.opts["ssh_cli_tgt"]) + self.opts = self.sopts @property def parse_tgt(self): @@ -594,7 +598,6 @@ class SSH: Spin up the needed threads or processes and execute the subsequent routines """ - opts = copy.deepcopy(self.opts) que = multiprocessing.Queue() running = {} targets_queue = deque(self.targets.keys()) @@ -605,7 +608,7 @@ class SSH: if not self.targets: log.error("No matching targets found in roster.") break - if len(running) < opts.get("ssh_max_procs", 25) and not init: + if len(running) < self.opts.get("ssh_max_procs", 25) and not init: if targets_queue: host = targets_queue.popleft() else: @@ -669,7 +672,7 @@ class SSH: continue args = ( que, - opts, + self.opts, host, self.targets[host], mine, @@ -763,7 +766,7 @@ class SSH: if len(rets) >= len(self.targets): break # Sleep when limit or all threads started - if len(running) >= opts.get("ssh_max_procs", 25) or len( + if len(running) >= self.opts.get("ssh_max_procs", 25) or len( self.targets ) >= len(running): time.sleep(0.1) diff --git a/tests/unit/client/test_ssh.py b/tests/unit/client/test_ssh.py index 23cb3d0700..5003500de1 100644 --- a/tests/unit/client/test_ssh.py +++ b/tests/unit/client/test_ssh.py @@ -95,7 +95,7 @@ class SSHReturnEventTests(ShellCase): assert "localhost" in ret assert "fun" in ret["localhost"] client.run() - display_output.assert_called_once_with(expected, "nested", opts) + display_output.assert_called_once_with(expected, "nested", client.opts) self.assertIs(ret, handle_ssh_ret[0]) assert len(client.event.fire_event.call_args_list) == 2 assert "fun" in client.event.fire_event.call_args_list[0][0][0] @@ -539,7 +539,7 @@ class SSHTests(ShellCase): MagicMock(return_value=salt.utils.yaml.safe_load(self.roster)), ): client._expand_target() - assert opts["tgt"] == host + assert client.opts["tgt"] == host def test_expand_target_dns(self): """ @@ -562,7 +562,7 @@ class SSHTests(ShellCase): MagicMock(return_value=salt.utils.yaml.safe_load(self.roster)), ): client._expand_target() - assert opts["tgt"] == host + assert client.opts["tgt"] == host def test_expand_target_no_user(self): """ @@ -602,7 +602,7 @@ class SSHTests(ShellCase): client = ssh.SSH(opts) assert opts["tgt"] == user + host client._update_targets() - assert opts["tgt"] == host + assert client.opts["tgt"] == host assert client.targets[host]["user"] == user.split("@")[0] def test_update_targets_dns(self): @@ -620,7 +620,7 @@ class SSHTests(ShellCase): client = ssh.SSH(opts) assert opts["tgt"] == user + host client._update_targets() - assert opts["tgt"] == host + assert client.opts["tgt"] == host assert client.targets[host]["user"] == user.split("@")[0] def test_update_targets_no_user(self): @@ -661,7 +661,7 @@ class SSHTests(ShellCase): ): client._expand_target() client._update_targets() - assert opts["tgt"] == host + assert client.opts["tgt"] == host assert client.targets[host]["user"] == user.split("@")[0] def test_parse_tgt(self): @@ -681,7 +681,7 @@ class SSHTests(ShellCase): client = ssh.SSH(opts) assert client.parse_tgt["hostname"] == host assert client.parse_tgt["user"] == user.split("@")[0] - assert self.opts.get("ssh_cli_tgt") == user + host + assert client.opts.get("ssh_cli_tgt") == user + host def test_parse_tgt_no_user(self): """ @@ -700,7 +700,7 @@ class SSHTests(ShellCase): client = ssh.SSH(opts) assert client.parse_tgt["hostname"] == host assert client.parse_tgt["user"] == opts["ssh_user"] - assert self.opts.get("ssh_cli_tgt") == host + assert client.opts.get("ssh_cli_tgt") == host def test_extra_filerefs(self): """ -- 2.35.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor