chef 0.8.8 → 0.8.10

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of chef might be problematic. Click here for more details.

@@ -27,7 +27,7 @@ require 'chef/config'
27
27
  Dir[File.join(File.dirname(__FILE__), 'chef/mixin/**/*.rb')].sort.each { |lib| require lib }
28
28
 
29
29
  class Chef
30
- VERSION = '0.8.8'
30
+ VERSION = '0.8.10'
31
31
  end
32
32
 
33
33
  # Adds a Dir.glob to Ruby 1.8.5, for compat
@@ -130,28 +130,62 @@ class Chef
130
130
 
131
131
  def gen_validation_key(name=Chef::Config[:validation_client_name], key_file=Chef::Config[:validation_key])
132
132
  # Create the validation key
133
- create_key = false
133
+ api_client = Chef::ApiClient.new
134
+ api_client.name(name)
135
+ api_client.admin(true)
136
+
134
137
  begin
135
- c = Chef::ApiClient.cdb_load(name)
138
+ # If both the couch record and file exist, don't do anything. Otherwise,
139
+ # re-generate the validation key.
140
+ Chef::ApiClient.cdb_load(name)
141
+
142
+ # The couch document was loaded successfully if we got to here; if we
143
+ # can't also load the file on the filesystem, we'll regenerate it all.
144
+ File.open(key_file, "r") do |file|
145
+ end
136
146
  rescue Chef::Exceptions::CouchDBNotFound
137
- create_key = true
147
+ create_validation_key(api_client, key_file)
148
+ rescue
149
+ if $!.class.name =~ /Errno::/
150
+ Chef::Log.error("Error opening validation key: #{$!} -- destroying and regenerating")
151
+ begin
152
+ api_client.cdb_destroy
153
+ rescue Bunny::ServerDownError => e
154
+ # create_validation_key is gonna fail anyway, so let's just bail out.
155
+ Chef::Log.fatal("Could not de-index (to rabbitmq) previous validation key - rabbitmq is down! Start rabbitmq then restart chef-server to re-generate it")
156
+ raise
157
+ end
158
+
159
+ create_validation_key(api_client, key_file)
160
+ else
161
+ raise
162
+ end
138
163
  end
164
+ end
165
+
166
+ private
167
+ def create_validation_key(api_client, key_file)
168
+ Chef::Log.info("Creating validation key...")
139
169
 
140
- if create_key
141
- Chef::Log.info("Creating validation key...")
142
- api_client = Chef::ApiClient.new
143
- api_client.name(name)
144
- api_client.admin(true)
145
- api_client.create_keys
170
+ api_client.create_keys
171
+ begin
146
172
  api_client.cdb_save
147
- key_dir = File.dirname(key_file)
148
- FileUtils.mkdir_p(key_dir) unless File.directory?(key_dir)
149
- File.open(key_file, File::WRONLY|File::EXCL|File::CREAT, 0600) do |f|
150
- f.print(api_client.private_key)
151
- end
152
- if (Chef::Config[:signing_ca_user] && Chef::Config[:signing_ca_group])
153
- FileUtils.chown(Chef::Config[:signing_ca_user], Chef::Config[:signing_ca_group], key_file)
154
- end
173
+ rescue Bunny::ServerDownError => e
174
+ # If rabbitmq is down, the client will have been saved in CouchDB,
175
+ # but not in the index.
176
+ Chef::Log.fatal("Could not index (to rabbitmq) validation key - rabbitmq is down! Start rabbitmq then restart chef-server to re-generate it")
177
+
178
+ # re-raise so the error bubbles out and nukes chef-server
179
+ raise e
180
+ end
181
+
182
+ key_dir = File.dirname(key_file)
183
+ FileUtils.mkdir_p(key_dir) unless File.directory?(key_dir)
184
+ File.open(key_file, File::WRONLY|File::CREAT, 0600) do |f|
185
+ f.print(api_client.private_key)
186
+ end
187
+ if (Chef::Config[:signing_ca_user] && Chef::Config[:signing_ca_group])
188
+ FileUtils.chown(Chef::Config[:signing_ca_user], Chef::Config[:signing_ca_group], key_file)
155
189
  end
156
190
  end
157
191
 
@@ -168,7 +168,7 @@ class Chef
168
168
  amqp_vhost '/chef'
169
169
  # Setting this to a UUID string also makes the queue durable
170
170
  # (persist across rabbitmq restarts)
