Skip to content

Commit

Permalink
Use a shell_out to rpm for RHEL instead of yum
Browse files Browse the repository at this point in the history
This should restore support for Fedora, where YUM's existence and
functionality is not guaranteed.
  • Loading branch information
hartmantis committed Aug 18, 2016
1 parent d478f9c commit cf6aa27
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
19 changes: 10 additions & 9 deletions libraries/resource_chef_dk_app_rhel.rb
Expand Up @@ -19,6 +19,7 @@
# limitations under the License.
#

require 'chef/mixin/shell_out'
require_relative 'resource_chef_dk_app'

class Chef
Expand All @@ -27,6 +28,8 @@ class Resource
#
# @author Jonathan Hartman <j@p4nt5.com>
class ChefDkAppRhel < ChefDkApp
include Chef::Mixin::ShellOut

provides :chef_dk_app, platform_family: 'rhel'
provides :chef_dk_app, platform: 'fedora'

Expand Down Expand Up @@ -107,19 +110,17 @@ class ChefDkAppRhel < ChefDkApp
end

#
# Use Chef's Package resource and Yum provider to find the currently
# installed version. We need to use Yum instead of Rpm here because the
# Rpm provider won't check for a version if no source property is
# offered.
# Shell out to the RPM command to get the currently installed version.
# We can't use a Chef provider here because the Rpm provider requires a
# source property that we don't have and the Yum provider has issues on
# Fedora.
#
# (see Chef::Resource::ChefDkApp#installed_version)
#
def installed_version
res = Chef::Resource::Package.new('chefdk', run_context)
prov = Chef::Provider::Package::Yum.new(res, run_context)
ver = prov.load_current_resource.version
return false if ver.nil?
ver = ver.split('-').first
sh = shell_out('rpm -q --info chefdk')
return false if sh.exitstatus.nonzero?
ver = sh.stdout.match(/^Version\W+:\W+([0-9]+\.[0-9]+\.[0-9]+)$/)[1]
ver == package_metadata[:version] ? 'latest' : ver
end
end
Expand Down
9 changes: 6 additions & 3 deletions spec/resources/chef_dk_app/rhel.rb
Expand Up @@ -5,9 +5,12 @@
include_context 'resources::chef_dk_app'

before(:each) do
allow_any_instance_of(Chef::Provider::Package::Yum)
.to receive(:load_current_resource)
.and_return(double(version: installed_version))
allow_any_instance_of(Chef::Mixin::ShellOut).to receive(:shell_out)
.with('rpm -q --info chefdk').and_return(double(
exitstatus: installed_version.nil? ? 1 : 0,
stdout: "Name : chefdk\nVersion : 0.17.17\n" \
"Release : 1.el7\n"
))
end

shared_examples_for 'any RHEL platform' do
Expand Down

0 comments on commit cf6aa27

Please sign in to comment.