Skip to content

Commit 1438c5e

Browse files
committed
Preserve technical failures in capability checks
1 parent 8fb3133 commit 1438c5e

2 files changed

Lines changed: 30 additions & 10 deletions

File tree

src/automax/plugins/capabilities.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,24 +110,31 @@ def manual_commands(self, params: Dict[str, Any], context: ExecutionContext) ->
110110

111111
def execute(self, params: Dict[str, Any], context: ExecutionContext) -> PluginResult:
112112
missing: list[str] = []
113+
errors: list[dict[str, Any]] = []
113114
stdout_parts: list[str] = []
114115
stderr_parts: list[str] = []
115-
for command in self.manual_commands(params, context):
116+
checked = self.manual_commands(params, context)
117+
for command in checked:
116118
rc, out, err = exec_remote(context, command)
117119
stdout_parts.append(out)
118120
stderr_parts.append(err)
119-
if rc != 0:
121+
if rc == 1:
120122
missing.append(command)
123+
elif rc != 0:
124+
errors.append({"command": command, "rc": rc, "stderr": err})
121125
stdout = "\n".join(part for part in stdout_parts if part)
122126
stderr = "\n".join(part for part in stderr_parts if part)
123-
checked = self.manual_commands(params, context)
124-
return PluginResult.success(
125-
changed=False,
126-
rc=0,
127-
stdout=stdout,
128-
stderr=stderr,
129-
data={"checked": checked, "failed": missing, "matches": not missing},
130-
)
127+
data = {"checked": checked, "failed": missing, "matches": not missing and not errors}
128+
if errors:
129+
data["errors"] = errors
130+
return PluginResult.failure(
131+
rc=errors[0]["rc"],
132+
stdout=stdout,
133+
stderr=stderr,
134+
message="os.capability.check failed with a technical command error",
135+
data=data,
136+
)
137+
return PluginResult.success(changed=False, rc=0, stdout=stdout, stderr=stderr, data=data)
131138

132139

133140
class PluginRequirementsPlugin(BasePlugin):

tests/test_next_engine.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5707,6 +5707,19 @@ def test_os_check_plugins_return_predicates_on_condition_false():
57075707
assert result.rc == 0
57085708
assert result.data[key] is False
57095709

5710+
def test_capability_check_preserves_technical_failures():
5711+
registry = AutomaxEngine().plugin_registry
5712+
5713+
result = registry.get("os.capability.check").execute(
5714+
{"commands": ["sh -c 'exit 2'"]},
5715+
_remote_context_for_result(2, stderr="syntax error"),
5716+
)
5717+
5718+
assert result.ok is False
5719+
assert result.rc == 2
5720+
assert result.data["matches"] is False
5721+
assert result.data["errors"][0]["rc"] == 2
5722+
57105723
def test_data_archive_and_compression_checks_return_predicates_on_condition_false():
57115724
registry = AutomaxEngine().plugin_registry
57125725

0 commit comments

Comments
 (0)