Skip to content

Commit 8fb3133

Browse files
committed
Make device checks return predicate results
1 parent 43b37a6 commit 8fb3133

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

docs/plugins/generated.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ with:
17121712

17131713
### `device.udev.rule.check`
17141714

1715-
Assert that a udev rules file exists and optionally matches rendered content.
1715+
Check whether a udev rules file exists and optionally matches rendered content.
17161716

17171717
- Remote session: `true`
17181718
- Dry-run support: `true`

src/automax/plugins/udev.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from automax.core.models import ExecutionContext, PluginResult
1111
from automax.plugins.base import BasePlugin, PluginValidationError, RenderedFileInstallMixin
12-
from automax.plugins.remote_utils import CHANGE_MARKER, exec_remote, quote, result_from_remote, sudo_prefix
12+
from automax.plugins.remote_utils import CHANGE_MARKER, exec_remote, predicate_result_from_remote, quote, result_from_remote, sudo_prefix
1313

1414

1515

@@ -170,7 +170,7 @@ def execute(self, params: Dict[str, Any], context: ExecutionContext) -> PluginRe
170170

171171
class UdevRuleCheckPlugin(BasePlugin):
172172
name = "device.udev.rule.check"
173-
description = "Assert that a udev rules file exists and optionally matches rendered content."
173+
description = "Check whether a udev rules file exists and optionally matches rendered content."
174174
required_params = ("path",)
175175
optional_params = ("content", "rules", "sudo")
176176
opens_remote_session = True
@@ -187,4 +187,11 @@ def manual_commands(self, params: Dict[str, Any], context: ExecutionContext) ->
187187

188188
def execute(self, params: Dict[str, Any], context: ExecutionContext) -> PluginResult:
189189
rc, out, err = exec_remote(context, self.manual_commands(params, context)[0])
190-
return result_from_remote(rc=rc, stdout=out, stderr=err, message="device.udev.rule.check failed", data={"path": str(params["path"])})
190+
return predicate_result_from_remote(
191+
rc=rc,
192+
stdout=out,
193+
stderr=err,
194+
message="device.udev.rule.check failed",
195+
data_key="matches" if ("content" in params or "rules" in params) else "exists",
196+
data={"path": str(params["path"])},
197+
)

tests/test_next_engine.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5623,6 +5623,18 @@ def test_presence_check_plugins_return_predicates_without_failing_on_absence():
56235623

56245624

56255625

5626+
5627+
5628+
def test_device_udev_rule_check_returns_predicate_on_condition_false():
5629+
result = AutomaxEngine().plugin_registry.get("device.udev.rule.check").execute(
5630+
{"path": "/etc/udev/rules.d/99-demo.rules"},
5631+
_remote_context_for_result(1, stderr="missing"),
5632+
)
5633+
5634+
assert result.ok is True
5635+
assert result.changed is False
5636+
assert result.data["exists"] is False
5637+
56265638
def test_security_and_filesystem_content_checks_return_predicates_on_condition_false():
56275639
registry = AutomaxEngine().plugin_registry
56285640

0 commit comments

Comments
 (0)