171
- amqp_consumer_id nil
171
+ amqp_consumer_id "default"
172
172
 
173
173
  client_key "/etc/chef/client.pem"
174
174
  validation_key "/etc/chef/validation.pem"
@@ -19,7 +19,7 @@
19
19
 
20
20
  require 'chef/log'
21
21
  require 'chef/node'
22
- require 'chef/resource_definition'
22
+ require 'chef/resource_definition_list'
23
23
  require 'chef/recipe'
24
24
  require 'chef/mixin/convert_to_class_name'
25
25
 
@@ -98,9 +98,12 @@ class Chef
98
98
  results = Hash.new
99
99
  @definition_files.each do |file|
100
100
  Chef::Log.debug("Loading cookbook #{name}'s definitions from #{file}")
101
- resourcedef = Chef::ResourceDefinition.new
102
- resourcedef.from_file(file)
103
- results[resourcedef.name] = resourcedef
101
+ resourcelist = Chef::ResourceDefinitionList.new
102
+ resourcelist.from_file(file)
103
+ results.merge!(resourcelist.defines) do |key, oldval, newval|
104
+ Chef::Log.info("Overriding duplicate definition #{key}, new found in #{file}")
105
+ newval
106
+ end
104
107
  end
105
108
  results
106
109
  end
@@ -75,7 +75,7 @@ class Chef
75
75
  cookbook_settings[cookbook_name][:lib_files]
76
76
  )
77
77
  load_cascading_files(
78
- "*.erb",
78
+ "*",
79
79
  File.join(cookbook, "templates"),
80
80
  cookbook_settings[cookbook_name][:template_files]
81
81
  )
@@ -36,5 +36,6 @@ class Chef
36
36
  class PrivateKeyMissing < RuntimeError; end
37
37
  class CannotWritePrivateKey < RuntimeError; end
38
38
  class RoleNotFound < RuntimeError; end
39
+ class ValidationFailed < ArgumentError; end
39
40
  end
40
41
  end
@@ -16,6 +16,7 @@
16
16
  # limitations under the License.
17
17
 
18
18
  class Chef
19
+
19
20
  module Mixin
20
21
  module ParamsValidate
21
22
 
@@ -105,26 +106,24 @@ class Chef
105
106
  # Raise an exception if the parameter is not found.
106
107
  def _pv_required(opts, key, is_required=true)
107
108
  if is_required
108
- if (opts.has_key?(key.to_s) && opts[key.to_s] != nil) ||
109
- (opts.has_key?(key.to_sym) && opts[key.to_sym] != nil)
109
+ if (opts.has_key?(key.to_s) && !opts[key.to_s].nil?) ||
110
+ (opts.has_key?(key.to_sym) && !opts[key.to_sym].nil?)
110
111
  true
111
112
  else
112
- raise ArgumentError, "Required argument #{key} is missing!"
113
+ raise Exceptions::ValidationFailed, "Required argument #{key} is missing!"
113
114
  end
114
115
  end
115
116
  end
116
117
 
117
118
  def _pv_equal_to(opts, key, to_be)
118
119
  value = _pv_opts_lookup(opts, key)
119
- if value != nil
120
+ unless value.nil?
120
121
  passes = false
121
- [ to_be ].flatten.each do |tb|
122
- if value == tb
123
- passes = true
124
- end
122
+ Array(to_be).each do |tb|
123
+ passes = true if value == tb
125
124
  end
126
125
  unless passes
127
- raise ArgumentError, "Option #{key} must be equal to one of: #{to_be.join(", ")}! You passed #{value.inspect}."
126
+ raise Exceptions::ValidationFailed, "Option #{key} must be equal to one of: #{to_be.join(", ")}! You passed #{value.inspect}."
128
127
  end
129
128
  end
130
129
  end
@@ -132,15 +131,13 @@ class Chef
132
131
  # Raise an exception if the parameter is not a kind_of?(to_be)
133
132
  def _pv_kind_of(opts, key, to_be)
134
133
  value = _pv_opts_lookup(opts, key)
135
- if value != nil
134
+ unless value.nil?
136
135
  passes = false
137
- [ to_be ].flatten.each do |tb|
138
- if value.kind_of?(tb)
139
- passes = true
140
- end
136
+ Array(to_be).each do |tb|
137
+ passes = true if value.kind_of?(tb)
141
138
  end
142
139
  unless passes
