Class: PuppetBox::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/puppetbox/result.rb

Constant Summary collapse

PS_OK =

OK - no errors encountered

0
PS_NOT_IDEMPOTENT =

Puppet indicicated changes made on second run

1
PS_ERROR =

Error(s) encountered while running puppet

2

Instance Method Summary collapse

Constructor Details

#initializeResult

Returns a new instance of Result.



17
18
19
# File 'lib/puppetbox/result.rb', line 17

def initialize()
  @report = []
end

Instance Method Details

#messages(run = -1)) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/puppetbox/result.rb', line 70

def messages(run=-1)
  messages = []
  if run < 0
    # all NESTED in order of report
    @report.each { |r|
      messages << r[:messages]
    }
  else
    if run < @report.size
      messages << @report[run][:messages]
    else
      raise "Report at index #{run} does not exist, #{@report.size} reports available"
    end
  end
  messages
end

#passed?Boolean

Test whether this set of results passed or not

Returns:

  • (Boolean)

    true if tests were executed and passed, nil if no tests were executed, false if tests were exectued and there were failures



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/puppetbox/result.rb', line 46

def passed?
  passed = nil
  @report.each { |r|
    puts "...REPORT"
    if passed == nil
      passed = (r[:status] == PS_OK)
    else
      passed &= (r[:status] == PS_OK)
    end
  }

  passed
end

#report_countObject



60
61
62
# File 'lib/puppetbox/result.rb', line 60

def report_count
  @report.size
end

#report_message_count(report) ⇒ Object



64
65
66
# File 'lib/puppetbox/result.rb', line 64

def report_message_count(report)
  @report[report].messages.size
end

#save(status_code, messages) ⇒ Object

0: The run succeeded with no changes or failures; the system was already in the desired state. 1: The run failed, or wasn’t attempted due to another run already in progress. 2: The run succeeded, and some resources were changed. 4: The run succeeded, and some resources failed. 6: The run succeeded, and included both changes and failures.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/puppetbox/result.rb', line 26

def save(status_code, messages)
  status = PS_ERROR
  if @report.empty?
    # first run
    if status_code == 0 or status_code == 2
      status = PS_OK
    end
  else
    if status_code == 0
      status = PS_OK
    elsif status_code == 2
      status = PS_NOT_IDEMPOTENT
    end
  end
  @report.push({:status => status, :messages => messages})
end