Skip to content

Commit 005ff9a

Browse files
author
Ciprian Badescu
committed
(PUP-1537) add hold attribute
This commit adds hold attribute to hold a package on Debian and Solaris instead using "held" value for ensure. Using "held" value for ensure prints deprecation warning
1 parent 9a2305b commit 005ff9a

File tree

5 files changed

+44
-13
lines changed

5 files changed

+44
-13
lines changed

lib/puppet/provider/package/dpkg.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def self.parse_line(line)
6767
elsif ['config-files', 'half-installed', 'unpacked', 'half-configured'].include?(hash[:status])
6868
hash[:ensure] = :absent
6969
end
70-
hash[:ensure] = :held if hash[:desired] == 'hold'
70+
hash[:hold] = (hash[:desired] == 'hold')
7171
else
7272
Puppet.debug("Failed to match dpkg-query line #{line.inspect}")
7373
end
@@ -81,6 +81,11 @@ def install
8181
unless file = @resource[:source]
8282
raise ArgumentError, _("You cannot install dpkg packages without a source")
8383
end
84+
85+
if :held == @resource[:ensure] && @resource[:hold]
86+
raise ArgumentError, _("You cannot use \"hold=>true\" while \"ensure=>held\"")
87+
end
88+
8489
args = []
8590

8691
# We always unhold when installing to remove any prior hold.
@@ -94,6 +99,7 @@ def install
9499
args << '-i' << file
95100

96101
dpkg(*args)
102+
self.hold if @resource[:hold]
97103
end
98104

99105
def update
@@ -144,10 +150,15 @@ def purge
144150
dpkg "--purge", @resource[:name]
145151
end
146152

147-
def hold
153+
def deprecated_hold
154+
Puppet.warning "\"ensure=>held\" has been deprecated and will be removed in a future version, use \"hold=true\" instead "
148155
if package_not_installed?(@resource[:name])
149156
self.install
150157
end
158+
hold
159+
end
160+
161+
def hold
151162
Tempfile.open('puppet_dpkg_set_selection') do |tmpfile|
152163
tmpfile.write("#{@resource[:name]} hold\n")
153164
tmpfile.flush
@@ -163,6 +174,7 @@ def unhold
163174
end
164175
end
165176

177+
#needed until ensure=held is removed
166178
def package_not_installed?(name)
167179
if !name.nil? && !name.empty?
168180
begin

lib/puppet/provider/package/pkg.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def self.ifo_flag(flags)
4949
).merge(
5050
case flags[1..1]
5151
when 'f'
52-
{:ensure => 'held'}
52+
{:hold => true}
53+
5354
when '-'
5455
{}
5556
else
@@ -107,6 +108,11 @@ def self.parse_line(line)
107108
end).merge({:provider => self.name})
108109
end
109110

111+
def deprecated_hold
112+
Puppet.warning "\"ensure=>held\" has been deprecated and will be removed in a future version, use \"hold=true\" instead "
113+
hold
114+
end
115+
110116
def hold
111117
pkg(:freeze, @resource[:name])
112118
end
@@ -217,6 +223,8 @@ def install(nofail = false)
217223
name += "@#{should}"
218224
end
219225
r = exec_cmd(command(:pkg), command, *args, name)
226+
self.hold if @resource[:hold]
227+
220228
return r if nofail
221229
raise Puppet::Error, _("Unable to update %{package}") % { package: r[:out] } if r[:exit] != 0
222230
end

lib/puppet/type/package.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ module Puppet
5454
feature :holdable, "The provider is capable of placing packages on hold
5555
such that they are not automatically upgraded as a result of
5656
other package dependencies unless explicit action is taken by
57-
a user or another package. Held is considered a superset of
58-
installed.",
57+
a user or another package.",
5958
:methods => [:hold]
6059
feature :install_only, "The provider accepts options to only install packages never update (kernels, etc.)"
6160
feature :install_options, "The provider accepts options to be
@@ -101,7 +100,7 @@ module Puppet
101100
end
102101

