Permalink
Browse files

ignore directory not empty error when deleting droplets

  • Loading branch information...
1 parent a6dff31 commit 4f72de2afc95816f4a41eaec2728f1991fe45551 Dmitriy Kalinin committed Mar 27, 2013
Showing with 37 additions and 13 deletions.
  1. +3 −0 lib/cloud_controller/legacy_api/legacy_staging.rb
  2. +34 −13 spec/app_stager_spec.rb
@@ -99,6 +99,9 @@ def store_droplet(guid, path)
def delete_droplet(guid)
key = key_from_guid(guid)
droplet_dir.files.destroy(key)
+ rescue Errno::ENOTEMPTY => e
+ logger.warn("Failed to delete droplet: #{e}\n#{e.backtrace}")
+ true
end
def droplet_exists?(guid)
View
@@ -532,22 +532,43 @@ def store_app_package(app)
before { AppStager.unstub(:delete_droplet) }
let(:app) { Models::App.make }
- it "should do nothing if the droplet does not exist" do
- guid = Sham.guid
- LegacyStaging.droplet_exists?(guid).should == false
- AppStager.delete_droplet(app)
- LegacyStaging.droplet_exists?(guid).should == false
+ context "when droplet does not exist" do
+ it "does nothing" do
+ LegacyStaging.droplet_exists?(app.guid).should == false
+ AppStager.delete_droplet(app)
+ LegacyStaging.droplet_exists?(app.guid).should == false
+ end
end
- it "should delete the droplet if it exists" do
- droplet = Tempfile.new(app.guid)
- droplet.write("droplet contents")
- droplet.close
- LegacyStaging.store_droplet(app.guid, droplet.path)
+ context "when droplet exists" do
+ before { LegacyStaging.store_droplet(app.guid, droplet.path) }
+
+ let(:droplet) do
+ Tempfile.new(app.guid).tap do |f|
+ f.write("droplet-contents")
+ f.close
+ end
+ end
+
+ it "deletes the droplet if it exists" do
+ expect {
+ AppStager.delete_droplet(app)
+ }.to change {
+ LegacyStaging.droplet_exists?(app.guid)
+ }.from(true).to(false)
+ end
- LegacyStaging.droplet_exists?(app.guid).should == true
- AppStager.delete_droplet(app)
- LegacyStaging.droplet_exists?(app.guid).should == false
+ # Fog (local) tries to delete parent directories that might be empty
+ # when deleting a file. Sometimes it will fail due to a race
+ # since those directories might have been populated in between
+ # emptiness check and actual deletion.
+ it "does not raise error when it fails to delete directory structure" do
+ Fog::Collection
+ .any_instance
+ .should_receive(:destroy)
+ .and_raise(Errno::ENOTEMPTY)
+ AppStager.delete_droplet(app)
+ end
end
end
end

0 comments on commit 4f72de2

Please sign in to comment.