From: Michal Fojtik <[email protected]>
Signed-off-by: Michal fojtik <[email protected]> --- server/lib/deltacloud/drivers/base_driver.rb | 11 ++++------- server/tests/drivers/mock/instances_test.rb | 6 ++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/server/lib/deltacloud/drivers/base_driver.rb b/server/lib/deltacloud/drivers/base_driver.rb index cfb689d..2682684 100644 --- a/server/lib/deltacloud/drivers/base_driver.rb +++ b/server/lib/deltacloud/drivers/base_driver.rb @@ -102,18 +102,15 @@ module Deltacloud def find_hardware_profile(credentials, profile_id, image_id) hwp = nil - if name + if profile_id unless hwp = hardware_profile(credentials, profile_id) - raise BackendError.new(400, "bad-hardware-profile-name", - "Hardware profile '#{name}' does not exist", nil) + raise Exceptions.exception_from_status(400, "Hardware profile '#{profile_id}' does not exists.") end else unless image = image(credentials, :id=>image_id) - raise BackendError.new(400, "bad-image-id", - "Image with ID '#{image_id}' does not exist", nil) + raise Exceptions.exception_from_status(400, "Image #{image_id} does not exists.") end - hwp = hardware_profiles(credentials, - :architecture=>image.architecture).first + hwp = hardware_profiles(credentials, :architecture => image.architecture).first end return hwp end diff --git a/server/tests/drivers/mock/instances_test.rb b/server/tests/drivers/mock/instances_test.rb index 4c05136..686d1f3 100644 --- a/server/tests/drivers/mock/instances_test.rb +++ b/server/tests/drivers/mock/instances_test.rb @@ -54,6 +54,12 @@ describe 'MockDriver Instances' do @driver.instance(:id => instance.id).must_be_nil end + it 'must respond with proper error when using unknown hardware profile' do + Proc.new { + @driver.create_instance('img1', :name => 'inst2-test', :realm_id => 'us', :hwp_id => 'unknown') + }.must_raise Deltacloud::Exceptions::ValidationFailure + end + it 'must allow to destroy created instance' do instance = @driver.create_instance('img1', :name => 'inst1-test-destroy') instance.must_be_kind_of Instance -- 1.8.0
