voxpupuli / beaker

Puppet Acceptance Testing Harness
https://groups.google.com/forum/#!forum/puppet-beaker
Apache License 2.0
367 stars 325 forks source link

Docker Hypervisor fails with BEAKER_provision=no #426

Closed leoc closed 10 years ago

leoc commented 10 years ago

Hi, first let me appreciate beaker. It is amazingly helpful. :+1:

I have switched from vagrant to docker. I like how the Docker images can be based on other images. I would like to create a simple image once with BEAKER_destroy=no. On further runs with BEAKER_destroy=no BEAKER_provision=no a new container should be created without having to run all those necessary apt-get calls.

But when I run BEAKER_destroy=no BEAKER_provision=no rake acceptance I get:

Hypervisor for debian-7-4 is none
Beaker::Hypervisor, found some none boxes to create

debian-7-4 17:24:13$  dpkg -s curl  
Warning: Try 1 -- Host debian-7-4 unreachable: getaddrinfo: Name or service not known
Warning: Trying again in 1 seconds
Warning: Try 2 -- Host debian-7-4 unreachable: getaddrinfo: Name or service not known
Warning: Trying again in 1 seconds
Warning: Try 3 -- Host debian-7-4 unreachable: getaddrinfo: Name or service not known
Warning: Trying again in 2 seconds
Warning: Try 4 -- Host debian-7-4 unreachable: getaddrinfo: Name or service not known
Warning: Trying again in 3 seconds
Warning: Try 5 -- Host debian-7-4 unreachable: getaddrinfo: Name or service not known
Warning: Trying again in 5 seconds
Warning: Try 6 -- Host debian-7-4 unreachable: getaddrinfo: Name or service not known
Warning: Trying again in 8 seconds
Warning: Try 7 -- Host debian-7-4 unreachable: getaddrinfo: Name or service not known
Warning: Trying again in 13 seconds
Warning: Try 8 -- Host debian-7-4 unreachable: getaddrinfo: Name or service not known
Warning: Trying again in 21 seconds
Warning: Try 9 -- Host debian-7-4 unreachable: getaddrinfo: Name or service not known
Warning: Trying again in 34 seconds
Warning: Try 10 -- Host debian-7-4 unreachable: getaddrinfo: Name or service not known
Warning: Trying again in 55 seconds
Warning: Try 11 -- Host debian-7-4 unreachable: getaddrinfo: Name or service not known
Warning: Trying again in 89 seconds
Failed to connect to debian-7-4
Failed: errored in validate
#<SocketError: getaddrinfo: Name or service not known>
/home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-rspec-2.2.6/lib/beaker-rspec/spec_helper.rb:41
/home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-rspec-2.2.6/lib/beaker-rspec/spec_helper.rb:5
/home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-rspec-2.2.6/lib/beaker-rspec.rb:5
/home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-rspec-2.2.6/lib/beaker-rspec.rb:5
/home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-rspec-2.2.6/lib/beaker-rspec.rb:1
/home/arthur/projects/puppet/puppet-puma/spec/spec_helper_acceptance.rb:1
/home/arthur/projects/puppet/puppet-puma/spec/spec_helper_acceptance.rb:1
/home/arthur/projects/puppet/puppet-puma/spec/acceptance/puma__app_spec.rb:1
/home/arthur/projects/puppet/puppet-puma/spec/acceptance/puma__app_spec.rb:1
/home/arthur/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/transport/session.rb:70:in `initialize': getaddrinfo: Name or service not known (SocketError)
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/transport/session.rb:70:in `open'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/transport/session.rb:70:in `block in initialize'
    from /home/arthur/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/timeout.rb:91:in `block in timeout'
    from /home/arthur/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/timeout.rb:35:in `block in catch'
    from /home/arthur/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/timeout.rb:35:in `catch'
    from /home/arthur/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/timeout.rb:35:in `catch'
    from /home/arthur/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/timeout.rb:106:in `timeout'
    from /home/arthur/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/timeout.rb:127:in `timeout'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh/transport/session.rb:67:in `initialize'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh.rb:202:in `new'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/net-ssh-2.9.1/lib/net/ssh.rb:202:in `start'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/ssh_connection.rb:41:in `connect'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/ssh_connection.rb:32:in `connect'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/host.rb:196:in `connection'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/host.rb:224:in `block in exec'
    from /home/arthur/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/host.rb:223:in `exec'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/host/unix/pkg.rb:30:in `check_for_package'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/host_prebuilt_steps.rb:94:in `block (2 levels) in validate_host'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/host_prebuilt_steps.rb:93:in `each'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/host_prebuilt_steps.rb:93:in `block in validate_host'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/shared/host_manager.rb:74:in `run_block_on'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/shared/host_manager.rb:71:in `block in run_block_on'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/shared/host_manager.rb:70:in `map'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/shared/host_manager.rb:70:in `run_block_on'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/dsl/patterns.rb:32:in `block_on'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/host_prebuilt_steps.rb:84:in `validate_host'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/hypervisor.rb:99:in `validate'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/network_manager.rb:61:in `block in validate'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/network_manager.rb:60:in `each_key'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-1.17.4/lib/beaker/network_manager.rb:60:in `validate'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-rspec-2.2.6/lib/beaker-rspec/beaker_shim.rb:36:in `validate'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-rspec-2.2.6/lib/beaker-rspec/spec_helper.rb:41:in `block in <top (required)>'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.99.2/lib/rspec/core.rb:154:in `configure'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-rspec-2.2.6/lib/beaker-rspec/spec_helper.rb:5:in `<top (required)>'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-rspec-2.2.6/lib/beaker-rspec.rb:5:in `require'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-rspec-2.2.6/lib/beaker-rspec.rb:5:in `<module:BeakerRSpec>'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/beaker-rspec-2.2.6/lib/beaker-rspec.rb:1:in `<top (required)>'
    from /home/arthur/projects/puppet/puppet-puma/spec/spec_helper_acceptance.rb:1:in `require'
    from /home/arthur/projects/puppet/puppet-puma/spec/spec_helper_acceptance.rb:1:in `<top (required)>'
    from /home/arthur/projects/puppet/puppet-puma/spec/acceptance/puma__app_spec.rb:1:in `require'
    from /home/arthur/projects/puppet/puppet-puma/spec/acceptance/puma__app_spec.rb:1:in `<top (required)>'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `load'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `block in load_spec_files'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `each'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `load_spec_files'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:18:in `run'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:103:in `run'
    from /home/arthur/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:17:in `block in autorun'
