# Checks that a yum check-update with multiline entries generates the correct
# software_patches_avail.cf file, including when there are errors.

body common control
{
    cfengine_3_7::
      inputs => {
                  "../dcs.sub.cf",
                  "../../../lib/stdlib.cf",
                  "../../../lib/packages.cf",
                };

    !cfengine_3_7::
      inputs => { "../dcs.sub.cf",
                  "../../../$(sys.local_libdir)/stdlib.cf",
                  "../../../$(sys.local_libdir)/packages.cf",
      };


    any::
      bundlesequence => { default($(this.promise_filename)) };
}

bundle agent init
{
  files:
      "$(G.testdir)/package-update-list.txt"
        create => "true",
        # Taken from various yum runs with long package names and
        # connection errors, broken at 80 columns.
        edit_line => insert_lines("Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: mirror.searchdaimon.com
 * extras: mirror.searchdaimon.com
 * updates: mirror.searchdaimon.com
http://centos.vianett.no/5.9/os/x86_64/repodata/repomd.xml: [Errno 4] IOError: <urlopen error (101, 'Network is unreachable')>
Trying other mirror.
Skipping security plugin, no data

yum.noarch                 3.2.29-43.el6_5      rhui-REGION-rhel-server-releases
yum-plugin-security.noarch
                           1.1.30-17.el6_5
                                                rhui-REGION-rhel-server-releases
Useless header:
phonon-backend-gstreamer.x86_64
                           1:4.6.2-28.el6_5     rhui-REGION-rhel-server-releases
java-1.6.0-openjdk.x86_64  1:1.6.0.0-5.1.13.3.el6_5
                                                rhui-REGION-rhel-server-releases
Obsoleting Packages
firefox.i386                        24.5.0-1.el5.centos                updates
    firefox.i386                    17.0.6-1.el5.centos                installed
firefox.x86_64                      24.5.0-1.el5.centos                updates
    firefox.x86_64                  17.0.6-1.el5.centos                installed");
}

# Taken from packages.cf, with some modifications.
body package_method yum_test
{
      package_changes => "bulk";
      package_list_command => "$(G.true)";
      package_patch_command => "$(G.true)";
      package_patch_list_command => "$(G.cat) $(G.testdir)/package-update-list.txt $(redhat_knowledge.check_update_postproc)";

      package_list_name_regex    => "$(rpm_knowledge.rpm3_name_regex)";
      package_list_version_regex => "$(rpm_knowledge.rpm3_version_regex)";
      package_list_arch_regex    => "$(rpm_knowledge.rpm3_arch_regex)";

      package_installed_regex => ".*";
      package_name_convention => "$(name)-$(version).$(arch)";

      package_delete_convention => "$(name)";

      package_list_update_command => "$(G.cat) $(G.testdir)/package-update-list.txt $(redhat_knowledge.check_update_postproc)";
      package_list_update_ifelapsed => "$(common_knowledge.list_update_ifelapsed)";

      package_patch_name_regex    => "$(redhat_knowledge.patch_name_regex)";
      package_patch_version_regex => "$(redhat_knowledge.patch_version_regex)";
      package_patch_arch_regex    => "$(redhat_knowledge.patch_arch_regex)";

      package_add_command    => "$(G.true)";
      package_update_command => "$(G.true)";
      package_patch_command  => "$(G.true)";
      package_delete_command => "$(G.true)";
      package_verify_command => "$(G.true)";
}

bundle agent test
{
  meta:
      # Redhat specific issue.
      "test_skip_unsupported" string => "!redhat|!enterprise|cfengine_3_7";

  packages:
      "dummy-nonexisting-package"
        package_policy => "addupdate",
        package_method => yum_test;
}

bundle agent check
{
  methods:
      "test" usebundle => sorted_check_diff("$(sys.workdir)/state/software_patches_avail.csv",
                                            "$(this.promise_dirname)/multiline_yum_check_update.cf.expected",
                                            "$(this.promise_filename)");
}
