Skip to content

Commit 2be0923

Browse files
authored
Merge pull request #7802 from b4ldr/PUP-6631
2 parents 464591c + d1eb7e0 commit 2be0923

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

lib/puppet/provider/package/apt.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
commands :aptget => "/usr/bin/apt-get"
1818
commands :aptcache => "/usr/bin/apt-cache"
19+
commands :aptmark => "/usr/bin/apt-mark"
1920
commands :preseed => "/usr/bin/debconf-set-selections"
2021

2122
defaultfor :osfamily => :debian
@@ -30,6 +31,39 @@ def self.defaultto_allow_virtual
3031
false
3132
end
3233

34+
def self.instances
35+
packages = super
36+
manual_marks = aptmark('showmanual').split("\n")
37+
packages.each do |package|
38+
package.mark = :manual if manual_marks.include?(package.name)
39+
end
40+
packages
41+
end
42+
43+
def query
44+
hash = super
45+
hash[:mark] = :manual if aptmark('showmanual').split("\n").include?(@resource[:name])
46+
hash
47+
end
48+
49+
def initialize(value={})
50+
super(value)
51+
@property_flush = {}
52+
end
53+
54+
def mark=(value)
55+
@property_flush[:mark] = value
56+
end
57+
58+
def flush
59+
# unless we are removing the package mark it if it hasn't already been marked
60+
if @property_flush
61+
unless @property_flush[:mark] || [:purge, :absent].include?(resource[:ensure])
62+
aptmark('manual', resource[:name])
63+
end
64+
end
65+
end
66+
3367
# A derivative of DPKG; this is how most people actually manage
3468
# Debian boxes, and the only thing that differs is that it can
3569
# install packages from remote sites.

spec/unit/provider/package/apt_spec.rb

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,83 @@
8686
provider.run_preseed
8787
end
8888

89+
describe ".instances" do
90+
before do
91+
allow(Puppet::Type::Package::ProviderDpkg).to receive(:instances).and_return([resource])
92+
end
93+
94+
context "when package is manual marked" do
95+
before do
96+
allow(described_class).to receive(:aptmark).with('showmanual').and_return("#{resource.name}\n")
97+
end
98+
99+
it 'sets mark to manual' do
100+
expect(resource).to receive(:mark=).with(:manual)
101+
described_class.instances
102+
end
103+
end
104+
105+
context 'when package is not manual marked ' do
106+
before do
107+
allow(described_class).to receive(:aptmark).with('showmanual').and_return('')
108+
end
109+
110+
it 'does not set mark to manual' do
111+
expect(resource).not_to receive(:mark=).with(:manual)
112+
described_class.instances
113+
end
114+
end
115+
end
116+
117+
describe 'query' do
118+
before do
119+
allow(provider).to receive(:dpkgquery).and_return("name: #{resource.name}" )
120+
end
121+
122+
context "when package is manual marked" do
123+
before do
124+
allow(described_class).to receive(:aptmark).with('showmanual').and_return("#{resource.name}\n")
125+
end
126+
127+
it 'sets mark to manual' do
128+
result = provider.query
129+
expect(result[:mark]).to eql(:manual)
130+
end
131+
end
132+
133+
context 'when package is not manual marked ' do
134+
before do
135+
allow(described_class).to receive(:aptmark).with('showmanual').and_return('')
136+
end
137+
138+
it 'does not set mark to manual' do
139+
result = provider.query
140+
expect(result[:mark]).to be_nil
141+
end
142+
end
143+
end
144+
145+
describe 'flush' do
146+
147+
context "when package is manual marked" do
148+
before do
149+
provider.mark = :manual
150+
end
151+
152+
it 'does not call aptmark' do
153+
expect(provider).not_to receive(:aptmark)
154+
provider.flush
155+
end
156+
end
157+
158+
context 'when package is not manual marked ' do
159+
it 'calls aptmark' do
160+
expect(described_class).to receive(:aptmark).with('manual', resource.name)
161+
provider.flush
162+
end
163+
end
164+
end
165+
89166
describe "when installing" do
90167
it "should preseed if a responsefile is provided" do
91168
resource[:responsefile] = "/my/file"

spec/unit/provider/package/aptitude_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
before do
1515
allow(Puppet::Util).to receive(:which).with('/usr/bin/dpkg-query').and_return(dpkgquery_path)
16+
allow(described_class).to receive(:aptmark).with('showmanual').and_return("")
1617
end
1718

1819
{ :absent => "deinstall ok config-files faff 1.2.3-1\n",

0 commit comments

Comments
 (0)