chef-utils 15.7.32 → 15.8.23

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74f53da2880ca1ca796c9cc0d52a3315d99a790120c4996c2b99be6e1cdfd2b9
4
- data.tar.gz: 91b7a00a02f44d22f174b0655d1431285f16bfff862a3942984767ccf2c9b299
3
+ metadata.gz: 8a28aa5def36bdd887baa21fa1bc954e013f2d96f0085a2394f7795d197c179d
4
+ data.tar.gz: 5fbdffc12d92275196fa30009a69409354a7a5a8e31b9c4ff7765383d6cec864
5
5
  SHA512:
6
- metadata.gz: 8c11c164763c9f57713ca5d238e0d0c44d13922d07662200be62569bc00a97bb9b11af9bcf825f3feda89b0cdfb09bc16146817a9dc6a345f99bd3e3f0f275e7
7
- data.tar.gz: 1a209177fb2bedf3760507bd7e2cc78845e9d21738dc54e6505d91671bbb3dafc3ef3920381dd3b52a61a0232bbe2325d03181a730b5a04a861baeabd4b080dc
6
+ metadata.gz: 27c83bfaddf110597458e442a50d7053c6a0487f0ef006a126857c2e34e074846e64781130e4e6dc3357236481e618543920d2266ea25d44a175da00f40a3982
7
+ data.tar.gz: b7dd58c04744d9318cfc7c23d55cef5089563b8b4501a5718d344ff2c7d84fe14d00368714ba7fe2efca36ab04a64bc586d4a0e11b4e7636e890db58703db8f7
data/lib/chef-utils.rb CHANGED
@@ -16,24 +16,31 @@
16
16
  #
17
17
 
18
18
  require_relative "chef-utils/dsl/architecture"
19
+ require_relative "chef-utils/dsl/cloud"
19
20
  require_relative "chef-utils/dsl/introspection"
20
21
  require_relative "chef-utils/dsl/os"
21
22
  require_relative "chef-utils/dsl/path_sanity"
22
23
  require_relative "chef-utils/dsl/platform"
23
24
  require_relative "chef-utils/dsl/platform_family"
25
+ require_relative "chef-utils/dsl/platform_version"
24
26
  require_relative "chef-utils/dsl/service"
25
27
  require_relative "chef-utils/dsl/train_helpers"
28
+ require_relative "chef-utils/dsl/virtualization"
26
29
  require_relative "chef-utils/dsl/which"
27
30
  require_relative "chef-utils/dsl/windows"
28
31
  require_relative "chef-utils/mash"
29
32
 
30
- # This is the Chef Infra Client DSL, not everytihng needs to go in here
33
+ # This is the Chef Infra Client DSL, not everything needs to go in here
31
34
  module ChefUtils
32
35
  include ChefUtils::DSL::Architecture
36
+ include ChefUtils::DSL::Cloud
37
+ include ChefUtils::DSL::Introspection
33
38
  include ChefUtils::DSL::OS
34
- include ChefUtils::DSL::PlatformFamily
35
39
  include ChefUtils::DSL::Platform
36
- include ChefUtils::DSL::Introspection
40
+ include ChefUtils::DSL::PlatformFamily
41
+ include ChefUtils::DSL::PlatformVersion
42
+ include ChefUtils::DSL::TrainHelpers
43
+ include ChefUtils::DSL::Virtualization
37
44
  include ChefUtils::DSL::Windows
38
45
  # FIXME: include ChefUtils::DSL::Which in Chef 16.0
39
46
  # FIXME: include ChefUtils::DSL::PathSanity in Chef 16.0
@@ -0,0 +1,134 @@
1
+ #
2
+ # Copyright:: Copyright 2018-2020, 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_relative "../internal"
19
+
20
+ module ChefUtils
21
+ module DSL
22
+ module Cloud
23
+ include Internal
24
+
25
+ # Determine if the current node is "in the cloud".
26
+ #
27
+ # @param [Chef::Node] node
28
+ #
29
+ # @return [Boolean]
30
+ #
31
+ def cloud?(node = __getnode)
32
+ node.key?("cloud")
33
+ end
34
+
35
+ # Return true if the current current node is in EC2
36
+ #
37
+ # @param [Chef::Node] node
38
+ #
39
+ # @return [Boolean]
40
+ #
41
+ def ec2?(node = __getnode)
42
+ node.key?("ec2")
43
+ end
44
+
45
+ # Return true if the current current node is in GCE
46
+ #
47
+ # @param [Chef::Node] node
48
+ #
49
+ # @return [Boolean]
50
+ #
51
+ def gce?(node = __getnode)
52
+ node.key?("gce")
53
+ end
54
+
55
+ # Return true if the current current node is in Rackspace
56
+ #
57
+ # @param [Chef::Node] node
58
+ #
59
+ # @return [Boolean]
60
+ #
61
+ def rackspace?(node = __getnode)
62
+ node.key?("rackspace")
63
+ end
64
+
65
+ # Return true if the current current node is in Eucalyptus
66
+ #
67
+ # @param [Chef::Node] node
68
+ #
69
+ # @return [Boolean]
70
+ #
71
+ def eucalyptus?(node = __getnode)
72
+ node.key?("eucalyptus")
73
+ end
74
+ # chef-sugar backcompat method
75
+ alias_method :euca?, :eucalyptus?
76
+
77
+ # Return true if the current current node is in Linode
78
+ #
79
+ # @param [Chef::Node] node
80
+ #
81
+ # @return [Boolean]
82
+ #
83
+ def linode?(node = __getnode)
84
+ node.key?("linode")
85
+ end
86
+
87
+ # Return true if the current current node is in Openstack
88
+ #
89
+ # @param [Chef::Node] node
90
+ #
91
+ # @return [Boolean]
92
+ #
93
+ def openstack?(node = __getnode)
94
+ node.key?("openstack")
95
+ end
96
+
97
+ # Return true if the current current node is in Azure
98
+ #
99
+ # @param [Chef::Node] node
100
+ #
101
+ # @return [Boolean]
102
+ #
103
+ def azure?(node = __getnode)
104
+ node.key?("azure")
105
+ end
106
+
107
+ # Return true if the current current node is in DigitalOcean
108
+ #
109
+ # @param [Chef::Node] node
110
+ # the node to check
111
+ #
112
+ # @return [Boolean]
113
+ #
114
+ def digital_ocean?(node = __getnode)
115
+ node.key?("digital_ocean")
116
+ end
117
+ # chef-sugar backcompat method
118
+ alias_method :digitalocean?, :digital_ocean?
119
+
120
+ # Return true if the current current node is in SoftLayer
121
+ #
122
+ # @param [Chef::Node] node
123
+ # the node to check
124
+ #
125
+ # @return [Boolean]
126
+ #
127
+ def softlayer?(node = __getnode)
128
+ node.key?("softlayer")
129
+ end
130
+
131
+ extend self
132
+ end
133
+ end
134
+ end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2018-2019, Chef Software Inc.
2
+ # Copyright:: Copyright 2018-2020, Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -97,6 +97,18 @@ module ChefUtils
97
97
  end
