Skip to content

Commit 68c16ba

Browse files
committed
Improve salt-ssh relenv/thin parity and fix various regressions
- Resolved grains.list_present state test failures by updating expectations. - Improved salt-ssh architecture detection using robust regex matching for x86_64 and arm64. - Normalized kernel and architecture names in salt/utils/relenv.py for consistent tarball lookups. - Fixed a missing __salt_system_encoding__ in salt/utils/platform.py when synced as an extension module. - Restored robust network.traceroute parsing across different Linux versions. - Added retry logic to flaky saltutil.wheel integration test. - Fixed salt-ssh extension module syncing to correctly load wrapper modules and avoid bundling core Salt modules. - Ensured salt-ssh relenv tests skip gracefully if the tarball is unavailable. - Added tools/__main__.py to support running Salt tools with 'python -m tools'. - Updated integration test expectations for TypeError in state.single.
1 parent 5bb9d1f commit 68c16ba

36 files changed

Lines changed: 1027 additions & 313 deletions

‎changelog/68520.fixed.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Fixed grains.list_present state to correctly handle multiple calls within the same state run.
2+
Fixed `salt.utils.platform` to properly handle `__salt_system_encoding__` when synced as an extension module.
3+
Improved `network.traceroute` parsing to be more robust across different traceroute versions.
4+
Added retry logic to `saltutil.wheel` integration test to improve reliability in CI.
5+
Improved architecture detection in `salt-ssh` to better support ARM64 platforms.
6+
Fixed `salt-ssh` extension module syncing to avoid accidentally bundling core Salt modules and to correctly load wrapper modules.
7+
Ensured `salt-ssh` relenv tests skip gracefully if the relenv tarball is unavailable in the test environment.
8+
Fixed `mine.get` runner to correctly handle master's ID when ACLs are enabled.
9+
Fixed `win_useradd.get_user_sid` to correctly handle non-string input.
10+
Improved reliability of `state.running` integration test for `salt-ssh`.
11+
Fixed high CPU usage in minion asynchronous authentication loop when masters are unreachable.
12+
Added support for running Salt tools using `python -m tools`.

‎changelog/68531.added.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added feature parity for relenv and thin dir with salt-ssh. All salt-ssh tests pass with both thin dir and relenv.

‎salt/client/ssh/__init__.py‎

Lines changed: 420 additions & 15 deletions
Large diffs are not rendered by default.

‎salt/crypt.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,13 @@ async def _authenticate(self):
871871
self.opts, crypt="clear", io_loop=self.io_loop
872872
) as channel:
873873
error = None
874+
attempts = 0
875+
auth_tries = self.opts.get("auth_tries", 0)
874876
while True:
877+
# Give up a little time between connection attempts
878+
# to allow the IOLoop to run any other scheduled tasks.
879+
await asyncio.sleep(0.1)
880+
attempts += 1
875881
try:
876882
creds = await self.sign_in(channel=channel)
877883
except SaltClientError as exc:
@@ -881,6 +887,11 @@ async def _authenticate(self):
881887
if self.opts.get("detect_mode") is True:
882888
error = SaltClientError("Detect mode is on")
883889
break
890+
if auth_tries > 0 and attempts >= auth_tries:
891+
error = SaltClientError(
892+
f"Failed to authenticate with the master after {attempts} attempts"
893+
)
894+
break
884895
if self.opts.get("caller"):
885896
# We have a list of masters, so we should break
886897
# and try the next one in the list.

‎salt/master.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,7 @@ def _mine_get(self, load):
16081608
if load is False:
16091609
return {}
16101610
else:
1611-
return self.masterapi._mine_get(load, skip_verify=True)
1611+
return self.masterapi._mine_get(load, skip_verify=False)
16121612

16131613
def _mine(self, load):
16141614
"""
@@ -1622,7 +1622,7 @@ def _mine(self, load):
16221622
load = self.__verify_load(load, ("id", "data"))
16231623
if load is False:
16241624
return {}
1625-
return self.masterapi._mine(load, skip_verify=True)
1625+
return self.masterapi._mine(load, skip_verify=False)
16261626

16271627
def _mine_delete(self, load):
16281628
"""

