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



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/puppetbox/result.rb', line 75

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



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/puppetbox/result.rb', line 52

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

  passed
end

#report_countObject



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

def report_count
  @report.size
end

#report_message_count(report) ⇒ Object



69
70
71
# File 'lib/puppetbox/result.rb', line 69

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

#save(status_code, messages) ⇒ Object

Puppet exit codes: 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.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/puppetbox/result.rb', line 27

def save(status_code, messages)

  # messages will usually be an array of output - one per line, but it might
  # not be and everthing expects to be so just turn it into one if it isn't
  # already...
  messages = Array(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