######################################################
#
#  Test of promise module using the Python library with promise-specific log_level
#
#####################################################
body common control
{
  inputs => { "../default.sub.cf" };
  bundlesequence => { default("$(this.promise_filename)") };
  version => "1.0";
}

#######################################################
bundle common python_check
{
  classes:
    "python_version_compatible_with_cfengine_library"
      expression => returnszero(
        "/usr/bin/python3 -c 'import sys; assert sys.version_info >= (3,6)'",
        "useshell"
      );
@if minimum_version(3.17)
    "cfengine_supports_custom_promises" expression => "any";
@endif
}

bundle agent init
{
  meta:
    "test_skip_unsupported"
      string => "!python_version_compatible_with_cfengine_library|!cfengine_supports_custom_promises";

  vars:
    "test_string" string => "hello, modules";

  files:
    "$(G.testfile).src"
      create => "true",
      edit_line => insert_lines("$(test_string)");

    "$(G.testfile).dst" delete => init_delete;

    "$(this.promise_dirname)/cfengine.py"
      copy_from => local_cp(
        "$(this.promise_dirname)/../../../modules/promises/cfengine.py"
      );
}

body delete init_delete
{
  dirlinks => "delete";
  rmdirs => "true";
}

bundle agent check
{
  vars:
    "command"
      string => "$(sys.cf_agent) -D AUTO -KIf $(this.promise_filename).sub";

  methods:
    "check"
      usebundle => dcs_passif_output(
        ".*", ".*info:.*", $(command), $(this.promise_filename)
      );
}
