Skip to content

Commit ea8a34f

Browse files
author
Jarret Lavallee
committed
(PUP-11452) Shell out to list packages in puppetserver_gem
Prior to this commit, the puppetserver_gem listed local packages using the GEM command line, which resulted in innacurate results if a gem was already loaded. This commit switches the listing of puppetserver gems to use the shell command.
1 parent 2171a85 commit ea8a34f

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

lib/puppet/provider/package/puppetserver_gem.rb

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def self.gemlist(options)
5353
end
5454

5555
if options[:local]
56-
list = execute_rubygems_list_command(gem_regex)
56+
list = execute_rubygems_list_command(command_options)
5757
else
5858
begin
5959
list = puppetservercmd(command_options)
@@ -137,7 +137,7 @@ def uninstall
137137
# for example: json (1.8.3 java)
138138
# but java platform gems should not be managed by this (or any) provider.
139139

140-
def self.execute_rubygems_list_command(gem_regex)
140+
def self.execute_rubygems_list_command(command_options)
141141
puppetserver_default_gem_home = '/opt/puppetlabs/server/data/puppetserver/jruby-gems'
142142
puppetserver_default_vendored_jruby_gems = '/opt/puppetlabs/server/data/puppetserver/vendored-jruby-gems'
143143
puppet_default_vendor_gems = '/opt/puppetlabs/puppet/lib/ruby/vendor_gems'
@@ -157,24 +157,15 @@ def self.execute_rubygems_list_command(gem_regex)
157157
gem_env['GEM_PATH'] = puppetserver_conf['jruby-puppet'].key?('gem-path') ? puppetserver_conf['jruby-puppet']['gem-path'].join(':') : puppetserver_default_gem_path
158158
end
159159
gem_env['GEM_SPEC_CACHE'] = "/tmp/#{$$}"
160-
Gem.paths = gem_env
161-
162-
sio_inn = StringIO.new
163-
sio_out = StringIO.new
164-
sio_err = StringIO.new
165-
stream_ui = Gem::StreamUI.new(sio_inn, sio_out, sio_err, false)
166-
gem_list_cmd = Gem::Commands::ListCommand.new
167-
gem_list_cmd.options[:domain] = :local
168-
gem_list_cmd.options[:args] = [gem_regex] if gem_regex
169-
gem_list_cmd.ui = stream_ui
170-
gem_list_cmd.execute
160+
161+
# Remove the 'gem' from the command_options
162+
command_options.shift
163+
gem_out = execute_gem_command(Puppet::Type::Package::ProviderPuppet_gem.provider_command, command_options, gem_env)
171164

172165
# There is no method exclude default gems from the local gem list,
173166
# for example: psych (default: 2.2.2)
174167
# but default gems should not be managed by this (or any) provider.
175-
gem_list = sio_out.string.lines.reject { |gem| gem =~ / \(default\: / }
168+
gem_list = gem_out.lines.reject { |gem| gem =~ / \(default\: / }
176169
gem_list.join("\n")
177-
ensure
178-
Gem.clear_paths
179170
end
180171
end

spec/unit/provider/package/puppetserver_gem_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@
105105

106106
describe ".gemlist" do
107107
context "listing installed packages" do
108-
it "uses the puppet rubygems library to list local gems" do
108+
it "uses the puppet_gem provider_command to list local gems" do
109109
expected = { name: 'world_airports', provider: :puppetserver_gem, ensure: ['1.1.3'] }
110-
expect(described_class).to receive(:execute_rubygems_list_command).with(nil).and_return(File.read(my_fixture('gem-list-local-packages')))
110+
expect(described_class).to receive(:execute_rubygems_list_command).with(['gem', 'list', '--local']).and_return(File.read(my_fixture('gem-list-local-packages')))
111111
expect(described_class.gemlist({ local: true })).to include(expected)
112112
end
113113
end

0 commit comments

Comments
 (0)