summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAJ Christensen <aj@opscode.com>2009-10-22 04:54:44 +1300
committerAJ Christensen <aj@opscode.com>2009-10-22 04:54:44 +1300
commit6a5c822a629b3f2800dece11a6ff0bbe81d22ac5 (patch)
treebe73c20449376d92dfa22e8be26d46c0bfb8e6ab
parente5dc027d13aa26a8c9acdb595c69b4c1aafe3f46 (diff)
downloadchef-6a5c822a629b3f2800dece11a6ff0bbe81d22ac5.tar.gz
CHEF-628: all_releases broken for Deploy
Sorts results to ensure consistent removal of the oldest release instead of occasionally the first one. Tests cover Dir#glob results from a broken system and a non-broken system. Removed force_deploy attribute from the resource, added :force_deploy to allowed actions.
-rw-r--r--chef/lib/chef/provider/deploy.rb2
-rw-r--r--chef/lib/chef/resource/deploy.rb14
-rw-r--r--chef/spec/unit/provider/deploy_spec.rb41
-rw-r--r--chef/spec/unit/resource/deploy_spec.rb1
4 files changed, 33 insertions, 25 deletions
diff --git a/chef/lib/chef/provider/deploy.rb b/chef/lib/chef/provider/deploy.rb
index 60e8766002..b7b087a193 100644
--- a/chef/lib/chef/provider/deploy.rb
+++ b/chef/lib/chef/provider/deploy.rb
@@ -167,7 +167,7 @@ class Chef
end
def all_releases
- Dir.glob(@new_resource.deploy_to + "/releases/*")
+ Dir.glob(@new_resource.deploy_to + "/releases/*").sort
end
def update_cached_repo
diff --git a/chef/lib/chef/resource/deploy.rb b/chef/lib/chef/resource/deploy.rb
index a2fa41e09a..dcec877643 100644
--- a/chef/lib/chef/resource/deploy.rb
+++ b/chef/lib/chef/resource/deploy.rb
@@ -69,10 +69,9 @@ class Chef
@remote = "origin"
@enable_submodules = false
@shallow_clone = false
- @force_deploy = false
@scm_provider = Chef::Provider::Git
@provider = Chef::Provider::Deploy::Timestamped
- @allowed_actions.push(:deploy, :rollback)
+ @allowed_actions.push(:force_deploy, :deploy, :rollback)
end
# where the checked out/cloned code goes
@@ -244,15 +243,6 @@ class Chef
)
end
- # Shall we run the deploy even if the code has not changed?
- def force_deploy(arg=nil)
- set_or_return(
- :force_deploy,
- arg,
- :kind_of => [ TrueClass, FalseClass ]
- )
- end
-
def scm_provider(arg=nil)
set_or_return(
:scm_provider,
@@ -357,4 +347,4 @@ class Chef
end
end
-end \ No newline at end of file
+end
diff --git a/chef/spec/unit/provider/deploy_spec.rb b/chef/spec/unit/provider/deploy_spec.rb
index 8993f07b92..6eb9ff8ca2 100644
--- a/chef/spec/unit/provider/deploy_spec.rb
+++ b/chef/spec/unit/provider/deploy_spec.rb
@@ -79,18 +79,37 @@ describe Chef::Provider::Deploy do
@provider.should_receive(:deploy)
@provider.action_force_deploy
end
-
- it "sets the release path to the penultimate release, symlinks, and rm's the last release on rollback" do
- @provider.unstub!(:release_path)
- all_releases = ["/my/deploy/dir/releases/20040815162342", "/my/deploy/dir/releases/20040700000000",
- "/my/deploy/dir/releases/20040600000000", "/my/deploy/dir/releases/20040500000000"].sort!
- Dir.stub!(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases)
- @provider.should_receive(:symlink)
- FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/releases/20040815162342")
- @provider.action_rollback
- @provider.release_path.should eql("/my/deploy/dir/releases/20040700000000")
+
+ describe "on systems with broken Dir.glob results" do
+ it "sets the release path to the penultimate release, symlinks, and rm's the last release on rollback" do
+ @provider.unstub!(:release_path)
+ all_releases = [ "/my/deploy/dir/releases/20040815162342",
+ "/my/deploy/dir/releases/20040700000000",
+ "/my/deploy/dir/releases/20040600000000",
+ "/my/deploy/dir/releases/20040500000000"]
+ Dir.stub!(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases)
+ @provider.should_receive(:symlink)
+ FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/releases/20040815162342")
+ @provider.action_rollback
+ @provider.release_path.should eql("/my/deploy/dir/releases/20040700000000")
+ end
end
-
+
+ describe "CHEF-628: on systems without broken Dir.glob results" do
+ it "sets the release path to the penultimate release, symlinks, and rm's the last release on rollback" do
+ @provider.unstub!(:release_path)
+ all_releases = [ "/my/deploy/dir/releases/20040500000000",
+ "/my/deploy/dir/releases/20040600000000",
+ "/my/deploy/dir/releases/20040700000000",
+ "/my/deploy/dir/releases/20040815162342" ]
+ Dir.stub!(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases)
+ @provider.should_receive(:symlink)
+ FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/releases/20040815162342")
+ @provider.action_rollback
+ @provider.release_path.should eql("/my/deploy/dir/releases/20040700000000")
+ end
+ end
+
it "raises a runtime error when there's no release to rollback to" do
all_releases = []
Dir.stub!(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases)
diff --git a/chef/spec/unit/resource/deploy_spec.rb b/chef/spec/unit/resource/deploy_spec.rb
index 96f60ca8dc..939175f7aa 100644
--- a/chef/spec/unit/resource/deploy_spec.rb
+++ b/chef/spec/unit/resource/deploy_spec.rb
@@ -73,7 +73,6 @@ describe Chef::Resource::Deploy do
resource_has_a_boolean_attribute(:migrate, :defaults_to=>false)
resource_has_a_boolean_attribute(:enable_submodules, :defaults_to=>false)
resource_has_a_boolean_attribute(:shallow_clone, :defaults_to=>false)
- resource_has_a_boolean_attribute(:force_deploy, :defaults_to=>false)
it "uses the first argument as the deploy directory" do
@resource.deploy_to.should eql("/my/deploy/dir")