File: simulate_safe_functions.cf

package info (click to toggle)
cfengine3 3.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,552 kB
  • sloc: ansic: 163,161; sh: 10,296; python: 2,950; makefile: 1,744; lex: 784; yacc: 633; perl: 211; pascal: 157; xml: 21; sed: 13
file content (51 lines) | stat: -rw-r--r-- 1,488 bytes parent folder | download | duplicates (3)
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
body common control
{
  inputs => { "../default.cf.sub" };
  bundlesequence => { default("$(this.promise_filename)") };
}

bundle agent init
{
  vars:
    "usemodule_unsafe_module_path" string => "$(sys.workdir)$(const.dirsep)modules$(const.dirsep)usemodule_unsafe.sh";
    "usemodule_safe_module_path" string => "$(sys.workdir)$(const.dirsep)modules$(const.dirsep)usemodule_safe.sh";

  files:
    "$(sys.statedir)/*safe"
      delete => tidy;
    "$(usemodule_unsafe_module_path)"
      create => "true",
      perms => m(700),
      content => "#!/bin/bash
touch $(sys.statedir)/usemodule_unsafe
";
    "$(usemodule_safe_module_path)"
      create => "true",
      perms => m(700),
      content => "#!/bin/bash
touch $(sys.statedir)/usemodule_safe
";
}

bundle agent test
{
  meta:
    "description" -> { "ENT-5299" }
      string => "Test that unsafe functions are only evaluated in --simulate mode when tagged as simulate_safe";

  vars:
    "cf_agent" string => ifelse(isvariable("sys.cf_agent"), "$(sys.cf_agent)", "/var/cfengine/bin/cf-agent");

  commands:
    "$(cf_agent) --timestamp --debug --simulate=manifest -Kf $(this.promise_filename).sub >$(sys.workdir)$(const.dirsep)state$(const.dirsep)agent.log"
      contain => in_shell;
}

bundle agent check
{
  vars:
    "result" string => readfile("$(sys.workdir)$(const.dirsep)state$(const.dirsep)agent.log");

  methods:
    "Pass/FAIL" usebundle => dcs_check_strcmp( "$(result)", "FAIL", $(this.promise_filename), "yes");
}