File: dcs.cf.sub

package info (click to toggle)
cfengine3 3.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 20,256 kB
  • ctags: 9,613
  • sloc: ansic: 116,129; sh: 12,366; yacc: 1,088; makefile: 1,006; lex: 391; perl: 197; xml: 21; sed: 4
file content (737 lines) | stat: -rw-r--r-- 24,787 bytes parent folder | download
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
########################################################################
# Acceptance test framework.
#
# See README for details about writing test cases.
########################################################################

bundle common G
{
  vars:
    windows::
      "cwd" string => execresult("C:\windows\system32\cmd.exe /C cd", "noshell");
      # 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");
      # Use for redirection, not as a real file.
      "dev_null" string => "/dev/null";
      "exeext" string => "";

    any::
      # General commands.
      "cmds" slist => { "date",
                        "diff",
                        "cat",
                        "colordiff",
                        "echo",
                        "egrep",
                        "env",
                        "false",
                        "grep",
                        "gzip",
                        "hexdump",
                        "ln",
                        "ls",
                        "mkdir",
                        "mock_package_manager",
                        "od",
                        "perl",
                        "printf",
                        "ps",
                        "psexec",
                        "pwd",
                        "rm",
                        "sed",
                        "seq",
                        "sleep",
                        "sort",
                        "tee",
                        "touch",
                        "true",
                        "wc",
                      };
      # Special cases.
      "make_cmds" slist => { "gmake", "make" };

    any::
      "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";
    !windows::
      "paths[bin]" string                    => "/bin";
      "paths[usr_bin]" string                => "/usr/bin";
      "paths[usr_local_bin]" string          => "/usr/local/bin";
      "paths[usr_contrib_bin]" string        => "/usr/contrib/bin";
    windows::
      "paths[mingw_msys_1_0_bin]" string     => "c:\\mingw\\msys\\1.0\\bin";
      "paths[msys_1_0_bin]" string           => "c:\\msys\\1.0\\bin";
      "paths[msys_bin]" string               => "c:\\msys\\bin";
      "paths[pstools]" string                => "c:\\PSTools";
      "paths[strawberry_perl_bin]" string    => "c:\\strawberry\\perl\\bin";
      "paths[tool_wrappers]" string          => "$(this.promise_dirname)\\tool_wrappers";

    any::
      "paths_indices" slist => getindices("paths");

  classes:
      # General commands.
      "$(paths_indices)_$(cmds)$(exeext)" expression => fileexists("$(paths[$(paths_indices)])$(const.dirsep)$(cmds)$(exeext)");
      "has_$(cmds)"                       expression => fileexists("$(paths[$(paths_indices)])$(const.dirsep)$(cmds)$(exeext)"),
      scope => "namespace";

      # Special cases.
      "$(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));

  vars:
      # General commands.
      "$(cmds)" string => "$(paths[$(paths_indices)])$(const.dirsep)$(cmds)$(exeext)",
      ifvarclass => canonify("$(paths_indices)_$(cmds)$(exeext)");

      # Special cases.
      # gmake has higher priority, so should come last.
      "make" string => "$(paths[$(paths_indices)])$(const.dirsep)make$(exeext)",
      ifvarclass => canonify("$(paths_indices)_make$(exeext)");
      "make" string => "$(paths[$(paths_indices)])$(const.dirsep)gmake$(exeext)",
      ifvarclass => canonify("$(paths_indices)_gmake$(exeext)");

    want_color.have_colordiff::
      "diff_maybecolor" string => $(colordiff);
    !want_color|!have_colordiff::
      "diff_maybecolor" string => $(diff);

  classes:
      "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";

    temp_declared::
      "testroot" string => getenv("TEMP", "65535");
      "testdir" string => concat(getenv("TEMP", "65535"), "$(const.dirsep)TEST.cfengine");
      "testfile" string => concat(getenv("TEMP", "65535"), "$(const.dirsep)TEST.cfengine");

    !temp_declared::
      "testroot" string => "$(const.dirsep)tmp";
      "testdir" string => "$(const.dirsep)tmp$(const.dirsep)TEST.cfengine";
      "testfile" string => "$(const.dirsep)tmp$(const.dirsep)TEST.cfengine";

}

