Skip to content

Commit ab0c896

Browse files
committed
(PUP-6631): attempted to support apt-mark
1 parent 749f0dd commit ab0c896

File tree

2 files changed

+55
-30
lines changed

2 files changed

+55
-30
lines changed

lib/puppet/provider/package/apt.rb

Lines changed: 27 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,32 @@ 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+
def initialize(value={})
43+
super(value)
44+
@property_flush = {}
45+
end
46+
47+
def mark=(value)
48+
@property_flush[:mark] = value
49+
end
50+
51+
def flush
52+
# unless we are removing the package mark it if it hasn't already been marked
53+
if @property_flush
54+
unless @property_flush[:mark] or [:purge, :absent].include?(resource[:ensure])
55+
aptmark('manual', resource[:ensure])
56+
end
57+
end
58+
end
59+
3360
# A derivative of DPKG; this is how most people actually manage
3461
# Debian boxes, and the only thing that differs is that it can
3562
# install packages from remote sites.

spec/unit/provider/package/apt_spec.rb

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

89+
context "When listing all instances" do
90+
let(:args) { ['-W', '--showformat', %Q{'${Status} ${Package} ${Version}\\n'}] }
91+
let(:bash_version) { '4.2-5ubuntu3' }
92+
let(:bash_installed_output) { "install ok installed bash #{bash_version}\n" }
93+
let(:bash_installed_io) { StringIO.new(bash_installed_output) }
94+
let(:execpipe_args) { args.unshift('myquery') }
95+
96+
before do
97+
allow(described_class).to receive(:command).with(:dpkgquery).and_return('myquery')
98+
allow(described_class).to receive(:command).with(:aptmark, 'showmanual').and_return('bash\n')
99+
end
100+
101+
it 'creates and return an instance for a single apt-mark entry' do
102+
expect(Puppet::Util::Execution).to receive(:execpipe).with(execpipe_args).and_yield(bash_installed_io)
103+
installed = double('bash', :mark => :manual)
104+
expect(described_class).to receive(:new).with(
105+
:ensure => "4.2-5ubuntu3",
106+
:error => "ok",
107+
:desired => "install",
108+
:name => "bash",
109+
:status => "installed",
110+
:provider => :apt,
111+
).and_return(installed)
112+
allow(installed).to receive(:name)
113+
114+
expect(described_class.instances).to eq([installed])
115+
end
116+
end
89117
describe "when installing" do
90118
it "should preseed if a responsefile is provided" do
91119
resource[:responsefile] = "/my/file"
@@ -123,36 +151,6 @@
123151
provider.install
124152
end
125153

126-
it "should select latest available version if range is specified" do
127-
resource[:ensure] = '>60.0'
128-
expect(provider).to receive(:aptget) do |*command|
129-
expect(command[-1]).to eq("#{name}=72.0.1+build1-0ubuntu0.19.04.1")
130-
end
131-
expect(provider).to receive(:aptcache).with(:madison, name).and_return(<<-HERE)
132-
#{name} | 72.0.1+build1-0ubuntu0.19.04.1 | http://ro.archive.ubuntu.com/ubuntu disco-updates/main amd64 Packages
133-
#{name} | 72.0.1+build1-0ubuntu0.19.04.1 | http://security.ubuntu.com/ubuntu disco-security/main amd64 Packages
134-
#{name} | 66.0.3+build1-0ubuntu1 | http://ro.archive.ubuntu.com/ubuntu disco/main amd64 Packages
135-
HERE
136-
expect(provider).to receive(:properties).and_return({:mark => :none})
137-
138-
provider.install
139-
end
140-
141-
it "should pass through ensure is no version can be selected" do
142-
resource[:ensure] = '>74.0'
143-
expect(provider).to receive(:aptget) do |*command|
144-
expect(command[-1]).to eq("#{name}=>74.0")
145-
end
146-
expect(provider).to receive(:aptcache).with(:madison, name).and_return(<<-HERE)
147-
#{name} | 72.0.1+build1-0ubuntu0.19.04.1 | http://ro.archive.ubuntu.com/ubuntu disco-updates/main amd64 Packages
148-
#{name} | 72.0.1+build1-0ubuntu0.19.04.1 | http://security.ubuntu.com/ubuntu disco-security/main amd64 Packages
149-
#{name} | 66.0.3+build1-0ubuntu1 | http://ro.archive.ubuntu.com/ubuntu disco/main amd64 Packages
150-
HERE
151-
expect(provider).to receive(:properties).and_return({:mark => :none})
152-
153-
provider.install
154-
end
155-
156154
it "should use --force-yes if a package version is specified" do
157155
resource[:ensure] = '1.0'
158156
expect(provider).to receive(:aptget) do |*command|

0 commit comments

Comments
 (0)