chef-apply 0.4.6 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -7
  3. data/chef-apply.gemspec +3 -3
  4. data/lib/chef_apply/version.rb +1 -1
  5. metadata +3 -38
  6. data/README.md +0 -62
  7. data/spec/fixtures/custom_config.toml +0 -2
  8. data/spec/integration/chef-run_spec.rb +0 -41
  9. data/spec/integration/fixtures/chef_help.out +0 -70
  10. data/spec/integration/fixtures/chef_version.out +0 -1
  11. data/spec/integration/spec_helper.rb +0 -55
  12. data/spec/spec_helper.rb +0 -154
  13. data/spec/support/matchers/output_to_terminal.rb +0 -36
  14. data/spec/unit/action/base_spec.rb +0 -60
  15. data/spec/unit/action/converge_target/ccr_failure_mapper_spec.rb +0 -106
  16. data/spec/unit/action/converge_target_spec.rb +0 -400
  17. data/spec/unit/action/generate_local_policy_spec.rb +0 -114
  18. data/spec/unit/action/generate_temp_cookbook/recipe_lookup_spec.rb +0 -122
  19. data/spec/unit/action/generate_temp_cookbook/temp_cookbook_spec.rb +0 -198
  20. data/spec/unit/action/generate_temp_cookbook_spec.rb +0 -73
  21. data/spec/unit/action/install_chef/minimum_chef_version_spec.rb +0 -90
  22. data/spec/unit/action/install_chef_spec.rb +0 -164
  23. data/spec/unit/cli/options_spec.rb +0 -75
  24. data/spec/unit/cli/validation_spec.rb +0 -81
  25. data/spec/unit/cli_spec.rb +0 -475
  26. data/spec/unit/config_spec.rb +0 -70
  27. data/spec/unit/file_fetcher_spec.rb +0 -40
  28. data/spec/unit/fixtures/multi-error.out +0 -2
  29. data/spec/unit/log_spec.rb +0 -37
  30. data/spec/unit/startup_spec.rb +0 -323
  31. data/spec/unit/target_host/linux_spec.rb +0 -57
  32. data/spec/unit/target_host/windows_spec.rb +0 -43
  33. data/spec/unit/target_host_spec.rb +0 -297
  34. data/spec/unit/target_resolver_spec.rb +0 -380
  35. data/spec/unit/telemeter/sender_spec.rb +0 -140
  36. data/spec/unit/telemeter_spec.rb +0 -191
  37. data/spec/unit/text/error_translation_spec.rb +0 -109
  38. data/spec/unit/ui/error_printer_spec.rb +0 -196
  39. data/spec/unit/ui/terminal_spec.rb +0 -119
  40. data/spec/unit/version_spec.rb +0 -31
