Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Look for resources in the same region as the selected template during provisioning. #13045

Merged
merged 1 commit into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/models/miq_provision_virt_workflow.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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