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,344 +1,355 @@
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_relative "../internal"
20
-
21
- module ChefUtils
22
- module DSL
23
- module PlatformFamily
24
- include Internal
25
-
26
- # Determine if the current node is a member of the 'arch' family.
27
- #
28
- # @param [Chef::Node] node the node to check
29
- # @since 15.5
30
- #
31
- # @return [Boolean]
32
- #
33
- def arch?(node = __getnode)
34
- node["platform_family"] == "arch"
35
- end
36
- # chef-sugar backcompat method
37
- alias_method :arch_linux?, :arch?
38
-
39
- # Determine if the current node is a member of the 'aix' platform family.
40
- #
41
- # @param [Chef::Node] node the node to check
42
- # @since 15.5
43
- #
44
- # @return [Boolean]
45
- #
46
- def aix?(node = __getnode)
47
- node["platform_family"] == "aix"
48
- end
49
-
50
- # Determine if the current node is a member of the 'debian' platform family (Debian, Ubuntu and derivatives).
51
- #
52
- # @param [Chef::Node] node the node to check
53
- # @since 15.5
54
- #
55
- # @return [Boolean]
56
- #
57
- def debian?(node = __getnode)
58
- node["platform_family"] == "debian"
59
- end
60
-
61
- # Determine if the current node is a member of the 'fedora' platform family (Fedora and Arista).
62
- #
63
- # @param [Chef::Node] node the node to check
64
- # @since 15.5
65
- #
66
- # @return [Boolean]
67
- #
68
- def fedora?(node = __getnode)
69
- node["platform_family"] == "fedora"
70
- end
71
-
72
- # Determine if the current node is a member of the 'mac_os_x' platform family.
73
- #
74
- # @param [Chef::Node] node the node to check
75
- # @since 15.5
76
- #
77
- # @return [Boolean]
78
- #
79
- def macos?(node = __getnode)
80
- node["platform_family"] == "mac_os_x"
81
- end
82
- # chef-sugar backcompat method
83
- alias_method :osx?, :macos?
84
- # chef-sugar backcompat method
85
- alias_method :mac?, :macos?
86
- # chef-sugar backcompat method
87
- alias_method :mac_os_x?, :macos?
88
-
89
- # Determine if the current node is a member of the 'rhel' platform family (Red Hat, CentOS, Oracle or Scientific Linux, but NOT Amazon Linux or Fedora).
90
- #
91
- # @param [Chef::Node] node the node to check
92
- # @since 15.5
93
- #
94
- # @return [Boolean]
95
- #
96
- def rhel?(node = __getnode)
97
- node["platform_family"] == "rhel"
98
- end
99
- # chef-sugar backcompat method
100
- alias_method :el?, :rhel?
101
-
102
- # Determine if the current node is a rhel6 compatible build (Red Hat, CentOS, Oracle or Scientific Linux).
103
- #
104
- # @param [Chef::Node] node the node to check
105
- # @since 15.5
106
- #
107
- # @return [Boolean]
108
- #
109
- def rhel6?(node = __getnode)
110
- node["platform_family"] == "rhel" && node["platform_version"].to_f >= 6.0 && node["platform_version"].to_f < 7.0
111
- end
112
-
113
- # Determine if the current node is a rhel7 compatible build (Red Hat, CentOS, Oracle or Scientific Linux).
114
- #
115
- # @param [Chef::Node] node the node to check
116
- # @since 15.5
117
- #
118
- # @return [Boolean]
119
- #
120
- def rhel7?(node = __getnode)
121
- node["platform_family"] == "rhel" && node["platform_version"].to_f >= 7.0 && node["platform_version"].to_f < 8.0
122
- end
123
-
124
- # Determine if the current node is a rhel8 compatible build (Red Hat, CentOS, Oracle or Scientific Linux).
125
- #
126
- # @param [Chef::Node] node the node to check
127
- # @since 15.5
128
- #
129
- # @return [Boolean]
130
- #
131
- def rhel8?(node = __getnode)
132
- node["platform_family"] == "rhel" && node["platform_version"].to_f >= 8.0 && node["platform_version"].to_f < 9.0
133
- end
134
-
135
- # Determine if the current node is a member of the 'amazon' platform family.
136
- #
137
- # @param [Chef::Node] node the node to check
138
- # @since 15.5
139
- #
140
- # @return [Boolean]
141
- #
142
- def amazon?(node = __getnode)
143
- node["platform_family"] == "amazon"
144
- end
145
- # chef-sugar backcompat method
146
- alias_method :amazon_linux?, :amazon?
147
-
148
- # Determine if the current node is a member of the 'solaris2' platform family.
149
- #
150
- # @param [Chef::Node] node the node to check
151
- # @since 15.5
152
- #
153
- # @return [Boolean]
154
- #
155
- def solaris2?(node = __getnode)
156
- node["platform_family"] == "solaris2"
157
- end
158
- # chef-sugar backcompat method
159
- alias_method :solaris?, :solaris2?
160
-
161
- # Determine if the current node is a member of the 'smartos' platform family.
162
- #
163
- # @param [Chef::Node] node the node to check
164
- # @since 15.5
165
- #
166
- # @return [Boolean]
167
- #
168
- def smartos?(node = __getnode)
169
- node["platform_family"] == "smartos"
170
- end
171
-
172
- # Determine if the current node is a member of the 'suse' platform family (openSUSE, SLES, and SLED).
173
- #
174
- # @param [Chef::Node] node the node to check
175
- # @since 15.5
176
- #
177
- # @return [Boolean]
178
- #
179
- def suse?(node = __getnode)
180
- node["platform_family"] == "suse"
181
- end
182
-
183
- # Determine if the current node is a member of the 'gentoo' platform family.
184
- #
185
- # @param [Chef::Node] node the node to check
186
- # @since 15.5
187
- #
188
- # @return [Boolean]
189
- #
190
- def gentoo?(node = __getnode)
191
- node["platform_family"] == "gentoo"
192
- end
193
-
194
- # Determine if the current node is a member of the 'freebsd' platform family.
195
- #
196
- # @param [Chef::Node] node the node to check
197
- # @since 15.5
198
- #
199
- # @return [Boolean]
200
- #
201
- def freebsd?(node = __getnode)
202
- node["platform_family"] == "freebsd"
203
- end
204
-
205
- # Determine if the current node is a member of the 'openbsd' platform family.
206
- #
207
- # @param [Chef::Node] node the node to check
208
- # @since 15.5
209
- #
210
- # @return [Boolean]
211
- #
212
- def openbsd?(node = __getnode)
213
- node["platform_family"] == "openbsd"
214
- end
215
-
216
- # Determine if the current node is a member of the 'netbsd' platform family.
217
- #
218
- # @param [Chef::Node] node the node to check
219
- # @since 15.5
220
- #
221
- # @return [Boolean]
222
- #
223
- def netbsd?(node = __getnode)
224
- node["platform_family"] == "netbsd"
225
- end
226
-
227
- # Determine if the current node is a member of the 'dragonflybsd' platform family.
228
- #
229
- # @param [Chef::Node] node the node to check
230
- # @since 15.5
231
- #
232
- # @return [Boolean]
233
- #
234
- def dragonflybsd?(node = __getnode)
235
- node["platform_family"] == "dragonflybsd"
236
- end
237
-
238
- # Determine if the current node is a member of the 'windows' platform family.
239
- #
240
- # @param [Chef::Node] node the node to check
241
- # @since 15.5
242
- #
243
- # @return [Boolean]
244
- #
245
- def windows?(node = __getnode(true))
246
- # This is all somewhat complicated. We prefer to get the node object so that chefspec can
247
- # stub the node object. But we also have to deal with class-parsing time where there is
248
- # no node object, so we have to fall back to RUBY_PLATFORM based detection. We cannot pull
249
- # the node object out of the Chef.run_context.node global object here (which is what the
250
- # false flag to __getnode is about) because some run-time code also cannot run under chefspec
251
- # on non-windows where the node is stubbed to windows.
252
- #
253
- # As a result of this the `windows?` helper and the `ChefUtils.windows?` helper do not behave
254
- # the same way in that the latter is not stubbable by chefspec.
255
- #
256
- node ? node["platform_family"] == "windows" : windows_ruby?
257
- end
258
-
259
- # Determine if the Ruby VM is currently running on a Windows node (ChefSpec can never stub
260
- # this behavior, so this is useful for code which can never be parsed on a non-Windows box).
261
- #
262
- # @since 15.5
263
- #
264
- # @return [Boolean]
265
- #
266
- def windows_ruby?
267
- !!(RUBY_PLATFORM =~ /mswin|mingw32|windows/)
268
- end
269
-
270
- #
271
- # Platform-Family-like Helpers
272
- #
273
- # These are meta-helpers which address the issue that platform_family is single valued and cannot
274
- # be an array while a tree-like Taxonomy is what is called for in some cases.
275
- #
276
-
277
- # If it uses RPM, it goes in here (rhel, fedora, amazon, suse platform_families). Deliberately does not
278
- # include AIX because bff is AIX's primary package manager and adding it here would make this substantially
279
- # less useful since in no way can AIX trace its lineage back to old redhat distros. This is most useful for
280
- # "smells like redhat, including SuSE".
281
- #
282
- # @param [Chef::Node] node the node to check
283
- # @since 15.5
284
- #
285
- # @return [Boolean]
286
- #
287
- def rpm_based?(node = __getnode)
288
- fedora_derived?(node) || node["platform_family"] == "suse"
289
- end
290
-
291
- # RPM-based distros which are not SuSE and are very loosely similar to fedora, using yum or dnf. The historical
292
- # lineage of the distro should have forked off from old redhat fedora distros at some point. Currently rhel,
293
- # fedora and amazon. This is most useful for "smells like redhat, but isn't SuSE".
294
- #
295
- # @param [Chef::Node] node the node to check
296
- # @since 15.5
297
- #
298
- # @return [Boolean]
299
- #
300
- def fedora_derived?(node = __getnode)
301
- redhat_based?(node) || node["platform_family"] == "amazon"
302
- end
303
-
304
- # RedHat distros -- fedora and rhel platform_families, nothing else. This is most likely not as useful as the
305
- # "fedora_derived?" helper.
306
- #
307
- # @param [Chef::Node] node the node to check
308
- # @since 15.5
309
- #
310
- # @return [Boolean]
311
- #
312
- def redhat_based?(node = __getnode)
313
- %w{rhel fedora}.include?(node["platform_family"])
314
- end
315
-
316
- # All of the Solaris-lineage.
317
- #
318
- # @param [Chef::Node] node the node to check
319
- # @since 15.5
320
- #
321
- # @return [Boolean]
322
- #
323
- def solaris_based?(node = __getnode)
324
- %w{solaris2 smartos omnios openindiana}.include?(node["platform"])
325
- end
326
-
327
- # All of the BSD-lineage.
328
- #
329
- # Note that macOS is not included since macOS deviates so significantly from BSD that including it would not be useful.
330
- #
331
- # @param [Chef::Node] node the node to check
332
- # @since 15.5
333
- #
334
- # @return [Boolean]
335
- #
336
- def bsd_based?(node = __getnode)
337
- # we could use os, platform_family or platform here equally
338
- %w{netbsd freebsd openbsd dragonflybsd}.include?(node["platform"])
339
- end
340
-
341
- extend self
342
- end
343
- end
344
- 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_relative "../internal"
20
+
21
+ module ChefUtils
22
+ module DSL
23
+ module PlatformFamily
24
+ include Internal
25
+
26
+ # Determine if the current node is a member of the 'arch' family.
27
+ #
28
+ # @param [Chef::Node] node the node to check
29
+ # @since 15.5
30
+ #
31
+ # @return [Boolean]
32
+ #
33
+ def arch?(node = __getnode)
34
+ node["platform_family"] == "arch"
35
+ end
36
+ # chef-sugar backcompat method
37
+ alias_method :arch_linux?, :arch?
38
+
39
+ # Determine if the current node is a member of the 'aix' platform family.
40
+ #
41
+ # @param [Chef::Node] node the node to check
42
+ # @since 15.5
43
+ #
44
+ # @return [Boolean]
45
+ #
46
+ def aix?(node = __getnode)
47
+ node["platform_family"] == "aix"
48
+ end
49
+
50
+ # Determine if the current node is a member of the 'debian' platform family (Debian, Ubuntu and derivatives).
51
+ #
52
+ # @param [Chef::Node] node the node to check
53
+ # @since 15.5
54
+ #
55
+ # @return [Boolean]
56
+ #
57
+ def debian?(node = __getnode)
58
+ node["platform_family"] == "debian"
59
+ end
60
+
61
+ # Determine if the current node is a member of the 'fedora' platform family (Fedora and Arista).
62
+ #
63
+ # @param [Chef::Node] node the node to check
64
+ # @since 15.5
65
+ #
66
+ # @return [Boolean]
67
+ #
68
+ def fedora?(node = __getnode)
69
+ node["platform_family"] == "fedora"
70
+ end
71
+
72
+ # Determine if the current node is a member of the 'mac_os_x' platform family.
73
+ #
74
+ # @param [Chef::Node] node the node to check
75
+ # @since 15.5
76
+ #
77
+ # @return [Boolean]
78
+ #
79
+ def macos?(node = __getnode)
80
+ node ? node["platform_family"] == "mac_os_x" : macos_ruby?
81
+ end
82
+ # chef-sugar backcompat method
83
+ alias_method :osx?, :macos?
84
+ # chef-sugar backcompat method
85
+ alias_method :mac?, :macos?
86
+ # chef-sugar backcompat method
87
+ alias_method :mac_os_x?, :macos?
88
+
89
+ # Determine if the Ruby VM is currently running on a Mac node (This is useful primarily for internal use
90
+ # by Chef Infra Client before the node object exists).
91
+ #
92
+ # @since 17.3
93
+ #
94
+ # @return [Boolean]
95
+ #
96
+ def macos_ruby?
97
+ !!(RUBY_PLATFORM =~ /darwin/)
98
+ end
99
+
100
+ # Determine if the current node is a member of the 'rhel' platform family (Red Hat, CentOS, Oracle or Scientific Linux, but NOT Amazon Linux or Fedora).
101
+ #
102
+ # @param [Chef::Node] node the node to check
103
+ # @since 15.5
104
+ #
105
+ # @return [Boolean]
106
+ #
107
+ def rhel?(node = __getnode)
108
+ node["platform_family"] == "rhel"
109
+ end
110
+ # chef-sugar backcompat method
111
+ alias_method :el?, :rhel?
112
+
113
+ # Determine if the current node is a rhel6 compatible build (Red Hat, CentOS, Oracle or Scientific Linux).
114
+ #
115
+ # @param [Chef::Node] node the node to check
116
+ # @since 15.5
117
+ #
118
+ # @return [Boolean]
119
+ #
120
+ def rhel6?(node = __getnode)
121
+ node["platform_family"] == "rhel" && node["platform_version"].to_f >= 6.0 && node["platform_version"].to_f < 7.0
122
+ end
123
+
124
+ # Determine if the current node is a rhel7 compatible build (Red Hat, CentOS, Oracle or Scientific Linux).
125
+ #
126
+ # @param [Chef::Node] node the node to check
127
+ # @since 15.5
128
+ #
129
+ # @return [Boolean]
130
+ #
131
+ def rhel7?(node = __getnode)
132
+ node["platform_family"] == "rhel" && node["platform_version"].to_f >= 7.0 && node["platform_version"].to_f < 8.0
133
+ end
134
+
135
+ # Determine if the current node is a rhel8 compatible build (Red Hat, CentOS, Oracle or Scientific Linux).
136
+ #
137
+ # @param [Chef::Node] node the node to check
138
+ # @since 15.5
139
+ #
140
+ # @return [Boolean]
141
+ #
142
+ def rhel8?(node = __getnode)
143
+ node["platform_family"] == "rhel" && node["platform_version"].to_f >= 8.0 && node["platform_version"].to_f < 9.0
144
+ end
145
+
146
+ # Determine if the current node is a member of the 'amazon' platform family.
147
+ #
148
+ # @param [Chef::Node] node the node to check
149
+ # @since 15.5
150
+ #
151
+ # @return [Boolean]
152
+ #
153
+ def amazon?(node = __getnode)
154
+ node["platform_family"] == "amazon"
155
+ end
156
+ # chef-sugar backcompat method
157
+ alias_method :amazon_linux?, :amazon?
158
+
159
+ # Determine if the current node is a member of the 'solaris2' platform family.
160
+ #
161
+ # @param [Chef::Node] node the node to check
162
+ # @since 15.5
163
+ #
164
+ # @return [Boolean]
165
+ #
166
+ def solaris2?(node = __getnode)
167
+ node["platform_family"] == "solaris2"
168
+ end
169
+ # chef-sugar backcompat method
170
+ alias_method :solaris?, :solaris2?
171
+
172
+ # Determine if the current node is a member of the 'smartos' platform family.
173
+ #
174
+ # @param [Chef::Node] node the node to check
175
+ # @since 15.5
176
+ #
177
+ # @return [Boolean]
178
+ #
179
+ def smartos?(node = __getnode)
180
+ node["platform_family"] == "smartos"
181
+ end
182
+
183
+ # Determine if the current node is a member of the 'suse' platform family (openSUSE, SLES, and SLED).
184
+ #
185
+ # @param [Chef::Node] node the node to check
186
+ # @since 15.5
187
+ #
188
+ # @return [Boolean]
189
+ #
190
+ def suse?(node = __getnode)
191
+ node["platform_family"] == "suse"
192
+ end
193
+
194
+ # Determine if the current node is a member of the 'gentoo' platform family.
195
+ #
196
+ # @param [Chef::Node] node the node to check
197
+ # @since 15.5
198
+ #
199
+ # @return [Boolean]
200
+ #
201
+ def gentoo?(node = __getnode)
202
+ node["platform_family"] == "gentoo"
203
+ end
204
+
205
+ # Determine if the current node is a member of the 'freebsd' platform family.
206
+ #
207
+ # @param [Chef::Node] node the node to check
208
+ # @since 15.5
209
+ #
210
+ # @return [Boolean]
211
+ #
212
+ def freebsd?(node = __getnode)
213
+ node["platform_family"] == "freebsd"
214
+ end
215
+
216
+ # Determine if the current node is a member of the 'openbsd' platform family.
217
+ #
218
+ # @param [Chef::Node] node the node to check
219
+ # @since 15.5
220
+ #
221
+ # @return [Boolean]
222
+ #
223
+ def openbsd?(node = __getnode)
224
+ node["platform_family"] == "openbsd"
225
+ end
226
+
227
+ # Determine if the current node is a member of the 'netbsd' platform family.
228
+ #
229
+ # @param [Chef::Node] node the node to check
230
+ # @since 15.5
231
+ #
232
+ # @return [Boolean]
233
+ #
234
+ def netbsd?(node = __getnode)
235
+ node["platform_family"] == "netbsd"
236
+ end
237
+
238
+ # Determine if the current node is a member of the 'dragonflybsd' platform family.
239
+ #
240
+ # @param [Chef::Node] node the node to check
241
+ # @since 15.5
242
+ #
243
+ # @return [Boolean]
244
+ #
245
+ def dragonflybsd?(node = __getnode)
246
+ node["platform_family"] == "dragonflybsd"
247
+ end
248
+
249
+ # Determine if the current node is a member of the 'windows' platform family.
250
+ #
251
+ # @param [Chef::Node] node the node to check
252
+ # @since 15.5
253
+ #
254
+ # @return [Boolean]
255
+ #
256
+ def windows?(node = __getnode(true))
257
+ # This is all somewhat complicated. We prefer to get the node object so that chefspec can
258
+ # stub the node object. But we also have to deal with class-parsing time where there is
259
+ # no node object, so we have to fall back to RUBY_PLATFORM based detection. We cannot pull
260
+ # the node object out of the Chef.run_context.node global object here (which is what the
261
+ # false flag to __getnode is about) because some run-time code also cannot run under chefspec
262
+ # on non-windows where the node is stubbed to windows.
263
+ #
264
+ # As a result of this the `windows?` helper and the `ChefUtils.windows?` helper do not behave
265
+ # the same way in that the latter is not stubbable by chefspec.
266
+ #
267
+ node ? node["platform_family"] == "windows" : windows_ruby?
268
+ end
269
+
270
+ # Determine if the Ruby VM is currently running on a Windows node (ChefSpec can never stub
271
+ # this behavior, so this is useful for code which can never be parsed on a non-Windows box).
272
+ #
273
+ # @since 15.5
274
+ #
275
+ # @return [Boolean]
276
+ #
277
+ def windows_ruby?
278
+ !!(RUBY_PLATFORM =~ /mswin|mingw32|windows/)
279
+ end
280
+
281
+ #
282
+ # Platform-Family-like Helpers
283
+ #
284
+ # These are meta-helpers which address the issue that platform_family is single valued and cannot
285
+ # be an array while a tree-like Taxonomy is what is called for in some cases.
286
+ #
287
+
288
+ # If it uses RPM, it goes in here (rhel, fedora, amazon, suse platform_families). Deliberately does not
289
+ # include AIX because bff is AIX's primary package manager and adding it here would make this substantially
290
+ # less useful since in no way can AIX trace its lineage back to old redhat distros. This is most useful for
291
+ # "smells like redhat, including SuSE".
292
+ #
293
+ # @param [Chef::Node] node the node to check
294
+ # @since 15.5
295
+ #
296
+ # @return [Boolean]
297
+ #
298
+ def rpm_based?(node = __getnode)
299
+ fedora_derived?(node) || node["platform_family"] == "suse"
300
+ end
301
+
302
+ # RPM-based distros which are not SuSE and are very loosely similar to fedora, using yum or dnf. The historical
303
+ # lineage of the distro should have forked off from old redhat fedora distros at some point. Currently rhel,
304
+ # fedora and amazon. This is most useful for "smells like redhat, but isn't SuSE".
305
+ #
306
+ # @param [Chef::Node] node the node to check
307
+ # @since 15.5
308
+ #
309
+ # @return [Boolean]
310
+ #
311
+ def fedora_derived?(node = __getnode)
312
+ redhat_based?(node) || node["platform_family"] == "amazon"
313
+ end
314
+
315
+ # RedHat distros -- fedora and rhel platform_families, nothing else. This is most likely not as useful as the
316
+ # "fedora_derived?" helper.
317
+ #
318
+ # @param [Chef::Node] node the node to check
319
+ # @since 15.5
320
+ #
321
+ # @return [Boolean]
322
+ #
323
+ def redhat_based?(node = __getnode)
324
+ %w{rhel fedora}.include?(node["platform_family"])
325
+ end
326
+
327
+ # All of the Solaris-lineage.
328
+ #
329
+ # @param [Chef::Node] node the node to check
330
+ # @since 15.5
331
+ #
332
+ # @return [Boolean]
333
+ #
334
+ def solaris_based?(node = __getnode)
335
+ %w{solaris2 smartos omnios openindiana}.include?(node["platform"])
336
+ end
337
+
338
+ # All of the BSD-lineage.
339
+ #
340
+ # Note that macOS is not included since macOS deviates so significantly from BSD that including it would not be useful.
341
+ #
342
+ # @param [Chef::Node] node the node to check
343
+ # @since 15.5
344
+ #
345
+ # @return [Boolean]
346
+ #
347
+ def bsd_based?(node = __getnode)
348
+ # we could use os, platform_family or platform here equally
349
+ %w{netbsd freebsd openbsd dragonflybsd}.include?(node["platform"])
350
+ end
351
+
352
+ extend self
353
+ end
354
+ end
355
+ end