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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +201 -201
  3. data/Rakefile +15 -15
  4. data/chef-utils.gemspec +50 -46
  5. data/lib/chef-utils/dist.rb +151 -98
  6. data/lib/chef-utils/dsl/architecture.rb +150 -150
  7. data/lib/chef-utils/dsl/cloud.rb +155 -144
  8. data/lib/chef-utils/dsl/default_paths.rb +60 -60
  9. data/lib/chef-utils/dsl/introspection.rb +134 -123
  10. data/lib/chef-utils/dsl/os.rb +58 -58
  11. data/lib/chef-utils/dsl/path_sanity.rb +39 -39
  12. data/lib/chef-utils/dsl/platform.rb +387 -372
  13. data/lib/chef-utils/dsl/platform_family.rb +355 -344
  14. data/lib/chef-utils/dsl/platform_version.rb +41 -41
  15. data/lib/chef-utils/dsl/service.rb +112 -112
  16. data/lib/chef-utils/dsl/train_helpers.rb +87 -87
  17. data/lib/chef-utils/dsl/virtualization.rb +272 -250
  18. data/lib/chef-utils/dsl/which.rb +123 -123
  19. data/lib/chef-utils/dsl/windows.rb +86 -86
  20. data/lib/chef-utils/internal.rb +114 -114
  21. data/lib/chef-utils/mash.rb +263 -240
  22. data/lib/chef-utils/parallel_map.rb +131 -0
  23. data/lib/chef-utils/version.rb +20 -20
  24. data/lib/chef-utils/version_string.rb +160 -160
  25. data/lib/chef-utils.rb +53 -53
  26. data/spec/spec_helper.rb +100 -100
  27. data/spec/unit/dsl/architecture_spec.rb +151 -151
  28. data/spec/unit/dsl/cloud_spec.rb +93 -89
  29. data/spec/unit/dsl/dsl_spec.rb +34 -34
  30. data/spec/unit/dsl/introspection_spec.rb +201 -189
  31. data/spec/unit/dsl/os_spec.rb +175 -175
  32. data/spec/unit/dsl/path_sanity_spec.rb +86 -86
  33. data/spec/unit/dsl/platform_family_spec.rb +235 -223
  34. data/spec/unit/dsl/platform_spec.rb +252 -238
  35. data/spec/unit/dsl/service_spec.rb +117 -117
  36. data/spec/unit/dsl/virtualization_spec.rb +75 -75
  37. data/spec/unit/dsl/which_spec.rb +171 -171
  38. data/spec/unit/dsl/windows_spec.rb +84 -84
  39. data/spec/unit/mash_spec.rb +51 -51
  40. data/spec/unit/parallel_map_spec.rb +156 -0
  41. 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 "#docker?" 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("virtualization", "systems", "docker").and_return(nil)
