chef-apply 0.2.8 → 0.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,7 +24,7 @@ require "chef_apply/target_host"
24
24
  RSpec.describe ChefApply::UI::ErrorPrinter do
25
25
 
26
26
  let(:orig_exception) { StandardError.new("test") }
27
- let(:target_host) { ChefApply::TargetHost.instance_for_url("mock://localhost") }
27
+ let(:target_host) { ChefApply::TargetHost.mock_instance("mock://localhost") }
28
28
  let(:wrapped_exception) { ChefApply::WrappedError.new(orig_exception, target_host) }
29
29
 
30
30
  let(:show_footer) { true }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-apply
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Software, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-29 00:00:00.000000000 Z
11
+ date: 2019-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-cli
@@ -178,6 +178,26 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: license-acceptance
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '1.0'
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: 1.0.11
191
+ type: :runtime
192
+ prerelease: false
193
+ version_requirements: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - "~>"
196
+ - !ruby/object:Gem::Version
197
+ version: '1.0'
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: 1.0.11
181
201
  - !ruby/object:Gem::Dependency
182
202
  name: bundler
183
203
  requirement: !ruby/object:Gem::Requirement
@@ -327,9 +347,6 @@ files:
327
347
  - lib/chef_apply/action/generate_local_policy.rb
328
348
  - lib/chef_apply/action/generate_temp_cookbook.rb
329
349
  - lib/chef_apply/action/install_chef.rb
330
- - lib/chef_apply/action/install_chef/base.rb
331
- - lib/chef_apply/action/install_chef/linux.rb
332
- - lib/chef_apply/action/install_chef/windows.rb
333
350
  - lib/chef_apply/action/reporter.rb
334
351
  - lib/chef_apply/cli.rb
335
352
  - lib/chef_apply/cli/help.rb
@@ -346,6 +363,8 @@ files:
346
363
  - lib/chef_apply/startup.rb
347
364
  - lib/chef_apply/status_reporter.rb
348
365
  - lib/chef_apply/target_host.rb
366
+ - lib/chef_apply/target_host/linux.rb
367
+ - lib/chef_apply/target_host/windows.rb
349
368
  - lib/chef_apply/target_resolver.rb
350
369
  - lib/chef_apply/telemeter.rb
351
370
  - lib/chef_apply/telemeter/patch.rb
@@ -371,7 +390,6 @@ files:
371
390
  - spec/unit/action/converge_target_spec.rb
372
391
  - spec/unit/action/generate_local_policy_spec.rb
373
392
  - spec/unit/action/generate_temp_cookbook_spec.rb
374
- - spec/unit/action/install_chef/base_spec.rb
375
393
  - spec/unit/action/install_chef_spec.rb
376
394
  - spec/unit/cli/options_spec.rb
377
395
  - spec/unit/cli/validation_spec.rb
@@ -384,6 +402,8 @@ files:
384
402
  - spec/unit/minimum_chef_version_spec.rb
385
403
  - spec/unit/recipe_lookup_spec.rb
386
404
  - spec/unit/startup_spec.rb
405
+ - spec/unit/target_host/linux_spec.rb
406
+ - spec/unit/target_host/windows_spec.rb
387
407
  - spec/unit/target_host_spec.rb
388
408
  - spec/unit/target_resolver_spec.rb
389
409
  - spec/unit/telemeter/sender_spec.rb
@@ -416,8 +436,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
416
436
  - !ruby/object:Gem::Version
417
437
  version: '0'
418
438
  requirements: []
419
- rubyforge_project:
420
- rubygems_version: 2.7.6
439
+ rubygems_version: 3.0.3
421
440
  signing_key:
422
441
  specification_version: 4
423
442
  summary: The ad-hoc execution tool for the Chef ecosystem.
