chef-zero 4.1.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chef_zero/rspec.rb +225 -222
- data/lib/chef_zero/version.rb +1 -1
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d33b522041ae43c415622aa4256a1fdb6e1c12dd
|
4
|
+
data.tar.gz: b9486a52dd93f3ee4e2a27c5195410b61acc486b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7da539d3289e42b8abec5960a9fbb30495410a42f820ae558b9b289e6bfeeae5a037b679d3f7d059482be7d48a45b08bd5032b038488ffeb6461ac3826daac02
|
7
|
+
data.tar.gz: 9d108127793484ae21fb50d87143486ad484ee9035c57391474467be9d3c624ddd23c51ab5a2f8963d8733e376efda52be8072f90e86517fdf964dbf77096d5d
|
data/lib/chef_zero/rspec.rb
CHANGED
@@ -4,71 +4,81 @@ require 'chef_zero/rest_request'
|
|
4
4
|
|
5
5
|
module ChefZero
|
6
6
|
module RSpec
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
7
|
+
module RSpecClassMethods
|
8
|
+
attr_accessor :server
|
9
|
+
attr_accessor :client_key
|
10
|
+
attr_reader :request_log
|
11
|
+
|
12
|
+
def clear_request_log
|
13
|
+
@request_log = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_server_options(chef_server_options)
|
17
|
+
if server && chef_server_options != server.options
|
18
|
+
server.stop
|
19
|
+
self.server = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
unless server
|
23
|
+
# TODO: can this be logged easily?
|
24
|
+
# pp :zero_opts => chef_server_options
|
25
|
+
|
26
|
+
# Set up configuration so that clients will point to the server
|
27
|
+
self.server = ChefZero::Server.new(chef_server_options)
|
28
|
+
self.client_key = Tempfile.new(['chef_zero_client_key', '.pem'])
|
29
|
+
client_key.write(ChefZero::PRIVATE_KEY)
|
30
|
+
client_key.close
|
31
|
+
# Start the server
|
32
|
+
server.start_background
|
33
|
+
server.on_response do |request, response|
|
34
|
+
request_log << [ request, response ]
|
35
|
+
end
|
36
|
+
else
|
37
|
+
server.clear_data
|
38
|
+
end
|
39
|
+
clear_request_log
|
40
|
+
end
|
24
41
|
end
|
42
|
+
extend RSpecClassMethods
|
25
43
|
|
26
44
|
def when_the_chef_server(description, *tags, &block)
|
27
|
-
if tags.last.is_a?(Hash)
|
28
|
-
opts = tags.last
|
29
|
-
else
|
30
|
-
opts = {}
|
31
|
-
end
|
32
45
|
context "When the Chef server #{description}", *tags do
|
33
|
-
|
46
|
+
extend WhenTheChefServerClassMethods
|
47
|
+
include WhenTheChefServerInstanceMethods
|
34
48
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
server_opts = server_opts.merge(opts)
|
49
|
+
def self.chef_server_options
|
50
|
+
@@chef_server_options
|
51
|
+
end
|
52
|
+
def chef_server_options
|
53
|
+
self.class.chef_server_options
|
54
|
+
end
|
42
55
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
56
|
+
@@chef_server_options = { port: 8900, signals: false, log_requests: true, server_scope: :each }
|
57
|
+
chef_server_options.merge!(chef_zero_opts) if self.respond_to?(:chef_zero_opts)
|
58
|
+
chef_server_options.merge!(tags.last) if tags.last.is_a?(Hash)
|
47
59
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
ChefZero::RSpec.server.on_response do |request, response|
|
60
|
-
ChefZero::RSpec.request_log << [ request, response ]
|
61
|
-
end
|
62
|
-
else
|
63
|
-
ChefZero::RSpec.server.clear_data
|
60
|
+
Log.debug("Starting Chef server with options #{chef_server_options}")
|
61
|
+
|
62
|
+
old_chef_server_url = nil
|
63
|
+
old_node_name = nil
|
64
|
+
old_client_key = nil
|
65
|
+
|
66
|
+
before chef_server_options[:server_scope] do
|
67
|
+
ChefZero::RSpec.set_server_options(chef_server_options)
|
68
|
+
|
69
|
+
if chef_server_options[:organization]
|
70
|
+
organization chef_server_options[:organization]
|
64
71
|
end
|
65
|
-
ChefZero::RSpec.clear_request_log
|
66
72
|
|
67
73
|
if defined?(Chef::Config)
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
74
|
+
old_chef_server_url = Chef::Config.chef_server_url
|
75
|
+
old_node_name = Chef::Config.node_name
|
76
|
+
old_client_key = Chef::Config.client_key
|
77
|
+
if chef_server_options[:organization]
|
78
|
+
Chef::Config.chef_server_url = "#{ChefZero::RSpec.server.url}/organizations/#{chef_server_options[:organization]}"
|
79
|
+
else
|
80
|
+
Chef::Config.chef_server_url = ChefZero::RSpec.server.url
|
81
|
+
end
|
72
82
|
Chef::Config.node_name = 'admin'
|
73
83
|
Chef::Config.client_key = ChefZero::RSpec.client_key.path
|
74
84
|
Chef::Config.http_retry_count = 0
|
@@ -76,224 +86,217 @@ module ChefZero
|
|
76
86
|
end
|
77
87
|
|
78
88
|
if defined?(Chef::Config)
|
79
|
-
after :
|
80
|
-
Chef::Config.chef_server_url =
|
81
|
-
Chef::Config.node_name =
|
82
|
-
Chef::Config.client_key =
|
89
|
+
after chef_server_options[:server_scope] do
|
90
|
+
Chef::Config.chef_server_url = old_chef_server_url
|
91
|
+
Chef::Config.node_name = old_node_name
|
92
|
+
Chef::Config.client_key = old_client_key
|
83
93
|
end
|
84
94
|
end
|
85
95
|
|
86
|
-
|
87
|
-
|
88
|
-
|
96
|
+
instance_eval(&block)
|
97
|
+
end
|
98
|
+
end
|
89
99
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
prev_object_path = @current_object_path
|
95
|
-
@current_object_path = "organizations/#{name}"
|
96
|
-
if block_given?
|
97
|
-
begin
|
98
|
-
instance_eval(&block)
|
99
|
-
ensure
|
100
|
-
@current_org = prev_org_name
|
101
|
-
@current_object_path = prev_object_path
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
100
|
+
module WhenTheChefServerClassMethods
|
101
|
+
def organization(name, org = '{}', &block)
|
102
|
+
before(chef_server_options[:server_scope]) { organization(name, org, &block) }
|
103
|
+
end
|
105
104
|
|
106
|
-
|
107
|
-
|
108
|
-
|
105
|
+
def acl_for(path, data)
|
106
|
+
before(chef_server_options[:server_scope]) { acl_for(path, data) }
|
107
|
+
end
|
109
108
|
|
110
|
-
|
111
|
-
|
112
|
-
|
109
|
+
def client(name, data, &block)
|
110
|
+
before(chef_server_options[:server_scope]) { client(name, data, &block) }
|
111
|
+
end
|
113
112
|
|
114
|
-
|
115
|
-
|
116
|
-
|
113
|
+
def container(name, data, &block)
|
114
|
+
before(chef_server_options[:server_scope]) { container(name, data, &block) }
|
115
|
+
end
|
117
116
|
|
118
|
-
|
119
|
-
|
117
|
+
def cookbook(name, version, data = {}, options = {}, &block)
|
118
|
+
before(chef_server_options[:server_scope]) do
|
119
|
+
cookbook(name, version, data, &block)
|
120
120
|
end
|
121
|
+
end
|
121
122
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
instance_eval(&block) if block_given?
|
126
|
-
end
|
127
|
-
end
|
123
|
+
def data_bag(name, data, &block)
|
124
|
+
before(chef_server_options[:server_scope]) { data_bag(name, data, &block) }
|
125
|
+
end
|
128
126
|
|
129
|
-
|
130
|
-
|
131
|
-
|
127
|
+
def environment(name, data, &block)
|
128
|
+
before(chef_server_options[:server_scope]) { environment(name, data, &block) }
|
129
|
+
end
|
132
130
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
instance_eval(&block) if block_given?
|
137
|
-
end
|
138
|
-
end
|
131
|
+
def group(name, data, &block)
|
132
|
+
before(chef_server_options[:server_scope]) { group(name, data, &block) }
|
133
|
+
end
|
139
134
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
end
|
144
|
-
end
|
135
|
+
def node(name, data, &block)
|
136
|
+
before(chef_server_options[:server_scope]) { node(name, data, &block) }
|
137
|
+
end
|
145
138
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
if data['metadata.rb'].nil?
|
150
|
-
data.delete('metadata.rb')
|
151
|
-
end
|
152
|
-
else
|
153
|
-
data['metadata.rb'] = "name #{name.inspect}; version #{version.inspect}"
|
154
|
-
end
|
155
|
-
ChefZero::RSpec.server.load_data({ 'cookbooks' => { "#{name}-#{version}" => data.merge(options) }}, current_org)
|
156
|
-
instance_eval(&block) if block_given?
|
157
|
-
end
|
158
|
-
end
|
139
|
+
def org_invite(*usernames)
|
140
|
+
before(chef_server_options[:server_scope]) { org_invite(*usernames) }
|
141
|
+
end
|
159
142
|
|
160
|
-
|
161
|
-
|
162
|
-
|
143
|
+
def org_member(*usernames)
|
144
|
+
before(chef_server_options[:server_scope]) { org_member(*usernames) }
|
145
|
+
end
|
163
146
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
instance_eval(&block) if block_given?
|
168
|
-
end
|
169
|
-
end
|
147
|
+
def role(name, data, &block)
|
148
|
+
before(chef_server_options[:server_scope]) { role(name, data, &block) }
|
149
|
+
end
|
170
150
|
|
171
|
-
|
172
|
-
|
173
|
-
|
151
|
+
def sandbox(name, data, &block)
|
152
|
+
before(chef_server_options[:server_scope]) { sandbox(name, data, &block) }
|
153
|
+
end
|
174
154
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
155
|
+
def user(name, data, &block)
|
156
|
+
before(chef_server_options[:server_scope]) { user(name, data, &block) }
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
module WhenTheChefServerInstanceMethods
|
161
|
+
def organization(name, org = '{}', &block)
|
162
|
+
ChefZero::RSpec.server.data_store.set([ 'organizations', name, 'org' ], dejsonize(org), :create_dir, :create)
|
163
|
+
prev_org_name = @current_org
|
164
|
+
@current_org = name
|
165
|
+
prev_object_path = @current_object_path
|
166
|
+
@current_object_path = "organizations/#{name}"
|
167
|
+
if block_given?
|
168
|
+
begin
|
169
|
+
instance_eval(&block)
|
170
|
+
ensure
|
171
|
+
@current_org = prev_org_name
|
172
|
+
@current_object_path = prev_object_path
|
179
173
|
end
|
180
174
|
end
|
175
|
+
end
|
181
176
|
|
182
|
-
|
183
|
-
|
184
|
-
|
177
|
+
def acl_for(path, data)
|
178
|
+
ChefZero::RSpec.server.load_data({ 'acls' => { path => data } }, current_org)
|
179
|
+
end
|
185
180
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
181
|
+
def acl(data)
|
182
|
+
acl_for(@current_object_path, data)
|
183
|
+
end
|
184
|
+
|
185
|
+
def client(name, data, &block)
|
186
|
+
with_object_path("clients/#{name}") do
|
187
|
+
ChefZero::RSpec.server.load_data({ 'clients' => { name => data } }, current_org)
|
188
|
+
instance_eval(&block) if block_given?
|
191
189
|
end
|
190
|
+
end
|
192
191
|
|
193
|
-
|
194
|
-
|
192
|
+
def container(name, data, &block)
|
193
|
+
with_object_path("containers/#{name}") do
|
194
|
+
ChefZero::RSpec.server.load_data({ 'containers' => { name => data } }, current_org)
|
195
|
+
instance_eval(&block) if block_given?
|
195
196
|
end
|
197
|
+
end
|
196
198
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
199
|
+
def cookbook(name, version, data = {}, options = {}, &block)
|
200
|
+
with_object_path("cookbooks/#{name}") do
|
201
|
+
if data.has_key?('metadata.rb')
|
202
|
+
if data['metadata.rb'].nil?
|
203
|
+
data.delete('metadata.rb')
|
204
|
+
end
|
205
|
+
else
|
206
|
+
data['metadata.rb'] = "name #{name.inspect}; version #{version.inspect}"
|
201
207
|
end
|
208
|
+
ChefZero::RSpec.server.load_data({ 'cookbooks' => { "#{name}-#{version}" => data.merge(options) }}, current_org)
|
209
|
+
instance_eval(&block) if block_given?
|
202
210
|
end
|
211
|
+
end
|
203
212
|
|
204
|
-
|
205
|
-
|
213
|
+
def data_bag(name, data, &block)
|
214
|
+
with_object_path("data/#{name}") do
|
215
|
+
ChefZero::RSpec.server.load_data({ 'data' => { name => data }}, current_org)
|
216
|
+
instance_eval(&block) if block_given?
|
206
217
|
end
|
218
|
+
end
|
207
219
|
|
208
|
-
|
209
|
-
|
220
|
+
def environment(name, data, &block)
|
221
|
+
with_object_path("environments/#{name}") do
|
222
|
+
ChefZero::RSpec.server.load_data({ 'environments' => { name => data } }, current_org)
|
223
|
+
instance_eval(&block) if block_given?
|
210
224
|
end
|
225
|
+
end
|
211
226
|
|
212
|
-
|
213
|
-
|
227
|
+
def group(name, data, &block)
|
228
|
+
with_object_path("groups/#{name}") do
|
229
|
+
ChefZero::RSpec.server.load_data({ 'groups' => { name => data } }, current_org)
|
230
|
+
instance_eval(&block) if block_given?
|
214
231
|
end
|
232
|
+
end
|
215
233
|
|
216
|
-
|
217
|
-
|
234
|
+
def node(name, data, &block)
|
235
|
+
with_object_path("nodes/#{name}") do
|
236
|
+
ChefZero::RSpec.server.load_data({ 'nodes' => { name => data } }, current_org)
|
237
|
+
instance_eval(&block) if block_given?
|
218
238
|
end
|
239
|
+
end
|
219
240
|
|
220
|
-
|
221
|
-
|
222
|
-
|
241
|
+
def org_invite(*usernames)
|
242
|
+
ChefZero::RSpec.server.load_data({ 'invites' => usernames }, current_org)
|
243
|
+
end
|
223
244
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
245
|
+
def org_member(*usernames)
|
246
|
+
ChefZero::RSpec.server.load_data({ 'members' => usernames }, current_org)
|
247
|
+
end
|
248
|
+
|
249
|
+
def role(name, data, &block)
|
250
|
+
with_object_path("roles/#{name}") do
|
251
|
+
ChefZero::RSpec.server.load_data({ 'roles' => { name => data } }, current_org)
|
252
|
+
instance_eval(&block) if block_given?
|
229
253
|
end
|
254
|
+
end
|
230
255
|
|
231
|
-
|
232
|
-
|
256
|
+
def sandbox(name, data, &block)
|
257
|
+
with_object_path("sandboxes/#{name}") do
|
258
|
+
ChefZero::RSpec.server.load_data({ 'sandboxes' => { name => data } }, current_org)
|
259
|
+
instance_eval(&block) if block_given?
|
233
260
|
end
|
261
|
+
end
|
234
262
|
|
235
|
-
|
236
|
-
|
237
|
-
|
263
|
+
def user(name, data, &block)
|
264
|
+
if ChefZero::RSpec.server.options[:osc_compat]
|
265
|
+
with_object_path("users/#{name}") do
|
266
|
+
ChefZero::RSpec.server.load_data({ 'users' => { name => data }}, current_org)
|
238
267
|
instance_eval(&block) if block_given?
|
239
268
|
end
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
with_object_path("users/#{name}") do
|
249
|
-
ChefZero::RSpec.server.load_data({ 'users' => { name => data }}, current_org)
|
250
|
-
instance_eval(&block) if block_given?
|
251
|
-
end
|
252
|
-
else
|
253
|
-
old_object_path = @current_object_path
|
254
|
-
@current_object_path = "users/#{name}"
|
255
|
-
begin
|
256
|
-
ChefZero::RSpec.server.load_data({ 'users' => { name => data }}, current_org)
|
257
|
-
instance_eval(&block) if block_given?
|
258
|
-
ensure
|
259
|
-
@current_object_path = old_object_path
|
260
|
-
end
|
269
|
+
else
|
270
|
+
old_object_path = @current_object_path
|
271
|
+
@current_object_path = "users/#{name}"
|
272
|
+
begin
|
273
|
+
ChefZero::RSpec.server.load_data({ 'users' => { name => data }}, current_org)
|
274
|
+
instance_eval(&block) if block_given?
|
275
|
+
ensure
|
276
|
+
@current_object_path = old_object_path
|
261
277
|
end
|
262
278
|
end
|
279
|
+
end
|
263
280
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
end
|
281
|
+
def dejsonize(data)
|
282
|
+
if data.is_a?(String)
|
283
|
+
data
|
284
|
+
else
|
285
|
+
FFI_Yajl::Encoder.encode(data, :pretty => true)
|
270
286
|
end
|
287
|
+
end
|
271
288
|
|
272
|
-
|
273
|
-
|
274
|
-
|
289
|
+
def current_org
|
290
|
+
@current_org || ChefZero::RSpec.server.options[:single_org] || nil
|
291
|
+
end
|
275
292
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
end
|
282
|
-
@current_object_path = old_object_path
|
293
|
+
def with_object_path(object_path)
|
294
|
+
old_object_path = @current_object_path
|
295
|
+
@current_object_path = object_path
|
296
|
+
begin
|
297
|
+
yield if block_given?
|
283
298
|
end
|
284
|
-
|
285
|
-
# after :each do
|
286
|
-
# if @@ChefZero::RSpec.server
|
287
|
-
# @@ChefZero::RSpec.server.stop
|
288
|
-
# @@ChefZero::RSpec.server = nil
|
289
|
-
# end
|
290
|
-
# if @@ChefZero::RSpec.client_key
|
291
|
-
# @@ChefZero::RSpec.client_key.unlink
|
292
|
-
# @@ChefZero::RSpec.client_key = nil
|
293
|
-
# end
|
294
|
-
# end
|
295
|
-
|
296
|
-
instance_eval(&block)
|
299
|
+
@current_object_path = old_object_path
|
297
300
|
end
|
298
301
|
end
|
299
302
|
end
|
data/lib/chef_zero/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-zero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Keiser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-log
|
@@ -56,16 +56,22 @@ dependencies:
|
|
56
56
|
name: ffi-yajl
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '1.1'
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '3.0'
|
62
65
|
type: :runtime
|
63
66
|
prerelease: false
|
64
67
|
version_requirements: !ruby/object:Gem::Requirement
|
65
68
|
requirements:
|
66
|
-
- - "
|
69
|
+
- - ">="
|
67
70
|
- !ruby/object:Gem::Version
|
68
71
|
version: '1.1'
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.0'
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
76
|
name: rack
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -233,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
239
|
version: '0'
|
234
240
|
requirements: []
|
235
241
|
rubyforge_project:
|
236
|
-
rubygems_version: 2.
|
242
|
+
rubygems_version: 2.4.2
|
237
243
|
signing_key:
|
238
244
|
specification_version: 4
|
239
245
|
summary: Self-contained, easy-setup, fast-start in-memory Chef server for testing
|