bundle common dcs_strings
{
  vars:
      "multiline_potatoes" string =>
      "BEGIN
    One potato
    Two potato
    Three potatoes
    Four
END";

      "multiline_potatoes_lesser" string =>
      "BEGIN
    One potato
    Three potatoes
    Four
END";
}

bundle common paths_init(filename)
{
  classes:
      "filename_absolute" expression => regcmp("/.*", "$(filename)");
}

bundle common paths_absolute(filename)
{
  vars:
    filename_absolute::
      "input_file"
      string => "$(filename)";
    !filename_absolute::
      "input_file"
      string => "$(G.cwd)/$(filename)";
}

bundle agent default(filename)
{
  classes:
      "have_test_run_$(bundles)" expression => "any";
  vars:

      "tests" slist => { "default:init",
                         "default:test",
                         "default:check"
      };

      "bundles" slist => bundlesmatching("default:(init|test|check)");

  methods:
      "any" usebundle => test_precheck;

    proceed_with_test::
      "any" usebundle => test_run("$(filename)"), inherit => "true";

  reports:
    EXTRA.verbose_mode::
      "$(this.bundle): found runnable bundle $(bundles)";
}

bundle agent test_run(filename)
{
  vars:

  methods:
      "any"
      usebundle => paths_init("$(filename)");
      "any"
      usebundle => paths_absolute("$(filename)");

    AUTO::
      "any" usebundle => "$(default.tests)",
      ifvarclass => canonify("have_test_run_$(default.tests)");

  reports:
    !AUTO::
      "# You must either specify '-D AUTO' or run the following commands:";
      "cf-agent -f .$(const.dirsep)$(filename) -b $(tests)";
}

bundle agent test_precheck
{
  vars:
      "test_skip_unsupported" slist => variablesmatching(".*_meta\.test_skip_unsupported");
      "test_skip_needs_work" slist => variablesmatching(".*_meta\.test_skip_needs_work");
      "test_suppress_fail" slist => variablesmatching(".*_meta\.test_suppress_fail");
      "test_suppress_fail_metatags" slist => getvariablemetatags("$(test_suppress_fail)");
      "test_suppress_fail_redmine" slist => filter("redmine.*", "test_suppress_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_suppress_fail_set" expression => some(".*", "test_suppress_fail");
      "test_suppress_fail_redmine_set" expression => some(".*", "test_suppress_fail_redmine");

      "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_suppress_fail_match" and => { "test_suppress_fail_set", "$($(test_suppress_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_redmine_set::
      "$(this.promise_filename) XFAIL/$(test_suppress_fail_redmine)";
    test_suppress_fail_match.!test_suppress_fail_redmine_set::
      "$(this.promise_filename) FAIL/no_redmine_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;
}

bundle agent dcs_check_diff(file1, file2, test)
{
  methods:
      "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));
}

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");
}

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");
      "file2r" string => execresult("$(G.cwd)/xml-c14nize $(file2)", "noshell");

    DEBUG.check_ready.!no_difference.has_hexdump::
      "file1h" string => execresult("$(G.hexdump) -C $(file1)", "useshell");
      "file2h" string => execresult("$(G.hexdump) -C $(file2)", "useshell");

    DEBUG.check_ready.!no_difference.!has_hexdump::
      "file1h" string => execresult("$(G.od) -c $(file1)", "useshell");
      "file2h" string => execresult("$(G.od) -c $(file2)", "useshell");

    DEBUG.check_ready.!no_difference.has_unified_diff::
      "diffu" string => execresult("$(G.diff_maybecolor) -u $(file2) $(file1) 2>$(G.dev_null)", "useshell");
    DEBUG.check_ready.!no_difference.!has_unified_diff::
      "diffu" string => execresult("$(G.diff_maybecolor) -c $(file2) $(file1) 2>$(G.dev_null)", "useshell");

  classes:
      "has_unified_diff" expression => returnszero(
                                                    "$(G.diff_maybecolor) -u $(G.etc_null) $(G.etc_null) >$(G.dev_null) 2>&1", "useshell");

    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");

      "expected_difference" expression => strcmp("$(expected_difference)", "yes");
      "check_ready" expression => "any";

  commands:
      "$(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"
      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";

    DEBUG.check_ready.!no_difference.!expected_difference::
      "$(file1) and $(file2) differ:";
      "$(file1): <$(file1r)>";
      "$(file2): <$(file2r)>";
      "dump $(file1):
$(file1h)";
      "dump $(file2):
$(file2h)";
      "$(diffu)";
    DEBUG.check_ready.no_difference.expected_difference::
      "Contents of $(file1) and $(file) is the same.";
}

