How to require a specific version of Serverspec for test-kitchen


#1

Hello. I’m pretty new to cookbook testing.

tl;dr – how do I restrict the version of Serverspec within test-kitchen? (if that is in fact a right thing to do).

We had a test-kitchen test integration suite that was working for one of our cookbooks, but today it started breaking. The cookbook converges fine; then the next step is to install Serverspec in order to run the serverspec tests.

...snip -----> Setting up Busser Creating BUSSER_ROOT in /tmp/verifier Creating busser binstub Installing Busser plugins: busser-serverspec Plugin serverspec installed (version 0.5.7) -----> Running postinstall for serverspec plugin Suite path directory /tmp/verifier/suites does not exist, skipping. Transferring files to -----> Running serverspec test suite -----> Installing Serverspec.. Fetching: rspec-support-3.4.1.gem (100%) Fetching: rspec-core-3.4.1.gem (100%) Fetching: diff-lcs-1.2.5.gem (100%) Fetching: rspec-expectations-3.4.0.gem (100%) Fetching: rspec-mocks-3.4.0.gem (100%) Fetching: rspec-3.4.0.gem (100%) Fetching: rspec-its-1.2.0.gem (100%) Fetching: multi_json-1.11.2.gem (100%) Fetching: net-ssh-3.0.1.gem (100%) /opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:533:in `ensure_required_ruby_version_met': net-ssh requires Ruby version >= 2.0. (Gem::InstallError)

Our systems still run ruby 1.9.3. We can’t just upgrade ruby quickly. I’m thinking that today’s Serverspec release of 2.25.0 as some newer dependencies which is just now causing this. (I haven’t verified this by digging into the gemspec of Serverspec 2.25.0).

I’m hoping a reasonable approach to keep our tests working is to restrict Serverspec to 2.24.x. Within our tests (not sure to call it test-kitchen or not), how can I restrict the Serverspec version? I tried this, but it didn’t work:

$ cat my-cookbook/test/integration/helpers/serverspec/spec_helper.rb gem 'serverspec', '= 2.24.3' require 'serverspec'

set :backend, :exec

12/16 01:19[root@the-test-host ~]# find /root/.gem/specs/ | grep -i serverspec
/root/.gem/specs/rubygems.org%443/quick/Marshal.4.8/busser-serverspec-0.5.7.gemspec
/root/.gem/specs/rubygems.org%443/quick/Marshal.4.8/serverspec-2.25.0.gemspec

Thanks in advance!
kallen


#2

Hi Kallen,


#3

Sorry, it seems that Discouse spoils quoted messages. This is what I said:

You need to create a Gemfile. For example

$ cat test/integration/default/serverspec/Gemfile source 'https://rubygems.org' gem 'serverspec', '~> 2.24.0'

The default refers to the name of your test-kitchen suite.


#4

To build on what @zuazo said, you can put that Gemfile in test/integration/helpers/serverspec, it’ll be available in all your test suites rather than just the default one.


#5

Rereading your question, the problem seems to be with the net-ssh gem, so:

$ cat test/integration/helpers/serverspec/Gemfile
gem 'net-ssh', '~> 2.0'

#6

I got it to work. Thank you so much!

When I tried by putting serverspec into the Gemfile, I got this failure:

source 'https://rubygems.org' # gem 'serverspec', '~> 2.24.0' # both this, and gem 'serverspec', '= 2.24.3' # this failed similarly

-----> Running serverspec test suite
-----> Bundle Installing…
run /opt/chef/embedded/bin/ruby /tmp/verifier/gems/bin/bundle install --gemfile /tmp/verifier/suites/serverspec/Gemfile --local || /opt/chef/embedded/bin/ruby /tmp/verifier/gems/bin/bundle install --gemfile /tmp/verifier/suites/serverspec/Gemfile from "."
Don’t run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Could not find gem ‘serverspec (= 2.24.3)’ in any of the gem sources listed in
your Gemfile or available on this machine.
Don’t run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Fetching gem metadata from https://rubygems.org/
Fetching version metadata from https://rubygems.org/
Resolving dependencies…
Using diff-lcs 1.2.5
Using multi_json 1.11.2
Installing net-ssh 3.0.1

   Gem::InstallError: net-ssh requires Ruby version >= 2.0.
   Using net-telnet 0.1.1
   Using rspec-support 3.4.1
   Using sfl 2.2
   Using bundler 1.11.2
   An error occurred while installing net-ssh (3.0.1), and Bundler cannot continue.
   Make sure that `gem install net-ssh -v '3.0.1'` succeeds before bundling.

-----> Installing Serverspec…
/opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:533:in `ensure_required_ruby_version_met’: net-ssh requires Ruby version >= 2.0. (Gem::InstallError)

And then this succeeded:

source 'https://rubygems.org' gem 'net-ssh', '~> 2.0'

-----> Running serverspec test suite
-----> Bundle Installing…
run /opt/chef/embedded/bin/ruby /tmp/verifier/gems/bin/bundle install --gemfile /tmp/verifier/suites/serverspec/Gemfile --local || /opt/chef/embedded/bin/ruby /tmp/verifier/gems/b
in/bundle install --gemfile /tmp/verifier/suites/serverspec/Gemfile from "."
Don’t run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Could not find gem ‘net-ssh (~> 2.0)’ in any of the gem sources listed in your
Gemfile or available on this machine.
Don’t run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Fetching gem metadata from https://rubygems.org/
Fetching version metadata from https://rubygems.org/
Resolving dependencies…
Installing net-ssh 2.9.2
Using bundler 1.11.2
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Use bundle show [gemname] to see where a bundled gem is installed.
-----> Installing Serverspec…
Fetching: rspec-support-3.4.1.gem (100%)
Fetching: rspec-core-3.4.1.gem (100%)
Fetching: diff-lcs-1.2.5.gem (100%)
Fetching: rspec-expectations-3.4.0.gem (100%)
Fetching: rspec-mocks-3.4.0.gem (100%)
Fetching: rspec-3.4.0.gem (100%)
Fetching: rspec-its-1.2.0.gem (100%)
Fetching: multi_json-1.11.2.gem (100%)
Fetching: net-scp-1.2.1.gem (100%)
Fetching: net-telnet-0.1.1.gem (100%)
Fetching: sfl-2.2.gem (100%)
Fetching: specinfra-2.47.0.gem (100%)
Fetching: serverspec-2.25.0.gem (100%)
-----> serverspec installed (version 2.25.0)