103102
newvalue(:held, :event => :package_held, :required_features => :holdable) do
104-
provider.hold
103+
provider.deprecated_hold
105104
end
106105

107106
# Alias the 'present' value.
@@ -611,5 +610,9 @@ def refresh
611610
provider.reinstall
612611
end
613612
end
613+
614+
newparam(:held, :parent => Puppet::Parameter::Boolean, :required_features => :holdable) do
615+
desc "Set to true to tell Debian apt/Solaris pkg to hold the package version"
616+
end
614617
end
615618
end

spec/unit/provider/package/dpkg_spec.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
expect(Puppet::Util::Execution).to receive(:execpipe).with(execpipe_args).and_yield(bash_installed_io)
3131

3232
installed = double('bash')
33-
expect(described_class).to receive(:new).with(:ensure => "4.2-5ubuntu3", :error => "ok", :desired => "install", :name => "bash", :status => "installed", :provider => :dpkg).and_return(installed)
33+
expect(described_class).to receive(:new).with(:ensure => "4.2-5ubuntu3", :hold => false, :error => "ok", :desired => "install", :name => "bash", :status => "installed", :provider => :dpkg).and_return(installed)
3434

3535
expect(described_class.instances).to eq([installed])
3636
end
@@ -39,9 +39,9 @@
3939
expect(Puppet::Util::Execution).to receive(:execpipe).with(execpipe_args).and_yield(all_installed_io)
4040

4141
bash = double('bash')
42-
expect(described_class).to receive(:new).with(:ensure => "4.2-5ubuntu3", :error => "ok", :desired => "install", :name => "bash", :status => "installed", :provider => :dpkg).and_return(bash)
42+
expect(described_class).to receive(:new).with(:ensure => "4.2-5ubuntu3", :hold => false, :error => "ok", :desired => "install", :name => "bash", :status => "installed", :provider => :dpkg).and_return(bash)
4343
vim = double('vim')
44-
expect(described_class).to receive(:new).with(:ensure => "2:7.3.547-6ubuntu5", :error => "ok", :desired => "install", :name => "vim", :status => "installed", :provider => :dpkg).and_return(vim)
44+
expect(described_class).to receive(:new).with(:ensure => "2:7.3.547-6ubuntu5", :hold => false, :error => "ok", :desired => "install", :name => "vim", :status => "installed", :provider => :dpkg).and_return(vim)
4545

4646
expect(described_class.instances).to eq([bash, vim])
4747
end
@@ -81,7 +81,7 @@ def dpkg_query_execution_returns(output)
8181
it "returns a hash of the found package status for an installed package" do
8282
dpkg_query_execution_returns(bash_installed_output)
8383

84-
expect(provider.query).to eq({:ensure => "4.2-5ubuntu3", :error => "ok", :desired => "install", :name => "bash", :status => "installed", :provider => :dpkg})
84+
expect(provider.query).to eq({:ensure => "4.2-5ubuntu3", :hold => false, :error => "ok", :desired => "install", :name => "bash", :status => "installed", :provider => :dpkg})
8585
end
8686

8787
it "considers the package absent if the dpkg-query result cannot be interpreted" do
@@ -126,7 +126,10 @@ def dpkg_query_execution_returns(output)
126126

127127
it "considers the package held if its state is 'hold'" do
128128
dpkg_query_execution_returns(bash_installed_output.gsub("install","hold"))
129-
expect(provider.query[:ensure]).to eq(:held)
129+
query=provider.query
130+
expect(query[:ensure]).to eq("4.2-5ubuntu3")
131+
expect(query[:hold]).to eq(true)
132+
130133
end
131134

