-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3ac41b
commit 1f155b2
Showing
4 changed files
with
117 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
gem 'rake' | ||
gem 'serverspec' |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'rake' | ||
require 'rspec/core/rake_task' | ||
|
||
suites = Dir.glob('*').select{|entry| File.directory?(entry) } | ||
|
||
class ServerspecTask < RSpec::Core::RakeTask | ||
|
||
attr_accessor :target | ||
|
||
def spec_command | ||
|
||
if target.nil? | ||
puts "specify either env TARGET_HOST or target_host=" | ||
exit 1 | ||
end | ||
|
||
cmd = super | ||
"env TARGET_HOST=#{target} STANDALONE_SPEC=true #{cmd} --format documentation --no-profile" | ||
end | ||
|
||
end | ||
|
||
namespace :serverspec do | ||
suites.each do |suite| | ||
desc "Run serverspec suite #{suite}" | ||
ServerspecTask.new(suite.to_sym) do |t| | ||
t.rspec_opts = "--no-color --format html --out report.html" if ENV['format'] == 'html' | ||
t.target = ENV['TARGET_HOST'] || ENV['target_host'] | ||
t.ruby_opts = "-I #{suite}/serverspec" | ||
t.pattern = "#{suite}/serverspec/*_spec.rb" | ||
end | ||
end | ||
end | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,56 @@ | ||
require 'serverspec' | ||
require 'pathname' | ||
if ENV['STANDALONE_SPEC'] | ||
|
||
include Serverspec::Helper::Exec | ||
include Serverspec::Helper::DetectOS | ||
require 'serverspec' | ||
require 'pathname' | ||
require 'net/ssh' | ||
require 'highline/import' | ||
|
||
RSpec.configure do |c| | ||
c.before :all do | ||
c.os = backend(Serverspec::Commands::Base).check_os | ||
include Serverspec::Helper::Ssh | ||
include Serverspec::Helper::DetectOS | ||
|
||
RSpec.configure do |c| | ||
|
||
if ENV['ASK_SUDO_PASSWORD'] | ||
c.sudo_password = ask('Enter sudo password: ') { |q| q.echo = false } | ||
else | ||
c.sudo_password = ENV['SUDO_PASSWORD'] | ||
end | ||
|
||
options = {} | ||
|
||
if ENV['ASK_LOGIN_PASSWORD'] | ||
options[:password] = ask("\nEnter login password: ") { |q| q.echo = false } | ||
else | ||
options[:password] = ENV['LOGIN_PASSWORD'] | ||
end | ||
|
||
if ENV['ASK_LOGIN_USERNAME'] | ||
user = ask("\nEnter login username: ") { |q| q.echo = false } | ||
else | ||
user = ENV['LOGIN_USERNAME'] || ENV['user'] || Etc.getlogin | ||
end | ||
|
||
if user.nil? | ||
puts 'specify login user env LOGIN_USERNAME= or user=' | ||
exit 1 | ||
end | ||
|
||
c.host = ENV['TARGET_HOST'] | ||
options.merge(Net::SSH::Config.for(c.host)) | ||
c.ssh = Net::SSH.start(c.host, user, options) | ||
c.os = backend.check_os | ||
|
||
end | ||
|
||
else | ||
require 'serverspec' | ||
|
||
include Serverspec::Helper::Exec | ||
include Serverspec::Helper::DetectOS | ||
|
||
RSpec.configure do |c| | ||
c.before :all do | ||
c.path = '/sbin:/usr/sbin' | ||
end | ||
end | ||
end |