Project

General

Profile

« Previous | Next » 

Revision 4cbb4a26

Added by Tom Caspy over 9 years ago

fixes #6098 - ec2 compute resources now check image validity.

View differences:

app/models/compute_resource.rb
false
end
def image_exists?(image)
true
end
protected
def client
app/models/compute_resources/foreman/model/ec2.rb
true
end
def image_exists?(image)
client.images.get(image).present?
end
private
def subnet_implies_is_vpc? args
app/models/image.rb
validates_lengths_from_database
validates :username, :name, :operatingsystem_id, :compute_resource_id, :architecture_id, :presence => true
validates :uuid, :presence => true, :uniqueness => {:scope => :compute_resource_id}
validate :uuid_exists?
scoped_search :on => [:name, :username], :complete_value => true
scoped_search :in => :compute_resources, :on => :name, :complete_value => :true, :rename => "compute_resource"
......
scoped_search :in => :operatingsystem, :on => :id, :rename => "operatingsystem", :complete_enabled => false, :only_explicit => true
scoped_search :on => :user_data, :complete_value => {:true => true, :false => false}
private
def uuid_exists?
return true if compute_resource.blank?
errors.add(:uuid, _("could not be found in %s") % compute_resource.name) unless compute_resource.image_exists?(uuid)
end
end
test/unit/host_test.rb
disable_orchestration
User.current = users :admin
Setting[:token_duration] = 0
Foreman::Model::EC2.any_instance.stubs(:image_exists?).returns(true)
end
test "should not save without a hostname" do
test/unit/image_test.rb
assert_nil host.image_id
end
test "image is invalid if uuid invalid" do
resource = compute_resources(:one)
image = resource.images.build(:name => "foo", :uuid => "bar")
ComputeResource.any_instance.stubs(:image_exists?).returns(false)
image.valid? #trigger validations
assert image.errors.messages.keys.include?(:uuid)
end
end

Also available in: Unified diff