From c71879c8bccf4878f6da9fde58738d9fb17019f5 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Thu, 25 Jun 2026 15:04:01 +0200 Subject: [PATCH 1/7] cfengine format ./tests/acceptance/*.sub.cf Signed-off-by: Ole Herman Schumacher Elgesem --- tests/acceptance/dcs.sub.cf | 908 +++++++++++++--------- tests/acceptance/default.sub.cf | 20 +- tests/acceptance/plucked.sub.cf | 1246 +++++++++++++++---------------- 3 files changed, 1198 insertions(+), 976 deletions(-) diff --git a/tests/acceptance/dcs.sub.cf b/tests/acceptance/dcs.sub.cf index 757943343b..4efc8c4f47 100644 --- a/tests/acceptance/dcs.sub.cf +++ b/tests/acceptance/dcs.sub.cf @@ -3,128 +3,170 @@ # # See README for details about writing test cases. ######################################################################## - bundle common G { vars: windows:: - "cwd" string => execresult("C:\windows\system32\cmd.exe /C cd", "noshell"), + "cwd" + string => execresult("C:\windows\system32\cmd.exe /C cd", "noshell"), meta => { "simulate_safe" }; + # Use for redirection, not as a real file. "dev_null" string => "nul"; "exeext" slist => { ".exe", ".bat" }; + !windows:: - "cwd" string => execresult("/bin/pwd 2>/dev/null || /usr/bin/pwd", "useshell"), + "cwd" + string => execresult( + "/bin/pwd 2>/dev/null || /usr/bin/pwd", "useshell" + ), meta => { "simulate_safe" }; + # Use for redirection, not as a real file. "dev_null" string => "/dev/null"; "exeext" string => ""; any:: # General commands. - "cmds" slist => { "date", - "dd", - "dos2unix", - "diff", - "cat", - "colordiff", - "cp", - "echo", - "egrep", - "env", - "false", - "grep", - "gsed", # will override sed on solaris hosts - "gzip", - "hexdump", - "ln", - "ls", - "mkdir", - "mkfifo", - "mkgroup", # AIX equivalent of groupadd - "mock_package_manager", - "mv", - "no_fds", - "od", - "perl", - "printf", - "ps", - "psexec", - "pwd", - "rm", - "sed", - "seq", - "sh", - "sleep", - "sort", - "stat", - "sudo", - "tee", - "touch", - "true", - "yes", - "wc", - }; + "cmds" + slist => { + "date", + "dd", + "dos2unix", + "diff", + "cat", + "colordiff", + "cp", + "echo", + "egrep", + "env", + "false", + "grep", + "gsed", + # will override sed on solaris hosts + "gzip", + "hexdump", + "ln", + "ls", + "mkdir", + "mkfifo", + "mkgroup", + # AIX equivalent of groupadd + "mock_package_manager", + "mv", + "no_fds", + "od", + "perl", + "printf", + "ps", + "psexec", + "pwd", + "rm", + "sed", + "seq", + "sh", + "sleep", + "sort", + "stat", + "sudo", + "tee", + "touch", + "true", + "yes", + "wc", + }; + # Special cases. "make_cmds" slist => { "gmake", "make" }; + # rmgroup is AIX equivalent of groupdel - "sbin_cmds" slist => { "rmgroup", "groupadd", "groupdel", "useradd", "userdel", "usermod" }; + "sbin_cmds" + slist => { + "rmgroup", "groupadd", "groupdel", "useradd", "userdel", "usermod" + }; any:: - "paths[tests]" string => "$(this.promise_dirname)"; + "paths[tests]" string => "$(this.promise_dirname)"; + solaris:: - "paths[usr_xpg4_bin]" string => "/usr/xpg4/bin"; - "paths[usr_ucb_sparcv7]" string => "/usr/ucb/sparcv7"; - "paths[opt_csw_bin]" string => "/opt/csw/bin"; - "paths[usr_sfw_bin]" string => "/usr/sfw/bin"; + "paths[usr_xpg4_bin]" string => "/usr/xpg4/bin"; + "paths[usr_ucb_sparcv7]" string => "/usr/ucb/sparcv7"; + "paths[opt_csw_bin]" string => "/opt/csw/bin"; + "paths[usr_sfw_bin]" string => "/usr/sfw/bin"; + !windows:: - "paths[bin]" string => "/bin"; - "paths[usr_bin]" string => "/usr/bin"; - "paths[usr_sbin]" string => "/usr/sbin"; - "paths[usr_local_bin]" string => "/usr/local/bin"; - "paths[usr_contrib_bin]" string => "/usr/contrib/bin"; + "paths[bin]" string => "/bin"; + "paths[usr_bin]" string => "/usr/bin"; + "paths[usr_sbin]" string => "/usr/sbin"; + "paths[usr_local_bin]" string => "/usr/local/bin"; + "paths[usr_contrib_bin]" string => "/usr/contrib/bin"; + windows:: - "paths[msys64_usr_bin]" string => "c:\\msys64\\usr\\bin"; - "paths[temp_msys64_usr_bin]" string => "d:\\a\\_temp\\msys64\\usr\\bin"; - "paths[tool_wrappers]" string => "$(this.promise_dirname)\\tool_wrappers"; + "paths[msys64_usr_bin]" string => "c:\\msys64\\usr\\bin"; + "paths[temp_msys64_usr_bin]" string => "d:\\a\\_temp\\msys64\\usr\\bin"; + "paths[tool_wrappers]" string => "$(this.promise_dirname)\\tool_wrappers"; any:: "paths_indices" slist => getindices("paths"); # dereferenced path of the executable - "deref_paths[$(paths[$(paths_indices)])][$(cmds)$(exeext)]" string => - filestat("$(paths[$(paths_indices)])$(const.dirsep)$(cmds)$(exeext)", - "linktarget"); + "deref_paths[$(paths[$(paths_indices)])][$(cmds)$(exeext)]" + string => filestat( + "$(paths[$(paths_indices)])$(const.dirsep)$(cmds)$(exeext)", + "linktarget" + ); classes: - # General commands. - "$(paths_indices)_$(cmds)$(exeext)" expression => - fileexists("$(deref_paths[$(paths[$(paths_indices)])][$(cmds)$(exeext)])"); - "has_$(cmds)" expression => - fileexists("$(deref_paths[$(paths[$(paths_indices)])][$(cmds)$(exeext)])"), - scope => "namespace"; + # General commands. + "$(paths_indices)_$(cmds)$(exeext)" + expression => fileexists( + "$(deref_paths[$(paths[$(paths_indices)])][$(cmds)$(exeext)])" + ); + + "has_$(cmds)" + expression => fileexists( + "$(deref_paths[$(paths[$(paths_indices)])][$(cmds)$(exeext)])" + ), + scope => "namespace"; - # Special cases. - "$(paths_indices)_$(sbin_cmds)$(exeext)" expression => fileexists("$(paths[$(paths_indices)])$(const.dirsep)$(sbin_cmds)$(exeext)"); - "$(paths_indices)_$(make_cmds)$(exeext)" expression => fileexists("$(paths[$(paths_indices)])$(const.dirsep)$(make_cmds)$(exeext)"); - "has_make" expression => fileexists("$(paths[$(paths_indices)])$(const.dirsep)$(make_cmds)$(exeext)"), + # Special cases. + "$(paths_indices)_$(sbin_cmds)$(exeext)" + expression => fileexists( + "$(paths[$(paths_indices)])$(const.dirsep)$(sbin_cmds)$(exeext)" + ); + + "$(paths_indices)_$(make_cmds)$(exeext)" + expression => fileexists( + "$(paths[$(paths_indices)])$(const.dirsep)$(make_cmds)$(exeext)" + ); + + "has_make" + expression => fileexists( + "$(paths[$(paths_indices)])$(const.dirsep)$(make_cmds)$(exeext)" + ), scope => "namespace"; - "want_color" expression => strcmp(getenv("CFENGINE_COLOR", 4k), "1"); - "have_colordiff" expression => fileexists($(colordiff)); + "want_color" expression => strcmp(getenv("CFENGINE_COLOR", 4k), "1"); + "have_colordiff" expression => fileexists($(colordiff)); vars: - # General commands. - "$(cmds)" string => "$(paths[$(paths_indices)])$(const.dirsep)$(cmds)$(exeext)", + # General commands. + "$(cmds)" + string => "$(paths[$(paths_indices)])$(const.dirsep)$(cmds)$(exeext)", if => canonify("$(paths_indices)_$(cmds)$(exeext)"); - # Special cases. - "$(sbin_cmds)" string => "$(paths[$(paths_indices)])$(const.dirsep)$(sbin_cmds)$(exeext)", + # Special cases. + "$(sbin_cmds)" + string => "$(paths[$(paths_indices)])$(const.dirsep)$(sbin_cmds)$(exeext)", if => canonify("$(paths_indices)_$(sbin_cmds)$(exeext)"); - # gmake has higher priority, so should come last. - "make" string => "$(paths[$(paths_indices)])$(const.dirsep)make$(exeext)", + + # gmake has higher priority, so should come last. + "make" + string => "$(paths[$(paths_indices)])$(const.dirsep)make$(exeext)", if => canonify("$(paths_indices)_make$(exeext)"); - "make" string => "$(paths[$(paths_indices)])$(const.dirsep)gmake$(exeext)", + + "make" + string => "$(paths[$(paths_indices)])$(const.dirsep)gmake$(exeext)", if => canonify("$(paths_indices)_gmake$(exeext)"); # on solaris, gsed works more like GNU sed, such as having `-i` option @@ -138,26 +180,46 @@ bundle common G want_color.have_colordiff:: "diff_maybecolor" string => $(colordiff); + !want_color|!have_colordiff:: "diff_maybecolor" string => $(diff); classes: - "temp_declared" not => strcmp(getenv("TEMP", "65536"), ""); + "temp_declared" not => strcmp(getenv("TEMP", "65536"), ""); vars: - "etc" string => "$(this.promise_dirname)$(const.dirsep)dummy_etc"; - "etc_motd" string => "$(this.promise_dirname)$(const.dirsep)dummy_etc$(const.dirsep)motd"; - "etc_passwd" string => "$(this.promise_dirname)$(const.dirsep)dummy_etc$(const.dirsep)passwd"; - "etc_shadow" string => "$(this.promise_dirname)$(const.dirsep)dummy_etc$(const.dirsep)shadow"; - "etc_group" string => "$(this.promise_dirname)$(const.dirsep)dummy_etc$(const.dirsep)group"; - # Use instead of /dev/null when you need a real empty file to open. - "etc_null" string => "$(this.promise_dirname)$(const.dirsep)dummy_etc$(const.dirsep)null"; - "write_args_sh" string => "$(this.promise_dirname)/write_args.sh"; + "etc" string => "$(this.promise_dirname)$(const.dirsep)dummy_etc"; + + "etc_motd" + string => "$(this.promise_dirname)$(const.dirsep)dummy_etc$(const.dirsep)motd"; + + "etc_passwd" + string => "$(this.promise_dirname)$(const.dirsep)dummy_etc$(const.dirsep)passwd"; + + "etc_shadow" + string => "$(this.promise_dirname)$(const.dirsep)dummy_etc$(const.dirsep)shadow"; + + "etc_group" + string => "$(this.promise_dirname)$(const.dirsep)dummy_etc$(const.dirsep)group"; + + # Use instead of /dev/null when you need a real empty file to open. + "etc_null" + string => "$(this.promise_dirname)$(const.dirsep)dummy_etc$(const.dirsep)null"; + + "write_args_sh" string => "$(this.promise_dirname)/write_args.sh"; temp_declared:: "testroot" string => getenv("TEMP", "65535"); - "testdir" string => concat(getenv("TEMP", "65535"), "$(const.dirsep)TESTDIR.cfengine"); - "testfile" string => concat(getenv("TEMP", "65535"), "$(const.dirsep)TEST.cfengine"); + + "testdir" + string => concat( + getenv("TEMP", "65535"), "$(const.dirsep)TESTDIR.cfengine" + ); + + "testfile" + string => concat( + getenv("TEMP", "65535"), "$(const.dirsep)TEST.cfengine" + ); !temp_declared:: "testroot" string => "$(const.dirsep)tmp"; @@ -165,23 +227,22 @@ bundle common G "testfile" string => "$(const.dirsep)tmp$(const.dirsep)TEST.cfengine"; classes: - "using_fakeroot" - expression => regcmp(".+", getenv("FAKEROOTKEY", "10")); + "using_fakeroot" expression => regcmp(".+", getenv("FAKEROOTKEY", "10")); } bundle common dcs_strings { vars: - "multiline_potatoes" string => - "BEGIN + "multiline_potatoes" + string => "BEGIN One potato Two potato Three potatoes Four END"; - "multiline_potatoes_lesser" string => - "BEGIN + "multiline_potatoes_lesser" + string => "BEGIN One potato Three potatoes Four @@ -191,44 +252,43 @@ END"; bundle agent paths_init(filename) { classes: - "filename_absolute" expression => regcmp("/.*", "$(filename)"); + "filename_absolute" expression => regcmp("/.*", "$(filename)"); } bundle agent paths_absolute(filename) { vars: filename_absolute:: - "input_file" - string => "$(filename)"; + "input_file" string => "$(filename)"; + !filename_absolute:: - "input_file" - string => "$(G.cwd)/$(filename)"; + "input_file" string => "$(G.cwd)/$(filename)"; } bundle agent default(filename) { classes: - "have_test_run_$(bundles)" expression => "any"; + "have_test_run_$(bundles)" expression => "any"; vars: - - "tests" slist => { "default:init", - "default:test", - "default:check", - "default:destroy" + "tests" + slist => { + "default:init", "default:test", "default:check", "default:destroy" }; - "bundles" slist => bundlesmatching("default:(init|test|check|destroy)"); + "bundles" slist => bundlesmatching("default:(init|test|check|destroy)"); files: - "$(G.testdir)/." create => "true"; + "$(G.testdir)/." create => "true"; methods: - "any" usebundle => collect_stories_metadata; - "any" usebundle => test_precheck; + "any" usebundle => collect_stories_metadata; + "any" usebundle => test_precheck; proceed_with_test:: - "any" usebundle => test_run("$(filename)"), inherit => "true"; + "any" + usebundle => test_run("$(filename)"), + inherit => "true"; reports: EXTRA.verbose_mode:: @@ -240,14 +300,13 @@ bundle agent test_run(filename) vars: methods: - "any" - usebundle => paths_init("$(filename)"); - "any" - usebundle => paths_absolute("$(filename)"); + "any" usebundle => paths_init("$(filename)"); + "any" usebundle => paths_absolute("$(filename)"); AUTO:: - "any" usebundle => "$(default.tests)", - if => canonify("have_test_run_$(default.tests)"); + "any" + usebundle => "$(default.tests)", + if => canonify("have_test_run_$(default.tests)"); reports: !AUTO:: @@ -259,14 +318,18 @@ bundle agent collect_stories_metadata { vars: "test_meta_vars" slist => { "description", "story_id", "covers" }; + classes: - "have_$(test_meta_vars)" expression => isvariable("test_meta.$(test_meta_vars)"); + "have_$(test_meta_vars)" + expression => isvariable("test_meta.$(test_meta_vars)"); reports: have_description:: "test description: $(test_meta.description)"; + have_story_id:: "test story_id: $(test_meta.story_id)"; + have_covers:: "test covers: $(test_meta.covers)"; } @@ -274,76 +337,108 @@ bundle agent collect_stories_metadata bundle agent test_precheck { vars: - "fail_types" slist => { "suppress", "soft", "flakey" }; + "fail_types" slist => { "suppress", "soft", "flakey" }; + + "test_skip_unsupported" + slist => variablesmatching(".*_meta\.test_skip_unsupported"); - "test_skip_unsupported" slist => variablesmatching(".*_meta\.test_skip_unsupported"); - "test_skip_needs_work" slist => variablesmatching(".*_meta\.test_skip_needs_work"); - "test_$(fail_types)_fail" slist => variablesmatching(".*_meta\.test_$(fail_types)_fail"); - "test_$(fail_types)_fail_metatags" slist => getvariablemetatags("$(test_$(fail_types)_fail)"); - "test_$(fail_types)_fail_ticket" slist => filter("(redmine|CFE-|ENT-|ARCHIVE-|QA-).*", "test_$(fail_types)_fail_metatags", "true", "false", 1); + "test_skip_needs_work" + slist => variablesmatching(".*_meta\.test_skip_needs_work"); + + "test_$(fail_types)_fail" + slist => variablesmatching(".*_meta\.test_$(fail_types)_fail"); + + "test_$(fail_types)_fail_metatags" + slist => getvariablemetatags("$(test_$(fail_types)_fail)"); + + "test_$(fail_types)_fail_ticket" + slist => filter( + "(redmine|CFE-|ENT-|ARCHIVE-|QA-).*", + "test_$(fail_types)_fail_metatags", + "true", + "false", + 1 + ); classes: - "test_skip_unsupported_set" expression => some(".*", "test_skip_unsupported"); - "test_skip_needs_work_set" expression => some(".*", "test_skip_needs_work"); - "test_$(fail_types)_fail_set" expression => some(".*", "test_$(fail_types)_fail"); - "test_$(fail_types)_fail_ticket_set" expression => some(".*", "test_$(fail_types)_fail_ticket"); + "test_skip_unsupported_set" + expression => some(".*", "test_skip_unsupported"); + + "test_skip_needs_work_set" expression => some(".*", "test_skip_needs_work"); + + "test_$(fail_types)_fail_set" + expression => some(".*", "test_$(fail_types)_fail"); - "test_skip_unsupported_match" and => { "test_skip_unsupported_set", "$($(test_skip_unsupported))" }; - "test_skip_needs_work_match" and => { "test_skip_needs_work_set", "$($(test_skip_needs_work))" }; - "test_$(fail_types)_fail_match" and => { "test_$(fail_types)_fail_set", "$($(test_$(fail_types)_fail))" }; + "test_$(fail_types)_fail_ticket_set" + expression => some(".*", "test_$(fail_types)_fail_ticket"); - "proceed_with_test" + "test_skip_unsupported_match" + and => { "test_skip_unsupported_set", "$($(test_skip_unsupported))" }; + + "test_skip_needs_work_match" + and => { "test_skip_needs_work_set", "$($(test_skip_needs_work))" }; + + "test_$(fail_types)_fail_match" + and => { "test_$(fail_types)_fail_set", "$($(test_$(fail_types)_fail))" }; + + "proceed_with_test" and => { "!test_skip_unsupported_match", "!test_skip_needs_work_match" }, scope => "namespace"; reports: test_skip_unsupported_match:: "$(this.promise_filename) Skip/unsupported"; + test_skip_needs_work_match:: "$(this.promise_filename) Skip/needs_work"; + test_suppress_fail_match.test_suppress_fail_ticket_set:: "$(this.promise_filename) XFAIL/$(test_suppress_fail_ticket)"; + test_suppress_fail_match.!test_suppress_fail_ticket_set:: "$(this.promise_filename) FAIL/no_ticket_number"; + test_soft_fail_match.test_soft_fail_ticket_set:: "$(this.promise_filename) SFAIL/$(test_soft_fail_ticket)"; + test_soft_fail_match.!test_soft_fail_ticket_set:: "$(this.promise_filename) FAIL/no_ticket_number"; + test_flakey_fail_match.test_flakey_fail_ticket_set:: "$(this.promise_filename) FLAKEY/$(test_flakey_fail_ticket)"; + test_flakey_fail_match.!test_flakey_fail_ticket_set:: "$(this.promise_filename) FAIL/no_ticket_number"; } ####################################################### - bundle agent dcs_sort(infile, outfile) { commands: - # Enforce byte sort order with LC_ALL. - "$(G.env) LC_ALL=C $(G.sort) $(infile) > $(outfile)" - contain => in_shell; + # Enforce byte sort order with LC_ALL. + "$(G.env) LC_ALL=C $(G.sort) $(infile) > $(outfile)" contain => in_shell; } bundle agent dcs_check_state(bundlename, expected_file, test) { vars: - "state" data => bundlestate($(bundlename)); + "state" data => bundlestate($(bundlename)); methods: - "" usebundle => file_make("$(G.testdir)/template", "{{%state}}"); - "" usebundle => file_make("$(G.testdir)/actual", ""); - "any" usebundle => dcs_check_state_prep(@(state)); - "any" usebundle => dcs_check_diff_expected("$(G.testdir)/actual", - $(expected_file), - $(test), - "no"); + "" usebundle => file_make("$(G.testdir)/template", "{{%state}}"); + "" usebundle => file_make("$(G.testdir)/actual", ""); + "any" usebundle => dcs_check_state_prep(@(state)); + + "any" + usebundle => dcs_check_diff_expected( + "$(G.testdir)/actual", $(expected_file), $(test), "no" + ); } bundle agent dcs_check_state_prep(state_container) { files: - "$(G.testdir)/actual" + "$(G.testdir)/actual" create => "true", edit_template => "$(G.testdir)/template", template_data => mergedata('{ "state": state_container }'), @@ -354,89 +449,116 @@ bundle agent dcs_check_diff(file1, file2, test) # @brief Pass if two files do not differ. { methods: - "any" usebundle => dcs_check_diff_expected($(file1), - $(file2), - $(test), - "no"); + "any" + usebundle => dcs_check_diff_expected($(file1), $(file2), $(test), "no"); } bundle agent dcs_if_diff(file1, file2, pass_class, fail_class) { methods: - "any" usebundle => dcs_if_diff_expected($(file1), - $(file2), - "no", - $(pass_class), - $(fail_class)); + "any" + usebundle => dcs_if_diff_expected( + $(file1), $(file2), "no", $(pass_class), $(fail_class) + ); } bundle agent sorted_check_diff(file1, file2, test) { methods: - "any" usebundle => dcs_sort("$(file1)", "$(file1).sort"); - "any" usebundle => dcs_sort("$(file2)", "$(file2).sort"); - "any" usebundle => dcs_check_diff_expected("$(file1).sort", - "$(file2).sort", - $(test), - "no"); + "any" usebundle => dcs_sort("$(file1)", "$(file1).sort"); + "any" usebundle => dcs_sort("$(file2)", "$(file2).sort"); + + "any" + usebundle => dcs_check_diff_expected( + "$(file1).sort", "$(file2).sort", $(test), "no" + ); } bundle agent xml_check_diff(file1, file2, test, expected_difference) { vars: DEBUG.check_ready.!no_difference:: - "file1r" string => execresult("$(G.cwd)/xml-c14nize $(file1)", "noshell"), + "file1r" + string => execresult("$(G.cwd)/xml-c14nize $(file1)", "noshell"), meta => { "simulate_safe" }; - "file2r" string => execresult("$(G.cwd)/xml-c14nize $(file2)", "noshell"), + + "file2r" + string => execresult("$(G.cwd)/xml-c14nize $(file2)", "noshell"), meta => { "simulate_safe" }; DEBUG.check_ready.!no_difference.has_hexdump:: - "file1h" string => execresult("$(G.hexdump) -C $(file1)", "useshell"), + "file1h" + string => execresult("$(G.hexdump) -C $(file1)", "useshell"), meta => { "simulate_safe" }; - "file2h" string => execresult("$(G.hexdump) -C $(file2)", "useshell"), + + "file2h" + string => execresult("$(G.hexdump) -C $(file2)", "useshell"), meta => { "simulate_safe" }; DEBUG.check_ready.!no_difference.!has_hexdump:: - "file1h" string => execresult("$(G.od) -c $(file1)", "useshell"), + "file1h" + string => execresult("$(G.od) -c $(file1)", "useshell"), meta => { "simulate_safe" }; - "file2h" string => execresult("$(G.od) -c $(file2)", "useshell"), + + "file2h" + string => execresult("$(G.od) -c $(file2)", "useshell"), meta => { "simulate_safe" }; DEBUG.check_ready.!no_difference.has_unified_diff:: - "diffu" string => execresult("$(G.diff_maybecolor) -u $(file2) $(file1) 2>$(G.dev_null)", "useshell"), + "diffu" + string => execresult( + "$(G.diff_maybecolor) -u $(file2) $(file1) 2>$(G.dev_null)", + "useshell" + ), meta => { "simulate_safe" }; + DEBUG.check_ready.!no_difference.!has_unified_diff:: - "diffu" string => execresult("$(G.diff_maybecolor) -c $(file2) $(file1) 2>$(G.dev_null)", "useshell"), + "diffu" + string => execresult( + "$(G.diff_maybecolor) -c $(file2) $(file1) 2>$(G.dev_null)", + "useshell" + ), meta => { "simulate_safe" }; classes: - "has_unified_diff" expression => returnszero( - "$(G.diff_maybecolor) -u $(G.etc_null) $(G.etc_null) >$(G.dev_null) 2>&1", "useshell"), - meta => { "simulate_safe" }; + "has_unified_diff" + expression => returnszero( + "$(G.diff_maybecolor) -u $(G.etc_null) $(G.etc_null) >$(G.dev_null) 2>&1", + "useshell" + ), + meta => { "simulate_safe" }; c14n_files_created:: - "no_difference" expression => returnszero( - "$(G.diff_maybecolor) $(G.testfile).default-xml-check-diff-1 $(G.testfile).default-xml-check-diff-2 >$(G.dev_null) 2>&1", - "useshell"), + "no_difference" + expression => returnszero( + "$(G.diff_maybecolor) $(G.testfile).default-xml-check-diff-1 $(G.testfile).default-xml-check-diff-2 >$(G.dev_null) 2>&1", + "useshell" + ), meta => { "simulate_safe" }; - "expected_difference" expression => strcmp("$(expected_difference)", "yes"); + "expected_difference" + expression => strcmp("$(expected_difference)", "yes"); + "check_ready" expression => "any"; commands: - "$(G.cwd)/xml-c14nize $(file1) > $(G.testfile).default-xml-check-diff-1" + "$(G.cwd)/xml-c14nize $(file1) > $(G.testfile).default-xml-check-diff-1" contain => in_shell; - "$(G.cwd)/xml-c14nize $(file2) > $(G.testfile).default-xml-check-diff-2" + + "$(G.cwd)/xml-c14nize $(file2) > $(G.testfile).default-xml-check-diff-2" contain => in_shell, classes => if_ok("c14n_files_created"); reports: check_ready.no_difference.!expected_difference:: "$(test) Pass"; + check_ready.!no_difference.expected_difference:: "$(test) Pass"; + check_ready.!no_difference.!expected_difference:: "$(test) FAIL"; + check_ready.no_difference.expected_difference:: "$(test) FAIL"; @@ -449,6 +571,7 @@ $(file1h)"; "dump $(file2): $(file2h)"; "$(diffu)"; + DEBUG.check_ready.no_difference.expected_difference:: "Contents of $(file1) and $(file) is the same."; } @@ -456,7 +579,7 @@ $(file2h)"; bundle agent dcs_report_generic_classes(x) { vars: - "choices" slist => { "repaired", "failed", "denied", "timeout", "kept" }; + "choices" slist => { "repaired", "failed", "denied", "timeout", "kept" }; reports: DEBUG:: @@ -467,60 +590,82 @@ bundle agent dcs_report_generic_classes(x) bundle agent dcs_generic_classes_to_string(x) { vars: - "choices" slist => { "repaired", "failed", "denied", "timeout", "kept" }; - "s[$(choices)]" string => "$(x)_$(choices)", if => '$(x)_$(choices)'; - "found_unsorted" slist => getvalues(s); - "found" slist => sort(found_unsorted, "lex"); - "found_str" string => format("%S", found); + "choices" slist => { "repaired", "failed", "denied", "timeout", "kept" }; + + "s[$(choices)]" + string => "$(x)_$(choices)", + if => '$(x)_$(choices)'; + + "found_unsorted" slist => getvalues(s); + "found" slist => sort(found_unsorted, "lex"); + "found_str" string => format("%S", found); reports: - "$(found_str)" bundle_return_value_index => "str"; + "$(found_str)" bundle_return_value_index => "str"; } # These set/clear global classes, so they can be tested in another bundle body classes dcs_all_classes(prefix) { - promise_kept => { "$(prefix)_promise_kept" }; - promise_repaired => { "$(prefix)_promise_repaired" }; - repair_failed => { "$(prefix)_repair_failed" }; - repair_denied => { "$(prefix)_repair_denied" }; - repair_timeout => { "$(prefix)_repair_timeout" }; - cancel_kept => { "$(prefix)_cancel_kept" }; - cancel_repaired => { "$(prefix)_cancel_repaired" }; - cancel_notkept => { "$(prefix)_cancel_notkept" }; + promise_kept => { "$(prefix)_promise_kept" }; + promise_repaired => { "$(prefix)_promise_repaired" }; + repair_failed => { "$(prefix)_repair_failed" }; + repair_denied => { "$(prefix)_repair_denied" }; + repair_timeout => { "$(prefix)_repair_timeout" }; + cancel_kept => { "$(prefix)_cancel_kept" }; + cancel_repaired => { "$(prefix)_cancel_repaired" }; + cancel_notkept => { "$(prefix)_cancel_notkept" }; } bundle agent dcs_all_negative_classes(prefix) { - # These must be global classes so they can be tested in another bundle - # We set them here, so they can be (possibly) cleared later + # These must be global classes so they can be tested in another bundle + # We set them here, so they can be (possibly) cleared later classes: - "$(prefix)_cancel_kept" expression => "any", scope => "namespace"; - "$(prefix)_cancel_repaired" expression => "any", scope => "namespace"; - "$(prefix)_cancel_notkept" expression => "any", scope => "namespace"; + "$(prefix)_cancel_kept" + expression => "any", + scope => "namespace"; + + "$(prefix)_cancel_repaired" + expression => "any", + scope => "namespace"; + + "$(prefix)_cancel_notkept" + expression => "any", + scope => "namespace"; } bundle agent dcs_all_classes_to_string(prefix) { vars: - "classes_all" slist => classesmatching("$(prefix)_.*(kept|notkept|failed|denied|repaired|timeout)"); - "classes" slist => sort(classes_all, "lex"); - "found_str" string => format("%S", classes); + "classes_all" + slist => classesmatching( + "$(prefix)_.*(kept|notkept|failed|denied|repaired|timeout)" + ); + + "classes" slist => sort(classes_all, "lex"); + "found_str" string => format("%S", classes); reports: - "$(found_str)" bundle_return_value_index => "str"; + "$(found_str)" bundle_return_value_index => "str"; } bundle agent dcs_check_diff_expected(file1, file2, test, expected_difference) { methods: - "any" usebundle => dcs_if_diff_expected($(file1), $(file2), $(expected_difference), - "dcs_check_diff_expected_pass_class", - "dcs_check_diff_expected_fail_class"); + "any" + usebundle => dcs_if_diff_expected( + $(file1), + $(file2), + $(expected_difference), + "dcs_check_diff_expected_pass_class", + "dcs_check_diff_expected_fail_class" + ); reports: dcs_check_diff_expected_pass_class:: "$(test) Pass"; + dcs_check_diff_expected_fail_class:: "$(test) FAIL"; } @@ -533,48 +678,75 @@ bundle agent dcs_if_diff_expected(file1, file2, expected_difference, pass_class, "file2r" string => readfile("$(file2)", "4096"); (EXTRA|DEBUG_HEXDUMP).check_ready.!no_difference.has_hexdump:: - "file1h" string => execresult("$(G.hexdump) -C $(file1)", "useshell"), + "file1h" + string => execresult("$(G.hexdump) -C $(file1)", "useshell"), meta => { "simulate_safe" }; - "file2h" string => execresult("$(G.hexdump) -C $(file2)", "useshell"), + + "file2h" + string => execresult("$(G.hexdump) -C $(file2)", "useshell"), meta => { "simulate_safe" }; (EXTRA|DEBUG_HEXDUMP).check_ready.!no_difference.!has_hexdump:: - "file1h" string => execresult("$(G.od) -c $(file1)", "useshell"), + "file1h" + string => execresult("$(G.od) -c $(file1)", "useshell"), meta => { "simulate_safe" }; - "file2h" string => execresult("$(G.od) -c $(file2)", "useshell"), + + "file2h" + string => execresult("$(G.od) -c $(file2)", "useshell"), meta => { "simulate_safe" }; DEBUG.check_ready.!no_difference.has_unified_diff:: - "diffu" string => execresult("$(G.diff_maybecolor) -u $(file2) $(file1) 2>$(G.dev_null)", "useshell"), + "diffu" + string => execresult( + "$(G.diff_maybecolor) -u $(file2) $(file1) 2>$(G.dev_null)", + "useshell" + ), meta => { "simulate_safe" }; + DEBUG.check_ready.!no_difference.!has_unified_diff:: - "diffu" string => execresult("$(G.diff_maybecolor) -c $(file2) $(file1) 2>$(G.dev_null)", "useshell"), + "diffu" + string => execresult( + "$(G.diff_maybecolor) -c $(file2) $(file1) 2>$(G.dev_null)", + "useshell" + ), meta => { "simulate_safe" }; classes: - "has_unified_diff" expression => returnszero( - "$(G.diff_maybecolor) -u $(G.etc_null) $(G.etc_null) >$(G.dev_null) 2>&1", "useshell"), - meta => { "simulate_safe" }; - - "no_difference" expression => returnszero( - "$(G.diff_maybecolor) $(file1) $(file2) >$(G.dev_null) 2>&1", - "useshell"), - meta => { "simulate_safe" }; - - "expected_difference" expression => strcmp("$(expected_difference)", "yes"); - "check_ready" expression => "any"; + "has_unified_diff" + expression => returnszero( + "$(G.diff_maybecolor) -u $(G.etc_null) $(G.etc_null) >$(G.dev_null) 2>&1", + "useshell" + ), + meta => { "simulate_safe" }; + + "no_difference" + expression => returnszero( + "$(G.diff_maybecolor) $(file1) $(file2) >$(G.dev_null) 2>&1", + "useshell" + ), + meta => { "simulate_safe" }; + + "expected_difference" expression => strcmp("$(expected_difference)", "yes"); + "check_ready" expression => "any"; check_ready.no_difference.!expected_difference:: - "$(pass_class)" expression => "any", + "$(pass_class)" + expression => "any", scope => "namespace"; + check_ready.!no_difference.expected_difference:: - "$(pass_class)" expression => "any", + "$(pass_class)" + expression => "any", scope => "namespace"; + check_ready.!no_difference.!expected_difference:: - "$(fail_class)" expression => "any", + "$(fail_class)" + expression => "any", scope => "namespace"; + check_ready.no_difference.expected_difference:: - "$(fail_class)" expression => "any", + "$(fail_class)" + expression => "any", scope => "namespace"; reports: @@ -585,13 +757,16 @@ $(file1r)"; "CONTENTS OF $(file2): $(file2r)"; "$(diffu)"; + (DEBUG_HEXDUMP|EXTRA).check_ready.!no_difference.!expected_difference:: "hexdump $(file1): $(file1h)"; "hexdump $(file2): $(file2h)"; + DEBUG.check_ready.no_difference.expected_difference:: "Contents of $(file1) and $(file) are the same but should differ."; + EXTRA:: "Diff command: $(G.diff_maybecolor) -u $(file2) $(file1) 2>$(G.dev_null)"; } @@ -599,24 +774,21 @@ $(file2h)"; bundle agent dcs_sleep(t) { commands: - "$(G.perl) -e 'sleep $(t)'"; + "$(G.perl) -e 'sleep $(t)'"; + reports: EXTRA:: "Sleeping $(t) seconds"; } ####################################################### - # Uses rm -rf instead of selecting and deleting files to avoid side-effects in # tests due to problems in file deleletion promises. - bundle agent dcs_fini(file) { commands: - "$(G.rm) -rf $(file)*" - contain => dcs_useshell; - "$(G.rm) -rf $(sys.statedir)/cf_state.*" - contain => dcs_useshell; + "$(G.rm) -rf $(file)*" contain => dcs_useshell; + "$(G.rm) -rf $(sys.statedir)/cf_state.*" contain => dcs_useshell; reports: EXTRA:: @@ -626,7 +798,7 @@ bundle agent dcs_fini(file) bundle agent dcs_copyfile(from, to) { files: - "$(to)" + "$(to)" create => "true", copy_from => dcs_sync($(from)); @@ -637,17 +809,17 @@ bundle agent dcs_copyfile(from, to) body copy_from dcs_sync(f) { - source => "$(f)"; - purge => "true"; - preserve => "false"; - type_check => "false"; - compare => "digest"; + source => "$(f)"; + purge => "true"; + preserve => "false"; + type_check => "false"; + compare => "digest"; } body contain dcs_useshell { - useshell => "true"; - chdir => "/"; + useshell => "true"; + chdir => "/"; } bundle agent dcs_runagent(args) @@ -655,36 +827,45 @@ bundle agent dcs_runagent(args) commands: debug_mode:: "$(sys.cf_agent) -Kdf $(args)"; + verbose_mode:: "$(sys.cf_agent) -Kvf $(args)"; + inform_mode:: "$(sys.cf_agent) -KIf $(args)"; + !debug_mode.!verbose_mode.!inform_mode:: "$(sys.cf_agent) -Kf $(args)"; } ####################################################### # Test based on whether two strings are the same - bundle agent dcs_check_strcmp(strA, strB, test, expected_difference) { classes: - "equal" expression => strcmp($(strA), $(strB)); - "expected_difference" or => { strcmp($(expected_difference), "yes"), - strcmp($(expected_difference), "true") }; + "equal" expression => strcmp($(strA), $(strB)); + + "expected_difference" + or => { + strcmp($(expected_difference), "yes"), + strcmp($(expected_difference), "true"), + }; + + "__passif" xor => { "equal", "expected_difference" }; - "__passif" xor => { "equal", "expected_difference" }; reports: EXTRA|!__passif:: "$(this.bundle): STRING A: '$(strA)'"; "$(this.bundle): STRING B: '$(strB)'"; + __passif:: "$(test) Pass"; + !__passif:: "$(test) FAIL"; } -bundle agent dcs_check_diff_elements( setA, setB, test, expected_difference) +bundle agent dcs_check_diff_elements(setA, setB, test, expected_difference) # @brief Test that there is or is not a difference between two lists or data containers elements (order elements does not matter) # # **Example:** @@ -708,61 +889,69 @@ bundle agent dcs_check_diff_elements( setA, setB, test, expected_difference) # ``` { vars: - "length_A" int => length( setA ); - "length_B" int => length( setB ); - "difference_A_B" slist => difference( setA, setB ); - "difference_B_A" slist => difference( setB, setA ); + "length_A" int => length(setA); + "length_B" int => length(setB); + "difference_A_B" slist => difference(setA, setB); + "difference_B_A" slist => difference(setB, setA); classes: - "_pass_same_length" - expression => eval( "$(length_A) == $(length_B)", class, infix ); - "_pass_no_elements_in_setA_that_are_not_in_setB" - expression => islessthan( length( difference_A_B ), 1 ); - "_pass_no_elements_in_setB_that_are_not_in_setA" - expression => islessthan( length( difference_B_A ), 1 ); + "_pass_same_length" + expression => eval("$(length_A) == $(length_B)", class, infix); - "__passif" and => { "_pass_same_length", - "_pass_no_elements_in_setA_that_are_not_in_setB", - "_pass_no_elements_in_setB_that_are_not_in_setA"}; + "_pass_no_elements_in_setA_that_are_not_in_setB" + expression => islessthan(length(difference_A_B), 1); + + "_pass_no_elements_in_setB_that_are_not_in_setA" + expression => islessthan(length(difference_B_A), 1); + + "__passif" + and => { + "_pass_same_length", + "_pass_no_elements_in_setA_that_are_not_in_setB", + "_pass_no_elements_in_setB_that_are_not_in_setA", + }; reports: DEBUG|EXTRA:: - - # We print each element of the list out individually on versions that didn't - # have the with attribute. No great way to specify a version less than a - # cfengine version. - "setA: $(setA)" if => eval( "$(sys.cf_version_minor) < 11", class, infix ); - "setB: $(setB)" if => eval( "$(sys.cf_version_minor) < 11", class, infix ); + # We print each element of the list out individually on versions that didn't + # have the with attribute. No great way to specify a version less than a + # cfengine version. + "setA: $(setA)" if => eval("$(sys.cf_version_minor) < 11", class, infix); + "setB: $(setB)" if => eval("$(sys.cf_version_minor) < 11", class, infix); @if minimum_version(3.11) - "setA: $(with)" with => join( ", ", setA ); - "setB: $(with)" with => join( ", ", setB ); + "setA: $(with)" with => join(", ", setA); + "setB: $(with)" with => join(", ", setB); @endif "setA and setB have the same number of elements" if => "_pass_same_length"; + "setA and setB do not have the same number of elements" if => not("_pass_same_length"); + "setA has $(length_A) elements and setB has $(length_B) ements" if => not("_pass_same_length"); "There are no elements in setA that are not in setB" if => "_pass_no_elements_in_setA_that_are_not_in_setB"; + "Element in setA that is not in setB: $(difference_A_B)" - if => not( "_pass_no_elements_in_setA_that_are_not_in_setB" ); + if => not("_pass_no_elements_in_setA_that_are_not_in_setB"); "There are no elements in setB that are not in setA" if => "_pass_no_elements_in_setB_that_are_not_in_setA"; + "Element in setB that is not in setA: $(difference_B_A)" - if => not( "_pass_no_elements_in_setB_that_are_not_in_setA" ); + if => not("_pass_no_elements_in_setB_that_are_not_in_setA"); __passif:: "$(test) Pass"; + !__passif:: "$(test) FAIL"; } ####################################################### # Test based on whether a string matches a regular expression - bundle agent dcs_check_regcmp(regex, thestring, test, expected_mismatch) # @brief Check if `regex` matches `thestring` Pass if they match, unless `expected_mismatch` is `true|yes`, in which case, FAIL # @param regex The regular expression to check `thestring` against @@ -771,40 +960,50 @@ bundle agent dcs_check_regcmp(regex, thestring, test, expected_mismatch) # @param expected_mismatch When `yes|true` the test will Pass if `regex` does not match `thestring` { classes: - "matched" expression => regcmp($(regex), $(thestring)); - "expected_mismatch" or => { strcmp($(expected_mismatch), "yes"), - strcmp($(expected_mismatch), "true") }; + "matched" expression => regcmp($(regex), $(thestring)); + + "expected_mismatch" + or => { + strcmp($(expected_mismatch), "yes"), + strcmp($(expected_mismatch), "true"), + }; + + "__passif" xor => { "matched", "expected_mismatch" }; - "__passif" xor => { "matched", "expected_mismatch" }; -reports: + reports: EXTRA|!__passif:: "$(this.bundle): REGEX: '$(regex)'"; "$(this.bundle): STRING TO MATCH: '$(thestring)'"; + __passif:: "$(test) Pass"; + !__passif:: "$(test) FAIL"; } ####################################################### # Pass the test if class - bundle agent dcs_passif(classname, test) { reports: - "$(test) Pass" if => $(classname); - "$(test) FAIL" if => not($(classname)); + "$(test) Pass" if => $(classname); + "$(test) FAIL" if => not($(classname)); EXTRA:: - "$(this.bundle): passing based on class '$(classname)'" if => $(classname); + "$(this.bundle): passing based on class '$(classname)'" + if => $(classname); + DEBUG:: - "$(this.bundle): failing based on class '$(classname)'" if => not($(classname)); + "$(this.bundle): failing based on class '$(classname)'" + if => not($(classname)); } bundle agent dcs_pass(test) { reports: - "$(test) Pass"; + "$(test) Pass"; + EXTRA:: "$(this.bundle): Explicitly passing..."; } @@ -812,7 +1011,8 @@ bundle agent dcs_pass(test) bundle agent dcs_fail(test) { reports: - "$(test) FAIL"; + "$(test) FAIL"; + EXTRA:: "$(this.bundle): Explicitly failing..."; } @@ -820,7 +1020,8 @@ bundle agent dcs_fail(test) bundle agent dcs_wait(test, seconds) { reports: - "$(test) Wait/$(seconds)"; + "$(test) Wait/$(seconds)"; + EXTRA:: "$(this.bundle): Explicitly waiting $(seconds) seconds..."; } @@ -828,14 +1029,17 @@ bundle agent dcs_wait(test, seconds) bundle agent dcs_passif_fileexists(file, test) { classes: - "__passif" expression => fileexists($(file)); + "__passif" expression => fileexists($(file)); methods: - "" usebundle => dcs_passif("__passif", $(test)), inherit => "true"; + "" + usebundle => dcs_passif("__passif", $(test)), + inherit => "true"; reports: DEBUG.!__passif:: "$(this.bundle): $(file) did not exist!"; + EXTRA.__passif:: "$(this.bundle): $(file) exists."; } @@ -843,14 +1047,17 @@ bundle agent dcs_passif_fileexists(file, test) bundle agent dcs_passif_file_absent(file, test) { classes: - "__passif" not => fileexists($(file)); + "__passif" not => fileexists($(file)); methods: - "" usebundle => dcs_passif("__passif", $(test)), inherit => "true"; + "" + usebundle => dcs_passif("__passif", $(test)), + inherit => "true"; reports: DEBUG.__passif:: "$(this.bundle): $(file) did not exist."; + EXTRA.!__passif:: "$(this.bundle): $(file) exists!"; } @@ -858,65 +1065,67 @@ bundle agent dcs_passif_file_absent(file, test) bundle agent dcs_passif_expected(expected, not_expected, test) { vars: - "ex" slist => splitstring($(expected), ",", 1000); - "notex" slist => splitstring($(not_expected), ",", 1000); - "e[$(ex)]" string => $(ex); - "e[$(notex)]" string => "!$(notex)"; - "classes" slist => getvalues(e); + "ex" slist => splitstring($(expected), ",", 1000); + "notex" slist => splitstring($(not_expected), ",", 1000); + "e[$(ex)]" string => $(ex); + "e[$(notex)]" string => "!$(notex)"; + "classes" slist => getvalues(e); classes: - "__passif" and => { @(classes) }; + "__passif" and => { @(classes) }; + methods: - "" usebundle => dcs_passif("__passif", $(test)), inherit => "true"; + "" + usebundle => dcs_passif("__passif", $(test)), + inherit => "true"; reports: DEBUG:: - "$(this.bundle): bad: $(ex) was NOT defined" - if => "!$(ex)"; - - "$(this.bundle): bad: $(notex) WAS defined" - if => "$(notex)"; + "$(this.bundle): bad: $(ex) was NOT defined" if => "!$(ex)"; + "$(this.bundle): bad: $(notex) WAS defined" if => "$(notex)"; EXTRA:: - "$(this.bundle): good: $(ex) WAS defined" - if => "$(ex)"; - - "$(this.bundle): good: $(notex) was NOT defined" - if => "!$(notex)"; + "$(this.bundle): good: $(ex) WAS defined" if => "$(ex)"; + "$(this.bundle): good: $(notex) was NOT defined" if => "!$(notex)"; } ####################################################### - bundle agent dcs_passif_output(wanted, unwanted, command, test) { vars: - "subout" string => execresult($(command), "useshell"), - meta => { "simulate_safe" }; + "subout" + string => execresult($(command), "useshell"), + meta => { "simulate_safe" }; classes: - "__passif_output_unwanted" expression => regcmp($(unwanted), $(subout)); - "__passif_output_wanted" expression => regcmp($(wanted), $(subout)); + "__passif_output_unwanted" expression => regcmp($(unwanted), $(subout)); + "__passif_output_wanted" expression => regcmp($(wanted), $(subout)); methods: - "" usebundle => dcs_passif_expected("__passif_output_wanted", # expected - "__passif_output_unwanted", # not expected - $(test)), + "" + usebundle => dcs_passif_expected( + "__passif_output_wanted", + # expected + "__passif_output_unwanted", + # not expected + $(test) + ), inherit => "true"; reports: DEBUG:: "$(this.bundle): bad: '$(wanted)' was NOT found in the output of '$(command)'" - if => "!__passif_output_wanted"; + if => "!__passif_output_wanted"; "$(this.bundle): bad: '$(unwanted)' WAS found in the output of '$(command)'" - if => "__passif_output_unwanted"; + if => "__passif_output_unwanted"; EXTRA:: "$(this.bundle): good: '$(wanted)' WAS found in the output of '$(command)'" - if => "__passif_output_wanted"; + if => "__passif_output_wanted"; "$(this.bundle): good: '$(unwanted)' was NOT found in the output of '$(command)'" - if => "!__passif_output_unwanted"; + if => "!__passif_output_unwanted"; DEBUG:: "$(this.bundle): the output of command '$(command)' was: '$(subout)'"; @@ -925,54 +1134,79 @@ bundle agent dcs_passif_output(wanted, unwanted, command, test) bundle agent dcs_passif_output1(wanted, command, test) { methods: - "" usebundle => dcs_passif_output($(wanted), # expected - "^(unlikely data){400}$", # not expected - $(command), - $(test)), + "" + usebundle => dcs_passif_output( + $(wanted), + # expected + "^(unlikely data){400}$", + # not expected + $(command), + $(test) + ), inherit => "true"; } bundle agent generate_key { classes: - "key_exists" expression => fileexists("$(sys.workdir)/ppkeys/localhost.pub"); + "key_exists" + expression => fileexists("$(sys.workdir)/ppkeys/localhost.pub"); + files: !key_exists:: "$(sys.workdir)/ppkeys/localhost.priv" create => "true", - copy_from => dcs_sync("$(this.promise_dirname)/root-MD5=617eb383deffef843ea856b129d0a423.priv"); + copy_from => dcs_sync( + "$(this.promise_dirname)/root-MD5=617eb383deffef843ea856b129d0a423.priv" + ); + "$(sys.workdir)/ppkeys/localhost.pub" create => "true", - copy_from => dcs_sync("$(this.promise_dirname)/root-MD5=617eb383deffef843ea856b129d0a423.pub"); + copy_from => dcs_sync( + "$(this.promise_dirname)/root-MD5=617eb383deffef843ea856b129d0a423.pub" + ); } bundle agent trust_key { classes: nova:: - "key_exists" expression => fileexists("$(sys.workdir)/ppkeys/root-SHA=ba71659fc294990d4f61ec1734515f89ce24524fbaeebad5b3f76da532da7390.pub"); + "key_exists" + expression => fileexists( + "$(sys.workdir)/ppkeys/root-SHA=ba71659fc294990d4f61ec1734515f89ce24524fbaeebad5b3f76da532da7390.pub" + ); + !nova:: - "key_exists" expression => fileexists("$(sys.workdir)/ppkeys/root-MD5=617eb383deffef843ea856b129d0a423.pub"); + "key_exists" + expression => fileexists( + "$(sys.workdir)/ppkeys/root-MD5=617eb383deffef843ea856b129d0a423.pub" + ); + files: !key_exists.nova:: "$(sys.workdir)/ppkeys/root-SHA=ba71659fc294990d4f61ec1734515f89ce24524fbaeebad5b3f76da532da7390.pub" create => "true", - copy_from => dcs_sync("$(this.promise_dirname)/root-MD5=617eb383deffef843ea856b129d0a423.pub"); + copy_from => dcs_sync( + "$(this.promise_dirname)/root-MD5=617eb383deffef843ea856b129d0a423.pub" + ); + !key_exists.!nova:: "$(sys.workdir)/ppkeys/root-MD5=617eb383deffef843ea856b129d0a423.pub" create => "true", - copy_from => dcs_sync("$(this.promise_dirname)/root-MD5=617eb383deffef843ea856b129d0a423.pub"); + copy_from => dcs_sync( + "$(this.promise_dirname)/root-MD5=617eb383deffef843ea856b129d0a423.pub" + ); } -body copy_from dcs_remote_cp(from,server, port) +body copy_from dcs_remote_cp(from, server, port) # @brief Download a file from a remote server. They server is always trusted. # # @param from The location of the file on the remote server # @param server The hostname or IP of the server from which to download { - servers => { "$(server)" }; - portnumber => "$(port)"; - source => "$(from)"; - compare => "mtime"; - trustkey => "true"; + servers => { "$(server)" }; + portnumber => "$(port)"; + source => "$(from)"; + compare => "mtime"; + trustkey => "true"; } diff --git a/tests/acceptance/default.sub.cf b/tests/acceptance/default.sub.cf index 40f15cc14d..0185e5328a 100644 --- a/tests/acceptance/default.sub.cf +++ b/tests/acceptance/default.sub.cf @@ -7,34 +7,30 @@ bundle common D { vars: any:: - "owndir" string => "$(this.promise_dirname)"; - # If not testing the masterfiles policy framework we want to include the # plucked bodies and bundles so that we have conveniant access to commonly # used bundles and bodies. !testing_masterfiles_policy_framework:: "inputs" slist => { - "$(D.owndir)$(const.dirsep)dcs.sub.cf", - "$(D.owndir)$(const.dirsep)plucked.sub.cf", - }; + "$(D.owndir)$(const.dirsep)dcs.sub.cf", + "$(D.owndir)$(const.dirsep)plucked.sub.cf", + }; # If testing the masterfiles policy framework then load the stdlib by # default so it can be leveraged as expected. testing_masterfiles_policy_framework:: "inputs" slist => { - "$(D.owndir)$(const.dirsep)dcs.sub.cf", - "$(D.owndir)$(const.dirsep)..$(const.dirsep)..$(const.dirsep)lib$(const.dirsep)stdlib.cf" - }; - - + "$(D.owndir)$(const.dirsep)dcs.sub.cf", + "$(D.owndir)$(const.dirsep)..$(const.dirsep)..$(const.dirsep)lib$(const.dirsep)stdlib.cf", + }; } body file control { - # plucked.sub.cf comes from the stdlib with `make pluck` - inputs => { @(D.inputs) }; + # plucked.sub.cf comes from the stdlib with `make pluck` + inputs => { @(D.inputs) }; } diff --git a/tests/acceptance/plucked.sub.cf b/tests/acceptance/plucked.sub.cf index 1d13802d9b..ef7bda1813 100644 --- a/tests/acceptance/plucked.sub.cf +++ b/tests/acceptance/plucked.sub.cf @@ -1,5 +1,4 @@ ### This is an auto-generated file, see Makefile.am and `make pluck` ### - bundle agent run_ifdefined(namespace, mybundle) # @brief bundle to maybe run another bundle dynamically # @param namespace the namespace, usually `$(this.namespace)` @@ -19,13 +18,13 @@ bundle agent run_ifdefined(namespace, mybundle) # ``` { vars: - "bundlesfound" slist => bundlesmatching("^$(namespace):$(mybundle)$"); - "count" int => length(bundlesfound); + "bundlesfound" slist => bundlesmatching("^$(namespace):$(mybundle)$"); + "count" int => length(bundlesfound); methods: - "any" + "any" usebundle => $(bundlesfound), - if => strcmp(1, $(count)); + if => strcmp(1, $(count)); reports: verbose_mode:: @@ -48,7 +47,7 @@ body contain powershell # # * Introduced in 3.17.0 { - useshell => "powershell"; + useshell => "powershell"; } body contain in_dir_shell(dir) @@ -63,8 +62,10 @@ body contain in_dir_shell(dir) # contain => in_dir_shell("/tmp"); # ``` { - chdir => "$(dir)"; - useshell => "true"; # canonical "useshell" but this is backwards-compatible + chdir => "$(dir)"; + useshell => "true"; + + # canonical "useshell" but this is backwards-compatible } body contain in_shell @@ -78,7 +79,9 @@ body contain in_shell # contain => in_shell; # ``` { - useshell => "true"; # canonical "useshell" but this is backwards-compatible + useshell => "true"; + + # canonical "useshell" but this is backwards-compatible } body contain in_shell_bg @@ -87,7 +90,9 @@ body contain in_shell_bg # parser strictness enhancements. Backgrounding is handeled by the body action # background attribute. { - useshell => "true"; # canonical "useshell" but this is backwards-compatible + useshell => "true"; + + # canonical "useshell" but this is backwards-compatible } body contain in_shell_and_silent @@ -102,8 +107,10 @@ body contain in_shell_and_silent # comment => "Silently run command in shell"; # ``` { - useshell => "true"; # canonical "useshell" but this is backwards-compatible - no_output => "true"; + useshell => "true"; + + # canonical "useshell" but this is backwards-compatible + no_output => "true"; } body contain in_dir_shell_and_silent(dir) @@ -118,26 +125,29 @@ body contain in_dir_shell_and_silent(dir) # contain => in_dir_shell_and_silent("/tmp"), # comment => "Silently run command in shell"; # ``` - { - useshell => "true"; # canonical "useshell" but this is backwards-compatible - no_output => "true"; - chdir => "$(dir)"; + useshell => "true"; + + # canonical "useshell" but this is backwards-compatible + no_output => "true"; + chdir => "$(dir)"; } body action if_elapsed(x) # @brief Evaluate the promise every `x` minutes # @param x The time in minutes between promise evaluations { - ifelapsed => "$(x)"; - expireafter => "$(x)"; + ifelapsed => "$(x)"; + expireafter => "$(x)"; } body action if_elapsed_day # @brief Evaluate the promise once every 24 hours { - ifelapsed => "1440"; # 60 x 24 - expireafter => "1400"; + ifelapsed => "1440"; + + # 60 x 24 + expireafter => "1400"; } body action warn_only @@ -145,21 +155,21 @@ body action warn_only # # The promise does not get repaired. { - action_policy => "warn"; - ifelapsed => "60"; + action_policy => "warn"; + ifelapsed => "60"; } body action immediate # @brief Evaluate the promise at every `cf-agent` execution. { - ifelapsed => "0"; + ifelapsed => "0"; } body classes if_repaired(x) # @brief Define class `x` if the promise has been repaired # @param x The name of the class { - promise_repaired => { "$(x)" }; + promise_repaired => { "$(x)" }; } body classes if_else(yes, no) @@ -167,47 +177,72 @@ body classes if_else(yes, no) # @param yes The name of the class that should be defined if the promise is kept or repaired # @param no The name of the class that should be defined if the promise could not be repaired { - promise_kept => { "$(yes)" }; - promise_repaired => { "$(yes)" }; - repair_failed => { "$(no)" }; - repair_denied => { "$(no)" }; - repair_timeout => { "$(no)" }; + promise_kept => { "$(yes)" }; + promise_repaired => { "$(yes)" }; + repair_failed => { "$(no)" }; + repair_denied => { "$(no)" }; + repair_timeout => { "$(no)" }; } body classes if_notkept(x) # @brief Define the class `x` if the promise is not kept and cannot be repaired. # @param x The name of the class that should be defined { - repair_failed => { "$(x)" }; - repair_denied => { "$(x)" }; - repair_timeout => { "$(x)" }; + repair_failed => { "$(x)" }; + repair_denied => { "$(x)" }; + repair_timeout => { "$(x)" }; } body classes if_ok(x) # @brief Define the class `x` if the promise is kept or repaired # @param x The name of the class that should be defined { - promise_repaired => { "$(x)" }; - promise_kept => { "$(x)" }; + promise_repaired => { "$(x)" }; + promise_kept => { "$(x)" }; } body classes if_ok_cancel(x) # @brief Cancel the class `x` if the promise is kept or repaired # @param x The name of the class that should be cancelled { - cancel_repaired => { "$(x)" }; - cancel_kept => { "$(x)" }; + cancel_repaired => { "$(x)" }; + cancel_kept => { "$(x)" }; } body classes classes_generic(x) # @brief Define `x` prefixed/suffixed with promise outcome # @param x The unique part of the classes to be defined { - promise_repaired => { "promise_repaired_$(x)", "$(x)_repaired", "$(x)_ok", "$(x)_reached" }; - repair_failed => { "repair_failed_$(x)", "$(x)_failed", "$(x)_not_ok", "$(x)_error", "$(x)_not_kept", "$(x)_reached" }; - repair_denied => { "repair_denied_$(x)", "$(x)_denied", "$(x)_not_ok", "$(x)_error", "$(x)_not_kept", "$(x)_reached" }; - repair_timeout => { "repair_timeout_$(x)", "$(x)_timeout", "$(x)_not_ok", "$(x)_error", "$(x)_not_kept", "$(x)_reached" }; - promise_kept => { "promise_kept_$(x)", "$(x)_kept", "$(x)_ok", "$(x)_reached" }; + promise_repaired => { + "promise_repaired_$(x)", "$(x)_repaired", "$(x)_ok", "$(x)_reached" + }; + repair_failed => { + "repair_failed_$(x)", + "$(x)_failed", + "$(x)_not_ok", + "$(x)_error", + "$(x)_not_kept", + "$(x)_reached", + }; + repair_denied => { + "repair_denied_$(x)", + "$(x)_denied", + "$(x)_not_ok", + "$(x)_error", + "$(x)_not_kept", + "$(x)_reached", + }; + repair_timeout => { + "repair_timeout_$(x)", + "$(x)_timeout", + "$(x)_not_ok", + "$(x)_error", + "$(x)_not_kept", + "$(x)_reached", + }; + promise_kept => { + "promise_kept_$(x)", "$(x)_kept", "$(x)_ok", "$(x)_reached" + }; } body classes results(scope, class_prefix) @@ -283,27 +318,26 @@ body classes results(scope, class_prefix) # **See also:** `scope`, `scoped_classes_generic`, `classes_generic` { scope => "$(scope)"; - - promise_kept => { "$(class_prefix)_reached", - "$(class_prefix)_kept" }; - - promise_repaired => { "$(class_prefix)_reached", - "$(class_prefix)_repaired" }; - - repair_failed => { "$(class_prefix)_reached", - "$(class_prefix)_error", - "$(class_prefix)_not_kept", - "$(class_prefix)_failed" }; - - repair_denied => { "$(class_prefix)_reached", - "$(class_prefix)_error", - "$(class_prefix)_not_kept", - "$(class_prefix)_denied" }; - - repair_timeout => { "$(class_prefix)_reached", - "$(class_prefix)_error", - "$(class_prefix)_not_kept", - "$(class_prefix)_timeout" }; + promise_kept => { "$(class_prefix)_reached", "$(class_prefix)_kept" }; + promise_repaired => { "$(class_prefix)_reached", "$(class_prefix)_repaired" }; + repair_failed => { + "$(class_prefix)_reached", + "$(class_prefix)_error", + "$(class_prefix)_not_kept", + "$(class_prefix)_failed", + }; + repair_denied => { + "$(class_prefix)_reached", + "$(class_prefix)_error", + "$(class_prefix)_not_kept", + "$(class_prefix)_denied", + }; + repair_timeout => { + "$(class_prefix)_reached", + "$(class_prefix)_error", + "$(class_prefix)_not_kept", + "$(class_prefix)_timeout", + }; } body classes diff_results(scope, x) @@ -337,9 +371,9 @@ body classes diff_results(scope, x) # } # ``` { - inherit_from => results( $(scope), $(x) ); - kept_returncodes => { "0" }; - failed_returncodes => { "1", "2" }; + inherit_from => results($(scope), $(x)); + kept_returncodes => { "0" }; + failed_returncodes => { "1", "2" }; } body classes scoped_classes_generic(scope, x) @@ -349,29 +383,54 @@ body classes scoped_classes_generic(scope, x) # @param scope The scope in which the class should be defined # @param x The unique part of the classes to be defined { - scope => "$(scope)"; - promise_repaired => { "promise_repaired_$(x)", "$(x)_repaired", "$(x)_ok", "$(x)_reached" }; - repair_failed => { "repair_failed_$(x)", "$(x)_failed", "$(x)_not_ok", "$(x)_error", "$(x)_not_kept", "$(x)_reached" }; - repair_denied => { "repair_denied_$(x)", "$(x)_denied", "$(x)_not_ok", "$(x)_error", "$(x)_not_kept", "$(x)_reached" }; - repair_timeout => { "repair_timeout_$(x)", "$(x)_timeout", "$(x)_not_ok", "$(x)_error", "$(x)_not_kept", "$(x)_reached" }; - promise_kept => { "promise_kept_$(x)", "$(x)_kept", "$(x)_ok", "$(x)_reached" }; + scope => "$(scope)"; + promise_repaired => { + "promise_repaired_$(x)", "$(x)_repaired", "$(x)_ok", "$(x)_reached" + }; + repair_failed => { + "repair_failed_$(x)", + "$(x)_failed", + "$(x)_not_ok", + "$(x)_error", + "$(x)_not_kept", + "$(x)_reached", + }; + repair_denied => { + "repair_denied_$(x)", + "$(x)_denied", + "$(x)_not_ok", + "$(x)_error", + "$(x)_not_kept", + "$(x)_reached", + }; + repair_timeout => { + "repair_timeout_$(x)", + "$(x)_timeout", + "$(x)_not_ok", + "$(x)_error", + "$(x)_not_kept", + "$(x)_reached", + }; + promise_kept => { + "promise_kept_$(x)", "$(x)_kept", "$(x)_ok", "$(x)_reached" + }; } body classes always(x) # @brief Define class `x` no matter what the outcome of the promise is # @param x The name of the class to be defined { - promise_repaired => { "$(x)" }; - promise_kept => { "$(x)" }; - repair_failed => { "$(x)" }; - repair_denied => { "$(x)" }; - repair_timeout => { "$(x)" }; + promise_repaired => { "$(x)" }; + promise_kept => { "$(x)" }; + repair_failed => { "$(x)" }; + repair_denied => { "$(x)" }; + repair_timeout => { "$(x)" }; } body classes kept_successful_command # @brief Set command to "kept" instead of "repaired" if it returns 0 { - kept_returncodes => { "0" }; + kept_returncodes => { "0" }; } bundle edit_line insert_before_if_no_line(before, string) @@ -379,12 +438,11 @@ bundle edit_line insert_before_if_no_line(before, string) # @param before The regular expression matching the line which `string` will be # inserted before # @param string The string to be prepended -# { insert_lines: - "$(string)" - location => before($(before)), - comment => "Prepend a line to the file if it doesn't already exist"; + "$(string)" + location => before($(before)), + comment => "Prepend a line to the file if it doesn't already exist"; } bundle edit_line insert_file(templatefile) @@ -393,8 +451,7 @@ bundle edit_line insert_file(templatefile) # @param templatefile The name of the file from which to import lines. { insert_lines: - - "$(templatefile)" + "$(templatefile)" comment => "Insert the template file into the file being edited", insert_type => "file"; } @@ -418,9 +475,7 @@ bundle edit_line lines_present(lines) # ``` { insert_lines: - - "$(lines)" - comment => "Append lines if they don't exist"; + "$(lines)" comment => "Append lines if they don't exist"; } bundle edit_line insert_lines(lines) @@ -428,9 +483,7 @@ bundle edit_line insert_lines(lines) # @param lines List or string that should be present in the file { insert_lines: - - "$(lines)" - comment => "Append lines if they don't exist"; + "$(lines)" comment => "Append lines if they don't exist"; } bundle edit_line append_if_no_line(lines) @@ -438,9 +491,7 @@ bundle edit_line append_if_no_line(lines) # @param lines List or string that should be present in the file { insert_lines: - - "$(lines)" - comment => "Append lines if they don't exist"; + "$(lines)" comment => "Append lines if they don't exist"; } bundle edit_line append_if_no_lines(lines) @@ -448,20 +499,16 @@ bundle edit_line append_if_no_lines(lines) # @param lines List or string that should be present in the file { insert_lines: - - "$(lines)" - comment => "Append lines if they don't exist"; + "$(lines)" comment => "Append lines if they don't exist"; } -bundle edit_line comment_lines_matching(regex,comment) +bundle edit_line comment_lines_matching(regex, comment) # @brief Comment lines in the file that matching an [anchored] regex # @param regex Anchored regex that the entire line needs to match # @param comment A string that is prepended to matching lines { replace_patterns: - - "^($(regex))$" - + "^($(regex))$" replace_with => comment("$(comment)"), comment => "Search and replace string"; } @@ -473,51 +520,44 @@ bundle edit_line contains_literal_string(string) # @param string The string (potentially multiline) to ensure exists in the # promised file. { - - insert_lines: - "$(string)" - insert_type => "preserve_block", - expand_scalars => "false", - whitespace_policy => { "exact_match" }; + insert_lines: + "$(string)" + insert_type => "preserve_block", + expand_scalars => "false", + whitespace_policy => { "exact_match" }; } -bundle edit_line uncomment_lines_matching(regex,comment) +bundle edit_line uncomment_lines_matching(regex, comment) # @brief Uncomment lines of the file where the regex matches # the entire text after the comment string # @param regex The regex that lines need to match after `comment` # @param comment The prefix of the line that is removed { replace_patterns: - - "^$(comment)\s?($(regex))$" - + "^$(comment)\s?($(regex))$" replace_with => uncomment, comment => "Uncomment lines matching a regular expression"; } -bundle edit_line comment_lines_containing(regex,comment) +bundle edit_line comment_lines_containing(regex, comment) # @brief Comment lines of the file matching a regex # @param regex A regex that a part of the line needs to match # @param comment A string that is prepended to matching lines { replace_patterns: - - "^((?!$(comment)).*$(regex).*)$" - + "^((?!$(comment)).*$(regex).*)$" replace_with => comment("$(comment)"), comment => "Comment out lines in a file"; } -bundle edit_line uncomment_lines_containing(regex,comment) +bundle edit_line uncomment_lines_containing(regex, comment) # @brief Uncomment lines of the file where the regex matches # parts of the text after the comment string # @param regex The regex that lines need to match after `comment` # @param comment The prefix of the line that is removed { replace_patterns: - - "^$(comment)\s?(.*$(regex).*)$" - + "^$(comment)\s?(.*$(regex).*)$" replace_with => uncomment, comment => "Uncomment a line containing a fragment"; } @@ -527,10 +567,7 @@ bundle edit_line delete_lines_matching(regex) # @param regex The regular expression that the lines need to match { delete_lines: - - "$(regex)" - - comment => "Delete lines matching regular expressions"; + "$(regex)" comment => "Delete lines matching regular expressions"; } bundle edit_line warn_lines_matching(regex) @@ -538,9 +575,7 @@ bundle edit_line warn_lines_matching(regex) # @param regex The regular expression that the lines need to match { delete_lines: - - "$(regex)" - + "$(regex)" comment => "Warn about lines in a file", action => warn_only; } @@ -555,12 +590,12 @@ bundle edit_line prepend_if_no_line(string) # * [`edit_line` bundles][edit_line] { insert_lines: - "$(string)" + "$(string)" location => start, comment => "Prepend a line to the file if it doesn't already exist"; } -bundle edit_line replace_line_end(start,end) +bundle edit_line replace_line_end(start, end) # @brief Give lines starting with `start` the ending given in `end` # # Whitespaces will be left unmodified. For example, @@ -576,13 +611,12 @@ bundle edit_line replace_line_end(start,end) # @param end The string lines should end with { field_edits: - - "\s*$(start)\s.*" + "\s*$(start)\s.*" comment => "Replace lines with $(this.start) and $(this.end)", - edit_field => line("(^|\s)$(start)\s*", "2", "$(end)","set"); + edit_field => line("(^|\s)$(start)\s*", "2", "$(end)", "set"); } -bundle edit_line replace_uncommented_substrings( _comment, _find, _replace ) +bundle edit_line replace_uncommented_substrings(_comment, _find, _replace) # @brief Replace all occurrences of `_find` with `_replace` on lines that do not follow a `_comment` # @param _comment Sequence of characters, each indicating the start of a comment. # @param _find String matching substring to replace @@ -609,15 +643,15 @@ bundle edit_line replace_uncommented_substrings( _comment, _find, _replace ) # * Introduced 3.17.0, 3.15.3 { vars: - "_reg_match_uncommented_lines_containing_find" - string => "^([^$(_comment)]*)\Q$(_find)\E(.*$)"; + "_reg_match_uncommented_lines_containing_find" + string => "^([^$(_comment)]*)\Q$(_find)\E(.*$)"; replace_patterns: "$(_reg_match_uncommented_lines_containing_find)" - replace_with => text_between_match1_and_match2( $(_replace) ); + replace_with => text_between_match1_and_match2($(_replace)); } -bundle edit_line append_to_line_end(start,end) +bundle edit_line append_to_line_end(start, end) # @brief Append `end` to any lines beginning with `start` # # `end` will be appended to all lines starting with `start` and not @@ -641,29 +675,26 @@ bundle edit_line append_to_line_end(start,end) # files: # "/tmp/boot-options" edit_line => append_to_line_end("kernel", "vga=791"); # ``` -# { field_edits: - - "\s*$(start)\s.*" + "\s*$(start)\s.*" comment => "Append lines with $(this.start) and $(this.end)", - edit_field => line("(^|\s)$(start)\s*", "2", "$(end)","append"); + edit_field => line("(^|\s)$(start)\s*", "2", "$(end)", "append"); } -bundle edit_line regex_replace(find,replace) +bundle edit_line regex_replace(find, replace) # @brief Find exactly a regular expression and replace exactly the match with a string. # You can think of this like a PCRE powered sed. # @param find The regular expression # @param replace The replacement string { replace_patterns: - - "$(find)" + "$(find)" replace_with => value("$(replace)"), comment => "Search and replace string"; } -bundle edit_line resolvconf(search,list) +bundle edit_line resolvconf(search, list) # @brief Adds search domains and name servers to the system # resolver configuration. # @@ -674,17 +705,15 @@ bundle edit_line resolvconf(search,list) # @param list An slist of nameserver addresses { delete_lines: - - "search.*" comment => "Reset search lines from resolver"; - "nameserver.*" comment => "Reset nameservers in resolver"; + "search.*" comment => "Reset search lines from resolver"; + "nameserver.*" comment => "Reset nameservers in resolver"; insert_lines: - - "search $(search)" comment => "Add search domains to resolver"; - "nameserver $(list)" comment => "Add name servers to resolver"; + "search $(search)" comment => "Add search domains to resolver"; + "nameserver $(list)" comment => "Add name servers to resolver"; } -bundle edit_line resolvconf_o(search,list,options) +bundle edit_line resolvconf_o(search, list, options) # @brief Adds search domains, name servers and options to the system # resolver configuration. # @@ -694,19 +723,16 @@ bundle edit_line resolvconf_o(search,list,options) # @param search The search domains with space # @param list An slist of nameserver addresses # @param options is an slist of variables to modify the resolver - { delete_lines: - - "search.*" comment => "Reset search lines from resolver"; - "nameserver.*" comment => "Reset nameservers in resolver"; - "options.*" comment => "Reset options in resolver"; + "search.*" comment => "Reset search lines from resolver"; + "nameserver.*" comment => "Reset nameservers in resolver"; + "options.*" comment => "Reset options in resolver"; insert_lines: - - "search $(search)" comment => "Add search domains to resolver"; - "nameserver $(list)" comment => "Add name servers to resolver"; - "options $(options)" comment => "Add options to resolver"; + "search $(search)" comment => "Add search domains to resolver"; + "nameserver $(list)" comment => "Add name servers to resolver"; + "options $(options)" comment => "Add options to resolver"; } bundle edit_line manage_variable_values_ini(tab, sectionName) @@ -725,19 +751,19 @@ bundle edit_line manage_variable_values_ini(tab, sectionName) # **See also:** `set_variable_values_ini()` { vars: - "index" slist => getindices("$(tab)[$(sectionName)]"); + "index" slist => getindices("$(tab)[$(sectionName)]"); delete_lines: - ".*" + ".*" select_region => INI_section(escape("$(sectionName)")), - comment => "Remove all entries in the region so there are no extra entries"; + comment => "Remove all entries in the region so there are no extra entries"; insert_lines: - "[$(sectionName)]" + "[$(sectionName)]" location => start, comment => "Insert lines"; - "$(index)=$($(tab)[$(sectionName)][$(index)])" + "$(index)=$($(tab)[$(sectionName)][$(index)])" select_region => INI_section(escape("$(sectionName)")); } @@ -756,39 +782,42 @@ bundle edit_line set_variable_values_ini(tab, sectionName) # **See also:** `manage_variable_values_ini()` { vars: - "index" slist => getindices("$(tab)[$(sectionName)]"); + "index" slist => getindices("$(tab)[$(sectionName)]"); - # Be careful if the index string contains funny chars - "cindex[$(index)]" string => canonify("$(index)"); + # Be careful if the index string contains funny chars + "cindex[$(index)]" string => canonify("$(index)"); classes: - "edit_$(cindex[$(index)])" not => strcmp("$($(tab)[$(sectionName)][$(index)])","dontchange"), + "edit_$(cindex[$(index)])" + not => strcmp("$($(tab)[$(sectionName)][$(index)])", "dontchange"), comment => "Create conditions to make changes"; field_edits: - - # If the line is there, but commented out, first uncomment it - "#+\s*$(index)\s*=.*" + # If the line is there, but commented out, first uncomment it + "#+\s*$(index)\s*=.*" select_region => INI_section(escape("$(sectionName)")), - edit_field => col("\s*=\s*","1","$(index)","set"), + edit_field => col("\s*=\s*", "1", "$(index)", "set"), if => "edit_$(cindex[$(index)])"; - # match a line starting like the key something - "\s*$(index)\s*=.*" - edit_field => col("\s*=\s*","2","$($(tab)[$(sectionName)][$(index)])","set"), + # match a line starting like the key something + "\s*$(index)\s*=.*" + edit_field => col( + "\s*=\s*", "2", "$($(tab)[$(sectionName)][$(index)])", "set" + ), select_region => INI_section(escape("$(sectionName)")), - classes => results("bundle", "set_variable_values_ini_not_$(cindex[$(index)])"), + classes => results( + "bundle", "set_variable_values_ini_not_$(cindex[$(index)])" + ), if => "edit_$(cindex[$(index)])"; insert_lines: - "[$(sectionName)]" + "[$(sectionName)]" location => start, comment => "Insert lines"; - "$(index)=$($(tab)[$(sectionName)][$(index)])" + "$(index)=$($(tab)[$(sectionName)][$(index)])" select_region => INI_section(escape("$(sectionName)")), - if => "!(set_variable_values_ini_not_$(cindex[$(index)])_kept|set_variable_values_ini_not_$(cindex[$(index)])_repaired).edit_$(cindex[$(index)])"; - + if => "!(set_variable_values_ini_not_$(cindex[$(index)])_kept|set_variable_values_ini_not_$(cindex[$(index)])_repaired).edit_$(cindex[$(index)])"; } bundle edit_line insert_ini_section(name, config) @@ -807,17 +836,16 @@ bundle edit_line insert_ini_section(name, config) # @param config The fully-qualified name of an associative array containing `v[LHS]="rhs"` { vars: - # TODO: refactor once 3.7.x is EOL - "indices" slist => getindices($(config)); - "k" slist => sort("indices", lex); + # TODO: refactor once 3.7.x is EOL + "indices" slist => getindices($(config)); + "k" slist => sort("indices", lex); insert_lines: - "[$(name)]" + "[$(name)]" location => start, comment => "Insert an ini section with values if not present"; - "$(k)=$($(config)[$(k)])" - location => after("[$(name)]"); + "$(k)=$($(config)[$(k)])" location => after("[$(name)]"); } bundle edit_line set_quoted_values(v) @@ -847,35 +875,33 @@ bundle edit_line set_quoted_values(v) # **See also:** `set_variable_values()` { meta: - "tags" - slist => - { + "tags" + slist => { "deprecated=3.6.0", "deprecation-reason=Generic reimplementation", - "replaced-by=set_line_based" + "replaced-by=set_line_based", }; vars: - "index" slist => getindices("$(v)"); - # Be careful if the index string contains funny chars + "index" slist => getindices("$(v)"); - "cindex[$(index)]" string => canonify("$(index)"); + # Be careful if the index string contains funny chars + "cindex[$(index)]" string => canonify("$(index)"); field_edits: - # If the line is there, but commented out, first uncomment it - "#+\s*$(index)\s*=.*" - edit_field => col("=","1","$(index)","set"); + # If the line is there, but commented out, first uncomment it + "#+\s*$(index)\s*=.*" edit_field => col("=", "1", "$(index)", "set"); - # match a line starting like the key = something - "\s*$(index)\s*=.*" - edit_field => col("=","2",'"$($(v)[$(index)])"',"set"), - classes => results("bundle", "$(cindex[$(index)])_in_file"), - comment => "Match a line starting like key = something"; + # match a line starting like the key = something + "\s*$(index)\s*=.*" + edit_field => col("=", "2", '"$($(v)[$(index)])"', "set"), + classes => results("bundle", "$(cindex[$(index)])_in_file"), + comment => "Match a line starting like key = something"; insert_lines: - '$(index)="$($(v)[$(index)])"' - comment => "Insert a variable definition", - if => "!($(cindex[$(index)])_in_file_kept|$(cindex[$(index)])_in_file_repaired)"; + '$(index)="$($(v)[$(index)])"' + comment => "Insert a variable definition", + if => "!($(cindex[$(index)])_in_file_kept|$(cindex[$(index)])_in_file_repaired)"; } bundle edit_line set_variable_values(v) @@ -905,39 +931,31 @@ bundle edit_line set_variable_values(v) # **See also:** `set_quoted_values()` { meta: - "tags" - slist => - { + "tags" + slist => { "deprecated=3.6.0", "deprecation-reason=Generic reimplementation", - "replaced-by=set_line_based" + "replaced-by=set_line_based", }; vars: + "index" slist => getindices("$(v)"); - "index" slist => getindices("$(v)"); - - # Be careful if the index string contains funny chars - - "cindex[$(index)]" string => canonify("$(index)"); - "cv" string => canonify("$(v)"); + # Be careful if the index string contains funny chars + "cindex[$(index)]" string => canonify("$(index)"); + "cv" string => canonify("$(v)"); field_edits: - - # match a line starting like the key = something - - "\s*$(index)\s*=.*" - - edit_field => col("\s*$(index)\s*=","2","$($(v)[$(index)])","set"), + # match a line starting like the key = something + "\s*$(index)\s*=.*" + edit_field => col("\s*$(index)\s*=", "2", "$($(v)[$(index)])", "set"), classes => results("bundle", "$(cv)_$(cindex[$(index)])_in_file"), comment => "Match a line starting like key = something"; insert_lines: - - "$(index)=$($(v)[$(index)])" - + "$(index)=$($(v)[$(index)])" comment => "Insert a variable definition", - if => "!($(cv)_$(cindex[$(index)])_in_file_kept|$(cv)_$(cindex[$(index)])_in_file_repaired)"; + if => "!($(cv)_$(cindex[$(index)])_in_file_kept|$(cv)_$(cindex[$(index)])_in_file_repaired)"; } bundle edit_line set_config_values(v) @@ -954,75 +972,76 @@ bundle edit_line set_config_values(v) # @param v The fully-qualified name of an associative array containing `v[LHS]="rhs"` { meta: - "tags" - slist => - { + "tags" + slist => { "deprecated=3.6.0", "deprecation-reason=Generic reimplementation", - "replaced-by=set_line_based" + "replaced-by=set_line_based", }; vars: - "index" slist => getindices("$(v)"); - - # Be careful if the index string contains funny chars - "cindex[$(index)]" string => canonify("$(index)"); + "index" slist => getindices("$(v)"); - # Escape the value (had a problem with special characters and regex's) - "ev[$(index)]" string => escape("$($(v)[$(index)])"); + # Be careful if the index string contains funny chars + "cindex[$(index)]" string => canonify("$(index)"); - # Do we have more than one line commented out? - "index_comment_matches_$(cindex[$(index)])" - int => countlinesmatching("^\s*#\s*($(index)\s+.*|$(index))$","$(edit.filename)"); + # Escape the value (had a problem with special characters and regex's) + "ev[$(index)]" string => escape("$($(v)[$(index)])"); + # Do we have more than one line commented out? + "index_comment_matches_$(cindex[$(index)])" + int => countlinesmatching( + "^\s*#\s*($(index)\s+.*|$(index))$", "$(edit.filename)" + ); classes: - # Check to see if this line exists - "line_exists_$(cindex[$(index)])" - expression => regline("^\s*($(index)\s.*|$(index))$","$(edit.filename)"), - scope => "bundle"; - - # if there's more than one comment, just add new (don't know who to use) - "multiple_comments_$(cindex[$(index)])" - expression => isgreaterthan("$(index_comment_matches_$(cindex[$(index)]))","1"), - scope => "bundle"; + # Check to see if this line exists + "line_exists_$(cindex[$(index)])" + expression => regline("^\s*($(index)\s.*|$(index))$", "$(edit.filename)"), + scope => "bundle"; + + # if there's more than one comment, just add new (don't know who to use) + "multiple_comments_$(cindex[$(index)])" + expression => isgreaterthan( + "$(index_comment_matches_$(cindex[$(index)]))", "1" + ), + scope => "bundle"; replace_patterns: - # If the line is commented out, uncomment and replace with - # the correct value - "^\s*#\s*($(index)\s+.*|$(index))$" - comment => "If we find a single commented entry we can uncomment it to + # If the line is commented out, uncomment and replace with + # the correct value + "^\s*#\s*($(index)\s+.*|$(index))$" + comment => "If we find a single commented entry we can uncomment it to keep the settings near any inline documentation. If there are multiple comments, then we don't try to replace them and instead will later append the new value after the first commented occurrence of $(index).", - handle => "set_config_values_replace_commented_line", - replace_with => value("$(index) $($(v)[$(index)])"), - if => "!line_exists_$(cindex[$(index)]).!replace_attempted_$(cindex[$(index)])_reached.!multiple_comments_$(cindex[$(index)])", - classes => results("bundle", "uncommented_$(cindex[$(index)])"); - - # If the line is there with the wrong value, replace with - # the correct value - "^\s*($(index)\s+(?!$(ev[$(index)])$).*|$(index))$" - comment => "Correct the value $(index)", + handle => "set_config_values_replace_commented_line", replace_with => value("$(index) $($(v)[$(index)])"), - classes => results("bundle", "replace_attempted_$(cindex[$(index)])"); + if => "!line_exists_$(cindex[$(index)]).!replace_attempted_$(cindex[$(index)])_reached.!multiple_comments_$(cindex[$(index)])", + classes => results("bundle", "uncommented_$(cindex[$(index)])"); - insert_lines: - # If the line doesn't exist, or there is more than one occurrence - # of the LHS commented out, insert a new line and try to place it - # after the commented LHS (keep new line with old comments) - "$(index) $($(v)[$(index)])" - comment => "Insert the value, marker exists $(index)", - location => after("^\s*#\s*($(index)\s+.*|$(index))$"), - if => "replace_attempted_$(cindex[$(index)])_reached.multiple_comments_$(cindex[$(index)])"; + # If the line is there with the wrong value, replace with + # the correct value + "^\s*($(index)\s+(?!$(ev[$(index)])$).*|$(index))$" + comment => "Correct the value $(index)", + replace_with => value("$(index) $($(v)[$(index)])"), + classes => results("bundle", "replace_attempted_$(cindex[$(index)])"); - # If the line doesn't exist and there are no occurrences - # of the LHS commented out, insert a new line at the eof - "$(index) $($(v)[$(index)])" - comment => "Insert the value, marker doesn't exist $(index)", - if => "replace_attempted_$(cindex[$(index)])_reached.!multiple_comments_$(cindex[$(index)])"; + insert_lines: + # If the line doesn't exist, or there is more than one occurrence + # of the LHS commented out, insert a new line and try to place it + # after the commented LHS (keep new line with old comments) + "$(index) $($(v)[$(index)])" + comment => "Insert the value, marker exists $(index)", + location => after("^\s*#\s*($(index)\s+.*|$(index))$"), + if => "replace_attempted_$(cindex[$(index)])_reached.multiple_comments_$(cindex[$(index)])"; + # If the line doesn't exist and there are no occurrences + # of the LHS commented out, insert a new line at the eof + "$(index) $($(v)[$(index)])" + comment => "Insert the value, marker doesn't exist $(index)", + if => "replace_attempted_$(cindex[$(index)])_reached.!multiple_comments_$(cindex[$(index)])"; } bundle edit_line set_line_based(v, sep, bp, kp, cp) @@ -1050,8 +1069,6 @@ bundle edit_line set_line_based(v, sep, bp, kp, cp) # # Adds a new line if none exists or if more than one commented-out # possible matches exist. -# -# # **Note:** If the data structure being used for the first parameter is in the current bundle, you can use `$(this.bundle).variable`. # # Originally `set_config_values` by Ed King. @@ -1063,9 +1080,8 @@ bundle edit_line set_line_based(v, sep, bp, kp, cp) # @param cp The comment pattern from line-start, e.g. `\s*#\s*` { meta: - "tags" - slist => - { + "tags" + slist => { "replaces=set_config_values", "replaces=set_config_values_matching", "replaces=set_variable_values", @@ -1074,94 +1090,86 @@ bundle edit_line set_line_based(v, sep, bp, kp, cp) }; vars: - "vkeys" slist => getindices("$(v)"); - "i" slist => grep($(kp), vkeys); + "vkeys" slist => getindices("$(v)"); + "i" slist => grep($(kp), vkeys); - # Be careful if the index string contains funny chars - "ci[$(i)]" string => canonify("$(i)"); + # Be careful if the index string contains funny chars + "ci[$(i)]" string => canonify("$(i)"); - # Escape the value (had a problem with special characters and regex's) - "ev[$(i)]" string => escape("$($(v)[$(i)])"); - - # Do we have more than one line commented out? - "comment_matches_$(ci[$(i)])" - int => countlinesmatching("^$(cp)($(i)$(bp).*|$(i))$", - $(edit.filename)); + # Escape the value (had a problem with special characters and regex's) + "ev[$(i)]" string => escape("$($(v)[$(i)])"); + # Do we have more than one line commented out? + "comment_matches_$(ci[$(i)])" + int => countlinesmatching("^$(cp)($(i)$(bp).*|$(i))$", $(edit.filename)); classes: - # 3.21.0 and greater know about a file being emptied before editing and - # skip this check since it does not make sense. + # 3.21.0 and greater know about a file being emptied before editing and + # skip this check since it does not make sense. @if minimum_version(3.21) - # Check to see if this line exists - "exists_$(ci[$(i)])" - expression => regline("^\s*($(i)$(bp).*|$(i))$", - $(edit.filename)), - unless => strcmp( "true", $(edit.empty_before_use) ); + # Check to see if this line exists + "exists_$(ci[$(i)])" + expression => regline("^\s*($(i)$(bp).*|$(i))$", $(edit.filename)), + unless => strcmp("true", $(edit.empty_before_use)); @endif - @if minimum_version(3.18) !(cfengine_3_18_0|cfengine_3_18_1|cfengine_3_18_2):: "exists_$(ci[$(i)])" - expression => regline("^\s*($(i)$(bp).*|$(i))$", - $(edit.filename)), - unless => strcmp( "true", $(edit.empty_before_use) ); + expression => regline("^\s*($(i)$(bp).*|$(i))$", $(edit.filename)), + unless => strcmp("true", $(edit.empty_before_use)); @endif - (cfengine_3_15|cfengine_3_16|cfengine_3_17|cfengine_3_18_0|cfengine_3_18_1|cfengine_3_18_2|cfengine_3_19|cfengine_3_20):: # Version 3.15.0 does not know about the before_version macro, so we keep the same behavior # TODO Remove after 3.21 is no longer supported. (3.15.0 was supported when 3.21 was released) # Check to see if this line exists "exists_$(ci[$(i)])" - expression => regline("^\s*($(i)$(bp).*|$(i))$", - $(edit.filename)); + expression => regline("^\s*($(i)$(bp).*|$(i))$", $(edit.filename)); any:: - # if there's more than one comment, just add new (don't know who to use) "multiple_comments_$(ci[$(i)])" - expression => isgreaterthan("$(comment_matches_$(ci[$(i)]))", - "1"); - + expression => isgreaterthan("$(comment_matches_$(ci[$(i)]))", "1"); replace_patterns: - # If the line is commented out, uncomment and replace with - # the correct value - "^$(cp)($(i)$(bp).*|$(i))$" - comment => "Uncommented the value '$(i)'", - replace_with => value("$(i)$(sep)$($(v)[$(i)])"), - if => "!exists_$(ci[$(i)]).!replace_attempted_$(ci[$(i)])_reached.!multiple_comments_$(ci[$(i)])", - classes => results("bundle", "uncommented_$(ci[$(i)])"); - - # If the line is there with the wrong value, replace with - # the correct value - "^\s*($(i)$(bp)(?!$(ev[$(i)])$).*|$(i))$" - comment => "Correct the value '$(i)'", + # If the line is commented out, uncomment and replace with + # the correct value + "^$(cp)($(i)$(bp).*|$(i))$" + comment => "Uncommented the value '$(i)'", + replace_with => value("$(i)$(sep)$($(v)[$(i)])"), + if => "!exists_$(ci[$(i)]).!replace_attempted_$(ci[$(i)])_reached.!multiple_comments_$(ci[$(i)])", + classes => results("bundle", "uncommented_$(ci[$(i)])"); + + # If the line is there with the wrong value, replace with + # the correct value + "^\s*($(i)$(bp)(?!$(ev[$(i)])$).*|$(i))$" + comment => "Correct the value '$(i)'", replace_with => value("$(i)$(sep)$($(v)[$(i)])"), - classes => results("bundle", "replace_attempted_$(ci[$(i)])"); + classes => results("bundle", "replace_attempted_$(ci[$(i)])"); insert_lines: - # If the line doesn't exist, or there is more than one occurrence - # of the LHS commented out, insert a new line and try to place it - # after the commented LHS (keep new line with old comments) - "$(i)$(sep)$($(v)[$(i)])" - comment => "Insert the value, marker '$(i)' exists", - location => after("^$(cp)($(i)$(bp).*|$(i))$"), - if => "replace_attempted_$(ci[$(i)])_reached.multiple_comments_$(ci[$(i)])"; - - # If the line doesn't exist and there are no occurrences - # of the LHS commented out, insert a new line at the eof - "$(i)$(sep)$($(v)[$(i)])" - comment => "Insert the value, marker '$(i)' doesn't exist", - if => "replace_attempted_$(ci[$(i)])_reached.!multiple_comments_$(ci[$(i)]).!exists_$(ci[$(i)])"; + # If the line doesn't exist, or there is more than one occurrence + # of the LHS commented out, insert a new line and try to place it + # after the commented LHS (keep new line with old comments) + "$(i)$(sep)$($(v)[$(i)])" + comment => "Insert the value, marker '$(i)' exists", + location => after("^$(cp)($(i)$(bp).*|$(i))$"), + if => "replace_attempted_$(ci[$(i)])_reached.multiple_comments_$(ci[$(i)])"; + + # If the line doesn't exist and there are no occurrences + # of the LHS commented out, insert a new line at the eof + "$(i)$(sep)$($(v)[$(i)])" + comment => "Insert the value, marker '$(i)' doesn't exist", + if => "replace_attempted_$(ci[$(i)])_reached.!multiple_comments_$(ci[$(i)]).!exists_$(ci[$(i)])"; reports: verbose_mode|EXTRA:: "$(this.bundle): Line for '$(i)' exists" if => "exists_$(ci[$(i)])"; - "$(this.bundle): Line for '$(i)' does not exist" if => "!exists_$(ci[$(i)])"; + + "$(this.bundle): Line for '$(i)' does not exist" + if => "!exists_$(ci[$(i)])"; } -bundle edit_line set_config_values_matching(v,pat) +bundle edit_line set_config_values_matching(v, pat) # @brief Sets the RHS of configuration items in the file of the form # # ``` @@ -1175,73 +1183,72 @@ bundle edit_line set_config_values_matching(v,pat) # @param pat Only elements of `v` that match the regex `pat` are use { meta: - "tags" - slist => - { + "tags" + slist => { "deprecated=3.6.0", "deprecation-reason=Generic reimplementation", - "replaced-by=set_line_based" + "replaced-by=set_line_based", }; vars: - "allparams" slist => getindices("$(v)"); - "index" slist => grep("$(pat)", "allparams"); + "allparams" slist => getindices("$(v)"); + "index" slist => grep("$(pat)", "allparams"); - # Be careful if the index string contains funny chars - "cindex[$(index)]" string => canonify("$(index)"); + # Be careful if the index string contains funny chars + "cindex[$(index)]" string => canonify("$(index)"); replace_patterns: - # If the line is there, maybe commented out, uncomment and replace with - # the correct value - "^\s*($(index)\s+(?!$($(v)[$(index)])).*|# ?$(index)\s+.*)$" + # If the line is there, maybe commented out, uncomment and replace with + # the correct value + "^\s*($(index)\s+(?!$($(v)[$(index)])).*|# ?$(index)\s+.*)$" comment => "Correct the value", replace_with => value("$(index) $($(v)[$(index)])"), classes => results("bundle", "replace_attempted_$(cindex[$(index)])"); insert_lines: - "$(index) $($(v)[$(index)])" + "$(index) $($(v)[$(index)])" if => "replace_attempted_$(cindex[$(index)])_reached"; - } -bundle edit_line maintain_key_values(v,sep) +bundle edit_line maintain_key_values(v, sep) # @brief Sets the RHS of configuration items with an giving separator # # Contributed by David Lee { meta: - "tags" - slist => - { + "tags" + slist => { "deprecated=3.6.0", "deprecation-reason=Generic reimplementation", - "replaced-by=set_line_based" + "replaced-by=set_line_based", }; vars: - "index" slist => getindices("$(v)"); - # Be careful if the index string contains funny chars - "cindex[$(index)]" string => canonify("$(index)"); - # Matching pattern for line (basically key-and-separator) - "keypat[$(index)]" string => "\s*$(index)\s*$(sep)\s*"; + "index" slist => getindices("$(v)"); + + # Be careful if the index string contains funny chars + "cindex[$(index)]" string => canonify("$(index)"); + + # Matching pattern for line (basically key-and-separator) + "keypat[$(index)]" string => "\s*$(index)\s*$(sep)\s*"; - # Values may contain regexps. Escape them for replace_pattern matching. - "ve[$(index)]" string => escape("$($(v)[$(index)])"); + # Values may contain regexps. Escape them for replace_pattern matching. + "ve[$(index)]" string => escape("$($(v)[$(index)])"); classes: - "$(cindex[$(index)])_key_in_file" + "$(cindex[$(index)])_key_in_file" comment => "Dynamic Class created if patterns matching", expression => regline("^$(keypat[$(index)]).*", "$(edit.filename)"); replace_patterns: - # For convergence need to use negative lookahead on value: - # "key sep (?!value).*" - "^($(keypat[$(index)]))(?!$(ve[$(index)])$).*" + # For convergence need to use negative lookahead on value: + # "key sep (?!value).*" + "^($(keypat[$(index)]))(?!$(ve[$(index)])$).*" comment => "Replace definition of $(index)", replace_with => value("$(match.1)$($(v)[$(index)])"); insert_lines: - "$(index)$(sep)$($(v)[$(index)])" + "$(index)$(sep)$($(v)[$(index)])" comment => "Insert definition of $(index)", if => "!$(cindex[$(index)])_key_in_file"; } @@ -1254,18 +1261,15 @@ bundle edit_line append_users_starting(v) # consider making `users` promises instead of modifying system files. { vars: - - "index" slist => getindices("$(v)"); + "index" slist => getindices("$(v)"); classes: - - "add_$(index)" not => userexists("$(index)"), + "add_$(index)" + not => userexists("$(index)"), comment => "Class created if user does not exist"; insert_lines: - - "$($(v)[$(index)])" - + "$($(v)[$(index)])" comment => "Append users into a password file format", if => "add_$(index)"; } @@ -1278,24 +1282,20 @@ bundle edit_line append_groups_starting(v) # consider making `users` promises instead of modifying system files. { vars: - - "index" slist => getindices("$(v)"); + "index" slist => getindices("$(v)"); classes: - - "add_$(index)" not => groupexists("$(index)"), + "add_$(index)" + not => groupexists("$(index)"), comment => "Class created if group does not exist"; insert_lines: - - "$($(v)[$(index)])" - + "$($(v)[$(index)])" comment => "Append users into a group file format", if => "add_$(index)"; - } -bundle edit_line set_colon_field(key,field,val) +bundle edit_line set_colon_field(key, field, val) # @brief Set the value of field number `field` of the line whose # first field is `key` to the value `val`, in a colon-separated file. # @param key The value the first field has to match @@ -1303,14 +1303,12 @@ bundle edit_line set_colon_field(key,field,val) # @param val The new value of `field` { field_edits: - - "$(key):.*" - + "$(key):.*" comment => "Edit a colon-separated file, using the first field as a key", - edit_field => col(":","$(field)","$(val)","set"); + edit_field => col(":", "$(field)", "$(val)", "set"); } -bundle edit_line set_user_field(user,field,val) +bundle edit_line set_user_field(user, field, val) # @brief Set the value of field number "field" in a `:-field` # formatted file like `/etc/passwd` # @param user A regular expression matching the user(s) to be modified @@ -1326,14 +1324,12 @@ bundle edit_line set_user_field(user,field,val) # * [edit_line field_edits][field_edits] { field_edits: - - "$(user):.*" - - comment => "Edit a user attribute in the password file", - edit_field => col(":","$(field)","$(val)","set"); + "$(user):.*" + comment => "Edit a user attribute in the password file", + edit_field => col(":", "$(field)", "$(val)", "set"); } -bundle edit_line set_escaped_user_field(user,field,val) +bundle edit_line set_escaped_user_field(user, field, val) # @brief Set the value of field number "field" in a `:-field` # formatted file like `/etc/passwd` # @param user The user to be modified @@ -1349,18 +1345,15 @@ bundle edit_line set_escaped_user_field(user,field,val) # * [edit_line field_edits][field_edits] { vars: - "escaped_user" - string => escape( "$(user)" ); + "escaped_user" string => escape("$(user)"); field_edits: - - "$(escaped_user):.*" - - comment => "Edit a user attribute in the password file", - edit_field => col(":","$(field)","$(val)","set"); + "$(escaped_user):.*" + comment => "Edit a user attribute in the password file", + edit_field => col(":", "$(field)", "$(val)", "set"); } -bundle edit_line append_user_field(group,field,allusers) +bundle edit_line append_user_field(group, field, allusers) # @brief For adding users to to a file like `/etc/group` # at field position `field`, comma separated subfields # @param group The group to be modified @@ -1371,11 +1364,9 @@ bundle edit_line append_user_field(group,field,allusers) # consider making `users` promises instead of modifying system files. { field_edits: - - "$(group):.*" - + "$(group):.*" comment => "Append users into a password file format", - edit_field => col(":","$(field)","$(allusers)","alphanum"); + edit_field => col(":", "$(field)", "$(allusers)", "alphanum"); } bundle edit_line expand_template(templatefile) @@ -1383,15 +1374,13 @@ bundle edit_line expand_template(templatefile) # @param templatefile The name of the file { insert_lines: - - "$(templatefile)" - + "$(templatefile)" insert_type => "file", comment => "Expand variables in the template file", expand_scalars => "true"; } -bundle edit_line replace_or_add(pattern,line) +bundle edit_line replace_or_add(pattern, line) # @brief Replace a pattern in a file with a single line. # # If the pattern is not found, add the line to the file. @@ -1403,18 +1392,17 @@ bundle edit_line replace_or_add(pattern,line) # @param line The line with which to replace matches of `pattern` { vars: - "cline" string => canonify("$(line)"); - "eline" string => escape("$(line)"); + "cline" string => canonify("$(line)"); + "eline" string => escape("$(line)"); replace_patterns: - "^(?!$(eline)$)$(pattern)$" + "^(?!$(eline)$)$(pattern)$" comment => "Replace a pattern here", replace_with => value("$(line)"), classes => results("bundle", "replace_$(cline)"); insert_lines: - "$(line)" - if => "replace_$(cline)_reached"; + "$(line)" if => "replace_$(cline)_reached"; } bundle edit_line converge(marker, lines) @@ -1446,12 +1434,13 @@ bundle edit_line converge(marker, lines) # * Introduced in 3.6.0 { vars: - "regex" string => escape($(marker)); + "regex" string => escape($(marker)); delete_lines: - ".*$(regex).*" comment => "Delete lines matching the marker"; + ".*$(regex).*" comment => "Delete lines matching the marker"; + insert_lines: - "$(lines)" comment => "Insert the given lines"; + "$(lines)" comment => "Insert the given lines"; } bundle edit_line converge_prepend(marker, lines) @@ -1483,12 +1472,15 @@ bundle edit_line converge_prepend(marker, lines) # * Introduced in 3.17.0, 3.15.3, 3.12.6 { vars: - "regex" string => escape($(marker)); + "regex" string => escape($(marker)); delete_lines: - ".*$(regex).*" comment => "Delete lines matching the marker"; + ".*$(regex).*" comment => "Delete lines matching the marker"; + insert_lines: - "$(lines)" location => start, comment => "Insert the given lines"; + "$(lines)" + location => start, + comment => "Insert the given lines"; } bundle edit_line fstab_option_editor(method, mount, option) @@ -1510,9 +1502,8 @@ bundle edit_line fstab_option_editor(method, mount, option) # "/etc/fstab" edit_line => fstab_option_editor("append", "/", "acl"); # ``` { - field_edits: - "(?!#)\S+\s+$(mount)\s.+" - edit_field => fstab_options($(option), $(method)); + field_edits: + "(?!#)\S+\s+$(mount)\s.+" edit_field => fstab_options($(option), $(method)); } body edit_field fstab_options(newval, method) @@ -1533,85 +1524,84 @@ body edit_field fstab_options(newval, method) # edit_field => fstab_options($(option), $(method)); # ``` { - field_separator => "\s+"; - select_field => "4"; - value_separator => ","; - field_value => "$(newval)"; - field_operation => "$(method)"; + field_separator => "\s+"; + select_field => "4"; + value_separator => ","; + field_value => "$(newval)"; + field_operation => "$(method)"; } -body edit_field quoted_var(newval,method) +body edit_field quoted_var(newval, method) # @brief Edit the quoted value of the matching line # @param newval The new value # @param method The method by which to edit the field (append|prepend|alphanum|set|delete) # Ref https://docs.cfengine.com/latest/reference-promise-types-files-edit_line-field_edits.html#field_operation { - field_separator => "\""; - select_field => "2"; - value_separator => " "; - field_value => "$(newval)"; - field_operation => "$(method)"; - extend_fields => "false"; - allow_blank_fields => "true"; + field_separator => "\""; + select_field => "2"; + value_separator => " "; + field_value => "$(newval)"; + field_operation => "$(method)"; + extend_fields => "false"; + allow_blank_fields => "true"; } -body edit_field col(split,col,newval,method) +body edit_field col(split, col, newval, method) # @brief Edit tabluar data with comma-separated sub-values # @param split The separator that defines columns # @param col The (1-based) index of the value to change # @param newval The new value # @param method The method by which to edit the field { - field_separator => "$(split)"; - select_field => "$(col)"; - value_separator => ","; - field_value => "$(newval)"; - field_operation => "$(method)"; - extend_fields => "true"; - allow_blank_fields => "true"; + field_separator => "$(split)"; + select_field => "$(col)"; + value_separator => ","; + field_value => "$(newval)"; + field_operation => "$(method)"; + extend_fields => "true"; + allow_blank_fields => "true"; } -body edit_field line(split,col,newval,method) +body edit_field line(split, col, newval, method) # @brief Edit tabular data with space-separated sub-values # @param split The separator that defines columns # @param col The (1-based) index of the value to change # @param newval The new value # @param method The method by which to edit the field { - field_separator => "$(split)"; - select_field => "$(col)"; - value_separator => " "; - field_value => "$(newval)"; - field_operation => "$(method)"; - extend_fields => "true"; - allow_blank_fields => "true"; + field_separator => "$(split)"; + select_field => "$(col)"; + value_separator => " "; + field_value => "$(newval)"; + field_operation => "$(method)"; + extend_fields => "true"; + allow_blank_fields => "true"; } -body replace_with text_between_match1_and_match2( _text ) +body replace_with text_between_match1_and_match2(_text) # @brief Replace matched line with substituted string # @param _text String to substitute between first and second match { - replace_value => "$(match.1)$(_text)$(match.2)"; - occurrences => "all"; + replace_value => "$(match.1)$(_text)$(match.2)"; + occurrences => "all"; } body replace_with value(x) # @brief Replace matching lines # @param x The replacement string { - replace_value => "$(x)"; - occurrences => "all"; + replace_value => "$(x)"; + occurrences => "all"; } body select_region INI_section(x) # @brief Restrict the `edit_line` promise to the lines in section `[x]` # @param x The name of the section in an INI-like configuration file { - select_start => "\[$(x)\]\s*"; - select_end => "\[.*\]\s*"; - + select_start => "\[$(x)\]\s*"; + select_end => "\[.*\]\s*"; @if minimum_version(3.10) - select_end_match_eof => "true"; + select_end_match_eof => "true"; @endif } @@ -1620,50 +1610,51 @@ body edit_defaults empty # # No backup is made { - empty_file_before_editing => "true"; - edit_backup => "false"; - #max_file_size => "300000"; + empty_file_before_editing => "true"; + edit_backup => "false"; + + #max_file_size => "300000"; } body location start # @brief Editing occurs before the matched line { - before_after => "before"; + before_after => "before"; } body location after(str) # @brief Editing occurs after the line matching `str` # @param str Regular expression matching the file line location { - before_after => "after"; - select_line_matching => "$(str)"; + before_after => "after"; + select_line_matching => "$(str)"; } body location before(str) # @brief Editing occurs before the line matching `str` # @param str Regular expression matching the file line location { - before_after => "before"; - select_line_matching => "$(str)"; + before_after => "before"; + select_line_matching => "$(str)"; } body replace_with comment(c) # @brief Comment all lines matching the pattern by preprending `c` # @param c The prefix that comments out lines { - replace_value => "$(c) $(match.1)"; - occurrences => "all"; + replace_value => "$(c) $(match.1)"; + occurrences => "all"; } body replace_with uncomment # @brief Uncomment all lines matching the pattern by removing # anything outside the matching string { - replace_value => "$(match.1)"; - occurrences => "all"; + replace_value => "$(match.1)"; + occurrences => "all"; } -body copy_from secure_cp(from,server) +body copy_from secure_cp(from, server) # @brief Download a file from a remote server over an encrypted channel # # Only copy the file if it is different from the local copy, and verify @@ -1672,25 +1663,25 @@ body copy_from secure_cp(from,server) # @param from The location of the file on the remote server # @param server The hostname or IP of the server from which to download { - source => "$(from)"; - servers => { "$(server)" }; - compare => "digest"; - encrypt => "true"; - verify => "true"; + source => "$(from)"; + servers => { "$(server)" }; + compare => "digest"; + encrypt => "true"; + verify => "true"; } -body copy_from remote_cp(from,server) +body copy_from remote_cp(from, server) # @brief Download a file from a remote server. # # @param from The location of the file on the remote server # @param server The hostname or IP of the server from which to download { - servers => { "$(server)" }; - source => "$(from)"; - compare => "mtime"; + servers => { "$(server)" }; + source => "$(from)"; + compare => "mtime"; } -body copy_from remote_dcp(from,server) +body copy_from remote_dcp(from, server) # @brief Download a file from a remote server if it is different from the local copy. # # @param from The location of the file on the remote server @@ -1698,9 +1689,9 @@ body copy_from remote_dcp(from,server) # # **See Also:** `local_dcp()` { - servers => { "$(server)" }; - source => "$(from)"; - compare => "digest"; + servers => { "$(server)" }; + source => "$(from)"; + compare => "digest"; } body copy_from local_cp(from) @@ -1721,7 +1712,7 @@ body copy_from local_cp(from) # # **See Also:** `local_dcp()` { - source => "$(from)"; + source => "$(from)"; } body copy_from local_dcp(from) @@ -1741,8 +1732,8 @@ body copy_from local_dcp(from) # # **See Also:** `local_cp()`, `remote_dcp()` { - source => "$(from)"; - compare => "digest"; + source => "$(from)"; + compare => "digest"; } body copy_from perms_cp(from) @@ -1750,8 +1741,8 @@ body copy_from perms_cp(from) # # @param from The path to the source file. { - source => "$(from)"; - preserve => "true"; + source => "$(from)"; + preserve => "true"; } body copy_from perms_dcp(from) @@ -1760,9 +1751,9 @@ body copy_from perms_dcp(from) # # @param from The path to the source file. { - source => "$(from)"; - preserve => "true"; - compare => "digest"; + source => "$(from)"; + preserve => "true"; + compare => "digest"; } body copy_from backup_local_cp(from) @@ -1770,8 +1761,8 @@ body copy_from backup_local_cp(from) # # @param from The path to the source file. { - source => "$(from)"; - copy_backup => "timestamp"; + source => "$(from)"; + copy_backup => "timestamp"; } body copy_from seed_cp(from) @@ -1794,11 +1785,11 @@ body copy_from seed_cp(from) # } # ``` { - source => "$(from)"; - compare => "exists"; + source => "$(from)"; + compare => "exists"; } -body copy_from sync_cp(from,server) +body copy_from sync_cp(from, server) # @brief Synchronize a file with a remote server. # # * If the file does not exist on the remote server then it should be purged. @@ -1822,11 +1813,11 @@ body copy_from sync_cp(from,server) # # **See Also:** `dir_sync()`, `copyfrom_sync()` { - servers => { "$(server)" }; - source => "$(from)"; - purge => "true"; - preserve => "true"; - type_check => "false"; + servers => { "$(server)" }; + source => "$(from)"; + purge => "true"; + preserve => "true"; + type_check => "false"; } body copy_from no_backup_cp(from) @@ -1834,8 +1825,8 @@ body copy_from no_backup_cp(from) # # @param from The path to the source file. { - source => "$(from)"; - copy_backup => "false"; + source => "$(from)"; + copy_backup => "false"; } body copy_from no_backup_cp_compare(from, comparison) @@ -1844,9 +1835,9 @@ body copy_from no_backup_cp_compare(from, comparison) # @param from The path to the source file. # @param comparison The comparison to use. (mtime|ctime|atime|exists|binary|hash|digest) { - source => "$(from)"; - copy_backup => "false"; - compare => "$(comparison)"; + source => "$(from)"; + copy_backup => "false"; + compare => "$(comparison)"; } body copy_from no_backup_dcp(from) @@ -1855,9 +1846,9 @@ body copy_from no_backup_dcp(from) # # @param from The path to the source file. { - source => "$(from)"; - copy_backup => "false"; - compare => "digest"; + source => "$(from)"; + copy_backup => "false"; + compare => "digest"; } body link_from linkfrom(source, type) @@ -1865,75 +1856,75 @@ body link_from linkfrom(source, type) # @param source link to this # @param type the link's type (`symlink` or `hardlink`) { - source => $(source); - link_type => $(type); + source => $(source); + link_type => $(type); } body perms m(mode) # @brief Set the file mode # @param mode The new mode { - mode => "$(mode)"; + mode => "$(mode)"; -#+begin_ENT-951 -# Remove after 3.20 is not supported - rxdirs => "true"; + #+begin_ENT-951 + # Remove after 3.20 is not supported + rxdirs => "true"; @if minimum_version(3.20) - rxdirs => "false"; + rxdirs => "false"; @endif -#+end + #+end } -body perms mo(mode,user) +body perms mo(mode, user) # @brief Set the file's mode and owners # @param mode The new mode # @param user The username of the new owner { - owners => { "$(user)" }; - mode => "$(mode)"; + owners => { "$(user)" }; + mode => "$(mode)"; -#+begin_ENT-951 -# Remove after 3.20 is not supported - rxdirs => "true"; + #+begin_ENT-951 + # Remove after 3.20 is not supported + rxdirs => "true"; @if minimum_version(3.20) - rxdirs => "false"; + rxdirs => "false"; @endif -#+end + #+end } -body perms mog(mode,user,group) +body perms mog(mode, user, group) # @brief Set the file's mode, owner and group # @param mode The new mode # @param user The username of the new owner # @param group The group name { - owners => { "$(user)" }; - groups => { "$(group)" }; - mode => "$(mode)"; + owners => { "$(user)" }; + groups => { "$(group)" }; + mode => "$(mode)"; -#+begin_ENT-951 -# Remove after 3.20 is not supported - rxdirs => "true"; + #+begin_ENT-951 + # Remove after 3.20 is not supported + rxdirs => "true"; @if minimum_version(3.20) - rxdirs => "false"; + rxdirs => "false"; @endif -#+end + #+end } -body perms og(u,g) +body perms og(u, g) # @brief Set the file's owner and group # @param u The username of the new owner # @param g The group name { - owners => { "$(u)" }; - groups => { "$(g)" }; + owners => { "$(u)" }; + groups => { "$(g)" }; } body perms owner(user) # @brief Set the file's owner # @param user The username of the new owner { - owners => { "$(user)" }; + owners => { "$(user)" }; } body perms system_owned(mode) @@ -1947,40 +1938,37 @@ body perms system_owned(mode) # "/etc/passwd" perms => system_owned("0644"); # ``` { - mode => "$(mode)"; + mode => "$(mode)"; -#+begin_ENT-951 -# Remove after 3.20 is not supported - rxdirs => "true"; + #+begin_ENT-951 + # Remove after 3.20 is not supported + rxdirs => "true"; @if minimum_version(3.20) - rxdirs => "false"; + rxdirs => "false"; @endif -#+end + #+end + !windows:: + owners => { "root" }; - !windows:: - owners => { "root" }; + windows:: + # NOTE: Setting owners will generate an error if the policy is not being + # executed as the user who's ownership is being targeted. While it seems + # that should typically be Administrator or SYSTEM, both are reported to + # result in errors by users, thus owners is currently omitted for Windows. + # ENT-9778 + groups => { "Administrators" }; - windows:: + freebsd|openbsd|netbsd|darwin:: + groups => { "wheel" }; - # NOTE: Setting owners will generate an error if the policy is not being - # executed as the user who's ownership is being targeted. While it seems - # that should typically be Administrator or SYSTEM, both are reported to - # result in errors by users, thus owners is currently omitted for Windows. + linux:: + groups => { "root" }; - # ENT-9778 - groups => { "Administrators" }; + solaris:: + groups => { "sys" }; - freebsd|openbsd|netbsd|darwin:: - groups => { "wheel" }; - - linux:: - groups => { "root" }; - - solaris:: - groups => { "sys" }; - - aix:: - groups => { "system" }; + aix:: + groups => { "system" }; } body depth_search recurse(d) @@ -1989,19 +1977,19 @@ body depth_search recurse(d) # # @param d The maximum search depth { - depth => "$(d)"; - xdev => "true"; + depth => "$(d)"; + xdev => "true"; } -body depth_search recurse_ignore(d,list) +body depth_search recurse_ignore(d, list) # @brief Search files and directories recursively, # but don't recurse into the specified directories # # @param d The maximum search depth # @param list The list of directories to be excluded { - depth => "$(d)"; - exclude_dirs => { @(list) }; + depth => "$(d)"; + exclude_dirs => { @(list) }; } body depth_search recurse_with_base(d) @@ -2011,34 +1999,34 @@ body depth_search recurse_with_base(d) # # @param d The maximum search depth { - depth => "$(d)"; - xdev => "true"; - include_basedir => "true"; + depth => "$(d)"; + xdev => "true"; + include_basedir => "true"; } body delete tidy # @brief Delete the file and remove empty directories # and links to directories { - dirlinks => "delete"; - rmdirs => "true"; + dirlinks => "delete"; + rmdirs => "true"; } body file_select all # @brief Select all file system entries { - leaf_name => { ".*" }; - file_result => "leaf_name"; + leaf_name => { ".*" }; + file_result => "leaf_name"; } body changes all_changes # @brief Detect all file changes using sha256 # and report the diff to CFEngine Enterprise { - hash => "sha256"; - report_changes => "all"; - report_diffs => "true"; - update_hashes => "yes"; + hash => "sha256"; + report_changes => "all"; + report_diffs => "true"; + update_hashes => "yes"; } bundle agent file_mustache(mustache_file, json_file, target_file) @@ -2055,7 +2043,7 @@ bundle agent file_mustache(mustache_file, json_file, target_file) # ``` { files: - "$(target_file)" + "$(target_file)" create => "true", edit_template => $(mustache_file), template_data => readjson($(json_file), "100k"), @@ -2076,7 +2064,7 @@ bundle agent file_mustache_jsonstring(mustache_file, json_string, target_file) # ``` { files: - "$(target_file)" + "$(target_file)" create => "true", edit_template => $(mustache_file), template_data => parsejson($(json_string)), @@ -2095,7 +2083,7 @@ bundle agent file_tidy(file) # ``` { files: - "$(file)" delete => tidy; + "$(file)" delete => tidy; reports: "DEBUG|DEBUG_$(this.bundle)":: @@ -2115,7 +2103,7 @@ bundle agent dir_sync(from, to) # ``` { files: - "$(to)/." + "$(to)/." create => "true", depth_search => recurse("inf"), copy_from => copyfrom_sync($(from)); @@ -2138,8 +2126,7 @@ bundle agent file_copy(from, to) # ``` { files: - "$(to)" - copy_from => copyfrom_sync($(from)); + "$(to)" copy_from => copyfrom_sync($(from)); reports: "DEBUG|DEBUG_$(this.bundle)":: @@ -2150,11 +2137,11 @@ body copy_from copyfrom_sync(f) # @brief Copy a directory or file with digest checksums, preserving attributes and purging leftovers # @param f the file or directory { - source => "$(f)"; - purge => "true"; - preserve => "true"; - type_check => "false"; - compare => "digest"; + source => "$(f)"; + purge => "true"; + preserve => "true"; + type_check => "false"; + compare => "digest"; } bundle agent file_make(file, str) @@ -2171,16 +2158,19 @@ bundle agent file_make(file, str) # ``` { vars: - "len" int => string_length($(str)); + "len" int => string_length($(str)); + summarize:: - "summary" string => format("%s...%s", - string_head($(str), 18), - string_tail($(str), 18)); + "summary" + string => format( + "%s...%s", string_head($(str), 18), string_tail($(str), 18) + ); + classes: - "summarize" expression => isgreaterthan($(len), 40); + "summarize" expression => isgreaterthan($(len), 40); files: - "$(file)" + "$(file)" create => "true", edit_line => insert_lines($(str)), edit_defaults => empty; @@ -2188,10 +2178,10 @@ bundle agent file_make(file, str) reports: "DEBUG|DEBUG_$(this.bundle)":: "DEBUG $(this.bundle): creating $(file) with contents '$(str)'" - if => "!summarize"; + if => "!summarize"; "DEBUG $(this.bundle): creating $(file) with contents '$(summary)'" - if => "summarize"; + if => "summarize"; } bundle agent file_make_mog(file, str, mode, owner, group) @@ -2211,16 +2201,19 @@ bundle agent file_make_mog(file, str, mode, owner, group) # ``` { vars: - "len" int => string_length($(str)); + "len" int => string_length($(str)); + summarize:: - "summary" string => format("%s...%s", - string_head($(str), 18), - string_tail($(str), 18)); + "summary" + string => format( + "%s...%s", string_head($(str), 18), string_tail($(str), 18) + ); + classes: - "summarize" expression => isgreaterthan($(len), 40); + "summarize" expression => isgreaterthan($(len), 40); files: - "$(file)" + "$(file)" create => "true", edit_line => insert_lines($(str)), perms => mog($(mode), $(owner), $(group)), @@ -2229,10 +2222,10 @@ bundle agent file_make_mog(file, str, mode, owner, group) reports: "DEBUG|DEBUG_$(this.bundle)":: "DEBUG $(this.bundle): creating $(file) with contents '$(str)', mode '$(mode)', owner '$(owner)' and group '$(group)'" - if => "!summarize"; + if => "!summarize"; "DEBUG $(this.bundle): creating $(file) with contents '$(summary)', mode '$(mode)', owner '$(owner)' and group '$(group)'" - if => "summarize"; + if => "summarize"; } bundle agent file_make_mustache(file, template, data) @@ -2252,14 +2245,14 @@ bundle agent file_make_mustache(file, template, data) # ``` { files: - "$(file)" - create => "true", - edit_template => "$(template)", - template_method => "mustache", - template_data => @(data); + "$(file)" + create => "true", + edit_template => "$(template)", + template_method => "mustache", + template_data => @(data); reports: - "DEBUG|DEBUG_$(this.bundle)":: + "DEBUG|DEBUG_$(this.bundle)":: "DEBUG $(this.bundle): rendering $(file) with template '$(template)'"; } @@ -2284,15 +2277,15 @@ bundle agent file_make_mustache_with_perms(file, template, data, mode, owner, gr # ``` { files: - "$(file)" - create => "true", - edit_template => "$(template)", - template_method => "mustache", - perms => mog( $(mode), $(owner), $(group) ), - template_data => @(data); + "$(file)" + create => "true", + edit_template => "$(template)", + template_method => "mustache", + perms => mog($(mode), $(owner), $(group)), + template_data => @(data); reports: - "DEBUG|DEBUG_$(this.bundle)":: + "DEBUG|DEBUG_$(this.bundle)":: "DEBUG $(this.bundle): rendering $(file) with template '$(template)'"; } @@ -2308,7 +2301,7 @@ bundle agent file_empty(file) # ``` { files: - "$(file)" + "$(file)" create => "true", edit_defaults => empty; @@ -2330,7 +2323,7 @@ bundle agent file_hardlink(target, link) # ``` { files: - "$(link)" + "$(link)" move_obstructions => "true", link_from => linkfrom($(target), "hardlink"); @@ -2352,7 +2345,7 @@ bundle agent file_link(target, link) # ``` { files: - "$(link)" + "$(link)" move_obstructions => "true", link_from => linkfrom($(target), "symlink"); @@ -2367,7 +2360,6 @@ bundle edit_line create_solaris_admin_file # See unit examples. { insert_lines: - - "$(solaris_knowledge.admin_nocheck)" + "$(solaris_knowledge.admin_nocheck)" comment => "Insert contents of Solaris admin file (automatically install packages)"; } From 11f9fb74de2636763367010890cbf1060883df1b Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Thu, 25 Jun 2026 15:06:58 +0200 Subject: [PATCH 2/7] cfengine format ./tests/acceptance/31_tickets/ Signed-off-by: Ole Herman Schumacher Elgesem --- .../acceptance/31_tickets/CFE-2367/1/test.cf | 29 +++---- .../acceptance/31_tickets/CFE-2367/2/test.cf | 41 +++++----- tests/acceptance/31_tickets/CFE-3866/test.cf | 55 ++++++------- .../acceptance/31_tickets/CFE-3987/1/test.cf | 64 +++++++-------- .../acceptance/31_tickets/CFE-3987/2/test.cf | 60 +++++++------- .../acceptance/31_tickets/CFE-3988/1/test.cf | 79 +++++++++---------- .../acceptance/31_tickets/ENT-8788/1/main.cf | 73 +++++++++-------- .../acceptance/31_tickets/ENT-8788/2/main.cf | 73 +++++++++-------- .../31_tickets/ENT-8818/1/staging/main.cf | 21 +++-- 9 files changed, 250 insertions(+), 245 deletions(-) diff --git a/tests/acceptance/31_tickets/CFE-2367/1/test.cf b/tests/acceptance/31_tickets/CFE-2367/1/test.cf index f6f6d17441..46246763a3 100644 --- a/tests/acceptance/31_tickets/CFE-2367/1/test.cf +++ b/tests/acceptance/31_tickets/CFE-2367/1/test.cf @@ -1,34 +1,35 @@ body file control { - inputs => { - "../../../default.sub.cf", - }; + inputs => { "../../../default.sub.cf" }; } + bundle agent __main__ # If this is the policy entry (cf-agent --file) then this bundle will be run by default. { methods: - "bundlesequence" usebundle => default("$(this.promise_filename)"); + "bundlesequence" usebundle => default("$(this.promise_filename)"); } + bundle agent test { meta: - "description" -> { "CFE-2367" } - string => "cf-agent should not fatally error when fileexists() is given an undefined variable as a parameter"; + "description" -> { "CFE-2367" } + string => "cf-agent should not fatally error when fileexists() is given an undefined variable as a parameter"; files: "$(G.testfile)" - content => "CFE-2367", - unless => fileexists( $(testfile) ); # testfile is not defined, in the - # original ticket filed this caused - # a fatal error + content => "CFE-2367", + unless => fileexists($(testfile)); + + # testfile is not defined, in the + # original ticket filed this caused + # a fatal error } bundle agent check { methods: - # Since this was testing for the absence of a fatal error, if we get to - # this point, we pass. - "Pass" - usebundle => dcs_pass("$(this.promise_filename)" ); + # Since this was testing for the absence of a fatal error, if we get to + # this point, we pass. + "Pass" usebundle => dcs_pass("$(this.promise_filename)"); } diff --git a/tests/acceptance/31_tickets/CFE-2367/2/test.cf b/tests/acceptance/31_tickets/CFE-2367/2/test.cf index 03ff5e5752..8be49c5afc 100644 --- a/tests/acceptance/31_tickets/CFE-2367/2/test.cf +++ b/tests/acceptance/31_tickets/CFE-2367/2/test.cf @@ -1,40 +1,41 @@ body file control { - inputs => { - "../../../default.sub.cf", - }; + inputs => { "../../../default.sub.cf" }; } + bundle agent __main__ # If this is the policy entry (cf-agent --file) then this bundle will be run by default. { methods: - "bundlesequence" usebundle => default("$(this.promise_filename)"); + "bundlesequence" usebundle => default("$(this.promise_filename)"); } + bundle agent test { meta: - "description" -> { "CFE-2367" } - string => "cf-agent should not fatally error when fileexists() is given an undefined variable as a parameter"; + "description" -> { "CFE-2367" } + string => "cf-agent should not fatally error when fileexists() is given an undefined variable as a parameter"; files: "$(G.testfile)" - content => "CFE-2367", - unless => and( fileexists( $(testfile) ) ); # testfile is not defined, - # in the original ticket - # filed this caused a fatal - # error and the workaround - # was to wrap the function - # call with and(), so we - # simply test that as in the - # original case, there is no - # fatal error. + content => "CFE-2367", + unless => and(fileexists($(testfile))); + + # testfile is not defined, + # in the original ticket + # filed this caused a fatal + # error and the workaround + # was to wrap the function + # call with and(), so we + # simply test that as in the + # original case, there is no + # fatal error. } bundle agent check { methods: - # Since this was testing for the absence of a fatal error, if we get to - # this point, we pass. - "Pass" - usebundle => dcs_pass("$(this.promise_filename)" ); + # Since this was testing for the absence of a fatal error, if we get to + # this point, we pass. + "Pass" usebundle => dcs_pass("$(this.promise_filename)"); } diff --git a/tests/acceptance/31_tickets/CFE-3866/test.cf b/tests/acceptance/31_tickets/CFE-3866/test.cf index 643ae0e0d3..5a8dd62645 100644 --- a/tests/acceptance/31_tickets/CFE-3866/test.cf +++ b/tests/acceptance/31_tickets/CFE-3866/test.cf @@ -1,85 +1,77 @@ body file control { - inputs => { - "../../default.sub.cf", - }; + inputs => { "../../default.sub.cf" }; } bundle agent __main__ { methods: - "bundlesequence" usebundle => default("$(this.promise_filename)"); + "bundlesequence" usebundle => default("$(this.promise_filename)"); } bundle agent init { files: - "$(G.testfile)" - delete => init_delete; + "$(G.testfile)" delete => init_delete; } body delete init_delete { - dirlinks => "delete"; - rmdirs => "true"; + dirlinks => "delete"; + rmdirs => "true"; } bundle agent test { meta: - "description" - string => "Test that select_region converges across multiple edit_line passes when the region is created in an earlier pass", - meta => { "CFE-3866" }; + "description" + string => "Test that select_region converges across multiple edit_line passes when the region is created in an earlier pass", + meta => { "CFE-3866" }; files: - "$(G.testfile)" - create => "true", - edit_line => insert_section_then_add_content; + "$(G.testfile)" + create => "true", + edit_line => insert_section_then_add_content; } bundle edit_line insert_section_then_add_content { # First promise: Create the section header insert_lines: - "[section]" - location => start; + "[section]" location => start; # Second promise: Add content within the section using select_region # This should converge even though the section didn't exist when # select_region was first evaluated (pass 1) - insert_lines: - "key=value" - location => append, - select_region => section_region; + "key=value" + location => append, + select_region => section_region; } body location append { - before_after => "after"; + before_after => "after"; } body select_region section_region { - select_start => "^\[section\]"; - include_start_delimiter => "true"; - select_end => "^\[.*\]"; - select_end_match_eof => "true"; + select_start => "^\[section\]"; + include_start_delimiter => "true"; + select_end => "^\[.*\]"; + select_end_match_eof => "true"; } bundle agent check { vars: - "expected" - string => "[section] + "expected" string => "[section] key=value "; - - "actual" - string => readfile("$(G.testfile)", "1000"); + "actual" string => readfile("$(G.testfile)", "1000"); classes: - "ok" expression => strcmp("$(expected)", "$(actual)"); + "ok" expression => strcmp("$(expected)", "$(actual)"); reports: DEBUG:: @@ -88,6 +80,7 @@ key=value ok:: "$(this.promise_filename) Pass"; + !ok:: "$(this.promise_filename) FAIL"; } diff --git a/tests/acceptance/31_tickets/CFE-3987/1/test.cf b/tests/acceptance/31_tickets/CFE-3987/1/test.cf index e8e56725cc..60b973e816 100644 --- a/tests/acceptance/31_tickets/CFE-3987/1/test.cf +++ b/tests/acceptance/31_tickets/CFE-3987/1/test.cf @@ -1,72 +1,72 @@ body file control { - inputs => { - "../../../default.sub.cf", - }; + inputs => { "../../../default.sub.cf" }; } + bundle agent __main__ # If this is the policy entry (cf-agent --file) then this bundle will be run by default. { methods: - "bundlesequence" usebundle => default("$(this.promise_filename)"); + "bundlesequence" usebundle => default("$(this.promise_filename)"); } bundle agent init { files: - # Seed the file we will exercise the test on - "$(G.testfile)" - copy_from => local_dcp( "$(this.promise_dirname)/before_test.xml.txt" ); + # Seed the file we will exercise the test on + "$(G.testfile)" + copy_from => local_dcp("$(this.promise_dirname)/before_test.xml.txt"); } + bundle agent test { meta: - "description" - string => "edit_line doesn't insert text immediately before a selected region if a location body only explicitly sets before_after => 'before'", - meta => { "CFE-3987" }; + "description" + string => "edit_line doesn't insert text immediately before a selected region if a location body only explicitly sets before_after => 'before'", + meta => { "CFE-3987" }; - "test_soft_fail" - string => "any", - meta => { "CFE-3987" }; + "test_soft_fail" + string => "any", + meta => { "CFE-3987" }; vars: - "seed_file" string => "$(this.promise_dirname)/before_test.xml.txt"; - "test_file" string => "$(G.testfile)"; + "seed_file" string => "$(this.promise_dirname)/before_test.xml.txt"; + "test_file" string => "$(G.testfile)"; files: - "$(test_file)" - edit_line => CFE_3987; + "$(test_file)" edit_line => CFE_3987; } bundle agent check { methods: - "Pass/FAIL" - usebundle => dcs_check_regcmp( - ".*INSERT\sME\R\s+ - #INSERT ME - - "Pass/FAIL" - usebundle => dcs_check_regcmp( - ".*\s+THIS MUST BE THE LAST FILTER IN THE DEFINED CHAIN\R\s+=+\s+-->\RINSERT\sME.*", - readfile( "$(test.test_file)" ), - $(this.promise_filename), - "no" - ); + # We expect to find lines that look something like this: + # THIS MUST BE THE LAST FILTER IN THE DEFINED CHAIN + # ===================================================== --> + #INSERT ME + "Pass/FAIL" + usebundle => dcs_check_regcmp( + ".*\s+THIS MUST BE THE LAST FILTER IN THE DEFINED CHAIN\R\s+=+\s+-->\RINSERT\sME.*", + readfile("$(test.test_file)"), + $(this.promise_filename), + "no" + ); } bundle edit_line CFE_3988 { insert_lines: - "INSERT ME" - select_region => my_comment_last_filter, - location => my_location_after_comment_last_filter; + "INSERT ME" + select_region => my_comment_last_filter, + location => my_location_after_comment_last_filter; } + body location my_location_after_comment_last_filter # @brief Editing occurs after the last line in the selected region { - before_after => "after"; - first_last => "last"; - select_line_matching => ".*"; + before_after => "after"; + first_last => "last"; + select_line_matching => ".*"; } body select_region my_comment_last_filter { - select_start => "\s+THIS MUST BE THE LAST FILTER IN THE DEFINED CHAIN"; - select_end => "\s+=+\s+-->"; - include_start_delimiter => "true"; - include_end_delimiter => "true"; - select_end_match_eof => "false"; + select_start => "\s+THIS MUST BE THE LAST FILTER IN THE DEFINED CHAIN"; + select_end => "\s+=+\s+-->"; + include_start_delimiter => "true"; + include_end_delimiter => "true"; + select_end_match_eof => "false"; } diff --git a/tests/acceptance/31_tickets/ENT-8788/1/main.cf b/tests/acceptance/31_tickets/ENT-8788/1/main.cf index 8e32746879..3726004b03 100644 --- a/tests/acceptance/31_tickets/ENT-8788/1/main.cf +++ b/tests/acceptance/31_tickets/ENT-8788/1/main.cf @@ -1,74 +1,81 @@ body file control { - inputs => { - "../../../default.sub.cf", - }; + inputs => { "../../../default.sub.cf" }; } + bundle agent __main__ # If this is the policy entry (cf-agent --file) then this bundle will be run by default. { methods: - "bundlesequence" usebundle => default("$(this.promise_filename)"); + "bundlesequence" usebundle => default("$(this.promise_filename)"); } bundle agent init { vars: - "original_file" string => "$(this.promise_dirname)/start.xml.txt"; - "test_file" string => "$(sys.workdir)/start.xml.test"; + "original_file" string => "$(this.promise_dirname)/start.xml.txt"; + "test_file" string => "$(sys.workdir)/start.xml.test"; + files: - "$(test_file)" - copy_from => local_cp("${original_file}"); + "$(test_file)" copy_from => local_cp("${original_file}"); } bundle agent test { meta: - "description" - string => "Inserting content that contains blank lines with file_preserve_block before select_line_matching does not split inserted content before and after select_line_matching", - meta => { "ENT-8788" }; + "description" + string => "Inserting content that contains blank lines with file_preserve_block before select_line_matching does not split inserted content before and after select_line_matching", + meta => { "ENT-8788" }; vars: - "new_content_file" string => "$(this.promise_dirname)/newcontent.xml.txt"; + "new_content_file" string => "$(this.promise_dirname)/newcontent.xml.txt"; files: "$(init.test_file)" - create => "false", - edit_defaults => size("500k"), - edit_line => insert_file_as_block_relative_to_first_or_last_line( - "$(new_content_file)", # File with content to insert if not found - "before", # Relative position to insert content (before|after) - "last", # which line match will we insert based on? - "\s+" # Regex to match the line we want to insert relative to - ); + create => "false", + edit_defaults => size("500k"), + edit_line => insert_file_as_block_relative_to_first_or_last_line( + "$(new_content_file)", + # File with content to insert if not found + "before", + # Relative position to insert content (before|after) + "last", + # which line match will we insert based on? + "\s+" + # Regex to match the line we want to insert relative to + ); } bundle agent check { methods: - - "Pass/Fail" usebundle => dcs_check_diff($(init.test_file), - "$(this.promise_dirname)/desired-result.xml.txt", - $(this.promise_filename)); + "Pass/Fail" + usebundle => dcs_check_diff( + $(init.test_file), + "$(this.promise_dirname)/desired-result.xml.txt", + $(this.promise_filename) + ); } bundle edit_line insert_file_as_block_relative_to_first_or_last_line(templatefile, relative_location, first_or_last, location_line_regex) { insert_lines: - - "$(templatefile)" - comment => "Insert the template file into the file being edited", - insert_type => "file_preserve_block", - location => location_before_after_first_or_last_line( $(relative_location), $(first_or_last), $(location_line_regex) ); + "$(templatefile)" + comment => "Insert the template file into the file being edited", + insert_type => "file_preserve_block", + location => location_before_after_first_or_last_line( + $(relative_location), $(first_or_last), $(location_line_regex) + ); } + body location location_before_after_first_or_last_line(relative_position, first_or_last, regex_matching_line) { - before_after => "$(relative_position)"; - first_last => "$(first_or_last)"; - select_line_matching => "$(regex_matching_line)"; + before_after => "$(relative_position)"; + first_last => "$(first_or_last)"; + select_line_matching => "$(regex_matching_line)"; } body edit_defaults size(bigenough) { - max_file_size => "$(bigenough)"; + max_file_size => "$(bigenough)"; } diff --git a/tests/acceptance/31_tickets/ENT-8788/2/main.cf b/tests/acceptance/31_tickets/ENT-8788/2/main.cf index e7af7a38ce..8b6662cf3d 100644 --- a/tests/acceptance/31_tickets/ENT-8788/2/main.cf +++ b/tests/acceptance/31_tickets/ENT-8788/2/main.cf @@ -1,74 +1,81 @@ body file control { - inputs => { - "../../../default.sub.cf", - }; + inputs => { "../../../default.sub.cf" }; } + bundle agent __main__ # If this is the policy entry (cf-agent --file) then this bundle will be run by default. { methods: - "bundlesequence" usebundle => default("$(this.promise_filename)"); + "bundlesequence" usebundle => default("$(this.promise_filename)"); } bundle agent init { vars: - "original_file" string => "$(this.promise_dirname)/start.xml.txt"; - "test_file" string => "$(sys.workdir)/start.xml.test"; + "original_file" string => "$(this.promise_dirname)/start.xml.txt"; + "test_file" string => "$(sys.workdir)/start.xml.test"; + files: - "$(test_file)" - copy_from => local_cp("${original_file}"); + "$(test_file)" copy_from => local_cp("${original_file}"); } bundle agent test { meta: - "description" - string => "Inserting content that does not contain blank lines with file_preserve_block before select_line_matching works as expected", - meta => { "ENT-8788" }; + "description" + string => "Inserting content that does not contain blank lines with file_preserve_block before select_line_matching works as expected", + meta => { "ENT-8788" }; vars: - "new_content_file" string => "$(this.promise_dirname)/newcontent.xml.txt"; + "new_content_file" string => "$(this.promise_dirname)/newcontent.xml.txt"; files: "$(init.test_file)" - create => "false", - edit_defaults => size("500k"), - edit_line => insert_file_as_block_relative_to_first_or_last_line( - "$(new_content_file)", # File with content to insert if not found - "before", # Relative position to insert content (before|after) - "last", # which line match will we insert based on? - "\s+" # Regex to match the line we want to insert relative to - ); + create => "false", + edit_defaults => size("500k"), + edit_line => insert_file_as_block_relative_to_first_or_last_line( + "$(new_content_file)", + # File with content to insert if not found + "before", + # Relative position to insert content (before|after) + "last", + # which line match will we insert based on? + "\s+" + # Regex to match the line we want to insert relative to + ); } bundle agent check { methods: - - "Pass/Fail" usebundle => dcs_check_diff($(init.test_file), - "$(this.promise_dirname)/desired-result.xml.txt", - $(this.promise_filename)); + "Pass/Fail" + usebundle => dcs_check_diff( + $(init.test_file), + "$(this.promise_dirname)/desired-result.xml.txt", + $(this.promise_filename) + ); } bundle edit_line insert_file_as_block_relative_to_first_or_last_line(templatefile, relative_location, first_or_last, location_line_regex) { insert_lines: - - "$(templatefile)" - comment => "Insert the template file into the file being edited", - insert_type => "file_preserve_block", - location => location_before_after_first_or_last_line( $(relative_location), $(first_or_last), $(location_line_regex) ); + "$(templatefile)" + comment => "Insert the template file into the file being edited", + insert_type => "file_preserve_block", + location => location_before_after_first_or_last_line( + $(relative_location), $(first_or_last), $(location_line_regex) + ); } + body location location_before_after_first_or_last_line(relative_position, first_or_last, regex_matching_line) { - before_after => "$(relative_position)"; - first_last => "$(first_or_last)"; - select_line_matching => "$(regex_matching_line)"; + before_after => "$(relative_position)"; + first_last => "$(first_or_last)"; + select_line_matching => "$(regex_matching_line)"; } body edit_defaults size(bigenough) { - max_file_size => "$(bigenough)"; + max_file_size => "$(bigenough)"; } diff --git a/tests/acceptance/31_tickets/ENT-8818/1/staging/main.cf b/tests/acceptance/31_tickets/ENT-8818/1/staging/main.cf index 0705e06ebc..81067d535b 100644 --- a/tests/acceptance/31_tickets/ENT-8818/1/staging/main.cf +++ b/tests/acceptance/31_tickets/ENT-8818/1/staging/main.cf @@ -1,33 +1,30 @@ # NOTE: This test file must have it's be renamed from .x.cf to .cf when the bug is fixed. body file control { - inputs => { - "../../../default.sub.cf", - }; + inputs => { "../../../default.sub.cf" }; } + bundle agent __main__ # If this is the policy entry (cf-agent --file) then this bundle will be run by default. { methods: - "bundlesequence" usebundle => default("$(this.promise_filename)"); + "bundlesequence" usebundle => default("$(this.promise_filename)"); } bundle agent test { meta: - "description" -> { "ENT-8818" } - string => "Referencing variables in a namespace that does not exist should not cause the agent to crash"; + "description" -> { "ENT-8818" } + string => "Referencing variables in a namespace that does not exist should not cause the agent to crash"; reports: - # NOTE: Here in the last variable I misspelled default as defult which is how I originally found this bug. - - "In $(this.namespace):$(this.bundle) $(const.dollar)(default:sys.cf_version_major) == $(defult:sys.cf_version_major)"; + # NOTE: Here in the last variable I misspelled default as defult which is how I originally found this bug. + "In $(this.namespace):$(this.bundle) $(const.dollar)(default:sys.cf_version_major) == $(defult:sys.cf_version_major)"; } bundle agent check { methods: - - # If we make ti this far we pass. - "Pass" usebundle => dcs_pass( $(this.promise_filename) ); + # If we make ti this far we pass. + "Pass" usebundle => dcs_pass($(this.promise_filename)); } From ef3397ece7d2c23fe106e70b4de4af5da1bc7da6 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Thu, 25 Jun 2026 15:08:00 +0200 Subject: [PATCH 3/7] cfengine format ./tests/acceptance/30_custom_promise_types/ Signed-off-by: Ole Herman Schumacher Elgesem --- .../01_basic_module.cf | 64 +++++----- .../30_custom_promise_types/02_if.cf | 104 +++++++++-------- .../30_custom_promise_types/05_meta_attr.cf | 63 +++++----- .../30_custom_promise_types/11_unless.cf | 104 +++++++++-------- .../12_multiple_promises.cf | 107 +++++++++-------- .../30_custom_promise_types/13_binary_path.cf | 14 ++- .../14_multiple_promise_types_same_module.cf | 110 ++++++++++-------- .../15_conflicting_interpreters.cf | 110 ++++++++++-------- .../17_early_module_failure.cf | 20 ++-- .../18_early_module_failure_classes.cf | 21 ++-- .../22_what_module_gets.cf | 36 +++--- .../23_action_policy/dryrun_supported.cf | 24 ++-- .../23_action_policy/dryrun_unsupported.cf | 24 ++-- .../explicit_warn_fake_supported.cf | 24 ++-- .../explicit_warn_supported.cf | 24 ++-- .../explicit_warn_unsupported.cf | 24 ++-- .../23_action_policy/simulate_supported.cf | 24 ++-- .../23_action_policy/simulate_unsupported.cf | 24 ++-- 18 files changed, 518 insertions(+), 403 deletions(-) diff --git a/tests/acceptance/30_custom_promise_types/01_basic_module.cf b/tests/acceptance/30_custom_promise_types/01_basic_module.cf index 6eb89eb392..5aa507fef8 100644 --- a/tests/acceptance/30_custom_promise_types/01_basic_module.cf +++ b/tests/acceptance/30_custom_promise_types/01_basic_module.cf @@ -5,37 +5,34 @@ ##################################################### body common control { - inputs => { "../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - bundle agent init { files: - "$(G.testfile)" - delete => init_delete; + "$(G.testfile)" delete => init_delete; } body delete init_delete { - dirlinks => "delete"; - rmdirs => "true"; + dirlinks => "delete"; + rmdirs => "true"; } ####################################################### - promise agent example { - interpreter => "/bin/bash"; - path => "$(this.promise_dirname)/example_module.sh"; + interpreter => "/bin/bash"; + path => "$(this.promise_dirname)/example_module.sh"; } body classes example { - promise_repaired => { "example_promise_repaired" }; + promise_repaired => { "example_promise_repaired" }; } bundle agent test @@ -43,13 +40,13 @@ bundle agent test meta: "description" -> { "CFE-3443" } string => "Test that you can add a promise module and evaluate a custom promise"; - "test_soft_fail" string => "windows", - meta => { "ENT-10217" }; + "test_soft_fail" + string => "windows", + meta => { "ENT-10217" }; vars: - "test_string" - string => "hello, modules"; + "test_string" string => "hello, modules"; example: cfengine:: @@ -58,42 +55,49 @@ bundle agent test classes => example; classes: - "file_created" - expression => canonify("$(G.testfile)_created"), - scope => "namespace"; - "file_updated" - expression => canonify("$(G.testfile)_content_updated"), - scope => "namespace"; - "file_update_failed" - expression => canonify("$(G.testfile)_content_update_failed"), - scope => "namespace"; + "file_created" + expression => canonify("$(G.testfile)_created"), + scope => "namespace"; + + "file_updated" + expression => canonify("$(G.testfile)_content_updated"), + scope => "namespace"; + + "file_update_failed" + expression => canonify("$(G.testfile)_content_update_failed"), + scope => "namespace"; } ####################################################### - bundle agent check { classes: - "file_ok" - expression => strcmp("$(test.test_string)", readfile("$(G.testfile)")), - if => fileexists("$(G.testfile)"); + "file_ok" + expression => strcmp("$(test.test_string)", readfile("$(G.testfile)")), + if => fileexists("$(G.testfile)"); - "ok" expression => "file_ok.file_created.file_updated.(!file_update_failed).example_promise_repaired"; + "ok" + expression => "file_ok.file_created.file_updated.(!file_update_failed).example_promise_repaired"; reports: DEBUG.file_ok:: "file_ok"; + DEBUG.file_created:: "file_created"; + DEBUG.file_updated:: "file_updated"; + DEBUG.file_update_failed:: "file_update_failed"; + DEBUG.example_promise_repaired:: "example_promise_repaired"; ok:: "$(this.promise_filename) Pass"; + !ok:: "$(this.promise_filename) FAIL"; } diff --git a/tests/acceptance/30_custom_promise_types/02_if.cf b/tests/acceptance/30_custom_promise_types/02_if.cf index 39ca005a66..c060a1aa20 100644 --- a/tests/acceptance/30_custom_promise_types/02_if.cf +++ b/tests/acceptance/30_custom_promise_types/02_if.cf @@ -5,52 +5,39 @@ ##################################################### body common control { - inputs => { "../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - bundle agent init { files: - "$(G.testfile)-0" - delete => init_delete; - "$(G.testfile)-1" - delete => init_delete; - "$(G.testfile)-2" - delete => init_delete; - "$(G.testfile)-3" - delete => init_delete; - "$(G.testfile)-4" - delete => init_delete; - "$(G.testfile)-5" - delete => init_delete; - "$(G.testfile)-6" - delete => init_delete; - "$(G.testfile)-7" - delete => init_delete; - "$(G.testfile)-8" - delete => init_delete; - "$(G.testfile)-9" - delete => init_delete; - "$(G.testfile)-10" - delete => init_delete; + "$(G.testfile)-0" delete => init_delete; + "$(G.testfile)-1" delete => init_delete; + "$(G.testfile)-2" delete => init_delete; + "$(G.testfile)-3" delete => init_delete; + "$(G.testfile)-4" delete => init_delete; + "$(G.testfile)-5" delete => init_delete; + "$(G.testfile)-6" delete => init_delete; + "$(G.testfile)-7" delete => init_delete; + "$(G.testfile)-8" delete => init_delete; + "$(G.testfile)-9" delete => init_delete; + "$(G.testfile)-10" delete => init_delete; } body delete init_delete { - dirlinks => "delete"; - rmdirs => "true"; + dirlinks => "delete"; + rmdirs => "true"; } ####################################################### - promise agent example { - interpreter => "/bin/bash"; - path => "$(this.promise_dirname)/example_module.sh"; + interpreter => "/bin/bash"; + path => "$(this.promise_dirname)/example_module.sh"; } bundle agent test @@ -58,53 +45,73 @@ bundle agent test meta: "description" -> { "CFE-3391" } string => "Test that custom promises work with if attribute"; - "test_soft_fail" string => "windows", + + "test_soft_fail" + string => "windows", meta => { "ENT-10217" }; vars: - "false_variable" - string => "cfengine.(!cfengine)"; - "true_variable" - string => "cfengine|(!cfengine)"; + "false_variable" string => "cfengine.(!cfengine)"; + "true_variable" string => "cfengine|(!cfengine)"; example: cfengine:: - "$(G.testfile)-0" # Created - no condition + "$(G.testfile)-0" + # Created - no condition message => "x"; - "$(G.testfile)-1" # Created - true condition + + "$(G.testfile)-1" + # Created - true condition message => "x", if => "cfengine"; - "$(G.testfile)-2" # Created - true condition from variable + + "$(G.testfile)-2" + # Created - true condition from variable message => "x", if => "$(true_variable)"; - "$(G.testfile)-3" # Created - true condition (inverted false variable) + + "$(G.testfile)-3" + # Created - true condition (inverted false variable) message => "x", if => "!($(false_variable))"; - "$(G.testfile)-4" # Created - not function call of something false + + "$(G.testfile)-4" + # Created - not function call of something false message => "x", if => not("$(false_variable)"); - "$(G.testfile)-5" # Not created - false condition + + "$(G.testfile)-5" + # Not created - false condition message => "x", if => "!cfengine"; - "$(G.testfile)-6" # Not created - false condition from variable + + "$(G.testfile)-6" + # Not created - false condition from variable message => "x", if => "$(false_variable)"; - "$(G.testfile)-7" # Not created - false condition (inverted true variable) + + "$(G.testfile)-7" + # Not created - false condition (inverted true variable) message => "x", if => "!($(true_variable))"; - "$(G.testfile)-8" # Not created - not function call of something true + + "$(G.testfile)-8" + # Not created - not function call of something true message => "x", if => not("$(true_variable)"); - "$(G.testfile)-9" # Not created - undefined variable in if + + "$(G.testfile)-9" + # Not created - undefined variable in if message => "x", if => "$(undefined_variable)"; - "$(G.testfile)-10" # Not created - unresolved function call in if + + "$(G.testfile)-10" + # Not created - unresolved function call in if message => "x", if => not("$(undefined_variable)"); } ####################################################### - bundle agent check { classes: @@ -126,6 +133,7 @@ bundle agent check reports: ok:: "$(this.promise_filename) Pass"; + !ok:: "$(this.promise_filename) FAIL"; } diff --git a/tests/acceptance/30_custom_promise_types/05_meta_attr.cf b/tests/acceptance/30_custom_promise_types/05_meta_attr.cf index 35f09e5618..c816891fcb 100644 --- a/tests/acceptance/30_custom_promise_types/05_meta_attr.cf +++ b/tests/acceptance/30_custom_promise_types/05_meta_attr.cf @@ -7,37 +7,34 @@ ##################################################### body common control { - inputs => { "../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - bundle agent init { files: - "$(G.testfile)" - delete => init_delete; + "$(G.testfile)" delete => init_delete; } body delete init_delete { - dirlinks => "delete"; - rmdirs => "true"; + dirlinks => "delete"; + rmdirs => "true"; } ####################################################### - promise agent example { - interpreter => "/bin/bash"; - path => "$(this.promise_dirname)/example_module.sh"; + interpreter => "/bin/bash"; + path => "$(this.promise_dirname)/example_module.sh"; } body classes example { - promise_repaired => { "example_promise_repaired" }; + promise_repaired => { "example_promise_repaired" }; } bundle agent test @@ -45,12 +42,13 @@ bundle agent test meta: "description" -> { "CFE-3440" } string => "Test that you can use a meta attribute with a custom promise"; - "test_soft_fail" string => "windows", + + "test_soft_fail" + string => "windows", meta => { "ENT-10217" }; vars: - "test_string" - string => "hello, modules"; + "test_string" string => "hello, modules"; example: cfengine:: @@ -60,42 +58,49 @@ bundle agent test meta => { "tag1", "tag2" }; classes: - "file_created" - expression => canonify("$(G.testfile)_created"), - scope => "namespace"; - "file_updated" - expression => canonify("$(G.testfile)_content_updated"), - scope => "namespace"; - "file_update_failed" - expression => canonify("$(G.testfile)_content_update_failed"), - scope => "namespace"; + "file_created" + expression => canonify("$(G.testfile)_created"), + scope => "namespace"; + + "file_updated" + expression => canonify("$(G.testfile)_content_updated"), + scope => "namespace"; + + "file_update_failed" + expression => canonify("$(G.testfile)_content_update_failed"), + scope => "namespace"; } ####################################################### - bundle agent check { classes: - "file_ok" - expression => strcmp("$(test.test_string)", readfile("$(G.testfile)")), - if => fileexists("$(G.testfile)"); + "file_ok" + expression => strcmp("$(test.test_string)", readfile("$(G.testfile)")), + if => fileexists("$(G.testfile)"); - "ok" expression => "file_ok.file_created.file_updated.(!file_update_failed).example_promise_repaired"; + "ok" + expression => "file_ok.file_created.file_updated.(!file_update_failed).example_promise_repaired"; reports: DEBUG.file_ok:: "file_ok"; + DEBUG.file_created:: "file_created"; + DEBUG.file_updated:: "file_updated"; + DEBUG.file_update_failed:: "file_update_failed"; + DEBUG.example_promise_repaired:: "example_promise_repaired"; ok:: "$(this.promise_filename) Pass"; + !ok:: "$(this.promise_filename) FAIL"; } diff --git a/tests/acceptance/30_custom_promise_types/11_unless.cf b/tests/acceptance/30_custom_promise_types/11_unless.cf index a1c56638bc..ceba1ae673 100644 --- a/tests/acceptance/30_custom_promise_types/11_unless.cf +++ b/tests/acceptance/30_custom_promise_types/11_unless.cf @@ -5,52 +5,39 @@ ##################################################### body common control { - inputs => { "../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - bundle agent init { files: - "$(G.testfile)-0" - delete => init_delete; - "$(G.testfile)-1" - delete => init_delete; - "$(G.testfile)-2" - delete => init_delete; - "$(G.testfile)-3" - delete => init_delete; - "$(G.testfile)-4" - delete => init_delete; - "$(G.testfile)-5" - delete => init_delete; - "$(G.testfile)-6" - delete => init_delete; - "$(G.testfile)-7" - delete => init_delete; - "$(G.testfile)-8" - delete => init_delete; - "$(G.testfile)-9" - delete => init_delete; - "$(G.testfile)-10" - delete => init_delete; + "$(G.testfile)-0" delete => init_delete; + "$(G.testfile)-1" delete => init_delete; + "$(G.testfile)-2" delete => init_delete; + "$(G.testfile)-3" delete => init_delete; + "$(G.testfile)-4" delete => init_delete; + "$(G.testfile)-5" delete => init_delete; + "$(G.testfile)-6" delete => init_delete; + "$(G.testfile)-7" delete => init_delete; + "$(G.testfile)-8" delete => init_delete; + "$(G.testfile)-9" delete => init_delete; + "$(G.testfile)-10" delete => init_delete; } body delete init_delete { - dirlinks => "delete"; - rmdirs => "true"; + dirlinks => "delete"; + rmdirs => "true"; } ####################################################### - promise agent example { - interpreter => "/bin/bash"; - path => "$(this.promise_dirname)/example_module.sh"; + interpreter => "/bin/bash"; + path => "$(this.promise_dirname)/example_module.sh"; } bundle agent test @@ -58,53 +45,73 @@ bundle agent test meta: "description" -> { "CFE-3431" } string => "Test that custom promises work with unless attribute"; - "test_soft_fail" string => "windows", + + "test_soft_fail" + string => "windows", meta => { "ENT-10217" }; vars: - "false_variable" - string => "cfengine.(!cfengine)"; - "true_variable" - string => "cfengine|(!cfengine)"; + "false_variable" string => "cfengine.(!cfengine)"; + "true_variable" string => "cfengine|(!cfengine)"; example: cfengine:: - "$(G.testfile)-0" # Created - no condition + "$(G.testfile)-0" + # Created - no condition message => "x"; - "$(G.testfile)-1" # Not created - true condition + + "$(G.testfile)-1" + # Not created - true condition message => "x", unless => "cfengine"; - "$(G.testfile)-2" # Not created - true condition from variable + + "$(G.testfile)-2" + # Not created - true condition from variable message => "x", unless => "$(true_variable)"; - "$(G.testfile)-3" # Not created - true condition (inverted false variable) + + "$(G.testfile)-3" + # Not created - true condition (inverted false variable) message => "x", unless => "!($(false_variable))"; - "$(G.testfile)-4" # NOT - not function call of something false + + "$(G.testfile)-4" + # NOT - not function call of something false message => "x", unless => not("$(false_variable)"); - "$(G.testfile)-5" # Created - false condition + + "$(G.testfile)-5" + # Created - false condition message => "x", unless => "!cfengine"; - "$(G.testfile)-6" # Created - false condition from variable + + "$(G.testfile)-6" + # Created - false condition from variable message => "x", unless => "$(false_variable)"; - "$(G.testfile)-7" # Created - false condition (inverted true variable) + + "$(G.testfile)-7" + # Created - false condition (inverted true variable) message => "x", unless => "!($(true_variable))"; - "$(G.testfile)-8" # Created - not function call of something true + + "$(G.testfile)-8" + # Created - not function call of something true message => "x", unless => not("$(true_variable)"); - "$(G.testfile)-9" # Created - undefined variable in unless + + "$(G.testfile)-9" + # Created - undefined variable in unless message => "x", unless => "$(undefined_variable)"; - "$(G.testfile)-10" # Created - unresolved function call in unless + + "$(G.testfile)-10" + # Created - unresolved function call in unless message => "x", unless => not("$(undefined_variable)"); } ####################################################### - bundle agent check { classes: @@ -126,6 +133,7 @@ bundle agent check reports: ok:: "$(this.promise_filename) Pass"; + !ok:: "$(this.promise_filename) FAIL"; } diff --git a/tests/acceptance/30_custom_promise_types/12_multiple_promises.cf b/tests/acceptance/30_custom_promise_types/12_multiple_promises.cf index bcb3f5a6c1..024d0fcfa9 100644 --- a/tests/acceptance/30_custom_promise_types/12_multiple_promises.cf +++ b/tests/acceptance/30_custom_promise_types/12_multiple_promises.cf @@ -6,44 +6,40 @@ ##################################################### body common control { - inputs => { "../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - bundle agent init { files: - "$(G.testfile)" - delete => init_delete; - "$(G.testfile)2" - delete => init_delete; + "$(G.testfile)" delete => init_delete; + "$(G.testfile)2" delete => init_delete; } body delete init_delete { - dirlinks => "delete"; - rmdirs => "true"; + dirlinks => "delete"; + rmdirs => "true"; } ####################################################### - promise agent example { - interpreter => "/bin/bash"; - path => "$(this.promise_dirname)/example_module.sh"; + interpreter => "/bin/bash"; + path => "$(this.promise_dirname)/example_module.sh"; } body classes example { - promise_repaired => { "example_promise_repaired" }; + promise_repaired => { "example_promise_repaired" }; } body classes example2 { - promise_repaired => { "example2_promise_repaired" }; + promise_repaired => { "example2_promise_repaired" }; } bundle agent test @@ -51,85 +47,104 @@ bundle agent test meta: "description" -> { "CFE-3443" } string => "Test that you can evaluate multiple custom promises of the same type"; - "test_soft_fail" string => "windows", + + "test_soft_fail" + string => "windows", meta => { "ENT-10217" }; vars: - "test_string" - string => "hello, modules"; + "test_string" string => "hello, modules"; example: cfengine:: "$(G.testfile)" message => "$(test_string)", classes => example; + "$(G.testfile)2" message => "$(test_string)", classes => example2; classes: - "file_created" - expression => canonify("$(G.testfile)_created"), - scope => "namespace"; - "file_updated" - expression => canonify("$(G.testfile)_content_updated"), - scope => "namespace"; - "file_update_failed" - expression => canonify("$(G.testfile)_content_update_failed"), - scope => "namespace"; - "file2_created" - expression => canonify("$(G.testfile)2_created"), - scope => "namespace"; - "file2_updated" - expression => canonify("$(G.testfile)2_content_updated"), - scope => "namespace"; - "file2_update_failed" - expression => canonify("$(G.testfile)2_content_update_failed"), - scope => "namespace"; + "file_created" + expression => canonify("$(G.testfile)_created"), + scope => "namespace"; + + "file_updated" + expression => canonify("$(G.testfile)_content_updated"), + scope => "namespace"; + + "file_update_failed" + expression => canonify("$(G.testfile)_content_update_failed"), + scope => "namespace"; + + "file2_created" + expression => canonify("$(G.testfile)2_created"), + scope => "namespace"; + + "file2_updated" + expression => canonify("$(G.testfile)2_content_updated"), + scope => "namespace"; + + "file2_update_failed" + expression => canonify("$(G.testfile)2_content_update_failed"), + scope => "namespace"; } ####################################################### - bundle agent check { classes: - "file_ok" - expression => strcmp("$(test.test_string)", readfile("$(G.testfile)")), - if => fileexists("$(G.testfile)"); - "file2_ok" - expression => strcmp("$(test.test_string)", readfile("$(G.testfile)2")), - if => fileexists("$(G.testfile)2"); + "file_ok" + expression => strcmp("$(test.test_string)", readfile("$(G.testfile)")), + if => fileexists("$(G.testfile)"); + + "file2_ok" + expression => strcmp("$(test.test_string)", readfile("$(G.testfile)2")), + if => fileexists("$(G.testfile)2"); - "example_ok" expression => "file_ok.file_created.file_updated.(!file_update_failed).example_promise_repaired"; - "example2_ok" expression => "file2_ok.file2_created.file2_updated.(!file2_update_failed).example2_promise_repaired"; + "example_ok" + expression => "file_ok.file_created.file_updated.(!file_update_failed).example_promise_repaired"; - "ok" expression => "example_ok.example2_ok"; + "example2_ok" + expression => "file2_ok.file2_created.file2_updated.(!file2_update_failed).example2_promise_repaired"; + + "ok" expression => "example_ok.example2_ok"; reports: DEBUG.file_ok:: "file_ok"; + DEBUG.file_created:: "file_created"; + DEBUG.file_updated:: "file_updated"; + DEBUG.file_update_failed:: "file_update_failed"; + DEBUG.example_promise_repaired:: "example_promise_repaired"; DEBUG.file2_ok:: "file2_ok"; + DEBUG.file2_created:: "file2_created"; + DEBUG.file2_updated:: "file2_updated"; + DEBUG.file2_update_failed:: "file2_update_failed"; + DEBUG.example2_promise_repaired:: "example_promise_repaired"; ok:: "$(this.promise_filename) Pass"; + !ok:: "$(this.promise_filename) FAIL"; } diff --git a/tests/acceptance/30_custom_promise_types/13_binary_path.cf b/tests/acceptance/30_custom_promise_types/13_binary_path.cf index f6cd98acb4..13eec0ad49 100644 --- a/tests/acceptance/30_custom_promise_types/13_binary_path.cf +++ b/tests/acceptance/30_custom_promise_types/13_binary_path.cf @@ -1,8 +1,8 @@ body common control { - inputs => { "../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } promise agent binary @@ -13,11 +13,12 @@ promise agent binary bundle agent test { meta: - "test_soft_fail" string => "windows", + "test_soft_fail" + string => "windows", meta => { "ENT-10217" }; + binary: - "foobar" - classes => if_ok("binary_ok"); + "foobar" classes => if_ok("binary_ok"); } bundle agent check @@ -25,6 +26,7 @@ bundle agent check reports: binary_ok:: "$(this.promise_filename) Pass"; + !binary_ok:: "$(this.promise_filename) FAIL"; } diff --git a/tests/acceptance/30_custom_promise_types/14_multiple_promise_types_same_module.cf b/tests/acceptance/30_custom_promise_types/14_multiple_promise_types_same_module.cf index 352660a244..c6650c8441 100644 --- a/tests/acceptance/30_custom_promise_types/14_multiple_promise_types_same_module.cf +++ b/tests/acceptance/30_custom_promise_types/14_multiple_promise_types_same_module.cf @@ -6,50 +6,46 @@ ##################################################### body common control { - inputs => { "../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - bundle agent init { files: - "$(G.testfile)" - delete => init_delete; - "$(G.testfile)2" - delete => init_delete; + "$(G.testfile)" delete => init_delete; + "$(G.testfile)2" delete => init_delete; } body delete init_delete { - dirlinks => "delete"; - rmdirs => "true"; + dirlinks => "delete"; + rmdirs => "true"; } ####################################################### - promise agent example { - interpreter => "/bin/bash"; - path => "$(this.promise_dirname)/example_module.sh"; + interpreter => "/bin/bash"; + path => "$(this.promise_dirname)/example_module.sh"; } promise agent example_two { - interpreter => "/bin/bash"; - path => "$(this.promise_dirname)/example_module.sh"; + interpreter => "/bin/bash"; + path => "$(this.promise_dirname)/example_module.sh"; } body classes example { - promise_repaired => { "example_promise_repaired" }; + promise_repaired => { "example_promise_repaired" }; } body classes example2 { - promise_repaired => { "example2_promise_repaired" }; + promise_repaired => { "example2_promise_repaired" }; } bundle agent test @@ -57,12 +53,13 @@ bundle agent test meta: "description" -> { "CFE-3443" } string => "Test that you can use the same custom module for two promise types"; - "test_soft_fail" string => "windows", + + "test_soft_fail" + string => "windows", meta => { "ENT-10217" }; vars: - "test_string" - string => "hello, modules"; + "test_string" string => "hello, modules"; example: cfengine:: @@ -77,68 +74,85 @@ bundle agent test classes => example2; classes: - "file_created" - expression => canonify("$(G.testfile)_created"), - scope => "namespace"; - "file_updated" - expression => canonify("$(G.testfile)_content_updated"), - scope => "namespace"; - "file_update_failed" - expression => canonify("$(G.testfile)_content_update_failed"), - scope => "namespace"; - "file2_created" - expression => canonify("$(G.testfile)2_created"), - scope => "namespace"; - "file2_updated" - expression => canonify("$(G.testfile)2_content_updated"), - scope => "namespace"; - "file2_update_failed" - expression => canonify("$(G.testfile)2_content_update_failed"), - scope => "namespace"; + "file_created" + expression => canonify("$(G.testfile)_created"), + scope => "namespace"; + + "file_updated" + expression => canonify("$(G.testfile)_content_updated"), + scope => "namespace"; + + "file_update_failed" + expression => canonify("$(G.testfile)_content_update_failed"), + scope => "namespace"; + + "file2_created" + expression => canonify("$(G.testfile)2_created"), + scope => "namespace"; + + "file2_updated" + expression => canonify("$(G.testfile)2_content_updated"), + scope => "namespace"; + + "file2_update_failed" + expression => canonify("$(G.testfile)2_content_update_failed"), + scope => "namespace"; } ####################################################### - bundle agent check { classes: - "file_ok" - expression => strcmp("$(test.test_string)", readfile("$(G.testfile)")), - if => fileexists("$(G.testfile)"); - "file2_ok" - expression => strcmp("$(test.test_string)", readfile("$(G.testfile)2")), - if => fileexists("$(G.testfile)2"); + "file_ok" + expression => strcmp("$(test.test_string)", readfile("$(G.testfile)")), + if => fileexists("$(G.testfile)"); + + "file2_ok" + expression => strcmp("$(test.test_string)", readfile("$(G.testfile)2")), + if => fileexists("$(G.testfile)2"); - "example_ok" expression => "file_ok.file_created.file_updated.(!file_update_failed).example_promise_repaired"; - "example2_ok" expression => "file2_ok.file2_created.file2_updated.(!file2_update_failed).example2_promise_repaired"; + "example_ok" + expression => "file_ok.file_created.file_updated.(!file_update_failed).example_promise_repaired"; - "ok" expression => "example_ok.example2_ok"; + "example2_ok" + expression => "file2_ok.file2_created.file2_updated.(!file2_update_failed).example2_promise_repaired"; + + "ok" expression => "example_ok.example2_ok"; reports: DEBUG.file_ok:: "file_ok"; + DEBUG.file_created:: "file_created"; + DEBUG.file_updated:: "file_updated"; + DEBUG.file_update_failed:: "file_update_failed"; + DEBUG.example_promise_repaired:: "example_promise_repaired"; DEBUG.file2_ok:: "file2_ok"; + DEBUG.file2_created:: "file2_created"; + DEBUG.file2_updated:: "file2_updated"; + DEBUG.file2_update_failed:: "file2_update_failed"; + DEBUG.example2_promise_repaired:: "example_promise_repaired"; ok:: "$(this.promise_filename) Pass"; + !ok:: "$(this.promise_filename) FAIL"; } diff --git a/tests/acceptance/30_custom_promise_types/15_conflicting_interpreters.cf b/tests/acceptance/30_custom_promise_types/15_conflicting_interpreters.cf index eb108acda6..78a93342eb 100644 --- a/tests/acceptance/30_custom_promise_types/15_conflicting_interpreters.cf +++ b/tests/acceptance/30_custom_promise_types/15_conflicting_interpreters.cf @@ -7,50 +7,46 @@ ##################################################### body common control { - inputs => { "../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - bundle agent init { files: - "$(G.testfile)" - delete => init_delete; - "$(G.testfile)2" - delete => init_delete; + "$(G.testfile)" delete => init_delete; + "$(G.testfile)2" delete => init_delete; } body delete init_delete { - dirlinks => "delete"; - rmdirs => "true"; + dirlinks => "delete"; + rmdirs => "true"; } ####################################################### - promise agent example { - interpreter => "/bin/bash"; - path => "$(this.promise_dirname)/example_module.sh"; + interpreter => "/bin/bash"; + path => "$(this.promise_dirname)/example_module.sh"; } promise agent example_two { - interpreter => "/bin/bash_noexist"; - path => "$(this.promise_dirname)/example_module.sh"; + interpreter => "/bin/bash_noexist"; + path => "$(this.promise_dirname)/example_module.sh"; } body classes example { - promise_repaired => { "example_promise_repaired" }; + promise_repaired => { "example_promise_repaired" }; } body classes example2 { - promise_repaired => { "example2_promise_repaired" }; + promise_repaired => { "example2_promise_repaired" }; } bundle agent test @@ -58,12 +54,13 @@ bundle agent test meta: "description" -> { "CFE-3443" } string => "Test that you cannot use a promise module with two different interpreters"; - "test_soft_fail" string => "windows", + + "test_soft_fail" + string => "windows", meta => { "ENT-10217" }; vars: - "test_string" - string => "hello, modules"; + "test_string" string => "hello, modules"; example: cfengine:: @@ -78,68 +75,85 @@ bundle agent test classes => example2; classes: - "file_created" - expression => canonify("$(G.testfile)_created"), - scope => "namespace"; - "file_updated" - expression => canonify("$(G.testfile)_content_updated"), - scope => "namespace"; - "file_update_failed" - expression => canonify("$(G.testfile)_content_update_failed"), - scope => "namespace"; - "file2_created" - expression => canonify("$(G.testfile)2_created"), - scope => "namespace"; - "file2_updated" - expression => canonify("$(G.testfile)2_content_updated"), - scope => "namespace"; - "file2_update_failed" - expression => canonify("$(G.testfile)2_content_update_failed"), - scope => "namespace"; + "file_created" + expression => canonify("$(G.testfile)_created"), + scope => "namespace"; + + "file_updated" + expression => canonify("$(G.testfile)_content_updated"), + scope => "namespace"; + + "file_update_failed" + expression => canonify("$(G.testfile)_content_update_failed"), + scope => "namespace"; + + "file2_created" + expression => canonify("$(G.testfile)2_created"), + scope => "namespace"; + + "file2_updated" + expression => canonify("$(G.testfile)2_content_updated"), + scope => "namespace"; + + "file2_update_failed" + expression => canonify("$(G.testfile)2_content_update_failed"), + scope => "namespace"; } ####################################################### - bundle agent check { classes: - "file_ok" - expression => strcmp("$(test.test_string)", readfile("$(G.testfile)")), - if => fileexists("$(G.testfile)"); - "file2_ok" - expression => strcmp("$(test.test_string)", readfile("$(G.testfile)2")), - if => fileexists("$(G.testfile)2"); + "file_ok" + expression => strcmp("$(test.test_string)", readfile("$(G.testfile)")), + if => fileexists("$(G.testfile)"); + + "file2_ok" + expression => strcmp("$(test.test_string)", readfile("$(G.testfile)2")), + if => fileexists("$(G.testfile)2"); - "example_ok" expression => "file_ok.file_created.file_updated.(!file_update_failed).example_promise_repaired"; - "example2_ok" expression => "!file2_ok.!file2_created.!file2_updated.!file2_update_failed.!example2_promise_repaired"; + "example_ok" + expression => "file_ok.file_created.file_updated.(!file_update_failed).example_promise_repaired"; - "ok" expression => "example_ok.example2_ok"; + "example2_ok" + expression => "!file2_ok.!file2_created.!file2_updated.!file2_update_failed.!example2_promise_repaired"; + + "ok" expression => "example_ok.example2_ok"; reports: DEBUG.file_ok:: "file_ok"; + DEBUG.file_created:: "file_created"; + DEBUG.file_updated:: "file_updated"; + DEBUG.file_update_failed:: "file_update_failed"; + DEBUG.example_promise_repaired:: "example_promise_repaired"; DEBUG.file2_ok:: "file2_ok"; + DEBUG.file2_created:: "file2_created"; + DEBUG.file2_updated:: "file2_updated"; + DEBUG.file2_update_failed:: "file2_update_failed"; + DEBUG.example2_promise_repaired:: "example_promise_repaired"; ok:: "$(this.promise_filename) Pass"; + !ok:: "$(this.promise_filename) FAIL"; } diff --git a/tests/acceptance/30_custom_promise_types/17_early_module_failure.cf b/tests/acceptance/30_custom_promise_types/17_early_module_failure.cf index 2210b316dc..631b4d8317 100644 --- a/tests/acceptance/30_custom_promise_types/17_early_module_failure.cf +++ b/tests/acceptance/30_custom_promise_types/17_early_module_failure.cf @@ -5,20 +5,24 @@ ##################################################### body common control { - inputs => { "../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - bundle agent check { vars: - "command" string => "$(sys.cf_agent) -D AUTO -KIf $(this.promise_filename).sub"; + "command" + string => "$(sys.cf_agent) -D AUTO -KIf $(this.promise_filename).sub"; methods: - "check" - usebundle => dcs_passif_output(".*error:.*", ".*(Assertion.*failed|fault).*", - $(command), $(this.promise_filename)); + "check" + usebundle => dcs_passif_output( + ".*error:.*", + ".*(Assertion.*failed|fault).*", + $(command), + $(this.promise_filename) + ); } diff --git a/tests/acceptance/30_custom_promise_types/18_early_module_failure_classes.cf b/tests/acceptance/30_custom_promise_types/18_early_module_failure_classes.cf index 86e6c67995..f47d17b546 100644 --- a/tests/acceptance/30_custom_promise_types/18_early_module_failure_classes.cf +++ b/tests/acceptance/30_custom_promise_types/18_early_module_failure_classes.cf @@ -5,17 +5,16 @@ ##################################################### body common control { - inputs => { "../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - promise agent bad { - interpreter => "/usr/bin/python3"; - path => "$(this.promise_dirname)/bad_import.py"; + interpreter => "/usr/bin/python3"; + path => "$(this.promise_dirname)/bad_import.py"; } bundle agent test @@ -25,24 +24,24 @@ bundle agent test string => "Test that a promise using an early-failing custom module still sets result classes"; bad: - "doesn't matter what I put here" - classes => test; + "doesn't matter what I put here" classes => test; } body classes test { - promise_repaired => { "test_promise_repaired" }; - repair_failed => { "test_promise_failed" }; + promise_repaired => { "test_promise_repaired" }; + repair_failed => { "test_promise_failed" }; } bundle agent check { classes: - "ok" expression => "test_promise_failed"; + "ok" expression => "test_promise_failed"; reports: ok:: "$(this.promise_filename) Pass"; + !ok:: "$(this.promise_filename) FAIL"; } diff --git a/tests/acceptance/30_custom_promise_types/22_what_module_gets.cf b/tests/acceptance/30_custom_promise_types/22_what_module_gets.cf index 63181be6af..80953def2f 100644 --- a/tests/acceptance/30_custom_promise_types/22_what_module_gets.cf +++ b/tests/acceptance/30_custom_promise_types/22_what_module_gets.cf @@ -5,32 +5,29 @@ ##################################################### body common control { - inputs => { "../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - bundle agent init { files: - "/tmp/module.log" - delete => init_delete; + "/tmp/module.log" delete => init_delete; } body delete init_delete { - dirlinks => "delete"; - rmdirs => "true"; + dirlinks => "delete"; + rmdirs => "true"; } ####################################################### - promise agent example { - interpreter => "/bin/bash"; - path => "$(this.promise_dirname)/cat_module.sh"; + interpreter => "/bin/bash"; + path => "$(this.promise_dirname)/cat_module.sh"; } bundle agent test @@ -38,21 +35,24 @@ bundle agent test meta: "description" -> { "CFE-3723" } string => "Test that input from cf-agent to promise module matches expected data"; - "test_soft_fail" string => "windows", + + "test_soft_fail" + string => "windows", meta => { "ENT-10217" }; example: cfengine:: - "Promiser" - attributeName => "attributeValue"; + "Promiser" attributeName => "attributeValue"; } ####################################################### - bundle agent check { methods: - "any" usebundle => dcs_check_diff("/tmp/module.log", - "$(this.promise_filename).expected", - "$(this.promise_filename)"); + "any" + usebundle => dcs_check_diff( + "/tmp/module.log", + "$(this.promise_filename).expected", + "$(this.promise_filename)" + ); } diff --git a/tests/acceptance/30_custom_promise_types/23_action_policy/dryrun_supported.cf b/tests/acceptance/30_custom_promise_types/23_action_policy/dryrun_supported.cf index 7b009e09ec..2c50cf5a26 100644 --- a/tests/acceptance/30_custom_promise_types/23_action_policy/dryrun_supported.cf +++ b/tests/acceptance/30_custom_promise_types/23_action_policy/dryrun_supported.cf @@ -6,29 +6,35 @@ ##################################################### body common control { - inputs => { "../../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - bundle agent test { meta: "description" -> { "CFE-3433" } string => "Test that dry-run can be used with custom promise modules supporting it"; - "test_soft_fail" string => "windows", + + "test_soft_fail" + string => "windows", meta => { "ENT-10217" }; } bundle agent check { vars: - "command" string => "$(sys.cf_agent) --dry-run -D AUTO -KIf $(this.promise_filename).sub"; + "command" + string => "$(sys.cf_agent) --dry-run -D AUTO -KIf $(this.promise_filename).sub"; methods: - "check" - usebundle => dcs_passif_output(".*warning: Should.*", ".*CRITICAL:.*", - $(command), $(this.promise_filename)); + "check" + usebundle => dcs_passif_output( + ".*warning: Should.*", + ".*CRITICAL:.*", + $(command), + $(this.promise_filename) + ); } diff --git a/tests/acceptance/30_custom_promise_types/23_action_policy/dryrun_unsupported.cf b/tests/acceptance/30_custom_promise_types/23_action_policy/dryrun_unsupported.cf index 77e213b673..1e61d2029a 100644 --- a/tests/acceptance/30_custom_promise_types/23_action_policy/dryrun_unsupported.cf +++ b/tests/acceptance/30_custom_promise_types/23_action_policy/dryrun_unsupported.cf @@ -6,29 +6,35 @@ ##################################################### body common control { - inputs => { "../../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - bundle agent test { meta: "description" -> { "CFE-3433" } string => "Test that --dry-run produces errors when used with custom promise modules not supporting it"; - "test_soft_fail" string => "windows", + + "test_soft_fail" + string => "windows", meta => { "ENT-10217" }; } bundle agent check { vars: - "command" string => "$(sys.cf_agent) --dry-run -D AUTO -KIf $(this.promise_filename).sub"; + "command" + string => "$(sys.cf_agent) --dry-run -D AUTO -KIf $(this.promise_filename).sub"; methods: - "check" - usebundle => dcs_passif_output(".*error: Not making changes.*", ".*CRITICAL:.*", - $(command), $(this.promise_filename)); + "check" + usebundle => dcs_passif_output( + ".*error: Not making changes.*", + ".*CRITICAL:.*", + $(command), + $(this.promise_filename) + ); } diff --git a/tests/acceptance/30_custom_promise_types/23_action_policy/explicit_warn_fake_supported.cf b/tests/acceptance/30_custom_promise_types/23_action_policy/explicit_warn_fake_supported.cf index 81ed9896aa..42da613e6f 100644 --- a/tests/acceptance/30_custom_promise_types/23_action_policy/explicit_warn_fake_supported.cf +++ b/tests/acceptance/30_custom_promise_types/23_action_policy/explicit_warn_fake_supported.cf @@ -6,29 +6,35 @@ ##################################################### body common control { - inputs => { "../../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - bundle agent test { meta: "description" -> { "CFE-3433" } string => "Test that a bug in a module is reported if it advertises action_policy feature, but doesn't properly implement it"; - "test_soft_fail" string => "windows", + + "test_soft_fail" + string => "windows", meta => { "ENT-10217" }; } bundle agent check { vars: - "command" string => "$(sys.cf_agent) -D AUTO -KIf $(this.promise_filename).sub"; + "command" + string => "$(sys.cf_agent) -D AUTO -KIf $(this.promise_filename).sub"; methods: - "check" - usebundle => dcs_passif_output(".*CRITICAL: Bug in promise module.*", "", - $(command), $(this.promise_filename)); + "check" + usebundle => dcs_passif_output( + ".*CRITICAL: Bug in promise module.*", + "", + $(command), + $(this.promise_filename) + ); } diff --git a/tests/acceptance/30_custom_promise_types/23_action_policy/explicit_warn_supported.cf b/tests/acceptance/30_custom_promise_types/23_action_policy/explicit_warn_supported.cf index 37e68f5518..9364265248 100644 --- a/tests/acceptance/30_custom_promise_types/23_action_policy/explicit_warn_supported.cf +++ b/tests/acceptance/30_custom_promise_types/23_action_policy/explicit_warn_supported.cf @@ -6,29 +6,35 @@ ##################################################### body common control { - inputs => { "../../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - bundle agent test { meta: "description" -> { "CFE-3433" } string => "Test that action_policy can be used with custom promise modules supporting it"; - "test_soft_fail" string => "windows", + + "test_soft_fail" + string => "windows", meta => { "ENT-10217" }; } bundle agent check { vars: - "command" string => "$(sys.cf_agent) -D AUTO -KIf $(this.promise_filename).sub"; + "command" + string => "$(sys.cf_agent) -D AUTO -KIf $(this.promise_filename).sub"; methods: - "check" - usebundle => dcs_passif_output(".*warning: Should.*", ".*CRITICAL:.*", - $(command), $(this.promise_filename)); + "check" + usebundle => dcs_passif_output( + ".*warning: Should.*", + ".*CRITICAL:.*", + $(command), + $(this.promise_filename) + ); } diff --git a/tests/acceptance/30_custom_promise_types/23_action_policy/explicit_warn_unsupported.cf b/tests/acceptance/30_custom_promise_types/23_action_policy/explicit_warn_unsupported.cf index 27df2493b3..a1e928ae91 100644 --- a/tests/acceptance/30_custom_promise_types/23_action_policy/explicit_warn_unsupported.cf +++ b/tests/acceptance/30_custom_promise_types/23_action_policy/explicit_warn_unsupported.cf @@ -6,29 +6,35 @@ ##################################################### body common control { - inputs => { "../../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - bundle agent test { meta: "description" -> { "CFE-3433" } string => "Test that action_policy produces errors when used with custom promise modules not supporting it"; - "test_soft_fail" string => "windows", + + "test_soft_fail" + string => "windows", meta => { "ENT-10217" }; } bundle agent check { vars: - "command" string => "$(sys.cf_agent) -D AUTO -KIf $(this.promise_filename).sub"; + "command" + string => "$(sys.cf_agent) -D AUTO -KIf $(this.promise_filename).sub"; methods: - "check" - usebundle => dcs_passif_output(".*error: Not making changes.*", ".*CRITICAL:.*", - $(command), $(this.promise_filename)); + "check" + usebundle => dcs_passif_output( + ".*error: Not making changes.*", + ".*CRITICAL:.*", + $(command), + $(this.promise_filename) + ); } diff --git a/tests/acceptance/30_custom_promise_types/23_action_policy/simulate_supported.cf b/tests/acceptance/30_custom_promise_types/23_action_policy/simulate_supported.cf index 2094f3759a..05f9329e1d 100644 --- a/tests/acceptance/30_custom_promise_types/23_action_policy/simulate_supported.cf +++ b/tests/acceptance/30_custom_promise_types/23_action_policy/simulate_supported.cf @@ -6,29 +6,35 @@ ##################################################### body common control { - inputs => { "../../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - bundle agent test { meta: "description" -> { "CFE-3433" } string => "Test that --simulate can be used with custom promise modules supporting it"; - "test_soft_fail" string => "windows", + + "test_soft_fail" + string => "windows", meta => { "ENT-10217" }; } bundle agent check { vars: - "command" string => "$(sys.cf_agent) --simulate manifest -D AUTO -KIf $(this.promise_filename).sub"; + "command" + string => "$(sys.cf_agent) --simulate manifest -D AUTO -KIf $(this.promise_filename).sub"; methods: - "check" - usebundle => dcs_passif_output(".*warning: Should.*", ".*CRITICAL:.*", - $(command), $(this.promise_filename)); + "check" + usebundle => dcs_passif_output( + ".*warning: Should.*", + ".*CRITICAL:.*", + $(command), + $(this.promise_filename) + ); } diff --git a/tests/acceptance/30_custom_promise_types/23_action_policy/simulate_unsupported.cf b/tests/acceptance/30_custom_promise_types/23_action_policy/simulate_unsupported.cf index 3b6408b13f..fece267512 100644 --- a/tests/acceptance/30_custom_promise_types/23_action_policy/simulate_unsupported.cf +++ b/tests/acceptance/30_custom_promise_types/23_action_policy/simulate_unsupported.cf @@ -6,29 +6,35 @@ ##################################################### body common control { - inputs => { "../../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - bundle agent test { meta: "description" -> { "CFE-3433" } string => "Test that --simulate produces errors when used with custom promise modules not supporting it"; - "test_soft_fail" string => "windows", + + "test_soft_fail" + string => "windows", meta => { "ENT-10217" }; } bundle agent check { vars: - "command" string => "$(sys.cf_agent) --simulate manifest -D AUTO -KIf $(this.promise_filename).sub"; + "command" + string => "$(sys.cf_agent) --simulate manifest -D AUTO -KIf $(this.promise_filename).sub"; methods: - "check" - usebundle => dcs_passif_output(".*error: Not making changes.*", ".*CRITICAL:.*", - $(command), $(this.promise_filename)); + "check" + usebundle => dcs_passif_output( + ".*error: Not making changes.*", + ".*CRITICAL:.*", + $(command), + $(this.promise_filename) + ); } From 99cf857d3116954259cbef0734afbbd51053b68d Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Thu, 25 Jun 2026 15:08:20 +0200 Subject: [PATCH 4/7] cfengine format ./tests/acceptance/29_simulate_mode/ Signed-off-by: Ole Herman Schumacher Elgesem --- .../acceptance/29_simulate_mode/diff_mode.cf | 38 +++++++++++-------- .../29_simulate_mode/manifest_full_mode.cf | 38 +++++++++++-------- .../29_simulate_mode/manifest_mode.cf | 38 +++++++++++-------- .../simulate_safe_functions.cf | 29 ++++++++++---- 4 files changed, 88 insertions(+), 55 deletions(-) diff --git a/tests/acceptance/29_simulate_mode/diff_mode.cf b/tests/acceptance/29_simulate_mode/diff_mode.cf index 971c6da897..a72b6ee53f 100644 --- a/tests/acceptance/29_simulate_mode/diff_mode.cf +++ b/tests/acceptance/29_simulate_mode/diff_mode.cf @@ -1,15 +1,14 @@ body common control { - inputs => { - "../default.sub.cf", - "./prepare_files_for_simulate_tests.cf.sub", - "./normalize_agent_output.cf.sub" - }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { + "../default.sub.cf", + "./prepare_files_for_simulate_tests.cf.sub", + "./normalize_agent_output.cf.sub", + }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } - bundle agent init { methods: @@ -19,11 +18,12 @@ bundle agent init bundle agent test { meta: - "test_soft_fail" string => "(solaris|aix|hpux|windows)", + "test_soft_fail" + string => "(solaris|aix|hpux|windows)", meta => { "ENT-6540,ENT-10254" }; - # ENT-6540 exotics fail to delete chroot - # ENT-10254 tests fail on Windows due to CRLF + # ENT-6540 exotics fail to delete chroot + # ENT-10254 tests fail on Windows due to CRLF "description" -> { "ENT-5302" } string => "Test that files promises in --simulate=diff mode produce proper output and only make changes in chroot"; @@ -37,9 +37,15 @@ bundle agent test bundle agent check { methods: - "normalize_agent_results" usebundle => normalize_agent_results("$(this.promise_filename).temp", - "$(this.promise_filename).actual"); - "check" usebundle => dcs_check_diff("$(this.promise_filename).actual", - "$(this.promise_filename).expected", - "$(this.promise_filename)"); + "normalize_agent_results" + usebundle => normalize_agent_results( + "$(this.promise_filename).temp", "$(this.promise_filename).actual" + ); + + "check" + usebundle => dcs_check_diff( + "$(this.promise_filename).actual", + "$(this.promise_filename).expected", + "$(this.promise_filename)" + ); } diff --git a/tests/acceptance/29_simulate_mode/manifest_full_mode.cf b/tests/acceptance/29_simulate_mode/manifest_full_mode.cf index db7a6a1f22..9ebdecfa80 100644 --- a/tests/acceptance/29_simulate_mode/manifest_full_mode.cf +++ b/tests/acceptance/29_simulate_mode/manifest_full_mode.cf @@ -1,15 +1,14 @@ body common control { - inputs => { - "../default.sub.cf", - "./prepare_files_for_simulate_tests.cf.sub", - "./normalize_agent_output.cf.sub" - }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { + "../default.sub.cf", + "./prepare_files_for_simulate_tests.cf.sub", + "./normalize_agent_output.cf.sub", + }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } - bundle agent init { methods: @@ -19,11 +18,12 @@ bundle agent init bundle agent test { meta: - "test_soft_fail" string => "(solaris|aix|hpux|windows)", + "test_soft_fail" + string => "(solaris|aix|hpux|windows)", meta => { "ENT-6540,ENT-10254" }; - # ENT-6540 exotics fail to delete chroot - # ENT-10254 tests fail on Windows due to CRLF + # ENT-6540 exotics fail to delete chroot + # ENT-10254 tests fail on Windows due to CRLF "description" -> { "ENT-5301" } string => "Test that files promises in --simulate=manifest-full mode produce proper output and only make changes in chroot"; @@ -37,9 +37,15 @@ bundle agent test bundle agent check { methods: - "normalize_agent_results" usebundle => normalize_agent_results("$(this.promise_filename).temp", - "$(this.promise_filename).actual"); - "check" usebundle => dcs_check_diff("$(this.promise_filename).actual", - "$(this.promise_filename).expected", - "$(this.promise_filename)"); + "normalize_agent_results" + usebundle => normalize_agent_results( + "$(this.promise_filename).temp", "$(this.promise_filename).actual" + ); + + "check" + usebundle => dcs_check_diff( + "$(this.promise_filename).actual", + "$(this.promise_filename).expected", + "$(this.promise_filename)" + ); } diff --git a/tests/acceptance/29_simulate_mode/manifest_mode.cf b/tests/acceptance/29_simulate_mode/manifest_mode.cf index 711c356d23..59c8bdd7c2 100644 --- a/tests/acceptance/29_simulate_mode/manifest_mode.cf +++ b/tests/acceptance/29_simulate_mode/manifest_mode.cf @@ -1,15 +1,14 @@ body common control { - inputs => { - "../default.sub.cf", - "./prepare_files_for_simulate_tests.cf.sub", - "./normalize_agent_output.cf.sub" - }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { + "../default.sub.cf", + "./prepare_files_for_simulate_tests.cf.sub", + "./normalize_agent_output.cf.sub", + }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } - bundle agent init { methods: @@ -19,11 +18,12 @@ bundle agent init bundle agent test { meta: - "test_soft_fail" string => "(solaris|aix|hpux|windows)", + "test_soft_fail" + string => "(solaris|aix|hpux|windows)", meta => { "ENT-6540,ENT-10254" }; - # ENT-6540 exotics fail to delete chroot - # ENT-10254 tests fail on Windows due to CRLF + # ENT-6540 exotics fail to delete chroot + # ENT-10254 tests fail on Windows due to CRLF "description" -> { "ENT-5301" } string => "Test that files promises in --simulate=manifest mode produce proper output and only make changes in chroot"; @@ -37,9 +37,15 @@ bundle agent test bundle agent check { methods: - "normalize_agent_results" usebundle => normalize_agent_results("$(this.promise_filename).temp", - "$(this.promise_filename).actual"); - "check" usebundle => dcs_check_diff("$(this.promise_filename).actual", - "$(this.promise_filename).expected", - "$(this.promise_filename)"); + "normalize_agent_results" + usebundle => normalize_agent_results( + "$(this.promise_filename).temp", "$(this.promise_filename).actual" + ); + + "check" + usebundle => dcs_check_diff( + "$(this.promise_filename).actual", + "$(this.promise_filename).expected", + "$(this.promise_filename)" + ); } diff --git a/tests/acceptance/29_simulate_mode/simulate_safe_functions.cf b/tests/acceptance/29_simulate_mode/simulate_safe_functions.cf index 0de654013e..289f5811d5 100644 --- a/tests/acceptance/29_simulate_mode/simulate_safe_functions.cf +++ b/tests/acceptance/29_simulate_mode/simulate_safe_functions.cf @@ -7,18 +7,22 @@ body common control 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"; + "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; + "$(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), @@ -34,7 +38,12 @@ bundle agent test 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"); + "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" @@ -44,8 +53,14 @@ bundle agent test bundle agent check { vars: - "result" string => readfile("$(sys.workdir)$(const.dirsep)state$(const.dirsep)agent.log"); + "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"); + "Pass/FAIL" + usebundle => dcs_check_strcmp( + "$(result)", "FAIL", $(this.promise_filename), "yes" + ); } From 3b1ab1ac30379d912218c2bb96cc3a9a06ddd282 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Thu, 25 Jun 2026 15:08:50 +0200 Subject: [PATCH 5/7] cfengine format ./tests/acceptance/25_cf-execd/ Signed-off-by: Ole Herman Schumacher Elgesem --- .../25_cf-execd/mail_1st_run_empty_new_log.cf | 40 ++-- .../25_cf-execd/mail_empty_old_and_new_log.cf | 48 +++-- .../25_cf-execd/mail_exclude_filter.cf | 43 ++-- .../mail_include_and_exclude_filters.cf | 71 ++++--- .../25_cf-execd/mail_include_filter.cf | 43 ++-- .../acceptance/25_cf-execd/mail_no_filter.cf | 36 ++-- .../mailfilter_1st_run_everything_filtered.cf | 44 ++--- ...ilter_empty_old_log_everything_filtered.cf | 52 +++-- .../25_cf-execd/slow/dies_in_time.cf | 85 ++++---- .../timed/mailfilter_repeated_runs.cf | 184 ++++++++++-------- 10 files changed, 327 insertions(+), 319 deletions(-) diff --git a/tests/acceptance/25_cf-execd/mail_1st_run_empty_new_log.cf b/tests/acceptance/25_cf-execd/mail_1st_run_empty_new_log.cf index 3e3aecfa65..b7a6a7ac0a 100644 --- a/tests/acceptance/25_cf-execd/mail_1st_run_empty_new_log.cf +++ b/tests/acceptance/25_cf-execd/mail_1st_run_empty_new_log.cf @@ -1,44 +1,42 @@ # Tests that no mail is sent by cf-execd on the first run (hence the old log # doesn't exist) and if the new log is empty. - body common control { - inputs => { "../default.sub.cf", "mailfilter_common.cf.sub" }; - bundlesequence => { default($(this.promiser_filename)) }; + inputs => { "../default.sub.cf", "mailfilter_common.cf.sub" }; + bundlesequence => { default($(this.promiser_filename)) }; } bundle agent init { vars: - "reports" slist => { - }; - - # No mail is expected at all, since everything is filtered. - "expected" slist => { }; - "unexpected" slist => { ".+" }; + "reports" slist => {}; - "includes" slist => { - }; - "excludes" slist => { - }; + # No mail is expected at all, since everything is filtered. + "expected" slist => {}; + "unexpected" slist => { ".+" }; + "includes" slist => {}; + "excludes" slist => {}; methods: - "any" usebundle => prepare_mailfilter_test(@(reports), - @(includes), - @(excludes)); + "any" + usebundle => prepare_mailfilter_test( + @(reports), @(includes), @(excludes) + ); } bundle agent test { meta: - "test_soft_fail" string => "windows", - meta => { "ENT-10215" }; + "test_soft_fail" + string => "windows", + meta => { "ENT-10215" }; } bundle agent check { methods: - "any" usebundle => check_cf_execd_mail(@(init.expected), - @(init.unexpected), - $(this.promise_filename)); + "any" + usebundle => check_cf_execd_mail( + @(init.expected), @(init.unexpected), $(this.promise_filename) + ); } diff --git a/tests/acceptance/25_cf-execd/mail_empty_old_and_new_log.cf b/tests/acceptance/25_cf-execd/mail_empty_old_and_new_log.cf index dbe497c931..317ab54dea 100644 --- a/tests/acceptance/25_cf-execd/mail_empty_old_and_new_log.cf +++ b/tests/acceptance/25_cf-execd/mail_empty_old_and_new_log.cf @@ -1,49 +1,47 @@ # Tests that no mail is sent by cf-execd if the old and new logs are empty. - body common control { - inputs => { "../default.sub.cf", "mailfilter_common.cf.sub" }; - bundlesequence => { default($(this.promiser_filename)) }; + inputs => { "../default.sub.cf", "mailfilter_common.cf.sub" }; + bundlesequence => { default($(this.promiser_filename)) }; } bundle agent init { vars: - "reports" slist => { - }; - - # No mail is expected at all, since everything is filtered. - "expected" slist => { }; - "unexpected" slist => { ".+" }; + "reports" slist => {}; - "includes" slist => { - }; - "excludes" slist => { - }; + # No mail is expected at all, since everything is filtered. + "expected" slist => {}; + "unexpected" slist => { ".+" }; + "includes" slist => {}; + "excludes" slist => {}; methods: - "any" usebundle => prepare_mailfilter_test(@(reports), - @(includes), - @(excludes)); + "any" + usebundle => prepare_mailfilter_test( + @(reports), @(includes), @(excludes) + ); files: - "$(sys.workdir)/outputs/old.log" - create => "true"; - "$(sys.workdir)/outputs/previous" - link_from => linkfrom("$(sys.workdir)/outputs/old.log", "symlink"); + "$(sys.workdir)/outputs/old.log" create => "true"; + + "$(sys.workdir)/outputs/previous" + link_from => linkfrom("$(sys.workdir)/outputs/old.log", "symlink"); } bundle agent test { meta: - "test_soft_fail" string => "windows", - meta => { "ENT-10215" }; + "test_soft_fail" + string => "windows", + meta => { "ENT-10215" }; } bundle agent check { methods: - "any" usebundle => check_cf_execd_mail(@(init.expected), - @(init.unexpected), - $(this.promise_filename)); + "any" + usebundle => check_cf_execd_mail( + @(init.expected), @(init.unexpected), $(this.promise_filename) + ); } diff --git a/tests/acceptance/25_cf-execd/mail_exclude_filter.cf b/tests/acceptance/25_cf-execd/mail_exclude_filter.cf index 3269074618..521db06207 100644 --- a/tests/acceptance/25_cf-execd/mail_exclude_filter.cf +++ b/tests/acceptance/25_cf-execd/mail_exclude_filter.cf @@ -1,45 +1,46 @@ # Tests that exclude mail filter causes excluded lines not to be mailed by # cf-execd. - body common control { - inputs => { "../default.sub.cf", "mailfilter_common.cf.sub" }; - bundlesequence => { default($(this.promise_filename)) }; + inputs => { "../default.sub.cf", "mailfilter_common.cf.sub" }; + bundlesequence => { default($(this.promise_filename)) }; } bundle agent init { vars: - "reports" slist => { - "CorrectString1", - "CorrectString2", - "WrongString1", - "WrongString2", - }; - "includes" slist => { }; - "excludes" slist => { "R: WrongString1", ".*WrongString[2]" }; + "reports" + slist => { + "CorrectString1", "CorrectString2", "WrongString1", "WrongString2", + }; + + "includes" slist => {}; + "excludes" slist => { "R: WrongString1", ".*WrongString[2]" }; methods: - "any" usebundle => prepare_mailfilter_test(@(reports), - @(includes), - @(excludes)); + "any" + usebundle => prepare_mailfilter_test( + @(reports), @(includes), @(excludes) + ); } bundle agent test { meta: - "test_soft_fail" string => "windows", - meta => { "ENT-10215" }; + "test_soft_fail" + string => "windows", + meta => { "ENT-10215" }; } bundle agent check { vars: - "expected" slist => { "CorrectString1", "CorrectString2" }; - "not_expected" slist => { "WrongString1", "WrongString2" }; + "expected" slist => { "CorrectString1", "CorrectString2" }; + "not_expected" slist => { "WrongString1", "WrongString2" }; methods: - "any" usebundle => check_cf_execd_mail(@(expected), - @(not_expected), - $(this.promise_filename)); + "any" + usebundle => check_cf_execd_mail( + @(expected), @(not_expected), $(this.promise_filename) + ); } diff --git a/tests/acceptance/25_cf-execd/mail_include_and_exclude_filters.cf b/tests/acceptance/25_cf-execd/mail_include_and_exclude_filters.cf index a944a0756f..744562d0cb 100644 --- a/tests/acceptance/25_cf-execd/mail_include_and_exclude_filters.cf +++ b/tests/acceptance/25_cf-execd/mail_include_and_exclude_filters.cf @@ -1,54 +1,65 @@ # Tests that combining include and exclude mail filters works, IOW only lines # matching the include filter should be printed, unless they also match the # exclude filter. - body common control { - inputs => { "../default.sub.cf", "mailfilter_common.cf.sub" }; - bundlesequence => { default($(this.promise_filename)) }; + inputs => { "../default.sub.cf", "mailfilter_common.cf.sub" }; + bundlesequence => { default($(this.promise_filename)) }; } bundle agent init { vars: - "reports" slist => { - "CorrectString1", - "CorrectString2", - "WrongString1", - "WrongString2", - "WrongString3", - }; - "includes" slist => { - "R: CorrectString1", ".*CorrectString[2]", - "R: WrongString1", ".*WrongString[2]" - }; - "excludes" slist => { - "R: WrongString1", ".*WrongString[2]", - # Tests anchoring. This is only a part of the string - # and should not match. - "orrectString1" - }; + "reports" + slist => { + "CorrectString1", + "CorrectString2", + "WrongString1", + "WrongString2", + "WrongString3", + }; + + "includes" + slist => { + "R: CorrectString1", + ".*CorrectString[2]", + "R: WrongString1", + ".*WrongString[2]", + }; + + "excludes" + slist => { + "R: WrongString1", + ".*WrongString[2]", + # Tests anchoring. This is only a part of the string + # and should not match. + "orrectString1", + }; + methods: - "any" usebundle => prepare_mailfilter_test(@(reports), - @(includes), - @(excludes)); + "any" + usebundle => prepare_mailfilter_test( + @(reports), @(includes), @(excludes) + ); } bundle agent test { meta: - "test_soft_fail" string => "windows", - meta => { "ENT-10215" }; + "test_soft_fail" + string => "windows", + meta => { "ENT-10215" }; } bundle agent check { vars: - "expected" slist => { "CorrectString1", "CorrectString2" }; - "not_expected" slist => { "WrongString1", "WrongString2", "WrongString3" }; + "expected" slist => { "CorrectString1", "CorrectString2" }; + "not_expected" slist => { "WrongString1", "WrongString2", "WrongString3" }; methods: - "any" usebundle => check_cf_execd_mail(@(expected), - @(not_expected), - $(this.promise_filename)); + "any" + usebundle => check_cf_execd_mail( + @(expected), @(not_expected), $(this.promise_filename) + ); } diff --git a/tests/acceptance/25_cf-execd/mail_include_filter.cf b/tests/acceptance/25_cf-execd/mail_include_filter.cf index 5d68ad05e3..9091eae0b1 100644 --- a/tests/acceptance/25_cf-execd/mail_include_filter.cf +++ b/tests/acceptance/25_cf-execd/mail_include_filter.cf @@ -1,45 +1,46 @@ # Tests that include mail filter causes only matched lines to be mailed by # cf-execd. - body common control { - inputs => { "../default.sub.cf", "mailfilter_common.cf.sub" }; - bundlesequence => { default($(this.promise_filename)) }; + inputs => { "../default.sub.cf", "mailfilter_common.cf.sub" }; + bundlesequence => { default($(this.promise_filename)) }; } bundle agent init { vars: - "reports" slist => { - "CorrectString1", - "CorrectString2", - "WrongString1", - "WrongString2", - }; - "includes" slist => { "R: CorrectString1", ".*CorrectString[2]" }; - "excludes" slist => { }; + "reports" + slist => { + "CorrectString1", "CorrectString2", "WrongString1", "WrongString2", + }; + + "includes" slist => { "R: CorrectString1", ".*CorrectString[2]" }; + "excludes" slist => {}; methods: - "any" usebundle => prepare_mailfilter_test(@(reports), - @(includes), - @(excludes)); + "any" + usebundle => prepare_mailfilter_test( + @(reports), @(includes), @(excludes) + ); } bundle agent test { meta: - "test_soft_fail" string => "windows", - meta => { "ENT-10215" }; + "test_soft_fail" + string => "windows", + meta => { "ENT-10215" }; } bundle agent check { vars: - "expected" slist => { "CorrectString1", "CorrectString2" }; - "not_expected" slist => { "WrongString1", "WrongString2" }; + "expected" slist => { "CorrectString1", "CorrectString2" }; + "not_expected" slist => { "WrongString1", "WrongString2" }; methods: - "any" usebundle => check_cf_execd_mail(@(expected), - @(not_expected), - $(this.promise_filename)); + "any" + usebundle => check_cf_execd_mail( + @(expected), @(not_expected), $(this.promise_filename) + ); } diff --git a/tests/acceptance/25_cf-execd/mail_no_filter.cf b/tests/acceptance/25_cf-execd/mail_no_filter.cf index 370be75ece..e1b1aced3e 100644 --- a/tests/acceptance/25_cf-execd/mail_no_filter.cf +++ b/tests/acceptance/25_cf-execd/mail_no_filter.cf @@ -1,40 +1,40 @@ # Tests that without mail filters, everything is mailed by cf-execd. - body common control { - inputs => { "../default.sub.cf", "mailfilter_common.cf.sub" }; - bundlesequence => { default($(this.promise_filename)) }; + inputs => { "../default.sub.cf", "mailfilter_common.cf.sub" }; + bundlesequence => { default($(this.promise_filename)) }; } bundle agent init { vars: - "reports" slist => { - "CorrectString1", - "CorrectString2", - }; - "includes" slist => { }; - "excludes" slist => { }; + "reports" slist => { "CorrectString1", "CorrectString2" }; + "includes" slist => {}; + "excludes" slist => {}; methods: - "any" usebundle => prepare_mailfilter_test(@(reports), - @(includes), - @(excludes)); + "any" + usebundle => prepare_mailfilter_test( + @(reports), @(includes), @(excludes) + ); } bundle agent test { meta: - "test_soft_fail" string => "windows", - meta => { "ENT-10215" }; + "test_soft_fail" + string => "windows", + meta => { "ENT-10215" }; } bundle agent check { vars: - "empty_list" slist => { }; + "empty_list" slist => {}; + methods: - "any" usebundle => check_cf_execd_mail(@(init.reports), - @(empty_list), - $(this.promise_filename)); + "any" + usebundle => check_cf_execd_mail( + @(init.reports), @(empty_list), $(this.promise_filename) + ); } diff --git a/tests/acceptance/25_cf-execd/mailfilter_1st_run_everything_filtered.cf b/tests/acceptance/25_cf-execd/mailfilter_1st_run_everything_filtered.cf index 4ad8779f81..38ec25bdd3 100644 --- a/tests/acceptance/25_cf-execd/mailfilter_1st_run_everything_filtered.cf +++ b/tests/acceptance/25_cf-execd/mailfilter_1st_run_everything_filtered.cf @@ -1,48 +1,42 @@ # Tests that no mail is sent by cf-execd if everything is filtered on the first # run (hence the old log doesn't exist). - body common control { - inputs => { "../default.sub.cf", "mailfilter_common.cf.sub" }; - bundlesequence => { default($(this.promiser_filename)) }; + inputs => { "../default.sub.cf", "mailfilter_common.cf.sub" }; + bundlesequence => { default($(this.promiser_filename)) }; } bundle agent init { vars: - "reports" slist => { - "WrongString1", - "WrongString2", - "WrongString3", - }; - - # No mail is expected at all, since everything is filtered. - "expected" slist => { }; - "unexpected" slist => { ".+" }; + "reports" slist => { "WrongString1", "WrongString2", "WrongString3" }; - "includes" slist => { - }; - "excludes" slist => { - ".*WrongString.*" - }; + # No mail is expected at all, since everything is filtered. + "expected" slist => {}; + "unexpected" slist => { ".+" }; + "includes" slist => {}; + "excludes" slist => { ".*WrongString.*" }; methods: - "any" usebundle => prepare_mailfilter_test(@(reports), - @(includes), - @(excludes)); + "any" + usebundle => prepare_mailfilter_test( + @(reports), @(includes), @(excludes) + ); } bundle agent test { meta: - "test_soft_fail" string => "windows", - meta => { "ENT-10215" }; + "test_soft_fail" + string => "windows", + meta => { "ENT-10215" }; } bundle agent check { methods: - "any" usebundle => check_cf_execd_mail(@(init.expected), - @(init.unexpected), - $(this.promise_filename)); + "any" + usebundle => check_cf_execd_mail( + @(init.expected), @(init.unexpected), $(this.promise_filename) + ); } diff --git a/tests/acceptance/25_cf-execd/mailfilter_empty_old_log_everything_filtered.cf b/tests/acceptance/25_cf-execd/mailfilter_empty_old_log_everything_filtered.cf index 3121d7bbac..1c20b55bf7 100644 --- a/tests/acceptance/25_cf-execd/mailfilter_empty_old_log_everything_filtered.cf +++ b/tests/acceptance/25_cf-execd/mailfilter_empty_old_log_everything_filtered.cf @@ -1,54 +1,48 @@ # Tests that no mail is sent by cf-execd if everything is filtered and the old # log is empty. - body common control { - inputs => { "../default.sub.cf", "mailfilter_common.cf.sub" }; - bundlesequence => { default($(this.promiser_filename)) }; + inputs => { "../default.sub.cf", "mailfilter_common.cf.sub" }; + bundlesequence => { default($(this.promiser_filename)) }; } bundle agent init { vars: - "reports" slist => { - "WrongString1", - "WrongString2", - "WrongString3", - }; - - # No mail is expected at all, since everything is filtered. - "expected" slist => { }; - "unexpected" slist => { ".+" }; + "reports" slist => { "WrongString1", "WrongString2", "WrongString3" }; - "includes" slist => { - }; - "excludes" slist => { - ".*WrongString.*" - }; + # No mail is expected at all, since everything is filtered. + "expected" slist => {}; + "unexpected" slist => { ".+" }; + "includes" slist => {}; + "excludes" slist => { ".*WrongString.*" }; methods: - "any" usebundle => prepare_mailfilter_test(@(reports), - @(includes), - @(excludes)); + "any" + usebundle => prepare_mailfilter_test( + @(reports), @(includes), @(excludes) + ); files: - "$(sys.workdir)/outputs/old.log" - create => "true"; - "$(sys.workdir)/outputs/previous" - link_from => linkfrom("$(sys.workdir)/outputs/old.log", "symlink"); + "$(sys.workdir)/outputs/old.log" create => "true"; + + "$(sys.workdir)/outputs/previous" + link_from => linkfrom("$(sys.workdir)/outputs/old.log", "symlink"); } bundle agent test { meta: - "test_soft_fail" string => "windows", - meta => { "ENT-10215" }; + "test_soft_fail" + string => "windows", + meta => { "ENT-10215" }; } bundle agent check { methods: - "any" usebundle => check_cf_execd_mail(@(init.expected), - @(init.unexpected), - $(this.promise_filename)); + "any" + usebundle => check_cf_execd_mail( + @(init.expected), @(init.unexpected), $(this.promise_filename) + ); } diff --git a/tests/acceptance/25_cf-execd/slow/dies_in_time.cf b/tests/acceptance/25_cf-execd/slow/dies_in_time.cf index 90faa20938..3bfbaa30ec 100644 --- a/tests/acceptance/25_cf-execd/slow/dies_in_time.cf +++ b/tests/acceptance/25_cf-execd/slow/dies_in_time.cf @@ -1,23 +1,16 @@ # ENT-3147, zd#3157 - # Ensure that cf-execd dies within 3 seconds after being signalled. - - body common control { - inputs => { - "../../default.sub.cf", - "../../run_with_server.cf.sub" - }; - bundlesequence => { default("$(this.promise_filename)") }; + inputs => { "../../default.sub.cf", "../../run_with_server.cf.sub" }; + bundlesequence => { default("$(this.promise_filename)") }; } bundle agent init { vars: - - "exec_command_script" string => -"#!/bin/sh -x + "exec_command_script" + string => "#!/bin/sh -x sleep 10 @@ -60,36 +53,34 @@ echo DONE > $(G.testdir)/exec_command.status "; files: - "$(G.testdir)/exec_command.sh" - create => "true", - perms => m(777), - edit_line => insert_lines("$(exec_command_script)"); + "$(G.testdir)/exec_command.sh" + create => "true", + perms => m(777), + edit_line => insert_lines("$(exec_command_script)"); methods: - "any" usebundle => dcs_fini("$(sys.piddir)/cf-execd.pid"); - "any" usebundle => dcs_fini("$(G.testdir)/EXECUTOR_WAS_SIGNALLED"); - "any" usebundle => dcs_fini("$(G.testdir)/cf_execd.status"); - "any" usebundle => dcs_fini("$(G.testdir)/exec_command.status"); + "any" usebundle => dcs_fini("$(sys.piddir)/cf-execd.pid"); + "any" usebundle => dcs_fini("$(G.testdir)/EXECUTOR_WAS_SIGNALLED"); + "any" usebundle => dcs_fini("$(G.testdir)/cf_execd.status"); + "any" usebundle => dcs_fini("$(G.testdir)/exec_command.status"); } bundle agent test { meta: - "test_soft_fail" string => "windows", - meta => { "ENT-10215" }; + "test_soft_fail" + string => "windows", + meta => { "ENT-10215" }; commands: - - "$(sys.cf_execd) -f $(this.promise_dirname)/kill_myself.execd.srv" - classes => if_repaired("executor_started"); + "$(sys.cf_execd) -f $(this.promise_dirname)/kill_myself.execd.srv" + classes => if_repaired("executor_started"); executor_started:: # Make sure it started fully - "$(G.sleep) 5" - classes => if_repaired("waited"); + "$(G.sleep) 5" classes => if_repaired("waited"); executor_started.waited:: - # Ensure executor PID is up "kill -0 `cat $(sys.piddir)/cf-execd.pid`" contain => in_shell, @@ -117,20 +108,18 @@ exit 1 # Executor was never signalled! executor_was_signalled:: # Wait again until executor runs the signal handler and exits gracefully - "$(G.sleep) 3" - classes => if_repaired("waited_for_cleanup"); + "$(G.sleep) 3" classes => if_repaired("waited_for_cleanup"); waited_for_cleanup:: # and another 10s for exec_command.sh script to exit - "$(G.sleep) 10" - classes => if_repaired("script_should_have_exited"); + "$(G.sleep) 10" classes => if_repaired("script_should_have_exited"); classes: - "test_bundle_done" expression => "script_should_have_exited", - scope => "namespace"; + "test_bundle_done" + expression => "script_should_have_exited", + scope => "namespace"; reports: - !executor_was_signalled:: "$(this.promise_filename) FAIL"; } @@ -140,20 +129,26 @@ bundle agent check { classes: test_bundle_done:: - "executor_is_dead" expression => - returnszero("$(G.grep) DEAD $(G.testdir)/cf_execd.status", - "useshell"); - "exec_command_finished" expression => - returnszero("$(G.grep) DONE $(G.testdir)/exec_command.status", - "useshell"); + "executor_is_dead" + expression => returnszero( + "$(G.grep) DEAD $(G.testdir)/cf_execd.status", "useshell" + ); + + "exec_command_finished" + expression => returnszero( + "$(G.grep) DONE $(G.testdir)/exec_command.status", "useshell" + ); methods: - "" usebundle => - dcs_passif_expected("executor_is_dead,exec_command_finished","", - "$(this.promise_filename)"), - inherit => "true"; + "" + usebundle => dcs_passif_expected( + "executor_is_dead,exec_command_finished", + "", + "$(this.promise_filename)" + ), + inherit => "true"; reports: !executor_is_dead.DEBUG:: - "FAIL: cf-execd did not die within 3s after TERM signal!"; + "FAIL: cf-execd did not die within 3s after TERM signal!"; } diff --git a/tests/acceptance/25_cf-execd/timed/mailfilter_repeated_runs.cf b/tests/acceptance/25_cf-execd/timed/mailfilter_repeated_runs.cf index bed447743d..5d6b5ce448 100644 --- a/tests/acceptance/25_cf-execd/timed/mailfilter_repeated_runs.cf +++ b/tests/acceptance/25_cf-execd/timed/mailfilter_repeated_runs.cf @@ -1,117 +1,132 @@ # Tests that the correct content is sent by cf-execd after several consecutive # cf-agent runs. - body common control { - inputs => { "../../default.sub.cf", "../mailfilter_common.cf.sub" }; - bundlesequence => { default($(this.promiser_filename)) }; + inputs => { "../../default.sub.cf", "../mailfilter_common.cf.sub" }; + bundlesequence => { default($(this.promiser_filename)) }; } bundle agent init { vars: - # Positions of WrongString inside the report should not matter, since it - # is filtered out. - "reports1" slist => { - "CorrectString1", - "CorrectString2", - "WrongString1", - "WrongString2", - "WrongString3", - }; - "expected1" slist => { - "CorrectString1", - "CorrectString2", - }; - - "reports2" slist => { - "WrongString1", - "CorrectString1", - "WrongString2", - "CorrectString2", - "WrongString3", - }; - "expected2" slist => { - # Nothing expected, since it is identical to - # previous run. - }; - - "reports3" slist => { - }; - "expected3" slist => { - # Nothing expected, because the log is empty. - }; - - "reports4" slist => { - "WrongString1", - "WrongString2", - "WrongString3", - }; - "expected4" slist => { - # Nothing expected, because everything is filtered. - }; - - "reports5" slist => { - "WrongString2", - "WrongString1", - "CorrectString2", - "CorrectString1", - "WrongString3", - }; - "expected5" slist => { - "CorrectString2", - "CorrectString1", - }; - - "unexpected" slist => { ".*WrongString.*" }; - - "includes" slist => { - "R: CorrectString1", ".*CorrectString[2]", - "R: WrongString1", ".*WrongString[2]" - }; - "excludes" slist => { - "R: WrongString1", ".*WrongString[2]", - # Tests anchoring. - "orrectString1" - }; + # Positions of WrongString inside the report should not matter, since it + # is filtered out. + "reports1" + slist => { + "CorrectString1", + "CorrectString2", + "WrongString1", + "WrongString2", + "WrongString3", + }; + + "expected1" slist => { "CorrectString1", "CorrectString2" }; + + "reports2" + slist => { + "WrongString1", + "CorrectString1", + "WrongString2", + "CorrectString2", + "WrongString3", + }; + + "expected2" + slist => { + # Nothing expected, since it is identical to + # previous run. + }; + + "reports3" slist => {}; + + "expected3" + slist => { + # Nothing expected, because the log is empty. + }; + + "reports4" slist => { "WrongString1", "WrongString2", "WrongString3" }; + + "expected4" + slist => { + # Nothing expected, because everything is filtered. + }; + + "reports5" + slist => { + "WrongString2", + "WrongString1", + "CorrectString2", + "CorrectString1", + "WrongString3", + }; + + "expected5" slist => { "CorrectString2", "CorrectString1" }; + "unexpected" slist => { ".*WrongString.*" }; + + "includes" + slist => { + "R: CorrectString1", + ".*CorrectString[2]", + "R: WrongString1", + ".*WrongString[2]", + }; + + "excludes" + slist => { + "R: WrongString1", + ".*WrongString[2]", + # Tests anchoring. + "orrectString1", + }; methods: test_pass_1:: - "any" usebundle => prepare_mailfilter_test(@(reports1), - @(includes), - @(excludes)); + "any" + usebundle => prepare_mailfilter_test( + @(reports1), @(includes), @(excludes) + ); + "any" usebundle => run_cf_execd(@(expected1), @(unexpected)); test_pass_2:: - "any" usebundle => prepare_mailfilter_test(@(reports2), - @(includes), - @(excludes)); + "any" + usebundle => prepare_mailfilter_test( + @(reports2), @(includes), @(excludes) + ); + "any" usebundle => run_cf_execd(@(expected2), @(unexpected)); test_pass_3:: - "any" usebundle => prepare_mailfilter_test(@(reports3), - @(includes), - @(excludes)); + "any" + usebundle => prepare_mailfilter_test( + @(reports3), @(includes), @(excludes) + ); + "any" usebundle => run_cf_execd(@(expected3), @(unexpected)); test_pass_4:: - "any" usebundle => prepare_mailfilter_test(@(reports4), - @(includes), - @(excludes)); + "any" + usebundle => prepare_mailfilter_test( + @(reports4), @(includes), @(excludes) + ); + "any" usebundle => run_cf_execd(@(expected4), @(unexpected)); test_pass_5:: - "any" usebundle => prepare_mailfilter_test(@(reports5), - @(includes), - @(excludes)); + "any" + usebundle => prepare_mailfilter_test( + @(reports5), @(includes), @(excludes) + ); + "any" usebundle => run_cf_execd(@(expected5), @(unexpected)); } bundle agent test { meta: - "test_soft_fail" string => "windows", - meta => { "ENT-10215" }; + "test_soft_fail" + string => "windows", + meta => { "ENT-10215" }; } bundle agent check @@ -119,6 +134,7 @@ bundle agent check methods: test_pass_1|test_pass_2|test_pass_3|test_pass_4:: "any" usebundle => dcs_wait($(this.promise_filename), 1); + test_pass_5:: "any" usebundle => compare_cf_execd_mail($(this.promise_filename)); } From d4f49e24a038de9748390317c8e6e5ec8ff94d28 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Thu, 25 Jun 2026 15:09:17 +0200 Subject: [PATCH 6/7] cfengine format ./tests/acceptance/21_methods/ Signed-off-by: Ole Herman Schumacher Elgesem --- tests/acceptance/21_methods/array_reset.cf | 20 +-- .../call_methods_using_array_expansion.cf | 56 ++++----- .../21_methods/callers/callers_directly.cf | 42 ++++--- .../21_methods/callers/promisers_directly.cf | 30 +++-- .../callers/promisers_indirectly.cf | 50 ++++---- .../acceptance/21_methods/method_outcomes.cf | 117 ++++++++---------- .../bundle_promiser_call_by_arg_defined.cf | 9 +- .../reachable/bundle_promiser_defined.cf | 2 - .../reachable/bundle_promiser_unreachable.cf | 6 +- ...e_reversed_usebundle_parameters_defined.cf | 6 +- .../bundle_usebundle_call_by_arg_defined.cf | 10 +- .../reachable/bundle_usebundle_defined.cf | 5 +- .../bundle_usebundle_parameters_defined.cf | 5 +- .../reachable/bundle_usebundle_unreachable.cf | 6 +- tests/acceptance/21_methods/reporting/kept.cf | 25 ++-- .../21_methods/usebundle_with_or_without.cf | 90 ++++++++------ tests/acceptance/21_methods/warn_only.cf | 22 ++-- 17 files changed, 247 insertions(+), 254 deletions(-) diff --git a/tests/acceptance/21_methods/array_reset.cf b/tests/acceptance/21_methods/array_reset.cf index c74f88a3c7..955173c0ca 100644 --- a/tests/acceptance/21_methods/array_reset.cf +++ b/tests/acceptance/21_methods/array_reset.cf @@ -3,41 +3,41 @@ # Redmine 6369 - make sure that arrays don't accumulate # ####################################################### - body common control { - inputs => { "../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } bundle agent test { vars: - "key_value" slist => { 1, 2, 3 }; + "key_value" slist => { 1, 2, 3 }; methods: - "in" usebundle => test_method($(key_value), $(key_value)); + "in" usebundle => test_method($(key_value), $(key_value)); } bundle agent test_method(key, value) { vars: - "array[$(key)]" string => "$(value)"; + "array[$(key)]" string => "$(value)"; } bundle agent check { vars: - "indices" slist => getindices("test_method.array"); - "dim" int => length("indices"); + "indices" slist => getindices("test_method.array"); + "dim" int => length("indices"); classes: - "ok" expression => strcmp("$(dim)", "1"); + "ok" expression => strcmp("$(dim)", "1"); reports: ok:: "$(this.promise_filename) Pass"; + !ok:: "$(this.promise_filename) FAIL"; diff --git a/tests/acceptance/21_methods/call_methods_using_array_expansion.cf b/tests/acceptance/21_methods/call_methods_using_array_expansion.cf index 6b6ce245e1..8a9a470c42 100644 --- a/tests/acceptance/21_methods/call_methods_using_array_expansion.cf +++ b/tests/acceptance/21_methods/call_methods_using_array_expansion.cf @@ -3,12 +3,11 @@ # Redmine 6369 - make sure that arrays don't accumulate # ####################################################### - body common control { - inputs => { "../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } bundle agent init @@ -18,53 +17,48 @@ bundle agent init "$(G.dos2unix) $(this.promise_filename).expected.txt" -> { "ENT-10433" }; files: - "$(G.testdir)/reports.txt" - delete => tidy; + "$(G.testdir)/reports.txt" delete => tidy; } + bundle agent test { meta: - - "description" -> { "CFE-636" } - string => "Check that methods can be called by expanding classic + "description" -> { "CFE-636" } + string => "Check that methods can be called by expanding classic arrays"; vars: - - "b1" string => "b1"; - "b2" string => "b2"; - "b[b2]" string => "b2"; + "b1" string => "b1"; + "b2" string => "b2"; + "b[b2]" string => "b2"; methods: - - "${b1}" - usebundle => ${b1}; - "${b[b2]}" - usebundle => ${b[b2]}("param"); - "${b[b2]}" - usebundle => ${b[${b2}]}("param2"); + "${b1}" usebundle => ${b1}; + "${b[b2]}" usebundle => ${b[b2]}("param"); + "${b[b2]}" usebundle => ${b[${b2}]}("param2"); } bundle agent check { methods: - - "Pass/Fail" - usebundle => dcs_check_diff( "$(G.testdir)/reports.txt", - "$(this.promise_filename).expected.txt", - $(this.promise_filename)); + "Pass/Fail" + usebundle => dcs_check_diff( + "$(G.testdir)/reports.txt", + "$(this.promise_filename).expected.txt", + $(this.promise_filename) + ); } -bundle agent b1{ +bundle agent b1 +{ reports: cfengine:: - "Bundle b1" - report_to_file => "$(G.testdir)/reports.txt"; + "Bundle b1" report_to_file => "$(G.testdir)/reports.txt"; } -bundle agent b2(ref){ +bundle agent b2(ref) +{ reports: cfengine:: - "Bundle b2 ${ref}" - report_to_file => "$(G.testdir)/reports.txt"; + "Bundle b2 ${ref}" report_to_file => "$(G.testdir)/reports.txt"; } diff --git a/tests/acceptance/21_methods/callers/callers_directly.cf b/tests/acceptance/21_methods/callers/callers_directly.cf index 624ba06765..3700ff4599 100644 --- a/tests/acceptance/21_methods/callers/callers_directly.cf +++ b/tests/acceptance/21_methods/callers/callers_directly.cf @@ -3,44 +3,48 @@ # Test the variable this.callers_promisers with one bundle # ####################################################### - body common control { - inputs => { "../../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - -bundle agent init { +bundle agent init +{ } -bundle agent test { +bundle agent test +{ methods: "test" usebundle => "caller"; } -bundle agent check { +bundle agent check +{ vars: - "callers_expect" string => "agent"; - # Due to the 4K variable limit we cannot test the whole structure, so - # just test one element within it. At least it's not completely broken - # if we find it. - "callers_actual" string => "$(dummy.callers[0][bundle][bundleType])"; + "callers_expect" string => "agent"; + + # Due to the 4K variable limit we cannot test the whole structure, so + # just test one element within it. At least it's not completely broken + # if we find it. + "callers_actual" string => "$(dummy.callers[0][bundle][bundleType])"; classes: - "success" expression => strcmp("${callers_expect}", "${callers_actual}"), - scope => "namespace"; + "success" + expression => strcmp("${callers_expect}", "${callers_actual}"), + scope => "namespace"; reports: success:: "$(this.promise_filename) Pass"; + !success:: "$(this.promise_filename) FAIL"; methods: - "any" usebundle => file_make($(G.testfile), $(callers_actual)); + "any" usebundle => file_make($(G.testfile), $(callers_actual)); reports: DEBUG:: @@ -48,12 +52,14 @@ bundle agent check { "ACTUAL: callers_string = $(callers_actual)"; } -bundle agent caller { +bundle agent caller +{ methods: "first call" usebundle => dummy; } -bundle agent dummy { +bundle agent dummy +{ vars: "callers" data => callstack_callers(); } diff --git a/tests/acceptance/21_methods/callers/promisers_directly.cf b/tests/acceptance/21_methods/callers/promisers_directly.cf index 54a62cba0c..fe7b27ee2e 100644 --- a/tests/acceptance/21_methods/callers/promisers_directly.cf +++ b/tests/acceptance/21_methods/callers/promisers_directly.cf @@ -3,46 +3,52 @@ # Test the variable this.callers_promisers with one bundle # ####################################################### - body common control { - inputs => { "../../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - -bundle agent init { +bundle agent init +{ } -bundle agent test { +bundle agent test +{ methods: "test" usebundle => "caller"; } -bundle agent check { +bundle agent check +{ reports: success:: "$(this.promise_filename) Pass"; + !success:: "$(this.promise_filename) FAIL"; } -bundle agent caller { +bundle agent caller +{ methods: "first call" usebundle => dummy; } -bundle agent dummy { +bundle agent dummy +{ vars: "callers_promisers" slist => callstack_promisers(); - "callers_promisers_expect" string => "any, any, test, first call"; "callers_promisers_actual" string => join(", ", "callers_promisers"); classes: - "success" expression => strcmp("${callers_promisers_expect}", "${callers_promisers_actual}"), + "success" + expression => strcmp( + "${callers_promisers_expect}", "${callers_promisers_actual}" + ), scope => "namespace"; reports: diff --git a/tests/acceptance/21_methods/callers/promisers_indirectly.cf b/tests/acceptance/21_methods/callers/promisers_indirectly.cf index 136efee86f..680ccf60b2 100644 --- a/tests/acceptance/21_methods/callers/promisers_indirectly.cf +++ b/tests/acceptance/21_methods/callers/promisers_indirectly.cf @@ -3,68 +3,76 @@ # Test the variable this.callers_promisers with one bundle called twice # ####################################################### - body common control { - inputs => { "../../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - -bundle agent init { +bundle agent init +{ } -bundle agent test { +bundle agent test +{ methods: "test" usebundle => "caller"; } -bundle agent check { +bundle agent check +{ reports: success_first.success_second:: "$(this.promise_filename) Pass"; + !(success_first.success_second):: "$(this.promise_filename) FAIL"; } -bundle agent caller { - +bundle agent caller +{ methods: "first call" usebundle => dummy; "second call" usebundle => dummy_inter; - } -bundle agent dummy_inter { - +bundle agent dummy_inter +{ methods: "inter" usebundle => dummy; - } -bundle agent dummy { - +bundle agent dummy +{ vars: # This bundle gets called twice, once directly, and once via dummy_inter "callers_promisers" slist => callstack_promisers(); - "callers_promisers_expect_first" string => "any, any, test, first call"; - "callers_promisers_expect_second" string => "any, any, test, second call, inter"; + + "callers_promisers_expect_second" + string => "any, any, test, second call, inter"; + "callers_promisers_actual" string => join(", ", "callers_promisers"); classes: - "success_first" expression => strcmp("${callers_promisers_expect_first}", "${callers_promisers_actual}"), + "success_first" + expression => strcmp( + "${callers_promisers_expect_first}", "${callers_promisers_actual}" + ), scope => "namespace"; - "success_second" expression => strcmp("${callers_promisers_expect_second}", "${callers_promisers_actual}"), + + "success_second" + expression => strcmp( + "${callers_promisers_expect_second}", "${callers_promisers_actual}" + ), scope => "namespace"; reports: DEBUG:: "EXPECT (first in ${this.bundle}): callers_promisers_string = ${callers_promisers_expect_first}"; "ACTUAL (first in ${this.bundle}): callers_promisers_string = ${callers_promisers_actual}"; - "EXPECT (second in ${this.bundle}): callers_promisers_string = ${callers_promisers_expect_second}"; "ACTUAL (second in ${this.bundle}): callers_promisers_string = ${callers_promisers_actual}"; } diff --git a/tests/acceptance/21_methods/method_outcomes.cf b/tests/acceptance/21_methods/method_outcomes.cf index 9d0a5e2ca9..a8cf60a809 100644 --- a/tests/acceptance/21_methods/method_outcomes.cf +++ b/tests/acceptance/21_methods/method_outcomes.cf @@ -3,29 +3,24 @@ # bundle. body file control { - inputs => { "../default.sub.cf" }; + inputs => { "../default.sub.cf" }; } bundle agent main { methods: - "init" - usebundle => init; - "check" - usebundle => check; + "init" usebundle => init; + "check" usebundle => check; } bundle agent init { classes: - # "method_FORCE_UNEXPECTED_FAIL" expression => "any"; + # "method_FORCE_UNEXPECTED_FAIL" expression => "any"; vars: - "method_outcome_classes" - slist => classesmatching("method_.*"); - - "sorted_method_outcome_classes" - slist => sort(method_outcome_classes, lex); + "method_outcome_classes" slist => classesmatching("method_.*"); + "sorted_method_outcome_classes" slist => sort(method_outcome_classes, lex); methods: "test kept bundle" @@ -44,7 +39,6 @@ bundle agent init usebundle => method_worst, classes => scoped_classes_generic("namespace", "method_worst_outcome"); - reports: "$(sorted_method_outcome_classes)"; } @@ -54,91 +48,80 @@ bundle agent check vars: "expected_classes" slist => { - "method_kept_outcome_kept", - "method_kept_outcome_ok", - "method_kept_outcome_reached", - "method_not_kept_outcome_error", - "method_not_kept_outcome_failed", - "method_not_kept_outcome_not_kept", - "method_not_kept_outcome_not_ok", - "method_not_kept_outcome_reached", - "method_repaired_outcome_ok", - "method_repaired_outcome_reached", - "method_repaired_outcome_repaired", - "method_worst_outcome_error", - "method_worst_outcome_failed", - "method_worst_outcome_not_kept", - "method_worst_outcome_not_ok", - "method_worst_outcome_reached", - #"method_FORCE_UNEXPECTED_FAILURE", - }; - - # Find classes that we expect to find but do not - "missing_expected_classes" - slist => difference( "expected_classes", "init.method_outcome_classes"); - - # Find classes that we did not expect to find - "unexpected_classes" - slist => difference( "init.method_outcome_classes", "expected_classes" ); - - # Count up the number of missing and extra classes - "num_missing" - int => length("missing_expected_classes"); - "num_unexpected" - int => length("unexpected_classes"); + "method_kept_outcome_kept", + "method_kept_outcome_ok", + "method_kept_outcome_reached", + "method_not_kept_outcome_error", + "method_not_kept_outcome_failed", + "method_not_kept_outcome_not_kept", + "method_not_kept_outcome_not_ok", + "method_not_kept_outcome_reached", + "method_repaired_outcome_ok", + "method_repaired_outcome_reached", + "method_repaired_outcome_repaired", + "method_worst_outcome_error", + "method_worst_outcome_failed", + "method_worst_outcome_not_kept", + "method_worst_outcome_not_ok", + "method_worst_outcome_reached", + #"method_FORCE_UNEXPECTED_FAILURE", + }; + + # Find classes that we expect to find but do not + "missing_expected_classes" + slist => difference("expected_classes", "init.method_outcome_classes"); + + # Find classes that we did not expect to find + "unexpected_classes" + slist => difference("init.method_outcome_classes", "expected_classes"); + + # Count up the number of missing and extra classes + "num_missing" int => length("missing_expected_classes"); + "num_unexpected" int => length("unexpected_classes"); classes: - # Fail if the counts are not as expected - "fail" - expression => isgreaterthan( "$(num_missing)", "0"); - "fail" - expression => isgreaterthan( "$(num_unexpected)", "0"); + # Fail if the counts are not as expected + "fail" expression => isgreaterthan("$(num_missing)", "0"); + "fail" expression => isgreaterthan("$(num_unexpected)", "0"); - # Pass if we found all expected classes and did not fail - "ok" and => { @(expected_classes), "!fail" }; + # Pass if we found all expected classes and did not fail + "ok" and => { @(expected_classes), "!fail" }; reports: ok:: "$(this.promise_filename) Pass"; + fail:: "$(this.promise_filename) FAIL"; - } bundle agent method_kept { reports: - "$(this.bundle)" - comment => "This promsie should have a kept outcome"; + "$(this.bundle)" comment => "This promsie should have a kept outcome"; } bundle agent method_repaired { -# This bundle runs a command that returns 0 and is by default considered -# repaired, so the bundle will be considered repaired + # This bundle runs a command that returns 0 and is by default considered + # repaired, so the bundle will be considered repaired commands: - "$(G.true)" - comment => "This promsie should have a repaired outcome"; + "$(G.true)" comment => "This promsie should have a repaired outcome"; } bundle agent method_not_kept { commands: - "$(G.false)" - comment => "This promise should have a not_kept outcome"; + "$(G.false)" comment => "This promise should have a not_kept outcome"; } bundle agent method_worst # @brief This bundle activates a promise that is repaired (/bin/true), a promise that is not kept (/bin/false), and a promise that is kept (report) { commands: - "$(G.true)" - comment => "This promsie should have a repaired outcome"; - - "$(G.false)" - comment => "This promise should have a not_kept outcome"; + "$(G.true)" comment => "This promsie should have a repaired outcome"; + "$(G.false)" comment => "This promise should have a not_kept outcome"; reports: - "$(this.bundle)" - comment => "This promsie should have a kept outcome"; + "$(this.bundle)" comment => "This promsie should have a kept outcome"; } diff --git a/tests/acceptance/21_methods/reachable/bundle_promiser_call_by_arg_defined.cf b/tests/acceptance/21_methods/reachable/bundle_promiser_call_by_arg_defined.cf index 037ccf689e..2e28ab9dc0 100644 --- a/tests/acceptance/21_methods/reachable/bundle_promiser_call_by_arg_defined.cf +++ b/tests/acceptance/21_methods/reachable/bundle_promiser_call_by_arg_defined.cf @@ -1,12 +1,10 @@ # Reachable bundle tests verify that you are allowed have references # to undefined bundles, as long as they are not actually called. - # These tests are left very simple on purpose, # they are not using the test framework. # They should be seen together, note that defined vs undefined variants are # almost identical, just replacing one detail to show what should work # and what should error. - bundle agent baz { reports: @@ -16,12 +14,13 @@ bundle agent baz bundle agent bar(x) { methods: - "$(x)"; # Tries to call baz, exists, works + "$(x)"; + + # Tries to call baz, exists, works } bundle agent main { methods: - "foo" - usebundle => bar("baz"); + "foo" usebundle => bar("baz"); } diff --git a/tests/acceptance/21_methods/reachable/bundle_promiser_defined.cf b/tests/acceptance/21_methods/reachable/bundle_promiser_defined.cf index e01cf79995..4f670d095d 100644 --- a/tests/acceptance/21_methods/reachable/bundle_promiser_defined.cf +++ b/tests/acceptance/21_methods/reachable/bundle_promiser_defined.cf @@ -1,12 +1,10 @@ # Reachable bundle tests verify that you are allowed have references # to undefined bundles, as long as they are not actually called. - # These tests are left very simple on purpose, # they are not using the test framework. # They should be seen together, note that defined vs undefined variants are # almost identical, just replacing one detail to show what should work # and what should error. - bundle agent foo { reports: diff --git a/tests/acceptance/21_methods/reachable/bundle_promiser_unreachable.cf b/tests/acceptance/21_methods/reachable/bundle_promiser_unreachable.cf index b0847e75f4..06d7477b80 100644 --- a/tests/acceptance/21_methods/reachable/bundle_promiser_unreachable.cf +++ b/tests/acceptance/21_methods/reachable/bundle_promiser_unreachable.cf @@ -1,12 +1,10 @@ # Reachable bundle tests verify that you are allowed have references # to undefined bundles, as long as they are not actually called. - # These tests are left very simple on purpose, # they are not using the test framework. # They should be seen together, note that defined vs undefined variants are # almost identical, just replacing one detail to show what should work # and what should error. - bundle agent bar { reports: @@ -17,7 +15,9 @@ bundle agent main { methods: out_of_context:: - "foo"; # Should not error because it's unreachable + "foo"; + + # Should not error because it's unreachable any:: "bar"; } diff --git a/tests/acceptance/21_methods/reachable/bundle_reversed_usebundle_parameters_defined.cf b/tests/acceptance/21_methods/reachable/bundle_reversed_usebundle_parameters_defined.cf index e0373ba2be..644a76f88c 100644 --- a/tests/acceptance/21_methods/reachable/bundle_reversed_usebundle_parameters_defined.cf +++ b/tests/acceptance/21_methods/reachable/bundle_reversed_usebundle_parameters_defined.cf @@ -1,20 +1,16 @@ # Reachable bundle tests verify that you are allowed have references # to undefined bundles, as long as they are not actually called. - # These tests are left very simple on purpose, # they are not using the test framework. # They should be seen together, note that defined vs undefined variants are # almost identical, just replacing one detail to show what should work # and what should error. - # reversed tests are just to show it should behave the same # if the called bundle comes after instead of before - bundle agent main { methods: - "foo" - usebundle => bar("baz"); + "foo" usebundle => bar("baz"); } bundle agent bar(x) diff --git a/tests/acceptance/21_methods/reachable/bundle_usebundle_call_by_arg_defined.cf b/tests/acceptance/21_methods/reachable/bundle_usebundle_call_by_arg_defined.cf index f586391d0f..df779f78e9 100644 --- a/tests/acceptance/21_methods/reachable/bundle_usebundle_call_by_arg_defined.cf +++ b/tests/acceptance/21_methods/reachable/bundle_usebundle_call_by_arg_defined.cf @@ -1,12 +1,10 @@ # Reachable bundle tests verify that you are allowed have references # to undefined bundles, as long as they are not actually called. - # These tests are left very simple on purpose, # they are not using the test framework. # They should be seen together, note that defined vs undefined variants are # almost identical, just replacing one detail to show what should work # and what should error. - bundle agent baz { reports: @@ -16,13 +14,13 @@ bundle agent baz bundle agent bar(x) { methods: - "foo" - usebundle => "$(x)"; # Will call baz, which exists, should work + "foo" usebundle => "$(x)"; + + # Will call baz, which exists, should work } bundle agent main { methods: - "foo" - usebundle => bar("baz"); + "foo" usebundle => bar("baz"); } diff --git a/tests/acceptance/21_methods/reachable/bundle_usebundle_defined.cf b/tests/acceptance/21_methods/reachable/bundle_usebundle_defined.cf index e4d1136a92..5a00d039a5 100644 --- a/tests/acceptance/21_methods/reachable/bundle_usebundle_defined.cf +++ b/tests/acceptance/21_methods/reachable/bundle_usebundle_defined.cf @@ -1,12 +1,10 @@ # Reachable bundle tests verify that you are allowed have references # to undefined bundles, as long as they are not actually called. - # These tests are left very simple on purpose, # they are not using the test framework. # They should be seen together, note that defined vs undefined variants are # almost identical, just replacing one detail to show what should work # and what should error. - bundle agent bar { reports: @@ -16,6 +14,5 @@ bundle agent bar bundle agent main { methods: - "foo" - usebundle => bar; + "foo" usebundle => bar; } diff --git a/tests/acceptance/21_methods/reachable/bundle_usebundle_parameters_defined.cf b/tests/acceptance/21_methods/reachable/bundle_usebundle_parameters_defined.cf index 8eee0f8e1c..ca66bd2a73 100644 --- a/tests/acceptance/21_methods/reachable/bundle_usebundle_parameters_defined.cf +++ b/tests/acceptance/21_methods/reachable/bundle_usebundle_parameters_defined.cf @@ -1,12 +1,10 @@ # Reachable bundle tests verify that you are allowed have references # to undefined bundles, as long as they are not actually called. - # These tests are left very simple on purpose, # they are not using the test framework. # They should be seen together, note that defined vs undefined variants are # almost identical, just replacing one detail to show what should work # and what should error. - bundle agent bar(x) { # bar exists and it's the bundle we want, so this will pass: @@ -18,6 +16,5 @@ bundle agent bar(x) bundle agent main { methods: - "foo" - usebundle => bar("baz"); + "foo" usebundle => bar("baz"); } diff --git a/tests/acceptance/21_methods/reachable/bundle_usebundle_unreachable.cf b/tests/acceptance/21_methods/reachable/bundle_usebundle_unreachable.cf index 3fd33f4a97..78aef58fcc 100644 --- a/tests/acceptance/21_methods/reachable/bundle_usebundle_unreachable.cf +++ b/tests/acceptance/21_methods/reachable/bundle_usebundle_unreachable.cf @@ -1,12 +1,10 @@ # Reachable bundle tests verify that you are allowed have references # to undefined bundles, as long as they are not actually called. - # These tests are left very simple on purpose, # they are not using the test framework. # They should be seen together, note that defined vs undefined variants are # almost identical, just replacing one detail to show what should work # and what should error. - bundle agent baz { reports: @@ -18,6 +16,8 @@ bundle agent main methods: "foo" if => "out_of_context", - usebundle => "bar"; # Should not error because it's unreachable + usebundle => "bar"; + + # Should not error because it's unreachable "baz"; } diff --git a/tests/acceptance/21_methods/reporting/kept.cf b/tests/acceptance/21_methods/reporting/kept.cf index 72339839ea..bb1f0a19fe 100644 --- a/tests/acceptance/21_methods/reporting/kept.cf +++ b/tests/acceptance/21_methods/reporting/kept.cf @@ -3,34 +3,32 @@ # Redmine#4852: test kept methods reporting # ####################################################### - body common control { - inputs => { "../../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - bundle agent init { methods: - "create" usebundle => test_create_hello; + "create" usebundle => test_create_hello; } ####################################################### - bundle agent test { methods: - - "verify" usebundle => test_create_hello, + "verify" + usebundle => test_create_hello, classes => test_verify_method; reports: OK:: "OK"; + FAIL:: "FAIL"; } @@ -38,7 +36,7 @@ bundle agent test bundle agent test_create_hello { files: - "$(G.testfile)" + "$(G.testfile)" create => "true", perms => test_m("000"), action => test_immediate; @@ -46,17 +44,17 @@ bundle agent test_create_hello body perms test_m(mode) { - mode => $(mode); + mode => $(mode); } body action test_immediate { - ifelapsed => 0; + ifelapsed => 0; } body classes test_verify_method { - promise_kept => {"ok"}; + promise_kept => { "ok" }; } bundle agent check @@ -64,6 +62,7 @@ bundle agent check reports: ok:: "$(this.promise_filename) Pass"; + !ok:: "$(this.promise_filename) FAIL"; } diff --git a/tests/acceptance/21_methods/usebundle_with_or_without.cf b/tests/acceptance/21_methods/usebundle_with_or_without.cf index f1c0e60633..7c43b7d91f 100644 --- a/tests/acceptance/21_methods/usebundle_with_or_without.cf +++ b/tests/acceptance/21_methods/usebundle_with_or_without.cf @@ -1,92 +1,106 @@ # Test that methods promises work correctly both with and without usebundle. - body common control { - inputs => { '../default.sub.cf' }; - bundlesequence => { default("$(this.promise_filename)") }; + inputs => { '../default.sub.cf' }; + bundlesequence => { default("$(this.promise_filename)") }; } bundle agent test { vars: - "test_var7" string => "7"; - "test_var8" string => "8"; + "test_var7" string => "7"; + "test_var8" string => "8"; methods: - "check1"; - "check2" usebundle => check2; - "bad_check3" usebundle => check3; - #"checkN(4)"; # Not currently working. - "checkN(5)" usebundle => checkN(5); - "bad_checkN(6)" usebundle => checkN(6); - "checkN(bad)" usebundle => checkN(good); - "check$(test_var7)"; - #"checkN($(test_var8))"; # Not currently working. + "check1"; + "check2" usebundle => check2; + "bad_check3" usebundle => check3; + + #"checkN(4)"; # Not currently working. + "checkN(5)" usebundle => checkN(5); + "bad_checkN(6)" usebundle => checkN(6); + "checkN(bad)" usebundle => checkN(good); + "check$(test_var7)"; + + #"checkN($(test_var8))"; # Not currently working. } bundle agent check1 { classes: - "ok_1" expression => "any", - scope => "namespace"; + "ok_1" + expression => "any", + scope => "namespace"; } + bundle agent check2 { classes: - "ok_2" expression => "any", - scope => "namespace"; + "ok_2" + expression => "any", + scope => "namespace"; } + bundle agent check3 { classes: - "ok_3" expression => "any", - scope => "namespace"; + "ok_3" + expression => "any", + scope => "namespace"; } + bundle agent bad_check3 { classes: - "bad_3" expression => "any", - scope => "namespace"; + "bad_3" + expression => "any", + scope => "namespace"; } + bundle agent checkN(X) { classes: - "ok_$(X)" expression => "any", - scope => "namespace"; + "ok_$(X)" + expression => "any", + scope => "namespace"; } + bundle agent bad_checkN(X) { classes: - "bad_$(X)" expression => "any", - scope => "namespace"; + "bad_$(X)" + expression => "any", + scope => "namespace"; } + bundle agent check7 { classes: - "ok_7" expression => "any", - scope => "namespace"; + "ok_7" + expression => "any", + scope => "namespace"; } bundle agent check { vars: - "cases" slist => { 1, 2, 3, 5, 6, 7, "good" }; - "positive" slist => maplist("ok_$(this)", "cases"); - "negative" slist => { maplist("bad_$(this)", "cases"), "ok_bad" }; + "cases" slist => { 1, 2, 3, 5, 6, 7, "good" }; + "positive" slist => maplist("ok_$(this)", "cases"); + "negative" slist => { maplist("bad_$(this)", "cases"), "ok_bad" }; classes: - "positive_match" and => { @(positive) }; - "negative_match" or => { @(negative) }; - "ok" expression => "positive_match.!negative_match"; + "positive_match" and => { @(positive) }; + "negative_match" or => { @(negative) }; + "ok" expression => "positive_match.!negative_match"; reports: DEBUG:: - "Classes not set that should be: $(positive)" - if => "!$(positive)"; - "Classes set that should not be: $(negative)" - if => "$(negative)"; + "Classes not set that should be: $(positive)" if => "!$(positive)"; + "Classes set that should not be: $(negative)" if => "$(negative)"; + ok:: "$(this.promise_filename) Pass"; + !ok:: "$(this.promise_filename) FAIL"; } diff --git a/tests/acceptance/21_methods/warn_only.cf b/tests/acceptance/21_methods/warn_only.cf index 8292b6409d..8fd31289f8 100644 --- a/tests/acceptance/21_methods/warn_only.cf +++ b/tests/acceptance/21_methods/warn_only.cf @@ -3,36 +3,33 @@ # Redmine#4852: test kept methods reporting # ####################################################### - body common control { - inputs => { "../default.sub.cf" }; - bundlesequence => { default("$(this.promise_filename)") }; - version => "1.0"; + inputs => { "../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; } ####################################################### - body action warnonly { - action_policy => "warn"; + action_policy => "warn"; } ####################################################### - bundle agent test { methods: - "verify" - usebundle => test_method, - action => warnonly, - classes => if_else("method_kept", "method_notkept"); + "verify" + usebundle => test_method, + action => warnonly, + classes => if_else("method_kept", "method_notkept"); } bundle agent test_method { reports: - "unwanted sideeffect!" classes => if_else("report_kept", "report_notkept"); + "unwanted sideeffect!" classes => if_else("report_kept", "report_notkept"); } bundle agent check @@ -43,6 +40,7 @@ bundle agent check reports: ok:: "$(this.promise_filename) Pass"; + !ok:: "$(this.promise_filename) FAIL"; } From ff9f9747ab9480af9301afa942ca042966cf025e Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Thu, 25 Jun 2026 16:47:42 +0200 Subject: [PATCH 7/7] Updated expected output in test Signed-off-by: Ole Herman Schumacher Elgesem --- .../30_custom_promise_types/22_what_module_gets.cf.expected | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/acceptance/30_custom_promise_types/22_what_module_gets.cf.expected b/tests/acceptance/30_custom_promise_types/22_what_module_gets.cf.expected index d06f1bc7c9..5536b5ea33 100644 --- a/tests/acceptance/30_custom_promise_types/22_what_module_gets.cf.expected +++ b/tests/acceptance/30_custom_promise_types/22_what_module_gets.cf.expected @@ -4,7 +4,7 @@ operation=validate_promise log_level=info promise_type=example promiser=Promiser -line_number=46 +line_number=45 filename=./30_custom_promise_types/22_what_module_gets.cf attribute_attributeName=attributeValue @@ -12,7 +12,7 @@ operation=evaluate_promise log_level=info promise_type=example promiser=Promiser -line_number=46 +line_number=45 filename=./30_custom_promise_types/22_what_module_gets.cf attribute_attributeName=attributeValue