From 6170667421d3d2be2833e1f05abd563692b24487 Mon Sep 17 00:00:00 2001 From: Leos Stejskal Date: Wed, 28 Aug 2024 11:08:30 +0200 Subject: [PATCH] Fixes #37800 - Don't apply the compute profile when updating host (cherry picked from commit 92e7ae96383932808fba4a0a7420a69032a09a66) --- app/controllers/api/v2/hosts_controller.rb | 1 - .../api/v2/hosts_controller_test.rb | 31 ++----------------- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/app/controllers/api/v2/hosts_controller.rb b/app/controllers/api/v2/hosts_controller.rb index b32e0ce0926..fea24492326 100644 --- a/app/controllers/api/v2/hosts_controller.rb +++ b/app/controllers/api/v2/hosts_controller.rb @@ -159,7 +159,6 @@ def update @all_parameters = true @host.attributes = host_attributes(host_params, @host) - apply_compute_profile(@host) if (params[:host] && params[:host][:compute_attributes].present?) || @host.compute_profile_id_changed? process_response @host.save rescue InterfaceTypeMapper::UnknownTypeException => e diff --git a/test/controllers/api/v2/hosts_controller_test.rb b/test/controllers/api/v2/hosts_controller_test.rb index a759c00b947..63370d057ff 100644 --- a/test/controllers/api/v2/hosts_controller_test.rb +++ b/test/controllers/api/v2/hosts_controller_test.rb @@ -374,19 +374,10 @@ def last_record post :create, params: { :host => valid_attrs } end - test "update applies attribute modifiers on the host" do - disable_orchestration - expect_attribute_modifier(ComputeAttributeMerge) - expect_attribute_modifier(InterfaceMerge, :merge_compute_attributes => true) - put :update, params: { :id => @host.to_param, :host => valid_attrs } - end - - test "update applies attribute modifiers on the host when compute profile is changed" do - disable_orchestration - expect_attribute_modifier(ComputeAttributeMerge) - expect_attribute_modifier(InterfaceMerge, :merge_compute_attributes => true) - + test "The update of the host does not apply the compute profile" do compute_attrs = compute_attributes(:with_interfaces) + + Host.any_instance.expects(:apply_compute_profile).never put :update, params: { :id => @host.to_param, :host => basic_attrs_with_profile(compute_attrs) } end @@ -429,22 +420,6 @@ def last_record assert_equal('newname', Nic::Base.find(nic_id).name) end - test "should update interfaces from compute profile" do - disable_orchestration - - compute_attrs = compute_attributes(:with_interfaces) - - put :update, params: { :id => @host.to_param, :host => basic_attrs_with_profile(compute_attrs) } - assert_response :success - - as_admin do - @host.interfaces.reload - assert_equal compute_attrs.vm_interfaces.count, @host.interfaces.count - assert_equal expected_compute_attributes(compute_attrs, 0), @host.interfaces.find_by_primary(true).compute_attributes - assert_equal expected_compute_attributes(compute_attrs, 1), @host.interfaces.find_by_primary(false).compute_attributes - end - end - test "should update host without :host root node and rails wraps it correctly" do put :update, params: { :id => @host.to_param, :name => 'newhostname' } request_parameters = @request.env['action_dispatch.request.request_parameters']