98
98
  end
99
99
 
100
+ # Determine if the current node includes the given recipe name.
101
+ #
102
+ # @param [String] recipe_name
103
+ #
104
+ # @return [Boolean]
105
+ #
106
+ def includes_recipe?(recipe_name, node = __getnode)
107
+ node.recipe?(recipe_name)
108
+ end
109
+ # chef-sugar backcompat method
110
+ alias_method :include_recipe?, :includes_recipe?
111
+
100
112
  extend self
101
113
  end
102
114
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2018-2019, Chef Software Inc.
2
+ # Copyright:: Copyright 2018-2020, Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,37 +33,41 @@ module ChefUtils
33
33
  #
34
34
  # @return [Boolean]
35
35
  #
36
- def linuxmint?(node = __getnode)
36
+ def linuxmint_platform?(node = __getnode)
37
37
  node["platform"] == "linuxmint"
38
38
  end
39
- # chef-sugar backcompat methods
40
- alias_method :mint?, :linuxmint?
41
- alias_method :linux_mint?, :linuxmint?
42
- alias_method :linuxmint_platform?, :linuxmint?
39
+ # chef-sugar backcompat method
40
+ alias_method :mint?, :linuxmint_platform?
41
+ # chef-sugar backcompat method
42
+ alias_method :linux_mint?, :linuxmint_platform?
43
+ # chef-sugar backcompat method
44
+ alias_method :linuxmint?, :linuxmint_platform?
43
45
 
44
- # Determine if the current node is ubuntu.
46
+ # Determine if the current node is Ubuntu.
45
47
  #
46
48
  # @param [Chef::Node] node
47
49
  #
48
50
  # @return [Boolean]
49
51
  #
50
- def ubuntu?(node = __getnode)
52
+ def ubuntu_platform?(node = __getnode)
51
53
  node["platform"] == "ubuntu"
52
54
  end
53
- alias_method :ubuntu_platform?, :ubuntu?
55
+ # chef-sugar backcompat method
56
+ alias_method :ubuntu?, :ubuntu_platform?
54
57
 
55
- # Determine if the current node is raspbian.
58
+ # Determine if the current node is Raspbian.
56
59
  #
57
60
  # @param [Chef::Node] node
58
61
  #
59
62
  # @return [Boolean]
60
63
  #
61
- def raspbian?(node = __getnode)
64
+ def raspbian_platform?(node = __getnode)
62
65
  node["platform"] == "raspbian"
63
66
  end
64
- alias_method :raspbian_platform?, :raspbian?
67
+ # chef-sugar backcompat method
68
+ alias_method :raspbian?, :raspbian_platform?
65
69
 
66
- # Determine if the current node is debian.
70
+ # Determine if the current node is Debian.
67
71
  #
68
72
  # @param [Chef::Node] node
69
73
  #
@@ -73,7 +77,7 @@ module ChefUtils
73
77
  node["platform"] == "debian"
74
78
  end
75
79
 
76
- # Determine if the current node is amazon linux.
80
+ # Determine if the current node is Amazon Linux.
77
81
  #
78
82
  # @param [Chef::Node] node
79
83
  #
@@ -83,69 +87,75 @@ module ChefUtils
83
87
  node["platform"] == "amazon"
84
88
  end
85
89
 
86
- # Determine if the current node is redhat enterprise.
90
+ # Determine if the current node is Red Hat Enterprise Linux.
87
91
  #
88
92
  # @param [Chef::Node] node
89
93
  #
90
94
  # @return [Boolean]
91
95
  #
92
- def redhat?(node = __getnode)
96
+ def redhat_platform?(node = __getnode)
93
97
  node["platform"] == "redhat"
94
98
  end
95
- # chef-sugar backcompat methods
96
- alias_method :redhat_enterprise?, :redhat?
97
- alias_method :redhat_enterprise_linux?, :redhat?
98
- alias_method :redhat_platform?, :redhat?
99
+ # chef-sugar backcompat method
100
+ alias_method :redhat_enterprise?, :redhat_platform?
101
+ # chef-sugar backcompat method
102
+ alias_method :redhat_enterprise_linux?, :redhat_platform?
103
+ # chef-sugar backcompat method
104
+ alias_method :redhat?, :redhat_platform?
99
105
 
100
- # Determine if the current node is centos.
106
+ # Determine if the current node is CentOS.
101
107
  #
102
108
  # @param [Chef::Node] node
103
109
  #
104
110
  # @return [Boolean]
105
111
  #
106
- def centos?(node = __getnode)
112
+ def centos_platform?(node = __getnode)
107
113
  node["platform"] == "centos"
108
114
  end
109
- alias_method :centos_platform?, :centos?
115
+ # chef-sugar backcompat method
116
+ alias_method :centos?, :centos_platform?
110
117
 
111
- # Determine if the current node is oracle linux.
118
+ # Determine if the current node is Oracle Linux.
112
119
  #
113
120
  # @param [Chef::Node] node
114
121
  #
115
122
  # @return [Boolean]
116
123
  #
117
- def oracle?(node = __getnode)
124
+ def oracle_platform?(node = __getnode)
118
125
  node["platform"] == "oracle"
119
126
  end
120
- # chef-sugar backcompat methods
121
- alias_method :oracle_linux?, :oracle?
122
- alias_method :oracle_platform?, :oracle?
127
+ # chef-sugar backcompat method
128
+ alias_method :oracle_linux?, :oracle_platform?
129
+ # chef-sugar backcompat method
130
+ alias_method :oracle?, :oracle_platform?
123
131
 
124
- # Determine if the current node is scientific linux.
132
+ # Determine if the current node is Scientific Linux.
125
133
  #
