chef-utils 16.10.17 → 17.10.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +201 -201
- data/Rakefile +15 -15
- data/chef-utils.gemspec +50 -46
- data/lib/chef-utils/dist.rb +151 -98
- data/lib/chef-utils/dsl/architecture.rb +150 -150
- data/lib/chef-utils/dsl/cloud.rb +155 -144
- data/lib/chef-utils/dsl/default_paths.rb +60 -60
- data/lib/chef-utils/dsl/introspection.rb +134 -123
- data/lib/chef-utils/dsl/os.rb +58 -58
- data/lib/chef-utils/dsl/path_sanity.rb +39 -39
- data/lib/chef-utils/dsl/platform.rb +387 -372
- data/lib/chef-utils/dsl/platform_family.rb +355 -344
- data/lib/chef-utils/dsl/platform_version.rb +41 -41
- data/lib/chef-utils/dsl/service.rb +112 -112
- data/lib/chef-utils/dsl/train_helpers.rb +87 -87
- data/lib/chef-utils/dsl/virtualization.rb +272 -250
- data/lib/chef-utils/dsl/which.rb +123 -123
- data/lib/chef-utils/dsl/windows.rb +86 -86
- data/lib/chef-utils/internal.rb +114 -114
- data/lib/chef-utils/mash.rb +263 -240
- data/lib/chef-utils/parallel_map.rb +131 -0
- data/lib/chef-utils/version.rb +20 -20
- data/lib/chef-utils/version_string.rb +160 -160
- data/lib/chef-utils.rb +53 -53
- data/spec/spec_helper.rb +100 -100
- data/spec/unit/dsl/architecture_spec.rb +151 -151
- data/spec/unit/dsl/cloud_spec.rb +93 -89
- data/spec/unit/dsl/dsl_spec.rb +34 -34
- data/spec/unit/dsl/introspection_spec.rb +201 -189
- data/spec/unit/dsl/os_spec.rb +175 -175
- data/spec/unit/dsl/path_sanity_spec.rb +86 -86
- data/spec/unit/dsl/platform_family_spec.rb +235 -223
- data/spec/unit/dsl/platform_spec.rb +252 -238
- data/spec/unit/dsl/service_spec.rb +117 -117
- data/spec/unit/dsl/virtualization_spec.rb +75 -75
- data/spec/unit/dsl/which_spec.rb +171 -171
- data/spec/unit/dsl/windows_spec.rb +84 -84
- data/spec/unit/mash_spec.rb +51 -51
- data/spec/unit/parallel_map_spec.rb +156 -0
- metadata +26 -10
@@ -1,189 +1,201 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Copyright:: Copyright (c) Chef Software Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
require "spec_helper"
|
20
|
-
|
21
|
-
RSpec.describe ChefUtils::DSL::Introspection do
|
22
|
-
class IntrospectionTestClass
|
23
|
-
include ChefUtils::DSL::Introspection
|
24
|
-
attr_accessor :node
|
25
|
-
|
26
|
-
def initialize(node)
|
27
|
-
@node = node
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
let(:node) { double("node") }
|
32
|
-
|
33
|
-
let(:test_instance) { IntrospectionTestClass.new(node) }
|
34
|
-
|
35
|
-
context "#
|
36
|
-
# FIXME: use a real VividMash for these tests instead of stubbing
|
37
|
-
it "is false by default" do
|
38
|
-
expect(node).to receive(:read).with("
|
39
|
-
expect(ChefUtils.
|
40
|
-
end
|
41
|
-
it "is true when ohai reports a
|
42
|
-
expect(node).to receive(:read).with("
|
43
|
-
expect(ChefUtils.
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
it "
|
54
|
-
expect(
|
55
|
-
expect(ChefUtils.
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
expect(
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
expect(File).to receive(:
|
67
|
-
expect(ChefUtils.systemd?(node)).to be
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
ENV["TEST_KITCHEN"]
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
ENV["CI"]
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
end
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
it "
|
185
|
-
expect(node).to receive(:recipe?).with("myrecipe").and_return(
|
186
|
-
expect(ChefUtils.
|
187
|
-
end
|
188
|
-
|
189
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require "spec_helper"
|
20
|
+
|
21
|
+
RSpec.describe ChefUtils::DSL::Introspection do
|
22
|
+
class IntrospectionTestClass
|
23
|
+
include ChefUtils::DSL::Introspection
|
24
|
+
attr_accessor :node
|
25
|
+
|
26
|
+
def initialize(node)
|
27
|
+
@node = node
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:node) { double("node") }
|
32
|
+
|
33
|
+
let(:test_instance) { IntrospectionTestClass.new(node) }
|
34
|
+
|
35
|
+
context "#effortless?" do
|
36
|
+
# FIXME: use a real VividMash for these tests instead of stubbing
|
37
|
+
it "is false by default" do
|
38
|
+
expect(node).to receive(:read).with("chef_packages", "chef", "chef_effortless").and_return(nil)
|
39
|
+
expect(ChefUtils.effortless?(node)).to be false
|
40
|
+
end
|
41
|
+
it "is true when ohai reports a effortless" do
|
42
|
+
expect(node).to receive(:read).with("chef_packages", "chef", "chef_effortless").and_return(true)
|
43
|
+
expect(ChefUtils.effortless?(node)).to be true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "#docker?" do
|
48
|
+
# FIXME: use a real VividMash for these tests instead of stubbing
|
49
|
+
it "is false by default" do
|
50
|
+
expect(node).to receive(:read).with("virtualization", "systems", "docker").and_return(nil)
|
51
|
+
expect(ChefUtils.docker?(node)).to be false
|
52
|
+
end
|
53
|
+
it "is true when ohai reports a docker guest" do
|
54
|
+
expect(node).to receive(:read).with("virtualization", "systems", "docker").and_return("guest")
|
55
|
+
expect(ChefUtils.docker?(node)).to be true
|
56
|
+
end
|
57
|
+
it "is false for any other value other than guest" do
|
58
|
+
expect(node).to receive(:read).with("virtualization", "systems", "docker").and_return("some nonsense")
|
59
|
+
expect(ChefUtils.docker?(node)).to be false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "#systemd?" do
|
64
|
+
# FIXME: somehow test the train helpers
|
65
|
+
it "returns false if /proc/1/comm does not exist" do
|
66
|
+
expect(File).to receive(:exist?).with("/proc/1/comm").and_return(false)
|
67
|
+
expect(ChefUtils.systemd?(node)).to be false
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns false if /proc/1/comm is not systemd" do
|
71
|
+
expect(File).to receive(:exist?).with("/proc/1/comm").and_return(true)
|
72
|
+
expect(File).to receive(:open).with("/proc/1/comm").and_return(StringIO.new("upstart\n"))
|
73
|
+
expect(ChefUtils.systemd?(node)).to be false
|
74
|
+
end
|
75
|
+
|
76
|
+
it "returns true if /proc/1/comm is systemd" do
|
77
|
+
expect(File).to receive(:exist?).with("/proc/1/comm").and_return(true)
|
78
|
+
expect(File).to receive(:open).with("/proc/1/comm").and_return(StringIO.new("systemd\n"))
|
79
|
+
expect(ChefUtils.systemd?(node)).to be true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "#kitchen?" do
|
84
|
+
before do
|
85
|
+
@saved = ENV["TEST_KITCHEN"]
|
86
|
+
end
|
87
|
+
after do
|
88
|
+
ENV["TEST_KITCHEN"] = @saved
|
89
|
+
end
|
90
|
+
|
91
|
+
it "return true if ENV['TEST_KITCHEN'] is not set" do
|
92
|
+
ENV.delete("TEST_KITCHEN")
|
93
|
+
expect(ChefUtils.kitchen?(node)).to be false
|
94
|
+
end
|
95
|
+
|
96
|
+
it "return true if ENV['TEST_KITCHEN'] is nil" do
|
97
|
+
ENV["TEST_KITCHEN"] = nil
|
98
|
+
expect(ChefUtils.kitchen?(node)).to be false
|
99
|
+
end
|
100
|
+
|
101
|
+
it "return true if ENV['TEST_KITCHEN'] is set" do
|
102
|
+
ENV["TEST_KITCHEN"] = "1"
|
103
|
+
expect(ChefUtils.kitchen?(node)).to be true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "#ci?" do
|
108
|
+
before do
|
109
|
+
@saved = ENV["CI"]
|
110
|
+
end
|
111
|
+
after do
|
112
|
+
ENV["CI"] = @saved
|
113
|
+
end
|
114
|
+
|
115
|
+
it "return true if ENV['CI'] is not set" do
|
116
|
+
ENV.delete("CI")
|
117
|
+
expect(ChefUtils.ci?(node)).to be false
|
118
|
+
end
|
119
|
+
|
120
|
+
it "return true if ENV['CI'] is nil" do
|
121
|
+
ENV["CI"] = nil
|
122
|
+
expect(ChefUtils.ci?(node)).to be false
|
123
|
+
end
|
124
|
+
|
125
|
+
it "return true if ENV['CI'] is set" do
|
126
|
+
ENV["CI"] = "1"
|
127
|
+
expect(ChefUtils.ci?(node)).to be true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context "#has_systemd_service_unit?" do
|
132
|
+
# FIXME: test through train helpers
|
133
|
+
|
134
|
+
before do
|
135
|
+
%w{ /etc /usr/lib /lib /run }.each do |base|
|
136
|
+
allow(File).to receive(:exist?).with("#{base}/systemd/system/example.service").and_return(false)
|
137
|
+
allow(File).to receive(:exist?).with("#{base}/systemd/system/example@.service").and_return(false)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
it "is false if no unit is present" do
|
142
|
+
expect(ChefUtils.has_systemd_service_unit?("example")).to be false
|
143
|
+
end
|
144
|
+
|
145
|
+
it "is false if no template is present" do
|
146
|
+
expect(ChefUtils.has_systemd_service_unit?("example@instance1")).to be false
|
147
|
+
end
|
148
|
+
|
149
|
+
%w{ /etc /usr/lib /lib /run }.each do |base|
|
150
|
+
it "finds a unit in #{base}" do
|
151
|
+
expect(File).to receive(:exist?).with("#{base}/systemd/system/example.service").and_return(true)
|
152
|
+
expect(ChefUtils.has_systemd_service_unit?("example")).to be true
|
153
|
+
end
|
154
|
+
|
155
|
+
it "finds a template in #{base}" do
|
156
|
+
expect(File).to receive(:exist?).with("#{base}/systemd/system/example@.service").and_return(true)
|
157
|
+
expect(ChefUtils.has_systemd_service_unit?("example@instance1")).to be true
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context "#has_systemd_unit?" do
|
163
|
+
# FIXME: test through train helpers
|
164
|
+
|
165
|
+
before do
|
166
|
+
%w{ /etc /usr/lib /lib /run }.each do |base|
|
167
|
+
allow(File).to receive(:exist?).with("#{base}/systemd/system/example.mount").and_return(false)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
it "is false if no unit is present" do
|
172
|
+
expect(ChefUtils.has_systemd_unit?("example.mount")).to be false
|
173
|
+
end
|
174
|
+
|
175
|
+
%w{ /etc /usr/lib /lib /run }.each do |base|
|
176
|
+
it "finds a unit in #{base}" do
|
177
|
+
expect(File).to receive(:exist?).with("#{base}/systemd/system/example.mount").and_return(true)
|
178
|
+
expect(ChefUtils.has_systemd_unit?("example.mount")).to be true
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context "#include_recipe?" do
|
184
|
+
it "is true when the recipe has been seen by the node" do
|
185
|
+
expect(node).to receive(:recipe?).with("myrecipe").and_return(true)
|
186
|
+
expect(ChefUtils.include_recipe?("myrecipe", node)).to be true
|
187
|
+
end
|
188
|
+
it "is false when the recipe has not been seen by the node" do
|
189
|
+
expect(node).to receive(:recipe?).with("myrecipe").and_return(false)
|
190
|
+
expect(ChefUtils.include_recipe?("myrecipe", node)).to be false
|
191
|
+
end
|
192
|
+
it "the alias is true when the recipe has been seen by the node" do
|
193
|
+
expect(node).to receive(:recipe?).with("myrecipe").and_return(true)
|
194
|
+
expect(ChefUtils.includes_recipe?("myrecipe", node)).to be true
|
195
|
+
end
|
196
|
+
it "the alias is false when the recipe has not been seen by the node" do
|
197
|
+
expect(node).to receive(:recipe?).with("myrecipe").and_return(false)
|
198
|
+
expect(ChefUtils.includes_recipe?("myrecipe", node)).to be false
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|