Skip to content

Commit

Permalink
Get job_plays by filtering job_events
Browse files Browse the repository at this point in the history
  • Loading branch information
bzwei committed Apr 17, 2017
1 parent eaae992 commit e4dcf45
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Expand Up @@ -94,15 +94,15 @@ def update_credentials(raw_job)

def update_plays(raw_job)
last_play_hash = nil
plays = raw_job.job_plays.collect do |play|
plays = raw_job.job_events(:event => 'playbook_on_play_start').collect do |play|
{
:name => play.play,
:resource_status => play.failed ? 'failed' : 'successful',
:start_time => play.started,
:start_time => play.created,
:ems_ref => play.id,
:resource_category => 'job_play'
}.tap do |h|
last_play_hash[:finish_time] = play.started if last_play_hash
last_play_hash[:finish_time] = play.created if last_play_hash
last_play_hash = h
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/service_ansible_tower_spec.rb
Expand Up @@ -72,7 +72,7 @@
:verbosity => 0,
:started => Time.current,
:finished => Time.current,
:job_plays => [],
:job_events => [],
:extra_vars_hash => {'var_name' => 'var_val'}))

job_done = service_mix_dialog_setter.launch_job
Expand Down
12 changes: 6 additions & 6 deletions spec/support/ansible_shared/automation_manager/job.rb
Expand Up @@ -30,14 +30,14 @@
'network_credential_id' => network_credential.manager_ref
).tap do |rjob|
allow(rjob).to receive(:stdout).with('html').and_return('<html><body>job stdout</body></html>')
allow(rjob).to receive(:job_plays).and_return(the_raw_plays)
allow(rjob).to receive(:job_events).with(:event => 'playbook_on_play_start').and_return(the_raw_plays)
end
end

let(:the_raw_plays) do
[
double('play1', :play => 'play1', :started => Time.current, :failed => false, :id => 1),
double('play2', :play => 'play2', :started => Time.current + 1, :failed => true, :id => 2)
double('play1', :play => 'play1', :created => Time.current, :failed => false, :id => 1),
double('play2', :play => 'play2', :created => Time.current + 1, :failed => true, :id => 2)
]
end

Expand Down Expand Up @@ -88,14 +88,14 @@
expect(subject.authentications).to match_array([machine_credential, cloud_credential, network_credential])

expect(subject.job_plays.first).to have_attributes(
:start_time => the_raw_plays.first.started,
:finish_time => the_raw_plays.last.started,
:start_time => the_raw_plays.first.created,
:finish_time => the_raw_plays.last.created,
:resource_status => 'successful',
:resource_category => 'job_play',
:name => 'play1'
)
expect(subject.job_plays.last).to have_attributes(
:start_time => the_raw_plays.last.started,
:start_time => the_raw_plays.last.created,
:finish_time => the_raw_job.finished,
:resource_status => 'failed',
:resource_category => 'job_play',
Expand Down

0 comments on commit e4dcf45

Please sign in to comment.