diff --git a/example_def.json b/example_def.json index 720d366bcd..46f8210ed2 100644 --- a/example_def.json +++ b/example_def.json @@ -1,32 +1,40 @@ { - "classes": - { - "my_apache": [ "server1", "server2", "redhat.*" ], - "my_other_apache": [ "server[34]", "debian.*" ], - "my_filehost": [ "server3" ], - "my_gateway": [ "server3" ], - "my_yum_role": [ "redhat.*" ], - "my_redhat_role": [ "redhat.*" ], - "my_apt_role": [ "debian.*" ], - "my_debian_role": [ "debian.*" ], - "services_autorun": [ "any" ], - "cfengine_internal_disable_agent_email": [ "enterprise_edition" ], - "cfe_internal_core_watchdog_enabled": [ "any" ], - "mpf_control_agent_default_repository": [ "any" ] - }, - - "inputs": [ "$(sys.libdir)/bundles.cf" ], - "vars": { - - "control_agent_default_repository": "/var/cfengine/edit_backups", - "acl": [ ".*$(def.domain)", "$(sys.policy_hub)/16" ], - "control_agent_maxconnections": 100, - "control_common_bundlesequence_end": [ "my_bundle", "my_other_bundle" ], - "control_agent_files_single_copy": [ "/etc/.*", "/tmp/special_file" ], - "input_name_patterns": [ ".*\\.cf",".*\\.dat",".*\\.txt", ".*\\.conf", ".*\\.mustache", - ".*\\.sh", ".*\\.pl", ".*\\.py", ".*\\.rb", - "cf_promises_release_id", ".*\\.json", ".*\\.yaml", ".*\\.js" ], - - "dir_templates": "/var/cfengine/templates_tests" - } + "classes": { + "my_apache": ["server1", "server2", "redhat.*"], + "my_other_apache": ["server[34]", "debian.*"], + "my_filehost": ["server3"], + "my_gateway": ["server3"], + "my_yum_role": ["redhat.*"], + "my_redhat_role": ["redhat.*"], + "my_apt_role": ["debian.*"], + "my_debian_role": ["debian.*"], + "services_autorun": ["any"], + "cfengine_internal_disable_agent_email": ["enterprise_edition"], + "cfe_internal_core_watchdog_enabled": ["any"], + "mpf_control_agent_default_repository": ["any"] + }, + "inputs": ["$(sys.libdir)/bundles.cf"], + "vars": { + "control_agent_default_repository": "/var/cfengine/edit_backups", + "acl": [".*$(def.domain)", "$(sys.policy_hub)/16"], + "control_agent_maxconnections": 100, + "control_common_bundlesequence_end": ["my_bundle", "my_other_bundle"], + "control_agent_files_single_copy": ["/etc/.*", "/tmp/special_file"], + "input_name_patterns": [ + ".*\\.cf", + ".*\\.dat", + ".*\\.txt", + ".*\\.conf", + ".*\\.mustache", + ".*\\.sh", + ".*\\.pl", + ".*\\.py", + ".*\\.rb", + "cf_promises_release_id", + ".*\\.json", + ".*\\.yaml", + ".*\\.js" + ], + "dir_templates": "/var/cfengine/templates_tests" + } } diff --git a/inventory/any.cf b/inventory/any.cf index 19ecaa513d..81cc837d73 100644 --- a/inventory/any.cf +++ b/inventory/any.cf @@ -1417,8 +1417,10 @@ body package_method inventory_lslpp(update_interval) package_list_update_command => "/usr/bin/true"; package_list_update_ifelapsed => $(update_interval); package_list_command => "/usr/bin/lslpp -Lqc"; + # list RPMs too package_list_version_regex => "[^:]+:[^:]+:([^:]+):.*"; + # Make sure version is not included in the name, that indicates RPM # packages, which we should ignore. package_list_name_regex => "[^:]+:(([^-:]|-[^0-9])+):.*"; @@ -1483,5 +1485,6 @@ body contain inventory_in_shell # Copy of `in_shell`, which see. { useshell => "true"; + # canonical "useshell" but this is backwards-compatible } diff --git a/services/main.cf b/services/main.cf index ef169336e2..8574ff935a 100644 --- a/services/main.cf +++ b/services/main.cf @@ -8,5 +8,6 @@ bundle agent mpf_main # User Defined Service Catalogue { methods: + # Activate your custom policies here } diff --git a/tests/acceptance/00_basics/def.json/control_common_bundlesequence_end.cf b/tests/acceptance/00_basics/def.json/control_common_bundlesequence_end.cf index 255febd1e1..86e9c36139 100644 --- a/tests/acceptance/00_basics/def.json/control_common_bundlesequence_end.cf +++ b/tests/acceptance/00_basics/def.json/control_common_bundlesequence_end.cf @@ -1,53 +1,60 @@ # Tests that the bundles specified in vars control_common_bundlesequence_end # are automatically run. - 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: - # This is bad, see below. - "files_to_copy" slist => { - "cfe_internal", - "controls", - "inventory", - "lib", - "promises.cf", - "services", + # This is bad, see below. + "files_to_copy" + slist => { + "cfe_internal", + "controls", + "inventory", + "lib", + "promises.cf", + "services", }; files: - "$(sys.inputdir)/." - create => "true"; - # Ideally this should be a complete subdir copy, but masterfiles files are - # currently mixed with other files, including this directory that we're - # in, so we would get an infinitely deep copy in that case. - "$(sys.inputdir)/$(files_to_copy)" - copy_from => dcs_sync("$(this.promise_dirname)/../../../../$(files_to_copy)"), - perms => m(600), - depth_search => recurse("inf"); + "$(sys.inputdir)/." create => "true"; + + # Ideally this should be a complete subdir copy, but masterfiles files are + # currently mixed with other files, including this directory that we're + # in, so we would get an infinitely deep copy in that case. + "$(sys.inputdir)/$(files_to_copy)" + copy_from => dcs_sync( + "$(this.promise_dirname)/../../../../$(files_to_copy)" + ), + perms => m(600), + depth_search => recurse("inf"); methods: - "" usebundle => file_make("$(sys.inputdir)/secondary.cf", ' + "" + usebundle => file_make( + "$(sys.inputdir)/secondary.cf", + ' bundle agent x { reports: "reporting actuation of bundle x"; } -'); +' + ); - "" usebundle => file_copy("$(this.promise_filename).json", "$(sys.inputdir)/def.json"); + "" + usebundle => file_copy( + "$(this.promise_filename).json", "$(sys.inputdir)/def.json" + ); } ####################################################### - bundle agent check { vars: @@ -55,5 +62,11 @@ bundle agent check "command" string => "$(sys.cf_agent) -Kf $(sys.inputdir)/promises.cf"; methods: - "" usebundle => dcs_passif_output(".*R: reporting actuation of bundle x.*", "", $(command), $(this.promise_filename)); + "" + usebundle => dcs_passif_output( + ".*R: reporting actuation of bundle x.*", + "", + $(command), + $(this.promise_filename) + ); } diff --git a/tests/acceptance/00_basics/def.json/control_common_bundlesequence_end.cf.json b/tests/acceptance/00_basics/def.json/control_common_bundlesequence_end.cf.json index 5e90b49002..49b1b0dcc2 100644 --- a/tests/acceptance/00_basics/def.json/control_common_bundlesequence_end.cf.json +++ b/tests/acceptance/00_basics/def.json/control_common_bundlesequence_end.cf.json @@ -1,7 +1,4 @@ { - "inputs": [ "$(sys.inputdir)/secondary.cf" ], - - "vars": { - "control_common_bundlesequence_end": [ "x" ] - } + "inputs": ["$(sys.inputdir)/secondary.cf"], + "vars": { "control_common_bundlesequence_end": ["x"] } } diff --git a/tests/acceptance/00_basics/def.json/inputs.cf b/tests/acceptance/00_basics/def.json/inputs.cf index eeb1353400..63aaa2d119 100644 --- a/tests/acceptance/00_basics/def.json/inputs.cf +++ b/tests/acceptance/00_basics/def.json/inputs.cf @@ -4,58 +4,72 @@ # Heavily inspired by the inputs.cf test in core. The key difference is that # this test does not explicitly refer to the variable defined in def.json, but # relies on the masterfiles policies to do it. - 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: - # This is bad, see below. - "files_to_copy" slist => { - "cfe_internal", - "controls", - "inventory", - "lib", - "promises.cf", - "services", + # This is bad, see below. + "files_to_copy" + slist => { + "cfe_internal", + "controls", + "inventory", + "lib", + "promises.cf", + "services", }; files: - "$(sys.inputdir)/." - create => "true"; - # Ideally this should be a complete subdir copy, but masterfiles files are - # currently mixed with other files, including this directory that we're - # in, so we would get an infinitely deep copy in that case. - "$(sys.inputdir)/$(files_to_copy)" - copy_from => dcs_sync("$(this.promise_dirname)/../../../../$(files_to_copy)"), - depth_search => recurse("inf"); + "$(sys.inputdir)/." create => "true"; + + # Ideally this should be a complete subdir copy, but masterfiles files are + # currently mixed with other files, including this directory that we're + # in, so we would get an infinitely deep copy in that case. + "$(sys.inputdir)/$(files_to_copy)" + copy_from => dcs_sync( + "$(this.promise_dirname)/../../../../$(files_to_copy)" + ), + depth_search => recurse("inf"); methods: - "" usebundle => file_make("$(sys.inputdir)/secondary.cf", ' + "" + usebundle => file_make( + "$(sys.inputdir)/secondary.cf", + ' bundle common x { classes: "test_class_4f862c89e9bc62fa6da0ca3c782678893c0dc246" expression => "any"; } -'); +' + ); - "" usebundle => file_copy("$(this.promise_filename).json", "$(sys.inputdir)/def.json"); + "" + usebundle => file_copy( + "$(this.promise_filename).json", "$(sys.inputdir)/def.json" + ); } ####################################################### - bundle agent check { vars: - "command" string => "$(sys.cf_promises) --show-classes -f $(sys.inputdir)/promises.cf|$(G.grep) test_class"; + "command" + string => "$(sys.cf_promises) --show-classes -f $(sys.inputdir)/promises.cf|$(G.grep) test_class"; methods: - "" usebundle => dcs_passif_output("test_class_4f862c89e9bc62fa6da0ca3c782678893c0dc246\s+source=promise", "", $(command), $(this.promise_filename)); + "" + usebundle => dcs_passif_output( + "test_class_4f862c89e9bc62fa6da0ca3c782678893c0dc246\s+source=promise", + "", + $(command), + $(this.promise_filename) + ); } diff --git a/tests/acceptance/00_basics/def.json/inputs.cf.json b/tests/acceptance/00_basics/def.json/inputs.cf.json index 4986384df1..525d507e17 100644 --- a/tests/acceptance/00_basics/def.json/inputs.cf.json +++ b/tests/acceptance/00_basics/def.json/inputs.cf.json @@ -1,3 +1,3 @@ { - "inputs": [ "$(sys.inputdir)/secondary.cf" ] + "inputs": ["$(sys.inputdir)/secondary.cf"] } diff --git a/tests/acceptance/09_services/unsafe/running_repaired.cf b/tests/acceptance/09_services/unsafe/running_repaired.cf index 580b9934d8..1bb11c17fd 100644 --- a/tests/acceptance/09_services/unsafe/running_repaired.cf +++ b/tests/acceptance/09_services/unsafe/running_repaired.cf @@ -1,29 +1,28 @@ bundle common test_meta { -vars: - "description" string => "Test that a service which is not running gets started"; - "story_id" string => "5583"; - "covers" string => "operational_repaired"; + vars: + "description" + string => "Test that a service which is not running gets started"; + + "story_id" string => "5583"; + "covers" string => "operational_repaired"; } ####################################################### - body common control { - inputs => { "../../dcs.sub.cf", - "../../../../$(sys.local_libdir)/stdlib.cf", - "service_common.cf.sub" - }; - - bundlesequence => { default($(this.promise_filename)) }; + inputs => { + "../../dcs.sub.cf", + "../../../../$(sys.local_libdir)/stdlib.cf", + "service_common.cf.sub", + }; + bundlesequence => { default($(this.promise_filename)) }; } ####################################################### - bundle agent init { meta: - # TODO fix this test to not mess with the ntp service - it is # currently provisioned by CFEngine on the buildslave itself, # thus creating test inconsistensies every 5 minutes. @@ -35,60 +34,67 @@ bundle agent init "test_skip_needs_work" string => "any"; methods: - "" usebundle => service_stop( $(service_common.service_name) ); + "" usebundle => service_stop($(service_common.service_name)); } ####################################################### - bundle agent test { methods: - "" usebundle => service_is_running("$(service_common.service_name)", "service_running_in_test", "service_not_running_in_test"); + "" + usebundle => service_is_running( + "$(service_common.service_name)", + "service_running_in_test", + "service_not_running_in_test" + ); services: service_not_running_in_test:: - "$(service_common.service_name)" + "$(service_common.service_name)" action => immediate, service_policy => "start"; } ####################################################### - bundle agent check1 { methods: - "" usebundle => service_is_running("$(service_common.service_name)", "service_running_in_check", "service_not_running_in_check"); + "" + usebundle => service_is_running( + "$(service_common.service_name)", + "service_running_in_check", + "service_not_running_in_check" + ); } bundle agent check2 { # Stop the service again afterwards to avoid errors about lingering processes. methods: - "" usebundle => service_stop( $(service_common.service_name) ); + "" usebundle => service_stop($(service_common.service_name)); + processes: - ".*ntpd.*" - process_select => ntpd, - signals => { "kill" }; + ".*ntpd.*" + process_select => ntpd, + signals => { "kill" }; } body process_select ntpd { - # To avoid killing the system ntpd. - stime_range => irange(ago(0,0,0,0,1,0), now); + # To avoid killing the system ntpd. + stime_range => irange(ago(0, 0, 0, 0, 1, 0), now); } bundle agent check { methods: - "" usebundle => check1; - "" usebundle => check2; + "" usebundle => check1; + "" usebundle => check2; classes: - "ok" and => { "service_not_running_in_test", "service_running_in_check" }; - + "ok" and => { "service_not_running_in_test", "service_running_in_check" }; reports: - DEBUG.service_running_in_test:: "$(service_common.service_name) found to be running in test bundle"; @@ -106,6 +112,7 @@ bundle agent check ok:: "$(this.promise_filename) Pass"; + !ok:: "$(this.promise_filename) FAIL"; } diff --git a/tests/acceptance/promises/autorun-D.cf b/tests/acceptance/promises/autorun-D.cf index 1e2a685d02..99e593de38 100644 --- a/tests/acceptance/promises/autorun-D.cf +++ b/tests/acceptance/promises/autorun-D.cf @@ -23,6 +23,7 @@ bundle agent init "promises_cf_slist" slist => findfiles("$(G.testdir)/**/promises.cf"); "promises_cf_path" string => nth(promises_cf_slist, 0); } + ####################################################### bundle agent check { diff --git a/tests/acceptance/promises/autorun-def_json.cf b/tests/acceptance/promises/autorun-def_json.cf index fb1932a119..2f7424da5c 100644 --- a/tests/acceptance/promises/autorun-def_json.cf +++ b/tests/acceptance/promises/autorun-def_json.cf @@ -31,6 +31,7 @@ bundle agent test meta: "description" string => "Test that def.json can enable autorun as expected."; + # We need to lay down the def.json that will enable autorun. files: "$(init.def_json_path)" @@ -43,6 +44,7 @@ bundle edit_line enable_autorun insert_lines: '{ "classes": { "services_autorun": ["any"] } }'; } + ####################################################### bundle agent check { diff --git a/tests/acceptance/promises/autorun.cf b/tests/acceptance/promises/autorun.cf index 911e0da7ad..ac23b47a03 100644 --- a/tests/acceptance/promises/autorun.cf +++ b/tests/acceptance/promises/autorun.cf @@ -53,6 +53,7 @@ bundle edit_line enable_autorun insert_lines: 'bundle common __autorun_enable { classes: "services_autorun" expression => "any"; }'; } + ####################################################### bundle agent check { diff --git a/tests/acceptance/promises/promises.cf b/tests/acceptance/promises/promises.cf index 7b61d0fec0..f33ce801d6 100644 --- a/tests/acceptance/promises/promises.cf +++ b/tests/acceptance/promises/promises.cf @@ -9,10 +9,12 @@ body common control bundlesequence => { default("$(this.promise_filename)") }; version => "1.0"; } + ####################################################### bundle agent init { } + ####################################################### bundle agent test { @@ -23,6 +25,7 @@ bundle agent test "$(sys.cf_promises) -c --eval-functions -f $(this.promise_dirname)/../../../promises.cf" classes => if_ok("agent_worked_all_right"); } + ####################################################### bundle agent check {