39
- expect(ChefUtils.docker?(node)).to be false
40
- end
41
- it "is true when ohai reports a docker guest" do
42
- expect(node).to receive(:read).with("virtualization", "systems", "docker").and_return("guest")
43
- expect(ChefUtils.docker?(node)).to be true
44
- end
45
- it "is false for any other value other than guest" do
46
- expect(node).to receive(:read).with("virtualization", "systems", "docker").and_return("some nonsense")
47
- expect(ChefUtils.docker?(node)).to be false
48
- end
49
- end
50
-
51
- context "#systemd?" do
52
- # FIXME: somehow test the train helpers
53
- it "returns false if /proc/1/comm does not exist" do
54
- expect(File).to receive(:exist?).with("/proc/1/comm").and_return(false)
55
- expect(ChefUtils.systemd?(node)).to be false
56
- end
57
-
58
- it "returns false if /proc/1/comm is not systemd" do
59
- expect(File).to receive(:exist?).with("/proc/1/comm").and_return(true)
60
- expect(File).to receive(:open).with("/proc/1/comm").and_return(StringIO.new("upstart\n"))
61
- expect(ChefUtils.systemd?(node)).to be false
62
- end
63
-
64
- it "returns true if /proc/1/comm is systemd" do
65
- expect(File).to receive(:exist?).with("/proc/1/comm").and_return(true)
66
- expect(File).to receive(:open).with("/proc/1/comm").and_return(StringIO.new("systemd\n"))
67
- expect(ChefUtils.systemd?(node)).to be true
68
- end
69
- end
70
-
71
- context "#kitchen?" do
72
- before do
73
- @saved = ENV["TEST_KITCHEN"]
74
- end
75
- after do
76
- ENV["TEST_KITCHEN"] = @saved
77
- end
78
-
79
- it "return true if ENV['TEST_KITCHEN'] is not set" do
80
- ENV.delete("TEST_KITCHEN")
81
- expect(ChefUtils.kitchen?(node)).to be false
82
- end
83
-
84
- it "return true if ENV['TEST_KITCHEN'] is nil" do
85
- ENV["TEST_KITCHEN"] = nil
86
- expect(ChefUtils.kitchen?(node)).to be false
87
- end
88
-
89
- it "return true if ENV['TEST_KITCHEN'] is set" do
90
- ENV["TEST_KITCHEN"] = "1"
91
- expect(ChefUtils.kitchen?(node)).to be true
92
- end
93
- end
94
-
95
- context "#ci?" do
96
- before do
97
- @saved = ENV["CI"]
98
- end
99
- after do
100
- ENV["CI"] = @saved
101
- end
102
-
103
- it "return true if ENV['CI'] is not set" do
104
- ENV.delete("CI")
105
- expect(ChefUtils.ci?(node)).to be false
106
- end
107
-
108
- it "return true if ENV['CI'] is nil" do
109
- ENV["CI"] = nil
110
- expect(ChefUtils.ci?(node)).to be false
111
- end
112
-
113
- it "return true if ENV['CI'] is set" do
114
- ENV["CI"] = "1"
115
- expect(ChefUtils.ci?(node)).to be true
116
- end
117
- end
118
-
119
- context "#has_systemd_service_unit?" do
120
- # FIXME: test through train helpers
121
-
122
- before do
123
- %w{ /etc /usr/lib /lib /run }.each do |base|
124
- allow(File).to receive(:exist?).with("#{base}/systemd/system/example.service").and_return(false)
125
- allow(File).to receive(:exist?).with("#{base}/systemd/system/example@.service").and_return(false)
126
- end
127
- end
128
-
129
- it "is false if no unit is present" do
130
- expect(ChefUtils.has_systemd_service_unit?("example")).to be false
131
- end
132
-
133
- it "is false if no template is present" do
134
- expect(ChefUtils.has_systemd_service_unit?("example@instance1")).to be false
135
- end
136
-
137
- %w{ /etc /usr/lib /lib /run }.each do |base|
138
- it "finds a unit in #{base}" do
139
- expect(File).to receive(:exist?).with("#{base}/systemd/system/example.service").and_return(true)
140
- expect(ChefUtils.has_systemd_service_unit?("example")).to be true
141
- end
142
-
143
- it "finds a template in #{base}" do
144
- expect(File).to receive(:exist?).with("#{base}/systemd/system/example@.service").and_return(true)
145
- expect(ChefUtils.has_systemd_service_unit?("example@instance1")).to be true
146
- end
147
- end
148
- end
149
-
150
- context "#has_systemd_unit?" do
151
- # FIXME: test through train helpers
152
-
153
- before do
154
- %w{ /etc /usr/lib /lib /run }.each do |base|
155
- allow(File).to receive(:exist?).with("#{base}/systemd/system/example.mount").and_return(false)
156
- end
157
- end
158
-
159
- it "is false if no unit is present" do
160
- expect(ChefUtils.has_systemd_unit?("example.mount")).to be false
161
- end
162
-
163
- %w{ /etc /usr/lib /lib /run }.each do |base|
164
- it "finds a unit in #{base}" do
165
- expect(File).to receive(:exist?).with("#{base}/systemd/system/example.mount").and_return(true)
166
- expect(ChefUtils.has_systemd_unit?("example.mount")).to be true
167
- end
168
- end
169
- end
170
-
171
- context "#include_recipe?" do
172
- it "is true when the recipe has been seen by the node" do
173
- expect(node).to receive(:recipe?).with("myrecipe").and_return(true)
174
- expect(ChefUtils.include_recipe?("myrecipe", node)).to be true
175
- end
176
- it "is false when the recipe has not been seen by the node" do
177
- expect(node).to receive(:recipe?).with("myrecipe").and_return(false)
178
- expect(ChefUtils.include_recipe?("myrecipe", node)).to be false
179
- end
180
- it "the alias is true when the recipe has been seen by the node" do
181
- expect(node).to receive(:recipe?).with("myrecipe").and_return(true)
182
- expect(ChefUtils.includes_recipe?("myrecipe", node)).to be true
183
- end
184
- it "the alias is false when the recipe has not been seen by the node" do
185
- expect(node).to receive(:recipe?).with("myrecipe").and_return(false)
186
- expect(ChefUtils.includes_recipe?("myrecipe", node)).to be false
187
- end
188
- end
189
- end
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