Class: Puppetfactory::Plugins::Dashboard
- Inherits:
-
Puppetfactory::Plugins
- Object
- Puppetfactory::Plugins
- Puppetfactory::Plugins::Dashboard
- Defined in:
- lib/puppetfactory/plugins/dashboard.rb
Instance Attribute Summary collapse
-
#current_test ⇒ Object
Returns the value of attribute current_test.
Attributes inherited from Puppetfactory::Plugins
Class Method Summary collapse
-
.test_completion(data) ⇒ Object
class method so the template can call it.
Instance Method Summary collapse
- #available_tests ⇒ Object
-
#initialize(options) ⇒ Dashboard
constructor
A new instance of Dashboard.
- #tabs(privileged = false) ⇒ Object
- #test_data ⇒ Object
- #update_results ⇒ Object
- #user_test_html(user, result = @current_test) ⇒ Object
Constructor Details
#initialize(options) ⇒ Dashboard
Returns a new instance of Dashboard.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/puppetfactory/plugins/dashboard.rb', line 6 def initialize() super() return unless [:puppetfactory] @server = [:puppetfactory] @path = [:dashboard_path] || '/etc/puppetfactory/dashboard' @interval = [:dashboard_interval] || 5 * 60 # test interval in seconds # TODO: finish a real mutex implementation and avoid the current (small) race condition #set :semaphore, Mutex.new @current_test = 'summary' @test_running = false start_testing() @server.get '/dashboard' do protected! # we can't call methods directly, because this block will execute in the scope # of the Puppetfactory server. Use the plugin system instead. @current = plugin(:Dashboard, :current_test) @available = plugin(:Dashboard, :available_tests) @test_data = plugin(:Dashboard, :test_data) return 'No testing data' unless @available and @test_data erb :dashboard end @server.get '/dashboard/details/:user' do |user| plugin(:Dashboard, :user_test_html, user) end @server.get '/dashboard/details/:user/:result' do |user, result| plugin(:Dashboard, :user_test_html, user, result) end @server.get '/dashboard/update' do $logger.info "Triggering dashboard update." if plugin(:Dashboard, :update_results) {'status' => 'success'}.to_json else {'status' => 'fail', 'message' => 'Already running'}.to_json end end @server.get '/dashboard/set/:current' do |current| $logger.info "Setting current test to #{current}." plugin(:Dashboard, :current_test=, current) {'status' => 'success'}.to_json end end |
Instance Attribute Details
#current_test ⇒ Object
Returns the value of attribute current_test.
4 5 6 |
# File 'lib/puppetfactory/plugins/dashboard.rb', line 4 def current_test @current_test end |
Class Method Details
.test_completion(data) ⇒ Object
class method so the template can call it
107 108 109 110 111 112 113 114 |
# File 'lib/puppetfactory/plugins/dashboard.rb', line 107 def self.test_completion(data) total = data['example_count'] rescue 0 failed = data['failure_count'] rescue 0 passed = total - failed percent = passed.to_f / total * 100.0 rescue 0 [total, passed, percent] end |
Instance Method Details
#available_tests ⇒ Object
86 87 88 |
# File 'lib/puppetfactory/plugins/dashboard.rb', line 86 def available_tests() Dir.chdir(@path) { `rake list`.split } rescue [] end |
#tabs(privileged = false) ⇒ Object
63 64 65 66 67 |
# File 'lib/puppetfactory/plugins/dashboard.rb', line 63 def tabs(privileged = false) return unless privileged { 'dashboard' => 'Testing Dashboard' } end |
#test_data ⇒ Object
90 91 92 |
# File 'lib/puppetfactory/plugins/dashboard.rb', line 90 def test_data() JSON.parse(File.read("#{@path}/output/summary.json")) rescue {} end |
#update_results ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/puppetfactory/plugins/dashboard.rb', line 69 def update_results() return false if @test_running @test_running = true Dir.chdir(@path) do case @current_test when 'all', 'summary' system('rake', 'generate') else system('rake', 'generate', "current_test=#{@current_test}") end end @test_running = false true end |
#user_test_html(user, result = @current_test) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/puppetfactory/plugins/dashboard.rb', line 94 def user_test_html(user, result = @current_test) begin if result == 'summary' File.read("#{@path}/output/html/#{user}.html") else File.read("#{@path}/output/html/#{result}/#{user}.html") end rescue Errno::ENOENT 'No results found' end end |