chefspec 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chef/formatters/chefspec.rb +198 -0
- data/lib/chefspec.rb +1 -0
- data/lib/chefspec/chef_runner.rb +23 -10
- data/lib/chefspec/version.rb +1 -1
- metadata +16 -9
@@ -0,0 +1,198 @@
|
|
1
|
+
if defined?(Chef::Formatters::Base)
|
2
|
+
class Chef
|
3
|
+
module Formatters
|
4
|
+
# A specific formatter for Chef 11. This base for this formatter was
|
5
|
+
# taken from Chef::Formatters:Min and all the output was then removed.
|
6
|
+
#
|
7
|
+
# @author Seth Vargo <sethvargo@gmail.com>
|
8
|
+
class ChefSpec < Formatters::Base
|
9
|
+
cli_name(:chefspec)
|
10
|
+
|
11
|
+
attr_reader :updated_resources
|
12
|
+
attr_reader :updates_by_resource
|
13
|
+
|
14
|
+
def initialize(out, err)
|
15
|
+
super
|
16
|
+
@updated_resources = []
|
17
|
+
@updates_by_resource = Hash.new {|h, k| h[k] = []}
|
18
|
+
end
|
19
|
+
|
20
|
+
# Called at the very start of a Chef Run
|
21
|
+
def run_start(version)
|
22
|
+
puts "Starting Chef Client, version #{version}"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Called at the end of the Chef run.
|
26
|
+
def run_completed(node)
|
27
|
+
end
|
28
|
+
|
29
|
+
# called at the end of a failed run
|
30
|
+
def run_failed(exception)
|
31
|
+
puts "chef client failed. #{@updated_resources.size} resources updated"
|
32
|
+
end
|
33
|
+
|
34
|
+
# Called right after ohai runs.
|
35
|
+
def ohai_completed(node)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Already have a client key, assuming this node has registered.
|
39
|
+
def skipping_registration(node_name, config)
|
40
|
+
end
|
41
|
+
|
42
|
+
# About to attempt to register as +node_name+
|
43
|
+
def registration_start(node_name, config)
|
44
|
+
end
|
45
|
+
|
46
|
+
def registration_completed
|
47
|
+
end
|
48
|
+
|
49
|
+
# Failed to register this client with the server.
|
50
|
+
def registration_failed(node_name, exception, config)
|
51
|
+
super
|
52
|
+
end
|
53
|
+
|
54
|
+
def node_load_start(node_name, config)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Failed to load node data from the server
|
58
|
+
def node_load_failed(node_name, exception, config)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Default and override attrs from roles have been computed, but not yet applied.
|
62
|
+
# Normal attrs from JSON have been added to the node.
|
63
|
+
def node_load_completed(node, expanded_run_list, config)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Called before the cookbook collection is fetched from the server.
|
67
|
+
def cookbook_resolution_start(expanded_run_list)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Called when there is an error getting the cookbook collection from the
|
71
|
+
# server.
|
72
|
+
def cookbook_resolution_failed(expanded_run_list, exception)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Called when the cookbook collection is returned from the server.
|
76
|
+
def cookbook_resolution_complete(cookbook_collection)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Called before unneeded cookbooks are removed
|
80
|
+
#--
|
81
|
+
# TODO: Should be called in CookbookVersion.sync_cookbooks
|
82
|
+
def cookbook_clean_start
|
83
|
+
end
|
84
|
+
|
85
|
+
# Called after the file at +path+ is removed. It may be removed if the
|
86
|
+
# cookbook containing it was removed from the run list, or if the file was
|
87
|
+
# removed from the cookbook.
|
88
|
+
def removed_cookbook_file(path)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Called when cookbook cleaning is finished.
|
92
|
+
def cookbook_clean_complete
|
93
|
+
end
|
94
|
+
|
95
|
+
# Called before cookbook sync starts
|
96
|
+
def cookbook_sync_start(cookbook_count)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Called when cookbook +cookbook_name+ has been sync'd
|
100
|
+
def synchronized_cookbook(cookbook_name)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Called when an individual file in a cookbook has been updated
|
104
|
+
def updated_cookbook_file(cookbook_name, path)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Called after all cookbooks have been sync'd.
|
108
|
+
def cookbook_sync_complete
|
109
|
+
end
|
110
|
+
|
111
|
+
# Called when cookbook loading starts.
|
112
|
+
def library_load_start(file_count)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Called after a file in a cookbook is loaded.
|
116
|
+
def file_loaded(path)
|
117
|
+
end
|
118
|
+
|
119
|
+
def file_load_failed(path, exception)
|
120
|
+
super
|
121
|
+
end
|
122
|
+
|
123
|
+
# Called when recipes have been loaded.
|
124
|
+
def recipe_load_complete
|
125
|
+
end
|
126
|
+
|
127
|
+
# Called before convergence starts
|
128
|
+
def converge_start(run_context)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Called when the converge phase is finished.
|
132
|
+
def converge_complete
|
133
|
+
end
|
134
|
+
|
135
|
+
# Called before action is executed on a resource.
|
136
|
+
def resource_action_start(resource, action, notification_type=nil, notifier=nil)
|
137
|
+
end
|
138
|
+
|
139
|
+
# Called when a resource fails, but will retry.
|
140
|
+
def resource_failed_retriable(resource, action, retry_count, exception)
|
141
|
+
end
|
142
|
+
|
143
|
+
# Called when a resource fails and will not be retried.
|
144
|
+
def resource_failed(resource, action, exception)
|
145
|
+
end
|
146
|
+
|
147
|
+
# Called when a resource action has been skipped b/c of a conditional
|
148
|
+
def resource_skipped(resource, action, conditional)
|
149
|
+
end
|
150
|
+
|
151
|
+
# Called after #load_current_resource has run.
|
152
|
+
def resource_current_state_loaded(resource, action, current_resource)
|
153
|
+
end
|
154
|
+
|
155
|
+
# Called when a resource has no converge actions, e.g., it was already correct.
|
156
|
+
def resource_up_to_date(resource, action)
|
157
|
+
end
|
158
|
+
|
159
|
+
## TODO: callback for assertion failures
|
160
|
+
|
161
|
+
## TODO: callback for assertion fallback in why run
|
162
|
+
|
163
|
+
# Called when a change has been made to a resource. May be called multiple
|
164
|
+
# times per resource, e.g., a file may have its content updated, and then
|
165
|
+
# its permissions updated.
|
166
|
+
def resource_update_applied(resource, action, update)
|
167
|
+
@updates_by_resource[resource.name] << Array(update)[0]
|
168
|
+
end
|
169
|
+
|
170
|
+
# Called after a resource has been completely converged.
|
171
|
+
def resource_updated(resource, action)
|
172
|
+
updated_resources << resource
|
173
|
+
end
|
174
|
+
|
175
|
+
# Called before handlers run
|
176
|
+
def handlers_start(handler_count)
|
177
|
+
end
|
178
|
+
|
179
|
+
# Called after an individual handler has run
|
180
|
+
def handler_executed(handler)
|
181
|
+
end
|
182
|
+
|
183
|
+
# Called after all handlers have executed
|
184
|
+
def handlers_completed
|
185
|
+
end
|
186
|
+
|
187
|
+
# An uncategorized message. This supports the case that a user needs to
|
188
|
+
# pass output that doesn't fit into one of the callbacks above. Note that
|
189
|
+
# there's no semantic information about the content or importance of the
|
190
|
+
# message. That means that if you're using this too often, you should add a
|
191
|
+
# callback for it.
|
192
|
+
def msg(message)
|
193
|
+
end
|
194
|
+
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
data/lib/chefspec.rb
CHANGED
data/lib/chefspec/chef_runner.rb
CHANGED
@@ -26,6 +26,7 @@ module ChefSpec
|
|
26
26
|
# @option options [Symbol] :log_level The log level to use (default is :warn)
|
27
27
|
# @option options [String] :platform The platform to load Ohai attributes from (must be present in fauxhai)
|
28
28
|
# @option options [String] :version The version of the platform to load Ohai attributes from (must be present in fauxhai)
|
29
|
+
# @option options [String] :ohai_data_path Path of a json file that will be passed to fauxhai as :path option
|
29
30
|
# @yield [node] Configuration block for Chef::Node
|
30
31
|
def initialize(options={})
|
31
32
|
defaults = {:cookbook_path => default_cookbook_path, :log_level => :warn, :dry_run => false, :step_into => []}
|
@@ -72,9 +73,15 @@ module ChefSpec
|
|
72
73
|
|
73
74
|
Chef::Config[:solo] = true
|
74
75
|
Chef::Config[:cache_type] = "Memory"
|
76
|
+
Chef::Config[:cache_options] = { :path => File.join(File.expand_path('~'), '.chef', 'checksums') }
|
75
77
|
Chef::Cookbook::FileVendor.on_create { |manifest| Chef::Cookbook::FileSystemFileVendor.new(manifest) }
|
76
78
|
Chef::Config[:cookbook_path] = @options[:cookbook_path]
|
77
79
|
Chef::Config[:client_key] = nil
|
80
|
+
|
81
|
+
# As of Chef 11, Chef uses custom formatters which munge the RSpec output.
|
82
|
+
# This uses a custom formatter which basically tells Chef to shut up.
|
83
|
+
Chef::Config.add_formatter('chefspec') if Chef::Config.respond_to?(:add_formatter)
|
84
|
+
|
78
85
|
Chef::Log.verbose = true if Chef::Log.respond_to?(:verbose)
|
79
86
|
Chef::Log.level(@options[:log_level])
|
80
87
|
@client = Chef::Client.new
|
@@ -133,7 +140,16 @@ module ChefSpec
|
|
133
140
|
return "chef_run: #{@node.run_list.to_s}" unless @node.run_list.empty?
|
134
141
|
'chef_run'
|
135
142
|
end
|
136
|
-
|
143
|
+
|
144
|
+
# Find the resource with the declared type and name
|
145
|
+
#
|
146
|
+
# @param [String] type The type of resource - e.g. 'file' or 'directory'
|
147
|
+
# @param [String] name The resource name
|
148
|
+
# @return [Chef::Resource] The matching resource, or Nil
|
149
|
+
def find_resource(type, name)
|
150
|
+
resources.find{|resource| resource_type(resource) == type and resource.name == name}
|
151
|
+
end
|
152
|
+
|
137
153
|
private
|
138
154
|
|
139
155
|
# Populate basic OHAI attributes required to get recipes working. This is a minimal set - if your recipe example
|
@@ -144,7 +160,12 @@ module ChefSpec
|
|
144
160
|
#
|
145
161
|
# @param [Ohai::System] ohai The ohai instance to set fake attributes on
|
146
162
|
def fake_ohai(ohai)
|
147
|
-
|
163
|
+
data = if @options.has_key?(:ohai_data_path)
|
164
|
+
Fauxhai::Mocker.new(:path => @options[:ohai_data_path]).data
|
165
|
+
else
|
166
|
+
Fauxhai::Mocker.new(:platform => @options[:platform], :version => @options[:version]).data
|
167
|
+
end
|
168
|
+
data.each_pair do |attribute, value|
|
148
169
|
ohai[attribute] = value
|
149
170
|
end
|
150
171
|
end
|
@@ -156,14 +177,6 @@ module ChefSpec
|
|
156
177
|
Pathname.new(File.join(caller(2).first.split(':').slice(0..-3).join(':'), '..', '..', '..')).cleanpath.to_s
|
157
178
|
end
|
158
179
|
|
159
|
-
# Find the resource with the declared type and name
|
160
|
-
#
|
161
|
-
# @param [String] type The type of resource - e.g. 'file' or 'directory'
|
162
|
-
# @param [String] name The resource name
|
163
|
-
# @return [Chef::Resource] The matching resource, or Nil
|
164
|
-
def find_resource(type, name)
|
165
|
-
resources.find{|resource| resource_type(resource) == type and resource.name == name}
|
166
|
-
end
|
167
180
|
end
|
168
181
|
|
169
182
|
end
|
data/lib/chefspec/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chefspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chef
|
@@ -48,17 +48,23 @@ dependencies:
|
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 0.1.1
|
54
|
+
- - <
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '2.0'
|
54
57
|
type: :runtime
|
55
58
|
prerelease: false
|
56
59
|
version_requirements: !ruby/object:Gem::Requirement
|
57
60
|
none: false
|
58
61
|
requirements:
|
59
|
-
- -
|
62
|
+
- - ! '>='
|
60
63
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
64
|
+
version: 0.1.1
|
65
|
+
- - <
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.0'
|
62
68
|
- !ruby/object:Gem::Dependency
|
63
69
|
name: minitest-chef-handler
|
64
70
|
requirement: !ruby/object:Gem::Requirement
|
@@ -193,6 +199,7 @@ executables: []
|
|
193
199
|
extensions: []
|
194
200
|
extra_rdoc_files: []
|
195
201
|
files:
|
202
|
+
- lib/chef/formatters/chefspec.rb
|
196
203
|
- lib/chef/knife/cookbook_create_specs.rb
|
197
204
|
- lib/chefspec/chef_runner.rb
|
198
205
|
- lib/chefspec/matchers/cron.rb
|
@@ -232,7 +239,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
232
239
|
version: '0'
|
233
240
|
segments:
|
234
241
|
- 0
|
235
|
-
hash: -
|
242
|
+
hash: -3143489054534407734
|
236
243
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
237
244
|
none: false
|
238
245
|
requirements:
|
@@ -241,12 +248,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
241
248
|
version: '0'
|
242
249
|
segments:
|
243
250
|
- 0
|
244
|
-
hash: -
|
251
|
+
hash: -3143489054534407734
|
245
252
|
requirements: []
|
246
253
|
rubyforge_project:
|
247
254
|
rubygems_version: 1.8.23
|
248
255
|
signing_key:
|
249
256
|
specification_version: 3
|
250
|
-
summary: chefspec-1.
|
257
|
+
summary: chefspec-1.1.0
|
251
258
|
test_files: []
|
252
259
|
has_rdoc:
|