Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #12946 - Do not fail miserably when compute instance is not found. #3006

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/models/concerns/orchestration/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test/unit/orchestration/compute_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down