Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Associate job with credentials #14113

Merged
merged 1 commit into from
Mar 6, 2017
Merged

Conversation

bzwei
Copy link
Contributor

@bzwei bzwei commented Mar 1, 2017

This is done when sync an Ansible Tower job with VMDB.

https://www.pivotaltracker.com/story/show/140808769

@bzwei
Copy link
Contributor Author

bzwei commented Mar 1, 2017

@miq-bot assign @gmcculloug
@miq-bot add_label enhancement
@miq-bot add_label providers/ansible_tower

@gmcculloug
Copy link
Member

@Fryguy @gtanzillo This looks good to me. Please review.

Copy link
Member

@gtanzillo gtanzillo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

self.authentications = %w(credential_id cloud_credential_id network_credential_id).collect do |credential_attr|
credential_ref = raw_job.try(credential_attr)
next if credential_ref.blank?
ext_management_system.credentials.find_by(:manager_ref => credential_ref)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an N+1. I think this whole thing can be simplified to

credential_refs = %w(credential_id cloud_credential_id network_credential_id).collect { |attr| raw_job.try(attr) }.delete_blanks
self.authentications = ext_management_system.credentials.where(:manager_ref => credential_refs)

Also, where did the credentials association come from. Is that new? cc @blomquisg

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Ansible Job is not an object we collect through inventory, this object is captured as part of the service provisioning task. A Job has three possible credential relationships, machine, network and cloud.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I understand that...still not sure how that applies to my comment...

find_by in a loop is an N+1 and can be easily fixed with collecting the query criteria up front.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was addressing that the object is not so much under provider control so @blomquisg might be like ¯_(ツ)_/¯.

@@ -65,6 +73,7 @@
expect(subject.ems_ref).to eq(the_raw_job.id)
expect(subject.status).to eq(the_raw_job.status)
expect(subject.parameters.first).to have_attributes(:name => 'param1', :value => 'val1')
expect(subject.authentications).to eq([machine_credential, cloud_credential, network_credential])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be match_array instead of eq. This way a change in order should not affect the test.

expect(subject.ems_ref).to eq(the_raw_job.id)
expect(subject.status).to eq(the_raw_job.status)
expect(subject.parameters.first).to have_attributes(:name => 'param1', :value => 'val1')
expect(subject.authentications).to eq([machine_credential, cloud_credential, network_credential])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here on the match_array

@bzwei bzwei force-pushed the job_credentials branch from 3fec021 to 29c4af2 Compare March 3, 2017 20:36
@bzwei bzwei force-pushed the job_credentials branch from 29c4af2 to 054598e Compare March 3, 2017 23:29
@miq-bot
Copy link
Member

miq-bot commented Mar 3, 2017

Checked commit bzwei@054598e with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
6 files checked, 0 offenses detected
Everything looks good. 👍

@gmcculloug gmcculloug merged commit fcaa410 into ManageIQ:master Mar 6, 2017
@gmcculloug gmcculloug added this to the Sprint 56 Ending Mar 13, 2017 milestone Mar 6, 2017
@bzwei bzwei deleted the job_credentials branch March 6, 2017 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants