Last active
August 29, 2015 14:21
rspec, new version after some help
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat Rakefile | |
require 'rake' | |
require 'rspec/core/rake_task' | |
hosts = %w( | |
atlspf01 | |
atlspf02 | |
atlspf03 | |
atlspf04 | |
) | |
task :spec => 'spec:all' | |
namespace :spec do | |
task :all => hosts.map {|h| 'spec:' + h.split('.')[0] } | |
hosts.each do |host| | |
begin | |
desc "Run serverspec to #{host}" | |
RSpec::Core::RakeTask.new(host) do |t| | |
ENV['TARGET_HOST'] = host | |
t.pattern = "spec/cfengine3/*_spec.rb" | |
end | |
rescue | |
end | |
end | |
end | |
$ cat spec/spec_helper.rb | |
require 'serverspec' | |
require 'net/ssh' | |
set :backend, :ssh | |
if ENV['ASK_SUDO_PASSWORD'] | |
begin | |
require 'highline/import' | |
rescue LoadError | |
fail "highline is not available. Try installing it." | |
end | |
set :sudo_password, ask("Enter sudo password: ") { |q| q.echo = false } | |
else | |
set :sudo_password, ENV['SUDO_PASSWORD'] | |
end | |
host = ENV['TARGET_HOST'] | |
options = Net::SSH::Config.for(host) | |
options[:user] ||= Etc.getlogin | |
set :host, options[:host_name] || host | |
set :ssh_options, options | |
$ cat spec/cfengine3/common_spec.rb | |
require 'spec_helper' | |
describe "All server tests" do | |
before(:each) do | |
puts "ServerSpec tests on [#{ENV['TARGET_HOST']}]" | |
end | |
describe package('cfengine-community') do | |
it { should be_installed } | |
end | |
describe command( '/var/cfengine/bin/cf-promises --version') do | |
its(:stdout) { should match /3\.6\.5/ } | |
end | |
describe service( 'cfengine3' ) do | |
it { should be_enabled } | |
end | |
for proc in [ 'execd', 'serverd', 'monitord' ] | |
describe process( "cf-#{proc}" ) do | |
it { should be_running } | |
end | |
end | |
describe port(5308) do | |
it { should be_listening } | |
end | |
end | |
Getting closer. Now works though all host, but: | |
1. how to make it NOT prompt for password, because SSH here passes tokens? Required net::ssh:kerberos, but can use ssh keys instead. | |
2. Stops at first failure rather than working through all hosts. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment