From 36577ffc744fc81db19c422cfb2814cf415dfb44 Mon Sep 17 00:00:00 2001 From: imriz Date: Mon, 28 Dec 2015 13:00:58 +0200 Subject: [PATCH] Fixes #12946 - Do not fail miserably when compute instance is not found. --- app/models/concerns/orchestration/compute.rb | 4 ++-- test/unit/orchestration/compute_test.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/orchestration/compute.rb b/app/models/concerns/orchestration/compute.rb index fc9cf68baaa..f47ce2d30dc 100644 --- a/app/models/concerns/orchestration/compute.rb +++ b/app/models/concerns/orchestration/compute.rb @@ -21,7 +21,7 @@ def compute_object # this is mostly relevant when the orchestration had a failure, and later on in the ui we try to retrieve the server again. # or when the server was removed not via foreman. elsif compute_resource_id.present? && compute_attributes - compute_resource.new_vm compute_attributes + compute_resource.new_vm compute_attributes rescue nil end end @@ -106,7 +106,7 @@ def setUserData def delUserData # Mostly copied from SSHProvision, should probably refactor to have both use a common set of PuppetCA actions - compute_attributes.merge!(:user_data => nil) # Unset any badly formatted data + compute_attributes.except!(:user_data) # Unset any badly formatted data # since we enable certificates/autosign via here, we also need to make sure we clean it up in case of an error if puppetca? respond_to?(:initialize_puppetca,true) && initialize_puppetca && delCertificate && delAutosign diff --git a/test/unit/orchestration/compute_test.rb b/test/unit/orchestration/compute_test.rb index b1b3b4fb0a0..0bdc3ca4e0a 100644 --- a/test/unit/orchestration/compute_test.rb +++ b/test/unit/orchestration/compute_test.rb @@ -9,6 +9,20 @@ class ComputeOrchestrationTest < ActiveSupport::TestCase assert host.errors.full_messages.first =~ /associate it/ end + test "rolling back userdata after it is set, deletes the attribute" do + image = images(:one) + host = FactoryGirl.build(:host, :operatingsystem => image.operatingsystem, :image => image, + :compute_resource => image.compute_resource) + prov_temp = FactoryGirl.create(:provisioning_template, :template_kind => TemplateKind.create(:name =>"user_data")) + host.stubs(:provisioning_template).returns(prov_temp) + attrs = {} + host.stubs(:compute_attributes).returns(attrs) + host.send(:setUserData) + assert_equal true, host.compute_attributes.key?(:user_data) + host.send(:delUserData) + assert_equal false, host.compute_attributes.key?(:user_data) + end + describe 'only physical interfaces are matched' do setup do @cr = FactoryGirl.build(:libvirt_cr)