#7

Is anyone experiencing the exact same fault but for Windows?

Adding the same Gemfile works for Linux. But not for Windows. I get the output below.
This is using ChefDK 0.6.0 and Chef-client 11.18.6.

This error makes sense as net-ssh does not support Ruby 1.9. This problem is not reproducible with Chef-Client 12 because that
comes with Ruby 2.x. However, our Infrastructure is still using Chef-Client 11.18.6 in
Production. So, as a result our CI still needs to test against it until we migrate fully to Chef Client 12.x

Here is the output

----> Running serverspec test suite
----> Bundle Installing…
run C:/opscode/chef/embedded/bin/ruby C:/Users/vagrant/AppData/Local/Temp/verifier/gems/bin/bundle install --gemfile C:/Users/vagrant/AppData/Local/Temp/verifier/suites/serve
ocal || C:/opscode/chef/embedded/bin/ruby C:/Users/vagrant/AppData/Local/Temp/verifier/gems/bin/bundle install --gemfile C:/Users/vagrant/AppData/Local/Temp/verifier/suites/serverspec

  Could not find gem 'net-ssh (~> 2.0) x86-mingw32' in any of the gem sources
  listed in your Gemfile or available on this machine.
  Fetching gem metadata from https://rubygems.org/.......
  ..
  Resolving dependencies...
  Rubygems 1.8.28 is not threadsafe, so your gems will be installed one at a time. Upgrade to Rubygems 2.1.0 or higher to enable parallel gem installation.

  Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://rubygems.org/gems/net-ssh-2.9.2.gem)
  Using bundler 1.11.2
  An error occurred while installing net-ssh (2.9.2), and Bundler cannot continue.
  Make sure that `gem install net-ssh -v '2.9.2'` succeeds before bundling.

----> Installing Serverspec…
$$$$$ C:/opscode/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:388:in ensure_required_ruby_version_met': net-ssh requires Ruby version >= 2.0. (Gem::InstallError) $$$$$ from C:/opscode/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:156:ininstall’
$$$$$ from C:/opscode/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/dependency_installer.rb:297:in block in install' $$$$$ from C:/opscode/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/dependency_installer.rb:270:ineach’
$$$$$ from C:/opscode/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/dependency_installer.rb:270:in each_with_index' $$$$$ from C:/opscode/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/dependency_installer.rb:270:ininstall’
$$$$$ from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/busser-0.7.1/lib/busser/rubygems.rb:44:in install_gem' $$$$$ from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/busser-0.7.1/lib/busser/helpers.rb:57:ininstall_gem’
$$$$$ from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/busser-serverspec-0.5.7/lib/busser/runner_plugin/serverspec.rb:60:in install_serverspec' $$$$$ from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/busser-serverspec-0.5.7/lib/busser/runner_plugin/serverspec.rb:33:intest’
$$$$$ from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/thor-0.19.0/lib/thor/command.rb:27:in run' $$$$$ from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/thor-0.19.0/lib/thor/invocation.rb:126:ininvoke_command’
$$$$$ from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/thor-0.19.0/lib/thor/invocation.rb:133:in block in invoke_all' $$$$$ from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/thor-0.19.0/lib/thor/invocation.rb:133:ineach’
$$$$$ from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/thor-0.19.0/lib/thor/invocation.rb:133:in map' $$$$$ from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/thor-0.19.0/lib/thor/invocation.rb:133:ininvoke_all’
$$$$$ from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/thor-0.19.0/lib/thor/group.rb:232:in dispatch' $$$$$ from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/thor-0.19.0/lib/thor/invocation.rb:115:ininvoke’
$$$$$ from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/busser-0.7.1/lib/busser/command/test.rb:43:in block in perform' $$$$$ from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/busser-0.7.1/lib/busser/command/test.rb:35:ineach’
$$$$$ from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/busser-0.7.1/lib/busser/command/test.rb:35:in `perform’

The SSL error certificate that is mentioned in log, I found this site and verified the .pem file it refered to was already in on my system

C:\opscode\chefdk\embedded\lib\ruby\site_ruby\2.1.0\rubygems\ssl_certs>gem which rubygems
C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems.rb

C:\opscode\chefdk\embedded\lib\ruby\site_ruby\2.1.0\rubygems\ssl_certs>dir
Directory of C:\opscode\chefdk\embedded\lib\ruby\site_ruby\2.1.0\rubygems\ssl_certs

16/09/2015 10:04 .
16/09/2015 10:04 …
15/05/2015 02:29 1,521 AddTrustExternalCARoot-2048.pem
15/05/2015 02:29 1,952 AddTrustExternalCARoot.pem
15/05/2015 02:29 834 Class3PublicPrimaryCertificationAuthority.pem
15/05/2015 02:29 1,367 DigiCertHighAssuranceEVRootCA.pem
15/05/2015 02:29 1,740 EntrustnetSecureServerCertificationAuthority.pem
15/05/2015 02:29 1,216 GeoTrustGlobalCA.pem