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

Add my_queue_name for ems_operations miq_requests #19739

Merged
merged 8 commits into from
Jan 28, 2020
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
1 change: 1 addition & 0 deletions app/models/configured_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ConfiguredSystem < ApplicationRecord
delegate :name, :to => :operating_system_flavor, :prefix => true, :allow_nil => true
delegate :name, :to => :provider, :prefix => true, :allow_nil => true
delegate :my_zone, :provider, :zone, :to => :manager
delegate :queue_name_for_ems_operations, :to => :manager, :allow_nil => true

virtual_column :my_zone, :type => :string
virtual_column :configuration_architecture_name, :type => :string
Expand Down
4 changes: 4 additions & 0 deletions app/models/miq_provision_configured_system_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def my_role(_action = nil)
'ems_operations'
end

def my_queue_name
src_configured_systems.first.nil? ? super : src_configured_systems.first&.queue_name_for_ems_operations
end

def self.request_task_class_from(_attribs)
ManageIQ::Providers::Foreman::ConfigurationManager::ProvisionTask
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/physical_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class PhysicalServer < ApplicationRecord
virtual_column :v_host_os, :type => :string, :uses => :host
virtual_delegate :emstype, :to => "ext_management_system", :allow_nil => true

delegate :queue_name_for_ems_operations, :to => :ext_management_system, :allow_nil => true

has_many :physical_switches, :through => :computer_system, :source => :connected_physical_switches

supports :refresh_ems
Expand Down
4 changes: 4 additions & 0 deletions app/models/physical_server_firmware_update_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def my_role(_action = nil)
'ems_operations'
end

def my_queue_name
affected_ems.queue_name_for_ems_operations
end

def self.request_task_class
PhysicalServerFirmwareUpdateTask
end
Expand Down
8 changes: 8 additions & 0 deletions app/models/physical_server_provision_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ def my_role(_action = nil)
'ems_operations'
end

def my_queue_name
source.nil? ? super : source.queue_name_for_ems_operations
end

def source
@source ||= PhysicalServer.find_by(:id => source_id)
end

def self.request_task_class
PhysicalServerProvisionTask
end
Expand Down
9 changes: 8 additions & 1 deletion app/models/vm_cloud_reconfigure_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@ def self.make_request(request, values, requester, auto_approve = false)
end
end

def vm
@vm ||= Vm.find_by(:id => options[:src_ids])
end

def my_zone
vm = Vm.find_by(:id => options[:src_ids])
vm.nil? ? super : vm.my_zone
end

def my_role(_action = nil)
'ems_operations'
end

def my_queue_name
vm.nil? ? super : vm.queue_name_for_ems_operations
end
end
9 changes: 8 additions & 1 deletion app/models/vm_migrate_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ class VmMigrateRequest < MiqRequest
validate :must_have_user
include MiqProvisionQuotaMixin

def vm
@vm ||= Vm.find_by(:id => options[:src_ids])
end

def my_zone
vm = Vm.find_by(:id => options[:src_ids])
vm.nil? ? super : vm.my_zone
end

def my_role(_action = nil)
'ems_operations'
end

def my_queue_name
vm.nil? ? super : vm.queue_name_for_ems_operations
end
end
19 changes: 19 additions & 0 deletions spec/models/configured_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,23 @@

expect(cs1.counterparts).to match_array([vm, cs2, cs3])
end

describe "#queue_name_for_ems_operations" do
context "with an active configured_system" do
let(:manager) { FactoryBot.create(:configuration_manager) }
let(:configured_system) { FactoryBot.create(:configured_system, :manager => manager) }

it "uses the manager's queue_name_for_ems_operations" do
expect(configured_system.queue_name_for_ems_operations).to eq(manager.queue_name_for_ems_operations)
end
end

context "with an archived configured_system" do
let(:configured_system) { FactoryBot.create(:configured_system) }

it "uses the manager's queue_name_for_ems_operations" do
expect(configured_system.queue_name_for_ems_operations).to be_nil
end
end
end
end
9 changes: 9 additions & 0 deletions spec/models/physical_server_firmware_update_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
expect(subject.my_role).to eq('ems_operations')
end

describe '#my_queue_name' do
let(:ems) { FactoryBot.create(:ems_physical_infra) }
let(:physical_server) { FactoryBot.create(:physical_server, :ext_management_system => ems) }

it "returns the ems's queue_name_for_ems_operations" do
expect(physical_server.queue_name_for_ems_operations).to eq(ems.queue_name_for_ems_operations)
end
end

it '#requested_task_idx' do
expect(subject.requested_task_idx).to eq([-1])
end
Expand Down
4 changes: 4 additions & 0 deletions spec/models/physical_server_provision_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
expect(subject.my_role).to eq('ems_operations')
end

it "#my_queue_name" do
expect(subject.my_queue_name).to be_nil
end

describe '.new_request_task' do
before do
allow(ems.class).to receive(:provision_class).and_return(task)
Expand Down
19 changes: 19 additions & 0 deletions spec/models/physical_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,23 @@
expect(subject.firmware_compatible?(binary2)).to eq(false)
end
end

describe "#queue_name_for_ems_operations" do
context "with an active configured_system" do
let(:manager) { FactoryBot.create(:physical_infra) }
let(:physical_server) { FactoryBot.create(:physical_server, :with_asset_detail, :ext_management_system => manager) }

it "uses the manager's queue_name_for_ems_operations" do
expect(physical_server.queue_name_for_ems_operations).to eq(manager.queue_name_for_ems_operations)
end
end

context "with an archived configured_system" do
let(:physical_server) { FactoryBot.create(:physical_server, :with_asset_detail) }

it "uses the manager's queue_name_for_ems_operations" do
expect(physical_server.queue_name_for_ems_operations).to be_nil
end
end
end
end