From 493d420b14ca766ba7de4801e1a981798515123e Mon Sep 17 00:00:00 2001 From: Yury Bushmelev Date: Thu, 12 Dec 2024 18:27:32 +0800 Subject: [PATCH] Drop unsupported OSes from unit tests --- spec/acceptance/define_group_spec.rb | 26 +-- spec/acceptance/define_versionlock_spec.rb | 86 +++------ spec/classes/init_spec.rb | 199 --------------------- spec/defines/plugin_spec.rb | 2 +- spec/defines/versionlock_spec.rb | 18 +- 5 files changed, 31 insertions(+), 300 deletions(-) diff --git a/spec/acceptance/define_group_spec.rb b/spec/acceptance/define_group_spec.rb index e22996dd..156555e4 100644 --- a/spec/acceptance/define_group_spec.rb +++ b/spec/acceptance/define_group_spec.rb @@ -17,20 +17,9 @@ apply_manifest(pp, catch_changes: true) end - # On stupid 7 test package has to be leaf package - # to be removed with a "groupremove". Can't find - # a common package that works. - case fact('os.release.major') - when '7' - describe package('libtool') do - it { is_expected.to be_installed } - end - else - describe package('make') do - it { is_expected.to be_installed } - end + describe package('make') do + it { is_expected.to be_installed } end - end context 'removing group RPM dev tools' do # Using puppet_apply as a helper @@ -46,15 +35,8 @@ apply_manifest(pp, catch_changes: true) end - case fact('os.release.major') - when '7' - describe package('libtool') do - it { is_expected.not_to be_installed } - end - else - describe package('make') do - it { is_expected.not_to be_installed } - end + describe package('make') do + it { is_expected.not_to be_installed } end end end diff --git a/spec/acceptance/define_versionlock_spec.rb b/spec/acceptance/define_versionlock_spec.rb index 6039929a..5108ac13 100644 --- a/spec/acceptance/define_versionlock_spec.rb +++ b/spec/acceptance/define_versionlock_spec.rb @@ -7,26 +7,17 @@ # Using puppet_apply as a helper it 'must work idempotently with no errors' do pp = <<-EOS - if versioncmp($facts['os']['release']['major'],'7') <= 0 { - yum::versionlock{ '0:bash-4.1.2-9.el6_2.*': - ensure => present, - } - yum::versionlock{ '0:tcsh-3.1.2-9.el6_2.*': - ensure => present, - } - } else { - yum::versionlock{ 'bash': - ensure => present, - version => '4.1.2', - release => '9.el6_2', - } - yum::versionlock{ 'tcsh': - ensure => present, - version => '3.1.2', - release => '9.el6_2', - arch => '*', - epoch => 0, - } + yum::versionlock{ 'bash': + ensure => present, + version => '4.1.2', + release => '9.el6_2', + } + yum::versionlock{ 'tcsh': + ensure => present, + version => '3.1.2', + release => '9.el6_2', + arch => '*', + epoch => 0, } # Lock a package with new style on all OSes @@ -44,31 +35,16 @@ apply_manifest(pp, catch_changes: true) end - if fact('os.release.major') == '7' - describe file('/etc/yum/pluginconf.d/versionlock.list') do - it { is_expected.to be_file } - it { is_expected.to contain '0:bash-4.1.2-9.el6_2.*' } - it { is_expected.to contain '0:tcsh-3.1.2-9.el6_2.*' } - it { is_expected.to contain '2:netscape-8.1.2-9.el6_2.*' } - end - else - describe file('/etc/dnf/plugins/versionlock.list') do - it { is_expected.to be_file } + describe file('/etc/dnf/plugins/versionlock.list') do + it { is_expected.to be_file } - it { is_expected.to contain 'bash-0:4.1.2-9.el6_2.*' } - it { is_expected.to contain 'tcsh-0:3.1.2-9.el6_2.*' } - it { is_expected.to contain 'netscape-2:8.1.2-9.el6_2.*' } - end + it { is_expected.to contain 'bash-0:4.1.2-9.el6_2.*' } + it { is_expected.to contain 'tcsh-0:3.1.2-9.el6_2.*' } + it { is_expected.to contain 'netscape-2:8.1.2-9.el6_2.*' } end - if fact('os.release.major') == '7' - describe package('yum-plugin-versionlock') do - it { is_expected.to be_installed } - end - else - describe package('python3-dnf-plugin-versionlock') do - it { is_expected.to be_installed } - end + describe package('python3-dnf-plugin-versionlock') do + it { is_expected.to be_installed } end end @@ -79,32 +55,16 @@ clean => true, } # Pick an obscure package that hopefully will not be installed. - if versioncmp($facts['os']['release']['major'],'7') <= 0 { - yum::versionlock{ '0:samba-devel-3.1.2-9.el6_2.*': - ensure => present, - } - } else { - yum::versionlock{'samba-devel': - ensure => present, - version => '3.1.2', - release => '9.el6_2', - } + yum::versionlock{'samba-devel': + ensure => present, + version => '3.1.2', + release => '9.el6_2', } EOS # Run it twice and test for idempotency apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) - # Check the cache is really empty. - # all repos will have 0 packages. - # bit confused by the motivation of the first test? - if fact('os.release.major') == '7' - shell('yum -C repolist -d0 | grep -v "repo id" | awk "{print $NF}" FS= | grep -v 0', acceptable_exit_codes: [1]) - shell('yum -q list available samba-devel', acceptable_exit_codes: [1]) - elsif %w[8 9].include?(fact('os.release.major')) - shell('dnf -q list --available samba-devel', acceptable_exit_codes: [1]) - else - shell('dnf install -y samba-devel | grep "All matches were filtered"', acceptable_exit_codes: [0]) - end + shell('dnf -q list --available samba-devel', acceptable_exit_codes: [1]) end end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 6357578c..f4611e71 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -151,56 +151,9 @@ updates-source centos-media ] - when '7' - it_behaves_like 'a catalog containing repos', %w[ - base - updates - cr - base-source - updates-source - centos-media - extras - centosplus - fasttrack - extras-source - base-debuginfo - ] - it_behaves_like 'a catalog not containing repos', %w[ - contrib - AppStream - BaseOS - Devel - HA - PowerTools - BaseOS-source - Appstream-source - c8-media-BaseOS - c8-media-AppStream - ] else it { is_expected.to have_yumrepo_resource_count(4) } end - when 'Amazon' - it { is_expected.to have_yumrepo_resource_count(16) } # rubocop:disable RSpec/RepeatedExample - - it_behaves_like 'a catalog containing repos', %w[ - amzn-main - amzn-main-debuginfo - amzn-main-source - amzn-nosrc - amzn-preview - amzn-preview-debuginfo - amzn-preview-source - amzn-updates - amzn-updates-debuginfo - amzn-updates-source - epel - epel-debuginfo - epel-source - epel-testing - epel-testing-debuginfo - epel-testing-source - ] when 'RedHat' it { is_expected.to have_yumrepo_resource_count(18) } @@ -224,47 +177,6 @@ rhui-REGION-rhel-server-debug-supplementary rhui-REGION-rhel-server-source-supplementary ] - when 'VirtuozzoLinux' - case facts[:os]['release']['major'] - when '6' - it { is_expected.to have_yumrepo_resource_count(12) } - - it_behaves_like 'a catalog containing repos', %w[ - virtuozzolinux-base - virtuozzolinux-updates - virtuozzolinux-base-debuginfo - virtuozzolinux-updates-debuginfo - virtuozzolinux-factory - virtuozzolinux-factory-debuginfo - virtuozzo-os - virtuozzo-updates - virtuozzo-os-debuginfo - virtuozzo-updates-debuginfo - virtuozzo-readykernel - obsoleted_tmpls - ] - when '7' - it { is_expected.to have_yumrepo_resource_count(16) } # rubocop:disable RSpec/RepeatedExample - - it_behaves_like 'a catalog containing repos', %w[ - virtuozzolinux-base - virtuozzolinux-updates - virtuozzolinux-base-debuginfo - virtuozzolinux-updates-debuginfo - virtuozzolinux-factory - virtuozzolinux-factory-debuginfo - virtuozzo-os - virtuozzo-updates - virtuozzo-os-debuginfo - virtuozzo-updates-debuginfo - virtuozzo-readykernel - obsoleted_tmpls - factory - factory-debuginfo - virtuozzolinux-vz-factory - virtuozzolinux-vz-factory-debuginfo - ] - end when 'AlmaLinux' case facts[:os]['release']['major'] when '8' @@ -357,73 +269,7 @@ extras-common extras-common-source ] - when '8' - it_behaves_like 'a catalog containing repos', %w[ - AppStream - cr - Devel - fasttrack - HA - PowerTools - BaseOS-source - Appstream-source - c8-media-BaseOS - c8-media-AppStream - extras - centosplus - extras-source - base-debuginfo - ] - when '7' - it_behaves_like 'a catalog containing repos', %w[ - cr - updates - extras - base-source - updates-source - extras-source - base-debuginfo - centosplus - centos-media - extras - centosplus - extras-source - base-debuginfo - ] - when '6' - it_behaves_like 'a catalog containing repos', %w[ - contrib - updates - extras - base-source - updates-source - extras-source - base-debuginfo - centosplus - centos-media - ] end - when 'Amazon' - it { is_expected.to have_yumrepo_resource_count(16) } # rubocop:disable RSpec/RepeatedExample - - it_behaves_like 'a catalog containing repos', %w[ - amzn-main - amzn-main-debuginfo - amzn-main-source - amzn-nosrc - amzn-preview - amzn-preview-debuginfo - amzn-preview-source - amzn-updates - amzn-updates-debuginfo - amzn-updates-source - epel - epel-debuginfo - epel-source - epel-testing - epel-testing-debuginfo - epel-testing-source - ] when 'RedHat' it { is_expected.to have_yumrepo_resource_count(18) } @@ -447,47 +293,6 @@ rhui-REGION-rhel-server-debug-supplementary rhui-REGION-rhel-server-source-supplementary ] - when 'VirtuozzoLinux' - case facts[:os]['release']['major'] - when '6' - it { is_expected.to have_yumrepo_resource_count(12) } - - it_behaves_like 'a catalog containing repos', %w[ - virtuozzolinux-base - virtuozzolinux-updates - virtuozzolinux-base-debuginfo - virtuozzolinux-updates-debuginfo - virtuozzolinux-factory - virtuozzolinux-factory-debuginfo - virtuozzo-os - virtuozzo-updates - virtuozzo-os-debuginfo - virtuozzo-updates-debuginfo - virtuozzo-readykernel - obsoleted_tmpls - ] - when '7' - it { is_expected.to have_yumrepo_resource_count(16) } # rubocop:disable RSpec/RepeatedExample - - it_behaves_like 'a catalog containing repos', %w[ - virtuozzolinux-base - virtuozzolinux-updates - virtuozzolinux-base-debuginfo - virtuozzolinux-updates-debuginfo - virtuozzolinux-factory - virtuozzolinux-factory-debuginfo - virtuozzo-os - virtuozzo-updates - virtuozzo-os-debuginfo - virtuozzo-updates-debuginfo - virtuozzo-readykernel - obsoleted_tmpls - factory - factory-debuginfo - virtuozzolinux-vz-factory - virtuozzolinux-vz-factory-debuginfo - ] - end when 'AlmaLinux' case facts[:os]['release']['major'] when '8' @@ -729,10 +534,6 @@ it { is_expected.to contain_yum__gpgkey('/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-9') } when '8' it { is_expected.to contain_yum__gpgkey('/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8') } - when '7' - it { is_expected.to contain_yum__gpgkey('/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7') } - when '6' - it { is_expected.to contain_yum__gpgkey('/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6') } end end diff --git a/spec/defines/plugin_spec.rb b/spec/defines/plugin_spec.rb index b41617f3..2928528c 100644 --- a/spec/defines/plugin_spec.rb +++ b/spec/defines/plugin_spec.rb @@ -6,7 +6,7 @@ on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) { facts } - let(:prefix) { facts[:os]['release']['major'] == '5' ? 'yum' : 'yum-plugin' } + let(:prefix) { 'yum-plugin' } context 'with no parameters' do let(:title) { 'fastestmirror' } diff --git a/spec/defines/versionlock_spec.rb b/spec/defines/versionlock_spec.rb index f024c662..11d4c692 100644 --- a/spec/defines/versionlock_spec.rb +++ b/spec/defines/versionlock_spec.rb @@ -4,10 +4,7 @@ describe 'yum::versionlock' do context 'with package_provider set to yum' do - let(:facts) do - { os: { release: { major: 7 } }, - package_provider: 'yum' } - end + let(:facts) { { package_provider: 'yum' } } context 'with a simple, well-formed title 0:bash-4.1.2-9.el6_2.x86_64' do let(:title) { '0:bash-4.1.2-9.el6_2.x86_64' } @@ -101,10 +98,7 @@ end context 'with a simple, well-formed package name title bash and a version' do - let(:facts) do - { os: { release: { major: 7 } }, - package_provider: 'yum' } - end + let(:facts) { { package_provider: 'yum' } } let(:title) { 'bash' } let(:params) { { version: '4.3' } } @@ -138,10 +132,7 @@ end context 'with package_provider set to dnf' do - let(:facts) do - { os: { release: { major: 8 } }, - package_provider: 'dnf' } - end + let(:facts) { { package_provider: 'dnf' } } context 'with a simple, well-formed title, no version set' do let(:title) { 'bash' } @@ -198,9 +189,6 @@ end context 'with package_provider unset' do - let(:facts) do - { os: { release: { major: 7 } } } - end let(:title) { 'bash' } let(:params) { { version: '4.3' } }