Skip to content

Commit

Permalink
Introduce BEAKER_HYPERVISOR
Browse files Browse the repository at this point in the history
Beaker already knows how to generate hosts on the fly using
beaker-hostgenrator. The problem is that there's no way to choose the
default hypervisor. This means you always specify the long form. Using
an environment variable we can simplify configs.
  • Loading branch information
ekohl committed Oct 9, 2018
1 parent 4bea5d5 commit cbecea0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/tutorials/lets_write_a_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ What needs to happen in this test:

This command will generate a host file for our system under test (SUT). It will use vmpooler as hypervisor for the host. Please check out [this](https://github.com/puppetlabs/beaker/tree/master/docs/how_to/hypervisors) doc to learn more about hypervisors for beaker.

Note that if it doesn't exist, it will be generated on the fly. This can also be influenced by using `BEAKER_HYPERVISOR` to choose the default hypervisor.

## Install and run HTTPD

Make a file named `install.rb` and put the following code into it:
Expand Down
5 changes: 4 additions & 1 deletion lib/beaker/options/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,11 @@ def parse_hosts_options
$stdout.puts dne_message
require 'beaker-hostgenerator'

host_generator_options = [ @options[:hosts_file] ]
host_generator_options += [ '--hypervisor', ENV['BEAKER_HYPERVISOR'] ] if ENV['BEAKER_HYPERVISOR']

hosts_file_content = begin
bhg_cli = BeakerHostGenerator::CLI.new( [ @options[:hosts_file] ] )
bhg_cli = BeakerHostGenerator::CLI.new(host_generator_options)
bhg_cli.execute
rescue BeakerHostGenerator::Exceptions::Error,
BeakerHostGenerator::Exceptions::InvalidNodeSpecError => error
Expand Down
33 changes: 33 additions & 0 deletions spec/beaker/options/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,46 @@ def mock_out_parsing
).and_return( cli_execute_return )
expect( BeakerHostGenerator::CLI ).to receive(
:new
).with(
[ 'notafile.yml' ]
).and_return( mock_beaker_hostgenerator_cli )
allow( Beaker::Options::HostsFileParser ).to receive(
:parse_hosts_string
).with( cli_execute_return )
parser.parse_hosts_options
end

it 'calls beaker-hostgenerator to get hosts information with a default hypervisor' do
old_beaker_hypervisor = ENV['BEAKER_HYPERVISOR']
begin
ENV['BEAKER_HYPERVISOR'] = 'docker'

parser.instance_variable_set( :@options, {
:hosts_file => 'notafile.yml'
} )
allow( Beaker::Options::HostsFileParser ).to receive(
:parse_hosts_file
).and_raise( Errno::ENOENT )

mock_beaker_hostgenerator_cli = Object.new
cli_execute_return = 'job150865'
expect( mock_beaker_hostgenerator_cli ).to receive(
:execute
).and_return( cli_execute_return )
expect( BeakerHostGenerator::CLI ).to receive(
:new
).with(
[ 'notafile.yml', '--hypervisor', 'docker' ]
).and_return( mock_beaker_hostgenerator_cli )
allow( Beaker::Options::HostsFileParser ).to receive(
:parse_hosts_string
).with( cli_execute_return )
parser.parse_hosts_options
ensure
ENV['BEAKER_HYPERVISOR'] = old_beaker_hypervisor
end
end

it 'sets the :hosts_file_generated flag to signal others when needed' do
options_test = {
:hosts_file => 'not_a_file.yml'
Expand Down

0 comments on commit cbecea0

Please sign in to comment.