126
134
  # @param [Chef::Node] node
127
135
  #
128
136
  # @return [Boolean]
129
137
  #
130
- def scientific?(node = __getnode)
138
+ def scientific_platform?(node = __getnode)
131
139
  node["platform"] == "scientific"
132
140
  end
133
- # chef-sugar backcompat methods
134
- alias_method :scientific_linux?, :scientific?
135
- alias_method :scientific_platform?, :scientific?
141
+ # chef-sugar backcompat method
142
+ alias_method :scientific_linux?, :scientific_platform?
143
+ # chef-sugar backcompat method
144
+ alias_method :scientific?, :scientific_platform?
136
145
 
137
- # Determine if the current node is clearos.
146
+ # Determine if the current node is ClearOS.
138
147
  #
139
148
  # @param [Chef::Node] node
140
149
  #
141
150
  # @return [Boolean]
142
151
  #
143
- def clearos?(node = __getnode)
152
+ def clearos_platform?(node = __getnode)
144
153
  node["platform"] == "clearos"
145
154
  end
146
- alias_method :clearos_platform?, :clearos?
155
+ # chef-sugar backcompat method
156
+ alias_method :clearos?, :clearos_platform?
147
157
 
148
- # Determine if the current node is fedora.
158
+ # Determine if the current node is Fedora.
149
159
  #
150
160
  # @param [Chef::Node] node
151
161
  #
@@ -155,7 +165,7 @@ module ChefUtils
155
165
  node["platform"] == "fedora"
156
166
  end
157
167
 
158
- # Determine if the current node is arch
168
+ # Determine if the current node is Arch Linux
159
169
  #
160
170
  # @param [Chef::Node] node
161
171
  #
@@ -165,7 +175,7 @@ module ChefUtils
165
175
  node["platform"] == "arch"
166
176
  end
167
177
 
168
- # Determine if the current node is solaris2
178
+ # Determine if the current node is Solaris2.
169
179
  #
170
180
  # @param [Chef::Node] node
171
181
  #
@@ -175,7 +185,7 @@ module ChefUtils
175
185
  node["platform"] == "solaris2"
176
186
  end
177
187
 
178
- # Determine if the current node is smartos
188
+ # Determine if the current node is SmartOS.
179
189
  #
180
190
  # @param [Chef::Node] node
181
191
  #
@@ -185,40 +195,43 @@ module ChefUtils
185
195
  node["platform"] == "smartos"
186
196
  end
187
197
 
188
- # Determine if the current node is omnios
198
+ # Determine if the current node is OmniOS.
189
199
  #
190
200
  # @param [Chef::Node] node
191
201
  #
192
202
  # @return [Boolean]
193
203
  #
194
- def omnios?(node = __getnode)
204
+ def omnios_platform?(node = __getnode)
195
205
  node["platform"] == "omnios"
196
206
  end
197
- alias_method :omnios_platform?, :omnios?
207
+ # chef-sugar backcompat method
208
+ alias_method :omnios?, :omnios_platform?
198
209
 
199
- # Determine if the current node is openindiana
210
+ # Determine if the current node is OpenIndiana.
200
211
  #
201
212
  # @param [Chef::Node] node
202
213
  #
203
214
  # @return [Boolean]
204
215
  #
205
- def openindiana?(node = __getnode)
216
+ def openindiana_platform?(node = __getnode)
206
217
  node["platform"] == "openindiana"
207
218
  end
208
- alias_method :openindiana_platform?, :openindiana?
219
+ # chef-sugar backcompat method
220
+ alias_method :openindiana?, :openindiana_platform?
209
221
 
210
- # Determine if the current node is nexentacore
222
+ # Determine if the current node is Nexenta Core Platform aka Nexenta OS.
211
223
  #
212
224
  # @param [Chef::Node] node
213
225
  #
214
226
  # @return [Boolean]
215
227
  #
216
- def nexentacore?(node = __getnode)
228
+ def nexentacore_platform?(node = __getnode)
217
229
  node["platform"] == "nexentacore"
218
230
  end
219
- alias_method :nexentacore_platform?, :nexentacore?
231
+ # chef-sugar backcompat method
232
+ alias_method :nexentacore?, :nexentacore_platform?
220
233
 
221
- # Determine if the current node is aix
234
+ # Determine if the current node is AIX.
222
235
  #
223
236
  # @param [Chef::Node] node
224
237
  #
@@ -228,7 +241,7 @@ module ChefUtils
228
241
  node["platform"] == "aix"
229
242
  end
230
243
 
231
- # Determine if the current node is freebsd
244
+ # Determine if the current node is FreeBSD.
232
245
  #
233
246
  # @param [Chef::Node] node
234
247
  #
@@ -238,7 +251,7 @@ module ChefUtils
238
251
  node["platform"] == "freebsd"
239
252
  end
240
253
 
241
- # Determine if the current node is openbsd
254
+ # Determine if the current node is OpenBSD.
242
255
  #
243
256
  # @param [Chef::Node] node
244
257
  #
@@ -248,7 +261,7 @@ module ChefUtils
248
261
  node["platform"] == "openbsd"
249
262
  end
250
263
 
251
- # Determine if the current node is netbsd
264
+ # Determine if the current node is NetBSD.
252
265
  #
253
266
  # @param [Chef::Node] node
254
267
  #
@@ -258,7 +271,7 @@ module ChefUtils
258
271
  node["platform"] == "netbsd"
259
272
  end
260
273
 
261
- # Determine if the current node is dragonflybsd
274
+ # Determine if the current node is DragonFly BSD.
262
275
  #
263
276
  # @param [Chef::Node] node
264
277
  #
@@ -268,7 +281,7 @@ module ChefUtils
268
281
  node["platform"] == "dragonfly"
269
282
  end
270
283
 
271
- # Determine if the current node is MacOS.
284
+ # Determine if the current node is macOS.
272
285
  #
273
286
  # @param [Chef::Node] node
274
287
  #
@@ -277,9 +290,10 @@ module ChefUtils
277
290
  def macos_platform?(node = __getnode)
278
291
  node["platform"] == "mac_os_x"
279
292
  end
293
+ # chef-sugar backcompat method
280
294
  alias_method :mac_os_x_platform?, :macos_platform?
281
295
 
