summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2016-12-19 21:44:46 -0800
committerTim Smith <tsmith@chef.io>2016-12-22 10:05:04 -0800
commit705e62202e2bae506f447967553d795f90fb25ac (patch)
tree0e5735f00f9c82d2b09074f636fc1087d6ddd17c
parentd0de89cff20ef0dd4e2be0cb8b8f6a7266154c69 (diff)
downloadohai-705e62202e2bae506f447967553d795f90fb25ac.tar.gz
Better debug logging
Gracefully fail in virtual box Include plugin name in more logs Be consistent in the log output format Help figure out how Virtualization systems were detected with logging Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/azure.rb10
-rw-r--r--lib/ohai/plugins/c.rb4
-rw-r--r--lib/ohai/plugins/dmi.rb10
-rw-r--r--lib/ohai/plugins/groovy.rb2
-rw-r--r--lib/ohai/plugins/haskell.rb8
-rw-r--r--lib/ohai/plugins/hostname.rb12
-rw-r--r--lib/ohai/plugins/ip_scopes.rb2
-rw-r--r--lib/ohai/plugins/linux/network.rb30
-rw-r--r--lib/ohai/plugins/linux/sessions.rb2
-rw-r--r--lib/ohai/plugins/linux/virtualization.rb18
-rw-r--r--lib/ohai/plugins/lua.rb2
-rw-r--r--lib/ohai/plugins/network.rb20
-rw-r--r--lib/ohai/plugins/scala.rb4
-rw-r--r--lib/ohai/plugins/solaris2/dmi.rb10
-rw-r--r--lib/ohai/plugins/virtualbox.rb39
-rw-r--r--lib/ohai/plugins/vmware.rb4
-rw-r--r--lib/ohai/util/file_helper.rb4
-rw-r--r--spec/unit/plugins/linux/network_spec.rb2
-rw-r--r--spec/unit/plugins/network_spec.rb46
19 files changed, 127 insertions, 102 deletions
diff --git a/lib/ohai/plugins/azure.rb b/lib/ohai/plugins/azure.rb
index 8bc29964..8d984083 100644
--- a/lib/ohai/plugins/azure.rb
+++ b/lib/ohai/plugins/azure.rb
@@ -24,14 +24,14 @@ Ohai.plugin(:Azure) do
# project for details
azure_metadata_from_hints = hint?("azure")
if azure_metadata_from_hints
- Ohai::Log.debug("azure plugin: azure_metadata_from_hints is present.")
+ Ohai::Log.debug("Plugin Azure: azure_metadata_from_hints is present.")
azure Mash.new
azure_metadata_from_hints.each { |k, v| azure[k] = v }
elsif has_waagent? || has_dhcp_option_245?
- Ohai::Log.debug("azure plugin: No hints present, but system appears to be on azure.")
+ Ohai::Log.debug("Plugin Azure: No hints present, but system appears to be on azure.")
azure Mash.new
else
- Ohai::Log.debug("azure plugin: No hints present for azure and doesn't appear to be azure.")
+ Ohai::Log.debug("Plugin Azure: No hints present for azure and doesn't appear to be azure.")
false
end
end
@@ -40,7 +40,7 @@ Ohai.plugin(:Azure) do
# http://blog.mszcool.com/index.php/2015/04/detecting-if-a-virtual-machine-runs-in-microsoft-azure-linux-windows-to-protect-your-software-when-distributed-via-the-azure-marketplace/
def has_waagent?
if File.exist?("/usr/sbin/waagent") || Dir.exist?('C:\WindowsAzure')
- Ohai::Log.debug("azure plugin: Found waagent used by MS Azure.")
+ Ohai::Log.debug("Plugin Azure: Found waagent used by MS Azure.")
return true
end
end
@@ -50,7 +50,7 @@ Ohai.plugin(:Azure) do
if File.exist?("/var/lib/dhcp/dhclient.eth0.leases")
File.open("/var/lib/dhcp/dhclient.eth0.leases").each do |line|
if line =~ /unknown-245/
- Ohai::Log.debug("azure plugin: Found unknown-245 DHCP option used by MS Azure.")
+ Ohai::Log.debug("Plugin Azure: Found unknown-245 DHCP option used by MS Azure.")
has_245 = true
break
end
diff --git a/lib/ohai/plugins/c.rb b/lib/ohai/plugins/c.rb
index e5107cdc..3dee1492 100644
--- a/lib/ohai/plugins/c.rb
+++ b/lib/ohai/plugins/c.rb
@@ -28,10 +28,10 @@ Ohai.plugin(:C) do
if so.exitstatus == 0
yield(so)
else
- Ohai::Log.debug("Plugin C '#{cmd}' failed. Skipping data.")
+ Ohai::Log.debug("Plugin C: '#{cmd}' failed. Skipping data.")
end
rescue Ohai::Exceptions::Exec
- Ohai::Log.debug("Plugin C '#{cmd}' binary could not be found. Skipping data.")
+ Ohai::Log.debug("Plugin C: '#{cmd}' binary could not be found. Skipping data.")
end
collect_data do
diff --git a/lib/ohai/plugins/dmi.rb b/lib/ohai/plugins/dmi.rb
index bcda1c4a..6acf7feb 100644
--- a/lib/ohai/plugins/dmi.rb
+++ b/lib/ohai/plugins/dmi.rb
@@ -92,14 +92,14 @@ Ohai.plugin(:DMI) do
elsif type = type_line.match(line)
if dmi_record == nil
- Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}")
+ Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}")
next
end
dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:application_identifier] = type[1]
elsif data = data_line.match(line)
if dmi_record == nil
- Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}")
+ Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}")
next
end
dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = data[2]
@@ -107,11 +107,11 @@ Ohai.plugin(:DMI) do
elsif extended_data = extended_data_line.match(line)
if dmi_record == nil
- Ohai::Log.debug("unexpected extended data line found before header; discarding:\n#{line}")
+ Ohai::Log.debug("Plugin DMI: unexpected extended data line found before header; discarding:\n#{line}")
next
end
if field == nil
- Ohai::Log.debug("unexpected extended data line found outside data section; discarding:\n#{line}")
+ Ohai::Log.debug("Plugin DMI: unexpected extended data line found outside data section; discarding:\n#{line}")
next
end
# overwrite "raw" value with a new Mash
@@ -119,7 +119,7 @@ Ohai.plugin(:DMI) do
dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field][extended_data[1]] = nil
else
- Ohai::Log.debug("unrecognized output line; discarding:\n#{line}")
+ Ohai::Log.debug("Plugin DMI: unrecognized output line; discarding:\n#{line}")
end
end
diff --git a/lib/ohai/plugins/groovy.rb b/lib/ohai/plugins/groovy.rb
index 7edbb67c..431a9dab 100644
--- a/lib/ohai/plugins/groovy.rb
+++ b/lib/ohai/plugins/groovy.rb
@@ -32,7 +32,7 @@ Ohai.plugin(:Groovy) do
languages[:groovy] = groovy
end
rescue Ohai::Exceptions::Exec
- Ohai::Log.debug('Groovy plugin: Could not shell_out "groovy -v". Skipping plugin')
+ Ohai::Log.debug('Plugin Groovy: Could not shell_out "groovy -v". Skipping plugin')
end
end
end
diff --git a/lib/ohai/plugins/haskell.rb b/lib/ohai/plugins/haskell.rb
index d3070e04..07132581 100644
--- a/lib/ohai/plugins/haskell.rb
+++ b/lib/ohai/plugins/haskell.rb
@@ -39,7 +39,7 @@ Ohai.plugin(:Haskell) do
haskell[:ghc][:description] = so.stdout.chomp
end
rescue Ohai::Exceptions::Exec
- Ohai::Log.debug('Haskell plugin: Could not shell_out "ghc --version". Skipping data')
+ Ohai::Log.debug('Plugin Haskell: Could not shell_out "ghc --version". Skipping data')
end
# Check for ghci
@@ -54,7 +54,7 @@ Ohai.plugin(:Haskell) do
haskell[:ghci][:description] = so.stdout.chomp
end
rescue Ohai::Exceptions::Exec
- Ohai::Log.debug('Haskell plugin: Could not shell_out "ghci --version". Skipping data')
+ Ohai::Log.debug('Plugin Haskell: Could not shell_out "ghci --version". Skipping data')
end
# Check for cabal
@@ -70,7 +70,7 @@ Ohai.plugin(:Haskell) do
haskell[:cabal][:description] = so.stdout.split("\n")[0].chomp
end
rescue Ohai::Exceptions::Exec
- Ohai::Log.debug('Haskell plugin: Could not shell_out "cabal --version". Skipping data')
+ Ohai::Log.debug('Plugin Haskell: Could not shell_out "cabal --version". Skipping data')
end
# Check for stack
@@ -87,7 +87,7 @@ Ohai.plugin(:Haskell) do
haskell[:stack][:description] = so.stdout.chomp
end
rescue Ohai::Exceptions::Exec
- Ohai::Log.debug('Haskell plugin: Could not shell_out "stack --version". Skipping data')
+ Ohai::Log.debug('Plugin Haskell: Could not shell_out "stack --version". Skipping data')
end
languages[:haskell] = haskell unless haskell.empty?
diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb
index 0f1b2c22..32d95fb3 100644
--- a/lib/ohai/plugins/hostname.rb
+++ b/lib/ohai/plugins/hostname.rb
@@ -120,19 +120,19 @@ Ohai.plugin(:Hostname) do
# Sometimes... very rarely, but sometimes, 'hostname --fqdn' falsely
# returns a blank string. WTF.
if ourfqdn.nil? || ourfqdn.empty?
- Ohai::Log.debug("hostname returned an empty string, retrying once.")
+ Ohai::Log.debug("Plugin Hostname: hostname returned an empty string, retrying once.")
ourfqdn = resolve_fqdn
end
if ourfqdn.nil? || ourfqdn.empty?
- Ohai::Log.debug("hostname returned an empty string twice and will" +
+ Ohai::Log.debug("Plugin Hostname: hostname returned an empty string twice and will" +
"not be set.")
else
fqdn ourfqdn
end
rescue
Ohai::Log.debug(
- "hostname returned an error, probably no domain set")
+ "Plugin Hostname: hostname returned an error, probably no domain set")
end
domain collect_domain
end
@@ -152,20 +152,20 @@ Ohai.plugin(:Hostname) do
# Sometimes... very rarely, but sometimes, 'hostname --fqdn' falsely
# returns a blank string. WTF.
if ourfqdn.nil? || ourfqdn.empty?
- Ohai::Log.debug("hostname --fqdn returned an empty string, retrying " +
+ Ohai::Log.debug("Plugin Hostname: hostname --fqdn returned an empty string, retrying " +
"once.")
ourfqdn = from_cmd("hostname --fqdn")
end
if ourfqdn.nil? || ourfqdn.empty?
- Ohai::Log.debug("hostname --fqdn returned an empty string twice and " +
+ Ohai::Log.debug("Plugin Hostname: hostname --fqdn returned an empty string twice and " +
"will not be set.")
else
fqdn ourfqdn
end
rescue
Ohai::Log.debug(
- "hostname --fqdn returned an error, probably no domain set")
+ "Plugin Hostname: hostname --fqdn returned an error, probably no domain set")
end
domain collect_domain
end
diff --git a/lib/ohai/plugins/ip_scopes.rb b/lib/ohai/plugins/ip_scopes.rb
index e9367762..5ef5474e 100644
--- a/lib/ohai/plugins/ip_scopes.rb
+++ b/lib/ohai/plugins/ip_scopes.rb
@@ -43,7 +43,7 @@ Ohai.plugin(:IpScopes) do
rescue LoadError => e
# our favourite gem is not installed. Boohoo.
- Ohai::Log.debug("Plugin ip_scopes: cannot load gem, plugin disabled: #{e}")
+ Ohai::Log.debug("Plugin IpScopes: cannot load gem, plugin disabled: #{e}")
end
end
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index 98c95245..5d9c2952 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -80,7 +80,7 @@ Ohai.plugin(:Network) do
so = shell_out("ip -o -f #{family[:name]} route show table #{default_route_table}")
so.stdout.lines do |line|
line.strip!
- Ohai::Log.debug("Parsing #{line}")
+ Ohai::Log.debug("Plugin Network: Parsing #{line}")
if line =~ /\\/
parts = line.split('\\')
route_dest = parts.shift.strip
@@ -95,13 +95,13 @@ Ohai.plugin(:Network) do
if route_ending =~ /\bdev\s+([^\s]+)\b/
route_int = $1
else
- Ohai::Log.debug("Skipping route entry without a device: '#{line}'")
+ Ohai::Log.debug("Plugin Network: Skipping route entry without a device: '#{line}'")
next
end
route_int = "venet0:0" if is_openvz? && !is_openvz_host? && route_int == "venet0" && iface["venet0:0"]
unless iface[route_int]
- Ohai::Log.debug("Skipping previously unseen interface from 'ip route show': #{route_int}")
+ Ohai::Log.debug("Plugin Network: Skipping previously unseen interface from 'ip route show': #{route_int}")
next
end
@@ -118,7 +118,7 @@ Ohai.plugin(:Network) do
addr = iface[route_int][:addresses]
unless addr.nil? || addr.has_key?(route_entry[:src]) ||
addr.values.all? { |a| a["family"] != family[:name] }
- Ohai::Log.debug("Skipping route entry whose src does not match the interface IP")
+ Ohai::Log.debug("Plugin Network: Skipping route entry whose src does not match the interface IP")
next
end
end
@@ -156,7 +156,7 @@ Ohai.plugin(:Network) do
so = shell_out("#{ethtool_binary} #{tmp_int}")
so.stdout.lines do |line|
line.chomp!
- Ohai::Log.debug("Parsing ethtool output: #{line}")
+ Ohai::Log.debug("Plugin Network: Parsing ethtool output: #{line}")
line.lstrip!
k, v = line.split(": ")
next unless keys.include? k
@@ -177,7 +177,7 @@ Ohai.plugin(:Network) do
iface.each_key do |tmp_int|
next unless iface[tmp_int][:encapsulation] == "Ethernet"
so = shell_out("#{ethtool_binary} -g #{tmp_int}")
- Ohai::Log.debug("Parsing ethtool output: #{so.stdout}")
+ Ohai::Log.debug("Plugin Network: Parsing ethtool output: #{so.stdout}")
type = nil
iface[tmp_int]["ring_params"] = {}
so.stdout.lines.each do |line|
@@ -462,7 +462,7 @@ Ohai.plugin(:Network) do
else
default_route_table = configuration(:default_route_table)
end
- Ohai::Log.debug("default route table is '#{default_route_table}'")
+ Ohai::Log.debug("Plugin Network: default route table is '#{default_route_table}'")
# Match the lead line for an interface from iproute2
# 3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
@@ -507,14 +507,14 @@ Ohai.plugin(:Network) do
else
"default_#{family[:name]}_interface"
end
- Ohai::Log.debug("Unable to determine '#{attribute_name}' as no default routes were found for that interface family")
+ Ohai::Log.debug("Plugin Network: Unable to determine '#{attribute_name}' as no default routes were found for that interface family")
else
network["#{default_prefix}_interface"] = default_route[:dev]
- Ohai::Log.debug("#{default_prefix}_interface set to #{default_route[:dev]}")
+ Ohai::Log.debug("Plugin Network: #{default_prefix}_interface set to #{default_route[:dev]}")
# setting gateway to 0.0.0.0 or :: if the default route is a link level one
network["#{default_prefix}_gateway"] = default_route[:via] ? default_route[:via] : family[:default_route].chomp("/0")
- Ohai::Log.debug("#{default_prefix}_gateway set to #{network["#{default_prefix}_gateway"]}")
+ Ohai::Log.debug("Plugin Network: #{default_prefix}_gateway set to #{network["#{default_prefix}_gateway"]}")
# deduce the default route the user most likely cares about to pick {ip,mac,ip6}address below
favored_route = favored_default_route(routes, iface, default_route, family)
@@ -527,20 +527,20 @@ Ohai.plugin(:Network) do
if family[:name] == "inet"
ipaddress favored_route[:src]
m = get_mac_for_interface(iface, favored_route[:dev])
- Ohai::Log.debug("Overwriting macaddress #{macaddress} with #{m} from interface #{favored_route[:dev]}") if macaddress
+ Ohai::Log.debug("Plugin Network: Overwriting macaddress #{macaddress} with #{m} from interface #{favored_route[:dev]}") if macaddress
macaddress m
elsif family[:name] == "inet6"
# this rarely does anything since we rarely have src for ipv6, so this usually falls back on the network plugin
ip6address favored_route[:src]
if macaddress
- Ohai::Log.debug("Not setting macaddress from ipv6 interface #{favored_route[:dev]} because macaddress is already set")
+ Ohai::Log.debug("Plugin Network: Not setting macaddress from ipv6 interface #{favored_route[:dev]} because macaddress is already set")
else
macaddress get_mac_for_interface(iface, favored_route[:dev])
end
end
else
- Ohai::Log.debug("the linux/network plugin was unable to deduce the favored default route for family '#{family[:name]}' despite finding a default route, and is not setting ipaddress/ip6address/macaddress. the network plugin may provide fallbacks.")
- Ohai::Log.debug("this potential default route was excluded: #{default_route}")
+ Ohai::Log.debug("Plugin Network: Unable to deduce the favored default route for family '#{family[:name]}' despite finding a default route, and is not setting ipaddress/ip6address/macaddress. the network plugin may provide fallbacks.")
+ Ohai::Log.debug("Plugin Network: This potential default route was excluded: #{default_route}")
end
end
end # end families.each
@@ -550,7 +550,7 @@ Ohai.plugin(:Network) do
route_result = so.stdout.split($/).grep( /^0.0.0.0/ )[0].split( /[ \t]+/ )
network[:default_gateway], network[:default_interface] = route_result.values_at(1, 7)
rescue Ohai::Exceptions::Exec
- Ohai::Log.debug("Unable to determine default interface")
+ Ohai::Log.debug("Plugin Network: Unable to determine default interface")
end
so = shell_out("ifconfig -a")
diff --git a/lib/ohai/plugins/linux/sessions.rb b/lib/ohai/plugins/linux/sessions.rb
index a2a3a09b..7fb2b5ae 100644
--- a/lib/ohai/plugins/linux/sessions.rb
+++ b/lib/ohai/plugins/linux/sessions.rb
@@ -45,6 +45,8 @@ Ohai.plugin(:Sessions) do
sessions[:by_user][user] = [s]
end
end
+ else
+ Ohai::Log.debug("Plugin Sessions: Could not find loginctl. Skipping plugin.")
end
end
end
diff --git a/lib/ohai/plugins/linux/virtualization.rb b/lib/ohai/plugins/linux/virtualization.rb
index ec101314..a0409472 100644
--- a/lib/ohai/plugins/linux/virtualization.rb
+++ b/lib/ohai/plugins/linux/virtualization.rb
@@ -49,6 +49,7 @@ Ohai.plugin(:Virtualization) do
# This file should exist on most Xen systems, normally empty for guests
if File.exist?("/proc/xen/capabilities")
if File.read("/proc/xen/capabilities") =~ /control_d/i
+ Ohai::Log.debug("Plugin Virtualization: /proc/xen/capabilities contains control_d. Detecting as Xen host")
virtualization[:role] = "host"
virtualization[:systems][:xen] = "host"
end
@@ -65,10 +66,12 @@ Ohai.plugin(:Virtualization) do
if File.exist?("/proc/modules")
modules = File.read("/proc/modules")
if modules =~ /^vboxdrv/
+ Ohai::Log.debug("Plugin Virtualization: /proc/modules contains vboxdrv. Detecting as vbox host")
virtualization[:system] = "vbox"
virtualization[:role] = "host"
virtualization[:systems][:vbox] = "host"
elsif modules =~ /^vboxguest/
+ Ohai::Log.debug("Plugin Virtualization: /proc/modules contains vboxguest. Detecting as vbox guest")
virtualization[:system] = "vbox"
virtualization[:role] = "guest"
virtualization[:systems][:vbox] = "guest"
@@ -77,6 +80,7 @@ Ohai.plugin(:Virtualization) do
# if nova binary is present we're on an openstack host
if nova_exists?
+ Ohai::Log.debug("Plugin Virtualization: nova command exists. Detecting as openstack host")
virtualization[:system] = "openstack"
virtualization[:role] = "host"
virtualization[:systems][:openstack] = "host"
@@ -85,6 +89,7 @@ Ohai.plugin(:Virtualization) do
# Detect paravirt KVM/QEMU from cpuinfo, report as KVM
if File.exist?("/proc/cpuinfo")
if File.read("/proc/cpuinfo") =~ /QEMU Virtual CPU|Common KVM processor|Common 32-bit KVM processor/
+ Ohai::Log.debug("Plugin Virtualization: /proc/cpuinfo lists a KVM paravirt CPU string. Detecting as kvm guest")
virtualization[:system] = "kvm"
virtualization[:role] = "guest"
virtualization[:systems][:kvm] = "guest"
@@ -96,9 +101,11 @@ Ohai.plugin(:Virtualization) do
if File.exist?("/sys/devices/virtual/misc/kvm")
virtualization[:system] = "kvm"
if File.read("/proc/cpuinfo") =~ /hypervisor/
+ Ohai::Log.debug("Plugin Virtualization: /sys/devices/virtual/misc/kvm present and /proc/cpuinfo lists the hypervisor feature. Detecting as kvm guest")
virtualization[:role] = "guest"
virtualization[:systems][:kvm] = "guest"
else
+ Ohai::Log.debug("Plugin Virtualization: /sys/devices/virtual/misc/kvm present and /proc/cpuinfo does not list the hypervisor feature. Detecting as kvm host")
virtualization[:role] = "host"
virtualization[:systems][:kvm] = "host"
end
@@ -107,10 +114,12 @@ Ohai.plugin(:Virtualization) do
# Detect OpenVZ / Virtuozzo.
# http://wiki.openvz.org/BC_proc_entries
if File.exist?("/proc/bc/0")
+ Ohai::Log.debug("Plugin Virtualization: /proc/bc/0 exists. Detecting as openvz host")
virtualization[:system] = "openvz"
virtualization[:role] = "host"
virtualization[:systems][:openvz] = "host"
elsif File.exist?("/proc/vz")
+ Ohai::Log.debug("Plugin Virtualization: /proc/vz exists. Detecting as openvz guest")
virtualization[:system] = "openvz"
virtualization[:role] = "guest"
virtualization[:systems][:openvz] = "guest"
@@ -119,6 +128,7 @@ Ohai.plugin(:Virtualization) do
# Detect Parallels virtual machine from pci devices
if File.exist?("/proc/bus/pci/devices")
if File.read("/proc/bus/pci/devices") =~ /1ab84000/
+ Ohai::Log.debug("Plugin Virtualization: /proc/bus/pci/devices contains '1ab84000' pci device. Detecting as parallels guest")
virtualization[:system] = "parallels"
virtualization[:role] = "guest"
virtualization[:systems][:parallels] = "guest"
@@ -129,6 +139,7 @@ Ohai.plugin(:Virtualization) do
if File.exist?("/usr/sbin/dmidecode")
guest = guest_from_dmi(shell_out("dmidecode").stdout)
if guest
+ Ohai::Log.debug("Plugin Virtualization: dmidecode contains string indicating #{guest} guest")
virtualization[:system] = guest
virtualization[:role] = "guest"
virtualization[:systems][guest.to_sym] = "guest"
@@ -142,9 +153,11 @@ Ohai.plugin(:Virtualization) do
if vxid && vxid[2]
virtualization[:system] = "linux-vserver"
if vxid[2] == "0"
+ Ohai::Log.debug("Plugin Virtualization: /proc/self/status contains 's_context' or 'VxID' with a value of 0. Detecting as linux-vserver host")
virtualization[:role] = "host"
virtualization[:systems]["linux-vserver"] = "host"
else
+ Ohai::Log.debug("Plugin Virtualization: /proc/self/status contains 's_context' or 'VxID' with a non-0 value. Detecting as linux-vserver guest")
virtualization[:role] = "guest"
virtualization[:systems]["linux-vserver"] = "guest"
end
@@ -173,6 +186,7 @@ Ohai.plugin(:Virtualization) do
cgroup_content = File.read("/proc/self/cgroup")
if cgroup_content =~ %r{^\d+:[^:]+:/(lxc|docker)/.+$} ||
cgroup_content =~ %r{^\d+:[^:]+:/[^/]+/(lxc|docker)-.+$}
+ Ohai::Log.debug("Plugin Virtualization: /proc/self/cgroup indicates #{$1} container. Detecting as #{$1} guest")
virtualization[:system] = $1
virtualization[:role] = "guest"
virtualization[:systems][$1.to_sym] = "guest"
@@ -181,6 +195,7 @@ Ohai.plugin(:Virtualization) do
# Even so, it is likely we are on an LXC capable host that is not being used as such
# So we're cautious here to not overwrite other existing values (OHAI-573)
unless virtualization[:system] && virtualization[:role]
+ Ohai::Log.debug("Plugin Virtualization: /proc/self/cgroup and lxc-version command exist. Detecting as lxc host")
virtualization[:system] = "lxc"
virtualization[:role] = "host"
end
@@ -190,6 +205,7 @@ Ohai.plugin(:Virtualization) do
virtualization[:systems][:lxc] = "host"
end
elsif File.exist?("/.dockerenv") || File.exist?("/.dockerinit")
+ Ohai::Log.debug("Plugin Virtualization: .dockerenv or .dockerinit exist. Detecting as docker guest")
virtualization[:system] = "docker"
virtualization[:role] = "guest"
virtualization[:systems][:docker] = "guest"
@@ -198,9 +214,11 @@ Ohai.plugin(:Virtualization) do
# Detect LXD
# See https://github.com/lxc/lxd/blob/master/doc/dev-lxd.md
if File.exist?("/dev/lxd/sock")
+ Ohai::Log.debug("Plugin Virtualization: /dev/lxd/sock exists. Detecting as lxd guest")
virtualization[:system] = "lxd"
virtualization[:role] = "guest"
elsif File.exist?("/var/lib/lxd/devlxd")
+ Ohai::Log.debug("Plugin Virtualization: /var/lib/lxd/devlxd exists. Detecting as lxd host")
virtualization[:system] = "lxd"
virtualization[:role] = "host"
end
diff --git a/lib/ohai/plugins/lua.rb b/lib/ohai/plugins/lua.rb
index 0a6aaeab..8c1ff496 100644
--- a/lib/ohai/plugins/lua.rb
+++ b/lib/ohai/plugins/lua.rb
@@ -31,7 +31,7 @@ Ohai.plugin(:Lua) do
languages[:lua] = lua if lua[:version]
end
rescue Ohai::Exceptions::Exec
- Ohai::Log.debug('Lua plugin: Could not shell_out "lua -v". Skipping plugin')
+ Ohai::Log.debug('Plugin Lua: Could not shell_out "lua -v". Skipping plugin')
end
end
end
diff --git a/lib/ohai/plugins/network.rb b/lib/ohai/plugins/network.rb
index 1a1175f5..91547d19 100644
--- a/lib/ohai/plugins/network.rb
+++ b/lib/ohai/plugins/network.rb
@@ -77,13 +77,13 @@ Ohai.plugin(:NetworkAddresses) do
v[:iface] == network[int_attr]
end
if gw_if_ips.empty?
- Ohai::Log.warn("[#{family}] no ip address on #{network[int_attr]}")
+ Ohai::Log.warn("Plugin Network: [#{family}] no ip address on #{network[int_attr]}")
elsif network[gw_attr] &&
network["interfaces"][network[int_attr]] &&
network["interfaces"][network[int_attr]]["addresses"]
if [ "0.0.0.0", "::", /^fe80:/ ].any? { |pat| pat === network[gw_attr] }
# link level default route
- Ohai::Log.debug("link level default #{family} route, picking ip from #{network[gw_attr]}")
+ Ohai::Log.debug("Plugin Network: link level default #{family} route, picking ip from #{network[gw_attr]}")
r = gw_if_ips.first
else
# checking network masks
@@ -92,9 +92,9 @@ Ohai.plugin(:NetworkAddresses) do
end.first
if r.nil?
r = gw_if_ips.first
- Ohai::Log.debug("[#{family}] no ipaddress/mask on #{network[int_attr]} matching the gateway #{network[gw_attr]}, picking #{r[:ipaddress]}")
+ Ohai::Log.debug("Plugin Network: [#{family}] no ipaddress/mask on #{network[int_attr]} matching the gateway #{network[gw_attr]}, picking #{r[:ipaddress]}")
else
- Ohai::Log.debug("[#{family}] Using default interface #{network[int_attr]} and default gateway #{network[gw_attr]} to set the default ip to #{r[:ipaddress]}")
+ Ohai::Log.debug("Plugin Network: [#{family}] Using default interface #{network[int_attr]} and default gateway #{network[gw_attr]} to set the default ip to #{r[:ipaddress]}")
end
end
else
@@ -103,7 +103,7 @@ Ohai.plugin(:NetworkAddresses) do
end
else
r = ips.first
- Ohai::Log.debug("[#{family}] no default interface, picking the first ipaddress")
+ Ohai::Log.debug("Plugin Network: [#{family}] no default interface, picking the first ipaddress")
end
return [ nil, nil ] if r.nil? || r.empty?
@@ -149,13 +149,13 @@ Ohai.plugin(:NetworkAddresses) do
# don't overwrite attributes if they've already been set by the "#{os}::network" plugin
if (family == "inet") && ipaddress.nil?
if r["ip"].nil?
- Ohai::Log.warn("unable to detect ipaddress")
+ Ohai::Log.warn("Plugin Network: unable to detect ipaddress")
else
ipaddress r["ip"]
end
elsif (family == "inet6") && ip6address.nil?
if r["ip"].nil?
- Ohai::Log.debug("unable to detect ip6address")
+ Ohai::Log.debug("Plugin Network: unable to detect ip6address")
else
ip6address r["ip"]
end
@@ -165,10 +165,10 @@ Ohai.plugin(:NetworkAddresses) do
# otherwise we set macaddress on a first-found basis (and we started with ipv4)
if macaddress.nil?
if r["mac"]
- Ohai::Log.debug("setting macaddress to '#{r["mac"]}' from interface '#{r["iface"]}' for family '#{family}'")
+ Ohai::Log.debug("Plugin Network: setting macaddress to '#{r["mac"]}' from interface '#{r["iface"]}' for family '#{family}'")
macaddress r["mac"]
else
- Ohai::Log.debug("unable to detect macaddress for family '#{family}'")
+ Ohai::Log.debug("Plugin Network: unable to detect macaddress for family '#{family}'")
end
end
@@ -177,7 +177,7 @@ Ohai.plugin(:NetworkAddresses) do
if results["inet"]["iface"] && results["inet6"]["iface"] &&
(results["inet"]["iface"] != results["inet6"]["iface"])
- Ohai::Log.debug("ipaddress and ip6address are set from different interfaces (#{results["inet"]["iface"]} & #{results["inet6"]["iface"]})")
+ Ohai::Log.debug("Plugin Network: ipaddress and ip6address are set from different interfaces (#{results["inet"]["iface"]} & #{results["inet6"]["iface"]})")
end
end
end
diff --git a/lib/ohai/plugins/scala.rb b/lib/ohai/plugins/scala.rb
index f847a565..ee905a64 100644
--- a/lib/ohai/plugins/scala.rb
+++ b/lib/ohai/plugins/scala.rb
@@ -28,7 +28,7 @@ Ohai.plugin(:Scala) do
scala[:version] = so.stderr.split[4]
end
rescue Ohai::Exceptions::Exec
- Ohai::Log.debug('Scala plugin: Could not shell_out "scala -version". Skipping data')
+ Ohai::Log.debug('Plugin Scala: Could not shell_out "scala -version". Skipping data')
end
# Check for sbt
@@ -40,7 +40,7 @@ Ohai.plugin(:Scala) do
scala[:sbt][:version] = so.stdout.split[3]
end
rescue Ohai::Exceptions::Exec
- Ohai::Log.debug('Scala plugin: Could not shell_out "sbt --version". Skipping data')
+ Ohai::Log.debug('Plugin Scala: Could not shell_out "sbt --version". Skipping data')
end
languages[:scala] = scala unless scala.empty?
diff --git a/lib/ohai/plugins/solaris2/dmi.rb b/lib/ohai/plugins/solaris2/dmi.rb
index 3f98dbfe..32f935db 100644
--- a/lib/ohai/plugins/solaris2/dmi.rb
+++ b/lib/ohai/plugins/solaris2/dmi.rb
@@ -153,7 +153,7 @@ Ohai.plugin(:DMI) do
elsif data = data_key_value_line.match(line)
if dmi_record == nil
- Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}")
+ Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}")
next
end
dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = data[2]
@@ -161,7 +161,7 @@ Ohai.plugin(:DMI) do
elsif data = data_key_only_line.match(line)
if dmi_record == nil
- Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}")
+ Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}")
next
end
dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = ""
@@ -169,11 +169,11 @@ Ohai.plugin(:DMI) do
elsif extended_data = extended_data_line.match(line)
if dmi_record == nil
- Ohai::Log.debug("unexpected extended data line found before header; discarding:\n#{line}")
+ Ohai::Log.debug("Plugin DMI: unexpected extended data line found before header; discarding:\n#{line}")
next
end
if field == nil
- Ohai::Log.debug("unexpected extended data line found outside data section; discarding:\n#{line}")
+ Ohai::Log.debug("Plugin DMI: unexpected extended data line found outside data section; discarding:\n#{line}")
next
end
# overwrite "raw" value with a new Mash
@@ -181,7 +181,7 @@ Ohai.plugin(:DMI) do
dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field][extended_data[1]] = extended_data[2]
else
- Ohai::Log.debug("unrecognized output line; discarding:\n#{line}")
+ Ohai::Log.debug("Plugin DMI: unrecognized output line; discarding:\n#{line}")
end
end
diff --git a/lib/ohai/plugins/virtualbox.rb b/lib/ohai/plugins/virtualbox.rb
index 435f649f..36558552 100644
--- a/lib/ohai/plugins/virtualbox.rb
+++ b/lib/ohai/plugins/virtualbox.rb
@@ -20,25 +20,30 @@ Ohai.plugin(:Virtualbox) do
provides "virtualbox"
collect_data do
- so = shell_out("VBoxControl guestproperty enumerate")
- if so.exitstatus == 0
- virtualbox Mash.new
- virtualbox[:host] = Mash.new
- virtualbox[:guest] = Mash.new
- so.stdout.lines.each do |line|
- case line
- when /LanguageID, value: (\S*),/
- virtualbox[:host][:language] = Regexp.last_match(1)
- when /VBoxVer, value: (\S*),/
- virtualbox[:host][:version] = Regexp.last_match(1)
- when /VBoxRev, value: (\S*),/
- virtualbox[:host][:revision] = Regexp.last_match(1)
- when /GuestAdd\/VersionExt, value: (\S*),/
- virtualbox[:guest][:guest_additions_version] = Regexp.last_match(1)
- when /GuestAdd\/Revision, value: (\S*),/
- virtualbox[:guest][:guest_additions_revision] = Regexp.last_match(1)
+ begin
+ so = shell_out("VBoxControl guestproperty enumerate")
+
+ if so.exitstatus == 0
+ virtualbox Mash.new
+ virtualbox[:host] = Mash.new
+ virtualbox[:guest] = Mash.new
+ so.stdout.lines.each do |line|
+ case line
+ when /LanguageID, value: (\S*),/
+ virtualbox[:host][:language] = Regexp.last_match(1)
+ when /VBoxVer, value: (\S*),/
+ virtualbox[:host][:version] = Regexp.last_match(1)
+ when /VBoxRev, value: (\S*),/
+ virtualbox[:host][:revision] = Regexp.last_match(1)
+ when /GuestAdd\/VersionExt, value: (\S*),/
+ virtualbox[:guest][:guest_additions_version] = Regexp.last_match(1)
+ when /GuestAdd\/Revision, value: (\S*),/
+ virtualbox[:guest][:guest_additions_revision] = Regexp.last_match(1)
+ end
end
end
+ rescue Ohai::Exceptions::Exec
+ Ohai::Log.debug('Plugin Virtualbox: Could not execute "VBoxControl guestproperty enumerate". Skipping data')
end
end
end
diff --git a/lib/ohai/plugins/vmware.rb b/lib/ohai/plugins/vmware.rb
index 53327e41..73b2505d 100644
--- a/lib/ohai/plugins/vmware.rb
+++ b/lib/ohai/plugins/vmware.rb
@@ -42,7 +42,7 @@ Ohai.plugin(:VMware) do
def get_vm_attributes(vmtools_path)
if !File.exist?(vmtools_path)
- Ohai::Log.debug("#{vmtools_path} not found")
+ Ohai::Log.debug("Plugin VMware: #{vmtools_path} not found")
else
vmware Mash.new
begin
@@ -62,7 +62,7 @@ Ohai.plugin(:VMware) do
vmware[param] = from_cmd("#{vmtools_path} #{param} status")
end
rescue
- Ohai::Log.debug("Error while collecting VMware guest attributes")
+ Ohai::Log.debug("Plugin VMware: Error while collecting VMware guest attributes")
end
end
end
diff --git a/lib/ohai/util/file_helper.rb b/lib/ohai/util/file_helper.rb
index 5b08e2db..eb9a12e9 100644
--- a/lib/ohai/util/file_helper.rb
+++ b/lib/ohai/util/file_helper.rb
@@ -26,11 +26,11 @@ module Ohai
paths.each do |path|
filename = File.join(path, cmd)
if File.executable?(filename)
- Ohai::Log.debug("#{self.name} plugin: found #{cmd} at #{filename}")
+ Ohai::Log.debug("Plugin #{self.name}: found #{cmd} at #{filename}")
return filename
end
end
- Ohai::Log.debug("#{self.name} plugin: did not find #{cmd}")
+ Ohai::Log.debug("Plugin #{self.name}: did not find #{cmd}")
false
end
end
diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb
index 6e78997f..4b88ebe2 100644
--- a/spec/unit/plugins/linux/network_spec.rb
+++ b/spec/unit/plugins/linux/network_spec.rb
@@ -1325,7 +1325,7 @@ EOM
end
it "logs a message and skips previously unseen interfaces in 'ip route show'" do
- expect(Ohai::Log).to receive(:debug).with("Skipping previously unseen interface from 'ip route show': virbr0").once
+ expect(Ohai::Log).to receive(:debug).with(/Skipping previously unseen interface from 'ip route show': virbr0/).once
allow(Ohai::Log).to receive(:debug) # Catches the 'Loading plugin network' type messages
plugin.run
end
diff --git a/spec/unit/plugins/network_spec.rb b/spec/unit/plugins/network_spec.rb
index 60d4cac6..31780b57 100644
--- a/spec/unit/plugins/network_spec.rb
+++ b/spec/unit/plugins/network_spec.rb
@@ -367,7 +367,7 @@ describe Ohai::System, "Network Plugin" do
end
it "informs about this setup" do
- expect(Ohai::Log).to receive(:debug).with(/^ipaddress and ip6address are set from different interfaces/)
+ expect(Ohai::Log).to receive(:debug).with(/ipaddress and ip6address are set from different interfaces/)
allow(Ohai::Log).to receive(:debug)
@plugin.run
end
@@ -396,7 +396,7 @@ describe Ohai::System, "Network Plugin" do
end
it "informs about this setup" do
- expect(Ohai::Log).to receive(:debug).with(/^ipaddress and ip6address are set from different interfaces/)
+ expect(Ohai::Log).to receive(:debug).with(/ipaddress and ip6address are set from different interfaces/)
allow(Ohai::Log).to receive(:debug)
@plugin.run
end
@@ -421,8 +421,8 @@ describe Ohai::System, "Network Plugin" do
end
it "warns about this conflict" do
- expect(Ohai::Log).to receive(:debug).with(/^\[inet\] no ipaddress\/mask on eth1/).once
- expect(Ohai::Log).to receive(:debug).with(/^\[inet6\] no ipaddress\/mask on eth1/).once
+ expect(Ohai::Log).to receive(:debug).with(/\[inet\] no ipaddress\/mask on eth1/).once
+ expect(Ohai::Log).to receive(:debug).with(/\[inet6\] no ipaddress\/mask on eth1/).once
allow(Ohai::Log).to receive(:debug)
@plugin.run
end
@@ -460,11 +460,11 @@ describe Ohai::System, "Network Plugin" do
end
it "warns about this conflict" do
- expect(Ohai::Log).to receive(:warn).with(/^unable to detect ipaddress/).once
- expect(Ohai::Log).to receive(:warn).with(/^\[inet\] no ip address on eth0/).once
- expect(Ohai::Log).to receive(:debug).with(/^unable to detect ip6address/).once
- expect(Ohai::Log).to receive(:debug).with(/^unable to detect macaddress/).twice # for each family
- expect(Ohai::Log).to receive(:warn).with(/^\[inet6\] no ip address on eth0/).once
+ expect(Ohai::Log).to receive(:warn).with(/unable to detect ipaddress/).once
+ expect(Ohai::Log).to receive(:warn).with(/\[inet\] no ip address on eth0/).once
+ expect(Ohai::Log).to receive(:debug).with(/unable to detect ip6address/).once
+ expect(Ohai::Log).to receive(:debug).with(/unable to detect macaddress/).twice # for each family
+ expect(Ohai::Log).to receive(:warn).with(/\[inet6\] no ip address on eth0/).once
@plugin.run
end
end
@@ -491,9 +491,9 @@ describe Ohai::System, "Network Plugin" do
end
it "should warn about it" do
- expect(Ohai::Log).to receive(:warn).with(/^unable to detect ipaddress/).once
- expect(Ohai::Log).to receive(:debug).with(/^unable to detect macaddress/).twice # for each family
- expect(Ohai::Log).to receive(:debug).with(/^unable to detect ip6address/).once
+ expect(Ohai::Log).to receive(:warn).with(/unable to detect ipaddress/).once
+ expect(Ohai::Log).to receive(:debug).with(/unable to detect macaddress/).twice # for each family
+ expect(Ohai::Log).to receive(:debug).with(/unable to detect ip6address/).once
@plugin.run
end
end
@@ -643,8 +643,8 @@ describe Ohai::System, "Network Plugin" do
it_populates_ipaddress_attributes
it "picks {ip,mac,ip6}address from the first interface" do
- expect(Ohai::Log).to receive(:debug).with(/^\[inet\] no default interface/).once
- expect(Ohai::Log).to receive(:debug).with(/^\[inet6\] no default interface/).once
+ expect(Ohai::Log).to receive(:debug).with(/\[inet\] no default interface/).once
+ expect(Ohai::Log).to receive(:debug).with(/\[inet6\] no default interface/).once
allow(Ohai::Log).to receive(:debug)
@plugin.run
expect(@plugin["ipaddress"]).to eq("192.168.99.11")
@@ -666,8 +666,8 @@ describe Ohai::System, "Network Plugin" do
it_populates_ipaddress_attributes
it "prefers global scope addressses to set {ip,mac,ip6}address" do
- expect(Ohai::Log).to receive(:debug).with(/^\[inet\] no default interface/).once
- expect(Ohai::Log).to receive(:debug).with(/^\[inet6\] no default interface/).once
+ expect(Ohai::Log).to receive(:debug).with(/\[inet\] no default interface/).once
+ expect(Ohai::Log).to receive(:debug).with(/\[inet6\] no default interface/).once
allow(Ohai::Log).to receive(:debug)
@plugin.run
expect(@plugin["ipaddress"]).to eq("192.168.99.11")
@@ -795,10 +795,10 @@ describe Ohai::System, "Network Plugin" do
end
it "warns about not being able to set {ip,mac}address (ipv4)" do
- expect(Ohai::Log).to receive(:warn).with(/^unable to detect ipaddress/).once
- expect(Ohai::Log).to receive(:debug).with(/^unable to detect macaddress/) # for ipv4
- expect(Ohai::Log).to receive(:debug).with(/^setting macaddress to/) # for ipv6
- expect(Ohai::Log).to receive(:debug).with(/^\[inet6\] Using default interface eth0 and default gateway/) # for ipv6
+ expect(Ohai::Log).to receive(:warn).with(/unable to detect ipaddress/).once
+ expect(Ohai::Log).to receive(:debug).with(/unable to detect macaddress/) # for ipv4
+ expect(Ohai::Log).to receive(:debug).with(/setting macaddress to/) # for ipv6
+ expect(Ohai::Log).to receive(:debug).with(/\[inet6\] Using default interface eth0 and default gateway/) # for ipv6
@plugin.run
end
@@ -810,7 +810,7 @@ describe Ohai::System, "Network Plugin" do
end
it "informs about macaddress being set using the ipv6 setup" do
- expect(Ohai::Log).to receive(:debug).with(/^setting macaddress to '00:16:3E:2F:36:79'/)
+ expect(Ohai::Log).to receive(:debug).with(/setting macaddress to '00:16:3E:2F:36:79'/)
allow(Ohai::Log).to receive(:debug)
@plugin.run
end
@@ -842,7 +842,7 @@ describe Ohai::System, "Network Plugin" do
end
it "informs about macaddress being set using the ipv6 setup" do
- expect(Ohai::Log).to receive(:debug).with(/^setting macaddress to '00:16:3E:2F:36:79'/)
+ expect(Ohai::Log).to receive(:debug).with(/setting macaddress to '00:16:3E:2F:36:79'/)
allow(Ohai::Log).to receive(:debug)
@plugin.run
end
@@ -962,7 +962,7 @@ describe Ohai::System, "Network Plugin" do
end
it "warns about not being able to set ipaddress" do
- expect(Ohai::Log).to receive(:warn).with(/^unable to detect ipaddress/).once
+ expect(Ohai::Log).to receive(:warn).with(/unable to detect ipaddress/).once
@plugin.run
end