chef-dk 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +2 -2
- data/README.md +25 -0
- data/lib/chef-dk/builtin_commands.rb +4 -0
- data/lib/chef-dk/cli.rb +46 -0
- data/lib/chef-dk/command/base.rb +4 -0
- data/lib/chef-dk/command/generator_commands/template.rb +2 -1
- data/lib/chef-dk/command/install.rb +105 -0
- data/lib/chef-dk/command/push.rb +123 -0
- data/lib/chef-dk/cookbook_profiler/identifiers.rb +5 -0
- data/lib/chef-dk/exceptions.rb +38 -0
- data/lib/chef-dk/generator.rb +16 -1
- data/lib/chef-dk/helpers.rb +1 -1
- data/lib/chef-dk/policyfile/cookbook_location_specification.rb +4 -0
- data/lib/chef-dk/policyfile/cookbook_locks.rb +73 -0
- data/lib/chef-dk/policyfile/reports/install.rb +70 -0
- data/lib/chef-dk/policyfile/reports/table_printer.rb +58 -0
- data/lib/chef-dk/policyfile/reports/upload.rb +70 -0
- data/lib/chef-dk/policyfile/solution_dependencies.rb +102 -8
- data/lib/chef-dk/policyfile/uploader.rb +37 -6
- data/lib/chef-dk/policyfile_compiler.rb +19 -5
- data/lib/chef-dk/policyfile_lock.rb +122 -9
- data/lib/chef-dk/policyfile_services/install.rb +131 -0
- data/lib/chef-dk/policyfile_services/push.rb +121 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb +6 -4
- data/lib/chef-dk/ui.rb +50 -0
- data/lib/chef-dk/version.rb +1 -1
- data/spec/shared/a_file_generator.rb +4 -1
- data/spec/test_helpers.rb +21 -0
- data/spec/unit/cli_spec.rb +100 -1
- data/spec/unit/command/base_spec.rb +23 -0
- data/spec/unit/command/exec_spec.rb +2 -2
- data/spec/unit/command/install_spec.rb +159 -0
- data/spec/unit/command/push_spec.rb +203 -0
- data/spec/unit/command/shell_init_spec.rb +1 -1
- data/spec/unit/policyfile/cookbook_location_specification_spec.rb +7 -0
- data/spec/unit/policyfile/cookbook_locks_spec.rb +13 -2
- data/spec/unit/policyfile/reports/install_spec.rb +115 -0
- data/spec/unit/policyfile/reports/upload_spec.rb +96 -0
- data/spec/unit/policyfile/solution_dependencies_spec.rb +1 -1
- data/spec/unit/policyfile/uploader_spec.rb +9 -12
- data/spec/unit/policyfile_lock_serialization_spec.rb +292 -0
- data/spec/unit/policyfile_services/install_spec.rb +170 -0
- data/spec/unit/policyfile_services/push_spec.rb +202 -0
- metadata +48 -6
@@ -0,0 +1,202 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2014 Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'spec_helper'
|
19
|
+
require 'chef-dk/policyfile_services/push'
|
20
|
+
|
21
|
+
describe ChefDK::PolicyfileServices::Push do
|
22
|
+
|
23
|
+
let(:working_dir) do
|
24
|
+
path = File.join(tempdir, "policyfile_services_test_working_dir")
|
25
|
+
Dir.mkdir(path)
|
26
|
+
path
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:policyfile_rb_explicit_name) { nil }
|
30
|
+
|
31
|
+
let(:policyfile_rb_name) { policyfile_rb_explicit_name || "Policyfile.rb" }
|
32
|
+
|
33
|
+
let(:policyfile_lock_name) { "Policyfile.lock.json" }
|
34
|
+
|
35
|
+
let(:policyfile_rb_path) { File.join(working_dir, policyfile_rb_name) }
|
36
|
+
|
37
|
+
let(:policyfile_lock_path) { File.join(working_dir, policyfile_lock_name) }
|
38
|
+
|
39
|
+
let(:policy_group) { "staging-cluster-1" }
|
40
|
+
|
41
|
+
let(:local_cookbooks_root) do
|
42
|
+
File.join(fixtures_path, "local_path_cookbooks")
|
43
|
+
end
|
44
|
+
|
45
|
+
let(:config) do
|
46
|
+
double("Chef::Config", chef_server_url: "https://localhost:10443", client_key: "/path/to/client/key.pem", node_name: "deuce")
|
47
|
+
end
|
48
|
+
|
49
|
+
let(:ui) { TestHelpers::TestUI.new }
|
50
|
+
|
51
|
+
let(:push_service) { described_class.new(policyfile: policyfile_rb_name, policy_group: policy_group, ui: ui, config: config, root_dir: working_dir) }
|
52
|
+
|
53
|
+
it "configures an HTTP client" do
|
54
|
+
expect(ChefDK::AuthenticatedHTTP).to receive(:new).with("https://localhost:10443",
|
55
|
+
signing_key_filename: "/path/to/client/key.pem",
|
56
|
+
client_name: "deuce")
|
57
|
+
push_service.http_client
|
58
|
+
end
|
59
|
+
|
60
|
+
it "infers the path to Policyfile.lock.json" do
|
61
|
+
expect(push_service.lockfile_path).to eq(policyfile_lock_path)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "has a storage configuration" do
|
65
|
+
storage_config = push_service.storage_config
|
66
|
+
expect(storage_config.policyfile_lock_filename).to eq(policyfile_lock_path)
|
67
|
+
expect(storage_config.relative_paths_root).to eq(working_dir)
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when given an explicit path to the policyfile" do
|
71
|
+
|
72
|
+
let(:policyfile_rb_name) { "MyPolicy.rb" }
|
73
|
+
|
74
|
+
let(:policyfile_lock_name) { "MyPolicy.lock.json" }
|
75
|
+
|
76
|
+
it "infers the path to the lockfile from the policyfile location" do
|
77
|
+
expect(push_service.lockfile_path).to eq(policyfile_lock_path)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when no lockfile is present" do
|
83
|
+
|
84
|
+
it "errors out" do
|
85
|
+
expect { push_service.run }.to raise_error(ChefDK::LockfileNotFound)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
context "when a lockfile is present" do
|
91
|
+
|
92
|
+
before do
|
93
|
+
File.open(policyfile_lock_path, "w+") { |f| f.print(lockfile_content) }
|
94
|
+
end
|
95
|
+
|
96
|
+
context "and the lockfile has invalid JSON" do
|
97
|
+
|
98
|
+
let(:lockfile_content) { ":::" }
|
99
|
+
|
100
|
+
it "errors out" do
|
101
|
+
expect { push_service.run }.to raise_error(ChefDK::PolicyfilePushError)
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
context "and the lockfile is semantically invalid" do
|
107
|
+
|
108
|
+
let(:lockfile_content) { '{ }' }
|
109
|
+
|
110
|
+
it "errors out" do
|
111
|
+
expect { push_service.run }.to raise_error(ChefDK::PolicyfilePushError)
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
context "and the lockfile is valid" do
|
117
|
+
|
118
|
+
let(:local_cookbook_path) { File.join(fixtures_path, "local_path_cookbooks/local-cookbook") }
|
119
|
+
|
120
|
+
let(:lockfile_content) do
|
121
|
+
<<-E
|
122
|
+
{
|
123
|
+
"name": "install-example",
|
124
|
+
"run_list": [
|
125
|
+
"recipe[local-cookbook::default]"
|
126
|
+
],
|
127
|
+
"cookbook_locks": {
|
128
|
+
"local-cookbook": {
|
129
|
+
"version": "2.3.4",
|
130
|
+
"identifier": "fab501cfaf747901bd82c1bc706beae7dc3a350c",
|
131
|
+
"dotted_decimal_identifier": "70567763561641081.489844270461035.258281553147148",
|
132
|
+
"source": "#{local_cookbook_path}",
|
133
|
+
"cache_key": null,
|
134
|
+
"scm_info": null,
|
135
|
+
"source_options": {
|
136
|
+
"path": "#{local_cookbook_path}"
|
137
|
+
}
|
138
|
+
}
|
139
|
+
},
|
140
|
+
"solution_dependencies": {
|
141
|
+
"Policyfile": [
|
142
|
+
[
|
143
|
+
"local-cookbook",
|
144
|
+
">= 0.0.0"
|
145
|
+
]
|
146
|
+
],
|
147
|
+
"dependencies": {
|
148
|
+
"local-cookbook (2.3.4)": [
|
149
|
+
|
150
|
+
]
|
151
|
+
}
|
152
|
+
}
|
153
|
+
}
|
154
|
+
E
|
155
|
+
end
|
156
|
+
|
157
|
+
let(:http_client) { instance_double(ChefDK::AuthenticatedHTTP) }
|
158
|
+
|
159
|
+
let(:updated_lockfile_io) { StringIO.new }
|
160
|
+
|
161
|
+
let(:uploader) { instance_double(ChefDK::Policyfile::Uploader) }
|
162
|
+
|
163
|
+
before do
|
164
|
+
expect(push_service).to receive(:http_client).and_return(http_client)
|
165
|
+
|
166
|
+
expect(ChefDK::Policyfile::Uploader).to receive(:new).
|
167
|
+
with(push_service.policyfile_lock, policy_group, http_client: http_client, ui: ui).
|
168
|
+
and_return(uploader)
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
it "configures a Policyfile Uploader" do
|
173
|
+
push_service.uploader
|
174
|
+
end
|
175
|
+
|
176
|
+
it "validates the lockfile, writes any updates, and uploads the cookbooks" do
|
177
|
+
allow(File).to receive(:open).and_call_original
|
178
|
+
expect(File).to receive(:open).with(policyfile_lock_path, "w+").and_yield(updated_lockfile_io)
|
179
|
+
expect(uploader).to receive(:upload)
|
180
|
+
|
181
|
+
push_service.run
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "when an error occurs in upload" do
|
185
|
+
|
186
|
+
before do
|
187
|
+
allow(File).to receive(:open).and_call_original
|
188
|
+
expect(File).to receive(:open).with(policyfile_lock_path, "w+").and_yield(updated_lockfile_io)
|
189
|
+
expect(uploader).to receive(:upload).and_raise("an error")
|
190
|
+
end
|
191
|
+
|
192
|
+
it "raises an error" do
|
193
|
+
expect { push_service.run }.to raise_error(ChefDK::PolicyfilePushError)
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-dk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel DeLeo
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-10-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mixlib-cli
|
@@ -28,32 +28,52 @@ dependencies:
|
|
28
28
|
version: '1.5'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: mixlib-shellout
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 2.0.0.rc.0
|
36
|
+
- - "<"
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 3.0.0
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.0.0.rc.0
|
46
|
+
- - "<"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 3.0.0
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: ffi-yajl
|
31
51
|
requirement: !ruby/object:Gem::Requirement
|
32
52
|
requirements:
|
33
53
|
- - "~>"
|
34
54
|
- !ruby/object:Gem::Version
|
35
|
-
version: '1.
|
55
|
+
version: '1.0'
|
36
56
|
type: :runtime
|
37
57
|
prerelease: false
|
38
58
|
version_requirements: !ruby/object:Gem::Requirement
|
39
59
|
requirements:
|
40
60
|
- - "~>"
|
41
61
|
- !ruby/object:Gem::Version
|
42
|
-
version: '1.
|
62
|
+
version: '1.0'
|
43
63
|
- !ruby/object:Gem::Dependency
|
44
64
|
name: chef
|
45
65
|
requirement: !ruby/object:Gem::Requirement
|
46
66
|
requirements:
|
47
67
|
- - "~>"
|
48
68
|
- !ruby/object:Gem::Version
|
49
|
-
version: 12.0.0.alpha.
|
69
|
+
version: 12.0.0.alpha.2
|
50
70
|
type: :runtime
|
51
71
|
prerelease: false
|
52
72
|
version_requirements: !ruby/object:Gem::Requirement
|
53
73
|
requirements:
|
54
74
|
- - "~>"
|
55
75
|
- !ruby/object:Gem::Version
|
56
|
-
version: 12.0.0.alpha.
|
76
|
+
version: 12.0.0.alpha.2
|
57
77
|
- !ruby/object:Gem::Dependency
|
58
78
|
name: solve
|
59
79
|
requirement: !ruby/object:Gem::Requirement
|
@@ -159,6 +179,8 @@ files:
|
|
159
179
|
- lib/chef-dk/command/generator_commands/recipe.rb
|
160
180
|
- lib/chef-dk/command/generator_commands/repo.rb
|
161
181
|
- lib/chef-dk/command/generator_commands/template.rb
|
182
|
+
- lib/chef-dk/command/install.rb
|
183
|
+
- lib/chef-dk/command/push.rb
|
162
184
|
- lib/chef-dk/command/shell_init.rb
|
163
185
|
- lib/chef-dk/command/verify.rb
|
164
186
|
- lib/chef-dk/commands_map.rb
|
@@ -179,11 +201,16 @@ files:
|
|
179
201
|
- lib/chef-dk/policyfile/dsl.rb
|
180
202
|
- lib/chef-dk/policyfile/null_cookbook_source.rb
|
181
203
|
- lib/chef-dk/policyfile/read_cookbook_for_compat_mode_upload.rb
|
204
|
+
- lib/chef-dk/policyfile/reports/install.rb
|
205
|
+
- lib/chef-dk/policyfile/reports/table_printer.rb
|
206
|
+
- lib/chef-dk/policyfile/reports/upload.rb
|
182
207
|
- lib/chef-dk/policyfile/solution_dependencies.rb
|
183
208
|
- lib/chef-dk/policyfile/storage_config.rb
|
184
209
|
- lib/chef-dk/policyfile/uploader.rb
|
185
210
|
- lib/chef-dk/policyfile_compiler.rb
|
186
211
|
- lib/chef-dk/policyfile_lock.rb
|
212
|
+
- lib/chef-dk/policyfile_services/install.rb
|
213
|
+
- lib/chef-dk/policyfile_services/push.rb
|
187
214
|
- lib/chef-dk/shell_out.rb
|
188
215
|
- lib/chef-dk/skeletons/code_generator/files/default/Berksfile
|
189
216
|
- lib/chef-dk/skeletons/code_generator/files/default/chefignore
|
@@ -224,6 +251,7 @@ files:
|
|
224
251
|
- lib/chef-dk/skeletons/code_generator/templates/default/repo/gitignore.erb
|
225
252
|
- lib/chef-dk/skeletons/code_generator/templates/default/resource.rb.erb
|
226
253
|
- lib/chef-dk/skeletons/code_generator/templates/default/template.erb
|
254
|
+
- lib/chef-dk/ui.rb
|
227
255
|
- lib/chef-dk/version.rb
|
228
256
|
- spec/shared/a_file_generator.rb
|
229
257
|
- spec/shared/a_generated_file.rb
|
@@ -244,6 +272,8 @@ files:
|
|
244
272
|
- spec/unit/command/generator_commands/recipe_spec.rb
|
245
273
|
- spec/unit/command/generator_commands/repo_spec.rb
|
246
274
|
- spec/unit/command/generator_commands/template_spec.rb
|
275
|
+
- spec/unit/command/install_spec.rb
|
276
|
+
- spec/unit/command/push_spec.rb
|
247
277
|
- spec/unit/command/shell_init_spec.rb
|
248
278
|
- spec/unit/command/verify_spec.rb
|
249
279
|
- spec/unit/commands_map_spec.rb
|
@@ -323,6 +353,8 @@ files:
|
|
323
353
|
- spec/unit/policyfile/cookbook_locks_spec.rb
|
324
354
|
- spec/unit/policyfile/null_cookbook_source_spec.rb
|
325
355
|
- spec/unit/policyfile/read_cookbook_for_compat_mode_upload_spec.rb
|
356
|
+
- spec/unit/policyfile/reports/install_spec.rb
|
357
|
+
- spec/unit/policyfile/reports/upload_spec.rb
|
326
358
|
- spec/unit/policyfile/solution_dependencies_spec.rb
|
327
359
|
- spec/unit/policyfile/storage_config_spec.rb
|
328
360
|
- spec/unit/policyfile/uploader_spec.rb
|
@@ -330,7 +362,10 @@ files:
|
|
330
362
|
- spec/unit/policyfile_evaluation_spec.rb
|
331
363
|
- spec/unit/policyfile_lock_build_spec.rb
|
332
364
|
- spec/unit/policyfile_lock_install_spec.rb
|
365
|
+
- spec/unit/policyfile_lock_serialization_spec.rb
|
333
366
|
- spec/unit/policyfile_lock_validation_spec.rb
|
367
|
+
- spec/unit/policyfile_services/install_spec.rb
|
368
|
+
- spec/unit/policyfile_services/push_spec.rb
|
334
369
|
- spec/unit/shell_out_spec.rb
|
335
370
|
homepage: http://www.getchef.com/
|
336
371
|
licenses: []
|
@@ -375,6 +410,8 @@ test_files:
|
|
375
410
|
- spec/unit/command/generator_commands/recipe_spec.rb
|
376
411
|
- spec/unit/command/generator_commands/repo_spec.rb
|
377
412
|
- spec/unit/command/generator_commands/template_spec.rb
|
413
|
+
- spec/unit/command/install_spec.rb
|
414
|
+
- spec/unit/command/push_spec.rb
|
378
415
|
- spec/unit/command/shell_init_spec.rb
|
379
416
|
- spec/unit/command/verify_spec.rb
|
380
417
|
- spec/unit/commands_map_spec.rb
|
@@ -454,6 +491,8 @@ test_files:
|
|
454
491
|
- spec/unit/policyfile/cookbook_locks_spec.rb
|
455
492
|
- spec/unit/policyfile/null_cookbook_source_spec.rb
|
456
493
|
- spec/unit/policyfile/read_cookbook_for_compat_mode_upload_spec.rb
|
494
|
+
- spec/unit/policyfile/reports/install_spec.rb
|
495
|
+
- spec/unit/policyfile/reports/upload_spec.rb
|
457
496
|
- spec/unit/policyfile/solution_dependencies_spec.rb
|
458
497
|
- spec/unit/policyfile/storage_config_spec.rb
|
459
498
|
- spec/unit/policyfile/uploader_spec.rb
|
@@ -461,6 +500,9 @@ test_files:
|
|
461
500
|
- spec/unit/policyfile_evaluation_spec.rb
|
462
501
|
- spec/unit/policyfile_lock_build_spec.rb
|
463
502
|
- spec/unit/policyfile_lock_install_spec.rb
|
503
|
+
- spec/unit/policyfile_lock_serialization_spec.rb
|
464
504
|
- spec/unit/policyfile_lock_validation_spec.rb
|
505
|
+
- spec/unit/policyfile_services/install_spec.rb
|
506
|
+
- spec/unit/policyfile_services/push_spec.rb
|
465
507
|
- spec/unit/shell_out_spec.rb
|
466
508
|
has_rdoc:
|