Skip to content

Commit f3196a6

Browse files
author
Thom May
committed
CHEF-987: allow yum to do localinstalls
1 parent 92d7de9 commit f3196a6

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

‎chef/lib/chef/provider/package/yum.rb‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,23 @@ def load_current_resource
115115
@current_resource=Chef::Resource::Package.new(@new_resource.name)
116116
@current_resource.package_name(@new_resource.package_name)
117117

118+
if@new_resource.source
119+
unless ::File.exists?(@new_resource.source)
120+
raiseChef::Exceptions::Package,"Package #{@new_resource.name} not found: #{@new_resource.source}"
121+
end
122+
123+
Chef::Log.debug("Checking rpm status for #{@new_resource.package_name}")
124+
status=popen4("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}")do |pid,stdin,stdout,stderr|
125+
stdout.eachdo |line|
126+
caseline
127+
when/([\w\d_.-]+)\s([\w\d_.-]+)/
128+
@current_resource.package_name($1)
129+
@new_resource.version($2)
130+
end
131+
end
132+
end
133+
end
134+
118135
Chef::Log.debug("Checking yum info for #{@new_resource.package_name}")
119136

120137
@yum.refresh
@@ -133,9 +150,15 @@ def load_current_resource
133150
end
134151

135152
definstall_package(name,version)
136-
run_command_with_systems_locale(
137-
:command=>"yum -d0 -e0 -y install #{name}-#{version}"
138-
)
153+
if@new_resource.source
154+
run_command_with_systems_locale(
155+
:command=>"yum -d0 -e0 -y localinstall #{@new_resource.source}"
156+
)
157+
else
158+
run_command_with_systems_locale(
159+
:command=>"yum -d0 -e0 -y install #{name}-#{version}"
160+
)
161+
end
139162
@yum.flush
140163
end
141164

‎chef/spec/unit/provider/package/yum_spec.rb‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
:name=>"cups",
2727
:version=>nil,
2828
:package_name=>"cups",
29-
:updated=>nil
29+
:updated=>nil,
30+
:source=>nil
3031
)
3132
@current_resource=mock("Chef::Resource::Package",
3233
:null_object=>true,
@@ -90,7 +91,8 @@
9091
:name=>"emacs",
9192
:version=>nil,
9293
:package_name=>"emacs",
93-
:updated=>nil
94+
:updated=>nil,
95+
:source=>nil
9496
)
9597
@yum_cache=mock(
9698
'Chef::Provider::Yum::YumCache',
@@ -109,6 +111,15 @@
109111
})
110112
@provider.install_package("emacs","1.0")
111113
end
114+
115+
it"should run yum localinstall if given a path to an rpm"do
116+
@new_resource.stub!(:source).and_return("/tmp/emacs-21.4-20.el5.i386.rpm")
117+
@provider.should_receive(:run_command_with_systems_locale).with({
118+
:command=>"yum -d0 -e0 -y localinstall /tmp/emacs-21.4-20.el5.i386.rpm"
119+
})
120+
@provider.install_package("emacs","21.4-20.el5")
121+
end
122+
112123
end
113124

114125
describeChef::Provider::Package::Yum,"upgrade_package"do
@@ -120,7 +131,8 @@
120131
:name=>"emacs",
121132
:version=>nil,
122133
:package_name=>"emacs",
123-
:updated=>nil
134+
:updated=>nil,
135+
:source=>nil
124136
)
125137
@yum_cache=mock(
126138
'Chef::Provider::Yum::YumCache',
@@ -166,7 +178,8 @@
166178
:name=>"emacs",
167179
:version=>nil,
168180
:package_name=>"emacs",
169-
:updated=>nil
181+
:updated=>nil,
182+
:source=>nil
170183
)
171184
@yum_cache=mock(
172185
'Chef::Provider::Yum::YumCache',
@@ -195,7 +208,8 @@
195208
:name=>"emacs",
196209
:version=>"10",
197210
:package_name=>"emacs",
198-
:updated=>nil
211+
:updated=>nil,
212+
:source=>nil
199213
)
200214
@yum_cache=mock(
201215
'Chef::Provider::Yum::YumCache',

0 commit comments

Comments
(0)