282
- # Determine if the current node is gentoo
296
+ # Determine if the current node is Gentoo.
283
297
  #
284
298
  # @param [Chef::Node] node
285
299
  #
@@ -289,7 +303,7 @@ module ChefUtils
289
303
  node["platform"] == "gentoo"
290
304
  end
291
305
 
292
- # Determine if the current node is slackware.
306
+ # Determine if the current node is Slackware.
293
307
  #
294
308
  # @param [Chef::Node] node
295
309
  #
@@ -309,18 +323,21 @@ module ChefUtils
309
323
  node["platform"] == "suse"
310
324
  end
311
325
 
312
- # Determine if the current node is OpenSuSE.
326
+ # Determine if the current node is OpenSUSE.
313
327
  #
314
328
  # @param [Chef::Node] node
315
329
  #
316
330
  # @return [Boolean]
317
331
  #
318
- def opensuse?(node = __getnode)
332
+ def opensuse_platform?(node = __getnode)
319
333
  node["platform"] == "opensuse" || node["platform"] == "opensuseleap"
320
334
  end
321
- alias_method :opensuse_platform?, :opensuse?
322
- alias_method :opensuseleap_platform?, :opensuse?
323
- alias_method :leap_platform?, :opensuse?
335
+ # chef-sugar backcompat method
336
+ alias_method :opensuse?, :opensuse_platform?
337
+ # chef-sugar backcompat method
338
+ alias_method :opensuseleap_platform?, :opensuse_platform?
339
+ # chef-sugar backcompat method
340
+ alias_method :leap_platform?, :opensuse_platform?
324
341
  # NOTE: to anyone adding :tumbleweed_platform? - :[opensuse]leap_platform? should be false on tumbleweed, :opensuse[_platform]? should be true
325
342
 
326
343
  # Determine if the current node is Windows.
@@ -31,7 +31,7 @@ module ChefUtils
31
31
  def arch?(node = __getnode)
32
32
  node["platform_family"] == "arch"
33
33
  end
34
- # chef-sugar backcompat methods
34
+ # chef-sugar backcompat method
35
35
  alias_method :arch_linux?, :arch?
36
36
 
37
37
  # Determine if the current node is a member of the 'aix' platform family.
@@ -73,8 +73,11 @@ module ChefUtils
73
73
  def macos?(node = __getnode)
74
74
  node["platform_family"] == "mac_os_x"
75
75
  end
76
+ # chef-sugar backcompat method
76
77
  alias_method :osx?, :macos?
78
+ # chef-sugar backcompat method
77
79
  alias_method :mac?, :macos?
80
+ # chef-sugar backcompat method
78
81
  alias_method :mac_os_x?, :macos?
79
82
 
80
83
  # 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).
@@ -86,9 +89,10 @@ module ChefUtils
86
89
  def rhel?(node = __getnode)
87
90
  node["platform_family"] == "rhel"
88
91
  end
92
+ # chef-sugar backcompat method
89
93
  alias_method :el?, :rhel?
90
94
 
91
- # Determine if the current node is a rhel6 compatible build (Red Hat, CentOS, Oracle or Scientific Linux)
95
+ # Determine if the current node is a rhel6 compatible build (Red Hat, CentOS, Oracle or Scientific Linux).
92
96
  #
93
97
  # @param [Chef::Node] node
94
98
  #
@@ -98,7 +102,7 @@ module ChefUtils
98
102
  node["platform_family"] == "rhel" && node["platform_version"].to_f >= 6.0 && node["platform_version"].to_f < 7.0
99
103
  end
100
104
 
101
- # Determine if the current node is a rhel7 compatible build (Red Hat, CentOS, Oracle or Scientific Linux)
105
+ # Determine if the current node is a rhel7 compatible build (Red Hat, CentOS, Oracle or Scientific Linux).
102
106
  #
103
107
  # @param [Chef::Node] node
104
108
  #
@@ -108,7 +112,7 @@ module ChefUtils
108
112
  node["platform_family"] == "rhel" && node["platform_version"].to_f >= 7.0 && node["platform_version"].to_f < 8.0
109
113
  end
110
114
 
111
- # Determine if the current node is a rhel8 compatible build (Red Hat, CentOS, Oracle or Scientific Linux)
115
+ # Determine if the current node is a rhel8 compatible build (Red Hat, CentOS, Oracle or Scientific Linux).
112
116
  #
113
117
  # @param [Chef::Node] node
114
118
  #
@@ -127,6 +131,7 @@ module ChefUtils
127
131
  def amazon?(node = __getnode)
128
132
  node["platform_family"] == "amazon"
129
133
  end
134
+ # chef-sugar backcompat method
130
135
  alias_method :amazon_linux?, :amazon?
131
136
 
132
137
  # Determine if the current node is a member of the 'solaris2' platform family.
@@ -138,7 +143,7 @@ module ChefUtils
138
143
  def solaris2?(node = __getnode)
139
144
  node["platform_family"] == "solaris2"
140
145
  end
141
- # chef-sugar backcompat methods
146
+ # chef-sugar backcompat method
142
147
  alias_method :solaris?, :solaris2?
143
148
 
144
149
  # Determine if the current node is a member of the 'smartos' platform family.
@@ -0,0 +1,40 @@
1
+ #
2
+ # Copyright:: Copyright 2018-2020, 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_relative "../internal"
19
+
20
+ module ChefUtils
21
+ module DSL
22
+ module PlatformVersion
23
+ include Internal
24
+
25
+ # Return the platform_version for the node. Acts like a String
26
+ # but also provides a mechanism for checking version constraints.
27
+ #
28
+ # @param [Chef::Node] node the node to check
29
+ # @since 15.8
30
+ #
31
+ # @return [ChefUtils::VersionString]
32
+ #
33
+ def platform_version(node = __getnode)
34
+ ChefUtils::VersionString.new(node["platform_version"])
35
+ end
36
+
37
+ extend self
38
+ end
39
+ end
40
+ end
@@ -66,6 +66,15 @@ module ChefUtils
66
66
  file_exist?("/sbin/chkconfig")
67
67
  end
68
68
 
69
+ #
70
+ # Returns if a particular service exists for a particular service init system. Init systems may be :initd, :upstart, :etc_rcd, :xinetd, and :systemd. Example: service_script_exist?(:systemd, 'ntpd')
71
+ #
72
+ # @param [Symbol] type The type of init system. :initd, :upstart, :xinetd, :etc_rcd, or :systemd
73
+ # @param [String] script The name of the service
74
+ # @since 15.5
75
+ #
76
+ # @return [Boolean]
77
+ #
69
78
  def service_script_exist?(type, script)
