File: 206.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 (126 lines) | stat: -rw-r--r-- 2,988 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
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
#######################################################
#
# Copy a file, then ensure that subsequent create=true doesn't
# overwrite mode, size, but DOES change owner, group - numeric UID/GID
#
#######################################################

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

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

bundle agent init
{
  vars:
    freebsd|solaris::
      "mode" int => "04751";
    !freebsd.!solaris::
      "mode" int => "01751";
    linux::
      "owner" string => "sys";
      "group" string => "sys";
    freebsd::
      "owner" string => "bin";
      "group" string => "sys";
    !(linux|freebsd)::
      "owner" string => "undefined-please-fix";
      "group" string => "undefined-please-fix";

    pass2.(freebsd|solaris)::
      "expect[modeoct]" string => "104755";

    pass2.!(freebsd|solaris|windows)::
      "expect[modeoct]" string => "101755";

    pass2.!windows::
      "expect[uid]" string => "0";
      "expect[gid]" string => "0";

    pass2.any::
      "expect[nlink]" string => "1";
      "expect[size]" string => "0";
      "fields" slist => getindices("expect");

  files:
      "$(G.testfile)"
      copy_from => init_copy("$(G.etc_group)"),
      perms => init_perms("$(mode)", "$(owner)", "$(group)"),
      classes => init_set_class("pass2");
}

body copy_from init_copy(file)
{
      source => "$(file)";
}

body perms init_perms(m, o, g)
{
      mode => "$(m)";
      owners => { "$(o)" };
      groups => { "$(g)" };
}


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

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

bundle agent test
{
  files:
      "$(G.testfile)"
      create => "true",
      perms => test_perms("a+r");
}

body perms test_perms(m)
{
      mode => "$(m)";
      owners => { "456" };
      groups => { "567" };
}

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

bundle agent check
{
  vars:
    freebsd|solaris::
      "expect[modeoct]" string => "104755";
    !freebsd.!solaris.!windows::
      "expect[modeoct]" string => "101755";
    !windows::
      "expect[uid]" string => "456";
      "expect[gid]" string => "567";
    any::
      "expect[nlink]" string => "1";
      "expect[size]" string => filestat("$(G.etc_group)", "size");

      "fields" slist => getindices("expect");
      "result[$(fields)]" string => filestat("$(G.testfile)", "$(fields)");

  classes:
      "not_ok" not => regcmp("$(expect[$(fields)])", "$(result[$(fields)])");

  reports:
    DEBUG::
      "expected:    $(fields) = '$(expect[$(fields)])'";
      "result:      $(fields) = '$(result[$(fields)])'";
    !not_ok::
      "$(this.promise_filename) Pass";
    not_ok::
      "$(this.promise_filename) FAIL";
}

### PROJECT_ID: core
### CATEGORY_ID: 27