File: this_promiser.cf

package info (click to toggle)
cfengine3 3.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 20,256 kB
  • ctags: 9,613
  • sloc: ansic: 116,129; sh: 12,366; yacc: 1,088; makefile: 1,006; lex: 391; perl: 197; xml: 21; sed: 4
file content (204 lines) | stat: -rw-r--r-- 5,379 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#######################################################
#
# Test this.promiser on files promises 
#
#######################################################

body common control
{
      inputs => { "../default.cf.sub" };
      bundlesequence  => { default("$(this.promise_filename)") };   
      version => "1.0";
}

body classes promiser0_generic
{
    promise_repaired => { "$(this.promiser)_repaired", "$(this.promiser)_0_ok" };
    promise_kept => { "$(this.promiser)_kept", "$(this.promiser)_0_ok" };
}

body classes promiser1_generic
{
    promise_repaired => { "$(this.promiser)_repaired", "$(this.promiser)_1_ok" };
    promise_kept => { "$(this.promiser)_kept", "$(this.promiser)_1_ok" };
}

body classes promiser2_generic
{
    promise_repaired => { "$(this.promiser)_repaired", "$(this.promiser)_2_ok" };
    promise_kept => { "$(this.promiser)_kept", "$(this.promiser)_2_ok" };
}

body classes promiser3_generic
{
    promise_repaired => { "$(this.promiser)_repaired", "$(this.promiser)_3_ok" };
    promise_kept => { "$(this.promiser)_kept", "$(this.promiser)_3_ok" };
}

body classes promiser4_generic
{
    promise_repaired => { "$(this.promiser)_repaired", "$(this.promiser)_4_ok" };
    promise_kept => { "$(this.promiser)_kept", "$(this.promiser)_4_ok" };
}

bundle agent init
{
  vars:
      "files" slist => { "aa", "ab", "ac", "ba", "bb", "bc" };

  files:
      "$(G.testdir)/copy_me_source"
        create => "true";
}

#######################################################

bundle agent test
{
  commands:
    "$(G.true)"
      classes => promiser0_generic;
  files:
    # 6 promisers
    "$(G.testdir)/$(init.files)"
      create => "true",
      classes => promiser1_generic;

    # 3 promisers
    "$(G.testdir)/a.*"
      perms => m("666"),
      classes => promiser2_generic;

    # 2 promisers - dir + 1 file
    "$(G.testdir)"
      file_select => by_exec_cmd,
      perms => m("666"),
      classes => promiser2_generic,
      depth_search => test_recurse;

    # 7 promisers - dir + 6 files
    "$(G.testdir)"
      file_select => test_plain,
      depth_search => test_recurse,
      delete => tidyfiles,
      classes => promiser3_generic;

    "$(G.testdir)/copy_me"
      copy_from => local_cp("$(this.promiser)_source");

  methods:
    "template_test" usebundle => template_test;
}

bundle agent template_test
{
  vars:
    "testdir" string => "$(G.testdir)/template_test";
    "cfe_files" slist => { "cfe_file1", "cfe_file2" };
    "mustache_files" slist => { "mustache_file1", "mustache_file2" };

  files:
    # create empty files so that we can test pattern and file_select cases
    "$(testdir)/."
      create => "true";

    "$(testdir)/$(cfe_files)"
      create => "true";
    "$(testdir)/$(mustache_files)"
      create => "true";

    "$(testdir)/$(cfe_files).cf-template"
      create => "true",
      edit_line => insert_lines("Just a cfengine line for $(this.promiser).");

    "$(testdir)/$(mustache_files).mustache"
      create => "true",
      edit_line => insert_lines("Just a mustache line for $(this.promiser).");

    "$(testdir)/cfe_file[1,2]"
      perms => m("666"),
      template_method => "cfengine",
      edit_template => "$(this.promiser).cf-template",
      classes => promiser4_generic;

    "$(testdir)/mustache_.*"
      file_select => mustache_files,
      perms => m("666"),
      template_method => "mustache",
      edit_template => "$(this.promiser).mustache",
      classes => promiser4_generic;
}

body file_select mustache_files
{
     leaf_name => { "@(template_test.mustache_files)" };
     file_result => "leaf_name";   
}

body delete tidyfiles
{
     dirlinks => "delete";
     rmdirs   => "true";
}

body file_select test_plain
{
      leaf_name => { "[a,b][a,b,c]" };
      file_types => { "plain" };
      file_result => "file_types.leaf_name";
}

body file_select by_exec_cmd
# Redmine #3530
{
      leaf_name => {"ba"};
      exec_program => "/bin/ls $(this.promiser)";
      file_result => "leaf_name.exec_program";
}

body depth_search test_recurse
{
      depth => "inf";
}


#######################################################

bundle agent check
{
  vars:
      "ok_promisers" slist => classesmatching(".*_ok");
      "ok_0_count" int => countclassesmatching(".*_0_ok");
      "ok_1_count" int => countclassesmatching(".*_1_ok");
      "ok_2_count" int => countclassesmatching(".*_2_ok");
      "ok_3_count" int => countclassesmatching(".*_3_ok");
      "ok_4_count" int => countclassesmatching(".*_4_ok");

  classes:
      "ok_expand" expression => none("__this_promiser_[0,1,2,3]_ok", ok_promisers);
      "ok0" expression => strcmp("$(ok_0_count)", 1);
      "ok1" expression => strcmp("$(ok_1_count)", 6);
      "ok2" expression => strcmp("$(ok_2_count)", 5);
      "ok3" expression => strcmp("$(ok_3_count)", 7);
      "ok4" expression => strcmp("$(ok_4_count)", 4);
      "ok5" expression => fileexists("$(G.testdir)/copy_me");

      "ok" and => { "ok_expand", "ok0", "ok1", "ok2", "ok3", "ok4", "ok5" };
  reports:
    DEBUG::
      "$(ok_promisers)";
      "0: $(ok_0_count)";
      "1: $(ok_1_count)";
      "2: $(ok_2_count)";
      "3: $(ok_3_count)";
      "4: $(ok_4_count)";
    DEBUG.!ok5::
      "5: file not copied";

    ok::
      "$(this.promise_filename) Pass";
    !ok::
      "$(this.promise_filename) FAIL";
}
### PROJECT_ID: core
### CATEGORY_ID: 27