Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lib/puppet/provider/package/apt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,6 +31,39 @@ 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 query
hash = super
hash[:mark] = :manual if aptmark('showmanual').split("\n").include?(@resource[:name])
hash
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] || [: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.
Expand Down
77 changes: 77 additions & 0 deletions spec/unit/provider/package/apt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,83 @@
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 '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"
Expand Down
1 change: 1 addition & 0 deletions spec/unit/provider/package/aptitude_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down