70
79
  case type
71
80
  when :initd
@@ -0,0 +1,249 @@
1
+ #
2
+ # Copyright:: Copyright 2018-2020, 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_relative "../internal"
19
+
20
+ module ChefUtils
21
+ module DSL
22
+ module Virtualization
23
+ include Internal
24
+
25
+ # Determine if the current node is a KVM guest.
26
+ #
27
+ # @param [Chef::Node] node
28
+ # @since 15.8
29
+ #
30
+ # @return [Boolean]
31
+ #
32
+ def kvm?(node = __getnode)
33
+ node.dig("virtualization", "system") == "kvm" && node.dig("virtualization", "role") == "guest"
34
+ end
35
+
36
+ # Determine if the current node is a KVM host.
37
+ #
38
+ # @param [Chef::Node] node
39
+ # @since 15.8
40
+ #
41
+ # @return [Boolean]
42
+ #
43
+ def kvm_host?(node = __getnode)
44
+ node.dig("virtualization", "system") == "kvm" && node.dig("virtualization", "role") == "host"
45
+ end
46
+
47
+ # Determine if the current node is running in a linux container.
48
+ #
49
+ # @param [Chef::Node] node
50
+ # @since 15.8
51
+ #
52
+ # @return [Boolean]
53
+ #
54
+ def lxc?(node = __getnode)
55
+ node.dig("virtualization", "system") == "lxc" && node.dig("virtualization", "role") == "guest"
56
+ end
57
+
58
+ # Determine if the current node is a linux container host.
59
+ #
60
+ # @param [Chef::Node] node
61
+ # @since 15.8
62
+ #
63
+ # @return [Boolean]
64
+ #
65
+ def lxc_host?(node = __getnode)
66
+ node.dig("virtualization", "system") == "lxc" && node.dig("virtualization", "role") == "host"
67
+ end
68
+
69
+ # Determine if the current node is running under Parallels Desktop.
70
+ #
71
+ # @param [Chef::Node] node
72
+ # @since 15.8
73
+ #
74
+ # @return [Boolean]
75
+ # true if the machine is currently running under Parallels Desktop, false
76
+ # otherwise
77
+ #
78
+ def parallels?(node = __getnode)
79
+ node.dig("virtualization", "system") == "parallels" && node.dig("virtualization", "role") == "guest"
80
+ end
81
+
82
+ # Determine if the current node is a Parallels Desktop host.
83
+ #
84
+ # @param [Chef::Node] node
85
+ # @since 15.8
86
+ #
87
+ # @return [Boolean]
88
+ # true if the machine is currently running under Parallels Desktop, false
89
+ # otherwise
90
+ #
91
+ def parallels_host?(node = __getnode)
92
+ node.dig("virtualization", "system") == "parallels" && node.dig("virtualization", "role") == "host"
93
+ end
94
+
95
+ # Determine if the current node is a VirtualBox guest.
96
+ #
97
+ # @param [Chef::Node] node
98
+ # @since 15.8
99
+ #
100
+ # @return [Boolean]
101
+ #
102
+ def vbox?(node = __getnode)
103
+ node.dig("virtualization", "system") == "vbox" && node.dig("virtualization", "role") == "guest"
104
+ end
105
+
106
+ # Determine if the current node is a VirtualBox host.
107
+ #
108
+ # @param [Chef::Node] node
109
+ # @since 15.8
110
+ #
111
+ # @return [Boolean]
112
+ #
113
+ def vbox_host?(node = __getnode)
114
+ node.dig("virtualization", "system") == "vbox" && node.dig("virtualization", "role") == "host"
115
+ end
116
+
117
+ # chef-sugar backcompat method
118
+ alias_method :virtualbox?, :vbox?
119
+
120
+ # Determine if the current node is a VMWare guest.
121
+ #
122
+ # @param [Chef::Node] node
123
+ # @since 15.8
124
+ #
125
+ # @return [Boolean]
126
+ #
127
+ def vmware?(node = __getnode)
128
+ node.dig("virtualization", "system") == "vmware" && node.dig("virtualization", "role") == "guest"
129
+ end
130
+
131
+ # Determine if the current node is VMware host.
132
+ #
133
+ # @param [Chef::Node] node
134
+ # @since 15.8
135
+ #
136
+ # @return [Boolean]
137
+ #
138
+ def vmware_host?(node = __getnode)
139
+ node.dig("virtualization", "system") == "vmware" && node.dig("virtualization", "role") == "host"
140
+ end
141
+
142
+ # Determine if the current node is an openvz guest.
143
+ #
144
+ # @param [Chef::Node] node
145
+ # @since 15.8
146
+ #
147
+ # @return [Boolean]
148
+ #
149
+ def openvz?(node = __getnode)
150
+ node.dig("virtualization", "system") == "openvz" && node.dig("virtualization", "role") == "guest"
151
+ end
152
+
153
+ # Determine if the current node is an openvz host.
154
+ #
155
+ # @param [Chef::Node] node
156
+ # @since 15.8
157
+ #
158
+ # @return [Boolean]
159
+ #
160
+ def openvz_host?(node = __getnode)
161
+ node.dig("virtualization", "system") == "openvz" && node.dig("virtualization", "role") == "host"
162
+ end
163
+
164
+ # Determine if the current node is running under any virutalization environment
165
+ #
166
+ # @param [Chef::Node] node
167
+ # @since 15.8
168
+ #
169
+ # @return [Boolean]
170
+ #
171
+ def guest?(node = __getnode)
172
+ node.dig("virtualization", "role") == "guest"
173
+ end
174
+
175
+ # chef-sugar backcompat method
176
+ alias_method :virtual?, :guest?
177
+
178
+ # Determine if the current node supports running guests under any virtualization environment
179
+ #
180
+ # @param [Chef::Node] node
181
+ # @since 15.8
182
+ #
183
+ # @return [Boolean]
184
+ #
185
+ def hypervisor?(node = __getnode)
186
+ node.dig("virtualization", "role") == "host"
187
+ end
188
+
189
+ # Determine if the current node is NOT running under any virtualization environment (bare-metal or hypervisor on metal)
190
+ #
191
+ # @param [Chef::Node] node
192
+ # @since 15.8
193
+ #
194
+ # @return [Boolean]
195
+ #
196
+ def physical?(node = __getnode)
197
+ !virtual?(node)
198
+ end
199
+
200
+ # Determine if the current node is running as a vagrant guest.
201
+ #
202
+ # Note that this API is equivalent to just looking for the vagrant user or the
203
+ # vagrantup.com domain in the hostname, which is the best API we have.
204
+ #
205
+ # @param [Chef::Node] node
206
+ # @since 15.8
207
+ #
208
+ # @return [Boolean]
209
+ # true if the machine is currently running vagrant, false
210
+ # otherwise
211
+ #
212
+ def vagrant?(node = __getnode)
213
+ vagrant_key?(node) || vagrant_domain?(node) || vagrant_user?(node)
214
+ end
215
+
216
+ private
217
+
218
+ # Check if the +vagrant+ key exists on the +node+ object. This key is no
219
+ # longer populated by vagrant, but it is kept around for legacy purposes.
220
+ #
221
+ # @param (see vagrant?)
222
+ # @return (see vagrant?)
223
+ #
224
+ def vagrant_key?(node = __getnode)
225
+ node.key?("vagrant")
226
+ end
227
+
228
+ # Check if "vagrantup.com" is included in the node's domain.
229
+ #
230
+ # @param (see vagrant?)
231
+ # @return (see vagrant?)
232
+ #
233
+ def vagrant_domain?(node = __getnode)
234
+ node.key?("domain") && !node["domain"].nil? && node["domain"].include?("vagrantup.com")
235
+ end
236
+
237
+ # Check if the system contains a +vagrant+ user.
238
+ #
239
+ # @param (see vagrant?)
240
+ # @return (see vagrant?)
241
+ #
242
+ def vagrant_user?(node = __getnode)
243
+ !!(Etc.getpwnam("vagrant") rescue nil)
244
+ end
245
+
246
+ extend self
247
+ end
248
+ end
249
+ end
@@ -20,6 +20,8 @@ require_relative "../internal"
20
20
  module ChefUtils
