chef 12.1.2 → 12.2.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/lib/chef/application/client.rb +2 -2
  3. data/lib/chef/audit/audit_reporter.rb +1 -1
  4. data/lib/chef/audit/runner.rb +15 -2
  5. data/lib/chef/client.rb +1 -1
  6. data/lib/chef/config.rb +6 -4
  7. data/lib/chef/dsl/powershell.rb +29 -0
  8. data/lib/chef/exceptions.rb +18 -3
  9. data/lib/chef/formatters/doc.rb +2 -2
  10. data/lib/chef/knife/bootstrap.rb +2 -1
  11. data/lib/chef/knife/bootstrap/templates/chef-full.erb +1 -1
  12. data/lib/chef/knife/core/subcommand_loader.rb +13 -5
  13. data/lib/chef/knife/exec.rb +2 -1
  14. data/lib/chef/knife/ssh.rb +12 -2
  15. data/lib/chef/mixin/params_validate.rb +42 -19
  16. data/lib/chef/mixin/powershell_type_coercions.rb +82 -0
  17. data/lib/chef/mixin/windows_architecture_helper.rb +8 -0
  18. data/lib/chef/node.rb +1 -1
  19. data/lib/chef/platform/provider_mapping.rb +0 -107
  20. data/lib/chef/platform/query_helpers.rb +7 -0
  21. data/lib/chef/provider/batch.rb +2 -0
  22. data/lib/chef/provider/cron.rb +2 -0
  23. data/lib/chef/provider/cron/aix.rb +2 -0
  24. data/lib/chef/provider/cron/unix.rb +2 -0
  25. data/lib/chef/provider/deploy.rb +104 -87
  26. data/lib/chef/provider/dsc_resource.rb +157 -0
  27. data/lib/chef/provider/env.rb +2 -0
  28. data/lib/chef/provider/env/windows.rb +2 -0
  29. data/lib/chef/provider/git.rb +4 -0
  30. data/lib/chef/provider/group.rb +5 -5
  31. data/lib/chef/provider/group/dscl.rb +2 -0
  32. data/lib/chef/provider/group/groupmod.rb +2 -0
  33. data/lib/chef/provider/group/usermod.rb +2 -0
  34. data/lib/chef/provider/group/windows.rb +2 -0
  35. data/lib/chef/provider/mdadm.rb +2 -0
  36. data/lib/chef/provider/mount/windows.rb +2 -0
  37. data/lib/chef/provider/package/homebrew.rb +1 -1
  38. data/lib/chef/provider/package/openbsd.rb +49 -18
  39. data/lib/chef/provider/package/rubygems.rb +7 -2
  40. data/lib/chef/provider/powershell_script.rb +2 -0
  41. data/lib/chef/provider/service/macosx.rb +1 -2
  42. data/lib/chef/provider/user/dscl.rb +7 -1
  43. data/lib/chef/provider/user/windows.rb +2 -0
  44. data/lib/chef/providers.rb +1 -0
  45. data/lib/chef/recipe.rb +2 -0
  46. data/lib/chef/resource.rb +9 -0
  47. data/lib/chef/resource/batch.rb +2 -0
  48. data/lib/chef/resource/cron.rb +3 -3
  49. data/lib/chef/resource/deploy.rb +52 -217
  50. data/lib/chef/resource/dsc_resource.rb +83 -0
  51. data/lib/chef/resource/env.rb +2 -0
  52. data/lib/chef/resource/git.rb +1 -1
  53. data/lib/chef/resource/group.rb +2 -0
  54. data/lib/chef/resource/homebrew_package.rb +1 -1
  55. data/lib/chef/resource/lwrp_base.rb +0 -8
  56. data/lib/chef/resource/mdadm.rb +2 -0
  57. data/lib/chef/resource/mount.rb +2 -0
  58. data/lib/chef/resource/powershell_script.rb +2 -0
  59. data/lib/chef/resource/user.rb +2 -0
  60. data/lib/chef/resources.rb +1 -0
  61. data/lib/chef/run_context.rb +1 -1
  62. data/lib/chef/shell.rb +7 -5
  63. data/lib/chef/util/dsc/resource_store.rb +110 -0
  64. data/lib/chef/util/path_helper.rb +76 -0
  65. data/lib/chef/util/powershell/cmdlet.rb +41 -7
  66. data/lib/chef/util/powershell/cmdlet_result.rb +18 -3
  67. data/lib/chef/util/powershell/ps_credential.rb +38 -0
  68. data/lib/chef/version.rb +1 -1
  69. data/lib/chef/win32/api.rb +2 -0
  70. data/lib/chef/win32/api/crypto.rb +63 -0
  71. data/lib/chef/win32/api/installer.rb +1 -1
  72. data/lib/chef/win32/crypto.rb +49 -0
  73. data/lib/chef/workstation_config_loader.rb +4 -3
  74. data/spec/functional/file_content_management/deploy_strategies_spec.rb +1 -1
  75. data/spec/functional/resource/cookbook_file_spec.rb +1 -1
  76. data/spec/functional/resource/deploy_revision_spec.rb +35 -0
  77. data/spec/functional/resource/directory_spec.rb +1 -1
  78. data/spec/functional/resource/dsc_resource_spec.rb +93 -0
  79. data/spec/functional/resource/env_spec.rb +4 -3
  80. data/spec/functional/resource/file_spec.rb +1 -1
  81. data/spec/functional/resource/powershell_spec.rb +2 -1
  82. data/spec/functional/resource/remote_directory_spec.rb +1 -1
  83. data/spec/functional/resource/remote_file_spec.rb +1 -1
  84. data/spec/functional/resource/template_spec.rb +1 -1
  85. data/spec/functional/resource/user/dscl_spec.rb +1 -2
  86. data/spec/functional/resource/user/useradd_spec.rb +27 -13
  87. data/spec/functional/util/powershell/cmdlet_spec.rb +3 -3
  88. data/spec/functional/win32/crypto_spec.rb +57 -0
  89. data/spec/spec_helper.rb +3 -0
  90. data/spec/support/platform_helpers.rb +14 -0
  91. data/spec/support/shared/functional/securable_resource_with_reporting.rb +5 -5
  92. data/spec/unit/application/client_spec.rb +4 -4
  93. data/spec/unit/audit/audit_reporter_spec.rb +1 -1
  94. data/spec/unit/audit/runner_spec.rb +10 -0
  95. data/spec/unit/config_spec.rb +2 -8
  96. data/spec/unit/knife/bootstrap_spec.rb +20 -8
  97. data/spec/unit/knife/core/subcommand_loader_spec.rb +29 -29
  98. data/spec/unit/mixin/params_validate_spec.rb +75 -61
  99. data/spec/unit/mixin/powershell_type_coercions_spec.rb +72 -0
  100. data/spec/unit/platform/query_helpers_spec.rb +22 -0
  101. data/spec/unit/platform_spec.rb +0 -5
  102. data/spec/unit/provider/dsc_resource_spec.rb +84 -0
  103. data/spec/unit/provider/package/openbsd_spec.rb +105 -17
  104. data/spec/unit/provider/service/macosx_spec.rb +3 -3
  105. data/spec/unit/provider_resolver_spec.rb +132 -0
  106. data/spec/unit/recipe_spec.rb +4 -0
  107. data/spec/unit/resource/deploy_spec.rb +27 -0
  108. data/spec/unit/resource/dsc_resource_spec.rb +85 -0
  109. data/spec/unit/shell_spec.rb +1 -1
  110. data/spec/unit/util/dsc/resource_store.rb +76 -0
  111. data/spec/unit/util/powershell/ps_credential_spec.rb +37 -0
  112. data/spec/unit/workstation_config_loader_spec.rb +1 -1
  113. metadata +159 -186
