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 2011/07/15 10:57:27 UTC

svn commit: r1147038 - in /incubator/deltacloud/trunk/server: lib/deltacloud/drivers/mock/mock_driver.rb tests/common.rb tests/drivers/mock/images_test.rb

Author: mfojtik
Date: Fri Jul 15 08:57:26 2011
New Revision: 1147038

URL: http://svn.apache.org/viewvc?rev=1147038&view=rev
Log:
Added support for destroying an image to mock driver.
Added unit test to check if destroying image works.

Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb
    incubator/deltacloud/trunk/server/tests/common.rb
    incubator/deltacloud/trunk/server/tests/drivers/mock/images_test.rb

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb?rev=1147038&r1=1147037&r2=1147038&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb Fri Jul 15 08:57:26 2011
@@ -135,31 +135,29 @@ class MockDriver < Deltacloud::BaseDrive
 
   def create_image(credentials, opts={})
     check_credentials(credentials)
-    instance = instance(credentials, :id => opts[:instance_id])
+    instance = instance(credentials, :id => opts[:id])
     raise 'CreateImageNotSupported' unless instance.can_create_image?
-    ids = Dir[ "#{@storage_root}/images/*.yml" ].collect{|e| File.basename( e, ".yml" )}
-    count = 0
-    while true
-      next_id = "img#{count}"
-      break if not ids.include?(next_id)
-      count += 1
-    end
     safely do
       image = {
+        :id => opts[:name],
 	:name => opts[:name],
 	:owner_id => 'root',
 	:description => opts[:description],
 	:architecture => 'i386',
 	:state => 'UP'
       }
-      File.open( "#{@storage_root}/images/#{next_id}.yml", 'w' ) do |f|
+      File.open( "#{@storage_root}/images/#{opts[:name]}.yml", 'w' ) do |f|
 	YAML.dump( image, f )
       end
-      image[:id] = next_id
       Image.new(image)
     end
   end
 
+  def destroy_image(credentials, id)
+    check_credentials( credentials )
+    FileUtils.rm( "#{@storage_root}/images/#{id}.yml" )
+  end
+
   #
   # Instances
   #

Modified: incubator/deltacloud/trunk/server/tests/common.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/tests/common.rb?rev=1147038&r1=1147037&r2=1147038&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/tests/common.rb (original)
+++ incubator/deltacloud/trunk/server/tests/common.rb Fri Jul 15 08:57:26 2011
@@ -98,6 +98,11 @@ module DeltacloudTestCommon
       end
     else
       get(uri, params || {}, opts[:auth] ? authenticate(opts) : {})
+      if last_response.status.to_s =~ /5(\d{2})/
+        puts "============= [ ERROR ] ================"
+        puts last_response.inspect
+        puts "========================================"
+      end
     end
     last_response.status.should_not == 401
   end
@@ -105,6 +110,11 @@ module DeltacloudTestCommon
   def get_auth_url(uri, params={}, opts={})
     opts.merge!(:auth => true)
     get_url(uri, params, opts)
+    if last_response.status.to_s =~ /5(\d{2})/
+      puts "============= [ ERROR ] ================"
+      puts last_response.inspect
+      puts "========================================"
+    end
   end
 
   def post_url(uri, params={}, opts={})
@@ -114,7 +124,12 @@ module DeltacloudTestCommon
         post(uri, params || {}, authenticate(opts))
       end
     else
-        post(uri, params || {}, authenticate(opts))
+      post(uri, params || {}, authenticate(opts))
+      if last_response.status.to_s =~ /5(\d{2})/
+        puts "============= [ ERROR ] ================"
+        puts last_response.inspect
+        puts "========================================"
+      end
     end
   end
 
@@ -125,7 +140,12 @@ module DeltacloudTestCommon
         delete(uri, params || {}, authenticate(opts))
       end
     else
-        delete(uri, params || {}, authenticate(opts))
+      delete(uri, params || {}, authenticate(opts))
+      if last_response.status.to_s =~ /5(\d{2})/
+        puts "============= [ ERROR ] ================"
+        puts last_response.inspect
+        puts "========================================"
+      end
     end
   end
 
@@ -136,7 +156,12 @@ module DeltacloudTestCommon
         put(uri, params || {}, authenticate(opts))
       end
     else
-        put(uri, params || {}, authenticate(opts))
+       put(uri, params || {}, authenticate(opts))
+      if last_response.status.to_s =~ /5(\d{2})/
+        puts "============= [ ERROR ] ================"
+        puts last_response.inspect
+        puts "========================================"
+      end
     end
   end
 

Modified: incubator/deltacloud/trunk/server/tests/drivers/mock/images_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/tests/drivers/mock/images_test.rb?rev=1147038&r1=1147037&r2=1147038&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/tests/drivers/mock/images_test.rb (original)
+++ incubator/deltacloud/trunk/server/tests/drivers/mock/images_test.rb Fri Jul 15 08:57:26 2011
@@ -113,6 +113,15 @@ module DeltacloudUnitTest
       Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
     end
 
+    def test_it_can_destroy_created_image
+      post_url "/api/images", { :name => "img4", :description => "Test::Unit image", :instance_id => "inst1"}
+      last_response.status.should == 201
+      delete_url "/api/images/img4", {}
+      last_response.status.should == 204
+      get_auth_url "/api/images/img4", {}
+      last_response.status.should == 404
+    end
+
     private
 
     def test_image_attributes(image)