ohai 8.26.1 → 13.0.0
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 +5 -5
- data/Gemfile +3 -4
- data/Rakefile +14 -0
- data/lib/ohai/application.rb +1 -0
- data/lib/ohai/config.rb +2 -88
- data/lib/ohai/dsl/plugin.rb +0 -4
- data/lib/ohai/exception.rb +0 -1
- data/lib/ohai/loader.rb +11 -2
- data/lib/ohai/log.rb +3 -1
- data/lib/ohai/mixin/command.rb +1 -318
- data/lib/ohai/mixin/do_metadata.rb +47 -0
- data/lib/ohai/mixin/ec2_metadata.rb +2 -29
- data/lib/ohai/mixin/gce_metadata.rb +0 -37
- data/lib/ohai/mixin/http_helper.rb +56 -0
- data/lib/ohai/mixin/network_constants.rb +0 -5
- data/lib/ohai/plugins/cloud.rb +144 -157
- data/lib/ohai/plugins/darwin/filesystem.rb +68 -22
- data/lib/ohai/plugins/digital_ocean.rb +24 -42
- data/lib/ohai/plugins/dmi.rb +81 -77
- data/lib/ohai/plugins/ec2.rb +33 -60
- data/lib/ohai/plugins/gce.rb +3 -1
- data/lib/ohai/plugins/hostname.rb +1 -16
- data/lib/ohai/plugins/linux/filesystem.rb +130 -81
- data/lib/ohai/plugins/linux/mdadm.rb +3 -45
- data/lib/ohai/plugins/linux/network.rb +1 -26
- data/lib/ohai/plugins/linux/platform.rb +4 -2
- data/lib/ohai/plugins/linux/virtualization.rb +1 -5
- data/lib/ohai/plugins/scala.rb +1 -13
- data/lib/ohai/plugins/solaris2/network.rb +1 -2
- data/lib/ohai/plugins/uptime.rb +0 -9
- data/lib/ohai/plugins/windows/cpu.rb +2 -1
- data/lib/ohai/plugins/windows/network.rb +1 -1
- data/lib/ohai/runner.rb +0 -5
- data/lib/ohai/system.rb +38 -8
- data/lib/ohai/version.rb +2 -2
- data/ohai.gemspec +1 -1
- data/spec/functional/application_spec.rb +0 -40
- data/spec/functional/plugins/powershell_spec.rb +1 -1
- data/spec/functional/plugins/root_group_spec.rb +1 -1
- data/spec/functional/plugins/windows/uptime_spec.rb +1 -1
- data/spec/ohai_spec.rb +1 -1
- data/spec/support/integration_helper.rb +17 -0
- data/spec/support/platform_helpers.rb +17 -0
- data/spec/unit/application_spec.rb +0 -1
- data/spec/unit/config_spec.rb +0 -111
- data/spec/unit/dsl/plugin_spec.rb +1 -1
- data/spec/unit/hints_spec.rb +1 -1
- data/spec/unit/loader_spec.rb +26 -1
- data/spec/unit/mixin/command_spec.rb +1 -69
- data/spec/unit/mixin/ec2_metadata_spec.rb +1 -1
- data/spec/unit/mixin/softlayer_metadata_spec.rb +1 -1
- data/spec/unit/plugin_config_spec.rb +0 -1
- data/spec/unit/plugins/abort_spec.rb +1 -1
- data/spec/unit/plugins/aix/cpu_spec.rb +1 -1
- data/spec/unit/plugins/aix/filesystem_spec.rb +2 -1
- data/spec/unit/plugins/aix/hostname_spec.rb +1 -1
- data/spec/unit/plugins/aix/kernel_spec.rb +1 -1
- data/spec/unit/plugins/aix/memory_spec.rb +1 -1
- data/spec/unit/plugins/aix/network_spec.rb +1 -1
- data/spec/unit/plugins/aix/os_spec.rb +1 -1
- data/spec/unit/plugins/aix/platform_spec.rb +1 -1
- data/spec/unit/plugins/aix/uptime_spec.rb +1 -1
- data/spec/unit/plugins/aix/virtualization_spec.rb +1 -1
- data/spec/unit/plugins/azure_spec.rb +1 -1
- data/spec/unit/plugins/bsd/filesystem_spec.rb +1 -1
- data/spec/unit/plugins/bsd/virtualization_spec.rb +1 -1
- data/spec/unit/plugins/c_spec.rb +1 -1
- data/spec/unit/plugins/chef_spec.rb +1 -2
- data/spec/unit/plugins/cloud_spec.rb +210 -50
- data/spec/unit/plugins/darwin/cpu_spec.rb +1 -1
- data/spec/unit/plugins/darwin/filesystem_spec.rb +62 -13
- data/spec/unit/plugins/darwin/hardware_spec.rb +2 -2
- data/spec/unit/plugins/darwin/hostname_spec.rb +1 -1
- data/spec/unit/plugins/darwin/kernel_spec.rb +1 -1
- data/spec/unit/plugins/darwin/memory_spec.rb +1 -1
- data/spec/unit/plugins/darwin/network_spec.rb +1 -1
- data/spec/unit/plugins/darwin/platform_spec.rb +1 -1
- data/spec/unit/plugins/darwin/system_profiler_spec.rb +2 -9
- data/spec/unit/plugins/darwin/virtualization_spec.rb +1 -1
- data/spec/unit/plugins/digital_ocean_spec.rb +39 -110
- data/spec/unit/plugins/dmi_spec.rb +1 -1
- data/spec/unit/plugins/ec2_spec.rb +10 -62
- data/spec/unit/plugins/elixir_spec.rb +1 -1
- data/spec/unit/plugins/erlang_spec.rb +1 -1
- data/spec/unit/plugins/eucalyptus_spec.rb +1 -1
- data/spec/unit/plugins/fail_spec.rb +1 -1
- data/spec/unit/plugins/freebsd/cpu_spec.rb +1 -1
- data/spec/unit/plugins/freebsd/hostname_spec.rb +1 -1
- data/spec/unit/plugins/freebsd/kernel_spec.rb +1 -1
- data/spec/unit/plugins/freebsd/os_spec.rb +1 -1
- data/spec/unit/plugins/freebsd/platform_spec.rb +1 -1
- data/spec/unit/plugins/gce_spec.rb +1 -1
- data/spec/unit/plugins/go_spec.rb +1 -1
- data/spec/unit/plugins/groovy_spec.rb +1 -1
- data/spec/unit/plugins/haskell_spec.rb +1 -1
- data/spec/unit/plugins/hostname_spec.rb +16 -41
- data/spec/unit/plugins/init_package_spec.rb +1 -1
- data/spec/unit/plugins/ip_scopes_spec.rb +18 -6
- data/spec/unit/plugins/java_spec.rb +1 -1
- data/spec/unit/plugins/joyent_spec.rb +17 -1
- data/spec/unit/plugins/kernel_spec.rb +1 -1
- data/spec/unit/plugins/linode_spec.rb +1 -1
- data/spec/unit/plugins/linux/block_device_spec.rb +1 -1
- data/spec/unit/plugins/linux/cpu_spec.rb +1 -2
- data/spec/unit/plugins/linux/filesystem_spec.rb +207 -201
- data/spec/unit/plugins/linux/fips_spec.rb +1 -1
- data/spec/unit/plugins/linux/hostname_spec.rb +1 -1
- data/spec/unit/plugins/linux/hostnamectl_spec.rb +1 -1
- data/spec/unit/plugins/linux/kernel_spec.rb +1 -1
- data/spec/unit/plugins/linux/lsb_spec.rb +1 -1
- data/spec/unit/plugins/linux/machineid_spec.rb +1 -1
- data/spec/unit/plugins/linux/mdadm_spec.rb +2 -68
- data/spec/unit/plugins/linux/memory_spec.rb +1 -1
- data/spec/unit/plugins/linux/network_spec.rb +3 -44
- data/spec/unit/plugins/linux/platform_spec.rb +4 -4
- data/spec/unit/plugins/linux/sessions_spec.rb +1 -1
- data/spec/unit/plugins/linux/uptime_spec.rb +1 -1
- data/spec/unit/plugins/linux/virtualization_spec.rb +1 -28
- data/spec/unit/plugins/lua_spec.rb +1 -1
- data/spec/unit/plugins/mono_spec.rb +1 -1
- data/spec/unit/plugins/netbsd/hostname_spec.rb +1 -1
- data/spec/unit/plugins/netbsd/kernel_spec.rb +1 -1
- data/spec/unit/plugins/netbsd/platform_spec.rb +1 -1
- data/spec/unit/plugins/network_spec.rb +1 -1
- data/spec/unit/plugins/nodejs_spec.rb +1 -1
- data/spec/unit/plugins/ohai_spec.rb +1 -1
- data/spec/unit/plugins/ohai_time_spec.rb +1 -1
- data/spec/unit/plugins/openbsd/hostname_spec.rb +1 -1
- data/spec/unit/plugins/openbsd/kernel_spec.rb +1 -1
- data/spec/unit/plugins/openbsd/platform_spec.rb +1 -1
- data/spec/unit/plugins/openstack_spec.rb +2 -3
- data/spec/unit/plugins/os_spec.rb +1 -1
- data/spec/unit/plugins/packages_spec.rb +1 -1
- data/spec/unit/plugins/passwd_spec.rb +17 -1
- data/spec/unit/plugins/perl_spec.rb +1 -1
- data/spec/unit/plugins/php_spec.rb +1 -1
- data/spec/unit/plugins/platform_spec.rb +1 -1
- data/spec/unit/plugins/powershell_spec.rb +1 -1
- data/spec/unit/plugins/python_spec.rb +1 -1
- data/spec/unit/plugins/rackspace_spec.rb +1 -2
- data/spec/unit/plugins/root_group_spec.rb +2 -2
- data/spec/unit/plugins/ruby_spec.rb +1 -1
- data/spec/unit/plugins/rust_spec.rb +1 -1
- data/spec/unit/plugins/scala_spec.rb +3 -37
- data/spec/unit/plugins/shard_spec.rb +1 -1
- data/spec/unit/plugins/shells_spec.rb +1 -1
- data/spec/unit/plugins/softlayer_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/cpu_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/dmi_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/hostname_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/kernel_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/memory_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/network_spec.rb +7 -4
- data/spec/unit/plugins/solaris2/platform_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/virtualization_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/zpools_spec.rb +1 -1
- data/spec/unit/plugins/ssh_host_keys_spec.rb +1 -1
- data/spec/unit/plugins/sysconf_spec.rb +1 -1
- data/spec/unit/plugins/timezone_spec.rb +1 -1
- data/spec/unit/plugins/virtualbox_spec.rb +1 -1
- data/spec/unit/plugins/vmware_spec.rb +2 -1
- data/spec/unit/plugins/windows/cpu_spec.rb +9 -2
- data/spec/unit/plugins/windows/fips_spec.rb +1 -1
- data/spec/unit/plugins/windows/memory_spec.rb +1 -1
- data/spec/unit/plugins/windows/uptime_spec.rb +1 -1
- data/spec/unit/plugins/windows/virtualization_spec.rb +1 -1
- data/spec/unit/provides_map_spec.rb +1 -1
- data/spec/unit/runner_spec.rb +1 -1
- data/spec/unit/system_spec.rb +68 -76
- data/spec/unit/util/file_helper_spec.rb +1 -1
- data/spec/unit/util/ip_helper_spec.rb +1 -1
- metadata +6 -20
- data/lib/ohai/plugins/cloud_v2.rb +0 -315
- data/lib/ohai/plugins/darwin/filesystem2.rb +0 -107
- data/lib/ohai/plugins/linux/filesystem2.rb +0 -223
- data/lib/ohai/plugins/linux/lspci.rb +0 -76
- data/lib/ohai/plugins/network_listeners.rb +0 -60
- data/lib/ohai/plugins/sigar/cpu.rb +0 -44
- data/lib/ohai/plugins/sigar/filesystem.rb +0 -50
- data/lib/ohai/plugins/sigar/memory.rb +0 -39
- data/lib/ohai/plugins/sigar/network.rb +0 -168
- data/lib/ohai/plugins/sigar/network_route.rb +0 -64
- data/lib/ohai/plugins/sigar/platform.rb +0 -30
- data/spec/unit/plugins/cloud_v2_spec.rb +0 -389
- data/spec/unit/plugins/darwin/filesystem2_spec.rb +0 -139
- data/spec/unit/plugins/linux/filesystem2_spec.rb +0 -437
- data/spec/unit/plugins/linux/lspci_spec.rb +0 -133
- data/spec/unit/plugins/sigar/network_route_spec.rb +0 -148
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 436fe05bd654044a382621b353229fc436bc3a4c
|
|
4
|
+
data.tar.gz: a785069184b37a9a057e061da997d47d55c1e161
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 334239f6d9138eda450ad1fac4bb8da0439b290dfa1d2551377bf37dcd082778f121cbdb5f4398a936bb98670cb030bbe22bea952cd8fa4216bba06a0b18360e
|
|
7
|
+
data.tar.gz: ea555c1670d775894b74c3b3b5a677e4b69c9097b121e518d1c50c5b7c3dc3dc2a4134bba7f28e1894137865131decf22f4d443d7adfa6b6207ec8301dfd19ac
|
data/Gemfile
CHANGED
|
@@ -3,9 +3,7 @@ source "https://rubygems.org"
|
|
|
3
3
|
gemspec
|
|
4
4
|
|
|
5
5
|
group :development do
|
|
6
|
-
gem "
|
|
7
|
-
|
|
8
|
-
gem "chefstyle", "0.4.0"
|
|
6
|
+
gem "chefstyle"
|
|
9
7
|
gem "overcommit", ">= 0.34.1"
|
|
10
8
|
gem "pry-byebug"
|
|
11
9
|
gem "pry-stack_explorer"
|
|
@@ -16,5 +14,6 @@ group :development do
|
|
|
16
14
|
gem "rspec-mocks", "~> 3.0"
|
|
17
15
|
gem "rspec-collection_matchers", "~> 1.0"
|
|
18
16
|
gem "rspec_junit_formatter"
|
|
19
|
-
gem "
|
|
17
|
+
gem "github_changelog_generator", git: "https://github.com/tduffield/github-changelog-generator", branch: "adjust-tag-section-mapping"
|
|
18
|
+
gem "ipaddr_extensions"
|
|
20
19
|
end
|
data/Rakefile
CHANGED
|
@@ -22,3 +22,17 @@ require "rubocop/rake_task"
|
|
|
22
22
|
RuboCop::RakeTask.new(:style) do |task|
|
|
23
23
|
task.options += ["--display-cop-names", "--no-color"]
|
|
24
24
|
end
|
|
25
|
+
|
|
26
|
+
begin
|
|
27
|
+
require "github_changelog_generator/task"
|
|
28
|
+
|
|
29
|
+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
|
30
|
+
config.future_release = Ohai::VERSION
|
|
31
|
+
config.max_issues = 0
|
|
32
|
+
config.add_issues_wo_labels = false
|
|
33
|
+
config.enhancement_labels = "enhancement,Enhancement,New Feature,Feature".split(",")
|
|
34
|
+
config.bug_labels = "bug,Bug,Improvement,Upstream Bug".split(",")
|
|
35
|
+
config.exclude_labels = "duplicate,question,invalid,wontfix,no_changelog,Exclude From Changelog,Question,Discussion".split(",")
|
|
36
|
+
end
|
|
37
|
+
rescue LoadError
|
|
38
|
+
end
|
data/lib/ohai/application.rb
CHANGED
data/lib/ohai/config.rb
CHANGED
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
|
|
20
20
|
require "chef-config/config"
|
|
21
21
|
require "ohai/exception"
|
|
22
|
-
require "ohai/log"
|
|
23
22
|
require "ohai/plugin_config"
|
|
24
23
|
|
|
25
24
|
module Ohai
|
|
@@ -28,99 +27,14 @@ module Ohai
|
|
|
28
27
|
# Reopens ChefConfig::Config to add Ohai configuration settings.
|
|
29
28
|
# see: https://github.com/chef/chef/blob/master/lib/chef/config.rb
|
|
30
29
|
class Config
|
|
31
|
-
# These methods need to be defined before they are used as config defaults,
|
|
32
|
-
# otherwise they will get method_missing'd to nil.
|
|
33
|
-
|
|
34
|
-
class << self
|
|
35
|
-
def merge_deprecated_config
|
|
36
|
-
[ :hints_path, :plugin_path ].each do |option|
|
|
37
|
-
if has_key?(option) && send(option) != send("default_#{option}".to_sym)
|
|
38
|
-
Ohai::Log.warn(option_deprecated(option))
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
ohai.merge!(configuration)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def default_hints_path
|
|
46
|
-
[ ChefConfig::Config.platform_specific_path("/etc/chef/ohai/hints") ]
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def default_plugin_path
|
|
50
|
-
[ File.expand_path(File.join(File.dirname(__FILE__), "plugins")), ChefConfig::Config.platform_specific_path("/etc/chef/ohai/plugins") ]
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# Copy deprecated configuration options into the ohai config context.
|
|
55
|
-
|
|
56
|
-
# Keep "old" config defaults around so anyone calling Ohai::Config[:key]
|
|
57
|
-
# won't be broken. Also allows users to append to configuration options
|
|
58
|
-
# (e.g., Ohai::Config[:plugin_path] << some_path) in their config files.
|
|
59
|
-
default :disabled_plugins, []
|
|
60
|
-
default :hints_path, default_hints_path
|
|
61
|
-
default :log_level, :auto
|
|
62
|
-
default :log_location, STDERR
|
|
63
|
-
default :plugin_path, default_plugin_path
|
|
64
|
-
|
|
65
|
-
# Log deprecation warning when a top-level configuration option is set.
|
|
66
|
-
# TODO: Should we implement a config_attr_reader so that deprecation
|
|
67
|
-
# warnings will be generatd on read?
|
|
68
|
-
[
|
|
69
|
-
:directory,
|
|
70
|
-
:disabled_plugins,
|
|
71
|
-
:log_level,
|
|
72
|
-
:log_location,
|
|
73
|
-
:version,
|
|
74
|
-
].each do |option|
|
|
75
|
-
# https://docs.chef.io/config_rb_client.html#ohai-settings
|
|
76
|
-
# hints_path and plugin_path are intentionally excluded here; warnings for
|
|
77
|
-
# setting these attributes are generated in merge_deprecated_config since
|
|
78
|
-
# append (<<) operations bypass the config writer.
|
|
79
|
-
config_attr_writer option do |value|
|
|
80
|
-
# log_level and log_location are common configuration options for chef
|
|
81
|
-
# and other chef applications. When configuration files are read there
|
|
82
|
-
# is no distinction between log_level and Ohai::Config[:log_level] and
|
|
83
|
-
# we may emit a false deprecation warning. The deprecation warnings for
|
|
84
|
-
# these settings reflect that possibility.
|
|
85
|
-
# Furthermore, when the top-level config settings are removed we will
|
|
86
|
-
# need to ensure that Ohai.config[:log_level] can be set by writing
|
|
87
|
-
# log_level in a configuration file for consistent behavior with chef.
|
|
88
|
-
deprecation_warning = if [ :log_level, :log_location ].include?(value)
|
|
89
|
-
option_might_be_deprecated(option)
|
|
90
|
-
else
|
|
91
|
-
option_deprecated(option)
|
|
92
|
-
end
|
|
93
|
-
Ohai::Log.warn(deprecation_warning)
|
|
94
|
-
value
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
30
|
|
|
98
31
|
config_context :ohai do
|
|
99
32
|
default :disabled_plugins, []
|
|
100
|
-
default :hints_path,
|
|
33
|
+
default :hints_path, [ ChefConfig::Config.platform_specific_path("/etc/chef/ohai/hints") ]
|
|
101
34
|
default :log_level, :auto
|
|
102
35
|
default :log_location, STDERR
|
|
103
36
|
default :plugin, Ohai::PluginConfig.new { |h, k| h[k] = Ohai::PluginConfig.new }
|
|
104
|
-
default :plugin_path,
|
|
105
|
-
default :critical_plugins, []
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
class << self
|
|
109
|
-
def option_deprecated(option)
|
|
110
|
-
<<-EOM.chomp!.tr("\n", " ")
|
|
111
|
-
Ohai::Config[:#{option}] is set. Ohai::Config[:#{option}] is deprecated and will
|
|
112
|
-
be removed in future releases of ohai. Use ohai.#{option} in your configuration
|
|
113
|
-
file to configure :#{option} for ohai.
|
|
114
|
-
EOM
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def option_might_be_deprecated(option)
|
|
118
|
-
option_deprecated(option) + <<-EOM.chomp!.tr("\n", " ")
|
|
119
|
-
If your configuration file is used with other applications which configure
|
|
120
|
-
:#{option}, and you have not configured Ohai::Config[:#{option}], you may
|
|
121
|
-
disregard this warning.
|
|
122
|
-
EOM
|
|
123
|
-
end
|
|
37
|
+
default :plugin_path, [ File.expand_path(File.join(File.dirname(__FILE__), "plugins")), ChefConfig::Config.platform_specific_path("/etc/chef/ohai/plugins") ]
|
|
124
38
|
end
|
|
125
39
|
end
|
|
126
40
|
|
data/lib/ohai/dsl/plugin.rb
CHANGED
|
@@ -85,12 +85,10 @@ module Ohai
|
|
|
85
85
|
include Ohai::Util::FileHelper
|
|
86
86
|
|
|
87
87
|
attr_reader :data
|
|
88
|
-
attr_reader :failed
|
|
89
88
|
|
|
90
89
|
def initialize(data)
|
|
91
90
|
@data = data
|
|
92
91
|
@has_run = false
|
|
93
|
-
@failed = false
|
|
94
92
|
end
|
|
95
93
|
|
|
96
94
|
def run
|
|
@@ -185,10 +183,8 @@ module Ohai
|
|
|
185
183
|
begin
|
|
186
184
|
self.run
|
|
187
185
|
rescue Ohai::Exceptions::Error => e
|
|
188
|
-
@failed = true
|
|
189
186
|
raise e
|
|
190
187
|
rescue => e
|
|
191
|
-
@failed = true
|
|
192
188
|
Ohai::Log.debug("Plugin #{self.name} threw #{e.inspect}")
|
|
193
189
|
e.backtrace.each { |line| Ohai::Log.debug( line ) }
|
|
194
190
|
end
|
data/lib/ohai/exception.rb
CHANGED
data/lib/ohai/loader.rb
CHANGED
|
@@ -70,8 +70,8 @@ module Ohai
|
|
|
70
70
|
|
|
71
71
|
# Searches all plugin paths and returns an Array of PluginFile objects
|
|
72
72
|
# representing each plugin file.
|
|
73
|
-
def plugin_files_by_dir
|
|
74
|
-
Array(
|
|
73
|
+
def plugin_files_by_dir(dir = Ohai.config[:plugin_path])
|
|
74
|
+
Array(dir).inject([]) do |plugin_files, plugin_path|
|
|
75
75
|
plugin_files + PluginFile.find_all_in(plugin_path)
|
|
76
76
|
end
|
|
77
77
|
end
|
|
@@ -85,6 +85,15 @@ module Ohai
|
|
|
85
85
|
collect_v7_plugins
|
|
86
86
|
end
|
|
87
87
|
|
|
88
|
+
def load_additional(from)
|
|
89
|
+
from = [ Ohai.config[:plugin_path], from].flatten
|
|
90
|
+
plugin_files_by_dir(from).collect do |plugin_file|
|
|
91
|
+
Ohai::Log.debug "Loading additional plugin: #{plugin_file}"
|
|
92
|
+
plugin = load_plugin_class(plugin_file.path, plugin_file.plugin_root)
|
|
93
|
+
load_v7_plugin(plugin)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
88
97
|
# Load a specified file as an ohai plugin and creates an instance of it.
|
|
89
98
|
# Not used by ohai itself, but can be used to load a plugin for testing
|
|
90
99
|
# purposes.
|
data/lib/ohai/log.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#
|
|
2
2
|
# Author:: Adam Jacob (<adam@chef.io>)
|
|
3
|
-
# Copyright:: Copyright (c) 2008-
|
|
3
|
+
# Copyright:: Copyright (c) 2008-2017, Chef Software Inc.
|
|
4
4
|
# License:: Apache License, Version 2.0
|
|
5
5
|
#
|
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -22,6 +22,8 @@ module Ohai
|
|
|
22
22
|
class Log
|
|
23
23
|
extend Mixlib::Log
|
|
24
24
|
|
|
25
|
+
# this class loading initalization is so that we don't lose early logger
|
|
26
|
+
# messages when run from the CLI?
|
|
25
27
|
init(STDERR)
|
|
26
28
|
level = :info
|
|
27
29
|
|
data/lib/ohai/mixin/command.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#
|
|
2
2
|
# Author:: Adam Jacob (<adam@chef.io>)
|
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
|
3
4
|
# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
|
|
4
5
|
# License:: Apache License, Version 2.0
|
|
5
6
|
#
|
|
@@ -17,12 +18,7 @@
|
|
|
17
18
|
#
|
|
18
19
|
|
|
19
20
|
require "ohai/exception"
|
|
20
|
-
require "ohai/config"
|
|
21
21
|
require "ohai/log"
|
|
22
|
-
require "stringio"
|
|
23
|
-
require "tmpdir"
|
|
24
|
-
require "fcntl"
|
|
25
|
-
require "etc"
|
|
26
22
|
require "mixlib/shellout"
|
|
27
23
|
|
|
28
24
|
module Ohai
|
|
@@ -48,319 +44,6 @@ module Ohai
|
|
|
48
44
|
end
|
|
49
45
|
|
|
50
46
|
module_function :shell_out
|
|
51
|
-
|
|
52
|
-
def run_command(args = {})
|
|
53
|
-
Ohai::Log.warn("Ohai::Mixin::Command run_command is deprecated and will be removed in Ohai 9.0.0")
|
|
54
|
-
if args.has_key?(:creates)
|
|
55
|
-
if File.exists?(args[:creates])
|
|
56
|
-
Ohai::Log.debug("Skipping #{args[:command]} - creates #{args[:creates]} exists.")
|
|
57
|
-
return false
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
stdout_string = nil
|
|
62
|
-
stderr_string = nil
|
|
63
|
-
|
|
64
|
-
args[:cwd] ||= Dir.tmpdir
|
|
65
|
-
unless File.directory?(args[:cwd])
|
|
66
|
-
raise Ohai::Exceptions::Exec, "#{args[:cwd]} does not exist or is not a directory"
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
status = nil
|
|
70
|
-
Dir.chdir(args[:cwd]) do
|
|
71
|
-
status, stdout_string, stderr_string = run_command_backend(args[:command], args[:timeout])
|
|
72
|
-
|
|
73
|
-
if stdout_string
|
|
74
|
-
Ohai::Log.debug("---- Begin #{args[:command]} STDOUT ----")
|
|
75
|
-
Ohai::Log.debug(stdout_string.strip)
|
|
76
|
-
Ohai::Log.debug("---- End #{args[:command]} STDOUT ----")
|
|
77
|
-
end
|
|
78
|
-
if stderr_string
|
|
79
|
-
Ohai::Log.debug("---- Begin #{args[:command]} STDERR ----")
|
|
80
|
-
Ohai::Log.debug(stderr_string.strip)
|
|
81
|
-
Ohai::Log.debug("---- End #{args[:command]} STDERR ----")
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
args[:returns] ||= 0
|
|
85
|
-
args[:no_status_check] ||= false
|
|
86
|
-
if status.exitstatus != args[:returns] && (not args[:no_status_check])
|
|
87
|
-
raise Ohai::Exceptions::Exec, "#{args[:command_string]} returned #{status.exitstatus}, expected #{args[:returns]}"
|
|
88
|
-
else
|
|
89
|
-
Ohai::Log.debug("Ran #{args[:command_string]} (#{args[:command]}) returned #{status.exitstatus}")
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
return status, stdout_string, stderr_string
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
module_function :run_command
|
|
96
|
-
|
|
97
|
-
def run_command_unix(command, timeout)
|
|
98
|
-
stderr_string, stdout_string, status = "", "", nil
|
|
99
|
-
|
|
100
|
-
exec_processing_block = lambda do |pid, stdin, stdout, stderr|
|
|
101
|
-
stdout_string, stderr_string = stdout.string.chomp, stderr.string.chomp
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
if timeout
|
|
105
|
-
begin
|
|
106
|
-
Timeout.timeout(timeout) do
|
|
107
|
-
status = popen4(command, {}, &exec_processing_block)
|
|
108
|
-
end
|
|
109
|
-
rescue Timeout::Error => e
|
|
110
|
-
Chef::Log.error("#{command} exceeded timeout #{timeout}")
|
|
111
|
-
raise(e)
|
|
112
|
-
end
|
|
113
|
-
else
|
|
114
|
-
status = popen4(command, {}, &exec_processing_block)
|
|
115
|
-
end
|
|
116
|
-
return status, stdout_string, stderr_string
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def run_command_windows(command, timeout)
|
|
120
|
-
shellout_opts = {}
|
|
121
|
-
shellout_opts[:timeout] = timeout if timeout
|
|
122
|
-
|
|
123
|
-
m = Mixlib::ShellOut.new(command, shellout_opts)
|
|
124
|
-
m.run_command
|
|
125
|
-
[m.status, m.stdout, m.stderr]
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
if RUBY_PLATFORM =~ /mswin|mingw32|windows/
|
|
129
|
-
alias :run_command_backend :run_command_windows
|
|
130
|
-
else
|
|
131
|
-
alias :run_command_backend :run_command_unix
|
|
132
|
-
end
|
|
133
|
-
# This is taken directly from Ara T Howard's Open4 library, and then
|
|
134
|
-
# modified to suit the needs of Ohai. Any bugs here are most likely
|
|
135
|
-
# my own, and not Ara's.
|
|
136
|
-
#
|
|
137
|
-
# The original appears in external/open4.rb in its unmodified form.
|
|
138
|
-
#
|
|
139
|
-
# Thanks Ara!
|
|
140
|
-
def popen4(cmd, args = {}, &b)
|
|
141
|
-
Ohai::Log.warn("Ohai::Mixin::Command popen4 is deprecated and will be removed in Ohai 9.0.0")
|
|
142
|
-
|
|
143
|
-
# Disable garbage collection to work around possible bug in MRI
|
|
144
|
-
# Ruby 1.8 suffers from intermittent segfaults believed to be due to GC while IO.select
|
|
145
|
-
# See OHAI-330 / CHEF-2916 / CHEF-1305
|
|
146
|
-
GC.disable
|
|
147
|
-
|
|
148
|
-
# Waitlast - this is magic.
|
|
149
|
-
#
|
|
150
|
-
# Do we wait for the child process to die before we yield
|
|
151
|
-
# to the block, or after? That is the magic of waitlast.
|
|
152
|
-
#
|
|
153
|
-
# By default, we are waiting before we yield the block.
|
|
154
|
-
args[:waitlast] ||= false
|
|
155
|
-
|
|
156
|
-
args[:user] ||= nil
|
|
157
|
-
unless args[:user].kind_of?(Integer)
|
|
158
|
-
args[:user] = Etc.getpwnam(args[:user]).uid if args[:user]
|
|
159
|
-
end
|
|
160
|
-
args[:group] ||= nil
|
|
161
|
-
unless args[:group].kind_of?(Integer)
|
|
162
|
-
args[:group] = Etc.getgrnam(args[:group]).gid if args[:group]
|
|
163
|
-
end
|
|
164
|
-
args[:environment] ||= {}
|
|
165
|
-
|
|
166
|
-
# Default on C locale so parsing commands output can be done
|
|
167
|
-
# independently of the node's default locale.
|
|
168
|
-
# "LC_ALL" could be set to nil, in which case we also must ignore it.
|
|
169
|
-
unless args[:environment].has_key?("LC_ALL")
|
|
170
|
-
args[:environment]["LC_ALL"] = "C"
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
pw, pr, pe, ps = IO.pipe, IO.pipe, IO.pipe, IO.pipe
|
|
174
|
-
|
|
175
|
-
verbose = $VERBOSE
|
|
176
|
-
begin
|
|
177
|
-
$VERBOSE = nil
|
|
178
|
-
ps.last.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
|
|
179
|
-
|
|
180
|
-
cid = fork do
|
|
181
|
-
Process.setsid
|
|
182
|
-
|
|
183
|
-
pw.last.close
|
|
184
|
-
STDIN.reopen pw.first
|
|
185
|
-
pw.first.close
|
|
186
|
-
|
|
187
|
-
pr.first.close
|
|
188
|
-
STDOUT.reopen pr.last
|
|
189
|
-
pr.last.close
|
|
190
|
-
|
|
191
|
-
pe.first.close
|
|
192
|
-
STDERR.reopen pe.last
|
|
193
|
-
pe.last.close
|
|
194
|
-
|
|
195
|
-
STDOUT.sync = STDERR.sync = true
|
|
196
|
-
|
|
197
|
-
if args[:group]
|
|
198
|
-
Process.egid = args[:group]
|
|
199
|
-
Process.gid = args[:group]
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
if args[:user]
|
|
203
|
-
Process.euid = args[:user]
|
|
204
|
-
Process.uid = args[:user]
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
args[:environment].each do |key, value|
|
|
208
|
-
ENV[key] = value
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
if args[:umask]
|
|
212
|
-
umask = ((args[:umask].respond_to?(:oct) ? args[:umask].oct : args[:umask].to_i) & 007777)
|
|
213
|
-
File.umask(umask)
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
begin
|
|
217
|
-
if cmd.kind_of?(Array)
|
|
218
|
-
exec(*cmd)
|
|
219
|
-
else
|
|
220
|
-
exec(cmd)
|
|
221
|
-
end
|
|
222
|
-
raise "forty-two"
|
|
223
|
-
rescue Exception => e
|
|
224
|
-
Marshal.dump(e, ps.last)
|
|
225
|
-
ps.last.flush
|
|
226
|
-
end
|
|
227
|
-
ps.last.close unless ps.last.closed?
|
|
228
|
-
exit!
|
|
229
|
-
end
|
|
230
|
-
ensure
|
|
231
|
-
$VERBOSE = verbose
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
[pw.first, pr.last, pe.last, ps.last].each { |fd| fd.close }
|
|
235
|
-
|
|
236
|
-
begin
|
|
237
|
-
e = Marshal.load ps.first
|
|
238
|
-
pw.last.close
|
|
239
|
-
pr.first.close
|
|
240
|
-
pe.first.close
|
|
241
|
-
Process.wait(cid)
|
|
242
|
-
raise(Exception === e ? e : "unknown failure!")
|
|
243
|
-
rescue EOFError # If we get an EOF error, then the exec was successful
|
|
244
|
-
42
|
|
245
|
-
ensure
|
|
246
|
-
ps.first.close
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
pw.last.sync = true
|
|
250
|
-
|
|
251
|
-
pi = [pw.last, pr.first, pe.first]
|
|
252
|
-
|
|
253
|
-
if b
|
|
254
|
-
begin
|
|
255
|
-
if args[:waitlast]
|
|
256
|
-
b[cid, *pi]
|
|
257
|
-
# send EOF so that if the child process is reading from STDIN
|
|
258
|
-
# it will actually finish up and exit
|
|
259
|
-
pi[0].close_write
|
|
260
|
-
Process.waitpid2(cid).last
|
|
261
|
-
else
|
|
262
|
-
# This took some doing.
|
|
263
|
-
# The trick here is to close STDIN
|
|
264
|
-
# Then set our end of the childs pipes to be O_NONBLOCK
|
|
265
|
-
# Then wait for the child to die, which means any IO it
|
|
266
|
-
# wants to do must be done - it's dead. If it isn't,
|
|
267
|
-
# it's because something totally skanky is happening,
|
|
268
|
-
# and we don't care.
|
|
269
|
-
o = StringIO.new
|
|
270
|
-
e = StringIO.new
|
|
271
|
-
|
|
272
|
-
#pi[0].close
|
|
273
|
-
|
|
274
|
-
stdout = pi[1]
|
|
275
|
-
stderr = pi[2]
|
|
276
|
-
|
|
277
|
-
stdout.sync = true
|
|
278
|
-
stderr.sync = true
|
|
279
|
-
|
|
280
|
-
stdout.fcntl(Fcntl::F_SETFL, pi[1].fcntl(Fcntl::F_GETFL) | Fcntl::O_NONBLOCK)
|
|
281
|
-
stderr.fcntl(Fcntl::F_SETFL, pi[2].fcntl(Fcntl::F_GETFL) | Fcntl::O_NONBLOCK)
|
|
282
|
-
|
|
283
|
-
stdout_finished = false
|
|
284
|
-
stderr_finished = false
|
|
285
|
-
|
|
286
|
-
results = nil
|
|
287
|
-
|
|
288
|
-
while !stdout_finished || !stderr_finished
|
|
289
|
-
begin
|
|
290
|
-
channels_to_watch = []
|
|
291
|
-
channels_to_watch << stdout if !stdout_finished
|
|
292
|
-
channels_to_watch << stderr if !stderr_finished
|
|
293
|
-
ready = IO.select(channels_to_watch, nil, nil, 1.0)
|
|
294
|
-
rescue Errno::EAGAIN
|
|
295
|
-
ensure
|
|
296
|
-
results = Process.waitpid2(cid, Process::WNOHANG)
|
|
297
|
-
if results
|
|
298
|
-
stdout_finished = true
|
|
299
|
-
stderr_finished = true
|
|
300
|
-
end
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
if ready && ready.first.include?(stdout)
|
|
304
|
-
line = results ? stdout.gets(nil) : stdout.gets
|
|
305
|
-
if line
|
|
306
|
-
o.write(line)
|
|
307
|
-
else
|
|
308
|
-
stdout_finished = true
|
|
309
|
-
end
|
|
310
|
-
end
|
|
311
|
-
if ready && ready.first.include?(stderr)
|
|
312
|
-
line = results ? stderr.gets(nil) : stderr.gets
|
|
313
|
-
if line
|
|
314
|
-
e.write(line)
|
|
315
|
-
else
|
|
316
|
-
stderr_finished = true
|
|
317
|
-
end
|
|
318
|
-
end
|
|
319
|
-
end
|
|
320
|
-
results = Process.waitpid2(cid) unless results
|
|
321
|
-
o.rewind
|
|
322
|
-
e.rewind
|
|
323
|
-
|
|
324
|
-
# **OHAI-275**
|
|
325
|
-
# The way we read from the pipes causes ruby to mark the strings
|
|
326
|
-
# as ASCII-8BIT (i.e., binary), but the content should be encoded
|
|
327
|
-
# as the default external encoding. For example, a command may
|
|
328
|
-
# return data encoded as UTF-8, but the strings will be marked as
|
|
329
|
-
# ASCII-8BIT. Later, when you attempt to print the values as
|
|
330
|
-
# UTF-8, Ruby will try to convert them and fail, raising an
|
|
331
|
-
# error.
|
|
332
|
-
#
|
|
333
|
-
# Ruby always marks strings as binary when read from IO in
|
|
334
|
-
# incomplete chunks, since you may have split the data within a
|
|
335
|
-
# multibyte char. In our case, we concat the chunks back
|
|
336
|
-
# together, so any multibyte chars will be reassembled.
|
|
337
|
-
#
|
|
338
|
-
# Note that all of this applies only to Ruby 1.9, which we check
|
|
339
|
-
# for by making sure that the Encoding class exists and strings
|
|
340
|
-
# have encoding methods.
|
|
341
|
-
if "".respond_to?(:force_encoding) && defined?(Encoding)
|
|
342
|
-
o.string.force_encoding(Encoding.default_external)
|
|
343
|
-
o.string.encode!("UTF-8", :invalid => :replace, :undef => :replace, :replace => "?")
|
|
344
|
-
e.string.force_encoding(Encoding.default_external)
|
|
345
|
-
e.string.encode!("UTF-8", :invalid => :replace, :undef => :replace, :replace => "?")
|
|
346
|
-
end
|
|
347
|
-
b[cid, pi[0], o, e]
|
|
348
|
-
results.last
|
|
349
|
-
end
|
|
350
|
-
ensure
|
|
351
|
-
pi.each { |fd| fd.close unless fd.closed? }
|
|
352
|
-
end
|
|
353
|
-
else
|
|
354
|
-
[cid, pw.last, pr.first, pe.first]
|
|
355
|
-
end
|
|
356
|
-
rescue Errno::ENOENT
|
|
357
|
-
raise Ohai::Exceptions::Exec, "command #{cmd} doesn't exist or is not in the PATH"
|
|
358
|
-
ensure
|
|
359
|
-
# we disabled GC entering
|
|
360
|
-
GC.enable
|
|
361
|
-
end
|
|
362
|
-
|
|
363
|
-
module_function :popen4
|
|
364
47
|
end
|
|
365
48
|
end
|
|
366
49
|
end
|