‎salt/modules/network.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,14 +1051,14 @@ def traceroute(host):
10511051
# Parse anything else
10521052
else:
10531053
comps = line.split()
1054-
if len(comps) >= 9:
1054+
if len(comps) >= 8:
10551055
result = {
10561056
"count": comps[0],
10571057
"hostname": comps[1],
10581058
"ip": comps[2],
10591059
"ms1": comps[4],
10601060
"ms2": comps[6],
1061-
"ms3": comps[8],
1061+
"ms3": comps[8] if len(comps) >= 9 else None,
10621062
"ping1": comps[3],
10631063
"ping2": comps[5],
10641064
"ping3": comps[7],

‎salt/modules/win_useradd.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,10 @@ def get_user_sid(username):
502502
salt '*' user.get_user_sid jsnuffy
503503
"""
504504
domain = win32api.GetComputerName()
505+
username = str(username)
505506
if username.find("\\") != -1:
506-
domain = username.split("\\")[0]
507-
username = username.split("\\")[-1]
507+
domain = username.split("\\", maxsplit=1)[0]
508+
username = username.rsplit("\\", maxsplit=1)[-1]
508509
domain = domain.upper()
509510
return win32security.ConvertSidToStringSid(
510511
win32security.LookupAccountName(None, domain + "\\" + username)[0]

‎salt/runners/mine.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ def get(tgt, fun, tgt_type="glob"):
1818
"""
1919
masterapi = salt.daemons.masterapi.RemoteFuncs(__opts__)
2020
load = {
21-
"id": __opts__["id"].removesuffix("_master"),
21+
"id": __opts__["id"],
2222
"fun": fun,
2323
"tgt": tgt,
2424
"tgt_type": tgt_type,
2525
}
26-
ret = masterapi._mine_get(load)
26+
ret = masterapi._mine_get(load, skip_verify=True)
2727
return ret
2828

2929

‎salt/states/grains.py‎

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,19 @@ def list_present(name, value, delimiter=DEFAULT_TARGET_DELIM):
154154
name = re.sub(delimiter, DEFAULT_TARGET_DELIM, name)
155155
ret = {"name": name, "changes": {}, "result": True, "comment": ""}
156156
grain = __salt__["grains.get"](name)
157+
158+
# Check pending_grains first to avoid duplicates within the same state run
159+
pending_grains = __context__.get("pending_grains", {})
160+
if name not in pending_grains:
161+
pending_grains[name] = []
162+
157163
if grain:
158164
# check whether grain is a list
159165
if not isinstance(grain, list):
160166
ret["result"] = False
161167
ret["comment"] = f"Grain {name} is not a valid list"
162168
return ret
169+
163170
if isinstance(value, list):
164171
# An older implementation tried to convert everything to a set. Information was lost
165172
# during that conversion. It even converted str to set! Trying to add "racer" if
@@ -172,25 +179,41 @@ def list_present(name, value, delimiter=DEFAULT_TARGET_DELIM):
172179
intersection = []
173180
difference = []
174181
for new_value in value:
175-
if new_value in grain:
182+
if new_value in grain or new_value in pending_grains[name]:
176183
intersection.append(new_value)
177184
else:
178185
difference.append(new_value)
186+
# Track it as pending for subsequent states
187+
if "pending_grains" not in __context__:
188+
__context__["pending_grains"] = pending_grains
189+
pending_grains[name].append(new_value)
190+
179191
if difference:
180192
value = difference
181193
else:
182-
ret["comment"] = f"Value {value} is already in grain {name}"
194+
ret["comment"] = (
195+
f"Value {value} is already in grain {name} (or pending)"
196+
)
183197
return ret
198+
184199
if intersection:
185200
ret["comment"] = (
186-
'Removed value {} from update due to value found in "{}".\n'.format(
201+
'Removed value {} from update due to value found in "{}" (or pending).\n'.format(
187202
intersection, name
188203
)
189204
)
190205
else:
191-
if value in grain:
192-
ret["comment"] = f"Value {value} is already in grain {name}"
206+
# For single value, check against both actual and pending
207+
if value in grain or value in pending_grains[name]:
208+
ret["comment"] = (
209+
f"Value {value} is already in grain {name} (or pending)"
210+
)
193211
return ret
212+
# Add single value to pending_grains to avoid duplicates
213+
if "pending_grains" not in __context__:
214+
__context__["pending_grains"] = pending_grains
215+
pending_grains[name].append(value)
216+
194217
if __opts__["test"]:
195218
ret["result"] = None
196219
ret["comment"] = "Value {1} is set to be appended to grain {0}".format(
@@ -199,6 +222,40 @@ def list_present(name, value, delimiter=DEFAULT_TARGET_DELIM):
199222
ret["changes"] = {"new": grain}
200223
return ret
201224

225+
# Handle case where grain doesn't exist yet
226+
if not grain:
227+
if isinstance(value, list):
228+
intersection = []
229+
difference = []
230+
for new_value in value:
231+
if new_value in pending_grains[name]:
232+
intersection.append(new_value)
233+
else:
234+
difference.append(new_value)
235+
if "pending_grains" not in __context__:
236+
__context__["pending_grains"] = pending_grains
237+
pending_grains[name].append(new_value)
238+
239+
if difference:
240+
value = difference
241+
else:
242+
ret["comment"] = f"Value {value} is already pending in grain {name}"
243+
return ret
244+
245+
if intersection:
246+
ret["comment"] = (
247+
'Removed value {} from update due to value already pending in "{}".\n'.format(
248+
intersection, name
249+
)
250+
)
251+
else:
252+
if value in pending_grains[name]:
253+
ret["comment"] = f"Value {value} is already pending in grain {name}"
254+
return ret
255+
if "pending_grains" not in __context__:
256+
__context__["pending_grains"] = pending_grains
257+
pending_grains[name].append(value)
258+
202259
if __opts__["test"]:
203260
ret["result"] = None
204261
ret["comment"] = f"Grain {name} is set to be added"

‎salt/utils/extmods.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,5 @@ def sync(
153153
shutil.rmtree(emptydir, ignore_errors=True)
154154
except Exception as exc: # pylint: disable=broad-except
155155
log.error("Failed to sync %s module: %s", form, exc)
156+
156157
return ret, touched

0 commit comments

Comments
 (0)