Skip to content

Commit

Permalink
Merge pull request #20244 from yrudman/fix-retirement-from-global
Browse files Browse the repository at this point in the history
Fix vm retirement initiated on global region

(cherry picked from commit 97c2e5b)
  • Loading branch information
carbonin authored and simaishi committed Jun 5, 2020
1 parent 360cb7f commit 3e237e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/models/mixins/inter_region_api_method_relay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def self.api_client_connection_for_region(region_number, user = User.current_use
def self.exec_api_call(region, collection_name, action, api_args = nil, id = nil)
require 'manageiq-api-client'
api_args ||= {}
collection = api_client_connection_for_region(region).public_send(collection_name)
user_name = api_args[:requester]&.fetch("user_name")
user_name = User.current_user&.userid if user_name.blank?
collection = api_client_connection_for_region(region, user_name).public_send(collection_name)
collection_or_instance = id ? collection.find(id) : collection
result = collection_or_instance.public_send(action, api_args)
case result
Expand Down
3 changes: 2 additions & 1 deletion spec/models/mixins/inter_region_api_method_relay_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def expect_api_call(expected_action, expected_args = nil)

describe ".exec_api_call" do
let(:region) { 0 }
let(:userid) { nil }
let(:action) { :the_action }
let(:api_connection) { double("ManageIQ::API::Client Connection") }
let(:api_collection) { double("ManageIQ::API::Client Collection", :name => collection_name) }
Expand All @@ -216,7 +217,7 @@ def expect_api_call(expected_action, expected_args = nil)
let(:api_resource) { ManageIQ::API::Client::Resource.subclass("test_resource").new(api_collection, {}) }

before do
expect(described_class).to receive(:api_client_connection_for_region).with(region).and_return(api_connection)
expect(described_class).to receive(:api_client_connection_for_region).with(region, userid).and_return(api_connection)
expect(api_connection).to receive(collection_name).and_return(api_collection)
end

Expand Down

0 comments on commit 3e237e9

Please sign in to comment.