Module: PDQTest::Execution
- Defined in:
- lib/pdqtest/execution.rb
Class Method Summary collapse
- .exec(cc, container, cmd) ⇒ Object
- .exec_err(res) ⇒ Object
- .exec_out(res) ⇒ Object
-
.exec_status(res, puppet = false) ⇒ Object
convert exit code (integer) to boolean: true == good; false == bad.
- .log_all(res) ⇒ Object
- .log_err(res) ⇒ Object
- .log_out(res) ⇒ Object
Class Method Details
.exec(cc, container, cmd) ⇒ Object
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 67 |
# File 'lib/pdqtest/execution.rb', line 34 def self.exec(cc, container, cmd) status = 0 res = {} res[:OUT]=[] res[:ERR]=[] res[:STATUS]=0 res[:REAL_CMD]=[] Array(cmd).each do |c| real_c = Util.wrap_cmd(c) res[:REAL_CMD] << real_c $logger.debug "Executing: #{real_c}" _res = cc._exec_real(container, real_c) if c =~ /robocopy/ # robocopy exit codes break the status check we do later on - we have # to manually 'fix' them here if _res[:STATUS] < 4 _res[:STATUS] = 0 end end res[:STATUS] += _res[:STATUS] res[:OUT] += _res[:OUT] res[:ERR] += _res[:ERR] # non zero status from something thats not puppet apply is probably an error if _res[:STATUS] != 0 && !(c =~ /pupet apply|bats/) $logger.warn "non-zero exit status: #{_res[:STATUS]} from #{real_c}: #{_res[:OUT]} #{_res[:ERR]}" end end res end |
.exec_err(res) ⇒ Object
9 10 11 |
# File 'lib/pdqtest/execution.rb', line 9 def self.exec_err(res) res[:ERR] end |
.exec_out(res) ⇒ Object
5 6 7 |
# File 'lib/pdqtest/execution.rb', line 5 def self.exec_out(res) res[:OUT] end |
.exec_status(res, puppet = false) ⇒ Object
convert exit code (integer) to boolean: true == good; false == bad
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/pdqtest/execution.rb', line 70 def self.exec_status(res, puppet=false) if puppet # 0 == ok, no changes # 2 == ok, changes made allowable_values = [0,2] else allowable_values = [0] end status = allowable_values.include?(res[:STATUS]) end |
.log_all(res) ⇒ Object
21 22 23 24 |
# File 'lib/pdqtest/execution.rb', line 21 def self.log_all(res) log_err(res) log_out(res) end |
.log_err(res) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/pdqtest/execution.rb', line 26 def self.log_err(res) exec_err(res).each { |l| # Output comes back as an array and needs to be iterated or we lose our # ansi formatting $logger.error l.chomp } end |
.log_out(res) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/pdqtest/execution.rb', line 13 def self.log_out(res) exec_out(res).each { |l| # Output comes back as an array and needs to be iterated or we lose our # ansi formatting $logger.info l.chomp } end |