21
21
  module DSL
22
22
  module Windows
23
+ require "chef-utils/version_string"
24
+
23
25
  include Internal
24
26
 
25
27
  # Determine if the current node is Windows Server Core.
@@ -52,6 +54,26 @@ module ChefUtils
52
54
  node["kernel"]["product_type"] == "Server"
53
55
  end
54
56
 
57
+ # Determine the current Windows NT version. The NT version often differs from the marketing version, but offers a good way to find desktop and server releases that are based on the same codebase. IE: NT 6.3 is Windows 8.1 and Windows 2012 R2.
58
+ #
59
+ # @param [Chef::Node] node
60
+ #
61
+ # @return [ChefUtils::VersionString]
62
+ #
63
+ def windows_nt_version(node = __getnode)
64
+ ChefUtils::VersionString.new(node["os_version"])
65
+ end
66
+
67
+ # Determine the installed version of PowerShell
68
+ #
69
+ # @param [Chef::Node] node
70
+ #
71
+ # @return [ChefUtils::VersionString]
72
+ #
73
+ def powershell_version(node = __getnode)
74
+ ChefUtils::VersionString.new(node["languages"]["powershell"]["version"])
75
+ end
76
+
55
77
  extend self
56
78
  end
57
79
  end
@@ -15,5 +15,5 @@
15
15
 
16
16
  module ChefUtils
17
17
  CHEFUTILS_ROOT = File.expand_path("../..", __FILE__)
18
- VERSION = "15.7.32".freeze
18
+ VERSION = "15.8.23".freeze
19
19
  end
@@ -139,5 +139,11 @@ module ChefUtils
139
139
  end
140
140
  end
141
141
 
142
+ # Back-compat API for chef-sugar. The other APIs are preferable.
143
+ #
144
+ # @api private
145
+ def satisfies?(*constraints)
146
+ Gem::Requirement.new(*constraints).satisfied_by?(@parsed_version)
147
+ end
142
148
  end
143
149
  end
data/spec/spec_helper.rb CHANGED
@@ -3,21 +3,25 @@ require "chef-utils"
3
3
  # FIXME: dynamically generate this for accuracy
4
4
  HELPER_MODULES = [
5
5
  ChefUtils::DSL::Architecture,
6
+ ChefUtils::DSL::Cloud,
6
7
  ChefUtils::DSL::Introspection,
7
8
  ChefUtils::DSL::OS,
8
9
  ChefUtils::DSL::PathSanity,
9
10
  ChefUtils::DSL::Platform,
10
11
  ChefUtils::DSL::PlatformFamily,
11
12
  ChefUtils::DSL::Service,
13
+ ChefUtils::DSL::Virtualization,
12
14
  ChefUtils::DSL::Which,
13
15
  ChefUtils::DSL::Windows,
14
16
  ].freeze
15
17
 
16
18
  ARCH_HELPERS = (ChefUtils::DSL::Architecture.methods - Module.methods).freeze
19
+ CLOUD_HELPERS = (ChefUtils::DSL::Cloud.methods - Module.methods).freeze
20
+ INTROSPECTION_HELPERS = (ChefUtils::DSL::Introspection.methods - Module.methods).freeze
17
21
  OS_HELPERS = (ChefUtils::DSL::OS.methods - Module.methods).freeze
18
- PLATFORM_HELPERS = (ChefUtils::DSL::Platform.methods - Module.methods).freeze
19
22
  PLATFORM_FAMILY_HELPERS = (ChefUtils::DSL::PlatformFamily.methods - Module.methods).freeze
20
- INTROSPECTION_HELPERS = (ChefUtils::DSL::Introspection.methods - Module.methods).freeze
23
+ PLATFORM_HELPERS = (ChefUtils::DSL::Platform.methods - Module.methods).freeze
24
+ VIRTUALIZATION_HELPERS = (ChefUtils::DSL::Virtualization.methods - Module.methods).freeze
21
25
  WINDOWS_HELPERS = (ChefUtils::DSL::Windows.methods - Module.methods).freeze
22
26
 
