Fix native-nested probe: guard message is split across string literals

The probe searched plugins/cloud/crud.py for the contiguous string
"no further nesting". Stock does not contain it. The message is split across
adjacent string literals:

    verrors.add(f"{name}.snapshot", "This option is only available for datasets that have no further "
                                    "nesting")

Python concatenates those at runtime, so the errmsg IS contiguous and CRUD_BLOCK's
runtime filter matches correctly -- but the SOURCE never contains the whole
phrase. The probe therefore found nothing, concluded iX had removed the guard, and
skipped the nested module as "already native" on every boot. apply.log would say
"TrueNAS now handles nesting natively" and the feature would never work.

It fails safe -- the stock guard stays in place, so no backup could be
misconfigured and no data was at risk -- but the module was 100% dead.

Verified against real middlewared on a live box: the probe returned native=yes
(wrong) before this change and native=no (correct) after.

The probe now strips whitespace and quote characters before matching, which is
robust to any wrapping or concatenation style. Added a regression test that
EXECUTES apply.sh's own probe code (extracted, not reimplemented -- a
reimplementation would pass while the shipped probe stayed broken) against the
real wrapped source, a single-line variant, and a three-way split.

75 tests, ruff and shellcheck clean.
This commit is contained in:
flan
2026-07-12 22:44:26 +00:00
parent 24f1f2c648
commit 150a241a0f
3 changed files with 95 additions and 1 deletions
+14 -1
View File
@@ -167,7 +167,20 @@ try:
crud = os.path.join(result['mw_dir'], 'plugins', 'cloud', 'crud.py')
with open(crud, encoding='utf-8', errors='replace') as fh:
stock_src = fh.read().split('\n# TRUECLOUD_PATCH', 1)[0]
if 'no further nesting' not in stock_src:
# The guard message is SPLIT across adjacent string literals in the source:
#
# verrors.add(..., 'This option is only available for datasets that have no further '
# 'nesting')
#
# Python concatenates those at runtime, so the errmsg is contiguous -- but the
# SOURCE never contains the whole phrase. A raw search finds nothing, concludes
# iX removed the guard, and silently skips this module FOREVER. (Caught only by
# running the probe against real middlewared.)
#
# Strip whitespace and quote characters, then match the compacted phrase. That
# is robust to any wrapping or concatenation style iX may use.
_drop = str.maketrans('', '', ' \\t\\n\\r' + chr(34) + chr(39))
if 'nofurthernesting' not in stock_src.translate(_drop):
result['native_nested'] = 'yes'
except Exception:
pass