(CONT-173) - Updating deprecated facter instances cont-173/main/updating_deprecated_facter
authorjordanbreen28 <jordan.breen@perforce.com>
Thu, 13 Oct 2022 12:10:57 +0000 (13:10 +0100)
committerjordanbreen28 <jordan.breen@perforce.com>
Fri, 14 Oct 2022 12:17:46 +0000 (13:17 +0100)
Prior to this PR, this module contained instances of Facter::Util::Resolution.exec and Facter::Util::Resolution.which, which are deprecated.
This PR aims to replace these exec helpers with their supported Facter::Core::Execution counterparts.

This PR:
- Replaced all Facter::Util::Resolution instances with corresponding Facter::Core::Execution exec helpers

Fix rubucop linting error

This commit corrects an error identified by rubocop in spec testing.

12 files changed:
lib/facter/apt_updates.rb
manifests/source.pp
spec/unit/facter/apt_dist_has_updates_spec.rb
spec/unit/facter/apt_dist_package_security_updates_spec.rb
spec/unit/facter/apt_dist_package_updates_spec.rb
spec/unit/facter/apt_dist_security_updates_spec.rb
spec/unit/facter/apt_dist_updates_spec.rb
spec/unit/facter/apt_has_updates_spec.rb
spec/unit/facter/apt_package_security_updates_spec.rb
spec/unit/facter/apt_package_updates_spec.rb
spec/unit/facter/apt_security_updates_spec.rb
spec/unit/facter/apt_updates_spec.rb

index e3b17d957e0a85a24f4f4782acf130de55a5d196..f261d2c16540a7bcc4e873c51dec618eafe92511 100644 (file)
@@ -9,7 +9,7 @@ apt_dist_updates = nil
 def get_updates(upgrade_option)
   apt_updates = nil
   if File.executable?('/usr/bin/apt-get')
-    apt_get_result = Facter::Util::Resolution.exec("/usr/bin/apt-get -s -o Debug::NoLocking=true #{upgrade_option} 2>&1")
+    apt_get_result = Facter::Core::Execution.execute("/usr/bin/apt-get -s -o Debug::NoLocking=true #{upgrade_option} 2>&1")
     unless apt_get_result.nil?
       apt_updates = [[], []]
       apt_get_result.each_line do |line|
index 8961e1564572123e9f0f8dfb20338ed98e4df401..b1be300a4539a4d5f879b90c89b277d6d3e4ea06 100644 (file)
@@ -142,7 +142,7 @@ define apt::source (
   $sourcelist = epp('apt/source.list.epp', {
       'comment'          => $comment,
       'includes'         => $includes,
-      'options'          => delete_undef_values( {
+      'options'          => delete_undef_values({
           'arch'              => $architecture,
           'trusted'           => $allow_unsigned ? { true => 'yes', false => undef },
           'allow-insecure'    => $allow_insecure ? { true => 'yes', false => undef },
index f6302416681ca943281ca65bc13992f79226354b..3ed4f3b213ed96a4f525239739ea7a8af9e2f2c3 100644 (file)
@@ -27,14 +27,14 @@ describe 'apt_has_dist_updates fact' do
     before(:each) do
       allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Debian')
       allow(File).to receive(:executable?) # Stub all other calls
-      allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+      allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls
       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
-      allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test')
+      allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test')
       apt_output = "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
                    "Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
                    "Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:stretch-backports [all])\n" \
                    "Conf planet.rb (22-2~bpo8+1 Debian Backports:stretch-backports [all])\n"
-      allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_output)
+      allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_output)
     end
     it { is_expected.to be true }
   end
index 2a5bfccb22474239900d285345a482541b22cb92..f16ff526577cc20472b797071951dbc178260d9a 100644 (file)
@@ -18,11 +18,11 @@ describe 'apt_package_security_dist_updates fact' do
     before(:each) do
       allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
       allow(File).to receive(:executable?) # Stub all other calls
-      allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+      allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls
       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
-      allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test')
+      allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test')
       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
-      allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_get_upgrade_output)
+      allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_get_upgrade_output)
     end
 
     describe 'on Debian' do
index 013c16dda72fa3d574160230bc9b371f2fbbdb2a..a27d607bab66c2d53283769c457c12cd8bcfd67c 100644 (file)
@@ -18,15 +18,15 @@ describe 'apt_package_dist_updates fact' do
     before(:each) do
       allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
       allow(File).to receive(:executable?) # Stub all other calls
-      allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+      allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls
       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
-      allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test')
+      allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test')
       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
       apt_output = "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
                    "Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
                    "Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:-backports [all])\n" \
                    "Conf planet.rb (22-2~bpo8+1 Debian Backports:-backports [all])\n"
-      allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_output)
+      allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_output)
     end
     it { is_expected.to eq(['extremetuxracer', 'planet.rb']) }
   end
index abeeccbcd878f7251ff8f65445239dbe50a20510..aa21e649c60581504494d572bc4ad3f9be6db055 100644 (file)
@@ -18,11 +18,11 @@ describe 'apt_security_updates fact' do
     before(:each) do
       allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
       allow(File).to receive(:executable?) # Stub all other calls
-      allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+      allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls
       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
-      allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test')
+      allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test')
       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
-      allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_get_upgrade_output)
+      allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_get_upgrade_output)
     end
 
     describe 'on Debian' do
