Skip to content

Comments

(PUP-6134) Explicitly locate gemcmd windows#5814

Closed
tkishel wants to merge 1 commit intopuppetlabs:4.10.xfrom
tkishel:PUP-6134-explicitly_locate_gemcmd_windows
Closed

(PUP-6134) Explicitly locate gemcmd windows#5814
tkishel wants to merge 1 commit intopuppetlabs:4.10.xfrom
tkishel:PUP-6134-explicitly_locate_gemcmd_windows

Conversation

@tkishel
Copy link
Contributor

@tkishel tkishel commented Apr 20, 2017

On Windows:

Puppet is unable to install a ruby gem anywhere other than Puppet's ruby.
Caused by Puppet prepending its paths (including our gem) to PATH.
This fix removes Puppet's paths from PATH when setting :gemcmd.

(A larger-scale solution would involve a path/target parameter to Package.)

@puppetcla
Copy link

CLA signed by all contributors.

@tkishel
Copy link
Contributor Author

tkishel commented Apr 21, 2017

Resubmitted this PR to recover from a rebase error with the previous PR.

@geoffnichols
Copy link
Contributor

Replaces #5460.

# That results in the which() method in self.command(name) in lib/puppet/provider.rb always returning Puppet's gem command.
# To prevent this, call which("gem") with a PATH without Puppet's paths, and set gemcmd to the full-path result.
path_array = Puppet::Util.get_env("PATH").split(File::PATH_SEPARATOR)
path_array.reject! {|p| p =~ /puppet/i}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method of constructing the PATH is a bit imprecise - a few problems I see:

  • What if a user relocated the installation to something without puppet in it?
  • What if the Ruby installation path contains puppet in it? (admittedly less likely)

We can add a little bit of code to find the actual current running Ruby like this:
https://stackoverflow.com/a/25929455

I can help out with putting that in the right spot within Puppet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I made an assumption that users might change INSTALLDIR from the default of C:\Program Files\Puppet Labs\Puppet but not change that last Puppet directory.

Since we already find and set RUBY_DIR, could we reuse it as follows?

if Puppet.features.microsoft_windows?
  ruby_bin_dir = Puppet::Util.get_env('RUBY_DIR') + '\bin'
  path_array = Puppet::Util.get_env('PATH').split(File::PATH_SEPARATOR)
  path_array.reject! {|p| p == ruby_bin_dir}
  path_without_puppet_ruby_bin_dir = path_array.join(File::PATH_SEPARATOR)
  commands :gemcmd => Puppet::Util.withenv({:PATH => path_without_puppet_ruby_bin_dir}, :windows) { which('gem') }
else
  commands :gemcmd => 'gem'
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if you make that available in another spot, I'll use it.

@tkishel tkishel force-pushed the PUP-6134-explicitly_locate_gemcmd_windows branch from b9be434 to e8452af Compare October 18, 2017 17:21
@tkishel tkishel changed the base branch from master to 4.10.x October 18, 2017 17:21
@tkishel tkishel force-pushed the PUP-6134-explicitly_locate_gemcmd_windows branch 2 times, most recently from 1cefba1 to c28122f Compare October 18, 2017 21:45
@tkishel
Copy link
Contributor Author

tkishel commented Oct 18, 2017

I have rebased onto 4.10.x but have not been able to clear the AppVeyor error. I thought it might be related to line 103 of spec/integration/type/package_spec.rb specifying the provider as :gem which, with this commit, will find no gem command if there is no gem in the path (outside of ours, which should be specified via the puppet_gemprovider) but changing it to :puppet_gemresults in another error when running bundle exec rake spec:

