From 69215f1497b46f602e77e21be4e7b0951b5be6e1 Mon Sep 17 00:00:00 2001 From: John Bond Date: Thu, 31 Oct 2019 15:26:07 +0100 Subject: [PATCH 1/3] (PUP-6631): attempted to support apt-mark --- lib/puppet/provider/package/apt.rb | 33 ++++++++++++++++++++++++++ spec/unit/provider/package/apt_spec.rb | 28 ++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/lib/puppet/provider/package/apt.rb b/lib/puppet/provider/package/apt.rb index dc5b95fa443..cee66450119 100644 --- a/lib/puppet/provider/package/apt.rb +++ b/lib/puppet/provider/package/apt.rb @@ -16,6 +16,7 @@ commands :aptget => "/usr/bin/apt-get" commands :aptcache => "/usr/bin/apt-cache" + commands :aptmark => "/usr/bin/apt-mark" commands :preseed => "/usr/bin/debconf-set-selections" defaultfor :osfamily => :debian @@ -30,6 +31,38 @@ def self.defaultto_allow_virtual false end + def self.instances + packages = super + manual_marks = aptmark('showmanual').split("\n") + packages.each do |package| + package.mark = :manual if manual_marks.include?(package.name) + end + packages + end + + def self.query + hash = super + hash[:mark] = :manual if aptmark('showmanual').split("\n").include?(@resource[:name]) + end + + def initialize(value={}) + super(value) + @property_flush = {} + end + + def mark=(value) + @property_flush[:mark] = value + end + + def flush + # unless we are removing the package mark it if it hasn't already been marked + if @property_flush + unless @property_flush[:mark] or [:purge, :absent].include?(resource[:ensure]) + aptmark('manual', resource[:name]) + end + end + end + # A derivative of DPKG; this is how most people actually manage # Debian boxes, and the only thing that differs is that it can # install packages from remote sites. diff --git a/spec/unit/provider/package/apt_spec.rb b/spec/unit/provider/package/apt_spec.rb index e761e86df57..8d100b37803 100644 --- a/spec/unit/provider/package/apt_spec.rb +++ b/spec/unit/provider/package/apt_spec.rb @@ -86,6 +86,34 @@ provider.run_preseed end + describe ".instances" do + before do + allow(Puppet::Type::Package::ProviderDpkg).to receive(:instances).and_return([resource]) + end + + context "when package is manual marked" do + before do + allow(described_class).to receive(:aptmark).with('showmanual').and_return("#{resource.name}\n") + end + + it 'sets mark to manual' do + expect(resource).to receive(:mark=).with(:manual) + described_class.instances + end + end + + context 'when package is not manual marked ' do + before do + allow(described_class).to receive(:aptmark).with('showmanual').and_return('') + end + + it 'does not set mark to manual' do + expect(resource).not_to receive(:mark=).with(:manual) + described_class.instances + end + end + end + describe "when installing" do it "should preseed if a responsefile is provided" do resource[:responsefile] = "/my/file" From 4bf1dd82fc029fc4a67b3baa2920f016a04d2bb6 Mon Sep 17 00:00:00 2001 From: gimmy Date: Mon, 20 Jul 2020 13:52:21 +0300 Subject: [PATCH 2/3] (PUP-6331) update query and add specs --- lib/puppet/provider/package/apt.rb | 5 +-- spec/unit/provider/package/apt_spec.rb | 49 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/package/apt.rb b/lib/puppet/provider/package/apt.rb index cee66450119..d862f9d534c 100644 --- a/lib/puppet/provider/package/apt.rb +++ b/lib/puppet/provider/package/apt.rb @@ -40,9 +40,10 @@ def self.instances packages end - def self.query + def query hash = super hash[:mark] = :manual if aptmark('showmanual').split("\n").include?(@resource[:name]) + hash end def initialize(value={}) @@ -57,7 +58,7 @@ def mark=(value) def flush # unless we are removing the package mark it if it hasn't already been marked if @property_flush - unless @property_flush[:mark] or [:purge, :absent].include?(resource[:ensure]) + unless @property_flush[:mark] || [:purge, :absent].include?(resource[:ensure]) aptmark('manual', resource[:name]) end end diff --git a/spec/unit/provider/package/apt_spec.rb b/spec/unit/provider/package/apt_spec.rb index 8d100b37803..03bcb86931b 100644 --- a/spec/unit/provider/package/apt_spec.rb +++ b/spec/unit/provider/package/apt_spec.rb @@ -114,6 +114,55 @@ end end + describe 'query' do + before do + allow(provider).to receive(:dpkgquery).and_return("name: #{resource.name}" ) + end + + context "when package is manual marked" do + before do + allow(described_class).to receive(:aptmark).with('showmanual').and_return("#{resource.name}\n") + end + + it 'sets mark to manual' do + result = provider.query + expect(result[:mark]).to eql(:manual) + end + end + + context 'when package is not manual marked ' do + before do + allow(described_class).to receive(:aptmark).with('showmanual').and_return('') + end + + it 'does not set mark to manual' do + result = provider.query + expect(result[:mark]).to be_nil + end + end + end + + describe 'flush' do + + context "when package is manual marked" do + before do + provider.mark = :manual + end + + it 'does not call aptmark' do + expect(provider).not_to receive(:aptmark) + provider.flush + end + end + + context 'when package is not manual marked ' do + it 'calls aptmark' do + expect(described_class).to receive(:aptmark).with('manual', resource.name) + provider.flush + end + end + end + describe "when installing" do it "should preseed if a responsefile is provided" do resource[:responsefile] = "/my/file" From d1eb7e094e338647d4bf0eb66292415fcf65fe84 Mon Sep 17 00:00:00 2001 From: gimmy Date: Mon, 20 Jul 2020 17:05:33 +0300 Subject: [PATCH 3/3] (PUP-6631) fix aptitude specs --- spec/unit/provider/package/aptitude_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/unit/provider/package/aptitude_spec.rb b/spec/unit/provider/package/aptitude_spec.rb index e3d8bbecaa5..5df6d79bfca 100644 --- a/spec/unit/provider/package/aptitude_spec.rb +++ b/spec/unit/provider/package/aptitude_spec.rb @@ -13,6 +13,7 @@ before do allow(Puppet::Util).to receive(:which).with('/usr/bin/dpkg-query').and_return(dpkgquery_path) + allow(described_class).to receive(:aptmark).with('showmanual').and_return("") end { :absent => "deinstall ok config-files faff 1.2.3-1\n",