Skip to content

Commit

Permalink
Merge pull request #13045 from lfu/in_region_1400991
Browse files Browse the repository at this point in the history
Look for resources in the same region as the selected template during provisioning.
(cherry picked from commit a25bb6c)

https://bugzilla.redhat.com/show_bug.cgi?id=1414886
  • Loading branch information
bdunne authored and simaishi committed Jan 19, 2017
1 parent 1525004 commit 4a41661
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/models/miq_provision_virt_workflow.rb
Expand Up @@ -357,6 +357,16 @@ def allowed_snapshots(_options = {})
result
end

def allowed_tags(options = {})
return {} if (source = load_ar_obj(get_source_vm)).blank?
super(options.merge(:region_number => source.region_number))
end

def allowed_pxe_servers(_options = {})
return {} if (source = load_ar_obj(get_source_vm)).blank?
PxeServer.in_region(source.region_number).each_with_object({}) { |p, h| h[p.id] = p.name }
end

def get_source_vm
get_source_and_targets[:vm]
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/miq_request_workflow.rb
Expand Up @@ -544,6 +544,8 @@ def get_tags
def allowed_tags(options = {})
return @tags unless @tags.nil?

region_number = options.delete(:region_number)

# TODO: Call allowed_tags properly from controller - it is currently hard-coded with no options passed
field_options = @dialogs.fetch_path(:dialogs, :purpose, :fields, :vm_tags, :options)
options = field_options unless field_options.nil?
Expand All @@ -557,6 +559,7 @@ def allowed_tags(options = {})
single_select = options[:single_select].blank? ? [] : options[:single_select].collect(&:to_s)

cats = Classification.visible.writeable.managed
cats = cats.in_region(region_number) if region_number
cats.each do |t|
next if exclude_list.include?(t.name)
next unless include_list.blank? || include_list.include?(t.name)
Expand All @@ -566,6 +569,7 @@ def allowed_tags(options = {})
end

ents = Classification.visible.writeable.parent_ids(@tags.keys).with_tag_name
ents = ents.in_region(region_number) if region_number
ents.each do |t|
full_tag_name = "#{@tags[t.parent_id][:name]}/#{t.name}"
next if exclude_list.include?(full_tag_name)
Expand Down
5 changes: 4 additions & 1 deletion app/models/mixins/cloud_init_template_mixin.rb
@@ -1,9 +1,12 @@
module CloudInitTemplateMixin
def allowed_cloud_init_customization_templates(_options = {})
result = []
return result if (source = load_ar_obj(get_source_vm)).blank?

customization_template_id = get_value(@values[:customization_template_id])
@values[:customization_template_script] = nil if customization_template_id.nil?
result = CustomizationTemplateCloudInit.all.collect do |c|

result = CustomizationTemplateCloudInit.in_region(source.region_number).all.collect do |c|
@values[:customization_template_script] = c.script if c.id == customization_template_id
build_ci_hash_struct(c, [:name, :description, :updated_at])
end
Expand Down
Expand Up @@ -128,6 +128,24 @@ def allowed_customization_templates(options)
expect(workflow).to receive(:super_allowed_customization_templates).with(options)
workflow.allowed_customization_templates(options)
end

it "should retrieve templates in region" do
template = FactoryGirl.create(:customization_template_cloud_init, :name => "test1")

my_region_number = template.my_region_number
other_region_id = (my_region_number + 1) * template.class.rails_sequence_factor + 1
pxe_image_type = FactoryGirl.create(:pxe_image_type, :name => "test_image", :id => other_region_id)
FactoryGirl.create(:customization_template_cloud_init,
:name => "test2",
:id => other_region_id,
:pxe_image_type => pxe_image_type)

expect(workflow).to receive(:supports_native_clone?).and_return(true)
result = workflow.allowed_customization_templates
expect(result.size).to eq(1)
expect(result.first.id).to eq(template.id)
expect(result.first.name).to eq(template.name)
end
end

describe "#make_request" do
Expand Down

0 comments on commit 4a41661

Please sign in to comment.