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 62 63 64 65 66 |
# 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() if Process.euid == 0 @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." case plugin(:Dashboard, :update_results) when :running {'status' => 'fail', 'message' => 'Already running'}.to_json when :success {'status' => 'success'}.to_json when :fail {'status' => 'fail', 'message' => "Tests failed to execute. Please see logs"}.to_json else {'status' => 'fail', 'message' => "Unknown status"}.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
121 122 123 124 125 126 127 128 |
# File 'lib/puppetfactory/plugins/dashboard.rb', line 121 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
100 101 102 |
# File 'lib/puppetfactory/plugins/dashboard.rb', line 100 def available_tests() Dir.chdir(@path) { `rake list`.split } rescue [] end |
#tabs(privileged = false) ⇒ Object
68 69 70 71 72 |
# File 'lib/puppetfactory/plugins/dashboard.rb', line 68 def tabs(privileged = false) return unless privileged { 'dashboard' => 'Testing Dashboard' } end |
#test_data ⇒ Object
104 105 106 |
# File 'lib/puppetfactory/plugins/dashboard.rb', line 104 def test_data() JSON.parse(File.read("#{@path}/output/summary.json")) rescue {} end |
#update_results ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/puppetfactory/plugins/dashboard.rb', line 74 def update_results() return :running if @test_running @test_running = true output = nil status = nil Dir.chdir(@path) do case @current_test when 'all', 'summary' output, status = Open3.capture2e('rake', 'generate') else output, status = Open3.capture2e('rake', 'generate', "current_test=#{@current_test}") end end if status.success? $logger.info output else $logger.error output end @test_running = false return status.success? ? :success : :fail end |
#user_test_html(user, result = @current_test) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/puppetfactory/plugins/dashboard.rb', line 108 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 |