From 548d782f7a71e381e7aad940fd79201375062bbf Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Wed, 22 Mar 2017 18:09:33 -0400 Subject: [PATCH 1/2] Add test for MiqProvisionVirtWorkflow#allowed_templates https://bugzilla.redhat.com/show_bug.cgi?id=1398725 --- .../miq_provision_virt_workflow_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/models/miq_provision_virt_workflow_spec.rb b/spec/models/miq_provision_virt_workflow_spec.rb index ec029dac9f6..b4297ccb5c1 100644 --- a/spec/models/miq_provision_virt_workflow_spec.rb +++ b/spec/models/miq_provision_virt_workflow_spec.rb @@ -320,4 +320,23 @@ expect(request.source_id).to eq(template.id) end end + + context "#allowed_templates" do + let(:external_region_id) do + remote_region_number = ApplicationRecord.my_region_number + 1 + ApplicationRecord.region_to_range(remote_region_number).first + end + + let(:remote_vmware) { FactoryGirl.create(:ems_vmware_with_authentication, :id => external_region_id) } + let(:local_vmware) { FactoryGirl.create(:ems_vmware_with_authentication) } + + it "only returns records from its region" do + EvmSpecHelper.local_guid_miq_server_zone # Because there is no default timezone in settings + FactoryGirl.create(:template_vmware, :ext_management_system => remote_vmware, :id => external_region_id) + FactoryGirl.create(:template_vmware, :ext_management_system => local_vmware) + + expect(MiqTemplate.count).to eq(2) + expect(workflow.allowed_templates.count).to eq(1) + end + end end From 7853c6fe4ba9547df440630df97dcf47fcefa917 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Wed, 22 Mar 2017 18:11:01 -0400 Subject: [PATCH 2/2] Limit selectable template to the local region https://bugzilla.redhat.com/show_bug.cgi?id=1398725 --- app/models/miq_provision_virt_workflow.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/miq_provision_virt_workflow.rb b/app/models/miq_provision_virt_workflow.rb index 8fd2126c3c6..7f3188ccabb 100644 --- a/app/models/miq_provision_virt_workflow.rb +++ b/app/models/miq_provision_virt_workflow.rb @@ -288,7 +288,7 @@ def allowed_templates(options = {}) end rails_logger('allowed_templates', 0) - vms = VmOrTemplate.all + vms = VmOrTemplate.in_my_region.all condition = allowed_template_condition unless options[:tag_filters].blank? @@ -309,7 +309,7 @@ def allowed_templates(options = {}) unless tag_conditions.blank? _log.info "Filtering VM templates with the following tag_filters: <#{tag_conditions.inspect}>" - vms = MiqTemplate.where(condition).find_tags_by_grouping(tag_conditions, :ns => "/managed") + vms = MiqTemplate.in_my_region.where(condition).find_tags_by_grouping(tag_conditions, :ns => "/managed") end end