23
27
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
@@ -0,0 +1,82 @@
1
+ #
2
+ # Copyright:: Copyright 2018-2020, 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 "fauxhai"
20
+
21
+ def cloud_reports_true_for(*args, node:)
22
+ args.each do |method|
23
+ it "reports true for #{method}" do
24
+ expect(described_class.send(method, node)).to be true
25
+ end
26
+ end
27
+ (CLOUD_HELPERS - args).each do |method|
28
+ it "reports false for #{method}" do
29
+ expect(described_class.send(method, node)).to be false
30
+ end
31
+ end
32
+ end
33
+
34
+ RSpec.describe ChefUtils::DSL::Cloud do
35
+ ( HELPER_MODULES - [ described_class ] ).each do |klass|
36
+ it "does not have methods that collide with #{klass}" do
37
+ expect((klass.methods - Module.methods) & CLOUD_HELPERS).to be_empty
38
+ end
39
+ end
40
+
41
+ CLOUD_HELPERS.each do |helper|
42
+ it "has the #{helper} in the ChefUtils module" do
43
+ expect(ChefUtils).to respond_to(helper)
44
+ end
45
+ end
46
+
47
+ context "on ec2" do
48
+ cloud_reports_true_for(:cloud?, :ec2?, node: { "ec2" => {}, "cloud" => {} })
49
+ end
50
+
51
+ context "on gce" do
52
+ cloud_reports_true_for(:cloud?, :gce?, node: { "gce" => {}, "cloud" => {} })
53
+ end
54
+
55
+ context "on rackspace" do
56
+ cloud_reports_true_for(:cloud?, :rackspace?, node: { "rackspace" => {}, "cloud" => {} })
57
+ end
58
+
59
+ context "on eucalyptus" do
60
+ cloud_reports_true_for(:cloud?, :eucalyptus?, :euca?, node: { "eucalyptus" => {}, "cloud" => {} })
61
+ end
62
+
63
+ context "on linode" do
64
+ cloud_reports_true_for(:cloud?, :linode?, node: { "linode" => {}, "cloud" => {} })
65
+ end
66
+
67
+ context "on openstack" do
68
+ cloud_reports_true_for(:cloud?, :openstack?, node: { "openstack" => {}, "cloud" => {} })
69
+ end
70
+
71
+ context "on azure" do
72
+ cloud_reports_true_for(:cloud?, :azure?, node: { "azure" => {}, "cloud" => {} })
73
+ end
74
+
75
+ context "on digital_ocean" do
76
+ cloud_reports_true_for(:cloud?, :digital_ocean?, :digitalocean?, node: { "digital_ocean" => {}, "cloud" => {} })
77
+ end
78
+
79
+ context "on softlayer" do
80
+ cloud_reports_true_for(:cloud?, :softlayer?, node: { "softlayer" => {}, "cloud" => {} })
81
+ end
82
+ end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2018-2019, Chef Software Inc.
2
+ # Copyright:: Copyright 2018-2020, Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -165,4 +165,23 @@ RSpec.describe ChefUtils::DSL::Introspection do
165
165
  end
166
166
  end
167
167
  end
168
+
169
+ context "#include_recipe?" do
170
+ it "is true when the recipe has been seen by the node" do
171
+ expect(node).to receive(:recipe?).with("myrecipe").and_return(true)
172
+ expect(ChefUtils.include_recipe?("myrecipe", node)).to be true
173
+ end
174
+ it "is false when the recipe has not been seen by the node" do
175
+ expect(node).to receive(:recipe?).with("myrecipe").and_return(false)
176
+ expect(ChefUtils.include_recipe?("myrecipe", node)).to be false
177
+ end
178
+ it "the alias is true when the recipe has been seen by the node" do
179
+ expect(node).to receive(:recipe?).with("myrecipe").and_return(true)
180
+ expect(ChefUtils.includes_recipe?("myrecipe", node)).to be true
181
+ end
182
+ it "the alias is false when the recipe has not been seen by the node" do
183
+ expect(node).to receive(:recipe?).with("myrecipe").and_return(false)
184
+ expect(ChefUtils.includes_recipe?("myrecipe", node)).to be false
185
+ end
186
+ end
168
187
  end
@@ -0,0 +1,74 @@
1
+ #
2
+ # Copyright:: Copyright 2018-2020, 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 "fauxhai"
20
+
21
+ def virtualization_reports_true_for(*args, node:)
22
+ args.each do |method|
23
+ it "reports true for #{method}" do
24
+ expect(described_class.send(method, node)).to be true
25
+ end
26
+ end
27
+ (VIRTUALIZATION_HELPERS - args).each do |method|
28
+ it "reports false for #{method}" do
29
+ expect(described_class.send(method, node)).to be false
30
+ end
31
+ end
32
+ end
33
+
34
+ RSpec.describe ChefUtils::DSL::Virtualization do
35
+ ( HELPER_MODULES - [ described_class ] ).each do |klass|
36
+ it "does not have methods that collide with #{klass}" do
37
+ expect((klass.methods - Module.methods) & VIRTUALIZATION_HELPERS).to be_empty
38
+ end
39
+ end
40
+
41
+ VIRTUALIZATION_HELPERS.each do |helper|
42
+ it "has the #{helper} in the ChefUtils module" do
43
+ expect(ChefUtils).to respond_to(helper)
44
+ end
45
+ end
46
+
47
+ context "on kvm" do
48
+ virtualization_reports_true_for(:guest?, :virtual?, :kvm?, node: { "virtualization" => { "system" => "kvm", "role" => "guest" } })
49
+ virtualization_reports_true_for(:hypervisor?, :physical?, :kvm_host?, node: { "virtualization" => { "system" => "kvm", "role" => "host" } })
50
+ end
51
+ context "on lxc" do
52
+ virtualization_reports_true_for(:guest?, :virtual?, :lxc?, node: { "virtualization" => { "system" => "lxc", "role" => "guest" } })
53
+ virtualization_reports_true_for(:hypervisor?, :physical?, :lxc_host?, node: { "virtualization" => { "system" => "lxc", "role" => "host" } })
54
+ end
55
+ context "on parallels" do
56
+ virtualization_reports_true_for(:guest?, :virtual?, :parallels?, node: { "virtualization" => { "system" => "parallels", "role" => "guest" } })
57
+ virtualization_reports_true_for(:hypervisor?, :physical?, :parallels_host?, node: { "virtualization" => { "system" => "parallels", "role" => "host" } })
58
+ end
59
+ context "on virtualbox" do
60
+ virtualization_reports_true_for(:guest?, :virtual?, :virtualbox?, :vbox?, node: { "virtualization" => { "system" => "vbox", "role" => "guest" } })
61
+ virtualization_reports_true_for(:hypervisor?, :physical?, :vbox_host?, node: { "virtualization" => { "system" => "vbox", "role" => "host" } })
62
+ end
63
+ context "on vmware" do
64
+ virtualization_reports_true_for(:guest?, :virtual?, :vmware?, node: { "virtualization" => { "system" => "vmware", "role" => "guest" } })
65
+ virtualization_reports_true_for(:hypervisor?, :physical?, :vmware_host?, node: { "virtualization" => { "system" => "vmware", "role" => "host" } })
66
+ end
67
+ context "on openvz" do
68
+ virtualization_reports_true_for(:guest?, :virtual?, :openvz?, node: { "virtualization" => { "system" => "openvz", "role" => "guest" } })
69
+ virtualization_reports_true_for(:hypervisor?, :physical?, :openvz_host?, node: { "virtualization" => { "system" => "openvz", "role" => "host" } })
70
+ end
71
+ context "on metal which is not a virt host" do
72
+ virtualization_reports_true_for(:physical?, node: {} )
73
+ end
74
+ end
@@ -17,13 +17,15 @@
17
17
 
