From a26da38ec5f116113f07aa9c58c92eb841dc87cb Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Thu, 16 Jan 2025 14:31:55 -0500 Subject: [PATCH] Revert "WIP - hack - workaround alias_attribute bug for now" This reverts commit e7acb3235e840aa89d479bf3993a08c53fc13e57. VERIFY we can drop this revert and the original commit pending due to https://www.github.com/ManageIQ/activerecord-virtual_attributes/pull/168 --- app/models/miq_provision.rb | 2 +- app/models/miq_provision/naming.rb | 4 +-- .../mixins/miq_provision_quota_mixin.rb | 10 +++---- .../service_template_provision_request.rb | 2 +- spec/models/miq_approval_spec.rb | 4 +-- spec/models/miq_provision_request_spec.rb | 2 +- spec/models/service_spec.rb | 28 +++++++++---------- ...e_template_provision_request_quota_spec.rb | 6 ++-- ...service_template_provision_request_spec.rb | 18 ++++++------ 9 files changed, 38 insertions(+), 38 deletions(-) diff --git a/app/models/miq_provision.rb b/app/models/miq_provision.rb index 55b10e67bcf..7cea18fdcaf 100644 --- a/app/models/miq_provision.rb +++ b/app/models/miq_provision.rb @@ -113,7 +113,7 @@ def self.get_description(prov_obj, vm_name) end _("%{title} from [%{name}] to [%{vm_name}]") % {:title => title, - :name => prov_obj.source.name, + :name => prov_obj.vm_template.name, :vm_name => vm_name} end diff --git a/app/models/miq_provision/naming.rb b/app/models/miq_provision/naming.rb index 31a50360762..73b09387a8a 100644 --- a/app/models/miq_provision/naming.rb +++ b/app/models/miq_provision/naming.rb @@ -46,9 +46,9 @@ def get_vm_full_name(unresolved_vm_name, prov_obj, determine_index) end def check_vm_name_uniqueness(fullname, prov_obj) - return nil if prov_obj.source.nil? + return nil if prov_obj.vm_template.nil? - ems = prov_obj.source.ext_management_system + ems = prov_obj.vm_template.ext_management_system return nil if ems.nil? VmOrTemplate.find_by("ems_id = ? and lower(name) = ?", ems.id, fullname.downcase) diff --git a/app/models/mixins/miq_provision_quota_mixin.rb b/app/models/mixins/miq_provision_quota_mixin.rb index 81f8b9b35ab..0f77d99b09c 100644 --- a/app/models/mixins/miq_provision_quota_mixin.rb +++ b/app/models/mixins/miq_provision_quota_mixin.rb @@ -315,13 +315,13 @@ def vm_quota_values(pr, result) end def service_quota_values(request, result) - return unless request.source + return unless request.service_template - request.source.service_resources.each do |sr| - if request.source.service_type == ServiceTemplate::SERVICE_TYPE_COMPOSITE + request.service_template.service_resources.each do |sr| + if request.service_template.service_type == ServiceTemplate::SERVICE_TYPE_COMPOSITE bundle_quota_values(sr, result) else - next if request.source.prov_type.starts_with?("generic") + next if request.service_template.prov_type.starts_with?("generic") vm_quota_values(sr.resource, result) end @@ -372,7 +372,7 @@ def flavor(request) end def number_of_cpus(prov, cloud, flavor_obj) - num_cpus = flavor_obj.try(:cpu_total_cores) if cloud + num_cpus = flavor_obj.try(:cpus) if cloud return num_cpus if num_cpus.present? request = prov.kind_of?(MiqRequest) ? prov : prov.miq_request diff --git a/app/models/service_template_provision_request.rb b/app/models/service_template_provision_request.rb index 3eeea246ed7..254338ae2fc 100644 --- a/app/models/service_template_provision_request.rb +++ b/app/models/service_template_provision_request.rb @@ -45,7 +45,7 @@ def my_role(action = nil) end def my_zone - @my_zone ||= dialog_zone || source.my_zone + @my_zone ||= dialog_zone || service_template.my_zone end def provision_dialog diff --git a/spec/models/miq_approval_spec.rb b/spec/models/miq_approval_spec.rb index 23f6b59ddb5..0c7f86f2fed 100644 --- a/spec/models/miq_approval_spec.rb +++ b/spec/models/miq_approval_spec.rb @@ -40,7 +40,7 @@ it "with an approver's own request" do vm_template = FactoryBot.create(:template_vmware) user = FactoryBot.create(:user_miq_request_approver) - request = FactoryBot.create(:miq_provision_request, :provision_type => 'template', :request_state => 'pending', :status => 'Ok', :src_vm_id => vm_template.id, :requester => user) + request = FactoryBot.create(:miq_provision_request, :provision_type => 'template', :state => 'pending', :status => 'Ok', :src_vm_id => vm_template.id, :requester => user) approval = FactoryBot.create(:miq_approval, :miq_request => request) expect { approval.approve(user, 'Why Not') }.to_not raise_error @@ -49,7 +49,7 @@ it "with an approver's object'" do vm_template = FactoryBot.create(:template_vmware) user = FactoryBot.create(:user_miq_request_approver) - request = FactoryBot.create(:miq_provision_request, :provision_type => 'template', :request_state => 'pending', :status => 'Ok', :src_vm_id => vm_template.id, :requester => user) + request = FactoryBot.create(:miq_provision_request, :provision_type => 'template', :state => 'pending', :status => 'Ok', :src_vm_id => vm_template.id, :requester => user) approval = FactoryBot.create(:miq_approval, :miq_request => request) expect { approval.approve(user, 'Why Not') }.to_not raise_error diff --git a/spec/models/miq_provision_request_spec.rb b/spec/models/miq_provision_request_spec.rb index 1a8b4bdb4c3..9e610981154 100644 --- a/spec/models/miq_provision_request_spec.rb +++ b/spec/models/miq_provision_request_spec.rb @@ -181,7 +181,7 @@ def create_request(user, vm_template, prov_options) @google_user2 = FactoryBot.create(:user_with_email, :miq_groups => [group]) @google_template = FactoryBot.create(:template_google, :ext_management_system => ems) flavor = FactoryBot.create(:flavor_google, :ems_id => ems.id, - :cpu_total_cores => 4, :cpu_cores_per_socket => 1, :memory => 1024) + :cpus => 4, :cpu_cores => 1, :memory => 1024) prov_options = {:number_of_vms => 1, :src_vm_id => vm_template.id, :boot_disk_size => ["10.GB", "10 GB"], :placement_auto => [true, 1], :instance_type => [flavor.id, flavor.name]} 2.times { create_request(@google_user1, @google_template, prov_options) } diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index c51e8d100b0..4cd61aeff98 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -73,8 +73,8 @@ @vm2 = FactoryBot.create(:vm_vmware) @service = FactoryBot.create(:service) - @service_c1 = FactoryBot.create(:service, :parent => @service) - @service_c2 = FactoryBot.create(:service, :parent => @service_c1) + @service_c1 = FactoryBot.create(:service, :service => @service) + @service_c2 = FactoryBot.create(:service, :service => @service_c1) @service << @vm @service_c1 << @vm1 @service_c2 << @vm1 @@ -426,7 +426,7 @@ describe ".queue_chargeback_reports" do before do - @service_c1 = FactoryBot.create(:service, :parent => @service) + @service_c1 = FactoryBot.create(:service, :service => @service) @service_c1.name = "Test_Service_2" @service_c1 << @vm1 @service_c1.save @@ -594,7 +594,7 @@ it "returns parent" do service = FactoryBot.create(:service) - service_c1 = FactoryBot.create(:service, :parent => service) + service_c1 = FactoryBot.create(:service, :service => service) expect(service_c1.parent).to eq(service) expect(service_c1.parent_service).to eq(service) # alias @@ -610,7 +610,7 @@ it "has parent" do service = FactoryBot.create(:service) - service_c1 = FactoryBot.create(:service, :parent => service) + service_c1 = FactoryBot.create(:service, :service => service) expect(service_c1.has_parent).to be_truthy expect(service_c1.has_parent?).to be_truthy # alias @@ -626,7 +626,7 @@ it "has root as parent" do service = FactoryBot.create(:service) - service_c1 = FactoryBot.create(:service, :parent => service) + service_c1 = FactoryBot.create(:service, :service => service) expect(service_c1.root).to eq(service) expect(service_c1.root_service).to eq(service) # alias end @@ -692,8 +692,8 @@ let(:service_with_type) { FactoryBot.create(:service, :type => "thing", :lifecycle_state => 'provisioned') } let(:unprovd_service_with_type) { FactoryBot.create(:service, :type => "thing") } let(:service_without_type) { FactoryBot.create(:service, :type => nil) } - let(:service_with_parent) { FactoryBot.create(:service, :parent => FactoryBot.create(:service), :lifecycle_state => 'provisioned') } - let(:unprovisioned_service_with_parent) { FactoryBot.create(:service, :parent => FactoryBot.create(:service)) } + let(:service_with_parent) { FactoryBot.create(:service, :service => FactoryBot.create(:service), :lifecycle_state => 'provisioned') } + let(:unprovisioned_service_with_parent) { FactoryBot.create(:service, :service => FactoryBot.create(:service)) } context "with no parent" do context "with type" do it "true" do @@ -817,7 +817,7 @@ child_service.remove_from_service(service) expect(service.services).to be_blank - expect(child_service.parent).to be_nil + expect(child_service.service).to be_nil end end @@ -860,11 +860,11 @@ def create_deep_tree @service = FactoryBot.create(:service) - @service_c1 = FactoryBot.create(:service, :parent => @service) - @service_c11 = FactoryBot.create(:service, :parent => @service_c1) - @service_c12 = FactoryBot.create(:service, :parent => @service_c1) - @service_c121 = FactoryBot.create(:service, :parent => @service_c12) - @service_c2 = FactoryBot.create(:service, :parent => @service) + @service_c1 = FactoryBot.create(:service, :service => @service) + @service_c11 = FactoryBot.create(:service, :service => @service_c1) + @service_c12 = FactoryBot.create(:service, :service => @service_c1) + @service_c121 = FactoryBot.create(:service, :service => @service_c12) + @service_c2 = FactoryBot.create(:service, :service => @service) end context "custom actions" do diff --git a/spec/models/service_template_provision_request_quota_spec.rb b/spec/models/service_template_provision_request_quota_spec.rb index afa135e773b..1cbc582caa9 100644 --- a/spec/models/service_template_provision_request_quota_spec.rb +++ b/spec/models/service_template_provision_request_quota_spec.rb @@ -22,7 +22,7 @@ def create_test_request(user, service_template) def create_service_bundle(user, items, options = {}) build_model_from_vms(items) request = build_service_template_request("top", user, :dialog => {"test" => "dialog"}) - res = request.source.service_resources.first.resource.service_resources.first.resource + res = request.service_template.service_resources.first.resource.service_resources.first.resource res.options.merge!(options) res.save request @@ -76,7 +76,7 @@ def create_service_bundle(user, items, options = {}) it "invalid service_template does not raise error" do requests = load_requests - requests.first.update(:source => nil) + requests.first.update(:service_template => nil) expect { request.check_quota(quota_method) }.not_to raise_error end end @@ -120,7 +120,7 @@ def build_google_service_item @google_template = FactoryBot.create(:template_google, :ext_management_system => ems) flavor = FactoryBot.create(:flavor_google, :ems_id => ems.id, - :cpu_total_cores => 4, :cpu_cores_per_socket => 1, :memory => 1024) + :cpus => 4, :cpu_cores => 1, :memory => 1024) @google_prov_options = {:number_of_vms => [1, '1'], :src_vm_id => @google_template.id, :boot_disk_size => ["10.GB", "10 GB"], :placement_auto => [true, 1], :instance_type => [flavor.id, flavor.name]} requests = [] diff --git a/spec/models/service_template_provision_request_spec.rb b/spec/models/service_template_provision_request_spec.rb index 815d2d7980f..03ff7a01aa9 100644 --- a/spec/models/service_template_provision_request_spec.rb +++ b/spec/models/service_template_provision_request_spec.rb @@ -34,7 +34,7 @@ it "pending state" do @request.update_request_status expect(@request.message).to eq("Pending = 4") - expect(@request.request_state).to eq("pending") + expect(@request.state).to eq("pending") expect(@request.status).to eq("Ok") end @@ -42,7 +42,7 @@ @task_1_1.update_and_notify_parent(:state => "queued", :status => "Ok", :message => "Test Message") @request.reload expect(@request.message).to eq("Pending = 2; Queued = 2") - expect(@request.request_state).to eq("active") + expect(@request.state).to eq("active") expect(@request.status).to eq("Ok") end @@ -51,7 +51,7 @@ @task_2_1.update_and_notify_parent(:state => "queued", :status => "Ok", :message => "Test Message") @request.reload expect(@request.message).to eq("Queued = 4") - expect(@request.request_state).to eq("queued") + expect(@request.state).to eq("queued") expect(@request.status).to eq("Ok") end @@ -59,7 +59,7 @@ @task_1_1.update_and_notify_parent(:state => "active", :status => "Ok", :message => "Test Message") @request.reload expect(@request.message).to eq("Active = 2; Pending = 2") - expect(@request.request_state).to eq("active") + expect(@request.state).to eq("active") expect(@request.status).to eq("Ok") end @@ -67,7 +67,7 @@ @task_1_1.update_and_notify_parent(:state => "finished", :status => "Ok", :message => "Test Message") @request.reload expect(@request.message).to eq("Finished = 1; Pending = 2; Provisioned = 1") - expect(@request.request_state).to eq("active") + expect(@request.state).to eq("active") expect(@request.status).to eq("Ok") end @@ -78,7 +78,7 @@ @task_2_1.update_and_notify_parent(:state => "finished", :status => "Ok", :message => "Test Message") @request.reload expect(@request.message).to eq("Request complete") - expect(@request.request_state).to eq("finished") + expect(@request.state).to eq("finished") expect(@request.status).to eq("Ok") end @@ -86,7 +86,7 @@ @task_1_1.update_and_notify_parent(:state => "active", :status => "Error", :message => "Error Message") @request.reload expect(@request.message).to eq("Active = 2; Pending = 2") - expect(@request.request_state).to eq("active") + expect(@request.state).to eq("active") expect(@request.status).to eq("Error") end @@ -94,7 +94,7 @@ @task_1_1.update_and_notify_parent(:state => "finished", :status => "Error", :message => "Error Message") @request.reload expect(@request.message).to eq("Finished = 2; Pending = 2") - expect(@request.request_state).to eq("active") + expect(@request.state).to eq("active") expect(@request.status).to eq("Error") end @@ -103,7 +103,7 @@ @task_2_1.update_and_notify_parent(:state => "finished", :status => "Error", :message => "Test Message") @request.reload expect(@request.message).to eq("Request completed with errors") - expect(@request.request_state).to eq("finished") + expect(@request.state).to eq("finished") expect(@request.status).to eq("Error") end