1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
body common control
{
inputs => { "../default.cf.sub" };
bundlesequence => { default("$(this.promise_filename)") };
}
bundle agent test
{
meta:
"description" -> { "ENT-4988" }
string => "Test some basic expectations when using process_stop in processes type promises";
"test_soft_fail" string => "windows",
meta => { "ENT-10257" };
processes:
# The policy file itself is not expected to be executable, this promise is
# expected to fail and be notkept.
"."
process_stop => "$(this.promise_filename)",
handle => "process_stop_not_executable_expect_failed",
classes => explicit_results( "namespace", "$(this.handle)_is" );
# G.true is expected to return true, and the promise is expected to be
# repaired. Note: At the time of authorship there is no validation that
# the selected pids were killed by process_stop. We are only using the
# return code.
"."
process_stop => "$(G.true)",
handle => "process_stop_return_zero_expect_repaired",
classes => explicit_results( "namespace", "$(this.handle)_is" );
# G.false is expected to return false, and the promise is expected to be
# repaired. Note: At the time of authorship there is no validation that
# the selected pids were killed by process_stop. We are only using the
# return code.
"."
process_stop => "$(G.false)",
handle => "process_stop_return_nonzero_expect_failed",
classes => explicit_results( "namespace", "$(this.handle)_is" );
# G.echo is expected to return true, and the promise is expected to be
# repaired. Note: At the time of authorship there is no validation that
# the selected pids were killed by process_stop. We are only using the
# return code.
"."
process_stop => "$(G.echo) pretend stop servicename",
handle => "process_stop_with_args_return_nonzero_expect_repaired",
classes => explicit_results( "namespace", "$(this.handle)_is" );
}
bundle agent check
{
vars:
"expected_classes" slist => {
"process_stop_with_args_return_nonzero_expect_repaired_is_repaired",
"process_stop_return_nonzero_expect_failed_is_failed",
"process_stop_return_zero_expect_repaired_is_repaired",
"process_stop_not_executable_expect_failed_is_failed",
};
DEBUG::
"found_classes" slist => classesmatching( "process_stop_.*");
"difference" slist => difference( found_classes, expected_classes );
classes:
"ok" and => { @(expected_classes) };
reports:
DEBUG::
"Found unexpected class: $(difference)";
ok::
"$(this.promise_filename) Pass";
!ok::
"$(this.promise_filename) FAIL";
}
body classes explicit_results(scope, class_prefix)
# @brief Define classes prefixed with `class_prefix` and suffixed with
# appropriate outcomes: _kept, _repaired, _failed, _denied, _timeout
#
# @param scope The scope in which the class should be defined (`bundle` or `namespace`)
# @param class_prefix The prefix for the classes defined
#
# This body can be applied to any promise and sets global
# (`namespace`) or local (`bundle`) classes based on its outcome. For
# instance, with `class_prefix` set to `abc`:
#
# This body is a simpler, more consistent version of the body `results`. The key
# difference is that fewer classes are defined, and only for explicit outcomes
# that we can know. For example this body does not define "OK/not OK" outcome
# classes, since a promise can be both kept and failed at the same time.
#
# It's important to understand that promises may do multiple things,
# so a promise is not simply "OK" or "not OK." The best way to
# understand what will happen when your specific promises get this
# body is to test it in all the possible combinations.
#
# **Suffix Notes:**
#
# * `_kept` indicates some aspect of the promise was kept
#
# * `_repaired` indicates some aspect of the promise was repaired
#
# * `_failed` indicates the promise failed
#
# * `_denied` indicates the promise repair was denied
#
# * `_timeout` indicates the promise timed out
#
# **Example:**
#
# ```cf3
# bundle agent example
# {
# commands:
# "/bin/true"
# classes => results("bundle", "my_class_prefix");
#
# reports:
# my_class_prefix_kept::
# "My promise was kept";
#
# my_class_prefix_repaired::
# "My promise was repaired";
# }
# ```
#
# **See also:** `scope`, `scoped_classes_generic`, `classes_generic`
{
scope => "$(scope)";
promise_kept => { "$(class_prefix)_kept" };
promise_repaired => { "$(class_prefix)_repaired" };
repair_failed => { "$(class_prefix)_failed" };
repair_denied => { "$(class_prefix)_denied" };
repair_timeout => { "$(class_prefix)_timeout" };
}
|