Skip to content

Commit

Permalink
Revert "WIP - hack - workaround alias_attribute bug for now"
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jrafanie committed Jan 16, 2025
1 parent 5d50c1c commit a26da38
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/models/miq_provision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions app/models/miq_provision/naming.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions app/models/mixins/miq_provision_quota_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/service_template_provision_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/models/miq_approval_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/models/miq_provision_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
28 changes: 14 additions & 14 deletions spec/models/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/models/service_template_provision_request_quota_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down
18 changes: 9 additions & 9 deletions spec/models/service_template_provision_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
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

it "queued state" do
@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

Expand All @@ -51,23 +51,23 @@
@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

it "active state" do
@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

it "partial tasks finished" do
@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

Expand All @@ -78,23 +78,23 @@
@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

it "active with error state" do
@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

it "partial finish with error state" do
@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

Expand All @@ -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

Expand Down

0 comments on commit a26da38

Please sign in to comment.