Skip to content

Commit 7294626

Browse files
committed
internal callbacks after creating/deleting releases
1 parent 73219b8 commit 7294626

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

chef/lib/chef/provider/deploy.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def cleanup!
146146
all_releases[0..-6].each do |old_release|
147147
Chef::Log.info "Removing old release #{old_release}"
148148
FileUtils.rm_rf(old_release)
149+
release_deleted(old_release)
149150
end
150151
end
151152

@@ -162,6 +163,7 @@ def copy_cached_repo
162163
Chef::Log.info "copying the cached checkout to #{release_path}"
163164
FileUtils.mkdir_p(@new_resource.deploy_to + "/releases")
164165
FileUtils.cp_r(@new_resource.destination, release_path, :preserve => true)
166+
release_created
165167
end
166168

167169
def enforce_ownership
@@ -209,6 +211,20 @@ def purge_tempfiles_from_current_release
209211

210212
protected
211213

214+
# Internal callback, called after copy_cached_repo.
215+
# Override if you need to keep state externally.
216+
def release_created
217+
end
218+
219+
# Internal callback, called during cleanup! for each old release removed.
220+
# Override if you need to keep state externally.
221+
def release_deleted(release_path)
222+
end
223+
224+
def release_slug
225+
raise Chef::Exceptions::Override, "You must override release_slug in #{self.to_s}"
226+
end
227+
212228
def install_gems
213229
gems_collection = Chef::ResourceCollection.new
214230
gem_packages.each { |rbgem| gems_collection << rbgem }
@@ -228,10 +244,6 @@ def gem_packages
228244
end
229245
end
230246

231-
def release_slug
232-
raise Chef::Exceptions::Override, "You must override release_slug in #{self.to_s}"
233-
end
234-
235247
def run_options(run_opts={})
236248
run_opts[:user] = @new_resource.user if @new_resource.user
237249
run_opts[:group] = @new_resource.group if @new_resource.group

chef/spec/unit/provider/deploy_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@
124124
@provider.copy_cached_repo
125125
end
126126

127+
it "calls the internal callback :release_created when copying the cached repo" do
128+
FileUtils.stub!(:mkdir_p)
129+
FileUtils.stub!(:cp_r)
130+
@provider.should_receive(:release_created)
131+
@provider.copy_cached_repo
132+
end
127133

128134
it "chowns the whole release dir to user and group specified in the resource" do
129135
@resource.user "foo"
@@ -235,6 +241,16 @@
235241
@provider.cleanup!
236242
end
237243

244+
it "fires a callback for :release_deleted when deleting an old release" do
245+
all_releases = ["/my/deploy/dir/20040815162342", "/my/deploy/dir/20040700000000",
246+
"/my/deploy/dir/20040600000000", "/my/deploy/dir/20040500000000",
247+
"/my/deploy/dir/20040400000000", "/my/deploy/dir/20040300000000"].sort!
248+
@provider.stub!(:all_releases).and_return(all_releases)
249+
FileUtils.stub!(:rm_rf)
250+
@provider.should_receive(:release_deleted).with("/my/deploy/dir/20040300000000")
251+
@provider.cleanup!
252+
end
253+
238254
it "puts resource.to_hash in @configuration for backwards compat with capistano-esque deploy hooks" do
239255
@provider.instance_variable_get(:@configuration).should == @resource.to_hash
240256
end

0 commit comments

Comments
 (0)