@@ -43,6 +43,14 @@ class Chef
43
43
  end
44
44
 
45
45
  def with_os_architecture(node)
46
+ node ||= begin
47
+ os_arch = ENV['PROCESSOR_ARCHITEW6432'] ||
48
+ ENV['PROCESSOR_ARCHITECTURE']
49
+ Hash.new.tap do |n|
50
+ n[:kernel] = Hash.new
51
+ n[:kernel][:machine] = os_arch == 'AMD64' ? :x86_64 : :i386
52
+ end
53
+ end
46
54
  wow64_redirection_state = nil
47
55
 
48
56
  if wow64_architecture_override_required?(node, node_windows_architecture(node))
@@ -323,7 +323,7 @@ class Chef
323
323
  if attrs.key?("recipes") || attrs.key?("run_list")
324
324
  raise Chef::Exceptions::AmbiguousRunlistSpecification, "please set the node's run list using the 'run_list' attribute only."
325
325
  end
326
- Chef::Log.info("Setting the run_list to #{new_run_list.inspect} from CLI options")
326
+ Chef::Log.info("Setting the run_list to #{new_run_list.to_s} from CLI options")
327
327
  run_list(new_run_list)
328
328
  end
329
329
  attrs
@@ -38,33 +38,16 @@ class Chef
38
38
  require 'chef/providers'
39
39
 
