-
Notifications
You must be signed in to change notification settings - Fork 897
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
Prepare parameter hash before passing to Tower API credential CU #14483
Conversation
@miq-bot add_labels wip, enhancement, providers/ansible_provider |
@jameswnl Cannot apply the following label because they are not recognized: providers/ansible_provider |
@miq-bot add_labels providers/ansible_tower |
@miq-bot remove_labels wip |
let(:finished_task) { FactoryGirl.create(:miq_task, :state => "Finished") } | ||
let(:manager) { FactoryGirl.create(:provider_ansible_tower, :with_authentication).managers.first } | ||
let(:manager) { FactoryGirl.create(ansible_provider, :with_authentication).managers.first } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be much simpler to define a let for the provider
outside of the shared examples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I tried it (defining outside), but it is failing somehow. To succeed, I'll have to pass it implicitly
.
I feel having the shared_examples
parameters being explicitly declared
in the block opening (as in shared_examples_for do | ansible_provider |
) provides more clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works here... #14419
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but as I said, that is passing the parameter implicitly
and I prefer more explicit
passing which brings more clarity to the code.
@@ -75,4 +83,5 @@ def delete_in_provider_queue | |||
COMMON_ATTRIBUTES = {}.freeze | |||
EXTRA_ATTRIBUTES = {}.freeze | |||
API_ATTRIBUTES = COMMON_ATTRIBUTES.merge(EXTRA_ATTRIBUTES).freeze | |||
# TOWER_KIND = 'ssh'.freeze # default to `ssh` just like Tower does |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this commented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am not sure if we want/need this default at all. what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type should never be created, right? So I wouldn't include the constant here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I had this line started out for helping the test (as it was originally at the Ansible::Credential
level. yeah, now removed.
b5640bb
to
22fba33
Compare
include ManageIQ::Providers::AnsibleTower::Shared::AutomationManager::Credential | ||
|
||
def self.provider_params(params) | ||
super.merge(:organization => 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it safe to hard code this id?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my new patch. Thanks Brandon!
With the changes from this PR in place, I still cannot update
Not when I look at the task id returned:
|
@mzazrivec I just did one with my setup and can't reproduce yours. |
I just pushed an update to have |
Found the cause to @mzazrivec 's issue. the |
@@ -1,5 +1,9 @@ | |||
require 'support/ansible_shared/automation_manager/credential' | |||
|
|||
describe ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ScmCredential do | |||
it_behaves_like 'ansible credential', :provider_embedded_ansible | |||
let(:ansible_manager) do | |||
FactoryGirl.create(:provider_embedded_ansible, :with_authentication, :with_default_organization).managers.first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's reusable enough to justify adding a trait to the factory, this should work:
FactoryGirl.create(:provider_embedded_ansible, :with_authentication, :default_organization => 1).managers.first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Good to know. Done now
let(:finished_task) { FactoryGirl.create(:miq_task, :state => "Finished") } | ||
let(:manager) { FactoryGirl.create(ansible_provider, :with_authentication).managers.first } | ||
let(:manager) { ansible_manager } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
spec/factories/provider.rb
Outdated
@@ -23,6 +23,11 @@ | |||
x.authentications << FactoryGirl.create(:authentication, :status => "Valid") | |||
end | |||
end | |||
trait(:with_default_organization) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove. See comment below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
Checked commits jameswnl/manageiq@5346f5c~...de286f8 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 spec/support/ansible_shared/automation_manager/credential.rb
|
@@ -1,5 +1,9 @@ | |||
require 'support/ansible_shared/automation_manager/credential' | |||
|
|||
describe ManageIQ::Providers::AnsibleTower::AutomationManager::Credential do | |||
describe ManageIQ::Providers::AnsibleTower::AutomationManager::ScmCredential do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is credential_spec.rb
testing ScmCredential
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because ManageIQ::Providers::AnsibleTower::AutomationManager::Credential
is not a concrete class and doesn't have TOWER_KIND
.
Maybe I'll rename the file to scm_credential_spec.rb
?
@@ -2,7 +2,15 @@ module ManageIQ::Providers::AnsibleTower::Shared::AutomationManager::Credential | |||
extend ActiveSupport::Concern | |||
|
|||
module ClassMethods | |||
def provider_params(params) | |||
params[:username] = params.delete(:userid) if params.include?(:userid) | |||
params[:username] = params.delete('userid') if params.include?('userid') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why both a String and Symbol key for userid
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string type is coming from API calls via HTTP.
You want me to take away the line handling :userid
? I keep it there so it will be consistent with all other attributes as in here
Other usage through ruby method invocation can use whole set of attributes using symbol
key.
or else will have to change all the credentials' ATTRIBUTES
hash keys.
The code is not needed since ManageIQ/manageiq#14483 has been merged.
The code is not needed since ManageIQ/manageiq#14483 has been merged.
UI ManageIQ/manageiq-ui-classic#818 is fine/yes so this has to be too. |
@jameswnl Can you take a look at the +++ b/spec/support/ansible_shared/automation_manager/credential.rb
@@ -17,10 +17,10 @@ shared_examples_for "ansible credential" do
let(:params) do
{
- :description => "Description",
- :name => "My Credential",
- :related => {},
- :userid => 'john'
+ :description => "Description",
+ :name => "My Credential",
+ :related => {},
+ :userid => 'john'
}
end |
@simaishi |
Thanks @jameswnl - marking it as |
:userid
to:username
:kind
:organization => 1
if it's theEmbeddedAnsible
. I.e. assign toDefault
organization in Tower