Skip to content

Commit

Permalink
Merge pull request ManageIQ#19775 from agrare/add_verify_credentials_…
Browse files Browse the repository at this point in the history
…task_to_host

Add verify_credentials_task to host
  • Loading branch information
gtanzillo authored Jan 28, 2020
2 parents daa659f + 447dde4 commit 5a86129
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
25 changes: 25 additions & 0 deletions app/models/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,31 @@ def self.batch_update_authentication(host_ids, creds = {})
errors.empty? ? true : errors
end

def verify_credentials_task(userid, auth_type = nil, options = {})
task_opts = {
:action => "Verify Host Credentials",
:userid => userid
}

queue_opts = {
:args => [auth_type, options],
:class_name => self.class.name,
:instance_id => id,
:method_name => "verify_credentials?",
:queue_name => queue_name_for_ems_operations,
:role => "ems_operations",
:zone => my_zone
}

MiqTask.generic_action_with_callback(task_opts, queue_opts)
end

def verify_credentials?(*args)
# Prevent the connection details, including the password, from being leaked into the logs
# and MiqQueue by only returning true/false
!!verify_credentials(*args)
end

def verify_credentials(auth_type = nil, options = {})
raise MiqException::MiqHostError, _("No credentials defined") if missing_credentials?(auth_type)
if auth_type.to_s != 'ipmi' && os_image_name !~ /linux_*/
Expand Down
20 changes: 19 additions & 1 deletion spec/models/host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,29 @@
EvmSpecHelper.local_miq_server

@password = "v2:{/OViaBJ0Ug+RSW9n7EFGqw==}"
@host = FactoryBot.create(:host_vmware_esx)
@ems = FactoryBot.create(:ems_vmware)
@host = FactoryBot.create(:host_vmware_esx, :ext_management_system => @ems)
@data = {:default => {:userid => "root", :password => @password}}
@options = {:save => false}
end

context "#verify_credentials_task" do
it "verifies the credentials" do
@host.update_authentication(@data, @options)
@host.save
@host.verify_credentials_task(FactoryBot.create(:user).userid)

expect(MiqQueue.last).to have_attributes(
:method_name => "verify_credentials?",
:instance_id => @host.id,
:class_name => @host.class.name,
:role => "ems_operations",
:zone => @ems.zone.name,
:queue_name => @ems.queue_name_for_ems_operations,
)
end
end

context "default credentials" do
it "save" do
@host.update_authentication(@data, @options)
Expand Down

0 comments on commit 5a86129

Please sign in to comment.