Skip to content

Commit

Permalink
Merge pull request #14779 from bzwei/job_play2
Browse files Browse the repository at this point in the history
Fetch Ansible job plays from job events.
  • Loading branch information
bdunne authored Apr 18, 2017
2 parents 23293b8 + e4dcf45 commit e22b912
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ gem "activerecord-session_store", "~>1.0.0"
gem "acts_as_list", "~>0.7.2"
gem "acts_as_tree", "~>2.1.0" # acts_as_tree needs to be required so that it loads before ancestry
gem "ancestry", "~>2.2.1", :require => false
gem "ansible_tower_client", "~>0.11.0", :require => false
gem "ansible_tower_client", "~>0.12.0", :require => false
gem "aws-sdk", "~>2", :require => false
gem "bundler", ">=1.11.1", :require => false
gem "color", "~>1.8"
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 e22b912

Please sign in to comment.