chef-utils 18.0.161 → 18.0.169
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 +4 -4
- data/LICENSE +201 -201
- data/Rakefile +15 -15
- data/chef-utils.gemspec +50 -50
- data/lib/chef-utils/dist.rb +154 -154
- data/lib/chef-utils/dsl/architecture.rb +150 -150
- data/lib/chef-utils/dsl/cloud.rb +155 -155
- data/lib/chef-utils/dsl/default_paths.rb +60 -60
- data/lib/chef-utils/dsl/introspection.rb +134 -134
- 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 -387
- data/lib/chef-utils/dsl/platform_family.rb +360 -360
- 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 -272
- 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 -263
- data/lib/chef-utils/parallel_map.rb +131 -131
- 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 -93
- data/spec/unit/dsl/dsl_spec.rb +34 -34
- data/spec/unit/dsl/introspection_spec.rb +201 -201
- 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 -235
- data/spec/unit/dsl/platform_spec.rb +252 -252
- 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 -156
- metadata +3 -3
@@ -1,134 +1,134 @@
|
|
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 "train_helpers"
|
20
|
-
|
21
|
-
module ChefUtils
|
22
|
-
module DSL
|
23
|
-
# This is for "introspection" helpers in the sense that we are inspecting the
|
24
|
-
# actual server or image under management to determine running state (duck-typing the system).
|
25
|
-
# The helpers here may use the node object state from ohai, but typically not the big 5: platform,
|
26
|
-
# platform_family, platform_version, arch, os. The helpers here should infer somewhat
|
27
|
-
# higher level facts about the system.
|
28
|
-
#
|
29
|
-
module Introspection
|
30
|
-
include TrainHelpers
|
31
|
-
|
32
|
-
# Determine if the node is using the Chef Effortless pattern in which the Chef Infra Client is packaged using Chef Habitat
|
33
|
-
#
|
34
|
-
# @param [Chef::Node] node the node to check
|
35
|
-
# @since 17.0
|
36
|
-
#
|
37
|
-
# @return [Boolean]
|
38
|
-
#
|
39
|
-
def effortless?(node = __getnode)
|
40
|
-
!!(node && node.read("chef_packages", "chef", "chef_effortless"))
|
41
|
-
end
|
42
|
-
|
43
|
-
# Determine if the node is a docker container.
|
44
|
-
#
|
45
|
-
# @param [Chef::Node] node the node to check
|
46
|
-
# @since 12.11
|
47
|
-
#
|
48
|
-
# @return [Boolean]
|
49
|
-
#
|
50
|
-
def docker?(node = __getnode)
|
51
|
-
# Using "File.exist?('/.dockerinit') || File.exist?('/.dockerenv')" makes Travis sad,
|
52
|
-
# and that makes us sad too.
|
53
|
-
!!(node && node.read("virtualization", "systems", "docker") == "guest")
|
54
|
-
end
|
55
|
-
|
56
|
-
# Determine if the node uses the systemd init system.
|
57
|
-
#
|
58
|
-
# @param [Chef::Node] node the node to check
|
59
|
-
# @since 15.5
|
60
|
-
#
|
61
|
-
# @return [Boolean]
|
62
|
-
#
|
63
|
-
def systemd?(node = __getnode)
|
64
|
-
file_exist?("/proc/1/comm") && file_open("/proc/1/comm").gets.chomp == "systemd"
|
65
|
-
end
|
66
|
-
|
67
|
-
# Determine if the node is running in Test Kitchen.
|
68
|
-
#
|
69
|
-
# @param [Chef::Node] node the node to check
|
70
|
-
# @since 15.5
|
71
|
-
#
|
72
|
-
# @return [Boolean]
|
73
|
-
#
|
74
|
-
def kitchen?(node = __getnode)
|
75
|
-
ENV.key?("TEST_KITCHEN")
|
76
|
-
end
|
77
|
-
|
78
|
-
# Determine if the node is running in a CI system that sets the CI env var.
|
79
|
-
#
|
80
|
-
# @param [Chef::Node] node the node to check
|
81
|
-
# @since 15.5
|
82
|
-
#
|
83
|
-
# @return [Boolean]
|
84
|
-
#
|
85
|
-
def ci?(node = __getnode)
|
86
|
-
ENV.key?("CI")
|
87
|
-
end
|
88
|
-
|
89
|
-
# Determine if the a systemd service unit is present on the system.
|
90
|
-
#
|
91
|
-
# @param [String] svc_name
|
92
|
-
# @since 15.5
|
93
|
-
#
|
94
|
-
# @return [Boolean]
|
95
|
-
#
|
96
|
-
def has_systemd_service_unit?(svc_name)
|
97
|
-
%w{ /etc /usr/lib /lib /run }.any? do |load_path|
|
98
|
-
file_exist?(
|
99
|
-
"#{load_path}/systemd/system/#{svc_name.gsub(/@.*$/, "@")}.service"
|
100
|
-
)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
# Determine if the a systemd unit of any type is present on the system.
|
105
|
-
#
|
106
|
-
# @param [String] svc_name
|
107
|
-
# @since 15.5
|
108
|
-
#
|
109
|
-
# @return [Boolean]
|
110
|
-
#
|
111
|
-
def has_systemd_unit?(svc_name)
|
112
|
-
# TODO: stop supporting non-service units with service resource
|
113
|
-
%w{ /etc /usr/lib /lib /run }.any? do |load_path|
|
114
|
-
file_exist?("#{load_path}/systemd/system/#{svc_name}")
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
# Determine if the current node includes the given recipe name.
|
119
|
-
#
|
120
|
-
# @param [String] recipe_name
|
121
|
-
# @since 15.8
|
122
|
-
#
|
123
|
-
# @return [Boolean]
|
124
|
-
#
|
125
|
-
def includes_recipe?(recipe_name, node = __getnode)
|
126
|
-
node.recipe?(recipe_name)
|
127
|
-
end
|
128
|
-
# chef-sugar backcompat method
|
129
|
-
alias_method :include_recipe?, :includes_recipe?
|
130
|
-
|
131
|
-
extend self
|
132
|
-
end
|
133
|
-
end
|
134
|
-
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 "train_helpers"
|
20
|
+
|
21
|
+
module ChefUtils
|
22
|
+
module DSL
|
23
|
+
# This is for "introspection" helpers in the sense that we are inspecting the
|
24
|
+
# actual server or image under management to determine running state (duck-typing the system).
|
25
|
+
# The helpers here may use the node object state from ohai, but typically not the big 5: platform,
|
26
|
+
# platform_family, platform_version, arch, os. The helpers here should infer somewhat
|
27
|
+
# higher level facts about the system.
|
28
|
+
#
|
29
|
+
module Introspection
|
30
|
+
include TrainHelpers
|
31
|
+
|
32
|
+
# Determine if the node is using the Chef Effortless pattern in which the Chef Infra Client is packaged using Chef Habitat
|
33
|
+
#
|
34
|
+
# @param [Chef::Node] node the node to check
|
35
|
+
# @since 17.0
|
36
|
+
#
|
37
|
+
# @return [Boolean]
|
38
|
+
#
|
39
|
+
def effortless?(node = __getnode)
|
40
|
+
!!(node && node.read("chef_packages", "chef", "chef_effortless"))
|
41
|
+
end
|
42
|
+
|
43
|
+
# Determine if the node is a docker container.
|
44
|
+
#
|
45
|
+
# @param [Chef::Node] node the node to check
|
46
|
+
# @since 12.11
|
47
|
+
#
|
48
|
+
# @return [Boolean]
|
49
|
+
#
|
50
|
+
def docker?(node = __getnode)
|
51
|
+
# Using "File.exist?('/.dockerinit') || File.exist?('/.dockerenv')" makes Travis sad,
|
52
|
+
# and that makes us sad too.
|
53
|
+
!!(node && node.read("virtualization", "systems", "docker") == "guest")
|
54
|
+
end
|
55
|
+
|
56
|
+
# Determine if the node uses the systemd init system.
|
57
|
+
#
|
58
|
+
# @param [Chef::Node] node the node to check
|
59
|
+
# @since 15.5
|
60
|
+
#
|
61
|
+
# @return [Boolean]
|
62
|
+
#
|
63
|
+
def systemd?(node = __getnode)
|
64
|
+
file_exist?("/proc/1/comm") && file_open("/proc/1/comm").gets.chomp == "systemd"
|
65
|
+
end
|
66
|
+
|
67
|
+
# Determine if the node is running in Test Kitchen.
|
68
|
+
#
|
69
|
+
# @param [Chef::Node] node the node to check
|
70
|
+
# @since 15.5
|
71
|
+
#
|
72
|
+
# @return [Boolean]
|
73
|
+
#
|
74
|
+
def kitchen?(node = __getnode)
|
75
|
+
ENV.key?("TEST_KITCHEN")
|
76
|
+
end
|
77
|
+
|
78
|
+
# Determine if the node is running in a CI system that sets the CI env var.
|
79
|
+
#
|
80
|
+
# @param [Chef::Node] node the node to check
|
81
|
+
# @since 15.5
|
82
|
+
#
|
83
|
+
# @return [Boolean]
|
84
|
+
#
|
85
|
+
def ci?(node = __getnode)
|
86
|
+
ENV.key?("CI")
|
87
|
+
end
|
88
|
+
|
89
|
+
# Determine if the a systemd service unit is present on the system.
|
90
|
+
#
|
91
|
+
# @param [String] svc_name
|
92
|
+
# @since 15.5
|
93
|
+
#
|
94
|
+
# @return [Boolean]
|
95
|
+
#
|
96
|
+
def has_systemd_service_unit?(svc_name)
|
97
|
+
%w{ /etc /usr/lib /lib /run }.any? do |load_path|
|
98
|
+
file_exist?(
|
99
|
+
"#{load_path}/systemd/system/#{svc_name.gsub(/@.*$/, "@")}.service"
|
100
|
+
)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Determine if the a systemd unit of any type is present on the system.
|
105
|
+
#
|
106
|
+
# @param [String] svc_name
|
107
|
+
# @since 15.5
|
108
|
+
#
|
109
|
+
# @return [Boolean]
|
110
|
+
#
|
111
|
+
def has_systemd_unit?(svc_name)
|
112
|
+
# TODO: stop supporting non-service units with service resource
|
113
|
+
%w{ /etc /usr/lib /lib /run }.any? do |load_path|
|
114
|
+
file_exist?("#{load_path}/systemd/system/#{svc_name}")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# Determine if the current node includes the given recipe name.
|
119
|
+
#
|
120
|
+
# @param [String] recipe_name
|
121
|
+
# @since 15.8
|
122
|
+
#
|
123
|
+
# @return [Boolean]
|
124
|
+
#
|
125
|
+
def includes_recipe?(recipe_name, node = __getnode)
|
126
|
+
node.recipe?(recipe_name)
|
127
|
+
end
|
128
|
+
# chef-sugar backcompat method
|
129
|
+
alias_method :include_recipe?, :includes_recipe?
|
130
|
+
|
131
|
+
extend self
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
data/lib/chef-utils/dsl/os.rb
CHANGED
@@ -1,58 +1,58 @@
|
|
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 OS
|
24
|
-
include Internal
|
25
|
-
|
26
|
-
#
|
27
|
-
# NOTE CAREFULLY: Most node['os'] values should not appear in this file at all.
|
28
|
-
#
|
29
|
-
# For cases where node['os'] == node['platform_family'] == node['platform'] then
|
30
|
-
# only the platform helper should be added.
|
31
|
-
#
|
32
|
-
|
33
|
-
# Determine if the current node is Linux.
|
34
|
-
#
|
35
|
-
# @param [Chef::Node] node the node to check
|
36
|
-
# @since 15.5
|
37
|
-
#
|
38
|
-
# @return [Boolean]
|
39
|
-
#
|
40
|
-
def linux?(node = __getnode)
|
41
|
-
node["os"] == "linux"
|
42
|
-
end
|
43
|
-
|
44
|
-
# Determine if the current node is Darwin.
|
45
|
-
#
|
46
|
-
# @param [Chef::Node] node the node to check
|
47
|
-
# @since 15.5
|
48
|
-
#
|
49
|
-
# @return [Boolean]
|
50
|
-
#
|
51
|
-
def darwin?(node = __getnode)
|
52
|
-
node["os"] == "darwin"
|
53
|
-
end
|
54
|
-
|
55
|
-
extend self
|
56
|
-
end
|
57
|
-
end
|
58
|
-
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 OS
|
24
|
+
include Internal
|
25
|
+
|
26
|
+
#
|
27
|
+
# NOTE CAREFULLY: Most node['os'] values should not appear in this file at all.
|
28
|
+
#
|
29
|
+
# For cases where node['os'] == node['platform_family'] == node['platform'] then
|
30
|
+
# only the platform helper should be added.
|
31
|
+
#
|
32
|
+
|
33
|
+
# Determine if the current node is Linux.
|
34
|
+
#
|
35
|
+
# @param [Chef::Node] node the node to check
|
36
|
+
# @since 15.5
|
37
|
+
#
|
38
|
+
# @return [Boolean]
|
39
|
+
#
|
40
|
+
def linux?(node = __getnode)
|
41
|
+
node["os"] == "linux"
|
42
|
+
end
|
43
|
+
|
44
|
+
# Determine if the current node is Darwin.
|
45
|
+
#
|
46
|
+
# @param [Chef::Node] node the node to check
|
47
|
+
# @since 15.5
|
48
|
+
#
|
49
|
+
# @return [Boolean]
|
50
|
+
#
|
51
|
+
def darwin?(node = __getnode)
|
52
|
+
node["os"] == "darwin"
|
53
|
+
end
|
54
|
+
|
55
|
+
extend self
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -1,39 +1,39 @@
|
|
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 "default_paths"
|
20
|
-
|
21
|
-
module ChefUtils
|
22
|
-
module DSL
|
23
|
-
module PathSanity
|
24
|
-
include ChefUtils::DSL::DefaultPaths
|
25
|
-
|
26
|
-
def sanitized_path(env = nil)
|
27
|
-
default_paths(env)
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def __sane_paths
|
33
|
-
__default_paths
|
34
|
-
end
|
35
|
-
|
36
|
-
extend self
|
37
|
-
end
|
38
|
-
end
|
39
|
-
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 "default_paths"
|
20
|
+
|
21
|
+
module ChefUtils
|
22
|
+
module DSL
|
23
|
+
module PathSanity
|
24
|
+
include ChefUtils::DSL::DefaultPaths
|
25
|
+
|
26
|
+
def sanitized_path(env = nil)
|
27
|
+
default_paths(env)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def __sane_paths
|
33
|
+
__default_paths
|
34
|
+
end
|
35
|
+
|
36
|
+
extend self
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|