Skip to content
This repository has been archived by the owner on Feb 18, 2022. It is now read-only.

(PUP-11452) Shell out to list packages in puppetserver_gem #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions lib/puppet/provider/package/puppetserver_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def self.gemlist(options)
end

if options[:local]
list = execute_rubygems_list_command(gem_regex)
list = execute_rubygems_list_command(command_options)
else
begin
list = puppetservercmd(command_options)
Expand Down Expand Up @@ -86,7 +86,7 @@ def self.gemlist(options)
# for example: json (1.8.3 java)
# but java platform gems should not be managed by this (or any) provider.

def self.execute_rubygems_list_command(gem_regex)
def self.execute_rubygems_list_command(command_options)
puppetserver_default_gem_home = '/opt/puppetlabs/server/data/puppetserver/jruby-gems'
puppetserver_default_vendored_jruby_gems = '/opt/puppetlabs/server/data/puppetserver/vendored-jruby-gems'
puppet_default_vendor_gems = '/opt/puppetlabs/puppet/lib/ruby/vendor_gems'
Expand All @@ -106,25 +106,17 @@ def self.execute_rubygems_list_command(gem_regex)
gem_env['GEM_PATH'] = puppetserver_conf['jruby-puppet'].key?('gem-path') ? puppetserver_conf['jruby-puppet']['gem-path'].join(':') : puppetserver_default_gem_path
end
gem_env['GEM_SPEC_CACHE'] = "/tmp/#{$$}"
Gem.paths = gem_env

sio_inn = StringIO.new
sio_out = StringIO.new
sio_err = StringIO.new
stream_ui = Gem::StreamUI.new(sio_inn, sio_out, sio_err, false)
gem_list_cmd = Gem::Commands::ListCommand.new
gem_list_cmd.options[:domain] = :local
gem_list_cmd.options[:args] = [gem_regex] if gem_regex
gem_list_cmd.ui = stream_ui
gem_list_cmd.execute

# Remove the 'gem' from the command_options
command_options.shift

output = execute_gem_command(Puppet::Type::Package::ProviderPuppet_gem.provider_command, command_options, gem_env)

# There is no method exclude default gems from the local gem list,
# for example: psych (default: 2.2.2)
# but default gems should not be managed by this (or any) provider.
gem_list = sio_out.string.lines.reject { |gem| gem =~ / \(default\: / }
gem_list = output.lines.reject { |gem| gem =~ / \(default\: / }
gem_list.join("\n")
ensure
Gem.clear_paths
end

def install(useversion = true)
Expand Down