From d49ba1fe3e7da56436dc6caa792c1bafe83a611e Mon Sep 17 00:00:00 2001 From: Manisha Singhal Date: Fri, 6 Sep 2024 10:07:49 +0200 Subject: [PATCH] Fixes compute object update failure due to autosign key after build --- .../foreman_salt/concerns/host_managed_extensions.rb | 2 +- test/unit/host_extensions_test.rb | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/models/foreman_salt/concerns/host_managed_extensions.rb b/app/models/foreman_salt/concerns/host_managed_extensions.rb index 84385d9d..3424f9d0 100644 --- a/app/models/foreman_salt/concerns/host_managed_extensions.rb +++ b/app/models/foreman_salt/concerns/host_managed_extensions.rb @@ -42,7 +42,7 @@ def inherited_attributes validate :salt_modules_in_host_environment - after_build :ensure_salt_autosign, if: ->(host) { host.salt_proxy } + before_provision :ensure_salt_autosign, if: ->(host) { host.salt_proxy } before_destroy :remove_salt_minion, if: ->(host) { host.salt_proxy } end diff --git a/test/unit/host_extensions_test.rb b/test/unit/host_extensions_test.rb index 96f79594..a5d2fe5c 100644 --- a/test/unit/host_extensions_test.rb +++ b/test/unit/host_extensions_test.rb @@ -64,7 +64,7 @@ class HostExtensionsTest < ActiveSupport::TestCase context 'autosign handling' do before do - @host = FactoryBot.create(:host, :managed) + @host = FactoryBot.create(:host, salt_autosign_key: 'asdfasdfasfasdf') @host.salt_proxy = @proxy stub_request(:post, "#{@proxy.url}/salt/autosign_key/asdfasdfasfasdf") .to_return(status: 200, body: '', headers: {}) @@ -72,10 +72,9 @@ class HostExtensionsTest < ActiveSupport::TestCase .to_return(status: 200, body: '', headers: {}) end - test 'host autosign is created when host is built' do + test 'host autosign is created before host is provisioned' do autosign_key = 'asdfasdfasfasdf' - @host.expects(:generate_provisioning_key).returns(autosign_key) - @host.build = true + @host.build = false assert @host.save! @host.clear_host_parameters_cache!