Added options template feature
This commit is contained in:
parent
994f8a906b
commit
e3910e3c09
36
lib/test
36
lib/test
@ -1,36 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require './rubyqa'
|
||||
|
||||
include RubyQA
|
||||
$Manager = Manager.new
|
||||
|
||||
host = Host.new(
|
||||
:ip => '127.0.0.1',
|
||||
:user => 'tristan',
|
||||
:cluster => true
|
||||
)
|
||||
|
||||
Manager.new_test("hostname in /etc/hostname") {|host|
|
||||
hostname = host.exec('cat /etc/hostname').strip
|
||||
facts = host.resources['facts'].data
|
||||
facts['networking']['hostname'] == hostname
|
||||
}
|
||||
|
||||
Manager.new_test("hostname in /etc/hosts", :cluster => true ) {|host|
|
||||
facts = host.resources['facts'].data
|
||||
hostname = facts['networking']['hostname']
|
||||
hosts = host.exec('cat /etc/hosts')
|
||||
match_regex = /127\.0\.0\.1.+#{hostname.downcase}/
|
||||
hosts.match? match_regex
|
||||
}
|
||||
|
||||
Manager.new_test("Has user tristan") do |host|
|
||||
passwd_file = host.exec("cat /etc/passwd")
|
||||
passwd_file.match? /tristan.*/
|
||||
end
|
||||
|
||||
|
||||
$Manager.add_host(host)
|
||||
$Manager.run_tests
|
||||
$Manager.report
|
29
lib/test.rb
29
lib/test.rb
@ -5,6 +5,7 @@ module RubyQA
|
||||
:site => "",
|
||||
:cluster => false,
|
||||
:has_key => "",
|
||||
:template => nil,
|
||||
}.freeze
|
||||
|
||||
attr_reader :name, :options, :proc
|
||||
@ -15,8 +16,13 @@ module RubyQA
|
||||
@options = DEFAULT_OPTIONS.merge(options)
|
||||
@test = test_block
|
||||
@description = ""
|
||||
if options[:description]
|
||||
if @options[:description]
|
||||
@description=options[:description]
|
||||
@options.delete(:description)
|
||||
end
|
||||
if @options.has_key? :template
|
||||
@template = @options[:template]
|
||||
@options.delete(:template)
|
||||
end
|
||||
end
|
||||
|
||||
@ -40,18 +46,26 @@ module RubyQA
|
||||
|
||||
def run (host)
|
||||
test_status = "N/A"
|
||||
if @test.call(host)
|
||||
context = Hash.new
|
||||
if @test.call(host, context)
|
||||
test_status = "PASSED"
|
||||
else
|
||||
test_status = "FAILED"
|
||||
end
|
||||
@tests[host.name]=test_status
|
||||
@tests[host.name]={
|
||||
:host => host,
|
||||
:status => test_status,
|
||||
:context => context
|
||||
}
|
||||
end
|
||||
|
||||
def report
|
||||
if @tests.count == 0
|
||||
return
|
||||
end
|
||||
template = nil
|
||||
|
||||
if @template.nil?
|
||||
template = ERB.new <<EOF, :trim_mode => '-'
|
||||
==============================================
|
||||
Test : "<%= @name %>"
|
||||
@ -59,11 +73,16 @@ Test : "<%= @name %>"
|
||||
Description : "<%= @description %>
|
||||
<% end -%>
|
||||
==============================================
|
||||
<% @tests.each do |key,val| -%>
|
||||
<%= key %> : <%= val %>
|
||||
<% @tests.each do |key,data| -%>
|
||||
<%= key %> : <%= data[:status] %> <% if data[:context].has_key? :note %> (<%= data[:context][:note] %>) <% end %>
|
||||
<% end -%>
|
||||
|
||||
EOF
|
||||
|
||||
else
|
||||
template = @template
|
||||
end
|
||||
|
||||
template.result(binding)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user