bundle agent dcs_report_generic_classes(x)
{
  vars:
      "choices" slist => { "repaired", "failed", "denied", "timeout", "kept" };

  reports:
    DEBUG::
      "class '$(x)_$(choices)' was defined" ifvarclass => '$(x)_$(choices)';
      "class '$(x)_$(choices)' was NOT defined" ifvarclass => '!$(x)_$(choices)';
}

bundle agent dcs_generic_classes_to_string(x)
{
  vars:
      "choices" slist => { "repaired", "failed", "denied", "timeout", "kept" };
      "s[$(choices)]" string => "$(x)_$(choices)", ifvarclass => '$(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";
}

# 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" };
}

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
  classes:
      "$(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);

  reports:
      "$(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");

  reports:
    dcs_check_diff_expected_pass_class::
      "$(test) Pass";
    dcs_check_diff_expected_fail_class::
      "$(test) FAIL";
}

bundle agent dcs_if_diff_expected(file1, file2, expected_difference, pass_class, fail_class)
{
  vars:
    DEBUG.check_ready.!no_difference::
      "file1r" string => readfile("$(file1)", "4096");
      "file2r" string => readfile("$(file2)", "4096");

    (EXTRA|DEBUG_HEXDUMP).check_ready.!no_difference.has_hexdump::
      "file1h" string => execresult("$(G.hexdump) -C $(file1)", "useshell");
      "file2h" string => execresult("$(G.hexdump) -C $(file2)", "useshell");

    (EXTRA|DEBUG_HEXDUMP).check_ready.!no_difference.!has_hexdump::
      "file1h" string => execresult("$(G.od) -c $(file1)", "useshell");
      "file2h" string => execresult("$(G.od) -c $(file2)", "useshell");

    DEBUG.check_ready.!no_difference.has_unified_diff::
      "diffu" string => execresult("$(G.diff_maybecolor) -u $(file2) $(file1) 2>$(G.dev_null)", "useshell");
    DEBUG.check_ready.!no_difference.!has_unified_diff::
      "diffu" string => execresult("$(G.diff_maybecolor) -c $(file2) $(file1) 2>$(G.dev_null)", "useshell");

  classes:
      "has_unified_diff" expression => returnszero(
                                                    "$(G.diff_maybecolor) -u $(G.etc_null) $(G.etc_null) >$(G.dev_null) 2>&1", "useshell");

      "no_difference" expression => returnszero(
                                                 "$(G.diff_maybecolor) $(file1) $(file2) >$(G.dev_null) 2>&1",
                                                 "useshell");

      "expected_difference" expression => strcmp("$(expected_difference)", "yes");
      "check_ready" expression => "any";

    check_ready.no_difference.!expected_difference::
      "$(pass_class)" expression => "any",
        scope => "namespace";
    check_ready.!no_difference.expected_difference::
      "$(pass_class)" expression => "any",
        scope => "namespace";
    check_ready.!no_difference.!expected_difference::
      "$(fail_class)" expression => "any",
        scope => "namespace";
    check_ready.no_difference.expected_difference::
      "$(fail_class)" expression => "any",
        scope => "namespace";

  reports:
    DEBUG.check_ready.!no_difference.!expected_difference::
      "FILES DIFFER BUT SHOULD BE THE SAME";
      "CONTENTS OF $(file1):
$(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)";
}

bundle agent dcs_sleep(t)
{
  commands:
      "$(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.workdir)/state/cf_state.*"
      contain => dcs_useshell;

  reports:
    EXTRA::
      "$(this.bundle): deleting $(file) with $(G.rm) -rf";
}

bundle agent dcs_copyfile(from, to)
{
  files:
      "$(to)"
      create => "true",
      copy_from => dcs_sync($(from));

  reports:
    EXTRA::
      "$(this.bundle): copying file $(from) to $(to)";
}

