You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2012/12/10 13:35:38 UTC

git commit: Mock: Fix reporting wrong hardware profile when creating instances (DTACLOUD-364)

Updated Branches:
  refs/heads/master 45c8aa222 -> da8e09c0c


Mock: Fix reporting wrong hardware profile when creating instances (DTACLOUD-364)


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/da8e09c0
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/da8e09c0
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/da8e09c0

Branch: refs/heads/master
Commit: da8e09c0c2ef13e7da39933cbd3f939eb1d8ad2b
Parents: 45c8aa2
Author: Michal Fojtik <mf...@redhat.com>
Authored: Thu Nov 22 13:53:40 2012 +0100
Committer: Michal fojtik <mf...@redhat.com>
Committed: Mon Dec 10 11:20:27 2012 +0100

----------------------------------------------------------------------
 server/lib/deltacloud/drivers/base_driver.rb |   11 ++++-------
 server/tests/drivers/mock/instances_test.rb  |    6 ++++++
 2 files changed, 10 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/da8e09c0/server/lib/deltacloud/drivers/base_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/base_driver.rb b/server/lib/deltacloud/drivers/base_driver.rb
index b828d33..c63f94f 100644
--- a/server/lib/deltacloud/drivers/base_driver.rb
+++ b/server/lib/deltacloud/drivers/base_driver.rb
@@ -106,18 +106,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

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/da8e09c0/server/tests/drivers/mock/instances_test.rb
----------------------------------------------------------------------
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