2019-10-18 17:36:00 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-01-22 20:57:31 +01:00
|
|
|
# Prepare platform "finger"
|
|
|
|
platform_finger = system.platform[:finger].split('.').first.to_s
|
|
|
|
|
2018-03-02 20:33:31 -03:00
|
|
|
## Some vars
|
2019-10-18 17:36:00 +01:00
|
|
|
common_packages = %w[
|
2018-02-12 08:16:03 -03:00
|
|
|
git
|
|
|
|
less
|
|
|
|
bc
|
|
|
|
curl
|
|
|
|
fail2ban
|
2019-10-18 17:36:00 +01:00
|
|
|
]
|
2018-03-02 20:33:31 -03:00
|
|
|
|
2019-10-03 22:35:30 +01:00
|
|
|
case platform[:family]
|
|
|
|
when 'redhat'
|
2019-12-07 03:26:54 +00:00
|
|
|
platform_packages =
|
2021-01-22 20:57:31 +01:00
|
|
|
case platform_finger
|
2021-07-01 08:32:43 +01:00
|
|
|
when 'centos-8', 'oraclelinux-8', 'almalinux-8', 'rockylinux-8'
|
2021-01-22 20:57:31 +01:00
|
|
|
%w[python3-dnf-plugin-versionlock]
|
2019-12-07 03:26:54 +00:00
|
|
|
else
|
|
|
|
%w[yum-plugin-versionlock]
|
|
|
|
end
|
2018-03-02 20:33:31 -03:00
|
|
|
held_packages = {
|
2018-03-06 18:27:16 -03:00
|
|
|
# We use this test for held packages in a list,
|
|
|
|
# with no version (current version).
|
2021-03-26 11:29:53 +00:00
|
|
|
iotop: ''
|
2018-03-02 20:33:31 -03:00
|
|
|
}
|
|
|
|
lock_file = '/etc/yum/pluginconf.d/versionlock.list'
|
|
|
|
when 'fedora'
|
2019-12-07 03:26:54 +00:00
|
|
|
platform_packages = ['python3-dnf-plugin-versionlock']
|
2018-03-02 20:33:31 -03:00
|
|
|
held_packages = {
|
2021-03-26 11:29:53 +00:00
|
|
|
alien: '8.95-8.fc29',
|
|
|
|
iotop: '0.6-18.fc29'
|
2018-03-02 20:33:31 -03:00
|
|
|
}
|
|
|
|
lock_file = '/etc/dnf/plugins/versionlock.list'
|
2019-03-06 09:41:23 -03:00
|
|
|
# Adding empty Suse entries, to get tests passing
|
|
|
|
# Don't know the correct values to add here.
|
2019-10-03 22:35:30 +01:00
|
|
|
when 'suse'
|
2019-10-18 17:36:00 +01:00
|
|
|
platform_packages = %w[]
|
2019-03-06 09:41:23 -03:00
|
|
|
held_packages = {}
|
|
|
|
lock_file = ''
|
2019-10-03 22:35:30 +01:00
|
|
|
when 'debian'
|
2019-10-18 17:36:00 +01:00
|
|
|
platform_packages = %w[]
|
2018-03-02 20:33:31 -03:00
|
|
|
held_packages = {
|
2021-03-26 11:29:53 +00:00
|
|
|
alien: '8.95',
|
2019-03-05 23:19:24 -03:00
|
|
|
# To match also ubuntu16's
|
2021-03-26 11:29:53 +00:00
|
|
|
iotop: '0.6-'
|
2018-03-02 20:33:31 -03:00
|
|
|
}
|
|
|
|
lock_file = '/var/lib/dpkg/status'
|
2019-12-08 03:23:49 +00:00
|
|
|
when 'linux'
|
|
|
|
case platform[:name]
|
|
|
|
when 'arch'
|
|
|
|
platform_packages = %w[ruby]
|
|
|
|
held_packages = {}
|
|
|
|
lock_file = ''
|
2021-02-10 14:56:43 +00:00
|
|
|
when 'gentoo'
|
|
|
|
# Empty for now: The `package` resource is not supported on your OS yet.
|
|
|
|
platform_packages = %w[]
|
|
|
|
held_packages = {}
|
|
|
|
lock_file = ''
|
2019-12-08 03:23:49 +00:00
|
|
|
end
|
2018-03-02 20:33:31 -03:00
|
|
|
end
|
|
|
|
|
2019-12-07 03:33:51 +00:00
|
|
|
# FIXME: - not testing Held packages
|
2019-08-13 19:16:06 +02:00
|
|
|
held_packages = {}
|
|
|
|
|
2019-10-03 22:35:30 +01:00
|
|
|
unheld_packages = (common_packages + platform_packages).flatten.uniq
|
2019-10-18 17:36:00 +01:00
|
|
|
all_packages = (unheld_packages + held_packages.keys.map(&:to_s)).flatten.uniq
|
2018-03-02 20:33:31 -03:00
|
|
|
|
|
|
|
### WANTED/REQUIRED/HELD
|
|
|
|
control 'Wanted/Required/Held packages' do
|
|
|
|
title 'should be installed'
|
|
|
|
|
|
|
|
all_packages.each do |p|
|
|
|
|
describe package(p) do
|
|
|
|
it { should be_installed }
|
|
|
|
end
|
2018-02-12 08:16:03 -03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-02 20:33:31 -03:00
|
|
|
### WANTED UNHELD
|
|
|
|
control 'Wanted packages' do
|
|
|
|
title 'should NOT be marked as hold'
|
|
|
|
|
2019-10-18 17:36:00 +01:00
|
|
|
unheld_packages.each do |p, v|
|
2019-10-03 22:35:30 +01:00
|
|
|
case platform[:family]
|
|
|
|
when 'redhat', 'fedora'
|
2018-03-02 20:33:31 -03:00
|
|
|
match_string = "#{p}-.*#{v}"
|
|
|
|
describe file(lock_file) do
|
|
|
|
its('content') { should_not match(match_string) }
|
|
|
|
end
|
2019-10-03 22:35:30 +01:00
|
|
|
when 'debian'
|
2018-03-02 20:33:31 -03:00
|
|
|
match_string = "^Package: #{p}\nStatus: install ok installed"
|
|
|
|
describe file(lock_file) do
|
|
|
|
its('content') { should match(match_string) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
### HELD
|
|
|
|
control 'Held packages' do
|
|
|
|
title 'should be marked as hold'
|
|
|
|
|
2019-10-18 17:36:00 +01:00
|
|
|
held_packages.each do |p, v|
|
2019-10-03 22:35:30 +01:00
|
|
|
case platform[:family]
|
|
|
|
when 'redhat', 'fedora'
|
2018-03-02 20:33:31 -03:00
|
|
|
match_string = "#{p}-.*#{v}"
|
2019-10-03 22:35:30 +01:00
|
|
|
when 'debian'
|
2019-12-07 03:33:51 +00:00
|
|
|
match_string = "^Package: #{p}\nStatus: hold ok "\
|
2021-10-02 10:09:13 +01:00
|
|
|
"installed\nP.*\nS.*\nI.*\nM.*\nA.*\nVersion: #{v}"
|
2018-03-02 20:33:31 -03:00
|
|
|
end
|
2019-10-18 17:36:00 +01:00
|
|
|
|
2018-03-02 20:33:31 -03:00
|
|
|
describe file(lock_file) do
|
|
|
|
its('content') { should match(match_string) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-10-18 17:36:00 +01:00
|
|
|
|
2018-03-02 20:33:31 -03:00
|
|
|
### UNWANTED
|
|
|
|
control 'Unwanted packages' do
|
|
|
|
title 'should be uninstalled'
|
2019-10-18 17:36:00 +01:00
|
|
|
%w[
|
2018-03-02 20:33:31 -03:00
|
|
|
avahi-daemon
|
2019-10-18 17:36:00 +01:00
|
|
|
].each do |p|
|
2018-03-02 20:33:31 -03:00
|
|
|
describe package(p) do
|
|
|
|
it { should_not be_installed }
|
|
|
|
end
|
2018-02-12 08:16:03 -03:00
|
|
|
end
|
|
|
|
end
|