Skip to content

Commit

Permalink
Improve allowed_storages filter spec
Browse files Browse the repository at this point in the history
The previous spec did not excercise the fix because the created objects'
ems_metadata tree did not match the `belongsto_filter` so the
`MiqFilter.belongsto2object_list` returned an empty array which bypassed
the `MiqPreloader.preload_and_map(sources, :storages)` call which caused
the exception.

Now without the fix in EmsFolder to add the `virtual_has_many` this spec
will raise the same exception we observed during provisioning.
  • Loading branch information
agrare committed Nov 4, 2024
1 parent eccb749 commit 12a9d26
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions spec/models/miq_request_workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,19 +350,39 @@
end

context "with a user with a belongs_to_filter" do
let(:root_folder) { FactoryBot.create(:ems_folder, :ems_id => ems.id).tap { |f| f.add_parent(ems) } }
let(:datacenter) { FactoryBot.create(:vmware_datacenter, :ems_id => ems.id).tap { |dc| dc.add_parent(root_folder) } }
let(:storage) { FactoryBot.create(:storage, :ems_id => ems.id).tap { |s| s.add_parent(datacenter) } }

before do
group = workflow.requester.miq_groups.first
group.entitlement = Entitlement.new
group.entitlement.set_managed_filters([])
group.entitlement.set_belongsto_filters(["/belongsto/ExtManagementSystem|#{ems.name}/EmsFolder|Datacenters"])
group.entitlement.set_belongsto_filters(belongsto_filter)
group.save!
end

it "filters out storages" do
allow(workflow).to receive(:get_source_and_targets).and_return(:ems => workflow.ci_to_hash_struct(ems))
allow(workflow).to receive(:allowed_hosts_obj).and_return([host])
context "with a filter that doesn't include the storage" do
let(:datacenter2) { FactoryBot.create(:vmware_datacenter, :ems_id => ems.id).tap { |f| f.add_parent(root_folder) } }
let(:belongsto_filter) { ["/belongsto/ExtManagementSystem|#{ems.name}/EmsFolder|#{root_folder.name}/EmsFolder|#{datacenter2.name}"] }

it "filters out storages" do
allow(workflow).to receive(:get_source_and_targets).and_return(:ems => workflow.ci_to_hash_struct(ems))
allow(workflow).to receive(:allowed_hosts_obj).and_return([host])

expect(workflow.allowed_storages.map(&:id)).to be_empty
end
end

context "with a filter that includes the storage" do
let(:belongsto_filter) { ["/belongsto/ExtManagementSystem|#{ems.name}/EmsFolder|#{root_folder.name}/EmsFolder|#{datacenter.name}/Storage|#{storage.name}"] }

expect(workflow.allowed_storages.map(&:id)).to be_empty
it "returns the storage" do
allow(workflow).to receive(:get_source_and_targets).and_return(:ems => workflow.ci_to_hash_struct(ems))
allow(workflow).to receive(:allowed_hosts_obj).and_return([host])

expect(workflow.allowed_storages.map(&:id)).to eq([storage.id])
end
end
end
end
Expand Down

0 comments on commit 12a9d26

Please sign in to comment.