Project

General

Profile

« Previous | Next » 

Revision 4c512942

Added by Ivan Necas about 8 years ago

Fixes #13986 - don't use image unless in image provisioning method

View differences:

app/models/concerns/orchestration/compute.rb
end
def validate_compute_provisioning
return true unless image_build?
return true if ( compute_attributes.nil? or (compute_attributes[:image_id] || compute_attributes[:image_ref]).blank? )
img = find_image
if img
self.image = img
return true if compute_attributes.nil?
if image_build?
return true if (compute_attributes[:image_id] || compute_attributes[:image_ref]).blank?
img = find_image
if img
self.image = img
else
failure(_("Selected image does not belong to %s") % compute_resource) and return false
end
else
failure(_("Selected image does not belong to %s") % compute_resource) and return false
# don't send the image information to the compute resource unless using the image provisioning method
[:image_id, :image_ref].each { |image_key| compute_attributes.delete(image_key) }
end
end
test/unit/orchestration/compute_test.rb
host.send(:setComputeDetails)
assert_equal expected_message(nic.type), host.errors.full_messages.first
end
describe "validate compute provisioning" do
setup do
@image = images(:one)
@host = FactoryGirl.build(:host, :operatingsystem => @image.operatingsystem, :image => @image,
:compute_resource => @image.compute_resource)
end
test "it checks the image belongs to the compute resource" do
@host.provision_method = 'image'
@host.compute_attributes = { :image_id => @image.uuid }
assert @host.valid?
@host.compute_attributes = { :image_id => 'not-existing-image' }
refute @host.valid?
assert @host.errors.full_messages.first =~ /image does not belong to/
end
test "removes the image from compute attributes if the provision method is build" do
@host.provision_method = 'build'
@host.compute_attributes = { :image_id => @image.uuid }
assert @host.valid?
assert_not_include @host.compute_attributes, :image_id
end
end
end
end

Also available in: Unified diff