File: default.cf

package info (click to toggle)
cfengine3 3.2.4-2%2Bnmu1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 8,976 kB
  • sloc: ansic: 66,527; sh: 11,600; yacc: 407; makefile: 288
file content (121 lines) | stat: -rw-r--r-- 3,093 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
bundle common G
{
classes:
  "bin_sort" expression => fileexists("/bin/sort");
  "usr_bin_sort" expression => fileexists("/usr/bin/sort");

vars:
    "cwd" string => execresult("/bin/pwd", "noshell");

    "logfile_leafname" string => "TEST.log";
    "logfile" string => "$(cwd)/$(logfile_leafname)";

  bin_sort::
    "sort" string => "/bin/sort";
  usr_bin_sort::
    "sort" string => "/usr/bin/sort";
}

bundle agent default(filename)
{
vars:
    "tests" slist => { "init", "test", "check", "fini" };


methods:
    AUTO::
	"any" usebundle => "$(tests)";

reports:
    !AUTO::
	"# You must either specify '-D AUTO' or run the following commands:";
	"cf-agent -f ./$(filename) -b $(tests)";
}

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

bundle agent default_sort(infile, outfile)
{
commands:
    "$(G.sort) $(infile) > $(outfile)"
	contain => default_shell_command;
}

bundle agent default_check_diff(file1, file2, test)
{
methods:
        "any" usebundle => check_diff("$(file1)", "$(file2)", "$(test)", "no");
}

bundle agent sorted_check_diff(file1, file2, test)
{
methods:
        "any" usebundle => default_sort("$(file1)", "$(file1).sort");
        "any" usebundle => default_sort("$(file2)", "$(file2).sort");
        "any" usebundle => check_diff("$(file1).sort", "$(file2).sort", "$(test)", "no");
}

bundle agent check_diff(file1, file2, test, expected_difference)
{
vars:
    DEBUG.!no_difference::
        "file1r" string => readfile("$(file1)", "9999999999");
        "file1h" string => execresult("/usr/bin/hexdump -C $(file1)", "useshell");
        "file2r" string => readfile("$(file2)", "9999999999");
        "file2h" string => execresult("/usr/bin/hexdump -C $(file2)", "useshell");
        "diffu"  string => execresult("/usr/bin/diff -u $(file2) $(file1)", "noshell");

classes:
	"no_difference" expression => returnszero(
	    "/usr/bin/diff -q $(file1) $(file2)",
	    "useshell");

        "expected_difference" expression => strcmp("$(expected_difference)", "yes");

reports:
    no_difference.!expected_difference::
	"$(test) Pass";
    !no_difference.expected_difference::
	"$(test) Pass";
    !no_difference.!expected_difference::
	"$(test) FAIL";
    no_difference.expected_difference::
	"$(test) FAIL";

    DEBUG.!no_difference.!expected_difference::
        "$(file1) and $(file2) differ:";
        "$(file1): <$(file1r)>";
        "$(file2): <$(file2r)>";
        "hexdump $(file1):
$(file1h)";
        "hexdump $(file2):
$(file2h)";
        "$(diffu)";
    DEBUG.no_difference.expected_difference::
        "Contents of $(file1) and $(file) is the same.";
}

body contain default_shell_command
{
useshell => "true";
}

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

# Uses rm -rf instead of selecting and deleting files to avoid side-effects in
# tests due to problems in file deleletion promises.

bundle agent default_fini(file)
{
commands:
  "/bin/rm -rf $(file)*"
    contain => useshell;
  "/bin/rm -rf $(sys.workdir)/state/cf_state.*"
    contain => useshell;
}

body contain useshell
{
  useshell => "true";
  chdir => "/";
}