Project

General

Profile

« Previous | Next » 

Revision cbe40e3d

Added by Ivan Necas almost 6 years ago

Refs #24072 - fix compute profile with CR set via HG

When compute resource is set via compute profile, we're not sending it
via the form (as it's disabled). Therefore, we need to search for in via
hostgroup.

View differences:

app/controllers/hosts_controller.rb
end
def compute_resource_selected
return not_found unless (params[:host] && (id = params[:host][:compute_resource_id]))
return not_found unless params[:host]
Taxonomy.as_taxonomy @organization, @location do
compute_profile_id = params[:host][:compute_profile_id] || Hostgroup.find_by_id(params[:host][:hostgroup_id]).try(:inherited_compute_profile_id)
compute_resource = ComputeResource.authorized(:view_compute_resources).find_by_id(id)
hostgroup = Hostgroup.find_by_id(params[:host][:hostgroup_id])
compute_resource_id = params[:host][:compute_resource_id] || hostgroup.try(:inherited_compute_resource_id)
return not_found if compute_resource_id.blank?
compute_profile_id = params[:host][:compute_profile_id] || hostgroup.try(:inherited_compute_profile_id)
compute_resource = ComputeResource.authorized(:view_compute_resources).find_by_id(compute_resource_id)
render :partial => "compute", :locals => { :compute_resource => compute_resource,
:vm_attrs => compute_resource.compute_profile_attributes_for(compute_profile_id) }
end
......
@host.set_hostgroup_defaults true
@host.set_compute_attributes unless params[:host][:compute_profile_id]
@host.apply_compute_profile(InterfaceMerge.new) if @host.compute_profile_id
set_class_variables(@host)
render :partial => "form"
end
test/integration/host_js_test.rb
test 'choosing a hostgroup with compute resource works' do
hostgroup = FactoryBot.create(:hostgroup, :with_environment, :with_subnet, :with_compute_resource)
compute_profile = FactoryBot.create(:compute_profile, :with_compute_attribute, :compute_resource => hostgroup.compute_resource)
compute_attributes = compute_profile.compute_attributes.where(:compute_resource_id => hostgroup.compute_resource.id).first
compute_attributes.vm_attrs['nics_attributes'] = {'0' => {'type' => 'bridge', 'bridge' => 'test'}}
compute_attributes.vm_attrs['cpus'] = '2'
compute_attributes.save
require 'fog/libvirt/models/compute/node'
Foreman::Model::Libvirt.any_instance.stubs(:hypervisor).returns(Fog::Compute::Libvirt::Node.new(:cpus => 4))
visit new_host_path
select2(hostgroup.name, :from => 'host_hostgroup_id')
wait_for_ajax
click_link('Virtual Machine')
assert page.has_text?('CPUs')
cpus_field = page.find_field('host_compute_attributes_cpus')
assert_equal '1', cpus_field.value
click_link('Host')
click_on_inherit('compute_profile')
select2(compute_profile.name, :from => 'host_compute_profile_id')
wait_for_ajax
click_link('Virtual Machine')
cpus_field = page.find_field('host_compute_attributes_cpus')
assert_equal '2', cpus_field.value
click_link('Interfaces')
click_button('Edit')
bridge_field = page.find_field('host_interfaces_attributes_0_compute_attributes_bridge')
assert_equal 'test', bridge_field.value
end
test 'saves correct values for inherited fields without hostgroup' do

Also available in: Unified diff