From: TP Honey Date: Tue, 12 Apr 2016 09:46:39 +0000 (+0100) Subject: Merge pull request #596 from danielhoherd/master X-Git-Tag: 2.3.0~20 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=015009d5530576136e5a5432e672125da0881d39;hp=91092bdc80f5b46bfd38ad4cd53bb5f6bf096e3c;p=puppet-modules%2Fpuppetlabs-apt.git Merge pull request #596 from danielhoherd/master Expose notify_update to apt::source --- diff --git a/README.md b/README.md index 6ea11d7..49266cc 100644 --- a/README.md +++ b/README.md @@ -425,7 +425,7 @@ Manages PPA repositories using `add-apt-repository`. Not supported on Debian. * `release`: *Optional if lsb-release is installed (unless you're using a different release than indicated by lsb-release, e.g., Linux Mint).* Specifies the operating system of your node. Valid options: a string containing a valid LSB distribution codename. Default: "$lsbdistcodename". -#### Defined Type: `apt:setting` +#### Defined Type: `apt::setting` Manages Apt configuration files. diff --git a/lib/facter/apt_updates.rb b/lib/facter/apt_updates.rb index 014782e..e880fdf 100644 --- a/lib/facter/apt_updates.rb +++ b/lib/facter/apt_updates.rb @@ -1,16 +1,32 @@ apt_package_updates = nil Facter.add("apt_has_updates") do confine :osfamily => 'Debian' - if File.executable?("/usr/lib/update-notifier/apt-check") - apt_check_result = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check 2>&1') - if not apt_check_result.nil? and apt_check_result =~ /^\d+;\d+$/ - apt_package_updates = apt_check_result.split(';') + if File.executable?("/usr/bin/apt-get") + apt_get_result = Facter::Util::Resolution.exec('/usr/bin/apt-get -s upgrade 2>&1') + if not apt_get_result.nil? + apt_package_updates = [[], []] + apt_get_result.each_line do |line| + if line =~ /^Inst\s/ + package = line.gsub(/^Inst\s([^\s]+)\s.*/, '\1').strip + apt_package_updates[0].push(package) + security_matches = [ + / Debian[^\s]+-updates /, + / Debian-Security:/, + / Ubuntu[^\s]+-security /, + / gNewSense[^\s]+-security / + ] + re = Regexp.union(security_matches) + if line.match(re) + apt_package_updates[1].push(package) + end + end + end end end setcode do if not apt_package_updates.nil? and apt_package_updates.length == 2 - apt_package_updates != ['0', '0'] + apt_package_updates != [[], []] end end end @@ -18,11 +34,10 @@ end Facter.add("apt_package_updates") do confine :apt_has_updates => true setcode do - packages = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check -p 2>&1').split("\n") if Facter.version < '2.0.0' - packages.join(',') + apt_package_updates[0].join(',') else - packages + apt_package_updates[0] end end end @@ -30,13 +45,13 @@ end Facter.add("apt_updates") do confine :apt_has_updates => true setcode do - Integer(apt_package_updates[0]) + Integer(apt_package_updates[0].length) end end Facter.add("apt_security_updates") do confine :apt_has_updates => true setcode do - Integer(apt_package_updates[1]) + Integer(apt_package_updates[1].length) end end diff --git a/spec/defines/key_compat_spec.rb b/spec/defines/key_compat_spec.rb index 872bcad..2faee9e 100644 --- a/spec/defines/key_compat_spec.rb +++ b/spec/defines/key_compat_spec.rb @@ -1,27 +1,34 @@ require 'spec_helper' describe 'apt::key', :type => :define do - let(:facts) { { :lsbdistid => 'Debian' } } + let(:facts) { { + :lsbdistid => 'Debian', + :osfamily => 'Debian', + } } GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30' let :title do GPG_KEY_ID end + let :pre_condition do + 'include apt' + end + describe 'normal operation' do describe 'default options' do - it 'contains the apt_key' do - should contain_apt_key(title).with({ + it { + is_expected.to contain_apt_key(title).with({ :id => title, :ensure => 'present', :source => nil, - :server => nil, + :server => 'keyserver.ubuntu.com', :content => nil, :keyserver_options => nil, }) - end + } it 'contains the apt_key present anchor' do - should contain_anchor("apt_key #{title} present") + is_expected.to contain_anchor("apt_key #{title} present") end end @@ -35,17 +42,17 @@ describe 'apt::key', :type => :define do } end it 'contains the apt_key' do - should contain_apt_key(title).with({ + is_expected.to contain_apt_key(title).with({ :id => GPG_KEY_ID, :ensure => 'present', :source => nil, - :server => nil, + :server => 'keyserver.ubuntu.com', :content => nil, :keyserver_options => nil, }) end it 'contains the apt_key present anchor' do - should contain_anchor("apt_key #{GPG_KEY_ID} present") + is_expected.to contain_anchor("apt_key #{GPG_KEY_ID} present") end end @@ -55,17 +62,17 @@ describe 'apt::key', :type => :define do } end it 'contains the apt_key' do - should contain_apt_key(title).with({ + is_expected.to contain_apt_key(title).with({ :id => title, :ensure => 'absent', :source => nil, - :server => nil, + :server => 'keyserver.ubuntu.com', :content => nil, :keyserver_options => nil, }) end it 'contains the apt_key absent anchor' do - should contain_anchor("apt_key #{title} absent") + is_expected.to contain_anchor("apt_key #{title} absent") end end @@ -78,7 +85,7 @@ describe 'apt::key', :type => :define do } end it 'contains the apt_key' do - should contain_apt_key(title).with({ + is_expected.to contain_apt_key(title).with({ :id => title, :ensure => 'present', :source => 'http://apt.puppetlabs.com/pubkey.gpg', @@ -88,7 +95,7 @@ describe 'apt::key', :type => :define do }) end it 'contains the apt_key present anchor' do - should contain_anchor("apt_key #{title} present") + is_expected.to contain_anchor("apt_key #{title} present") end end @@ -97,7 +104,7 @@ describe 'apt::key', :type => :define do :key_server => 'p-gp.m-it.edu', } end it 'contains the apt_key' do - should contain_apt_key(title).with({ + is_expected.to contain_apt_key(title).with({ :id => title, :server => 'p-gp.m-it.edu', }) @@ -111,7 +118,7 @@ describe 'apt::key', :type => :define do } end it 'contains the apt_key' do - should contain_apt_key(title).with({ + is_expected.to contain_apt_key(title).with({ :id => title, :server => 'hkp://pgp.mit.edu', }) @@ -124,7 +131,7 @@ describe 'apt::key', :type => :define do } end it 'contains the apt_key' do - should contain_apt_key(title).with({ + is_expected.to contain_apt_key(title).with({ :id => title, :server => 'hkp://pgp.mit.edu:80', }) @@ -276,36 +283,42 @@ describe 'apt::key', :type => :define do describe 'duplication' do context 'two apt::key resources for same key, different titles' do let :pre_condition do - "apt::key { 'duplicate': key => '#{title}', }" + "#{super()}\napt::key { 'duplicate': key => '#{title}', }" end - it 'contains two apt::key resources' do - should contain_apt__key('duplicate').with({ + it 'contains the duplicate apt::key resource' do + is_expected.to contain_apt__key('duplicate').with({ :key => title, :ensure => 'present', }) - should contain_apt__key(title).with({ + end + + it 'contains the original apt::key resource' do + is_expected.to contain_apt__key(title).with({ :id => title, :ensure => 'present', }) end - it 'contains only a single apt_key' do - should contain_apt_key('duplicate').with({ + it 'contains the native apt_key' do + is_expected.to contain_apt_key('duplicate').with({ :id => title, :ensure => 'present', :source => nil, - :server => nil, + :server => 'keyserver.ubuntu.com', :content => nil, :keyserver_options => nil, }) - should_not contain_apt_key(title) + end + + it 'does not contain the original apt_key' do + is_expected.not_to contain_apt_key(title) end end context 'two apt::key resources, different ensure' do let :pre_condition do - "apt::key { 'duplicate': key => '#{title}', ensure => 'absent', }" + "#{super()}\napt::key { 'duplicate': key => '#{title}', ensure => 'absent', }" end it 'informs the user of the impossibility' do expect { subject.call }.to raise_error(/already ensured as absent/) diff --git a/spec/unit/facter/apt_has_updates_spec.rb b/spec/unit/facter/apt_has_updates_spec.rb index b6eee26..bcd6bb5 100644 --- a/spec/unit/facter/apt_has_updates_spec.rb +++ b/spec/unit/facter/apt_has_updates_spec.rb @@ -11,33 +11,11 @@ describe 'apt_has_updates fact' do it { is_expected.to be_nil } end - describe 'on Debian based distro missing update-notifier-common' do + describe 'on Debian based distro missing apt-get' do before { Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' File.stubs(:executable?) # Stub all other calls - File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns false - } - it { is_expected.to be_nil } - end - - describe 'on Debian based distro with broken packages' do - before { - Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' - File.stubs(:executable?) # Stub all other calls - Facter::Util::Resolution.stubs(:exec) # Catch all other calls - File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>&1').returns "E: Error: BrokenCount > 0" - } - it { is_expected.to be_nil } - end - - describe 'on Debian based distro with unknown error with semicolons' do - before { - Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' - File.stubs(:executable?) # Stub all other calls - Facter::Util::Resolution.stubs(:exec) # Catch all other calls - File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>&1').returns "E: Unknown Error: 'This error contains something that could be parsed like 4;3' (10)" + File.expects(:executable?).with('/usr/bin/apt-get').returns false } it { is_expected.to be_nil } end @@ -47,8 +25,12 @@ describe 'apt_has_updates fact' do Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' File.stubs(:executable?) # Stub all other calls Facter::Util::Resolution.stubs(:exec) # Catch all other calls - File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>&1').returns "4;3" + 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 ""+ + "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"+ + "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" } it { is_expected.to be true } end diff --git a/spec/unit/facter/apt_package_updates_spec.rb b/spec/unit/facter/apt_package_updates_spec.rb index 08bfb42..d7587ca 100644 --- a/spec/unit/facter/apt_package_updates_spec.rb +++ b/spec/unit/facter/apt_package_updates_spec.rb @@ -16,15 +16,18 @@ describe 'apt_package_updates fact' do Facter.fact(:osfamily).stubs(:value).returns 'Debian' File.stubs(:executable?) # Stub all other calls Facter::Util::Resolution.stubs(:exec) # Catch all other calls - File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>&1').returns "1;2" - Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check -p 2>&1').returns "puppet-common\nlinux-generic\nlinux-image-generic" + 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 ""+ + "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"+ + "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" } it { if Facter.version < '2.0.0' - is_expected.to eq('puppet-common,linux-generic,linux-image-generic') + is_expected.to eq('tzdata,unhide.rb') else - is_expected.to eq(['puppet-common', 'linux-generic', 'linux-image-generic']) + is_expected.to eq(['tzdata','unhide.rb']) end } end diff --git a/spec/unit/facter/apt_security_updates_spec.rb b/spec/unit/facter/apt_security_updates_spec.rb index 83aa6ff..174b60d 100644 --- a/spec/unit/facter/apt_security_updates_spec.rb +++ b/spec/unit/facter/apt_security_updates_spec.rb @@ -16,10 +16,14 @@ describe 'apt_security_updates fact' do Facter.fact(:osfamily).stubs(:value).returns 'Debian' File.stubs(:executable?) # Stub all other calls Facter::Util::Resolution.stubs(:exec) # Catch all other calls - File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>&1').returns "14;7" + 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 ""+ + "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"+ + "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" } - it { is_expected.to eq(7) } + it { is_expected.to eq(1) } end end diff --git a/spec/unit/facter/apt_updates_spec.rb b/spec/unit/facter/apt_updates_spec.rb index 781ffd6..8c726fc 100644 --- a/spec/unit/facter/apt_updates_spec.rb +++ b/spec/unit/facter/apt_updates_spec.rb @@ -16,10 +16,14 @@ describe 'apt_updates fact' do Facter.fact(:osfamily).stubs(:value).returns 'Debian' File.stubs(:executable?) # Stub all other calls Facter::Util::Resolution.stubs(:exec) # Catch all other calls - File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true - Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>&1').returns "14;7" + 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 ""+ + "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"+ + "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" } - it { is_expected.to eq(14) } + it { is_expected.to eq(2) } end end