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 => "",
|
:site => "",
|
||||||
:cluster => false,
|
:cluster => false,
|
||||||
:has_key => "",
|
:has_key => "",
|
||||||
|
:template => nil,
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
attr_reader :name, :options, :proc
|
attr_reader :name, :options, :proc
|
||||||
@ -15,8 +16,13 @@ module RubyQA
|
|||||||
@options = DEFAULT_OPTIONS.merge(options)
|
@options = DEFAULT_OPTIONS.merge(options)
|
||||||
@test = test_block
|
@test = test_block
|
||||||
@description = ""
|
@description = ""
|
||||||
if options[:description]
|
if @options[:description]
|
||||||
@description=options[:description]
|
@description=options[:description]
|
||||||
|
@options.delete(:description)
|
||||||
|
end
|
||||||
|
if @options.has_key? :template
|
||||||
|
@template = @options[:template]
|
||||||
|
@options.delete(:template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -40,18 +46,26 @@ module RubyQA
|
|||||||
|
|
||||||
def run (host)
|
def run (host)
|
||||||
test_status = "N/A"
|
test_status = "N/A"
|
||||||
if @test.call(host)
|
context = Hash.new
|
||||||
|
if @test.call(host, context)
|
||||||
test_status = "PASSED"
|
test_status = "PASSED"
|
||||||
else
|
else
|
||||||
test_status = "FAILED"
|
test_status = "FAILED"
|
||||||
end
|
end
|
||||||
@tests[host.name]=test_status
|
@tests[host.name]={
|
||||||
|
:host => host,
|
||||||
|
:status => test_status,
|
||||||
|
:context => context
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def report
|
def report
|
||||||
if @tests.count == 0
|
if @tests.count == 0
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
template = nil
|
||||||
|
|
||||||
|
if @template.nil?
|
||||||
template = ERB.new <<EOF, :trim_mode => '-'
|
template = ERB.new <<EOF, :trim_mode => '-'
|
||||||
==============================================
|
==============================================
|
||||||
Test : "<%= @name %>"
|
Test : "<%= @name %>"
|
||||||
@ -59,11 +73,16 @@ Test : "<%= @name %>"
|
|||||||
Description : "<%= @description %>
|
Description : "<%= @description %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
==============================================
|
==============================================
|
||||||
<% @tests.each do |key,val| -%>
|
<% @tests.each do |key,data| -%>
|
||||||
<%= key %> : <%= val %>
|
<%= key %> : <%= data[:status] %> <% if data[:context].has_key? :note %> (<%= data[:context][:note] %>) <% end %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
else
|
||||||
|
template = @template
|
||||||
|
end
|
||||||
|
|
||||||
template.result(binding)
|
template.result(binding)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user