Skip to content

Commit 6e584a2

Browse files
committed
Top down evaluation custom promise type test
Signed-off-by: Victor Moene <victor.moene@northern.tech>
1 parent 24efff1 commit 6e584a2

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
body common control
2+
{
3+
inputs => { "../default.cf.sub" };
4+
bundlesequence => { "test", "cleanup" };
5+
evaluation_order => "top_down";
6+
}
7+
8+
promise agent dummy
9+
{
10+
path => "$(this.promise_dirname)/dummy_promise_type.py";
11+
interpreter => "/usr/bin/python3";
12+
}
13+
14+
bundle agent test
15+
{
16+
17+
dummy:
18+
"/tmp/dummyfile"
19+
smth => "hello";
20+
21+
vars:
22+
"content"
23+
string => readfile("/tmp/dummyfile");
24+
25+
files:
26+
"/tmp/dummyfile"
27+
content => "ok";
28+
29+
vars:
30+
"content"
31+
string => readfile("/tmp/dummyfile");
32+
33+
classes:
34+
"ok"
35+
expression => strcmp("$(content)", "ok");
36+
37+
reports:
38+
ok::
39+
"$(this.promise_filename) Pass";
40+
!ok::
41+
"$(this.promise_filename) FAIL";
42+
43+
DEBUG::
44+
"$(content)";
45+
}
46+
47+
bundle agent cleanup
48+
{
49+
files:
50+
"/tmp/dummyfile"
51+
delete => tidy;
52+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from cfengine import (
2+
PromiseModule,
3+
Result,
4+
)
5+
6+
7+
class DummyPromiseType(PromiseModule):
8+
9+
def __init__(self, **kwargs):
10+
super(DummyPromiseType, self).__init__(
11+
name="dummy_promise_module", version="0.0.0", **kwargs
12+
)
13+
14+
def validate_promise(self, promiser, attributes, meta):
15+
pass
16+
17+
def evaluate_promise(self, promiser, attributes, metadata):
18+
19+
with open(promiser, "a") as f:
20+
f.write("test")
21+
22+
return Result.KEPT
23+
24+
25+
if __name__ == "__main__":
26+
DummyPromiseType().start()

0 commit comments

Comments
 (0)