Skip to content

Top down evaluation custom promise type test #3029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
body common control
{
inputs => { "../../default.cf.sub" };
bundlesequence => { "test", "cleanup" };
evaluation_order => "top_down";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯

}

promise agent dummy
{
path => "$(this.promise_dirname)/dummy_promise_type.py";
interpreter => "/usr/bin/python3";
}

bundle agent test
{

dummy:
"/tmp/dummyfile"
smth => "hello";

vars:
"content"
string => readfile("/tmp/dummyfile");

files:
"/tmp/dummyfile"
content => "ok";

vars:
"content"
string => readfile("/tmp/dummyfile");

classes:
"ok"
expression => strcmp("$(content)", "ok");

reports:
ok::
"$(this.promise_filename) Pass";
!ok::
"$(this.promise_filename) FAIL";

DEBUG::
"$(content)";
}

bundle agent cleanup
{
files:
"/tmp/dummyfile"
delete => tidy;
}
26 changes: 26 additions & 0 deletions tests/acceptance/30_custom_promise_types/dummy_promise_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from cfengine import (
PromiseModule,
Result,
)


class DummyPromiseType(PromiseModule):

def __init__(self, **kwargs):
super(DummyPromiseType, self).__init__(
name="dummy_promise_module", version="0.0.0", **kwargs
)

def validate_promise(self, promiser, attributes, meta):
pass

def evaluate_promise(self, promiser, attributes, metadata):

with open(promiser, "a") as f:
f.write("test")

return Result.KEPT


if __name__ == "__main__":
DummyPromiseType().start()
Loading