/home/arthur/.rvm/rubies/ruby-2.1.1/bin/ruby -S rspec spec/acceptance failed

That is how my default.yml looks like:

HOSTS:
  debian-7-4:
    platform: debian-7.4-x64
    image: debian:7.4
    hypervisor: docker
CONFIG:
   type: foss

Is there no way to avoid the creation of a new image each run?

EDIT: Maybe I am misunderstanding things. But as far as I can see destroy really stops the current container and then deletes the image? Whereas provision creates the image and runs the necessary apt-get calls. Shouldn't those two steps be split up into something like create image, start container from image, stop and destroy container and destroy container and images. I think the two steps in the middle should not be part of provision and destroy, no?

electrical commented 10 years ago

hi,

the container always needs to be destroyed but the image can be preserved by enabling this option ( see example in my nodeset configs ) https://github.com/elasticsearch/puppet-elasticsearch/blob/master/spec/acceptance/nodesets/centos-6-x64.yml#L14

leoc commented 10 years ago

Alright, thank you. I added this to the wiki.

Still, when I use that command and remove the BEAKER env variables beaker seems to run the following commands every run.

apt-get update
apt-get install --force-yes  -y curl
apt-get install --force-yes  -y ntpdate
apt-get install --force-yes  -y lsb-release

Shouldn't that be part of the image creation process, which should only run once unless/until I delete the image? Or might that be some problem with my projects spec_helper_acceptance.rb? It looks like that:

require 'beaker-rspec'
require 'pry'

hosts.each do |host|
  # install_package host, 'rubygems'
  # on host, 'DEBIAN_FRONTEND=noninteractive apt-get install --yes -q openssl libssl-dev'
  # on host, 'gem install puppet --no-ri --no-rdoc'
  on host, "mkdir -p #{host['distmoduledir']}"
end

RSpec.configure do |c|
  # Project root
  proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))

  # Readable test descriptions
  c.formatter = :documentation

  # Configure all nodes in nodeset
  c.before :suite do
    # Install module
    puppet_module_install(:source => proj_root, :module_name => 'puma')
  end
end
electrical commented 10 years ago

Hi,

Things that should in the image you can do with this: https://github.com/elasticsearch/puppet-elasticsearch/blob/master/spec/acceptance/nodesets/centos-6-x64.yml#L11-L13

leoc commented 10 years ago

I know that. I am just wondering, why every run of the rake task is executing:

apt-get update
apt-get install --force-yes  -y curl
apt-get install --force-yes  -y ntpdate
apt-get install --force-yes  -y lsb-release

Those have not been defined by my projects configuration. Or so I suppose. :-) And I think they should not be run by beaker but by the image creation process. Isn't it? (At least when using the docker hypervisor)

electrical commented 10 years ago

Ah, those are in beaker it self in the pre-build steps. That's to ensure that they will be installed no matter what.

electrical commented 10 years ago

See https://github.com/puppetlabs/beaker/blob/master/lib/beaker/host_prebuilt_steps.rb#L13-L16

leoc commented 10 years ago

Ah! I understand.

As I am not into the beaker development (yet :-). What do you think about moving those concerns into the docker image creation process when using docker?

I'd love to create a pull request. My solution would be to not install the packages from the prebuilt steps when using docker and just adding the needed packages to https://github.com/puppetlabs/beaker/blob/master/lib/beaker/hypervisor/docker.rb#L96 Do you have any hints on that?

I think this would speed up the execution of specs tremendously.

leoc commented 10 years ago

I looked again. The validate_host method does check whether a package is installed. So I think installing those packages per default in beakers docker code would suffice. I will have a try and request a pull.

Thank you for your help on this. :+1:

electrical commented 10 years ago

Hi,

The packages are setup by default unrelated to which hyper-visor you use. This is to ensure that the required packages are installed even if the base image that is used have it installed or not. I doubt it will have much use to send a PR for this to be very honest.

leoc commented 10 years ago

Hi again,

As far as I can see those packages are mandatory, as are the packages here: https://github.com/puppetlabs/beaker/blob/master/lib/beaker/hypervisor/docker.rb#L115

Beaker always creates a new image; installing openssh. Why not simply install those packages there too? It speeds up the execution and one does not have to add those packages to the projects host config manually. And it would not break other hypervisors.

electrical commented 10 years ago

Hi,

Sorry that i miss understood you. Yeah it makes sense to put them in that step. I've put them in my nodeset files.