143
- raise ArgumentError, "Option #{key} must be a kind of #{to_be}! You passed #{value.inspect}."
140
+ raise Exceptions::ValidationFailed, "Option #{key} must be a kind of #{to_be}! You passed #{value.inspect}."
144
141
  end
145
142
  end
146
143
  end
@@ -148,14 +145,32 @@ class Chef
148
145
  # Raise an exception if the parameter does not respond to a given set of methods.
149
146
  def _pv_respond_to(opts, key, method_name_list)
150
147
  value = _pv_opts_lookup(opts, key)
151
- if value != nil
152
- [ method_name_list ].flatten.each do |method_name|
148
+ unless value.nil?
149
+ Array(method_name_list).each do |method_name|
153
150
  unless value.respond_to?(method_name)
154
- raise ArgumentError, "Option #{key} must have a #{method_name} method!"
151
+ raise Exceptions::ValidationFailed, "Option #{key} must have a #{method_name} method!"
155
152
  end
156
153
  end
157
154
  end
158
155
  end
156
+
157
+ # Assert that parameter returns false when passed a predicate method.
158
+ # For example, :cannot_be => :blank will raise a Exceptions::ValidationFailed
159
+ # error value.blank? returns a 'truthy' (not nil or false) value.
160
+ #
161
+ # Note, this will *PASS* if the object doesn't respond to the method.
162
+ # So, to make sure a value is not nil and not blank, you need to do
163
+ # both :cannot_be => :blank *and* :cannot_be => :nil (or :required => true)
164
+ def _pv_cannot_be(opts, key, predicate_method_base_name)
165
+ value = _pv_opts_lookup(opts, key)
166
+ predicate_method = (predicate_method_base_name.to_s + "?").to_sym
167
+
168
+ if value.respond_to?(predicate_method)
169
+ if value.send(predicate_method)
170
+ raise Exceptions::ValidationFailed, "Option #{key} cannot be #{predicate_method_base_name}"
171
+ end
172
+ end
173
+ end
159
174
 
160
175
  # Assign a default value to a parameter.
161
176
  def _pv_default(opts, key, default_value)
@@ -178,7 +193,7 @@ class Chef
178
193
  end
179
194
  end
180
195
  unless passes
181
- raise ArgumentError, "Option #{key}'s value #{value} does not match regular expression #{regex.to_s}"
196
+ raise Exceptions::ValidationFailed, "Option #{key}'s value #{value} does not match regular expression #{regex.to_s}"
182
197
  end
183
198
  end
184
199
  end
@@ -190,7 +205,7 @@ class Chef
190
205
  if value != nil
191
206
  callbacks.each do |message, zeproc|
192
207
  if zeproc.call(value) != true
193
- raise ArgumentError, "Option #{key}'s value #{value} #{message}!"
208
+ raise Exceptions::ValidationFailed, "Option #{key}'s value #{value} #{message}!"
194
209
  end
195
210
  end
196
211
  end
@@ -1,5 +1,4 @@
1
1
  #
2
- # Author:: Sam Ruby
3
2
  # Author:: Daniel DeLeo (<dan@opscode.com>)
4
3
  # Copyright:: Copyright (c) 2009 Opscode, Inc.
5
4
  # Copyright:: Copyright (c) 2005 Sam Ruby
@@ -17,8 +16,36 @@
17
16
  # See the License for the specific language governing permissions and
18
17
  # limitations under the License.
19
18
 
20
- # Code adapted from Sam Ruby's xchar.rb http://intertwingly.net/stories/2005/09/28/xchar.rb
19
+ #
20
+ # Portions of this code are adapted from Sam Ruby's xchar.rb
21
+ # http://intertwingly.net/stories/2005/09/28/xchar.rb
22
+ #
23
+ # Such code appears here under Sam's original MIT license, while portions of
24
+ # this file are covered by the above Apache License. For a completely MIT
25
+ # licensed version, please see Sam's original.
26
+ #
21
27
  # Thanks, Sam!
28
+ #
29
+ # Copyright (c) 2005, Sam Ruby
30
+ #
31
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
32
+ # of this software and associated documentation files (the "Software"), to deal
33
+ # in the Software without restriction, including without limitation the rights
34
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
35
+ # copies of the Software, and to permit persons to whom the Software is
36
+ # furnished to do so, subject to the following conditions:
37
+ #
38
+ # The above copyright notice and this permission notice shall be included in
39
+ # all copies or substantial portions of the Software.
40
+ #
41
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
44
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
46
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
47
+ # THE SOFTWARE.
48
+
22
49
 
