Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue when using rspec-puppet when puppetlabs-chocolatey is a dependency #691

Open
lmayorga1980 opened this issue May 25, 2018 · 9 comments

Comments

@lmayorga1980
Copy link

lmayorga1980 commented May 25, 2018

rspec-puppet: 2.6.11

    Failure/Error:
       rescue Win32::Registry::Error => e
         value = nil
     
     NameError:
       uninitialized constant RSpec::Puppet::Win32::Registry::Error
       Did you mean?  KeyError
                      RSpec::Puppet::Errors
                      IOError
                      Errno
     # ./spec/fixtures/modules/r10k/chocolatey/lib/puppet_x/chocolatey/chocolatey_install.rb:16:in `rescue in install_path'
     # ./spec/fixtures/modules/r10k/chocolatey/lib/puppet_x/chocolatey/chocolatey_install.rb:11:in `install_path'
     # ./spec/fixtures/modules/r10k/chocolatey/lib/puppet_x/chocolatey/chocolatey_version.rb:12:in `version'
     # ./spec/fixtures/modules/r10k/chocolatey/lib/puppet_x/chocolatey/chocolatey_common.rb:53:in `choco_version'
     # ./spec/fixtures/modules/r10k/chocolatey/lib/puppet/provider/chocolateysource/windows.rb:115:in `validate'
     # ./spec/fixtures/modules/r10k/chocolatey/lib/puppet/type/chocolateysource.rb:116:in `block (2 levels) in <top (required)>'
     # /home/user/.gem/ruby/2.3.0/gems/puppet-5.3.3/lib/puppet/type.rb:2398:in `initialize'
     # /home/user/.gem/ruby/2.3.0/gems/puppet-5.3.3/lib/puppet/resource.rb:460:in `new'
     # /home/user/.gem/ruby/2.3.0/gems/puppet-5.3.3/lib/puppet/resource.rb:460:in `to_ral'
     # /home/user/.gem/ruby/2.3.0/gems/puppet-5.3.3/lib/puppet/resource/catalog.rb:625:in `block in to_catalog'
     # /home/user/.gem/ruby/2.3.0/gems/puppet-5.3.3/lib/puppet/resource/catalog.rb:617:in `each'
     # /home/user/.gem/ruby/2.3.0/gems/puppet-5.3.3/lib/puppet/resource/catalog.rb:617:in `to_catalog'
     # /home/user/.gem/ruby/2.3.0/gems/puppet-5.3.3/lib/puppet/resource/catalog.rb:498:in `to_ral'
     # /home/user/.gem/ruby/2.3.0/gems/rspec-puppet-2.6.11/lib/rspec-puppet/matchers/compile.rb:142:in `cycles_found?'
     # /home/user/.gem/ruby/2.3.0/gems/rspec-puppet-2.6.11/lib/rspec-puppet/matchers/compile.rb:25:in `matches?'
     # ./spec/classes/roles/role_appserverwin_spec.rb:26:in `block (5 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # NoMethodError:
     #   private method `open' called for 2147483650:Fixnum
     #   ./spec/fixtures/modules/r10k/chocolatey/lib/puppet_x/chocolatey/chocolatey_install.rb:13:in `install_path'

@brettjacobson
Copy link

@lmayorga1980 this error is when you are executing ON linux, for Windows OS, correct? I'm having a very very similar problem. My test works all fine when I execute ON windows, but the same test fails with this type of error when executing on a host that is Linux.

@lmayorga1980
Copy link
Author

@brettjacobson correct! 👍

@brettjacobson
Copy link

I believe this is a problem related to the use of the operatingsystem fact. when the fact is set to "windows" my test encounters this error; which if you are using rspec-puppet-facts it will set. If you do not use the rspec-puppet-facts os_facts, but set the fact to windows yourself, you'll engage a different error in chocolatey module itself.

So far my workaround is to NOT use os_facts from rspect-puppet-facts, but define my facts as follows in my test:

      let(:facts) do
        {
          kernel: 'windows',
          osfamily: 'windows',
          # operatingsystem: 'NOTwindows', # this short-circuits the puppetlabs-registry module bug
          architecture: 'x64',
          chocolateyversion: '0.10.11',
          choco_install_path: 'C:\ProgramData\chocolatey',
          path: 'C:\temp',
        }
      end

I have to leave operatingsystem as completely undefined, to short-circuit the chocolatey problem and the registry module problem, both.

@brettjacobson
Copy link

I suspect this is the wrong repo for this issue, but not sure what the correct place is.

@lmayorga1980
Copy link
Author

@brettjacobson I believe I created this https://github.com/lmayorga1980/puppet-module-chrome as a way of testing my rspec-puppet and beaker version and so far it does not fail anymore.

Seems like the problem has been fixed.

gem list --local | grep rspec
beaker-rspec (6.2.4)
rspec (3.8.0)
rspec-core (3.8.0)
rspec-expectations (3.8.1)
rspec-its (1.2.0)
rspec-mocks (3.8.0)
rspec-puppet (2.6.15)
rspec-puppet-facts (1.9.0)
rspec-puppet-utils (3.4.0)
rspec-support (3.8.0)
serverspec (2.41.3)

@jorhett
Copy link

jorhett commented Mar 12, 2019

This is still occurring almost a year later. The code in question which fails is https://github.com/puppetlabs/puppetlabs-chocolatey/blob/master/lib/puppet_x/chocolatey/chocolatey_install.rb#L8-L19 which is why changing the OS to something other than windows works around it.

It would appear that rspec's win32/registry doesn't handle Win32::Registry::Error nor does it allow inspecting the environment with

hive = Win32::Registry::HKEY_LOCAL_MACHINE
hive.open('SYSTEM\CurrentControlSet\Control\Session Manager\Environment', Win32::Registry::KEY_READ | 0x100) do |reg|
              value = reg['ChocolateyInstall']
end

@jorhett
Copy link

jorhett commented Mar 12, 2019

FWIW, this stub in the chocolatey module itself seems to resolve the problem https://github.com/chocolatey/puppet-chocolatey/blob/master/spec/unit/facter/choco_install_path_spec.rb#L10

Honestly I think that this is a bug in the chocolatey function, and this issue should be opened there: https://github.com/chocolatey/puppet-chocolatey/issues

@rnelson0
Copy link

@rodjek and @ferventcoder, do the two of you have insight into which project should address this issue? It's still occurring with the rspec-puppet v2.7.8 (via PDK 1.15.0) and puppetlabs/chocolatey v5.0.1.

@rodjek
Copy link
Owner

rodjek commented Feb 29, 2020

@rnelson0 I think this should be handled in the chocolatey module, updating the conditional so that it detects if its being used inside rspec-puppet with something like (defined?(RSpec::Puppet) && RSpec::Puppet.rspec_puppet_example?) and short circuiting the windows specific code.

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

No branches or pull requests

5 participants