18
18
  require "spec_helper"
19
19
 
20
+ WINDOWS_BOOL_HELPERS = %i{windows_server_core? windows_server? windows_workstation?}.freeze
21
+
20
22
  def windows_reports_true_for(*args)
21
23
  args.each do |method|
22
24
  it "reports true for #{method}" do
23
25
  expect(described_class.send(method, node)).to be true
24
26
  end
25
27
  end
26
- (WINDOWS_HELPERS - args).each do |method|
28
+ (WINDOWS_BOOL_HELPERS - args).each do |method|
27
29
  it "reports false for #{method}" do
28
30
  expect(described_class.send(method, node)).to be false
29
31
  end
@@ -43,21 +45,39 @@ RSpec.describe ChefUtils::DSL::Windows do
43
45
  end
44
46
  end
45
47
 
46
- context "on Windows Server Core" do
47
- let(:node) { { "kernel" => { "server_core" => true } } }
48
+ context "windows boolean helpers" do
49
+ context "on Windows Server Core" do
50
+ let(:node) { { "kernel" => { "server_core" => true } } }
48
51
 
49
- windows_reports_true_for(:windows_server_core?)
50
- end
52
+ windows_reports_true_for(:windows_server_core?)
53
+ end
54
+
55
+ context "on Windows Workstation" do
56
+ let(:node) { { "kernel" => { "product_type" => "Workstation" } } }
57
+
58
+ windows_reports_true_for(:windows_workstation?)
59
+ end
51
60
 
52
- context "on Windows Workstation" do
53
- let(:node) { { "kernel" => { "product_type" => "Workstation" } } }
61
+ context "on Windows Server" do
62
+ let(:node) { { "kernel" => { "product_type" => "Server" } } }
54
63
 
55
- windows_reports_true_for(:windows_workstation?)
64
+ windows_reports_true_for(:windows_server?)
65
+ end
56
66
  end
57
67
 
58
- context "on Windows Server" do
59
- let(:node) { { "kernel" => { "product_type" => "Server" } } }
68
+ context "#windows_nt_version on Windows Server 2012 R2" do
69
+ let(:node) { { "os_version" => "6.3.9600" } }
70
+ it "it returns a ChefUtils::VersionString object with 6.3.9600" do
71
+ expect(described_class.send(:windows_nt_version, node)).to eq "6.3.9600"
72
+ expect(described_class.send(:windows_nt_version, node)).to be_a_kind_of ChefUtils::VersionString
73
+ end
74
+ end
60
75
 
61
- windows_reports_true_for(:windows_server?)
76
+ context "#powershell_version on Windows Server 2012 R2" do
77
+ let(:node) { { "languages" => { "powershell" => { "version" => "4.0" } } } }
78
+ it "it returns a ChefUtils::VersionString object with 4.0" do
79
+ expect(described_class.send(:powershell_version, node)).to eq "4.0"
80
+ expect(described_class.send(:powershell_version, node)).to be_a_kind_of ChefUtils::VersionString
81
+ end
62
82
  end
63
83
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 15.7.32
4
+ version: 15.8.23
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: 2020-01-27 00:00:00.000000000 Z
11
+ date: 2020-02-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -22,13 +22,16 @@ files:
22
22
  - chef-utils.gemspec
23
23
  - lib/chef-utils.rb
24
24
  - lib/chef-utils/dsl/architecture.rb
25
+ - lib/chef-utils/dsl/cloud.rb
25
26
  - lib/chef-utils/dsl/introspection.rb
26
27
  - lib/chef-utils/dsl/os.rb
27
28
  - lib/chef-utils/dsl/path_sanity.rb
28
29
  - lib/chef-utils/dsl/platform.rb
29
30
  - lib/chef-utils/dsl/platform_family.rb
31
+ - lib/chef-utils/dsl/platform_version.rb
30
32
  - lib/chef-utils/dsl/service.rb
31
33
  - lib/chef-utils/dsl/train_helpers.rb
34
+ - lib/chef-utils/dsl/virtualization.rb
32
35
  - lib/chef-utils/dsl/which.rb
33
36
  - lib/chef-utils/dsl/windows.rb
34
37
  - lib/chef-utils/internal.rb
@@ -37,6 +40,7 @@ files:
37
40
  - lib/chef-utils/version_string.rb
38
41
  - spec/spec_helper.rb
39
42
  - spec/unit/dsl/architecture_spec.rb
43
+ - spec/unit/dsl/cloud_spec.rb
40
44
  - spec/unit/dsl/dsl_spec.rb
41
45
  - spec/unit/dsl/introspection_spec.rb
42
46
  - spec/unit/dsl/os_spec.rb
@@ -44,6 +48,7 @@ files:
44
48
  - spec/unit/dsl/platform_family_spec.rb
45
49
  - spec/unit/dsl/platform_spec.rb
46
50
  - spec/unit/dsl/service_spec.rb
51
+ - spec/unit/dsl/virtualization_spec.rb
47
52
  - spec/unit/dsl/which_spec.rb
48
53
  - spec/unit/dsl/windows_spec.rb
49
54
  - spec/unit/mash_spec.rb