Skip to content

Commit

Permalink
Persist hosts throughout tests
Browse files Browse the repository at this point in the history
The spec helper initializes hosts before the test suite is begun. The
hosts array is assigned to an RSpec setting to persist access across
testing.
  • Loading branch information
Alice Nodelman committed Nov 6, 2013
1 parent 2c7893d commit 2a4d973
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Gemfile.lock
.bundle
*.swp
9 changes: 4 additions & 5 deletions lib/beaker-rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def config

def provision
@network_manager = Beaker::NetworkManager.new(@options, @logger)
@hosts = @network_manager.provision
RSpec.configuration.hosts = @network_manager.provision
end

def validate
Beaker::Utils::Validator.validate(@hosts, @logger)
Beaker::Utils::Validator.validate(RSpec.configuration.hosts, @logger)
end

def setup(args = [])
Expand All @@ -30,14 +30,13 @@ def setup(args = [])
@options[:debug] = true
@logger = Beaker::Logger.new(@options)
@options[:logger] = @logger
@hosts = []
RSpec.configuration.hosts = []
end

def hosts
@hosts
RSpec.configuration.hosts
end


def cleanup
@network_manager.cleanup
end
Expand Down
22 changes: 12 additions & 10 deletions sample.cfg
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
HOSTS:
pe-ubuntu-lucid:
ubuntu-10-04-4-x64-master:
roles:
- master
- agent
- dashboard
- database
vmname : pe-ubuntu-lucid
platform: ubuntu-10.04-i386
snapshot : clean-w-keys
hypervisor : fusion
pe-centos6:
platform: ubuntu-10.04-amd64
hypervisor : vagrant
box: ubuntu-server-10044-x64-vbox4210
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-10044-x64-vbox4210.box
ip : 192.168.20.20
ubuntu-10-04-4-x64-agent:
roles:
- agent
vmname : pe-centos6
platform: el-6-i386
hypervisor : fusion
snapshot: clean-w-keys
platform: ubuntu-10.04-amd64
hypervisor : vagrant
box: ubuntu-server-10044-x64-vbox4210
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-10044-x64-vbox4210.box
ip : 192.168.21.21
CONFIG:
nfs_server: none
consoleport: 443
7 changes: 7 additions & 0 deletions spec/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module BeakerRSpec::Helpers
include Beaker::DSL

def hosts
self.class.hosts
end
end
36 changes: 24 additions & 12 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
require "rspec/expectations"
require "beaker-rspec"
require 'beaker-rspec'
require 'helpers'

include BeakerRSpec

RSpec.configure do |c|
# Enable color
c.tty = true

# Define persistant hosts setting
c.add_setting :hosts

RSpec.configure do |config|
# System specific config
config.include BeakerRSpec
c.extend BeakerRSpec::Helpers #to allow dsl access outside tests

config.before(:all) do
setup(['--hosts', 'sample.cfg'])
provision
validate
end
# Defined target nodeset
nodeset = ENV['RSPEC_SET'] || 'sample.cfg'
preserve = ENV['RSPEC_DESTROY'] ? '--preserve-hosts' : ''
fresh_nodes = ENV['RSPEC_PROVISION'] ? '' : '--no-provision'

config.after(:all) do
cleanup
end
# Configure all nodes in nodeset
c.setup([preserve, fresh_nodes, '--type','git','--hosts', nodeset])
c.provision
c.validate

# Destroy nodes if no preserve hosts
c.after :suite do
c.cleanup
end
end

0 comments on commit 2a4d973

Please sign in to comment.