Project

General

Profile

« Previous | Next » 

Revision dc313926

Added by Ivan Necas almost 6 years ago

Fixes #24072 - freeip with compute resource via hostgroup

In #5790, we added an option to set the compute resource via hostgroup.
There was one thing missed though: the freeip not getting assigned
automagically, when the compute resource was selected this way.

After this change, we make sure to check for the ip addresses (and other
potential subnet related refreshes) after the hostgroup is selected, in
case the interfaces were populated during the hostgroup change.

View differences:

app/assets/javascripts/host_edit.js
}
var nic_update_handler = function() {
update_nics(function() {
interface_subnet_selected(primary_nic_form().find('select.interface_subnet'), 'ip');
interface_subnet_selected(primary_nic_form().find('select.interface_subnet6'), 'ip6');
});
update_nics(updatePrimarySubnetIPs);
};
function updatePrimarySubnetIPs() {
interface_subnet_selected(primary_nic_form().find('select.interface_subnet'), 'ip');
interface_subnet_selected(primary_nic_form().find('select.interface_subnet6'), 'ip6');
}
function computeResourceSelected(item){
providerSpecificNICInfo = null;
var compute = $(item).val();
......
// to handle case if def process_taxonomy changed compute_resource_id to nil
if (!host_compute_resource_id.val()) {
host_compute_resource_id.change();
} else {
// in case the compute resource was selected, we still want to check for
// free ip if applicable
updatePrimarySubnetIPs();
}
update_capabilities(host_compute_resource_id.val() ? $('#capabilities').val() : $('#bare_metal_capabilities').val());
}
test/integration/host_js_test.rb
end
test 'choosing a hostgroup with compute resource works' do
hostgroup = FactoryBot.create(:hostgroup, :with_environment, :with_subnet, :with_compute_resource)
hostgroup = FactoryBot.create(:hostgroup, :with_environment, :with_subnet, :with_domain, :with_compute_resource)
hostgroup.subnet.update!(ipam: IPAM::MODES[:db])
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'}}
......
cpus_field = page.find_field('host_compute_attributes_cpus')
assert_equal '1', cpus_field.value
click_link('Host')
click_link('Interfaces')
click_button('Edit')
ipv4_field = page.find_field('host_interfaces_attributes_0_ip')
refute_empty ipv4_field.value
close_interfaces_modal
find(:css, '#host_tab').click
click_on_inherit('compute_profile')
select2(compute_profile.name, :from => 'host_compute_profile_id')
wait_for_ajax
......
fill_in 'host_interfaces_attributes_0_mac', :with => '00:11:11:11:11:11'
wait_for_ajax
fill_in 'host_interfaces_attributes_0_ip', :with => '1.1.1.1'
click_button 'Ok' # close interfaces
# wait for the dialog to close
Timeout.timeout(Capybara.default_max_wait_time) do
loop while find(:css, '#interfaceModal', :visible => false).visible?
end
close_interfaces_modal
click_on_submit
find('#host-show') # wait for host details page
......
wait_for_ajax
fill_in 'host_interfaces_attributes_0_ip', :with => '2.3.4.44'
wait_for_ajax
click_button 'Ok'
# wait for the dialog to close
Timeout.timeout(Capybara.default_max_wait_time) do
loop while find(:css, '#interfaceModal', :visible => false).visible?
end
close_interfaces_modal
wait_for_ajax
click_on_submit
test/integration_test_helper.rb
end
end
def close_interfaces_modal
click_button 'Ok' # close interfaces
# wait for the dialog to close
Timeout.timeout(Capybara.default_max_wait_time) do
loop while find(:css, '#interfaceModal', :visible => false).visible?
end
end
def login_user(username, password)
logout_admin
visit "/"

Also available in: Unified diff