1#!/var/cfengine/bin/cf-agent -f-
2body common control
3{
4        inputs => { "../default.cf.sub" };
5        bundlesequence  => { default("$(this.promise_filename)") };
6        version => "1.0";
7}
8
9
10bundle agent init {
11  vars:
12      "ROOT" string => "/tmp/CFE-2489";
13      "SOURCE" string => "$(ROOT)/SOURCE";
14      "use_bundles"
15        slist => { "bundle_uses_copy_from_without_param",
16                   "bundle_uses_copy_from_with_param" };
17
18  files:
19      "$(init.ROOT)/$(use_bundles)/." create => "true";
20
21      # Setup source files to copy_from
22      "$(init.ROOT)/SOURCE/$(init.ROOT)/$(use_bundles)/file.txt"
23        create => "true";
24}
25bundle agent test {
26  meta:
27      "description" -> { "CFE-2489" }
28        string => "Test that this.promiser holds the correct value in a copy_from body that uses parameters";
29
30      "test_soft_fail"
31        string => "any",
32        meta => { "CFE-2489" };
33
34  methods:
35      "XXX" usebundle => $(init.use_bundles);
36}
37
38bundle agent bundle_uses_copy_from_without_param {
39
40  files:
41
42      # As expected, when a copy_from promise uses a non-parameterized body the
43      # this.promiser context is as expected (points to the promised file).
44
45      "$(init.ROOT)/$(this.bundle)/file.txt"
46        copy_from => my_copy_without_param();
47
48}
49body copy_from my_copy_without_param() {
50        source  => "$(init.ROOT)/SOURCE/$(this.promiser)";
51        compare => "digest";
52}
53
54bundle agent bundle_uses_copy_from_with_param {
55
56  files:
57
58      # Oddly, when a copy_from promise uses a parameterized body, the
59      # this.promiser context does not contain the promised file, instead, it
60      # seems to contain the parents promiser. So, in this case, it wrongly gets
61      # XXX from the 'test' bundle.
62
63      "$(init.ROOT)/$(this.bundle)/file.txt"
64        copy_from => my_copy_with_param( "use_of_paramater_should_not_change_this_promiser" );
65
66}
67body copy_from my_copy_with_param(root) {
68        source  => "$(init.ROOT)/SOURCE/$(this.promiser)";
69        compare => "digest";
70}
71
72bundle agent check
73{
74
75  classes:
76
77      "pass"
78        expression => filesexist( '[ "$(init.ROOT)/bundle_uses_copy_from_with_param/file.txt",
79                                      "$(init.ROOT)/bundle_uses_copy_from_without_param/file.txt" ]' );
80  reports:
81
82      "$(this.promise_filename) $(with)"
83        with => ifelse( "pass", "Pass", "FAIL");
84}
85
86bundle agent __main__
87{
88  methods:
89      "init";
90      "test";
91      "check";
92}
93