@@ -1,117 +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
-
18
- require "chef_apply/action/base"
19
- require "chef_apply/minimum_chef_version"
20
- require "fileutils"
21
-
22
- module ChefApply::Action::InstallChef
23
- class Base < ChefApply::Action::Base
24
-
25
- def perform_action
26
- if ChefApply::MinimumChefVersion.check!(target_host, config[:check_only]) == :minimum_version_met
27
- notify(:already_installed)
28
- else
29
- perform_local_install
30
- end
31
- end
32
-
33
- def name
34
- # We have subclasses - so this'll take the qualified name
35
- # eg InstallChef::Windows, etc
36
- self.class.name.split("::")[-2..-1].join("::")
37
- end
38
-
39
- def upgrading?
40
- @upgrading
41
- end
42
-
43
- def perform_local_install
44
- package = lookup_artifact()
45
- notify(:downloading)
46
- local_path = download_to_workstation(package.url)
47
- notify(:uploading)
48
- remote_path = upload_to_target(local_path)
49
- notify(:installing)
50
- install_chef_to_target(remote_path)
51
- notify(:install_complete)
52
- end
53
-
54
- def perform_remote_install
55
- raise NotImplementedError
56
- end
57
-
58
- def lookup_artifact
59
- return @artifact_info if @artifact_info
60
- require "mixlib/install"
61
- c = train_to_mixlib(target_host.platform)
62
- Mixlib::Install.new(c).artifact_info
63
- end
64
-
65
- def version_to_install
66
- lookup_artifact.version
67
- end
68
-
69
- def train_to_mixlib(platform)
70
- opts = {
71
- platform_version: platform.release,
72
- platform: platform.name,
73
- architecture: platform.arch,
74
- product_name: "chef",
75
- product_version: :latest,
76
- channel: :stable,
77
- platform_version_compatibility_mode: true,
78
- }
79
- case platform.name
80
- when /windows/
81
- opts[:platform] = "windows"
82
- when "redhat", "centos"
83
- opts[:platform] = "el"
84
- when "suse"
85
- opts[:platform] = "sles"
86
- when "amazon"
87
- opts[:platform] = "el"
88
- if platform.release.to_i > 2010 # legacy Amazon version 1
89
- opts[:platform_version] = "6"
90
- else
91
- opts[:platform_version] = "7"
92
- end
93
- end
94
- opts
95
- end
96
-
97
- def download_to_workstation(url_path)
98
- require "chef_apply/file_fetcher"
99
- ChefApply::FileFetcher.fetch(url_path)
100
- end
101
-
102
- def upload_to_target(local_path)
103
- installer_dir = setup_remote_temp_path()
104
- remote_path = File.join(installer_dir, File.basename(local_path))
105
- target_host.upload_file(local_path, remote_path)
106
- remote_path
107
- end
108
-
109
- def setup_remote_temp_path
110
- raise NotImplementedError
111
- end
112
-
113
- def install_chef_to_target(remote_path)
114
- raise NotImplementedError
115
- end
116
- end
117
- end
@@ -1,37 +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
-
18
- module ChefApply::Action::InstallChef
19
- class Linux < ChefApply::Action::InstallChef::Base
20
- def install_chef_to_target(remote_path)
21
- install_cmd = case File.extname(remote_path)
22
- when ".rpm"
23
- "rpm -Uvh #{remote_path}"
24
- when ".deb"
25
- "dpkg -i #{remote_path}"
26
- end
27
- target_host.run_command!(install_cmd)
28
- nil
29
- end
30
-
31
- def setup_remote_temp_path
32
- installer_dir = "/tmp/chef-installer"
33
- target_host.mkdir(installer_dir)
34
- installer_dir
35
- end
36
- end
37
- end
@@ -1,54 +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
-
18
- module ChefApply::Action::InstallChef
19
- class Windows < ChefApply::Action::InstallChef::Base
20
-
21
- def perform_remote_install
22
- require "mixlib/install"
23
- installer = Mixlib::Install.new({
24
- platform: "windows",
25
- product_name: "chef",
26
- channel: :stable,
27
- shell_type: :ps1,
28
- version: "13",
29
- })
30
- target_host.run_command! installer.install_command
31
- end
32
-
33
- # TODO: These methods are implemented, but are currently
34
- # not runnable - see explanation in InstallChef::Base
35
- def install_chef_to_target(remote_path)
36
- # While powershell does not mind the mixed path separators \ and /,
37
- # 'cmd.exe' definitely does - so we'll make the path cmd-friendly
38
- # before running the command
39
- cmd = "cmd /c msiexec /package #{remote_path.tr("/", "\\")} /quiet"
40
- target_host.run_command!(cmd)
41
- end
42
-
43
- def setup_remote_temp_path
44
- return @temppath if @temppath
45
-
46
- r = target_host.run_command!("Write-Host -NoNewline $env:TEMP")
47
- temppath = "#{r.stdout}\\chef-installer"
48
-
49
- # Failure here is acceptable - the dir could already exist
50
- target_host.run_command("New-Item -ItemType Directory -Force -Path #{temppath}")
51
- @temppath = temppath
52
- end
53
- end
54
- end
@@ -1,168 +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/install_chef"
20
- require "chef_apply/target_host"
21
-
22
- RSpec.describe ChefApply::Action::InstallChef::Base do
23
- let(:mock_os_name) { "mock" }
24
- let(:mock_os_family) { "mock" }
25
- let(:mock_os_release ) { "unknown" }
26
- let(:mock_opts) do
27
- {
28
- name: mock_os_name,
29
- family: mock_os_family,
30
- release: mock_os_release,
31
- arch: "x86_64",
32
- }
33
- end
34
- let(:target_host) do
35
- ChefApply::TargetHost.new("mock://user1:password1@localhost")
36
- end
37
-
38
- let(:reporter) do
39
- ChefApply::MockReporter.new
40
- end
41
-
42
- subject(:install) do
43
- ChefApply::Action::InstallChef::Base.new(target_host: target_host,
44
- reporter: reporter,
45
- check_only: false) end
46
- before do
47
- target_host.connect!
48
- target_host.backend.mock_os(mock_opts)
49
- end
50
-
51
- context "#perform_action" do
52
- context "when chef is already installed on target" do
53
- it "notifies of success and takes no further action" do
54
- expect(ChefApply::MinimumChefVersion).to receive(:check!).with(install.target_host, false)
55
- .and_return(:minimum_version_met)
56
- expect(install).not_to receive(:perform_local_install)
57
- install.perform_action
58
- end
59
- end
60
-
61
- context "when chef is not already installed on target" do
62
- it "should invoke perform_local_install" do
63
- expect(ChefApply::MinimumChefVersion).to receive(:check!).with(install.target_host, false)
64
- .and_return(:client_not_installed)
65
- expect(install).to receive(:perform_local_install)
66
- install.perform_action
67
- end
68
- end
69
- end
70
-
71
- context "#perform_local_install" do
72
- let(:artifact) { double("artifact") }
73
- let(:package_url) { "https://chef.io/download/package/here" }
74
- before do
75
- allow(artifact).to receive(:url).and_return package_url
76
- end
77
-
78
- it "performs the steps necessary to perform an installation" do
79
- expect(install).to receive(:lookup_artifact).and_return artifact
80
- expect(install).to receive(:download_to_workstation).with(package_url) .and_return "/local/path"
81
- expect(install).to receive(:upload_to_target).with("/local/path").and_return("/remote/path")
82
- expect(install).to receive(:install_chef_to_target).with("/remote/path")
83
-
84
- install.perform_local_install
85
- end
86
- end
87
-
88
- context "#train_to_mixlib" do
89
- let(:platform) { double }
90
- before do
91
- allow(platform).to receive(:release).and_return "1234"
92
- allow(platform).to receive(:name).and_return "beos"
93
- allow(platform).to receive(:arch).and_return "ppc"
94
- end
95
-
96
- context "when any flavor of windows" do
97
- before do
98
- allow(platform).to receive(:name).and_return "windows_10_pro_n"
99
- end
100
-
101
- it "sets platform name to 'windows'" do
102
- mixlib_info = install.train_to_mixlib(platform)
103
- expect(mixlib_info[:platform]).to eq "windows"
104
- end
105
- end
106
-
107
- context "when redhat" do
108
- before do
109
- allow(platform).to receive(:name).and_return "redhat"
110
- end
111
-
112
- it "sets platform name to 'el'" do
113
- mixlib_info = install.train_to_mixlib(platform)
114
- expect(mixlib_info[:platform]).to eq "el"
115
- end
116
- end
117
-
118
- context "when centos" do
119
- before do
120
- allow(platform).to receive(:name).and_return "centos"
121
- end
122
-
123
- it "sets platform name to 'el'" do
124
- mixlib_info = install.train_to_mixlib(platform)
125
- expect(mixlib_info[:platform]).to eq "el"
126
- end
127
- end
128
-
129
- context "when suse" do
130
- before do
131
- allow(platform).to receive(:name).and_return "suse"
132
- end
133
-
134
- it "sets platform name to 'sles'" do
135
- mixlib_info = install.train_to_mixlib(platform)
136
- expect(mixlib_info[:platform]).to eq "sles"
137
- end
138
- end
139
- context "when amazon" do
140
- before do
141
- allow(platform).to receive(:name).and_return "amazon"
142
- end
143
-
144
- context "when amazon linux 1.x" do
145
- before do
146
- allow(platform).to receive(:release).and_return "2017.09"
147
- end
148
-
149
- it "sets platform name to 'amazon' and plaform_version to '6'" do
150
- mixlib_info = install.train_to_mixlib(platform)
151
- expect(mixlib_info[:platform]).to eq "el"
152
- expect(mixlib_info[:platform_version]).to eq "6"
153
- end
154
- end
155
- context "when amazon linux 2.x" do
156
- before do
157
- allow(platform).to receive(:release).and_return "2"
158
- end
159
-
160
- it "sets platform name to 'amazon' and plaform_version to '7'" do
161
- mixlib_info = install.train_to_mixlib(platform)
162
- expect(mixlib_info[:platform]).to eq "el"
163
- expect(mixlib_info[:platform_version]).to eq "7"
164
- end
165
- end
166
- end
167
- end
168
- end