40
40
  {
41
- :mac_os_x => {
42
- :default => {
43
- :package => Chef::Provider::Package::Homebrew,
44
- :user => Chef::Provider::User::Dscl,
45
- :group => Chef::Provider::Group::Dscl
46
- }
47
- },
48
- :mac_os_x_server => {
49
- :default => {
50
- :package => Chef::Provider::Package::Homebrew,
51
- :user => Chef::Provider::User::Dscl,
52
- :group => Chef::Provider::Group::Dscl
53
- }
54
- },
55
41
  :freebsd => {
56
42
  :default => {
57
43
  :group => Chef::Provider::Group::Pw,
58
44
  :user => Chef::Provider::User::Pw,
59
- :cron => Chef::Provider::Cron
60
45
  }
61
46
  },
62
47
  :ubuntu => {
63
48
  :default => {
64
49
  :package => Chef::Provider::Package::Apt,
65
50
  :service => Chef::Provider::Service::Debian,
66
- :cron => Chef::Provider::Cron,
67
- :mdadm => Chef::Provider::Mdadm
68
51
  },
69
52
  ">= 11.10" => {
70
53
  :ifconfig => Chef::Provider::Ifconfig::Debian
@@ -79,40 +62,30 @@ class Chef
79
62
  :default => {
80
63
  :package => Chef::Provider::Package::Apt,
81
64
  :service => Chef::Provider::Service::Debian,
82
- :cron => Chef::Provider::Cron,
83
- :mdadm => Chef::Provider::Mdadm
84
65
  }
85
66
  },
86
67
  :linaro => {
87
68
  :default => {
88
69
  :package => Chef::Provider::Package::Apt,
89
70
  :service => Chef::Provider::Service::Debian,
90
- :cron => Chef::Provider::Cron,
91
- :mdadm => Chef::Provider::Mdadm
92
71
  }
93
72
  },
94
73
  :raspbian => {
95
74
  :default => {
96
75
  :package => Chef::Provider::Package::Apt,
97
76
  :service => Chef::Provider::Service::Debian,
98
- :cron => Chef::Provider::Cron,
99
- :mdadm => Chef::Provider::Mdadm
100
77
  }
101
78
  },
102
79
  :linuxmint => {
103
80
  :default => {
104
81
  :package => Chef::Provider::Package::Apt,
105
82
  :service => Chef::Provider::Service::Upstart,
106
- :cron => Chef::Provider::Cron,
107
- :mdadm => Chef::Provider::Mdadm
108
83
  }
109
84
  },
110
85
  :debian => {
111
86
  :default => {
112
87
  :package => Chef::Provider::Package::Apt,
113
88
  :service => Chef::Provider::Service::Debian,
114
- :cron => Chef::Provider::Cron,
115
- :mdadm => Chef::Provider::Mdadm
116
89
  },
117
90
  ">= 6.0" => {
118
91
  :service => Chef::Provider::Service::Insserv
@@ -124,25 +97,19 @@ class Chef
124
97
  :xenserver => {
125
98
  :default => {
126
99
  :service => Chef::Provider::Service::Redhat,
127
- :cron => Chef::Provider::Cron,
128
100
  :package => Chef::Provider::Package::Yum,
129
- :mdadm => Chef::Provider::Mdadm
130
101
  }
131
102
  },
132
103
  :xcp => {
133
104
  :default => {
134
105
  :service => Chef::Provider::Service::Redhat,
135
- :cron => Chef::Provider::Cron,
136
106
  :package => Chef::Provider::Package::Yum,
137
- :mdadm => Chef::Provider::Mdadm
138
107
  }
139
108
  },
140
109
  :centos => {
141
110
  :default => {
142
111
  :service => Chef::Provider::Service::Systemd,
143
- :cron => Chef::Provider::Cron,
144
112
  :package => Chef::Provider::Package::Yum,
145
- :mdadm => Chef::Provider::Mdadm,
146
113
  :ifconfig => Chef::Provider::Ifconfig::Redhat
147
114
  },
148
115
  "< 7" => {
@@ -152,17 +119,13 @@ class Chef
152
119
  :amazon => {
153
120
  :default => {
154
121
  :service => Chef::Provider::Service::Redhat,
155
- :cron => Chef::Provider::Cron,
156
122
  :package => Chef::Provider::Package::Yum,
157
- :mdadm => Chef::Provider::Mdadm
158
123
  }
159
124
  },
160
125
  :scientific => {
161
126
  :default => {
162
127
  :service => Chef::Provider::Service::Systemd,
163
- :cron => Chef::Provider::Cron,
164
128
  :package => Chef::Provider::Package::Yum,
165
- :mdadm => Chef::Provider::Mdadm
166
129
  },
167
130
  "< 7" => {
168
131
  :service => Chef::Provider::Service::Redhat
@@ -171,9 +134,7 @@ class Chef
171
134
  :fedora => {
172
135
  :default => {
173
136
  :service => Chef::Provider::Service::Systemd,
174
- :cron => Chef::Provider::Cron,
175
137
  :package => Chef::Provider::Package::Yum,
176
- :mdadm => Chef::Provider::Mdadm,
177
138
  :ifconfig => Chef::Provider::Ifconfig::Redhat
178
139
  },
179
140
  "< 15" => {
@@ -183,7 +144,6 @@ class Chef
183
144
  :opensuse => {
184
145
  :default => {
185
146
  :service => Chef::Provider::Service::Redhat,
186
- :cron => Chef::Provider::Cron,
187
147
  :package => Chef::Provider::Package::Zypper,
188
148
  :group => Chef::Provider::Group::Suse
189
149
  },
@@ -195,7 +155,6 @@ class Chef
195
155
  :suse => {
196
156
  :default => {
197
157
  :service => Chef::Provider::Service::Systemd,
198
- :cron => Chef::Provider::Cron,
199
158
  :package => Chef::Provider::Package::Zypper,
200
159
  :group => Chef::Provider::Group::Gpasswd
201
160
  },
@@ -207,9 +166,7 @@ class Chef
207
166
  :oracle => {
208
167
  :default => {
209
168
  :service => Chef::Provider::Service::Systemd,
210
- :cron => Chef::Provider::Cron,
211
169
  :package => Chef::Provider::Package::Yum,
212
- :mdadm => Chef::Provider::Mdadm
213
170
  },
214
171
  "< 7" => {
215
172
  :service => Chef::Provider::Service::Redhat
@@ -218,9 +175,7 @@ class Chef
218
175
  :redhat => {
219
176
  :default => {
220
177
  :service => Chef::Provider::Service::Systemd,
221
- :cron => Chef::Provider::Cron,
222
178
  :package => Chef::Provider::Package::Yum,
223
- :mdadm => Chef::Provider::Mdadm,
224
179
  :ifconfig => Chef::Provider::Ifconfig::Redhat
225
180
  },
226
181
  "< 7" => {
@@ -230,27 +185,21 @@ class Chef
230
185
  :ibm_powerkvm => {
231
186
  :default => {
232
187
  :service => Chef::Provider::Service::Redhat,
233
- :cron => Chef::Provider::Cron,
234
188
  :package => Chef::Provider::Package::Yum,
235
- :mdadm => Chef::Provider::Mdadm,
236
189
  :ifconfig => Chef::Provider::Ifconfig::Redhat
237
190
  }
238
191
  },
239
192
  :cloudlinux => {
240
193
  :default => {
241
194
  :service => Chef::Provider::Service::Redhat,
242
- :cron => Chef::Provider::Cron,
243
195
  :package => Chef::Provider::Package::Yum,
244
- :mdadm => Chef::Provider::Mdadm,
245
196
  :ifconfig => Chef::Provider::Ifconfig::Redhat
246
197
  }
247
198
  },
248
199
  :parallels => {
249
200
  :default => {
250
201
  :service => Chef::Provider::Service::Redhat,
251
- :cron => Chef::Provider::Cron,
252
202
  :package => Chef::Provider::Package::Yum,
253
- :mdadm => Chef::Provider::Mdadm,
254
203
  :ifconfig => Chef::Provider::Ifconfig::Redhat
255
204
  }
256
205
  },
@@ -258,46 +207,12 @@ class Chef
258
207
  :default => {
259
208
  :package => Chef::Provider::Package::Portage,
260
209
  :service => Chef::Provider::Service::Gentoo,
261
- :cron => Chef::Provider::Cron,
262
- :mdadm => Chef::Provider::Mdadm
263
210
  }
264
211
  },
265
212
  :arch => {
266
213
  :default => {
267
214
  :package => Chef::Provider::Package::Pacman,
268
215
  :service => Chef::Provider::Service::Systemd,
269
- :cron => Chef::Provider::Cron,
270
- :mdadm => Chef::Provider::Mdadm
271
- }
272
- },
273
- :mswin => {
274
- :default => {
275
- :env => Chef::Provider::Env::Windows,
276
- :user => Chef::Provider::User::Windows,
277
- :group => Chef::Provider::Group::Windows,
278
- :mount => Chef::Provider::Mount::Windows,
279
- :batch => Chef::Provider::Batch,
280
- :powershell_script => Chef::Provider::PowershellScript
281
- }
282
- },
283
- :mingw32 => {
284
- :default => {
285
- :env => Chef::Provider::Env::Windows,
286
- :user => Chef::Provider::User::Windows,
287
- :group => Chef::Provider::Group::Windows,
288
- :mount => Chef::Provider::Mount::Windows,
289
- :batch => Chef::Provider::Batch,
290
- :powershell_script => Chef::Provider::PowershellScript
291
- }
292
- },
293
- :windows => {
294
- :default => {
295
- :env => Chef::Provider::Env::Windows,
296
- :user => Chef::Provider::User::Windows,
297
- :group => Chef::Provider::Group::Windows,
298
- :mount => Chef::Provider::Mount::Windows,
299
- :batch => Chef::Provider::Batch,
300
- :powershell_script => Chef::Provider::PowershellScript
301
216
  }
302
217
  },
303
218
  :solaris => {},
@@ -305,7 +220,6 @@ class Chef
305
220
  :default => {
306
221
  :mount => Chef::Provider::Mount::Solaris,
307
222
  :package => Chef::Provider::Package::Ips,
308
- :cron => Chef::Provider::Cron::Solaris,
309
223
  :group => Chef::Provider::Group::Usermod
310
224
  }
311
225
  },
@@ -313,7 +227,6 @@ class Chef
313
227
  :default => {
314
228
  :mount => Chef::Provider::Mount::Solaris,
315
229
  :package => Chef::Provider::Package::Ips,
316
- :cron => Chef::Provider::Cron::Solaris,
317
230
  :group => Chef::Provider::Group::Usermod
318
231
  }
319
232
  },
@@ -321,7 +234,6 @@ class Chef
321
234
  :default => {
322
235
  :mount => Chef::Provider::Mount::Solaris,
323
236
  :package => Chef::Provider::Package::Solaris,
324
- :cron => Chef::Provider::Cron::Solaris,
325
237
  :group => Chef::Provider::Group::Usermod
326
238
  }
327
239
  },
@@ -329,7 +241,6 @@ class Chef
329
241
  :default => {
330
242
  :mount => Chef::Provider::Mount::Solaris,
331
243
  :package => Chef::Provider::Package::Ips,
332
- :cron => Chef::Provider::Cron::Solaris,
333
244
  :group => Chef::Provider::Group::Usermod,
334
245
  :user => Chef::Provider::User::Solaris,
335
246
  }
@@ -338,14 +249,12 @@ class Chef
338
249
  :default => {
339
250
  :mount => Chef::Provider::Mount::Solaris,
340
251
  :package => Chef::Provider::Package::Ips,
341
- :cron => Chef::Provider::Cron::Solaris,
342
252
  :group => Chef::Provider::Group::Usermod,
343
253
  :user => Chef::Provider::User::Solaris,
344
254
  },
345
255
  "< 5.11" => {
346
256
  :mount => Chef::Provider::Mount::Solaris,
347
257
  :package => Chef::Provider::Package::Solaris,
348
- :cron => Chef::Provider::Cron::Solaris,
349
258
  :group => Chef::Provider::Group::Usermod,
350
259
  :user => Chef::Provider::User::Solaris,
351
260
  }
@@ -354,22 +263,9 @@ class Chef
354
263
  :default => {
355
264
  :mount => Chef::Provider::Mount::Solaris,
356
265
  :package => Chef::Provider::Package::SmartOS,
357
- :cron => Chef::Provider::Cron::Solaris,
358
266
  :group => Chef::Provider::Group::Usermod
359
267
  }
360
268
  },
361
- :netbsd => {
362
- :default => {
363
- :group => Chef::Provider::Group::Groupmod
364
- }
365
- },
366
- :openbsd => {
367
- :default => {
368
- :group => Chef::Provider::Group::Usermod,
369
- :package => Chef::Provider::Package::Openbsd,
370
- :service => Chef::Provider::Service::Openbsd
371
- }
372
- },
373
269
  :hpux => {
374
270
  :default => {
375
271
  :group => Chef::Provider::Group::Usermod
@@ -380,7 +276,6 @@ class Chef
380
276
  :group => Chef::Provider::Group::Aix,
381
277
  :mount => Chef::Provider::Mount::Aix,
382
278
  :ifconfig => Chef::Provider::Ifconfig::Aix,
383
- :cron => Chef::Provider::Cron::Aix,
384
279
  :package => Chef::Provider::Package::Aix,
385
280
  :user => Chef::Provider::User::Aix,
386
281
  :service => Chef::Provider::Service::Aix
@@ -390,8 +285,6 @@ class Chef
390
285
  :default => {
391
286
  :package => Chef::Provider::Package::Paludis,
392
287
  :service => Chef::Provider::Service::Systemd,
393
- :cron => Chef::Provider::Cron,
394
- :mdadm => Chef::Provider::Mdadm
395
288
  }
396
289
  },
397
290
  :default => {
@@ -47,6 +47,13 @@ class Chef
47
47
  node[:languages] && node[:languages][:powershell] &&
48
48
  node[:languages][:powershell][:version].to_i >= 4
49
49
  end
50
+
51
+ def supports_dsc_invoke_resource?(node)
52
+ require 'rubygems'
53
+ supports_dsc?(node) &&
54
+ Gem::Version.new(node[:languages][:powershell][:version]) >=
55
+ Gem::Version.new("5.0.10018.0")
56
+ end
50
57
  end
51
58
  end
52
59
  end
@@ -22,6 +22,8 @@ class Chef
22
22
  class Provider
23
23
  class Batch < Chef::Provider::WindowsScript
24
24
 
25
+ provides :batch, os: "windows"
26
+
25
27
  def initialize (new_resource, run_context)
26
28
  super(new_resource, run_context, '.bat')
27
29
  end
@@ -25,6 +25,8 @@ class Chef
25
25
  class Cron < Chef::Provider
26
26
  include Chef::Mixin::Command
27
27
 
28
+ provides :cron, os: ["!aix", "!solaris2"]
29
+
28
30
  SPECIAL_TIME_VALUES = [:reboot, :yearly, :annually, :monthly, :weekly, :daily, :midnight, :hourly]
29
31
  CRON_ATTRIBUTES = [:minute, :hour, :day, :month, :weekday, :time, :command, :mailto, :path, :shell, :home, :environment]
30
32
  WEEKDAY_SYMBOLS = [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday]
@@ -23,6 +23,8 @@ class Chef
23
23
  class Cron
24
24
  class Aix < Chef::Provider::Cron::Unix
25
25
 
26
+ provides :cron, os: "aix"
27
+
26
28
  private
27
29
 
28
30
  # For AIX we ignore env vars/[ :mailto, :path, :shell, :home ]
@@ -27,6 +27,8 @@ class Chef
27
27
  class Unix < Chef::Provider::Cron
28
28
  include Chef::Mixin::ShellOut
29
29
 
30
+ provides :cron, os: 'solaris2'
31
+
30
32
  private
31
33
 
32
34
  def read_crontab
@@ -42,18 +42,38 @@ class Chef
42
42
 
43
43
  # @configuration is not used by Deploy, it is only for backwards compat with
44
44
  # chef-deploy or capistrano hooks that might use it to get environment information
45
- @configuration = @new_resource.to_hash
45
+ @configuration = new_resource.to_hash
46
46
  @configuration[:environment] = @configuration[:environment] && @configuration[:environment]["RAILS_ENV"]
47
47
  end
48
48
 
49
+ # @return [Array] create_dirs_before_symlink parameter set on the resource
50
+ def create_dirs_before_symlink
51
+ new_resource.create_dirs_before_symlink || []
52
+ end
53
+
54
+ # @return [Array] purge_before_symlink paremeter set on the resource
55
+ def purge_before_symlink
56
+ new_resource.purge_before_symlink || []
57
+ end
58
+
59
+ # @return [Hash] symlinks parameter set on the resource
60
+ def symlinks
61
+ new_resource.symlinks || {}
62
+ end
63
+
64
+ # @return [Hash] symlink_before_migrate parameter set on the resource
65
+ def symlink_before_migrate
66
+ new_resource.symlink_before_migrate || {}
67
+ end
68
+
49
69
  def whyrun_supported?
50
70
  true
51
71
  end
52
72
 
53
73
  def load_current_resource
54
- @scm_provider.load_current_resource
55
- @release_path = @new_resource.deploy_to + "/releases/#{release_slug}"
56
- @shared_path = @new_resource.shared_path
74
+ scm_provider.load_current_resource
75
+ @release_path = new_resource.deploy_to + "/releases/#{release_slug}"
76
+ @shared_path = new_resource.shared_path
57
77
  end
58
78
 
59
79
  def sudo(command,&block)
@@ -62,10 +82,10 @@ class Chef
62
82
 
63
83
  def run(command, &block)
64
84
  exec = execute(command, &block)
65
- exec.user(@new_resource.user) if @new_resource.user
66
- exec.group(@new_resource.group) if @new_resource.group
85
+ exec.user(new_resource.user) if new_resource.user
86
+ exec.group(new_resource.group) if new_resource.group
67
87
  exec.cwd(release_path) unless exec.cwd
68
- exec.environment(@new_resource.environment) unless exec.environment
88
+ exec.environment(new_resource.environment) unless exec.environment
69
89
  converge_by("execute #{command}") do
70
90
  exec
71
91
  end
@@ -78,8 +98,8 @@ class Chef
78
98
  #There is no reason to assume 2 deployments in a single chef run, hence fails in whyrun.
79
99
  end
80
100
 
81
- [ @new_resource.before_migrate, @new_resource.before_symlink,
82
- @new_resource.before_restart, @new_resource.after_restart ].each do |script|
101
+ [ new_resource.before_migrate, new_resource.before_symlink,
102
+ new_resource.before_restart, new_resource.after_restart ].each do |script|
83
103
  requirements.assert(:deploy, :force_deploy) do |a|
84
104
  callback_file = "#{release_path}/#{script}"
85
105
  a.assertion do
@@ -100,7 +120,7 @@ class Chef
100
120
  save_release_state
101
121
  if deployed?(release_path )
102
122
  if current_release?(release_path )
103
- Chef::Log.debug("#{@new_resource} is the latest version")
123
+ Chef::Log.debug("#{new_resource} is the latest version")
104
124
  else
105
125
  rollback_to release_path
106
126
  end
@@ -117,7 +137,7 @@ class Chef
117
137
  converge_by("delete deployed app at #{release_path} prior to force-deploy") do
118
138
  Chef::Log.info("Already deployed app at #{release_path}, forcing.")
119
139
  FileUtils.rm_rf(release_path)
120
- Chef::Log.info("#{@new_resource} forcing deploy of already deployed app at #{release_path}")
140
+ Chef::Log.info("#{new_resource} forcing deploy of already deployed app at #{release_path}")
121
141
  end
122
142
  end
123
143
 
@@ -143,7 +163,7 @@ class Chef
143
163
 
144
164
  releases_to_nuke.each do |i|
145
165
  converge_by("roll back by removing release #{i}") do
146
- Chef::Log.info "#{@new_resource} removing release: #{i}"
166
+ Chef::Log.info "#{new_resource} removing release: #{i}"
147
167
  FileUtils.rm_rf i
148
168
  end
149
169
  release_deleted(i)
@@ -157,21 +177,21 @@ class Chef
157
177
  copy_cached_repo
158
178
  install_gems
159
179
  enforce_ownership
160
- callback(:before_migrate, @new_resource.before_migrate)
180
+ callback(:before_migrate, new_resource.before_migrate)
161
181
  migrate
162
- callback(:before_symlink, @new_resource.before_symlink)
182
+ callback(:before_symlink, new_resource.before_symlink)
163
183
  symlink
164
- callback(:before_restart, @new_resource.before_restart)
184
+ callback(:before_restart, new_resource.before_restart)
165
185
  restart
166
- callback(:after_restart, @new_resource.after_restart)
186
+ callback(:after_restart, new_resource.after_restart)
167
187
  cleanup!
168
- Chef::Log.info "#{@new_resource} deployed to #{@new_resource.deploy_to}"
188
+ Chef::Log.info "#{new_resource} deployed to #{new_resource.deploy_to}"
169
189
  end
170
190
 
171
191
  def rollback
172
- Chef::Log.info "#{@new_resource} rolling back to previous release #{release_path}"
192
+ Chef::Log.info "#{new_resource} rolling back to previous release #{release_path}"
173
193
  symlink
174
- Chef::Log.info "#{@new_resource} restarting with previous release"
194
+ Chef::Log.info "#{new_resource} restarting with previous release"
175
195
  restart
176
196
  end
177
197
 
@@ -179,7 +199,7 @@ class Chef
179
199
  @collection = Chef::ResourceCollection.new
180
200
  case callback_code
181
201
  when Proc
182
- Chef::Log.info "#{@new_resource} running callback #{what}"
202
+ Chef::Log.info "#{new_resource} running callback #{what}"
183
203
  recipe_eval(&callback_code)
184
204
  when String
185
205
  run_callback_from_file("#{release_path}/#{callback_code}")
@@ -191,17 +211,17 @@ class Chef
191
211
  def migrate
192
212
  run_symlinks_before_migrate
193
213
 
194
- if @new_resource.migrate
214
+ if new_resource.migrate
195
215
  enforce_ownership
196
216
 
197
- environment = @new_resource.environment
217
+ environment = new_resource.environment
198
218
  env_info = environment && environment.map do |key_and_val|
199
219
  "#{key_and_val.first}='#{key_and_val.last}'"
200
220
  end.join(" ")
201
221
 
202
- converge_by("execute migration command #{@new_resource.migration_command}") do
203
- Chef::Log.info "#{@new_resource} migrating #{@new_resource.user} with environment #{env_info}"
204
- run_command(run_options(:command => @new_resource.migration_command, :cwd=>release_path, :log_level => :info))
222
+ converge_by("execute migration command #{new_resource.migration_command}") do
223
+ Chef::Log.info "#{new_resource} migrating #{new_resource.user} with environment #{env_info}"
224
+ run_command(run_options(:command => new_resource.migration_command, :cwd=>release_path, :log_level => :info))
205
225
  end
206
226
  end
207
227
  end
@@ -210,18 +230,18 @@ class Chef
210
230
  purge_tempfiles_from_current_release
211
231
  link_tempfiles_to_current_release
212
232
  link_current_release_to_production
213
- Chef::Log.info "#{@new_resource} updated symlinks"
233
+ Chef::Log.info "#{new_resource} updated symlinks"
214
234
  end
215
235
 
216
236
  def restart
217
- if restart_cmd = @new_resource.restart_command
237
+ if restart_cmd = new_resource.restart_command
218
238
  if restart_cmd.kind_of?(Proc)
219
- Chef::Log.info("#{@new_resource} restarting app with embedded recipe")
239
+ Chef::Log.info("#{new_resource} restarting app with embedded recipe")
220
240
  recipe_eval(&restart_cmd)
221
241
  else
222
- converge_by("restart app using command #{@new_resource.restart_command}") do
223
- Chef::Log.info("#{@new_resource} restarting app")
224
- run_command(run_options(:command => @new_resource.restart_command, :cwd => @new_resource.current_path))
242
+ converge_by("restart app using command #{new_resource.restart_command}") do
243
+ Chef::Log.info("#{new_resource} restarting app")
244
+ run_command(run_options(:command => new_resource.restart_command, :cwd => new_resource.current_path))
225
245
  end
226
246
  end
227
247
  end
@@ -232,10 +252,10 @@ class Chef
232
252
  release_created(release_path)
233
253
  end
234
254
 
235
- chop = -1 - @new_resource.keep_releases
255
+ chop = -1 - new_resource.keep_releases
236
256
  all_releases[0..chop].each do |old_release|
237
257
  converge_by("remove old release #{old_release}") do
238
- Chef::Log.info "#{@new_resource} removing old release #{old_release}"
258
+ Chef::Log.info "#{new_resource} removing old release #{old_release}"
239
259
  FileUtils.rm_rf(old_release)
240
260
  end
241
261
  release_deleted(old_release)
@@ -243,11 +263,11 @@ class Chef
243
263
  end
244
264
 
245
265
  def all_releases
246
- Dir.glob(Chef::Util::PathHelper.escape_glob(@new_resource.deploy_to) + "/releases/*").sort
266
+ Dir.glob(Chef::Util::PathHelper.escape_glob(new_resource.deploy_to) + "/releases/*").sort
247
267
  end
248
268
 
249
269
  def update_cached_repo
250
- if @new_resource.svn_force_export
270
+ if new_resource.svn_force_export
251
271
  # TODO assertion, non-recoverable - @scm_provider must be svn if force_export?
252
272
  svn_force_export
253
273
  else
@@ -256,95 +276,92 @@ class Chef
256
276
  end
257
277
 
258
278
  def run_scm_sync
259
- @scm_provider.run_action(:sync)
279
+ scm_provider.run_action(:sync)
260
280
  end
261
281
 
262
282
  def svn_force_export
263
- Chef::Log.info "#{@new_resource} exporting source repository"
264
- @scm_provider.run_action(:force_export)
283
+ Chef::Log.info "#{new_resource} exporting source repository"
284
+ scm_provider.run_action(:force_export)
265
285
  end
266
286
 
267
287
  def copy_cached_repo
268
- target_dir_path = @new_resource.deploy_to + "/releases"
288
+ target_dir_path = new_resource.deploy_to + "/releases"
269
289
  converge_by("deploy from repo to #{target_dir_path} ") do
270
290
  FileUtils.rm_rf(release_path) if ::File.exist?(release_path)
271
291
  FileUtils.mkdir_p(target_dir_path)
272
- FileUtils.cp_r(::File.join(@new_resource.destination, "."), release_path, :preserve => true)
273
- Chef::Log.info "#{@new_resource} copied the cached checkout to #{release_path}"
292
+ FileUtils.cp_r(::File.join(new_resource.destination, "."), release_path, :preserve => true)
293
+ Chef::Log.info "#{new_resource} copied the cached checkout to #{release_path}"
274
294
  end
275
295
  end
276
296
 
277
297
  def enforce_ownership
278
- converge_by("force ownership of #{@new_resource.deploy_to} to #{@new_resource.group}:#{@new_resource.user}") do
279
- FileUtils.chown_R(@new_resource.user, @new_resource.group, @new_resource.deploy_to)
280
- Chef::Log.info("#{@new_resource} set user to #{@new_resource.user}") if @new_resource.user
281
- Chef::Log.info("#{@new_resource} set group to #{@new_resource.group}") if @new_resource.group
298
+ converge_by("force ownership of #{new_resource.deploy_to} to #{new_resource.group}:#{new_resource.user}") do
299
+ FileUtils.chown_R(new_resource.user, new_resource.group, new_resource.deploy_to)
300
+ Chef::Log.info("#{new_resource} set user to #{new_resource.user}") if new_resource.user
301
+ Chef::Log.info("#{new_resource} set group to #{new_resource.group}") if new_resource.group
282
302
  end
283
303
  end
284
304
 
285
305
  def verify_directories_exist
286
- create_dir_unless_exists(@new_resource.deploy_to)
287
- create_dir_unless_exists(@new_resource.shared_path)
306
+ create_dir_unless_exists(new_resource.deploy_to)
307
+ create_dir_unless_exists(new_resource.shared_path)
288
308
  end
289
309
 
290
310
  def link_current_release_to_production
291
- converge_by(["remove existing link at #{@new_resource.current_path}",
292
- "link release #{release_path} into production at #{@new_resource.current_path}"]) do
293
- FileUtils.rm_f(@new_resource.current_path)
311
+ converge_by(["remove existing link at #{new_resource.current_path}",
312
+ "link release #{release_path} into production at #{new_resource.current_path}"]) do
313
+ FileUtils.rm_f(new_resource.current_path)
294
314
  begin
295
- FileUtils.ln_sf(release_path, @new_resource.current_path)
315
+ FileUtils.ln_sf(release_path, new_resource.current_path)
296
316
  rescue => e
297
317
  raise Chef::Exceptions::FileNotFound.new("Cannot symlink current release to production: #{e.message}")
298
318
  end
299
- Chef::Log.info "#{@new_resource} linked release #{release_path} into production at #{@new_resource.current_path}"
319
+ Chef::Log.info "#{new_resource} linked release #{release_path} into production at #{new_resource.current_path}"
300
320
  end
301
321
  enforce_ownership
302
322
  end
303
323
 
304
324
  def run_symlinks_before_migrate
305
- links_info = @new_resource.symlink_before_migrate.map { |src, dst| "#{src} => #{dst}" }.join(", ")
325
+ links_info = symlink_before_migrate.map { |src, dst| "#{src} => #{dst}" }.join(", ")
306
326
  converge_by("make pre-migration symlinks: #{links_info}") do
307
- @new_resource.symlink_before_migrate.each do |src, dest|
327
+ symlink_before_migrate.each do |src, dest|
308
328
  begin
309
- FileUtils.ln_sf(@new_resource.shared_path + "/#{src}", release_path + "/#{dest}")
329
+ FileUtils.ln_sf(new_resource.shared_path + "/#{src}", release_path + "/#{dest}")
310
330
  rescue => e
311
- raise Chef::Exceptions::FileNotFound.new("Cannot symlink #{@new_resource.shared_path}/#{src} to #{release_path}/#{dest} before migrate: #{e.message}")
331
+ raise Chef::Exceptions::FileNotFound.new("Cannot symlink #{new_resource.shared_path}/#{src} to #{release_path}/#{dest} before migrate: #{e.message}")
312
332
  end
313
333
  end
314
- Chef::Log.info "#{@new_resource} made pre-migration symlinks"
334
+ Chef::Log.info "#{new_resource} made pre-migration symlinks"
315
335
  end
316
336
  end
317
337
 
318
338
  def link_tempfiles_to_current_release
319
- dirs_info = @new_resource.create_dirs_before_symlink.join(",")
320
- @new_resource.create_dirs_before_symlink.each do |dir|
339
+ dirs_info = create_dirs_before_symlink.join(",")
340
+ create_dirs_before_symlink.each do |dir|
321
341
  create_dir_unless_exists(release_path + "/#{dir}")
322
342
  end
323
- Chef::Log.info("#{@new_resource} created directories before symlinking: #{dirs_info}")
343
+ Chef::Log.info("#{new_resource} created directories before symlinking: #{dirs_info}")
324
344
 
325
- links_info = @new_resource.symlinks.map { |src, dst| "#{src} => #{dst}" }.join(", ")
345
+ links_info = symlinks.map { |src, dst| "#{src} => #{dst}" }.join(", ")
326
346
  converge_by("link shared paths into current release: #{links_info}") do
327
- @new_resource.symlinks.each do |src, dest|
347
+ symlinks.each do |src, dest|
328
348
  begin
329
- FileUtils.ln_sf(::File.join(@new_resource.shared_path, src), ::File.join(release_path, dest))
349
+ FileUtils.ln_sf(::File.join(new_resource.shared_path, src), ::File.join(release_path, dest))
330
350
  rescue => e
331
- raise Chef::Exceptions::FileNotFound.new("Cannot symlink shared data #{::File.join(@new_resource.shared_path, src)} to #{::File.join(release_path, dest)}: #{e.message}")
351
+ raise Chef::Exceptions::FileNotFound.new("Cannot symlink shared data #{::File.join(new_resource.shared_path, src)} to #{::File.join(release_path, dest)}: #{e.message}")
332
352
  end
333
353
  end
334
- Chef::Log.info("#{@new_resource} linked shared paths into current release: #{links_info}")
354
+ Chef::Log.info("#{new_resource} linked shared paths into current release: #{links_info}")
335
355
  end
336
356
  run_symlinks_before_migrate
337
357
  enforce_ownership
338
358
  end
339
359
 
340
- def create_dirs_before_symlink
341
- end
342
-
343
360
  def purge_tempfiles_from_current_release
344
- log_info = @new_resource.purge_before_symlink.join(", ")
361
+ log_info = purge_before_symlink.join(", ")
345
362
  converge_by("purge directories in checkout #{log_info}") do
346
- @new_resource.purge_before_symlink.each { |dir| FileUtils.rm_rf(release_path + "/#{dir}") }
347
- Chef::Log.info("#{@new_resource} purged directories in checkout #{log_info}")
363
+ purge_before_symlink.each { |dir| FileUtils.rm_rf(release_path + "/#{dir}") }
364
+ Chef::Log.info("#{new_resource} purged directories in checkout #{log_info}")
348
365
  end
349
366
  end
350
367
 
@@ -394,10 +411,10 @@ class Chef
394
411
  end
395
412
 
396
413
  def run_options(run_opts={})
397
- run_opts[:user] = @new_resource.user if @new_resource.user
398
- run_opts[:group] = @new_resource.group if @new_resource.group
399
- run_opts[:environment] = @new_resource.environment if @new_resource.environment
400
- run_opts[:log_tag] = @new_resource.to_s
414
+ run_opts[:user] = new_resource.user if new_resource.user
415
+ run_opts[:group] = new_resource.group if new_resource.group
416
+ run_opts[:environment] = new_resource.environment if new_resource.environment
417
+ run_opts[:log_tag] = new_resource.to_s
401
418
  run_opts[:log_level] ||= :debug
402
419
  if run_opts[:log_level] == :info
403
420
  if STDOUT.tty? && !Chef::Config[:daemon] && Chef::Log.info?
@@ -408,7 +425,7 @@ class Chef
408
425
  end
409
426
 
410
427
  def run_callback_from_file(callback_file)
411
- Chef::Log.info "#{@new_resource} queueing checkdeploy hook #{callback_file}"
428
+ Chef::Log.info "#{new_resource} queueing checkdeploy hook #{callback_file}"
412
429
  recipe_eval do
413
430
  Dir.chdir(release_path) do
414
431
  from_file(callback_file) if ::File.exist?(callback_file)
@@ -418,20 +435,20 @@ class Chef
418
435
 
419
436
  def create_dir_unless_exists(dir)
420
437
  if ::File.directory?(dir)
421
- Chef::Log.debug "#{@new_resource} not creating #{dir} because it already exists"
438
+ Chef::Log.debug "#{new_resource} not creating #{dir} because it already exists"
422
439
  return false
423
440
  end
424
441
  converge_by("create new directory #{dir}") do
425
442
  begin
426
443
  FileUtils.mkdir_p(dir)
427
- Chef::Log.debug "#{@new_resource} created directory #{dir}"
428
- if @new_resource.user
429
- FileUtils.chown(@new_resource.user, nil, dir)
430
- Chef::Log.debug("#{@new_resource} set user to #{@new_resource.user} for #{dir}")
444
+ Chef::Log.debug "#{new_resource} created directory #{dir}"
445
+ if new_resource.user
446
+ FileUtils.chown(new_resource.user, nil, dir)
447
+ Chef::Log.debug("#{new_resource} set user to #{new_resource.user} for #{dir}")
431
448
  end
432
- if @new_resource.group
433
- FileUtils.chown(nil, @new_resource.group, dir)
434
- Chef::Log.debug("#{@new_resource} set group to #{@new_resource.group} for #{dir}")
449
+ if new_resource.group
450
+ FileUtils.chown(nil, new_resource.group, dir)
451
+ Chef::Log.debug("#{new_resource} set group to #{new_resource.group} for #{dir}")
435
452
  end
436
453
  rescue => e
437
454
  raise Chef::Exceptions::FileNotFound.new("Cannot create directory #{dir}: #{e.message}")
@@ -442,7 +459,7 @@ class Chef
442
459
  def with_rollback_on_error
443
460
  yield
444
461
  rescue ::Exception => e
445
- if @new_resource.rollback_on_error
462
+ if new_resource.rollback_on_error
446
463
  Chef::Log.warn "Error on deploying #{release_path}: #{e.message}"
447
464
  failed_release = release_path
448
465
 
@@ -461,8 +478,8 @@ class Chef
461
478
  end
462
479
 
463
480
  def save_release_state
464
- if ::File.exists?(@new_resource.current_path)
465
- release = ::File.readlink(@new_resource.current_path)
481
+ if ::File.exists?(new_resource.current_path)
482
+ release = ::File.readlink(new_resource.current_path)
466
483
  @previous_release_path = release if ::File.exists?(release)
467
484
  end
468
485
  end