23
50
  class Chef
24
51
  module Mixin
@@ -182,13 +182,10 @@ class Chef
182
182
  def name(arg=nil)
183
183
  if arg != nil
184
184
  validate(
185
- { :name => arg },
186
- {
187
- :name => {
188
- :kind_of => String
189
- }
190
- }
191
- )
185
+ {:name => arg },
186
+ {:name => { :kind_of => String,
187
+ :cannot_be => :blank}
188
+ })
192
189
  @name = arg
193
190
  else
194
191
  @name
@@ -211,7 +211,7 @@ class Chef
211
211
  def copy_cached_repo
212
212
  Chef::Log.info "copying the cached checkout to #{release_path}"
213
213
  FileUtils.mkdir_p(@new_resource.deploy_to + "/releases")
214
- FileUtils.cp_r(::File.join(@new_resource.destination, "."), release_path, :preserve => true)
214
+ run_command(:command => "cp -RPp #{::File.join(@new_resource.destination, ".")} #{release_path}")
215
215
  release_created(release_path)
216
216
  end
217
217
 
@@ -42,7 +42,9 @@ class Chef
42
42
  cache_file_name = "cookbooks/#{cookbook_name}/templates/default/#{@new_resource.source}"
43
43
  template_cache_name = "#{cookbook_name}_#{@new_resource.source}"
44
44
 
45
- if Chef::Config[:solo]
45
+ if @new_resource.local
46
+ cache_file_name = @new_resource.source
47
+ elsif Chef::Config[:solo]
46
48
  cache_file_name = solo_cache_file_name
47
49
  else
48
50
  raw_template_file = fetch_template_via_rest(cache_file_name, template_cache_name)
@@ -28,6 +28,7 @@ class Chef
28
28
  @action = "create"
29
29
  @source = "#{::File.basename(name)}.erb"
30
30
  @cookbook = nil
31
+ @local = false
31
32
  @variables = Hash.new
32
33
  end
33
34
 
@@ -55,6 +56,14 @@ class Chef
55
56
  )
56
57
  end
57
58
 
59
+ def local(args=nil)
60
+ set_or_return(
61
+ :local,
62
+ args,
63
+ :kind_of => [ TrueClass, FalseClass ]
64
+ )
65
+ end
66
+
58
67
  end
59
68
  end
60
69
  end
@@ -64,4 +64,4 @@ class Chef
64
64
  "#{name.to_s}"
65
65
  end
66
66
  end
67
- end
67
+ end
@@ -0,0 +1,38 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 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 'chef/mixin/from_file'
20
+ require 'chef/resource_definition'
21
+
22
+ class Chef
23
+ class ResourceDefinitionList
24
+ include Chef::Mixin::FromFile
25
+
26
+ attr_accessor :defines
27
+
28
+ def initialize
29
+ @defines = Hash.new
30
+ end
31
+
32
+ def define(resource_name, prototype_params=nil, &block)
33
+ @defines[resource_name] = ResourceDefinition.new
34
+ @defines[resource_name].define(resource_name, prototype_params, &block)
35
+ true
36
+ end
37
+ end
38
+ end
@@ -133,7 +133,7 @@ class Chef
133
133
  @seen_roles << name
134
134
  if from == 'disk' || Chef::Config[:solo]
135
135
  # Load the role from disk
136
- Chef::Role.from_disk("#{name}") || Chef::Exceptions::RoleNotFound
136
+ Chef::Role.from_disk("#{name}") || raise(Chef::Exceptions::RoleNotFound)
137
137
  elsif from == 'server'
138
138
  # Load the role from the server
139
139
  begin
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 8
8
- - 8
9
- version: 0.8.8
8
+ - 10
9
+ version: 0.8.10
10
10
  platform: ruby
11
11
  authors:
12
12
  - Adam Jacob
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-17 00:00:00 -07:00
17
+ date: 2010-04-01 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -376,6 +376,7 @@ files:
376
376
  - lib/chef/resource_collection/stepable_iterator.rb
377
377
  - lib/chef/resource_collection.rb
378
378
  - lib/chef/resource_definition.rb
379
+ - lib/chef/resource_definition_list.rb
379
380
  - lib/chef/rest.rb
380
381
  - lib/chef/role.rb
381
382
  - lib/chef/run_list.rb