chef 10.16.2 → 10.16.4.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- data/distro/common/html/chef-client.8.html +4 -4
- data/distro/common/html/chef-expander.8.html +4 -4
- data/distro/common/html/chef-expanderctl.8.html +4 -4
- data/distro/common/html/chef-server-webui.8.html +4 -4
- data/distro/common/html/chef-server.8.html +4 -4
- data/distro/common/html/chef-solo.8.html +4 -4
- data/distro/common/html/chef-solr.8.html +4 -4
- data/distro/common/html/knife-bootstrap.1.html +4 -4
- data/distro/common/html/knife-client.1.html +5 -5
- data/distro/common/html/knife-configure.1.html +5 -5
- data/distro/common/html/knife-cookbook-site.1.html +7 -7
- data/distro/common/html/knife-cookbook.1.html +8 -8
- data/distro/common/html/knife-data-bag.1.html +4 -4
- data/distro/common/html/knife-environment.1.html +7 -7
- data/distro/common/html/knife-exec.1.html +4 -4
- data/distro/common/html/knife-index.1.html +5 -5
- data/distro/common/html/knife-node.1.html +5 -5
- data/distro/common/html/knife-role.1.html +4 -4
- data/distro/common/html/knife-search.1.html +6 -6
- data/distro/common/html/knife-ssh.1.html +5 -5
- data/distro/common/html/knife-status.1.html +5 -5
- data/distro/common/html/knife-tag.1.html +4 -4
- data/distro/common/html/knife.1.html +320 -0
- data/distro/common/html/shef.1.html +8 -8
- data/distro/common/man/man1/knife-bootstrap.1 +1 -1
- data/distro/common/man/man1/knife-client.1 +1 -1
- data/distro/common/man/man1/knife-configure.1 +1 -1
- data/distro/common/man/man1/knife-cookbook-site.1 +1 -1
- data/distro/common/man/man1/knife-cookbook.1 +1 -1
- data/distro/common/man/man1/knife-data-bag.1 +1 -1
- data/distro/common/man/man1/knife-environment.1 +1 -1
- data/distro/common/man/man1/knife-exec.1 +1 -1
- data/distro/common/man/man1/knife-index.1 +1 -1
- data/distro/common/man/man1/knife-node.1 +1 -1
- data/distro/common/man/man1/knife-role.1 +1 -1
- data/distro/common/man/man1/knife-search.1 +1 -1
- data/distro/common/man/man1/knife-ssh.1 +1 -1
- data/distro/common/man/man1/knife-status.1 +1 -1
- data/distro/common/man/man1/knife-tag.1 +1 -1
- data/distro/common/man/man1/knife.1 +1 -1
- data/distro/common/man/man1/shef.1 +1 -1
- data/distro/common/man/man8/chef-client.8 +1 -1
- data/distro/common/man/man8/chef-expander.8 +1 -1
- data/distro/common/man/man8/chef-expanderctl.8 +1 -1
- data/distro/common/man/man8/chef-server-webui.8 +1 -1
- data/distro/common/man/man8/chef-server.8 +1 -1
- data/distro/common/man/man8/chef-solo.8 +1 -1
- data/distro/common/man/man8/chef-solr.8 +1 -1
- data/lib/chef/config.rb +1 -1
- data/lib/chef/knife/bootstrap.rb +0 -1
- data/lib/chef/knife/bootstrap/ubuntu12.10-gems.erb +60 -0
- data/lib/chef/knife/ssh.rb +7 -4
- data/lib/chef/mixin/why_run.rb +4 -11
- data/lib/chef/provider.rb +3 -7
- data/lib/chef/provider/deploy.rb +0 -6
- data/lib/chef/provider/remote_directory.rb +13 -18
- data/lib/chef/provider/service.rb +1 -1
- data/lib/chef/version.rb +1 -1
- data/spec/data/git_bundles/sinatra-test-app-with-callback-files.gitbundle +0 -0
- data/spec/data/git_bundles/sinatra-test-app.gitbundle +0 -0
- data/spec/functional/resource/deploy_revision_spec.rb +499 -0
- data/spec/unit/config_spec.rb +8 -0
- data/spec/unit/knife/ssh_spec.rb +17 -0
- data/spec/unit/provider/deploy/revision_spec.rb +0 -6
- data/spec/unit/provider/deploy_spec.rb +4 -38
- data/spec/unit/provider/erl_call_spec.rb +0 -2
- data/spec/unit/provider/file_spec.rb +0 -1
- data/spec/unit/provider/git_spec.rb +0 -10
- data/spec/unit/provider/group/groupadd_spec.rb +1 -1
- data/spec/unit/provider/package/rubygems_spec.rb +0 -18
- data/spec/unit/provider/package/yum_spec.rb +0 -4
- data/spec/unit/provider/remote_directory_spec.rb +15 -2
- data/spec/unit/provider/route_spec.rb +0 -4
- data/spec/unit/provider/service_spec.rb +2 -2
- data/spec/unit/provider/user_spec.rb +7 -16
- data/spec/unit/provider_spec.rb +4 -3
- metadata +23 -13
data/lib/chef/provider/deploy.rb
CHANGED
@@ -149,12 +149,6 @@ class Chef
|
|
149
149
|
|
150
150
|
def deploy
|
151
151
|
verify_directories_exist
|
152
|
-
# CHEF-3435: We need to create the directories if they don't exist before calling the
|
153
|
-
# scm_provider because it expects them to be there in its own assertations
|
154
|
-
unless self.converge_actions.empty?
|
155
|
-
Chef::Log.info "#{@new_resource} running collected converge_actions before calling scm_provider"
|
156
|
-
self.converge_actions.converge!
|
157
|
-
end
|
158
152
|
update_cached_repo # no converge-by - scm provider will dothis
|
159
153
|
enforce_ownership
|
160
154
|
copy_cached_repo
|
@@ -39,22 +39,18 @@ class Chef
|
|
39
39
|
name !~ /(?:^|#{Regexp.escape(::File::SEPARATOR)})\.\.?$/
|
40
40
|
end)
|
41
41
|
|
42
|
-
converge_by("Create managed files in directory") do
|
43
|
-
files_to_transfer.each do |cookbook_file_relative_path|
|
44
|
-
create_cookbook_file(cookbook_file_relative_path)
|
45
|
-
# the file is removed from the purge list
|
46
|
-
files_to_purge.delete(::File.join(@new_resource.path, cookbook_file_relative_path))
|
47
|
-
# parent directories are also removed from the purge list
|
48
|
-
directories=::File.dirname(::File.join(@new_resource.path, cookbook_file_relative_path)).split(::File::SEPARATOR)
|
49
|
-
for i in 0..directories.length-1
|
50
|
-
files_to_purge.delete(::File.join(directories[0..i]))
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
42
|
|
55
|
-
|
56
|
-
|
43
|
+
files_to_transfer.each do |cookbook_file_relative_path|
|
44
|
+
create_cookbook_file(cookbook_file_relative_path)
|
45
|
+
# the file is removed from the purge list
|
46
|
+
files_to_purge.delete(::File.join(@new_resource.path, cookbook_file_relative_path))
|
47
|
+
# parent directories are also removed from the purge list
|
48
|
+
directories=::File.dirname(::File.join(@new_resource.path, cookbook_file_relative_path)).split(::File::SEPARATOR)
|
49
|
+
for i in 0..directories.length-1
|
50
|
+
files_to_purge.delete(::File.join(directories[0..i]))
|
51
|
+
end
|
57
52
|
end
|
53
|
+
purge_unmanaged_files(files_to_purge)
|
58
54
|
end
|
59
55
|
|
60
56
|
def action_create_if_missing
|
@@ -173,11 +169,10 @@ class Chef
|
|
173
169
|
dir
|
174
170
|
end
|
175
171
|
|
176
|
-
|
172
|
+
def whyrun_supported?
|
173
|
+
true
|
174
|
+
end
|
177
175
|
|
178
|
-
def whyrun_supported?
|
179
|
-
true
|
180
176
|
end
|
181
|
-
|
182
177
|
end
|
183
178
|
end
|
@@ -121,7 +121,7 @@ class Chef
|
|
121
121
|
|
122
122
|
def action_reload
|
123
123
|
if @current_resource.running
|
124
|
-
converge_by("
|
124
|
+
converge_by("reload service #{@new_resource}") do
|
125
125
|
reload_service
|
126
126
|
Chef::Log.info("#{@new_resource} reloaded")
|
127
127
|
end
|
data/lib/chef/version.rb
CHANGED
Binary file
|
@@ -0,0 +1,499 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Daniel DeLeo (<dan@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'spec_helper'
|
20
|
+
require 'tmpdir'
|
21
|
+
|
22
|
+
# Deploy relies heavily on symlinks, so it doesn't work on windows.
|
23
|
+
describe Chef::Resource::DeployRevision, :unix_only => true do
|
24
|
+
|
25
|
+
let(:file_cache_path) { Dir.mktmpdir }
|
26
|
+
let(:deploy_directory) { Dir.mktmpdir }
|
27
|
+
|
28
|
+
# By making restart or other operations write to this file, we can externally
|
29
|
+
# track the order in which those operations happened.
|
30
|
+
let(:observe_order_file) { Tempfile.new("deploy-resource-observe-operations") }
|
31
|
+
|
32
|
+
before do
|
33
|
+
@old_file_cache_path = Chef::Config[:file_cache_path]
|
34
|
+
Chef::Config[:file_cache_path] = file_cache_path
|
35
|
+
end
|
36
|
+
|
37
|
+
after do
|
38
|
+
Chef::Config[:file_cache_path] = @old_file_cache_path
|
39
|
+
FileUtils.remove_entry_secure deploy_directory if File.exist?(deploy_directory)
|
40
|
+
FileUtils.remove_entry_secure file_cache_path
|
41
|
+
observe_order_file.close
|
42
|
+
FileUtils.remove_entry_secure observe_order_file.path
|
43
|
+
end
|
44
|
+
|
45
|
+
before(:all) do
|
46
|
+
@ohai = Ohai::System.new
|
47
|
+
@ohai.require_plugin("os")
|
48
|
+
end
|
49
|
+
|
50
|
+
let(:node) do
|
51
|
+
|
52
|
+
Chef::Node.new.tap do |n|
|
53
|
+
n.name "rspec-test"
|
54
|
+
n.consume_external_attrs(@ohai.data, {})
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
let(:event_dispatch) { Chef::EventDispatch::Dispatcher.new }
|
59
|
+
let(:run_context) { Chef::RunContext.new(node, {}, event_dispatch) }
|
60
|
+
|
61
|
+
|
62
|
+
# These tests use git's bundle feature, which is a way to export an entire
|
63
|
+
# git repo (or subset of commits) as a single file.
|
64
|
+
#
|
65
|
+
# Generally you can treat a git bundle as a regular git remote.
|
66
|
+
#
|
67
|
+
# See also: http://git-scm.com/2010/03/10/bundles.html
|
68
|
+
let(:git_bundle_repo) { File.expand_path("git_bundles/sinatra-test-app.gitbundle", CHEF_SPEC_DATA) }
|
69
|
+
|
70
|
+
let(:git_bundle_with_in_repo_callbacks) { File.expand_path("git_bundles/sinatra-test-app-with-callback-files.gitbundle", CHEF_SPEC_DATA) }
|
71
|
+
|
72
|
+
# This is the fourth version
|
73
|
+
let(:latest_rev) { "3eb5ca6c353c83d9179dd3b29347539829b401f3" }
|
74
|
+
|
75
|
+
# This is the third version
|
76
|
+
let(:previous_rev) { "6d19a6dbecc8e37f5b2277345885c0c783eb8fb1" }
|
77
|
+
|
78
|
+
|
79
|
+
# This is the sixth version, it is on the "with-deploy-scripts" branch
|
80
|
+
let(:rev_with_in_repo_callbacks) { "2404d015882659754bdb93ad6e4b4d3d02691a82" }
|
81
|
+
|
82
|
+
# Read values from the +observe_order_file+ and split each line. This way you
|
83
|
+
# can see in which order things really happened.
|
84
|
+
def actual_operations_order
|
85
|
+
IO.read(observe_order_file.path).split("\n").map(&:strip)
|
86
|
+
end
|
87
|
+
|
88
|
+
# 1. touch `restart.txt` in cwd so we know that the command is run with the
|
89
|
+
# right cwd.
|
90
|
+
# 2. Append +tag+ to the `observe_order_file` so we can check the order in
|
91
|
+
# which operations happen later in the test.
|
92
|
+
def shell_restart_command(tag)
|
93
|
+
"touch restart.txt && echo '#{tag}' >> #{observe_order_file.path}"
|
94
|
+
end
|
95
|
+
|
96
|
+
let(:basic_deploy_resource) do
|
97
|
+
Chef::Resource::DeployRevision.new(deploy_directory, run_context).tap do |r|
|
98
|
+
r.repo git_bundle_repo
|
99
|
+
r.symlink_before_migrate({})
|
100
|
+
r.symlinks({})
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
let(:deploy_to_latest_rev) do
|
105
|
+
basic_deploy_resource.dup.tap do |r|
|
106
|
+
r.revision(latest_rev)
|
107
|
+
r.restart_command shell_restart_command(:deploy_to_latest_rev)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
let(:deploy_to_previous_rev) do
|
112
|
+
basic_deploy_resource.dup.tap do |r|
|
113
|
+
r.revision(previous_rev)
|
114
|
+
r.restart_command shell_restart_command(:deploy_to_previous_rev)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
let(:deploy_to_latest_rev_again) do
|
119
|
+
basic_deploy_resource.dup.tap do |r|
|
120
|
+
r.revision(latest_rev)
|
121
|
+
r.restart_command shell_restart_command(:deploy_to_latest_rev_again)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Computes the full path for +path+ relative to the deploy directory
|
126
|
+
def rel_path(path)
|
127
|
+
File.expand_path(path, deploy_directory)
|
128
|
+
end
|
129
|
+
|
130
|
+
def actual_current_rev
|
131
|
+
Dir.chdir(rel_path("current")) do
|
132
|
+
`git rev-parse HEAD`.strip
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def self.the_app_is_deployed_at_revision(target_rev_spec)
|
137
|
+
it "deploys the app to the target revision (#{target_rev_spec})" do
|
138
|
+
target_rev = send(target_rev_spec)
|
139
|
+
|
140
|
+
File.should exist(rel_path("current"))
|
141
|
+
|
142
|
+
actual_current_rev.should == target_rev
|
143
|
+
|
144
|
+
# Is the app code actually there?
|
145
|
+
File.should exist(rel_path("current/app/app.rb"))
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context "when deploying a simple app" do
|
150
|
+
describe "for the first time, with the required directory layout precreated" do
|
151
|
+
before do
|
152
|
+
FileUtils.mkdir_p(rel_path("releases"))
|
153
|
+
FileUtils.mkdir_p(rel_path("shared"))
|
154
|
+
deploy_to_latest_rev.run_action(:deploy)
|
155
|
+
end
|
156
|
+
|
157
|
+
the_app_is_deployed_at_revision(:latest_rev)
|
158
|
+
|
159
|
+
it "restarts the application" do
|
160
|
+
File.should exist(rel_path("current/restart.txt"))
|
161
|
+
actual_operations_order.should == %w[deploy_to_latest_rev]
|
162
|
+
end
|
163
|
+
|
164
|
+
it "is marked as updated" do
|
165
|
+
deploy_to_latest_rev.should be_updated_by_last_action
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe "back to a previously deployed revision, with the directory structure precreated" do
|
170
|
+
before do
|
171
|
+
FileUtils.mkdir_p(rel_path("releases"))
|
172
|
+
FileUtils.mkdir_p(rel_path("shared"))
|
173
|
+
|
174
|
+
deploy_to_latest_rev.run_action(:deploy)
|
175
|
+
deploy_to_previous_rev.run_action(:deploy)
|
176
|
+
deploy_to_latest_rev_again.run_action(:deploy)
|
177
|
+
end
|
178
|
+
|
179
|
+
the_app_is_deployed_at_revision(:latest_rev)
|
180
|
+
|
181
|
+
it "restarts the application after rolling back" do
|
182
|
+
actual_operations_order.should == %w[deploy_to_latest_rev deploy_to_previous_rev deploy_to_latest_rev_again]
|
183
|
+
end
|
184
|
+
|
185
|
+
it "is marked updated" do
|
186
|
+
deploy_to_latest_rev_again.should be_updated_by_last_action
|
187
|
+
end
|
188
|
+
|
189
|
+
it "deploys the right code" do
|
190
|
+
IO.read(rel_path("current/app/app.rb")).should include("this is the fourth version of the app")
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe "for the first time, with no existing directory layout" do
|
195
|
+
before do
|
196
|
+
deploy_to_latest_rev.run_action(:deploy)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "creates the required directory tree" do
|
200
|
+
File.should be_directory(rel_path("releases"))
|
201
|
+
File.should be_directory(rel_path("shared"))
|
202
|
+
File.should be_directory(rel_path("releases/#{latest_rev}"))
|
203
|
+
|
204
|
+
File.should be_directory(rel_path("current/tmp"))
|
205
|
+
File.should be_directory(rel_path("current/config"))
|
206
|
+
File.should be_directory(rel_path("current/public"))
|
207
|
+
|
208
|
+
File.should be_symlink(rel_path("current"))
|
209
|
+
File.readlink(rel_path("current")).should == rel_path("releases/#{latest_rev}")
|
210
|
+
end
|
211
|
+
|
212
|
+
the_app_is_deployed_at_revision(:latest_rev)
|
213
|
+
|
214
|
+
it "restarts the application" do
|
215
|
+
File.should exist(rel_path("current/restart.txt"))
|
216
|
+
actual_operations_order.should == %w[deploy_to_latest_rev]
|
217
|
+
end
|
218
|
+
|
219
|
+
it "is marked as updated" do
|
220
|
+
deploy_to_latest_rev.should be_updated_by_last_action
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe "again to the current revision" do
|
225
|
+
before do
|
226
|
+
deploy_to_latest_rev.run_action(:deploy)
|
227
|
+
deploy_to_latest_rev.run_action(:deploy)
|
228
|
+
end
|
229
|
+
|
230
|
+
the_app_is_deployed_at_revision(:latest_rev)
|
231
|
+
|
232
|
+
it "does not restart the app" do
|
233
|
+
actual_operations_order.should == %w[deploy_to_latest_rev]
|
234
|
+
end
|
235
|
+
|
236
|
+
it "is not marked updated" do
|
237
|
+
deploy_to_latest_rev.should_not be_updated_by_last_action
|
238
|
+
end
|
239
|
+
|
240
|
+
end
|
241
|
+
|
242
|
+
describe "again with force_deploy" do
|
243
|
+
before do
|
244
|
+
deploy_to_latest_rev.run_action(:force_deploy)
|
245
|
+
deploy_to_latest_rev_again.run_action(:force_deploy)
|
246
|
+
end
|
247
|
+
|
248
|
+
the_app_is_deployed_at_revision(:latest_rev)
|
249
|
+
|
250
|
+
it "restarts the app" do
|
251
|
+
actual_operations_order.should == %w[deploy_to_latest_rev deploy_to_latest_rev_again]
|
252
|
+
end
|
253
|
+
|
254
|
+
it "is marked updated" do
|
255
|
+
deploy_to_latest_rev.should be_updated_by_last_action
|
256
|
+
end
|
257
|
+
|
258
|
+
end
|
259
|
+
|
260
|
+
describe "again to a new revision" do
|
261
|
+
before do
|
262
|
+
deploy_to_previous_rev.run_action(:deploy)
|
263
|
+
deploy_to_latest_rev.run_action(:deploy)
|
264
|
+
end
|
265
|
+
|
266
|
+
the_app_is_deployed_at_revision(:latest_rev)
|
267
|
+
|
268
|
+
it "restarts the application after the new deploy" do
|
269
|
+
actual_operations_order.should == %w[deploy_to_previous_rev deploy_to_latest_rev]
|
270
|
+
end
|
271
|
+
|
272
|
+
it "is marked updated" do
|
273
|
+
deploy_to_previous_rev.should be_updated_by_last_action
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
describe "back to a previously deployed revision (implicit rollback)" do
|
278
|
+
before do
|
279
|
+
deploy_to_latest_rev.run_action(:deploy)
|
280
|
+
deploy_to_previous_rev.run_action(:deploy)
|
281
|
+
deploy_to_latest_rev_again.run_action(:deploy)
|
282
|
+
end
|
283
|
+
|
284
|
+
the_app_is_deployed_at_revision(:latest_rev)
|
285
|
+
|
286
|
+
it "restarts the application after rolling back" do
|
287
|
+
actual_operations_order.should == %w[deploy_to_latest_rev deploy_to_previous_rev deploy_to_latest_rev_again]
|
288
|
+
end
|
289
|
+
|
290
|
+
it "is marked updated" do
|
291
|
+
deploy_to_latest_rev_again.should be_updated_by_last_action
|
292
|
+
end
|
293
|
+
|
294
|
+
it "deploys the right code" do
|
295
|
+
IO.read(rel_path("current/app/app.rb")).should include("this is the fourth version of the app")
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
# CHEF-3435
|
300
|
+
describe "to a deploy_to path that does not yet exist" do
|
301
|
+
|
302
|
+
let(:top_level_tmpdir) { Dir.mktmpdir }
|
303
|
+
|
304
|
+
# override top level deploy_directory let block with one that is two
|
305
|
+
# directories deeper
|
306
|
+
let(:deploy_directory) { File.expand_path("nested/deeper", top_level_tmpdir) }
|
307
|
+
|
308
|
+
after do
|
309
|
+
FileUtils.remove_entry_secure top_level_tmpdir
|
310
|
+
end
|
311
|
+
|
312
|
+
before do
|
313
|
+
File.should_not exist(deploy_directory)
|
314
|
+
deploy_to_latest_rev.run_action(:deploy)
|
315
|
+
end
|
316
|
+
|
317
|
+
it "creates the required directory tree" do
|
318
|
+
File.should be_directory(rel_path("releases"))
|
319
|
+
File.should be_directory(rel_path("shared"))
|
320
|
+
File.should be_directory(rel_path("releases/#{latest_rev}"))
|
321
|
+
|
322
|
+
File.should be_directory(rel_path("current/tmp"))
|
323
|
+
File.should be_directory(rel_path("current/config"))
|
324
|
+
File.should be_directory(rel_path("current/public"))
|
325
|
+
|
326
|
+
File.should be_symlink(rel_path("current"))
|
327
|
+
File.readlink(rel_path("current")).should == rel_path("releases/#{latest_rev}")
|
328
|
+
end
|
329
|
+
|
330
|
+
the_app_is_deployed_at_revision(:latest_rev)
|
331
|
+
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
context "when deploying an app with inline recipe callbacks" do
|
336
|
+
|
337
|
+
# Use closures to capture and mutate this variable. This allows us to track
|
338
|
+
# ordering of operations.
|
339
|
+
callback_order = []
|
340
|
+
|
341
|
+
let(:deploy_to_latest_with_inline_recipes) do
|
342
|
+
deploy_to_latest_rev.dup.tap do |r|
|
343
|
+
r.symlink_before_migrate "config/config.ru" => "config.ru"
|
344
|
+
r.before_migrate do
|
345
|
+
callback_order << :before_migrate
|
346
|
+
|
347
|
+
file "#{release_path}/before_migrate.txt" do
|
348
|
+
# The content here isn't relevant, but it gets printed when running
|
349
|
+
# the tests. Could be handy for debugging.
|
350
|
+
content callback_order.inspect
|
351
|
+
end
|
352
|
+
end
|
353
|
+
r.before_symlink do
|
354
|
+
callback_order << :before_symlink
|
355
|
+
|
356
|
+
current_release_path = release_path
|
357
|
+
ruby_block "ensure before symlink" do
|
358
|
+
block do
|
359
|
+
if ::File.exist?(::File.join(current_release_path, "/tmp"))
|
360
|
+
raise "Ordering issue with provider, expected symlinks to not have been created"
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
file "#{release_path}/before_symlink.txt" do
|
366
|
+
content callback_order.inspect
|
367
|
+
end
|
368
|
+
end
|
369
|
+
r.before_restart do
|
370
|
+
callback_order << :before_restart
|
371
|
+
|
372
|
+
current_release_path = release_path
|
373
|
+
ruby_block "ensure after symlink" do
|
374
|
+
block do
|
375
|
+
unless ::File.exist?(::File.join(current_release_path, "/tmp"))
|
376
|
+
raise "Ordering issue with provider, expected symlinks to have been created"
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
file "#{release_path}/tmp/before_restart.txt" do
|
382
|
+
content callback_order.inspect
|
383
|
+
end
|
384
|
+
end
|
385
|
+
r.after_restart do
|
386
|
+
callback_order << :after_restart
|
387
|
+
file "#{release_path}/tmp/after_restart.txt" do
|
388
|
+
content callback_order.inspect
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
before do
|
395
|
+
callback_order.clear # callback_order variable is global for this context group
|
396
|
+
deploy_to_latest_with_inline_recipes.run_action(:deploy)
|
397
|
+
end
|
398
|
+
|
399
|
+
the_app_is_deployed_at_revision(:latest_rev)
|
400
|
+
|
401
|
+
it "is marked updated" do
|
402
|
+
deploy_to_latest_with_inline_recipes.should be_updated_by_last_action
|
403
|
+
end
|
404
|
+
|
405
|
+
it "calls the callbacks in order" do
|
406
|
+
callback_order.should == [:before_migrate, :before_symlink, :before_restart, :after_restart]
|
407
|
+
end
|
408
|
+
|
409
|
+
it "runs chef resources in the callbacks" do
|
410
|
+
File.should exist(rel_path("current/before_migrate.txt"))
|
411
|
+
File.should exist(rel_path("current/before_symlink.txt"))
|
412
|
+
File.should exist(rel_path("current/tmp/before_restart.txt"))
|
413
|
+
File.should exist(rel_path("current/tmp/after_restart.txt"))
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
context "when deploying an app with in-repo callback scripts" do
|
418
|
+
let(:deploy_with_in_repo_callbacks) do
|
419
|
+
basic_deploy_resource.dup.tap do |r|
|
420
|
+
r.repo git_bundle_with_in_repo_callbacks
|
421
|
+
r.revision rev_with_in_repo_callbacks
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
before do
|
426
|
+
deploy_with_in_repo_callbacks.run_action(:deploy)
|
427
|
+
end
|
428
|
+
|
429
|
+
the_app_is_deployed_at_revision(:rev_with_in_repo_callbacks)
|
430
|
+
|
431
|
+
it "runs chef resources in the callbacks" do
|
432
|
+
File.should exist(rel_path("current/before_migrate.txt"))
|
433
|
+
File.should exist(rel_path("current/before_symlink.txt"))
|
434
|
+
File.should exist(rel_path("current/tmp/before_restart.txt"))
|
435
|
+
File.should exist(rel_path("current/tmp/after_restart.txt"))
|
436
|
+
end
|
437
|
+
|
438
|
+
end
|
439
|
+
|
440
|
+
context "when deploying an app with migrations" do
|
441
|
+
let(:deploy_with_migration) do
|
442
|
+
basic_deploy_resource.dup.tap do |r|
|
443
|
+
|
444
|
+
# Need this so we can call methods from this test inside the inline
|
445
|
+
# recipe callbacks
|
446
|
+
spec_context = self
|
447
|
+
|
448
|
+
r.revision latest_rev
|
449
|
+
|
450
|
+
# enable migrations
|
451
|
+
r.migrate true
|
452
|
+
# abuse `shell_restart_command` so we can observe order of when the
|
453
|
+
# miration command gets run
|
454
|
+
r.migration_command shell_restart_command("migration")
|
455
|
+
r.before_migrate do
|
456
|
+
|
457
|
+
# inline recipe callbacks don't cwd, so you have to get the release
|
458
|
+
# directory as a local and "capture" it in the closure.
|
459
|
+
current_release = release_path
|
460
|
+
execute spec_context.shell_restart_command("before_migrate") do
|
461
|
+
cwd current_release
|
462
|
+
end
|
463
|
+
end
|
464
|
+
r.before_symlink do
|
465
|
+
current_release = release_path
|
466
|
+
execute spec_context.shell_restart_command("before_symlink") do
|
467
|
+
cwd current_release
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|
471
|
+
r.before_restart do
|
472
|
+
current_release = release_path
|
473
|
+
execute spec_context.shell_restart_command("before_restart") do
|
474
|
+
cwd current_release
|
475
|
+
end
|
476
|
+
end
|
477
|
+
|
478
|
+
r.after_restart do
|
479
|
+
current_release = release_path
|
480
|
+
execute spec_context.shell_restart_command("after_restart") do
|
481
|
+
cwd current_release
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
before do
|
489
|
+
deploy_with_migration.run_action(:deploy)
|
490
|
+
end
|
491
|
+
|
492
|
+
it "runs migrations in between the before_migrate and before_symlink steps" do
|
493
|
+
actual_operations_order.should == %w[before_migrate migration before_symlink before_restart after_restart]
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
end
|
498
|
+
|
499
|
+
|