132135
context "parsing tests" do
@@ -138,6 +141,7 @@ def dpkg_query_execution_returns(output)
138141
:status => 'status',
139142
:name => resource_name,
140143
:ensure => 'ensure',
144+
:hold => false,
141145
:provider => :dpkg,
142146
}
143147
end
@@ -183,6 +187,7 @@ def parser_test(dpkg_output_string, gold_hash, number_of_debug_logs = 0)
183187
end
184188

185189
it "uses 'dpkg -i' to install the package" do
190+
expect(resource).to receive(:[]).with(:hold).and_return(false)
186191
expect(resource).to receive(:[]).with(:source).and_return("mypackagefile")
187192
expect(provider).to receive(:unhold)
188193
expect(provider).to receive(:dpkg).with(any_args, "-i", "mypackagefile")
@@ -191,6 +196,7 @@ def parser_test(dpkg_output_string, gold_hash, number_of_debug_logs = 0)
191196
end
192197

193198
it "keeps old config files if told to do so" do
199+
expect(resource).to receive(:[]).with(:hold).and_return(false)
194200
expect(resource).to receive(:[]).with(:configfiles).and_return(:keep)
195201
expect(provider).to receive(:unhold)
196202
expect(provider).to receive(:dpkg).with("--force-confold", any_args)
@@ -199,6 +205,7 @@ def parser_test(dpkg_output_string, gold_hash, number_of_debug_logs = 0)
199205
end
200206

201207
it "replaces old config files if told to do so" do
208+
expect(resource).to receive(:[]).with(:hold).and_return(false)
202209
expect(resource).to receive(:[]).with(:configfiles).and_return(:replace)
203210
expect(provider).to receive(:unhold)
204211
expect(provider).to receive(:dpkg).with("--force-confnew", any_args)
@@ -207,6 +214,7 @@ def parser_test(dpkg_output_string, gold_hash, number_of_debug_logs = 0)
207214
end
208215

209216
it "ensures any hold is removed" do
217+
expect(resource).to receive(:[]).with(:hold).and_return(false)
210218
expect(provider).to receive(:unhold).once
211219
expect(provider).to receive(:dpkg)
212220
provider.install
@@ -226,7 +234,7 @@ def parser_test(dpkg_output_string, gold_hash, number_of_debug_logs = 0)
226234
allow(provider).to receive(:execute)
227235
allow(provider).to receive(:package_not_installed?).and_return(true)
228236
expect(provider).to receive(:install).once
229-
provider.hold
237+
provider.deprecated_hold
230238
end
231239

232240
it "skips install new package if package is allready installed" do

spec/unit/provider/package/pkg_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def self.it_should_respond_to(*actions)
9090

9191
{
9292
'pkg://omnios/[email protected],5.11-0.151006:20130506T161045Z i--' => {:name => 'SUNWcs', :ensure => '0.5.11,5.11-0.151006:20130506T161045Z', :status => 'installed', :provider => :pkg, :publisher => 'omnios'},
93-
'pkg://omnios/incorporation/jeos/illumos-gate@11,5.11-0.151006:20130506T183443Z if-' => {:name => 'incorporation/jeos/illumos-gate', :ensure => 'held', :status => 'installed', :provider => :pkg, :publisher => 'omnios'},
93+
'pkg://omnios/incorporation/jeos/illumos-gate@11,5.11-0.151006:20130506T183443Z if-' => {:name => 'incorporation/jeos/illumos-gate', :ensure => "11,5.11-0.151006:20130506T183443Z", :hold => true, :status => 'installed', :provider => :pkg, :publisher => 'omnios'},
9494
'pkg://solaris/[email protected],5.11-0.151.0.1:20101105T001108Z installed -----' => {:name => 'SUNWcs', :ensure => '0.5.11,5.11-0.151.0.1:20101105T001108Z', :status => 'installed', :provider => :pkg, :publisher => 'solaris'},
9595
}.each do |k, v|
9696
it "[#{k}] should correctly parse" do

0 commit comments

Comments
 (0)