index d8a2696054bb1ac88e1e55a8059c9e4ed76524a3..21352b5567406f3f8720caacd3f13d8e615c2ac3 100644 (file)
@@ -18,15 +18,15 @@ describe 'apt_updates fact' do
     before(:each) do
       allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
       allow(File).to receive(:executable?) # Stub all other calls
-      allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+      allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls
       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
-      allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test')
+      allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return('test')
       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
       apt_output = "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
                    "Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
                    "Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:-backports [all])\n" \
                    "Conf planet.rb (22-2~bpo8+1 Debian Backports:-backports [all])\n"
-      allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_output)
+      allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').and_return(apt_output)
     end
     it { is_expected.to eq(2) }
   end
index d0813c8b4ec9495976d16b836c1e70902af5a269..0f0a74094c8a4f8697d1d3787259c9d1f3742008 100644 (file)
@@ -27,13 +27,13 @@ describe 'apt_has_updates fact' do
     before(:each) do
       allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
       allow(File).to receive(:executable?) # Stub all other calls
-      allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+      allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls
       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
       apt_output = "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
                    "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
                    "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:-backports [all])\n" \
                    "Conf unhide.rb (22-2~bpo8+1 Debian Backports:-backports [all])\n"
-      allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_output)
+      allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_output)
     end
     it { is_expected.to be true }
   end
index d9d4643ca7baacc90e0b1acd1700859ce141998b..28516cac48ea56eae60dec97ea6902194da1874b 100644 (file)
@@ -18,9 +18,9 @@ describe 'apt_package_security_updates fact' do
     before(:each) do
       allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
       allow(File).to receive(:executable?) # Stub all other calls
-      allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+      allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls
       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
-      allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_get_upgrade_output)
+      allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_get_upgrade_output)
     end
 
     describe 'on Debian' do
index d32339fea85204e2ff3981c46e1891469939d5b4..69db490dd60afb0fd787de347d0a3b5479ea0895 100644 (file)
@@ -18,13 +18,13 @@ describe 'apt_package_updates fact' do
     before(:each) do
       allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
       allow(File).to receive(:executable?) # Stub all other calls
-      allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+      allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls
       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
       apt_output = "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
                    "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
                    "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:-backports [all])\n" \
                    "Conf unhide.rb (22-2~bpo8+1 Debian Backports:-backports [all])\n"
-      allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_output)
+      allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_output)
     end
     it { is_expected.to eq(['tzdata', 'unhide.rb']) }
   end
index 4baeb810e53a732d7d6469545cbba424c9d484dc..9d3e587a89585982f9a9f6dc5002122406575d12 100644 (file)
@@ -18,9 +18,9 @@ describe 'apt_security_updates fact' do
     before(:each) do
       allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
       allow(File).to receive(:executable?) # Stub all other calls
-      allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+      allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls
       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
-      allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_get_upgrade_output)
+      allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_get_upgrade_output)
     end
 
     describe 'on Debian' do
index 280c6af8e90cf2d9ed46e480ead1dc4e8936e9bb..a8eacbf20bcf7e8e937d4e562f2fedc736c78369 100644 (file)
@@ -18,13 +18,13 @@ describe 'apt_updates fact' do
     before(:each) do
       allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian')
       allow(File).to receive(:executable?) # Stub all other calls
-      allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
+      allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls
       allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true)
       apt_output = "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
                    "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \
                    "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:-backports [all])\n" \
                    "Conf unhide.rb (22-2~bpo8+1 Debian Backports:-backports [all])\n"
-      allow(Facter::Util::Resolution).to receive(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_output)
+      allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').and_return(apt_output)
     end
     it { is_expected.to eq(2) }
   end