chef-utils 17.10.29 → 17.10.95
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +201 -201
- data/Rakefile +15 -15
- data/chef-utils.gemspec +50 -50
- data/lib/chef-utils/dist.rb +151 -151
- 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 +355 -355
- 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 +8 -8
@@ -1,41 +1,41 @@
|
|
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 PlatformVersion
|
24
|
-
include Internal
|
25
|
-
|
26
|
-
# Return the platform_version for the node. Acts like a String
|
27
|
-
# but also provides a mechanism for checking version constraints.
|
28
|
-
#
|
29
|
-
# @param [Chef::Node] node the node to check
|
30
|
-
# @since 15.8
|
31
|
-
#
|
32
|
-
# @return [ChefUtils::VersionString]
|
33
|
-
#
|
34
|
-
def platform_version(node = __getnode)
|
35
|
-
ChefUtils::VersionString.new(node["platform_version"])
|
36
|
-
end
|
37
|
-
|
38
|
-
extend self
|
39
|
-
end
|
40
|
-
end
|
41
|
-
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 PlatformVersion
|
24
|
+
include Internal
|
25
|
+
|
26
|
+
# Return the platform_version for the node. Acts like a String
|
27
|
+
# but also provides a mechanism for checking version constraints.
|
28
|
+
#
|
29
|
+
# @param [Chef::Node] node the node to check
|
30
|
+
# @since 15.8
|
31
|
+
#
|
32
|
+
# @return [ChefUtils::VersionString]
|
33
|
+
#
|
34
|
+
def platform_version(node = __getnode)
|
35
|
+
ChefUtils::VersionString.new(node["platform_version"])
|
36
|
+
end
|
37
|
+
|
38
|
+
extend self
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,112 +1,112 @@
|
|
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
|
-
require_relative "train_helpers"
|
21
|
-
|
22
|
-
module ChefUtils
|
23
|
-
module DSL
|
24
|
-
# NOTE: these are mixed into the service resource+providers specifically and deliberately not
|
25
|
-
# injected into the global namespace
|
26
|
-
module Service
|
27
|
-
include Internal
|
28
|
-
include TrainHelpers
|
29
|
-
include Introspection
|
30
|
-
|
31
|
-
# Returns if debian's old rc.d manager is installed (not necessarily the primary init system).
|
32
|
-
#
|
33
|
-
# @since 15.5
|
34
|
-
#
|
35
|
-
# @return [Boolean]
|
36
|
-
#
|
37
|
-
def debianrcd?
|
38
|
-
file_exist?("/usr/sbin/update-rc.d")
|
39
|
-
end
|
40
|
-
|
41
|
-
# Returns if debian's old invoke rc.d manager is installed (not necessarily the primary init system).
|
42
|
-
#
|
43
|
-
# @since 15.5
|
44
|
-
#
|
45
|
-
# @return [Boolean]
|
46
|
-
#
|
47
|
-
def invokercd?
|
48
|
-
file_exist?("/usr/sbin/invoke-rc.d")
|
49
|
-
end
|
50
|
-
|
51
|
-
# Returns if upstart is installed (not necessarily the primary init system).
|
52
|
-
#
|
53
|
-
# @since 15.5
|
54
|
-
#
|
55
|
-
# @return [Boolean]
|
56
|
-
#
|
57
|
-
def upstart?
|
58
|
-
file_exist?("/sbin/initctl")
|
59
|
-
end
|
60
|
-
|
61
|
-
# Returns if insserv is installed (not necessarily the primary init system).
|
62
|
-
#
|
63
|
-
# @since 15.5
|
64
|
-
#
|
65
|
-
# @return [Boolean]
|
66
|
-
#
|
67
|
-
def insserv?
|
68
|
-
file_exist?("/sbin/insserv")
|
69
|
-
end
|
70
|
-
|
71
|
-
# Returns if redhat's init system is installed (not necessarily the primary init system).
|
72
|
-
#
|
73
|
-
# @since 15.5
|
74
|
-
#
|
75
|
-
# @return [Boolean]
|
76
|
-
#
|
77
|
-
def redhatrcd?
|
78
|
-
file_exist?("/sbin/chkconfig")
|
79
|
-
end
|
80
|
-
|
81
|
-
#
|
82
|
-
# 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')
|
83
|
-
#
|
84
|
-
# @param [Symbol] type The type of init system. :initd, :upstart, :xinetd, :etc_rcd, or :systemd
|
85
|
-
# @param [String] script The name of the service
|
86
|
-
# @since 15.5
|
87
|
-
#
|
88
|
-
# @return [Boolean]
|
89
|
-
#
|
90
|
-
def service_script_exist?(type, script)
|
91
|
-
case type
|
92
|
-
when :initd
|
93
|
-
file_exist?("/etc/init.d/#{script}")
|
94
|
-
when :upstart
|
95
|
-
file_exist?("/etc/init/#{script}.conf")
|
96
|
-
when :xinetd
|
97
|
-
file_exist?("/etc/xinetd.d/#{script}")
|
98
|
-
when :etc_rcd
|
99
|
-
file_exist?("/etc/rc.d/#{script}")
|
100
|
-
when :systemd
|
101
|
-
file_exist?("/etc/init.d/#{script}") ||
|
102
|
-
has_systemd_service_unit?(script) ||
|
103
|
-
has_systemd_unit?(script)
|
104
|
-
else
|
105
|
-
raise ArgumentError, "type of service must be one of :initd, :upstart, :xinetd, :etc_rcd, or :systemd"
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
extend self
|
110
|
-
end
|
111
|
-
end
|
112
|
-
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
|
+
require_relative "train_helpers"
|
21
|
+
|
22
|
+
module ChefUtils
|
23
|
+
module DSL
|
24
|
+
# NOTE: these are mixed into the service resource+providers specifically and deliberately not
|
25
|
+
# injected into the global namespace
|
26
|
+
module Service
|
27
|
+
include Internal
|
28
|
+
include TrainHelpers
|
29
|
+
include Introspection
|
30
|
+
|
31
|
+
# Returns if debian's old rc.d manager is installed (not necessarily the primary init system).
|
32
|
+
#
|
33
|
+
# @since 15.5
|
34
|
+
#
|
35
|
+
# @return [Boolean]
|
36
|
+
#
|
37
|
+
def debianrcd?
|
38
|
+
file_exist?("/usr/sbin/update-rc.d")
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns if debian's old invoke rc.d manager is installed (not necessarily the primary init system).
|
42
|
+
#
|
43
|
+
# @since 15.5
|
44
|
+
#
|
45
|
+
# @return [Boolean]
|
46
|
+
#
|
47
|
+
def invokercd?
|
48
|
+
file_exist?("/usr/sbin/invoke-rc.d")
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns if upstart is installed (not necessarily the primary init system).
|
52
|
+
#
|
53
|
+
# @since 15.5
|
54
|
+
#
|
55
|
+
# @return [Boolean]
|
56
|
+
#
|
57
|
+
def upstart?
|
58
|
+
file_exist?("/sbin/initctl")
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns if insserv is installed (not necessarily the primary init system).
|
62
|
+
#
|
63
|
+
# @since 15.5
|
64
|
+
#
|
65
|
+
# @return [Boolean]
|
66
|
+
#
|
67
|
+
def insserv?
|
68
|
+
file_exist?("/sbin/insserv")
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns if redhat's init system is installed (not necessarily the primary init system).
|
72
|
+
#
|
73
|
+
# @since 15.5
|
74
|
+
#
|
75
|
+
# @return [Boolean]
|
76
|
+
#
|
77
|
+
def redhatrcd?
|
78
|
+
file_exist?("/sbin/chkconfig")
|
79
|
+
end
|
80
|
+
|
81
|
+
#
|
82
|
+
# 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')
|
83
|
+
#
|
84
|
+
# @param [Symbol] type The type of init system. :initd, :upstart, :xinetd, :etc_rcd, or :systemd
|
85
|
+
# @param [String] script The name of the service
|
86
|
+
# @since 15.5
|
87
|
+
#
|
88
|
+
# @return [Boolean]
|
89
|
+
#
|
90
|
+
def service_script_exist?(type, script)
|
91
|
+
case type
|
92
|
+
when :initd
|
93
|
+
file_exist?("/etc/init.d/#{script}")
|
94
|
+
when :upstart
|
95
|
+
file_exist?("/etc/init/#{script}.conf")
|
96
|
+
when :xinetd
|
97
|
+
file_exist?("/etc/xinetd.d/#{script}")
|
98
|
+
when :etc_rcd
|
99
|
+
file_exist?("/etc/rc.d/#{script}")
|
100
|
+
when :systemd
|
101
|
+
file_exist?("/etc/init.d/#{script}") ||
|
102
|
+
has_systemd_service_unit?(script) ||
|
103
|
+
has_systemd_unit?(script)
|
104
|
+
else
|
105
|
+
raise ArgumentError, "type of service must be one of :initd, :upstart, :xinetd, :etc_rcd, or :systemd"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
extend self
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -1,87 +1,87 @@
|
|
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
|
-
require "stringio" unless defined?(StringIO)
|
19
|
-
require_relative "../internal"
|
20
|
-
|
21
|
-
module ChefUtils
|
22
|
-
module DSL
|
23
|
-
module TrainHelpers
|
24
|
-
include Internal
|
25
|
-
|
26
|
-
#
|
27
|
-
# FIXME: generally these helpers all use the pattern of checking for target_mode?
|
28
|
-
# and then if it is we use train. That approach should likely be flipped so that
|
29
|
-
# even when we're running without target mode we still use train in its local
|
30
|
-
# mode. A prerequisite for that will be better CI testing of train against
|
31
|
-
# chef-client though, and ensuring that the APIs are entirely compatible. This
|
32
|
-
# will be particularly problematic for shell_out APIs and eventual file-creating
|
33
|
-
# APIs which are unlikely to be as sophisticated as the exiting code in chef-client
|
34
|
-
# for locally shelling out and creating files, and just dropping inspec local mode
|
35
|
-
# into chef-client would break the world.
|
36
|
-
#
|
37
|
-
|
38
|
-
# Train wrapper around File.exist? to make it local mode aware.
|
39
|
-
#
|
40
|
-
# @param filename filename to check
|
41
|
-
# @return [Boolean] if it exists
|
42
|
-
#
|
43
|
-
def file_exist?(filename)
|
44
|
-
if __transport_connection
|
45
|
-
__transport_connection.file(filename).exist?
|
46
|
-
else
|
47
|
-
File.exist?(filename)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# XXX: modifications to the StringIO won't get written back
|
52
|
-
# FIXME: this is very experimental and may be a bad idea and may break at any time
|
53
|
-
# @api private
|
54
|
-
#
|
55
|
-
def file_open(*args, &block)
|
56
|
-
if __transport_connection
|
57
|
-
content = __transport_connection.file(args[0]).content
|
58
|
-
string_io = StringIO.new content
|
59
|
-
yield string_io if block_given?
|
60
|
-
string_io
|
61
|
-
else
|
62
|
-
File.open(*args, &block)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# Alias to easily convert IO.read / File.read to file_read
|
67
|
-
def file_read(path)
|
68
|
-
file_open(path).read
|
69
|
-
end
|
70
|
-
|
71
|
-
def file_directory?(path)
|
72
|
-
if __transport_connection
|
73
|
-
__transport_connection.file(filename).directory?
|
74
|
-
else
|
75
|
-
File.directory?(path)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
# Alias to easily convert Dir.exist to dir_exist
|
80
|
-
def dir_exist?(path)
|
81
|
-
file_directory?(path)
|
82
|
-
end
|
83
|
-
|
84
|
-
extend self
|
85
|
-
end
|
86
|
-
end
|
87
|
-
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
|
+
require "stringio" unless defined?(StringIO)
|
19
|
+
require_relative "../internal"
|
20
|
+
|
21
|
+
module ChefUtils
|
22
|
+
module DSL
|
23
|
+
module TrainHelpers
|
24
|
+
include Internal
|
25
|
+
|
26
|
+
#
|
27
|
+
# FIXME: generally these helpers all use the pattern of checking for target_mode?
|
28
|
+
# and then if it is we use train. That approach should likely be flipped so that
|
29
|
+
# even when we're running without target mode we still use train in its local
|
30
|
+
# mode. A prerequisite for that will be better CI testing of train against
|
31
|
+
# chef-client though, and ensuring that the APIs are entirely compatible. This
|
32
|
+
# will be particularly problematic for shell_out APIs and eventual file-creating
|
33
|
+
# APIs which are unlikely to be as sophisticated as the exiting code in chef-client
|
34
|
+
# for locally shelling out and creating files, and just dropping inspec local mode
|
35
|
+
# into chef-client would break the world.
|
36
|
+
#
|
37
|
+
|
38
|
+
# Train wrapper around File.exist? to make it local mode aware.
|
39
|
+
#
|
40
|
+
# @param filename filename to check
|
41
|
+
# @return [Boolean] if it exists
|
42
|
+
#
|
43
|
+
def file_exist?(filename)
|
44
|
+
if __transport_connection
|
45
|
+
__transport_connection.file(filename).exist?
|
46
|
+
else
|
47
|
+
File.exist?(filename)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# XXX: modifications to the StringIO won't get written back
|
52
|
+
# FIXME: this is very experimental and may be a bad idea and may break at any time
|
53
|
+
# @api private
|
54
|
+
#
|
55
|
+
def file_open(*args, &block)
|
56
|
+
if __transport_connection
|
57
|
+
content = __transport_connection.file(args[0]).content
|
58
|
+
string_io = StringIO.new content
|
59
|
+
yield string_io if block_given?
|
60
|
+
string_io
|
61
|
+
else
|
62
|
+
File.open(*args, &block)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Alias to easily convert IO.read / File.read to file_read
|
67
|
+
def file_read(path)
|
68
|
+
file_open(path).read
|
69
|
+
end
|
70
|
+
|
71
|
+
def file_directory?(path)
|
72
|
+
if __transport_connection
|
73
|
+
__transport_connection.file(filename).directory?
|
74
|
+
else
|
75
|
+
File.directory?(path)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Alias to easily convert Dir.exist to dir_exist
|
80
|
+
def dir_exist?(path)
|
81
|
+
file_directory?(path)
|
82
|
+
end
|
83
|
+
|
84
|
+
extend self
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|