1# Test that we don't refresh the package updates too often in the legacy package
2# promise.
3
4body common control
5{
6    inputs => { "../../../../dcs.cf.sub",
7                "../../../../../../inventory/any.cf",
8                "../../../../../../$(sys.local_libdir)/stdlib.cf",
9                "../../../../../../$(sys.local_libdir)/packages.cf"
10              };
11    bundlesequence  => { "inventory_autorun", default("$(this.promise_filename)") };
12}
13
14bundle agent init
15{
16  packages:
17    # Old way of forcing package updates, for the legacy packages promise.
18    debian::
19      "cfe_internal_non_existing_package"
20      package_policy => "add",
21      package_method => inventory_apt_get($(cfe_autorun_inventory_packages.refresh)),
22      action => if_elapsed_day;
23
24    redhat::
25      "cfe_internal_non_existing_package"
26      package_policy => "add",
27      package_method => inventory_yum_rpm($(cfe_autorun_inventory_packages.refresh)),
28      action => if_elapsed_day;
29}
30
31bundle agent test
32{
33  meta:
34      "test_skip_needs_work" string => "!redhat.!debian";
35      # RedHat 4 RPM has a bug which corrupts the RPM DB during our tests, so it is untestable.
36      "test_skip_unsupported" string => "redhat_4|centos_4";
37
38  classes:
39      "cache_exists" expression => fileexists("$(sys.workdir)/state/software_update_timestamp_$(pkg_man)"),
40        scope => "namespace";
41
42  vars:
43    redhat::
44      "pkg_man" string => "yum";
45    debian::
46      "pkg_man" string => "apt-get";
47    any::
48      "last_update" string => filestat("$(sys.workdir)/state/software_update_timestamp_$(pkg_man)", "mtime");
49
50  files:
51    test_pass_1::
52      "$(G.testdir)/first_update.txt"
53        create => "true",
54        edit_line => insert_lines($(last_update));
55    test_pass_2::
56      "$(G.testdir)/second_update.txt"
57        create => "true",
58        edit_line => insert_lines($(last_update));
59}
60
61bundle agent check
62{
63  methods:
64    !cache_exists::
65      "any" usebundle => dcs_fail($(this.promise_filename));
66
67    test_pass_1.cache_exists::
68      "any" usebundle => dcs_wait($(this.promise_filename), 70);
69
70    test_pass_2.cache_exists::
71      "any" usebundle => dcs_check_diff("$(G.testdir)/first_update.txt",
72                                        "$(G.testdir)/second_update.txt",
73                                        "$(this.promise_filename)");
74}
75body package_method inventory_apt_get(update_interval)
76# @depends debian_knowledge
77# @brief APT installation package method for inventory purposes only
78# @param update_interval how often to update the package and patch list
79#
80# This package method is a copy of the yum_rpm method just for
81# inventory purposes.
82#
83# This package method interacts with the APT package manager through
84# `apt-get`.  It will never run "apt-get update" but is otherwise
85# exactly like the `apt_get` package method and *may* use the network
86# to install packages, as APT may decide.
87{
88      package_changes => "bulk";
89      package_list_command => "$(debian_knowledge.call_dpkg) -l";
90      package_list_name_regex => "$(debian_knowledge.list_name_regex)";
91      package_list_version_regex => "$(debian_knowledge.list_version_regex)";
92      package_installed_regex => ".i.*"; # packages that have been uninstalled may be listed
93      package_name_convention => "$(name)=$(version)";
94
95      # set it to "0" to avoid caching of list during upgrade
96      package_list_update_ifelapsed => $(update_interval);
97
98      # Target a specific release, such as backports
99      package_add_command => "$(debian_knowledge.call_apt_get) --help >/dev/null 2>&1 ; /bin/true";
100      package_list_update_command => "$(debian_knowledge.call_apt_get) update";
101      package_delete_command => "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes -q remove";
102      package_update_command =>  "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes install";
103      package_patch_command =>  "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes install";
104      package_verify_command => "$(debian_knowledge.call_dpkg) -s";
105      package_noverify_returncode => "1";
106
107      package_patch_list_command => "$(debian_knowledge.call_apt_get) --just-print dist-upgrade";
108      package_patch_name_regex => "$(debian_knowledge.patch_name_regex)";
109      package_patch_version_regex => "$(debian_knowledge.patch_version_regex)";
110
111      # make correct version comparisons
112      package_version_less_command => "$(debian_knowledge.dpkg_compare_less)";
113      package_version_equal_command => "$(debian_knowledge.dpkg_compare_equal)";
114}
115
116body package_method inventory_yum_rpm(update_interval)
117# @depends common_knowledge redhat_knowledge rpm_knowledge
118# @brief Yum+RPM installation method for inventory purposes only
119# @param update_interval how often to update the package and patch list
120#
121# This package method is a copy of the yum_rpm method just for
122# inventory purposes.
123#
124# It will never run "yum update" but is otherwise exactly like the
125# `yum_rpm()` package method and *may* use the network to install
126# packages, as Yum may decide.
127{
128      package_changes => "bulk";
129      package_list_command => "$(rpm_knowledge.call_rpm) -qa --qf '$(rpm_knowledge.rpm3_output_format)'";
130      package_patch_list_command => "$(redhat_knowledge.call_yum) $(redhat_knowledge.yum_offline_options) check-update $(redhat_knowledge.check_update_postproc)";
131
132      package_list_name_regex    => "$(rpm_knowledge.rpm3_name_regex)";
133      package_list_version_regex => "$(rpm_knowledge.rpm3_version_regex)";
134      package_list_arch_regex    => "$(rpm_knowledge.rpm3_arch_regex)";
135
136      package_installed_regex => ".*";
137      package_name_convention => "$(name)-$(version).$(arch)";
138
139      # just give the package name to rpm to delete, otherwise it gets "name.*" (from package_name_convention above)
140      package_delete_convention => "$(name)";
141
142      # set it to "0" to avoid caching of list during upgrade
143      package_list_update_command => "$(redhat_knowledge.call_yum) $(redhat_knowledge.yum_options) check-update $(redhat_knowledge.check_update_postproc)";
144      package_list_update_ifelapsed => $(update_interval);
145
146      package_patch_name_regex    => "$(redhat_knowledge.patch_name_regex)";
147      package_patch_version_regex => "$(redhat_knowledge.patch_version_regex)";
148      package_patch_arch_regex    => "$(redhat_knowledge.patch_arch_regex)";
149
150      package_add_command    => "$(redhat_knowledge.call_yum) --help >/dev/null 2>&1 ; /bin/true";
151      package_update_command => "$(redhat_knowledge.call_yum) $(redhat_knowledge.yum_options) -y update";
152      package_patch_command  => "$(redhat_knowledge.call_yum) $(redhat_knowledge.yum_options) -y update";
153      package_delete_command => "$(rpm_knowledge.call_rpm) -e --nodeps";
154      package_verify_command => "$(rpm_knowledge.call_rpm) -V";
155}
156