@@ -1,114 +0,0 @@
1
- #
2
- # Copyright:: Copyright (c) 2017 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
- require "spec_helper"
18
- require "chef_apply/action/generate_local_policy"
19
- require "chef-cli/policyfile_services/install"
20
- require "chef-cli/ui"
21
- require "chef-cli/policyfile_services/export_repo"
22
-
23
- RSpec.describe ChefApply::Action::GenerateLocalPolicy do
24
- subject { ChefApply::Action::GenerateLocalPolicy.new(cookbook: cookbook) }
25
- let(:cookbook) do
26
- double("TempCookbook",
27
- path: "/my/temp/cookbook",
28
- export_path: "/my/temp/cookbook/export",
29
- policyfile_lock_path: "/my/temp/cookbook/policyfile.lock")
30
- end
31
-
32
- let(:installer_double) do
33
- instance_double(ChefCLI::PolicyfileServices::Install, run: :ok)
34
- end
35
-
36
- let(:exporter_double) do
37
- instance_double(ChefCLI::PolicyfileServices::ExportRepo,
38
- archive_file_location: "/path/to/export",
39
- run: :ok)
40
- end
41
-
42
- before do
43
- allow(subject).to receive(:notify)
44
- end
45
-
46
- describe "#perform_action" do
47
- context "in the normal case" do
48
- it "exports the policy notifying caller of progress, setting archive_file_location" do
49
- expect(subject).to receive(:notify).ordered.with(:generating)
50
- expect(subject).to receive(:installer).ordered.and_return installer_double
51
- expect(installer_double).to receive(:run).ordered
52
- expect(subject).to receive(:notify).ordered.with(:exporting)
53
- expect(subject).to receive(:exporter).ordered.and_return exporter_double
54
- expect(exporter_double).to receive(:run).ordered
55
- expect(subject).to receive(:exporter).ordered.and_return exporter_double
56
- expect(subject).to receive(:notify).ordered.with(:success)
57
- subject.perform_action
58
- expect(subject.archive_file_location).to eq("/path/to/export")
59
- end
60
- end
61
-
62
- context "when PolicyfileServices raises an error" do
63
- it "reraises as PolicyfileInstallError" do
64
- expect(subject).to receive(:installer).and_return installer_double
65
- expect(installer_double).to receive(:run).and_raise(ChefCLI::PolicyfileInstallError.new("", nil))
66
- expect { subject.perform_action }.to raise_error(ChefApply::Action::PolicyfileInstallError)
67
- end
68
- end
69
-
70
- context "when the path name is too long" do
71
- let(:name) { "THIS_IS_A_REALLY_LONG_STRING111111111111111111111111111111111111111111111111111111" }
72
-
73
- # There is an issue with policyfile generation where, if we have a cookbook with too long
74
- # of a name or directory name the policyfile will not generate. This is because the tar
75
- # library that ChefCLI uses comes from the Rubygems package and is meant for packaging
76
- # gems up, so it can impose a 100 character limit. We attempt to solve this by ensuring
77
- # that the paths/names we generate with `TempCookbook` are short.
78
- #
79
- # This is here for documentation
80
- # 2018-05-18 mp addendum: this cna take upwards of 15s to run on ci nodes, pending
81
- # for now since it's not testing any Chef Apply functionality.
82
- xit "fails to create when there is a long path name" do
83
- err = ChefCLI::PolicyfileExportRepoError
84
- expect { subject.perform_action }.to raise_error(err) do |e|
85
- expect(e.cause.class).to eq(Gem::Package::TooLongFileName)
86
- expect(e.cause.message).to match(/should be 100 or less/)
87
- end
88
- end
89
- end
90
- end
91
-
92
- describe "#exporter" do
93
-
94
- it "returns a correctly constructed ExportRepo" do
95
- expect(ChefCLI::PolicyfileServices::ExportRepo).to receive(:new)
96
- .with(policyfile: cookbook.policyfile_lock_path,
97
- root_dir: cookbook.path,
98
- export_dir: cookbook.export_path,
99
- archive: true, force: true)
100
- .and_return exporter_double
101
- expect(subject.exporter).to eq exporter_double
102
- end
103
- end
104
-
105
- describe "#installer" do
106
- it "returns a correctly constructed Install service" do
107
- expect(ChefCLI::PolicyfileServices::Install).to receive(:new)
108
- .with(ui: ChefCLI::UI, root_dir: cookbook.path)
109
- .and_return(installer_double)
110
- expect(subject.installer).to eq installer_double
111
- end
112
- end
113
-
114
- end
@@ -1,122 +0,0 @@
1
- #
2
- # Copyright:: Copyright (c) 2018 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_apply/action/generate_temp_cookbook/recipe_lookup"
20
- require "chef/exceptions"
21
- require "chef/cookbook/cookbook_version_loader"
22
- require "chef/cookbook_version"
23
- require "chef/cookbook_loader"
24
-
25
- RSpec.describe ChefApply::Action::GenerateTempCookbook::RecipeLookup do
26
- let(:repo_path) { "repo_path" }
27
- subject(:rp) { ChefApply::Action::GenerateTempCookbook::RecipeLookup.new([repo_path]) }
28
- VL = Chef::Cookbook::CookbookVersionLoader
29
- let(:version_loader) { instance_double(VL) }
30
- let(:cookbook_version) { instance_double(Chef::CookbookVersion, root_dir: "dir", name: "name") }
31
- let(:cookbook_loader) { instance_double(Chef::CookbookLoader, load_cookbooks: nil) }
32
-
33
- describe "#split" do
34
- it "splits a customer provided specifier into a cookbook part and possible recipe part" do
35
- expect(rp.split("/some/path")).to eq(%w{/some/path})
36
- expect(rp.split("cookbook::recipe")).to eq(%w{cookbook recipe})
37
- end
38
- end
39
-
40
- describe "#load_cookbook" do
41
- context "when a directory is provided" do
42
- let(:recipe_specifier) { "/some/directory" }
43
- let(:default_recipe) { File.join(recipe_specifier, "default.rb") }
44
- let(:recipes_by_name) { { "default" => default_recipe } }
45
- before do
46
- expect(File).to receive(:directory?).with(recipe_specifier).and_return(true)
47
- expect(VL).to receive(:new).with(recipe_specifier).and_return(version_loader)
48
- end
49
-
50
- it "loads the cookbook and returns the path to the default recipe" do
51
- expect(version_loader).to receive(:load!)
52
- expect(version_loader).to receive(:cookbook_version).and_return(cookbook_version)
53
- expect(rp.load_cookbook(recipe_specifier)).to eq(cookbook_version)
54
- end
55
-
56
- context "the directory is not a cookbook" do
57
- it "raise an InvalidCookbook error" do
58
- expect(version_loader).to receive(:load!).and_raise(Chef::Exceptions::CookbookNotFoundInRepo.new)
59
- expect { rp.load_cookbook(recipe_specifier) }.to raise_error(ChefApply::Action::GenerateTempCookbook::RecipeLookup::InvalidCookbook)
60
- end
61
- end
62
- end
63
-
64
- context "when a cookbook name is provided" do
65
- let(:recipe_specifier) { "cb" }
66
- before do
67
- expect(File).to receive(:directory?).with(recipe_specifier).and_return(false)
68
- expect(Chef::CookbookLoader).to receive(:new).and_return(cookbook_loader)
69
- end
70
-
71
- context "and a cookbook in the cookbook repository exists with that name" do
72
- it "returns the default cookbook" do
73
- expect(cookbook_loader).to receive(:[]).with(recipe_specifier).and_return(cookbook_version)
74
- expect(rp.load_cookbook(recipe_specifier)).to eq(cookbook_version)
75
- end
76
- end
77
-
78
- context "and a cookbook exists but it is invalid" do
79
- it "raises an InvalidCookbook error" do
80
- expect(cookbook_loader).to receive(:[]).with(recipe_specifier).and_raise(Chef::Exceptions::CookbookNotFoundInRepo.new)
81
- expect(File).to receive(:directory?).with(File.join(repo_path, recipe_specifier)).and_return(true)
82
- expect { rp.load_cookbook(recipe_specifier) }.to raise_error(ChefApply::Action::GenerateTempCookbook::RecipeLookup::InvalidCookbook)
83
- end
84
- end
85
-
86
- context "and a cookbook does not exist" do
87
- it "raises an CookbookNotFound error" do
88
- expect(cookbook_loader).to receive(:[]).with(recipe_specifier).and_raise(Chef::Exceptions::CookbookNotFoundInRepo.new)
89
- expect(File).to receive(:directory?).with(File.join(repo_path, recipe_specifier)).and_return(false)
90
- expect { rp.load_cookbook(recipe_specifier) }.to raise_error(ChefApply::Action::GenerateTempCookbook::RecipeLookup::CookbookNotFound)
91
- end
92
- end
93
- end
94
- end
95
-
96
- describe "#find_recipe" do
97
- let(:recipe) { double("recipe") }
98
-
99
- context "no recipe is specified" do
100
- it "finds a default recipe" do
101
- expect(cookbook_version).to receive(:recipe_filenames_by_name).and_return({ "default" => recipe })
102
- expect(rp.find_recipe(cookbook_version)).to eq(recipe)
103
- end
104
- it "when there is no default recipe it raises a NoDefaultRecipe error" do
105
- expect(cookbook_version).to receive(:recipe_filenames_by_name).and_return({})
106
- expect { rp.find_recipe(cookbook_version) }.to raise_error(ChefApply::Action::GenerateTempCookbook::RecipeLookup::NoDefaultRecipe)
107
- end
108
- end
109
-
110
- context "a recipe is specified" do
111
- let(:desired_recipe) { "a_recipe" }
112
- it "finds the specified recipe" do
113
- expect(cookbook_version).to receive(:recipe_filenames_by_name).and_return({ desired_recipe => recipe })
114
- expect(rp.find_recipe(cookbook_version, desired_recipe)).to eq(recipe)
115
- end
116
- it "when there is no recipe with that name it raises a RecipeNotFound error" do
117
- expect(cookbook_version).to receive(:recipe_filenames_by_name).and_return({})
118
- expect { rp.find_recipe(cookbook_version, desired_recipe) }.to raise_error(ChefApply::Action::GenerateTempCookbook::RecipeLookup::RecipeNotFound)
119
- end
120
- end
121
- end
122
- end
@@ -1,198 +0,0 @@
1
- #
2
- # Copyright:: Copyright (c) 2018 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 "tempfile"
20
- require "securerandom"
21
- require "chef_apply/action/generate_temp_cookbook/temp_cookbook"
22
- RSpec.describe "ChefApply::Action::GenerateTempCookbook::TempCookbook" do
23
- subject(:tc) { ChefApply::Action::GenerateTempCookbook::TempCookbook.new }
24
- let(:uuid) { SecureRandom.uuid }
25
-
26
- before do
27
- @repo_paths = ChefApply::Config.chef.cookbook_repo_paths
28
- ChefApply::Config.chef.cookbook_repo_paths = []
29
- end
30
-
31
- after do
32
- ChefApply::Config.chef.cookbook_repo_paths = @repo_paths
33
- subject.delete
34
- end
35
-
36
- describe "#from_existing_recipe" do
37
- it "raises an error if the recipe does not have a .rb extension" do
38
- err = ChefApply::Action::GenerateTempCookbook::TempCookbook::UnsupportedExtension
39
- expect { subject.from_existing_recipe("/some/file.chef") }.to raise_error(err)
40
- end
41
-
42
- context "when there is an existing cookbook" do
43
- let(:cb) do
44
- d = Dir.mktmpdir
45
- File.open(File.join(d, "metadata.rb"), "w+") do |f|
46
- f << "name \"foo\""
47
- end
48
- FileUtils.mkdir(File.join(d, "recipes"))
49
- d
50
- end
51
-
52
- let(:existing_recipe) do
53
- File.open(File.join(cb, "recipes/default.rb"), "w+") do |f|
54
- f.write(uuid)
55
- f
56
- end
57
- end
58
-
59
- after do
60
- FileUtils.remove_entry cb
61
- end
62
-
63
- it "copies the whole cookbook" do
64
- subject.from_existing_recipe(existing_recipe.path)
65
- expect(File.read(File.join(subject.path, "recipes/default.rb"))).to eq(uuid)
66
- expect(File.read(File.join(subject.path, "Policyfile.rb"))).to eq <<~EXPECTED_POLICYFILE
67
- name "foo_policy"
68
- default_source :supermarket
69
- run_list "foo::default"
70
- cookbook "foo", path: "."
71
- EXPECTED_POLICYFILE
72
- expect(File.read(File.join(subject.path, "metadata.rb"))).to eq("name \"foo\"")
73
- end
74
- end
75
-
76
- context "when there is only a single recipe not in a cookbook" do
77
- let(:existing_recipe) do
78
- t = Tempfile.new(["recipe", ".rb"])
79
- t.write(uuid)
80
- t.close
81
- t
82
- end
83
-
84
- after do
85
- existing_recipe.unlink
86
- end
87
-
88
- it "copies the existing recipe into a new cookbook" do
89
- subject.from_existing_recipe(existing_recipe.path)
90
- recipe_filename = File.basename(existing_recipe.path)
91
- recipe_name = File.basename(recipe_filename, File.extname(recipe_filename))
92
- expect(File.read(File.join(subject.path, "recipes/", recipe_filename))).to eq(uuid)
93
- expect(File.read(File.join(subject.path, "Policyfile.rb"))).to eq <<~EXPECTED_POLICYFILE
94
- name "cw_recipe_policy"
95
- default_source :supermarket
96
- run_list "cw_recipe::#{recipe_name}"
97
- cookbook "cw_recipe", path: "."
98
- EXPECTED_POLICYFILE
99
- expect(File.read(File.join(subject.path, "metadata.rb"))).to eq("name \"cw_recipe\"\n")
100
- end
101
- end
102
- end
103
-
104
- describe "#from_resource" do
105
- it "creates a recipe containing the supplied recipe" do
106
- subject.from_resource("directory", "/tmp/foo", [])
107
- expect(File.read(File.join(subject.path, "recipes/default.rb"))).to eq("directory '/tmp/foo'\n")
108
- end
109
- end
110
-
111
- describe "#generate_metadata" do
112
- it "generates metadata in the temp cookbook" do
113
- f = subject.generate_metadata("foo")
114
- expect(File.read(f)).to eq("name \"foo\"\n")
115
- end
116
- end
117
-
118
- describe "#generate_policyfile" do
119
- context "when there is no existing policyfile" do
120
- it "generates a policyfile in the temp cookbook" do
121
- f = subject.generate_policyfile("foo", "bar")
122
- expect(File.read(f)).to eq <<~EXPECTED_POLICYFILE
123
- name "foo_policy"
124
- default_source :supermarket
125
- run_list "foo::bar"
126
- cookbook "foo", path: "."
127
- EXPECTED_POLICYFILE
128
- end
129
-
130
- context "when there are configured cookbook_repo_paths" do
131
- it "generates a policyfile in the temp cookbook" do
132
- ChefApply::Config.chef.cookbook_repo_paths = %w{one two}
133
- f = subject.generate_policyfile("foo", "bar")
134
- expect(File.read(f)).to eq <<~EXPECTED_POLICYFILE
135
- name "foo_policy"
136
- default_source :chef_repo, "one"
137
- default_source :chef_repo, "two"
138
- default_source :supermarket
139
- run_list "foo::bar"
140
- cookbook "foo", path: "."
141
- EXPECTED_POLICYFILE
142
- end
143
- end
144
- end
145
-
146
- context "when there is an existing policyfile" do
147
- before do
148
- File.open(File.join(subject.path, "Policyfile.rb"), "a") do |f|
149
- f << "this is a policyfile"
150
- end
151
- end
152
- it "only overrides the existing run_list in the policyfile" do
153
- f = subject.generate_policyfile("foo", "bar")
154
- expect(File.read(f)).to eq <<~EXPECTED_POLICYFILE
155
- this is a policyfile
156
- # Overriding run_list with command line specified value
157
- run_list "foo::bar"
158
- EXPECTED_POLICYFILE
159
- end
160
- end
161
- end
162
-
163
- describe "#create_resource_definition" do
164
- let(:r1) { "directory" }
165
- let(:r2) { "/tmp" }
166
- let(:props) { nil }
167
- context "when no properties are provided" do
168
- it "it creates a simple resource" do
169
- expect(subject.create_resource_definition(r1, r2, [])).to eq("directory '/tmp'\n")
170
- end
171
- end
172
-
173
- context "when properties are provided" do
174
- let(:props) do
175
- {
176
- "key1" => "value",
177
- "key2" => 0.1,
178
- "key3" => 100,
179
- "key4" => true,
180
- "key_with_underscore" => "value",
181
- }
182
- end
183
-
184
- it "converts the properties to chef-client args" do
185
- expected = <<~EXPECTED_RESOURCE
186
- directory '/tmp' do
187
- key1 'value'
188
- key2 0.1
189
- key3 100
190
- key4 true
191
- key_with_underscore 'value'
192
- end
193
- EXPECTED_RESOURCE
194
- expect(subject.create_resource_definition(r1, r2, props)).to eq(expected)
195
- end
196
- end
197
- end
198
- end
@@ -1,73 +0,0 @@
1
- #
2
- # Copyright:: Copyright (c) 2018 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 "chef_apply/action/generate_temp_cookbook"
19
-
20
- RSpec.describe ChefApply::Action::GenerateTempCookbook do
21
- let(:options) { {} }
22
- subject { ChefApply::Action::GenerateTempCookbook }
23
-
24
- describe ".from_options" do
25
- context "when given options for a recipe" do
26
- let(:options) { { recipe_spec: "some::recipe" } }
27
- it "returns a GenerateCookbookFromRecipe action" do
28
- expect(subject.from_options(options)).to be_a(ChefApply::Action::GenerateCookbookFromRecipe)
29
- end
30
- end
31
-
32
- context "when given options for a resource" do
33
- let(:resource_properties) { {} }
34
- let(:options) do
35
- { resource_name: "user1", resource_type: "user",
36
- resource_properties: resource_properties }
37
- end
38
-
39
- it "returns a GenerateCookbookFromResource action" do
40
- expect(subject.from_options(options)).to be_a ChefApply::Action::GenerateCookbookFromResource
41
- end
42
- end
43
-
44
- context "when not given sufficient options for either" do
45
- let(:options) { {} }
46
- it "raises MissingOptions" do
47
- expect { subject.from_options(options) }.to raise_error ChefApply::Action::MissingOptions
48
- end
49
- end
50
-
51
- end
52
-
53
- describe "#perform_action" do
54
- subject { ChefApply::Action::GenerateTempCookbook.new( {} ) }
55
- it "generates a cookbook, notifies caller, and makes the cookbook available" do
56
- expect(subject).to receive(:notify).ordered.with(:generating)
57
- expect(subject).to receive(:generate)
58
- expect(subject).to receive(:notify).ordered.with(:success)
59
- subject.perform_action
60
- expect(subject.generated_cookbook).to_not be nil
61
- end
62
-
63
- end
64
-
65
- end
66
-
67
- RSpec.describe ChefApply::Action::GenerateCookbookFromRecipe do
68
- xit "#generate", "Please implement me"
69
- end
70
-
71
- RSpec.describe ChefApply::Action::GenerateCookbookFromResource do
72
- xit "#generate", "Please implement me"
73
- end