Skip to content

Commit

Permalink
Make sure exit_status is an integer not a string (#838)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris1984 authored Sep 14, 2023
1 parent faae8aa commit dd0b073
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def task_status(host_task, host_name)
{
'state' => host_task.state,
'output' => host_task.main_action.live_output.map { |line| line['output'] }.join("\n"),
'exit_status' => host_task.main_action.exit_status,
'exit_status' => ActiveModel::Type::Integer.new.cast(host_task.main_action.exit_status),
'sequence' => sequence(host_name),
'report_done' => host_done?(host_name),
}
Expand Down
12 changes: 11 additions & 1 deletion test/jobs/connector_playbook_execution_reporter_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def send_report(report)
assert_not_nil actual_report
actual_jsonl = read_jsonl(actual_report)

assert_equal true, actual.output['task']['invocation_status']['task_state']['task_done_reported']
assert_equal 0, actual.output['task']['invocation_status']['hosts_state']['TEST_UUID1']['exit_status']
assert_equal 0, actual.output['task']['invocation_status']['hosts_state']['TEST_UUID2']['exit_status']

assert_equal true, @job_invocation.finished?
assert_equal 'stopped', @job_invocation.sub_task_for_host(Host.where(name: 'host1').first)['state']

Expand Down Expand Up @@ -85,6 +89,9 @@ def send_report(report)
actual_json1 = read_jsonl(actual_report1)
actual_json2 = read_jsonl(actual_report2)

assert_equal true, actual.output['task']['invocation_status']['task_state']['task_done_reported']
assert_equal 0, actual.output['task']['invocation_status']['hosts_state']['TEST_UUID1']['exit_status']

assert_equal 'stopped', @job_invocation.sub_task_for_host(Host.where(name: 'host1').first)['state']

assert_not_nil actual_report_updated = actual_json1.find { |l| l['type'] == 'playbook_run_update' && l['host'] == 'TEST_UUID1' }
Expand Down Expand Up @@ -149,6 +156,9 @@ def send_report(report)
actual_json2 = read_jsonl(actual_report2)
actual_json3 = read_jsonl(actual_report3)

assert_equal true, actual.output['task']['invocation_status']['task_state']['task_done_reported']
assert_equal 0, actual.output['task']['invocation_status']['hosts_state']['TEST_UUID1']['exit_status']

assert_not_nil actual_report_updated = actual_json1.find { |l| l['type'] == 'playbook_run_update' && l['host'] == 'TEST_UUID1' }
assert_equal 'TEST_CORRELATION', actual_report_updated['correlation_id']
assert_equal 'TEST_UUID1', actual_report_updated['host']
Expand Down Expand Up @@ -263,7 +273,7 @@ def generate_job_invocation
{ 'timestamp' => (Time.now - (5 - i)).to_f, 'output' => "#{i}\n" }
end
Support::DummyDynflowAction.any_instance.stubs(:live_output).returns(fake_output)
Support::DummyDynflowAction.any_instance.stubs(:exit_status).returns(0)
Support::DummyDynflowAction.any_instance.stubs(:exit_status).returns("0")

job_invocation
end
Expand Down

0 comments on commit dd0b073

Please sign in to comment.