Permalink
Browse files

[cc][fix] Remove old droplets when using the new stager.

The new code for updating droplets staged with the new stager didn't
remove the previous droplet (if any).

Change-Id: Ieadc2d25d0e1fc66cf98443162a9c40f7171d35f
  • Loading branch information...
1 parent e250e1e commit ceef90d769d7aeaaaadfc93f8eff45c809490295 mpage committed Mar 1, 2012
Showing with 42 additions and 0 deletions.
  1. +7 −0 cloud_controller/app/models/app.rb
  2. +35 −0 cloud_controller/spec/models/app_spec.rb
@@ -521,6 +521,13 @@ def remove_collaborator(user)
end
def update_staged_package(upload_path)
+ # Remove old package if needed
+ if self.staged_package_path
+ CloudController.logger.info("Removing old staged package for" \
+ + " app_id=#{self.id} app_name=#{self.name}" \
+ + " path=#{self.staged_package_path}")
+ FileUtils.rm_f(self.staged_package_path)
+ end
self.staged_package_hash = Digest::SHA1.file(upload_path).hexdigest
FileUtils.mv(upload_path, self.staged_package_path)
end
@@ -56,11 +56,46 @@
end
end
+ describe '#update_staged_package' do
+ let(:app) { App.new }
+
+ before :each do
+ @tmpdir = Dir.mktmpdir
+ AppPackage.stubs(:package_dir).returns(@tmpdir)
+ end
+
+ after :each do
+ FileUtils.rm_rf(@tmpdir)
+ end
+
+ it 'should remove the old package' do
+ old_package = create_test_package(@tmpdir)
+ app.staged_package_hash = old_package[:name]
+
+ new_package = create_test_package(@tmpdir)
+ app.update_staged_package(new_package[:path])
+
+ File.exist?(old_package[:path]).should be_false
+ end
+ end
+
def create_user(email, pw)
u = User.new(:email => email)
u.set_and_encrypt_password(pw)
u.save
u.should be_valid
u
end
+
+ def create_test_package(base_dir)
+ name = "test_package#{Time.now.to_f}#{Process.pid}"
+ ret = {
+ :name => name,
+ :path => File.join(base_dir, name),
+ :contents => name,
+ }
+ File.open(ret[:path], 'w+') {|f| f.write(ret[:contents]) }
+
+ ret
+ end
end

0 comments on commit ceef90d

Please sign in to comment.