File: 003.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 (94 lines) | stat: -rw-r--r-- 2,154 bytes parent folder | download | duplicates (7)
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
#######################################################
#
# Ensure that the transformer runs only once for every file in a recursive tree
#
#######################################################

body common control
{
      inputs => { "../../default.cf.sub" };
      bundlesequence  => { default("$(this.promise_filename)") };
      version => "1.0";
      cache_system_functions => "off"; # for execresult in check bundle
}

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

bundle agent init
{
  vars:
      "files" slist => { "1", "2", "3" };

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

      "$(G.testdir)/files/$(files)"
      copy_from => init_copy;
}

body copy_from init_copy
{
      source => "$(G.etc_group)";
}

body classes init_set_class(class)
{
      promise_kept => { "$(class)" };
      promise_repaired => { "$(class)" };
}

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

bundle agent test
{
  vars:
      "counter" string => "$(G.testdir)/counter";

  files:
    windows::
      "$(G.testdir)/files"
      transformer => "$(G.echo) $(this.promiser) >> $(counter)",
      file_select => test_plain,
      depth_search => test_recurse;
    !windows::
      "$(G.testdir)/files"
      transformer => "/bin/sh -c 'echo $(this.promiser) >> $(counter)'",
      file_select => test_plain,
      depth_search => test_recurse;
}

body file_select test_plain
{
      file_types => { "plain" };
      file_result => "file_types";
}

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

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

bundle agent check
{
  vars:
      "count" string => execresult("$(G.wc) -l $(test.counter)", "noshell");
    DEBUG::
      "list" string => execresult("$(G.ls) -1 $(G.testdir)/files", "noshell");

  classes:
      "ok" expression => regcmp("^\s*3\s.*", "$(count)");

  reports:
    DEBUG.!ok::
      "3 transformations expected, saw (wc): '$(count)'";
      "3 copies of $(G.etc_group) expected, saw (ls): '$(list)'";
    ok::
      "$(this.promise_filename) Pass";
    !ok::
      "$(this.promise_filename) FAIL";
}
### PROJECT_ID: core
### CATEGORY_ID: 27