body copy_from dcs_sync(f)
{
      source => "$(f)";
      purge => "true";
      preserve => "false";
      type_check => "false";
      compare => "digest";
}

body contain dcs_useshell
{
      useshell => "true";
      chdir => "/";
}

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") };

      "__passif" xor => { "equal", "expected_difference" };
  reports:
    EXTRA|!__passif::
      "$(this.bundle): STRING A: '$(strA)'";
      "$(this.bundle): STRING B: '$(strB)'";
    __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)
{
  classes:
      "matched" expression => regcmp($(regex), $(thestring));
      "expected_mismatch" or => { strcmp($(expected_mismatch), "yes"),
                                  strcmp($(expected_mismatch), "true") };

      "__passif" xor => { "equal", "expected_mismatch" };
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" ifvarclass => $(classname);
      "$(test) FAIL" ifvarclass => not($(classname));

    EXTRA::
      "$(this.bundle): passing based on class '$(classname)'" ifvarclass => $(classname);
    DEBUG::
      "$(this.bundle): failing based on class '$(classname)'" ifvarclass => not($(classname));
}

bundle agent dcs_pass(test)
{
  reports:
      "$(test) Pass";
    EXTRA::
      "$(this.bundle): Explicitly passing...";
}

bundle agent dcs_fail(test)
{
  reports:
      "$(test) FAIL";
    EXTRA::
      "$(this.bundle): Explicitly failing...";
}

bundle agent dcs_wait(test, seconds)
{
  reports:
      "$(test) Wait/$(seconds)";
    EXTRA::
      "$(this.bundle): Explicitly waiting $(seconds) seconds...";
}

bundle agent dcs_passif_fileexists(file, test)
{
  classes:
      "__passif" expression => fileexists($(file));

  methods:
      "" usebundle => dcs_passif("__passif", $(test)), inherit => "true";

  reports:
    DEBUG.!__passif::
      "$(this.bundle): $(file) did not exist!";
    EXTRA.__passif::
      "$(this.bundle): $(file) exists.";
}

bundle agent dcs_passif_file_absent(file, test)
{
  classes:
      "__passif" not => fileexists($(file));

  methods:
      "" usebundle => dcs_passif("__passif", $(test)), inherit => "true";

  reports:
    DEBUG.__passif::
      "$(this.bundle): $(file) did not exist.";
    EXTRA.!__passif::
      "$(this.bundle): $(file) exists!";
}

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);

  classes:
      "__passif" and => { @(classes) };
  methods:
      "" usebundle => dcs_passif("__passif", $(test)), inherit => "true";

  reports:
    DEBUG::
      "$(this.bundle): bad: $(ex) was NOT defined"
      ifvarclass => "!$(ex)";

      "$(this.bundle): bad: $(notex) WAS defined"
      ifvarclass => "$(notex)";

    EXTRA::
      "$(this.bundle): good: $(ex) WAS defined"
      ifvarclass => "$(ex)";

      "$(this.bundle): good: $(notex) was NOT defined"
      ifvarclass => "!$(notex)";
}

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

bundle agent dcs_passif_output(wanted, unwanted, command, test)
{
  vars:
      "subout" string => execresult($(command), "useshell");

  classes:
      "__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)),
      inherit => "true";

  reports:
    DEBUG::
      "$(this.bundle): bad: $(wanted) was NOT found in the output of $(command)"
      ifvarclass => "!__passif_output_wanted";

      "$(this.bundle): bad: $(unwanted) WAS found in the output of $(command)"
      ifvarclass => "__passif_output_unwanted";

    EXTRA::
      "$(this.bundle): good: $(wanted) WAS found in the output of $(command)"
      ifvarclass => "__passif_output_wanted";

      "$(this.bundle): good: $(unwanted) was NOT found in the output of $(command)"
      ifvarclass => "!__passif_output_unwanted";

    DEBUG::
      "$(this.bundle): the output of command '$(command)' was: $(subout)";
}

bundle agent dcs_passif_output1(wanted, command, test)
{
  methods:
      "" usebundle => dcs_passif_output($(wanted), # expected
                                        "^(unlikely data){400}$", # not expected
                                        $(command),
                                        $(test)),
      inherit => "true";
}