From 86f654a13baec042b6d249c3f6fb875a00351f98 Mon Sep 17 00:00:00 2001 From: "justin.cattle" Date: Tue, 22 Nov 2016 17:34:01 +0000 Subject: [PATCH] (MODULES-4118) Set dpkg option NoLocking in apt_updates fact Although the man page for apt-get indicates the --simluate means locking will be disabled, testing indicates it isn't. Indeed, regulary collecting facts causes it to clash with the apt_update Exec occasionally, resulting in failures to lock /var/lib/dpkg Spefically setting the NoLocking option fixes the issue. --- lib/facter/apt_updates.rb | 2 +- spec/unit/facter/apt_has_updates_spec.rb | 2 +- spec/unit/facter/apt_package_updates_spec.rb | 2 +- spec/unit/facter/apt_security_updates_spec.rb | 2 +- spec/unit/facter/apt_updates_spec.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/facter/apt_updates.rb b/lib/facter/apt_updates.rb index e880fdf..b355f5b 100644 --- a/lib/facter/apt_updates.rb +++ b/lib/facter/apt_updates.rb @@ -2,7 +2,7 @@ apt_package_updates = nil Facter.add("apt_has_updates") do confine :osfamily => 'Debian' if File.executable?("/usr/bin/apt-get") - apt_get_result = Facter::Util::Resolution.exec('/usr/bin/apt-get -s upgrade 2>&1') + apt_get_result = Facter::Util::Resolution.exec('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1') if not apt_get_result.nil? apt_package_updates = [[], []] apt_get_result.each_line do |line| diff --git a/spec/unit/facter/apt_has_updates_spec.rb b/spec/unit/facter/apt_has_updates_spec.rb index bcd6bb5..d030e0f 100644 --- a/spec/unit/facter/apt_has_updates_spec.rb +++ b/spec/unit/facter/apt_has_updates_spec.rb @@ -26,7 +26,7 @@ describe 'apt_has_updates fact' do File.stubs(:executable?) # Stub all other calls Facter::Util::Resolution.stubs(:exec) # Catch all other calls File.expects(:executable?).with('/usr/bin/apt-get').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s upgrade 2>&1').returns ""+ + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns ""+ "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:jessie-backports [all])\n"+ diff --git a/spec/unit/facter/apt_package_updates_spec.rb b/spec/unit/facter/apt_package_updates_spec.rb index d7587ca..49cecee 100644 --- a/spec/unit/facter/apt_package_updates_spec.rb +++ b/spec/unit/facter/apt_package_updates_spec.rb @@ -17,7 +17,7 @@ describe 'apt_package_updates fact' do File.stubs(:executable?) # Stub all other calls Facter::Util::Resolution.stubs(:exec) # Catch all other calls File.expects(:executable?).with('/usr/bin/apt-get').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s upgrade 2>&1').returns ""+ + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns ""+ "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:jessie-backports [all])\n"+ diff --git a/spec/unit/facter/apt_security_updates_spec.rb b/spec/unit/facter/apt_security_updates_spec.rb index 174b60d..f0dcab2 100644 --- a/spec/unit/facter/apt_security_updates_spec.rb +++ b/spec/unit/facter/apt_security_updates_spec.rb @@ -17,7 +17,7 @@ describe 'apt_security_updates fact' do File.stubs(:executable?) # Stub all other calls Facter::Util::Resolution.stubs(:exec) # Catch all other calls File.expects(:executable?).with('/usr/bin/apt-get').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s upgrade 2>&1').returns ""+ + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns ""+ "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:jessie-backports [all])\n"+ diff --git a/spec/unit/facter/apt_updates_spec.rb b/spec/unit/facter/apt_updates_spec.rb index 8c726fc..d2c2bf2 100644 --- a/spec/unit/facter/apt_updates_spec.rb +++ b/spec/unit/facter/apt_updates_spec.rb @@ -17,7 +17,7 @@ describe 'apt_updates fact' do File.stubs(:executable?) # Stub all other calls Facter::Util::Resolution.stubs(:exec) # Catch all other calls File.expects(:executable?).with('/usr/bin/apt-get').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s upgrade 2>&1').returns ""+ + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns ""+ "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:jessie-backports [all])\n"+ -- 2.32.3