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

Refresh to pick up extra attributes of Ansible Credentials #14106

Merged
merged 1 commit into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
class ManageIQ::Providers::AnsibleTower::AutomationManager::Credential < ManageIQ::Providers::ExternalAutomationManager::Authentication
COMMON_ATTRIBUTES = {}.freeze
EXTRA_ATTRIBUTES = {}.freeze
API_ATTRIBUTES = COMMON_ATTRIBUTES.merge(EXTRA_ATTRIBUTES).freeze
end
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,6 @@ def credentials
inventory_object = persister.credentials.find_or_build(credential.id.to_s)
inventory_object.name = credential.name
inventory_object.userid = credential.username
# credential.description
# credential.host
# credential.password
# credential.security_token
# credential.project
# credential.domain
# credential.ssh_key_data
# credential.ssh_key_unlock
# credential.organization
# credential.become_method # '', 'sudo', 'su', 'pbrun', 'pfexec'
# credential.become_username
# credential.become_password
# credential.vault_password
# credential.subscription
# credential.tenant
# credential.secret
# credential.client
# credential.authorize
# credential.authorize_password
provider_module = ManageIQ::Providers::Inflector.provider_module(collector.manager.class).name
inventory_object.type = case credential.kind
when 'net' then "#{provider_module}::AutomationManager::NetworkCredential"
Expand All @@ -99,6 +80,9 @@ def credentials
when 'openstack' then "#{provider_module}::AutomationManager::OpenstackCredential"
else "#{provider_module}::AutomationManager::Credential"
end
inventory_object.options = inventory_object.type.constantize::EXTRA_ATTRIBUTES.keys.each_with_object({}) do |k, h|
h[k] = credential.public_send(k)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
class ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Credential <
ManageIQ::Providers::EmbeddedAutomationManager::Authentication
COMMON_ATTRIBUTES = {}.freeze
EXTRA_ATTRIBUTES = {}.freeze
API_ATTRIBUTES = COMMON_ATTRIBUTES.merge(EXTRA_ATTRIBUTES).freeze
end
2 changes: 1 addition & 1 deletion app/models/manager_refresh/inventory/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def has_authentications(options = {})
has_inventory({
:model_class => ::Authentication,
:manager_ref => [:manager_ref],
:inventory_object_attributes => %i(name userid type),
:inventory_object_attributes => %i(name userid type options),
}.merge(options))
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,27 @@ def assert_credentials
:name => "Demo Credential",
:userid => "admin",
)
expect(machine_credential.options.keys).to match_array(machine_credential.class::EXTRA_ATTRIBUTES.keys)
Copy link
Member

Choose a reason for hiding this comment

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

can you also test for the values here and in the other 2 tests?
Or are they empty?
If empty, maybe change to creds that are not empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I modified the machine credential and now added the check for a couple values. The other network/cloud credentials we don't have any extra attributes for them yet.

Copy link
Member

Choose a reason for hiding this comment

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

but its not yet in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😅 forgot the --force options when pushing. now done

expect(machine_credential.options[:become_method]).to eq('su')
expect(machine_credential.options[:become_username]).to eq('root')

network_credential = expected_configuration_script.authentications.find_by(
:type => ManageIQ::Providers::AnsibleTower::AutomationManager::NetworkCredential
)
expect(network_credential).to have_attributes(
:name => "Demo Creds 2",
:userid => "awdd",
)
expect(network_credential.options.keys).to match_array(network_credential.class::EXTRA_ATTRIBUTES.keys)

cloud_credential = expected_configuration_script.authentications.find_by(
:type => ManageIQ::Providers::AnsibleTower::AutomationManager::VmwareCredential
)
expect(cloud_credential).to have_attributes(
:name => "dev-vc60",
:userid => "[email protected]",
)
expect(cloud_credential.options.keys).to match_array(cloud_credential.class::EXTRA_ATTRIBUTES.keys)
end

def assert_playbooks
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.