Puppet::Error: 
Could not list gems: Execution of '/opt/puppetlabs/puppet/bin/gem list --local' returned 1: 
/Users/tom.kishel/.rvm/gems/ruby-2.3.0/gems/bundler-1.15.4/lib/bundler/spec_set.rb:87:in 
`block in materialize': Could not find rake-10.1.1 in any of the sources (Bundler::GemNotFound)

A similar error occurs when running bundle exec rake spec in Windows. In both cases, running that same gem list or gem.cmd list command actually lists gems and does not set an error in $?

I will need help addressing that. Note that manually testing this commit on Windows with puppet apply correctly manages a gem package, and puppet resource package correctly lists the gems of the non-puppet vendored ruby.

@theshanx
Copy link
Contributor

@Iristyle @geoffnichols any advice on how we can troubleshoot the AppVeyor check or who we can ask to help?

@tkishel tkishel force-pushed the PUP-6134-explicitly_locate_gemcmd_windows branch from c28122f to 65483fb Compare December 11, 2017 22:44
@tkishel tkishel force-pushed the PUP-6134-explicitly_locate_gemcmd_windows branch from 65483fb to fb576c5 Compare December 29, 2017 00:27
@tkishel
Copy link
Contributor Author

tkishel commented Dec 29, 2017

The AppVeyor Windows environment, unlike the Puppet Agent Windows environment, does not define a RUBY_DIR environment variable, causing the following error:

Failure/Error: ruby_bin_dir = Puppet::Util.get_env('RUBY_DIR') + '\bin'                                                                           
                                                                                                                                                  
Puppet::Error:                                                                                                                                    
  Could not autoload puppet/type/package: Could not autoload puppet/provider/package/gem: undefined method `+' for nil:NilClass                   

Resolved for AppVeyor by checking for nil before concatenation.

Note that RUBY_DIR should always be defined and prepended to PATH in a Puppet Agent Windows environment, via environment.bat: it's that prepending that causes the problem documented in PUP-6134. Also note that if RUBY_DIR is not defined, this provider would not be the first point of failure!

@tkishel tkishel force-pushed the PUP-6134-explicitly_locate_gemcmd_windows branch from fb576c5 to c1cd7c6 Compare December 29, 2017 18:01
On Windows:

Puppet is unable to install a ruby gem anywhere other than Puppet's ruby.
Caused by Puppet prepending its paths (including our gem) to PATH.
This fix removes Puppet's paths from PATH when setting :gemcmd.
@tkishel tkishel force-pushed the PUP-6134-explicitly_locate_gemcmd_windows branch from c1cd7c6 to 82bcd9e Compare December 29, 2017 21:48
@melissa
Copy link
Contributor

melissa commented Oct 23, 2018

@caseywilliams @branan is this still an issue with the updates that happened to the MSI paths in puppet 6?

@mcdonaldseanp
Copy link
Contributor

@melissa yeah, nothing about the path updates would have changed this. It would still be an issue.

@melissa
Copy link
Contributor

melissa commented Feb 21, 2019

@Iristyle could you take another look at this?

@tkishel
Copy link
Contributor Author

tkishel commented Feb 21, 2019

I understand we may consider this to be a breaking change, as we may have users using this bug as a feature to manage puppet gems on Windows (normally managed via the puppet_gem provider) via the gem provider?

@jtappa
Copy link
Contributor

jtappa commented Apr 8, 2019

Could someone from @puppetlabs/windows please take a look at this?

@geoffnichols geoffnichols requested a review from a team May 22, 2019 00:10
@shrug shrug requested a review from a team July 22, 2019 21:34
@shrug
Copy link
Contributor

shrug commented Jul 22, 2019

Adding @puppetlabs/night-s-watch to review

@joshcooper
Copy link
Contributor

@tkishel since you added targetable package providers to 5.5.16 and up (which applies to the gem provider), I believe we can close this PR and the ticket PUP-6134, correct?

@joshcooper
Copy link
Contributor

Looks like this is superseded by the targetable provider work in PUP-6488, so I'm going to close this PR. Please reopen if I've got that wrong.

@joshcooper joshcooper closed this Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants