ohai 0.6.4 → 0.6.6.rc.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,6 +19,7 @@
19
19
  require 'ohai/exception'
20
20
  require 'ohai/config'
21
21
  require 'ohai/log'
22
+ require 'stringio'
22
23
  require 'tmpdir'
23
24
  require 'fcntl'
24
25
  require 'etc'
@@ -299,6 +300,29 @@ module Ohai
299
300
  results = Process.waitpid2(cid) unless results
300
301
  o.rewind
301
302
  e.rewind
303
+
304
+ # **OHAI-275**
305
+ # The way we read from the pipes causes ruby to mark the strings
306
+ # as ASCII-8BIT (i.e., binary), but the content should be encoded
307
+ # as the default external encoding. For example, a command may
308
+ # return data encoded as UTF-8, but the strings will be marked as
309
+ # ASCII-8BIT. Later, when you attempt to print the values as
310
+ # UTF-8, Ruby will try to convert them and fail, raising an
311
+ # error.
312
+ #
313
+ # Ruby always marks strings as binary when read from IO in
314
+ # incomplete chunks, since you may have split the data within a
315
+ # multibyte char. In our case, we concat the chunks back
316
+ # together, so any multibyte chars will be reassembled.
317
+ #
318
+ # Note that all of this applies only to Ruby 1.9, which we check
319
+ # for by making sure that the Encoding class exists and strings
320
+ # have encoding methods.
321
+ if "".respond_to?(:force_encoding) && defined?(Encoding)
322
+ o.string.force_encoding(Encoding.default_external)
323
+ e.string.force_encoding(Encoding.default_external)
324
+ end
325
+
302
326
  b[cid, pi[0], o, e]
303
327
  results.last
304
328
  end
@@ -20,6 +20,17 @@ provides "virtualization"
20
20
 
21
21
  virtualization Mash.new
22
22
 
23
+ if from("sysctl -n security.jail.jailed").to_i == 1
24
+ virtualization[:system] = "jail"
25
+ virtualization[:role] = "guest"
26
+ end
27
+
28
+ # XXX doesn't work when jail is there but not running (ezjail-admin stop)
29
+ if from("jls -n \| wc -l").to_i >= 1
30
+ virtualization[:system] = "jail"
31
+ virtualization[:role] = "host"
32
+ end
33
+
23
34
  # KVM Host support for FreeBSD is in development
24
35
  # http://feanor.sssup.it/~fabio/freebsd/lkvm/
25
36
 
@@ -24,6 +24,8 @@ begin
24
24
  require_plugin "network"
25
25
 
26
26
  network['interfaces'].keys.each do |ifName|
27
+ next if network['interfaces'][ifName]['addresses'].nil?
28
+
27
29
  network['interfaces'][ifName]['addresses'].each do |address,attrs|
28
30
  begin
29
31
  attrs.merge! 'ip_scope' => address.to_ip.scope
@@ -66,7 +66,7 @@ popen4("ls -l /dev/disk/by-uuid/* | awk '{print $11, $9}'") do |pid, stdin, stdo
66
66
  end
67
67
 
68
68
  # Grab any missing mount information from /proc/mounts
69
- File.open('/proc/mounts').each do |line|
69
+ File.open('/proc/mounts').read_nonblock(4096).each do |line|
70
70
  if line =~ /^(\S+) (\S+) (\S+) (\S+) \S+ \S+$/
71
71
  filesystem = $1
72
72
  next if fs.has_key?(filesystem)
@@ -20,19 +20,40 @@ provides "lsb"
20
20
 
21
21
  lsb Mash.new
22
22
 
23
- begin
23
+ if File.exists?("/etc/lsb-release")
24
24
  File.open("/etc/lsb-release").each do |line|
25
25
  case line
26
- when /^DISTRIB_ID=(.+)$/
26
+ when /^DISTRIB_ID=["']?(.+?)["']?$/
27
27
  lsb[:id] = $1
28
- when /^DISTRIB_RELEASE=(.+)$/
28
+ when /^DISTRIB_RELEASE=["']?(.+?)["']?$/
29
29
  lsb[:release] = $1
30
- when /^DISTRIB_CODENAME=(.+)$/
30
+ when /^DISTRIB_CODENAME=["']?(.+?)["']?$/
31
31
  lsb[:codename] = $1
32
- when /^DISTRIB_DESCRIPTION=(.+)$/
32
+ when /^DISTRIB_DESCRIPTION=["']?(.+?)["']?$/
33
33
  lsb[:description] = $1
34
34
  end
35
35
  end
36
- rescue
37
- Ohai::Log.debug("Skipping LSB, cannot find /etc/lsb-release")
36
+ elsif File.exists?("/usr/bin/lsb_release")
37
+ # Fedora/Redhat, requires redhat-lsb package
38
+ popen4("lsb_release -a") do |pid, stdin, stdout, stderr|
39
+
40
+ stdin.close
41
+ stdout.each do |line|
42
+ case line
43
+ when /^Distributor ID:\s+(.+)$/
44
+ lsb[:id] = $1
45
+ when /^Description:\s+(.+)$/
46
+ lsb[:description] = $1
47
+ when /^Release:\s+(.+)$/
48
+ lsb[:release] = $1
49
+ when /^Codename:\s+(.+)$/
50
+ lsb[:codename] = $1
51
+ else
52
+ lsb[:id] = line
53
+ end
54
+
55
+ end
56
+ end
57
+ else
58
+ Ohai::Log.debug("Skipping LSB, cannot find /etc/lsb-release or /usr/bin/lsb_release")
38
59
  end
@@ -47,6 +47,7 @@ elsif File.exists?('/etc/gentoo-release')
47
47
  elsif File.exists?('/etc/SuSE-release')
48
48
  platform "suse"
49
49
  platform_version File.read("/etc/SuSE-release").scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join(".")
50
+ platform_version File.read("/etc/SuSE-release").scan(/VERSION = ([\d\.]{2,})/).flatten.join(".") if platform_version == ""
50
51
  elsif File.exists?('/etc/slackware-version')
51
52
  platform "slackware"
52
53
  platform_version File.read("/etc/slackware-version").scan(/(\d+|\.+)/).join
@@ -22,19 +22,27 @@ virtualization Mash.new
22
22
 
23
23
  # if it is possible to detect paravirt vs hardware virt, it should be put in
24
24
  # virtualization[:mechanism]
25
- if File.exists?("/proc/xen/capabilities") && File.read("/proc/xen/capabilities") =~ /control_d/i
26
- virtualization[:system] = "xen"
27
- virtualization[:role] = "host"
28
- elsif File.exists?("/proc/sys/xen/independent_wallclock")
25
+ if File.exists?("/proc/xen/capabilities")
29
26
  virtualization[:system] = "xen"
30
- virtualization[:role] = "guest"
27
+ if File.read("/proc/xen/capabilities") =~ /control_d/i
28
+ virtualization[:role] = "host"
29
+ else
30
+ virtualization[:role] = "guest"
31
+ end
31
32
  end
32
33
 
33
- # Detect KVM hosts by kernel module
34
+ # Detect from kernel module
34
35
  if File.exists?("/proc/modules")
35
- if File.read("/proc/modules") =~ /^kvm/
36
+ modules = File.read("/proc/modules")
37
+ if modules =~ /^kvm/
36
38
  virtualization[:system] = "kvm"
37
39
  virtualization[:role] = "host"
40
+ elsif modules =~ /^vboxdrv/
41
+ virtualization[:system] = "vbox"
42
+ virtualization[:role] = "host"
43
+ elsif modules =~ /^vboxguest/
44
+ virtualization[:system] = "vbox"
45
+ virtualization[:role] = "guest"
38
46
  end
39
47
  end
40
48
 
@@ -50,6 +58,17 @@ if File.exists?("/proc/cpuinfo")
50
58
  end
51
59
  end
52
60
 
61
+ # http://wiki.openvz.org/Proc/user_beancounters
62
+ if File.exists?("/proc/user_beancounters")
63
+ if File.read("/proc/user_beancounters") =~ /\n\s+0:\s+/
64
+ virtualization[:emulator] = "openvz"
65
+ virtualization[:role] = "host"
66
+ else
67
+ virtualization[:emulator] = "openvz"
68
+ virtualization[:role] = "guest"
69
+ end
70
+ end
71
+
53
72
  # http://www.dmo.ca/blog/detecting-virtualization-on-linux
54
73
  if File.exists?("/usr/sbin/dmidecode")
55
74
  popen4("dmidecode") do |pid, stdin, stdout, stderr|
@@ -57,19 +76,19 @@ if File.exists?("/usr/sbin/dmidecode")
57
76
  dmi_info = stdout.read
58
77
  case dmi_info
59
78
  when /Manufacturer: Microsoft/
60
- if dmi_info =~ /Product Name: Virtual Machine/
79
+ if dmi_info =~ /Product Name: Virtual Machine/
61
80
  virtualization[:system] = "virtualpc"
62
81
  virtualization[:role] = "guest"
63
- end
82
+ end
64
83
  when /Manufacturer: VMware/
65
- if dmi_info =~ /Product Name: VMware Virtual Platform/
84
+ if dmi_info =~ /Product Name: VMware Virtual Platform/
66
85
  virtualization[:system] = "vmware"
67
86
  virtualization[:role] = "guest"
68
87
  end
69
88
  when /Manufacturer: Xen/
70
89
  if dmi_info =~ /Product Name: HVM domU/
71
90
  virtualization[:system] = "xen"
72
- virtualization[:role] = "guest"
91
+ virtualization[:role] = "guest"
73
92
  end
74
93
  else
75
94
  nil
@@ -2,21 +2,31 @@ provides 'etc', 'current_user'
2
2
 
3
3
  require 'etc'
4
4
 
5
+ def fix_encoding(str)
6
+ str.force_encoding(Encoding.default_external) if str.respond_to?(:force_encoding)
7
+ str
8
+ end
9
+
5
10
  unless etc
6
11
  etc Mash.new
7
12
 
8
13
  etc[:passwd] = Mash.new
9
14
  etc[:group] = Mash.new
10
-
15
+
11
16
  Etc.passwd do |entry|
12
- etc[:passwd][entry.name] = Mash.new(:dir => entry.dir, :gid => entry.gid, :uid => entry.uid, :shell => entry.shell, :gecos => entry.gecos)
17
+ user_passwd_entry = Mash.new(:dir => entry.dir, :gid => entry.gid, :uid => entry.uid, :shell => entry.shell, :gecos => entry.gecos)
18
+ user_passwd_entry.each_value {|v| fix_encoding(v)}
19
+ etc[:passwd][fix_encoding(entry.name)] = user_passwd_entry
13
20
  end
14
-
21
+
15
22
  Etc.group do |entry|
16
- etc[:group][entry.name] = Mash.new(:gid => entry.gid, :members => entry.mem)
23
+ group_entry = Mash.new(:gid => entry.gid,
24
+ :members => entry.mem.map {|u| fix_encoding(u)})
25
+
26
+ etc[:group][fix_encoding(entry.name)] = group_entry
17
27
  end
18
28
  end
19
29
 
20
30
  unless current_user
21
- current_user Etc.getlogin
22
- end
31
+ current_user fix_encoding(Etc.getlogin)
32
+ end
@@ -36,7 +36,7 @@ end
36
36
  def has_rackspace_mac?
37
37
  network[:interfaces].values.each do |iface|
38
38
  unless iface[:arp].nil?
39
- return true if iface[:arp].value?("00:00:0c:07:ac:01")
39
+ return true if iface[:arp].value?("00:00:0c:07:ac:01") or iface[:arp].value?("00:00:0c:9f:f0:01")
40
40
  end
41
41
  end
42
42
  false
@@ -43,7 +43,7 @@ values = {
43
43
  :host_os => "::Config::CONFIG['host_os']",
44
44
  :host_vendor => "::Config::CONFIG['host_vendor']",
45
45
  :bin_dir => "::Config::CONFIG['bindir']",
46
- :ruby_bin => "::File.join(::Config::CONFIG['bindir'], ::Config::CONFIG['ruby_install_name'])"
46
+ :ruby_bin => "::File.join(::Config::CONFIG['bindir'], ::Config::CONFIG['ruby_install_name'])"
47
47
  }
48
48
 
49
49
  # Create a query string from above hash
@@ -64,6 +64,12 @@ end
64
64
  # Perform one more (conditional) query
65
65
  bin_dir = languages[:ruby][:bin_dir]
66
66
  ruby_bin = languages[:ruby][:ruby_bin]
67
- if File.exist?("#{bin_dir}\/gem")
68
- languages[:ruby][:gems_dir] = run_ruby "puts %x{#{ruby_bin} #{bin_dir}\/gem env gemdir}.chomp!"
67
+ gem_binaries = [
68
+ run_ruby("require 'rubygems'; puts ::Gem.default_exec_format % 'gem'"),
69
+ "gem"
70
+ ].map {|bin| ::File.join(bin_dir, bin)}
71
+ gem_binary = gem_binaries.find {|bin| ::File.exists? bin }
72
+ if gem_binary
73
+ languages[:ruby][:gems_dir] = run_ruby "puts %x{#{ruby_bin} #{gem_binary} env gemdir}.chomp!"
74
+ languages[:ruby][:gem_bin] = gem_binary
69
75
  end
@@ -0,0 +1,51 @@
1
+ #
2
+ # Author:: Toomas Pelberg (<toomas.pelberg@playtech.com>)
3
+ # Copyright:: Copyright (c) 2011 Opscode, 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 "sigar"
20
+ require_plugin "network"
21
+
22
+ provides "network"
23
+
24
+ def flags(flags)
25
+ f = ""
26
+ if (flags & Sigar::RTF_UP) != 0
27
+ f += "U"
28
+ end
29
+ if (flags & Sigar::RTF_GATEWAY) != 0
30
+ f += "G"
31
+ end
32
+ if (flags & Sigar::RTF_HOST) != 0
33
+ f += "H"
34
+ end
35
+ f
36
+ end
37
+
38
+ sigar=Sigar.new
39
+ sigar.net_route_list.each do |route|
40
+ next unless network[:interfaces][route.ifname] # this should never happen
41
+ network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route]
42
+ route_data={}
43
+ (route.methods-Object.methods).each do |m|
44
+ if(m == :flags)
45
+ route_data[m]=flags(route.send(m))
46
+ else
47
+ route_data[m]=route.send(m)
48
+ end
49
+ end
50
+ network[:interfaces][route.ifname][:route][route.destination] = route_data
51
+ end
@@ -79,7 +79,7 @@ popen4("ifconfig -a") do |pid, stdin, stdout, stderr|
79
79
  stdout.each do |line|
80
80
  if line =~ /^([0-9a-zA-Z\.\:\-]+): \S+ mtu (\d+) index (\d+)/
81
81
  cint = $1
82
- iface[cint] = Mash.new
82
+ iface[cint] = Mash.new unless iface[cint]
83
83
  iface[cint][:mtu] = $2
84
84
  iface[cint][:index] = $3
85
85
  if line =~ / flags\=\d+\<((ADDRCONF|ANYCAST|BROADCAST|CoS|DEPRECATED|DHCP|DUPLICATE|FAILED|FIXEDMTU|INACTIVE|LOOPBACK|MIP|MULTI_BCAST|MULTICAST|NOARP|NOFAILOVER|NOLOCAL|NONUD|NORTEXCH|NOXMIT|OFFLINE|POINTOPOINT|PREFERRED|PRIVATE|ROUTER|RUNNING|STANDBY|TEMPORARY|UNNUMBERED|UP|VIRTUAL|XRESOLV|IPv4|IPv6|,)+)\>\s/
@@ -18,12 +18,16 @@
18
18
 
19
19
  provides "platform", "platform_version", "platform_build"
20
20
 
21
- popen4("uname -X") do |pid, stdin, stdout, stderr|
21
+ if File.exists?("/sbin/uname")
22
+ uname_exec = "/sbin/uname"
23
+ else
24
+ uname_exec = "uname"
25
+ end
26
+
27
+ popen4("#{uname_exec} -X") do |pid, stdin, stdout, stderr|
22
28
  stdin.close
23
29
  stdout.each do |line|
24
30
  case line
25
- when /^System =\s+(.+)$/
26
- platform = ($1.eql?("SunOS") ? "solaris2" : $1.downcase)
27
31
  when /^Release =\s+(.+)$/
28
32
  platform_version $1
29
33
  when /^KernelID =\s+(.+)$/
@@ -31,3 +35,22 @@ popen4("uname -X") do |pid, stdin, stdout, stderr|
31
35
  end
32
36
  end
33
37
  end
38
+
39
+ File.open("/etc/release") do |file|
40
+ while line = file.gets
41
+ case line
42
+ when /^\s*(OpenIndiana).*oi_(\d+).*$/
43
+ platform "openindiana"
44
+ platform_version $2
45
+ when /^\s*(OpenSolaris).*snv_(\d+).*$/
46
+ platform "opensolaris"
47
+ platform_version $2
48
+ when /^\s*(Oracle Solaris) (\d+)\s.*$/
49
+ platform "solaris2"
50
+ when /^\s*(Solaris)\s.*$/
51
+ platform "solaris2"
52
+ when /^\s*(NexentaCore)\s.*$/
53
+ platform "nexentacore"
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,64 @@
1
+ #
2
+ # Author:: Jason J. W. Williams (williamsjj@digitar.com)
3
+ # Copyright:: Copyright (c) 2011 Opscode, 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
+ provides "zpools"
20
+
21
+ pools = Mash.new
22
+
23
+ # Grab ZFS zpools overall health and attributes
24
+ popen4("zpool list -H -o name,size,alloc,free,cap,dedup,health,version") do |pid, stdin, stdout, stderr|
25
+ stdin.close
26
+ stdout.each do |line|
27
+ case line
28
+ when /^([-_0-9A-Za-z]*)\s+([.0-9]+[MGTPE])\s+([.0-9]+[MGTPE])\s+([.0-9]+[MGTPE])\s+(\d+%)\s+([.0-9]+x)\s+([-_0-9A-Za-z]+)\s+(\d+)$/
29
+ pools[$1] = Mash.new
30
+ pools[$1][:pool_size] = $2
31
+ pools[$1][:pool_allocated] = $3
32
+ pools[$1][:pool_free] = $4
33
+ pools[$1][:capacity_used] = $5
34
+ pools[$1][:dedup_factor] = $6
35
+ pools[$1][:health] = $7
36
+ pools[$1][:zpool_version] = $8
37
+ end
38
+ end
39
+ end
40
+
41
+ # Grab individual health for devices in the zpools
42
+ for pool in pools.keys
43
+ pools[pool][:devices] = Mash.new
44
+ # Run "zpool status" as non-root user (adm) so that
45
+ # the command won't try to open() each device which can
46
+ # hang the command if any of the disks are bad.
47
+ popen4("su adm -c \"zpool status #{pool}\"") do |pid, stdin, stdout, stderr|
48
+ stdin.close
49
+ stdout.each do |line|
50
+ case line
51
+ when /^\s+(c[-_a-zA-Z0-9]+)\s+([-_a-zA-Z0-9]+)\s+(\d+)\s+(\d+)\s+(\d+)$/
52
+ pools[pool][:devices][$1] = Mash.new
53
+ pools[pool][:devices][$1][:state] = $2
54
+ pools[pool][:devices][$1][:errors] = Mash.new
55
+ pools[pool][:devices][$1][:errors][:read] = $3
56
+ pools[pool][:devices][$1][:errors][:write] = $4
57
+ pools[pool][:devices][$1][:errors][:checksum] = $5
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ # Set the zpools data
64
+ zpools pools
@@ -29,7 +29,7 @@ disks.each do |disk|
29
29
  fs[filesystem] = Mash.new
30
30
  ld_info[filesystem] = Mash.new
31
31
  disk.properties_.each do |p|
32
- ld_info[filesystem][p.name.wmi_underscore.to_sym] = disk[p.name]
32
+ ld_info[filesystem][p.name.wmi_underscore.to_sym] = disk.send(p.name)
33
33
  end
34
34
  fs[filesystem][:kb_size] = ld_info[filesystem][:size].to_i / 1000
35
35
  fs[filesystem][:kb_available] = ld_info[filesystem][:free_space].to_i / 1000
@@ -39,7 +39,7 @@ end
39
39
  host = WMI::Win32_OperatingSystem.find(:first)
40
40
  kernel[:os_info] = Mash.new
41
41
  host.properties_.each do |p|
42
- kernel[:os_info][p.name.wmi_underscore.to_sym] = host[p.name]
42
+ kernel[:os_info][p.name.wmi_underscore.to_sym] = host.send(p.name)
43
43
  end
44
44
 
45
45
  kernel[:name] = "#{kernel[:os_info][:caption]}"
@@ -50,7 +50,7 @@ kernel[:os] = os_lookup(kernel[:os_info][:os_type]) || languages[:ruby][:host_os
50
50
  host = WMI::Win32_ComputerSystem.find(:first)
51
51
  kernel[:cs_info] = Mash.new
52
52
  host.properties_.each do |p|
53
- kernel[:cs_info][p.name.wmi_underscore.to_sym] = host[p.name]
53
+ kernel[:cs_info][p.name.wmi_underscore.to_sym] = host.send(p.name)
54
54
  end
55
55
 
56
56
  kernel[:machine] = machine_lookup("#{kernel[:cs_info][:system_type]}")
@@ -62,7 +62,7 @@ drivers = WMI::Win32_PnPSignedDriver.find(:all)
62
62
  drivers.each do |driver|
63
63
  pnp_drivers[driver.DeviceID] = Mash.new
64
64
  driver.properties_.each do |p|
65
- pnp_drivers[driver.DeviceID][p.name.wmi_underscore.to_sym] = driver[p.name]
65
+ pnp_drivers[driver.DeviceID][p.name.wmi_underscore.to_sym] = driver.send(p.name)
66
66
  end
67
67
  if driver.DeviceName
68
68
  kext[driver.DeviceName] = pnp_drivers[driver.DeviceID]
@@ -50,7 +50,7 @@ adapters.each do |adapter|
50
50
  i = adapter.Index
51
51
  iface_config[i] = Mash.new
52
52
  adapter.properties_.each do |p|
53
- iface_config[i][p.name.wmi_underscore.to_sym] = adapter[p.name]
53
+ iface_config[i][p.name.wmi_underscore.to_sym] = adapter.send(p.name)
54
54
  end
55
55
  end
56
56
 
@@ -59,7 +59,7 @@ adapters.each do |adapter|
59
59
  i = adapter.Index
60
60
  iface_instance[i] = Mash.new
61
61
  adapter.properties_.each do |p|
62
- iface_instance[i][p.name.wmi_underscore.to_sym] = adapter[p.name]
62
+ iface_instance[i][p.name.wmi_underscore.to_sym] = adapter.send(p.name)
63
63
  end
64
64
  end
65
65
 
@@ -87,7 +87,8 @@ iface_instance.keys.each do |i|
87
87
  rescue
88
88
  end
89
89
  end
90
- iface[cint][:configuration][:mac_address].each do |mac_addr|
90
+ # Apparently you can have more than one mac_address? Odd.
91
+ [iface[cint][:configuration][:mac_address]].flatten.each do |mac_addr|
91
92
  iface[cint][:addresses][mac_addr] = {
92
93
  "family" => "lladdr"
93
94
  }
@@ -106,7 +107,7 @@ end
106
107
  cint=nil
107
108
  status, stdout, stderr = run_command(:command => "arp -a")
108
109
  if status == 0
109
- stdout.each do |line|
110
+ stdout.split("\n").each do |line|
110
111
  if line =~ /^Interface:\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+[-]+\s+(0x\S+)/
111
112
  cint = $2.downcase
112
113
  end
@@ -18,6 +18,6 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = '0.6.4'
21
+ VERSION = '0.6.6.rc.0'
22
22
  end
23
23
 
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  #
2
3
  # Author:: Diego Algorta (diego@oboxodo.com)
3
4
  # Copyright:: Copyright (c) 2009 Diego Algorta
@@ -35,4 +36,12 @@ describe Ohai::Mixin::Command, "popen4" do
35
36
  end
36
37
  end
37
38
 
39
+ if defined?(::Encoding) && "".respond_to?(:force_encoding) #i.e., ruby 1.9
40
+ it "[OHAI-275] should mark strings as in the default external encoding" do
41
+ extend Ohai::Mixin::Command
42
+ snowy = run_command(:command => ("echo '" + ('☃' * 8096) + "'"))[1]
43
+ snowy.encoding.should == Encoding.default_external
44
+ end
45
+ end
46
+
38
47
  end
@@ -0,0 +1,62 @@
1
+ #
2
+ # Author:: Toomas Pelberg (toomas.pelberg@playtech.com>)
3
+ # Copyright:: Copyright (c) 2011 Opscode, 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 File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb'))
20
+
21
+ tmp = ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] || '/tmp'
22
+
23
+ describe Ohai::System, "plugin fail" do
24
+
25
+ before(:all) do
26
+ begin
27
+ Dir.mkdir("#{tmp}/plugins")
28
+ rescue Errno::EEXIST
29
+ # Ignore it
30
+ end
31
+ fail_plugin=File.open("#{tmp}/plugins/fail.rb","w+")
32
+ fail_plugin.write("provides \"fail\"require 'thiswillblowupinyourface'\nk=MissingClassName.new\nfail \"ohnoes\"")
33
+ fail_plugin.close
34
+ real_plugin=File.open("#{tmp}/plugins/real.rb","w+")
35
+ real_plugin.write("provides \"real\"\nreal \"useful\"\n")
36
+ real_plugin.close
37
+ @plugin_path=Ohai::Config[:plugin_path]
38
+ end
39
+
40
+ before(:each) do
41
+ Ohai::Config[:plugin_path]=["#{tmp}/plugins"]
42
+ @ohai=Ohai::System.new
43
+ end
44
+
45
+ after(:all) do
46
+ File.delete("#{tmp}/plugins/fail.rb")
47
+ File.delete("#{tmp}/plugins/real.rb")
48
+ begin
49
+ Dir.delete("#{tmp}/plugins")
50
+ rescue
51
+ # Don't care if it fails
52
+ end
53
+ Ohai::Config[:plugin_path]=@plugin_path
54
+ end
55
+
56
+ it "should continue gracefully if plugin loading fails" do
57
+ @ohai.require_plugin("fail")
58
+ @ohai.require_plugin("real")
59
+ @ohai.data[:real].should eql("useful")
60
+ @ohai.data.should_not have_key("fail")
61
+ end
62
+ end
@@ -24,37 +24,89 @@ describe Ohai::System, "Linux lsb plugin" do
24
24
  @ohai = Ohai::System.new
25
25
  @ohai[:os] = "linux"
26
26
  @ohai.stub!(:require_plugin).and_return(true)
27
- @mock_file = mock("/etc/lsb-release")
28
- @mock_file.stub!(:each).
29
- and_yield("DISTRIB_ID=Ubuntu").
30
- and_yield("DISTRIB_RELEASE=8.04").
31
- and_yield("DISTRIB_CODENAME=hardy").
32
- and_yield('DISTRIB_DESCRIPTION="Ubuntu 8.04"')
33
- File.stub!(:open).with("/etc/lsb-release").and_return(@mock_file)
27
+ @ohai.extend(SimpleFromFile)
34
28
  end
29
+
30
+ describe "on systems with /etc/lsb-release" do
31
+ before(:each) do
32
+ @mock_file = mock("/etc/lsb-release")
33
+ @mock_file.stub!(:each).
34
+ and_yield("DISTRIB_ID=Ubuntu").
35
+ and_yield("DISTRIB_RELEASE=8.04").
36
+ and_yield("DISTRIB_CODENAME=hardy").
37
+ and_yield('DISTRIB_DESCRIPTION="Ubuntu 8.04"')
38
+ File.stub!(:open).with("/etc/lsb-release").and_return(@mock_file)
39
+ File.stub!(:exists?).with("/etc/lsb-release").and_return(true)
40
+ end
41
+
42
+ it "should set lsb[:id]" do
43
+ @ohai._require_plugin("linux::lsb")
44
+ @ohai[:lsb][:id].should == "Ubuntu"
45
+ end
35
46
 
36
- it "should set lsb[:id]" do
37
- @ohai._require_plugin("linux::lsb")
38
- @ohai[:lsb][:id].should == "Ubuntu"
39
- end
47
+ it "should set lsb[:release]" do
48
+ @ohai._require_plugin("linux::lsb")
49
+ @ohai[:lsb][:release].should == "8.04"
50
+ end
40
51
 
41
- it "should set lsb[:release]" do
42
- @ohai._require_plugin("linux::lsb")
43
- @ohai[:lsb][:release].should == "8.04"
44
- end
52
+ it "should set lsb[:codename]" do
53
+ @ohai._require_plugin("linux::lsb")
54
+ @ohai[:lsb][:codename].should == "hardy"
55
+ end
45
56
 
46
- it "should set lsb[:codename]" do
47
- @ohai._require_plugin("linux::lsb")
48
- @ohai[:lsb][:codename].should == "hardy"
57
+ it "should set lsb[:description]" do
58
+ @ohai._require_plugin("linux::lsb")
59
+ @ohai[:lsb][:description].should == "Ubuntu 8.04"
60
+ end
49
61
  end
62
+
63
+ describe "on systems with /usr/bin/lsb_release" do
64
+ before(:each) do
65
+ File.stub!(:exists?).with("/etc/lsb-release").and_return(false)
66
+ File.stub!(:exists?).with("/usr/bin/lsb_release").and_return(true)
67
+
68
+ @stdin = mock("STDIN", { :close => true })
69
+ @pid = 10
70
+ @stderr = mock("STDERR")
71
+ @stdout = mock("STDOUT")
72
+ @status = 0
73
+
74
+ @stdout.stub!(:each).
75
+ and_yield("LSB Version: :core-4.0-ia32:core-4.0-noarch").
76
+ and_yield("Distributor ID: Fedora").
77
+ and_yield("Description: Fedora release 14 (Laughlin)").
78
+ and_yield("Release: 14").
79
+ and_yield("Codename: Laughlin")
80
+
81
+ @ohai.stub!(:popen4).with("lsb_release -a").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
82
+
83
+ end
84
+
85
+ it "should set lsb[:id]" do
86
+ @ohai._require_plugin("linux::lsb")
87
+ @ohai[:lsb][:id].should == "Fedora"
88
+ end
50
89
 
51
- it "should set lsb[:description]" do
52
- @ohai._require_plugin("linux::lsb")
53
- @ohai[:lsb][:description].should == "\"Ubuntu 8.04\""
54
- end
90
+ it "should set lsb[:release]" do
91
+ @ohai._require_plugin("linux::lsb")
92
+ @ohai[:lsb][:release].should == "14"
93
+ end
94
+
95
+ it "should set lsb[:codename]" do
96
+ @ohai._require_plugin("linux::lsb")
97
+ @ohai[:lsb][:codename].should == "Laughlin"
98
+ end
55
99
 
56
- it "should not set any lsb values if /etc/lsb-release cannot be read" do
57
- File.stub!(:open).with("/etc/lsb-release").and_raise(IOError)
100
+ it "should set lsb[:description]" do
101
+ @ohai._require_plugin("linux::lsb")
102
+ @ohai[:lsb][:description].should == "Fedora release 14 (Laughlin)"
103
+ end
104
+
105
+ end
106
+
107
+ it "should not set any lsb values if /etc/lsb-release or /usr/bin/lsb_release do not exist " do
108
+ File.stub!(:exists?).with("/etc/lsb-release").and_return(false)
109
+ File.stub!(:exists?).with("/usr/bin/lsb_release").and_return(false)
58
110
  @ohai.attribute?(:lsb).should be(false)
59
111
  end
60
- end
112
+ end
@@ -198,6 +198,27 @@ describe Ohai::System, "Linux plugin platform" do
198
198
  @ohai[:platform].should == "suse"
199
199
  @ohai[:platform_version].should == "11.2"
200
200
  end
201
+
202
+ it "[OHAI-272] should read the version as 11.3" do
203
+ File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3")
204
+ @ohai._require_plugin("linux::platform")
205
+ @ohai[:platform].should == "suse"
206
+ @ohai[:platform_version].should == "11.3"
207
+ end
208
+
209
+ it "[OHAI-272] should read the version as 9.1" do
210
+ File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("SuSE Linux 9.1 (i586)\nVERSION = 9.1")
211
+ @ohai._require_plugin("linux::platform")
212
+ @ohai[:platform].should == "suse"
213
+ @ohai[:platform_version].should == "9.1"
214
+ end
215
+
216
+ it "[OHAI-272] should read the version as 11.4" do
217
+ File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon")
218
+ @ohai._require_plugin("linux::platform")
219
+ @ohai[:platform].should == "suse"
220
+ @ohai[:platform_version].should == "11.4"
221
+ end
201
222
  end
202
223
 
203
224
  end
@@ -27,11 +27,11 @@ describe Ohai::System, "Linux virtualization platform" do
27
27
 
28
28
  # default to all requested Files not existing
29
29
  File.stub!(:exists?).with("/proc/xen/capabilities").and_return(false)
30
- File.stub!(:exists?).with("/proc/sys/xen/independent_wallclock").and_return(false)
31
30
  File.stub!(:exists?).with("/proc/modules").and_return(false)
32
31
  File.stub!(:exists?).with("/proc/cpuinfo").and_return(false)
33
32
  File.stub!(:exists?).with("/usr/sbin/dmidecode").and_return(false)
34
33
  File.stub!(:exists?).with("/proc/self/status").and_return(false)
34
+ File.stub!(:exists?).with("/proc/user_beancounters").and_return(false)
35
35
  end
36
36
 
37
37
  describe "when we are checking for xen" do
@@ -39,12 +39,13 @@ describe Ohai::System, "Linux virtualization platform" do
39
39
  File.should_receive(:exists?).with("/proc/xen/capabilities").and_return(true)
40
40
  File.stub!(:read).with("/proc/xen/capabilities").and_return("control_d")
41
41
  @ohai._require_plugin("linux::virtualization")
42
- @ohai[:virtualization][:system].should == "xen"
42
+ @ohai[:virtualization][:system].should == "xen"
43
43
  @ohai[:virtualization][:role].should == "host"
44
44
  end
45
45
 
46
- it "should set xen guest if /proc/sys/xen/independent_wallclock exists" do
47
- File.should_receive(:exists?).with("/proc/sys/xen/independent_wallclock").and_return(true)
46
+ it "should set xen guest if /proc/xen/capabilities exists" do
47
+ File.should_receive(:exists?).with("/proc/xen/capabilities").and_return(true)
48
+ File.stub!(:read).with("/proc/xen/capabilities").and_return("")
48
49
  @ohai._require_plugin("linux::virtualization")
49
50
  @ohai[:virtualization][:system].should == "xen"
50
51
  @ohai[:virtualization][:role].should == "guest"
@@ -65,7 +66,7 @@ describe Ohai::System, "Linux virtualization platform" do
65
66
  @ohai[:virtualization][:system].should == "kvm"
66
67
  @ohai[:virtualization][:role].should == "host"
67
68
  end
68
-
69
+
69
70
  it "should set kvm guest if /proc/cpuinfo contains QEMU Virtual CPU" do
70
71
  File.should_receive(:exists?).with("/proc/cpuinfo").and_return(true)
71
72
  File.stub!(:read).with("/proc/cpuinfo").and_return("QEMU Virtual CPU")
@@ -81,6 +82,30 @@ describe Ohai::System, "Linux virtualization platform" do
81
82
  end
82
83
  end
83
84
 
85
+ describe "when we are checking for VirtualBox" do
86
+ it "should set vbox host if /proc/modules contains vboxdrv" do
87
+ File.should_receive(:exists?).with("/proc/modules").and_return(true)
88
+ File.stub!(:read).with("/proc/modules").and_return("vboxdrv 268268 3 vboxnetadp,vboxnetflt")
89
+ @ohai._require_plugin("linux::virtualization")
90
+ @ohai[:virtualization][:system].should == "vbox"
91
+ @ohai[:virtualization][:role].should == "host"
92
+ end
93
+
94
+ it "should set vbox guest if /proc/modules contains vboxguest" do
95
+ File.should_receive(:exists?).with("/proc/modules").and_return(true)
96
+ File.stub!(:read).with("/proc/modules").and_return("vboxguest 177749 2 vboxsf")
97
+ @ohai._require_plugin("linux::virtualization")
98
+ @ohai[:virtualization][:system].should == "vbox"
99
+ @ohai[:virtualization][:role].should == "guest"
100
+ end
101
+
102
+ it "should not set virtualization if vbox isn't there" do
103
+ File.should_receive(:exists?).at_least(:once).and_return(false)
104
+ @ohai._require_plugin("linux::virtualization")
105
+ @ohai[:virtualization].should == {}
106
+ end
107
+ end
108
+
84
109
  describe "when we are parsing dmidecode" do
85
110
  before(:each) do
86
111
  File.should_receive(:exists?).with("/usr/sbin/dmidecode").and_return(true)
@@ -106,8 +131,8 @@ System Information
106
131
  UUID: D29974A4-BE51-044C-BDC6-EFBC4B87A8E9
107
132
  Wake-up Type: Power Switch
108
133
  MSVPC
109
- @stdout.stub!(:read).and_return(ms_vpc_dmidecode)
110
-
134
+ @stdout.stub!(:read).and_return(ms_vpc_dmidecode)
135
+
111
136
  @ohai.stub!(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
112
137
  @ohai._require_plugin("linux::virtualization")
113
138
  @ohai[:virtualization][:system].should == "virtualpc"
@@ -179,6 +204,29 @@ VMWARE
179
204
  @ohai[:virtualization].should == {}
180
205
  end
181
206
  end
207
+ describe "when we are checking for openvz" do
208
+ it "should set openvz host if /proc/user_beancounters contains 0:" do
209
+ File.should_receive(:exists?).with("/proc/user_beancounters").and_return(true)
210
+ File.stub!(:read).with("/proc/user_beancounters").and_return("\n 0: ")
211
+ @ohai._require_plugin("linux::virtualization")
212
+ @ohai[:virtualization][:emulator].should == "openvz"
213
+ @ohai[:virtualization][:role].should == "host"
214
+ end
215
+
216
+ it "should set openvz guest if /proc/user_beancounters doesn't contain 0:" do
217
+ File.should_receive(:exists?).with("/proc/user_beancounters").and_return(true)
218
+ File.stub!(:read).with("/proc/user_beancounters").and_return("101:")
219
+ @ohai._require_plugin("linux::virtualization")
220
+ @ohai[:virtualization][:emulator].should == "openvz"
221
+ @ohai[:virtualization][:role].should == "guest"
222
+ end
223
+
224
+ it "should not set virtualization if openvz isn't there" do
225
+ File.should_receive(:exists?).at_least(:once).and_return(false)
226
+ @ohai._require_plugin("linux::virtualization")
227
+ @ohai[:virtualization].should == {}
228
+ end
229
+ end
182
230
 
183
231
  it "should not set virtualization if no tests match" do
184
232
  @ohai._require_plugin("linux::virtualization")
@@ -16,17 +16,28 @@ describe Ohai::System, "plugin etc" do
16
16
  @ohai[:etc][:passwd]['root'].should == Mash.new(:shell => '/bin/zsh', :gecos => 'BOFH', :gid => 1, :uid => 1, :dir => '/root')
17
17
  @ohai[:etc][:passwd]['www'].should == Mash.new(:shell => '/bin/false', :gecos => 'Serving the web since 1970', :gid => 800, :uid => 800, :dir => '/var/www')
18
18
  end
19
-
19
+
20
20
  it "should set the current user" do
21
21
  Etc.should_receive(:getlogin).and_return('chef')
22
22
  @ohai._require_plugin("passwd")
23
23
  @ohai[:current_user].should == 'chef'
24
24
  end
25
-
25
+
26
26
  it "should set the available groups" do
27
27
  Etc.should_receive(:group).and_yield(GroupEntry.new("admin", 100, ['root', 'chef'])).and_yield(GroupEntry.new('www', 800, ['www', 'deploy']))
28
28
  @ohai._require_plugin("passwd")
29
29
  @ohai[:etc][:group]['admin'].should == Mash.new(:gid => 100, :members => ['root', 'chef'])
30
30
  @ohai[:etc][:group]['www'].should == Mash.new(:gid => 800, :members => ['www', 'deploy'])
31
31
  end
32
- end
32
+
33
+ if "".respond_to?(:force_encoding)
34
+ it "sets the encoding of strings to the default external encoding" do
35
+ fields = ["root", 1, 1, '/root', '/bin/zsh', 'BOFH']
36
+ fields.each {|f| f.force_encoding(Encoding::ASCII_8BIT) if f.respond_to?(:force_encoding) }
37
+ Etc.stub!(:passwd).and_yield(PasswdEntry.new(*fields))
38
+ @ohai._require_plugin("passwd")
39
+ root = @ohai[:etc][:passwd]['root']
40
+ root['gecos'].encoding.should == Encoding.default_external
41
+ end
42
+ end
43
+ end
@@ -42,6 +42,8 @@ describe Ohai::System, "plugin ruby" do
42
42
  :host_os => ::Config::CONFIG['host_os'],
43
43
  :host_vendor => ::Config::CONFIG['host_vendor'],
44
44
  :gems_dir => %x{#{ruby_bin} #{::Config::CONFIG['bindir']}/gem env gemdir}.chomp!,
45
+ :gem_bin => [ ::Gem.default_exec_format % 'gem', 'gem' ].map{|bin| "#{::Config::CONFIG['bindir']}/#{bin}"
46
+ }.find{|bin| ::File.exists? bin},
45
47
  :ruby_bin => ruby_bin
46
48
  }.each do |attribute, value|
47
49
  it "should have #{attribute} set" do
@@ -0,0 +1,134 @@
1
+ #
2
+ # Author:: Toomas Pelberg (<toomas.pelberg@playtech.com>)
3
+ # Copyright:: Copyright (c) 2011 Opscode, 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 File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
20
+ require 'sigar'
21
+ require 'ohai'
22
+
23
+ describe Ohai::System, "Sigar network route plugin" do
24
+
25
+ before(:each) do
26
+ @ohai = Ohai::System.new
27
+ @sigar = double("Sigar")
28
+ @net_info_conf={
29
+ :default_gateway => "192.168.1.254",
30
+ :default_gateway_interface => "eth0",
31
+ :primary_dns => "192.168.1.254",
32
+ :secondary_dns => "8.8.8.8",
33
+ :host_name => "localhost"
34
+ }
35
+ net_info=double("Sigar::NetInfo")
36
+ @net_info_conf.each_pair do |k,v|
37
+ net_info.stub(k).and_return(v)
38
+ end
39
+ @net_route_conf={
40
+ :destination => "192.168.1.0",
41
+ :gateway => "0.0.0.0",
42
+ :flags => 1,
43
+ :refcnt => 0,
44
+ :use => 0,
45
+ :ifname => "eth0",
46
+ :metric => 0,
47
+ :mtu => 0,
48
+ :window => 0,
49
+ :irtt => 0
50
+ }
51
+ net_route=double("Sigar::NetRoute")
52
+ @net_route_conf.each_pair do |k,v|
53
+ net_route.stub(k).and_return(v)
54
+ end
55
+ @net_interface_conf={
56
+ :flags => 2115,
57
+ :destination => "192.168.1.1",
58
+ :mtu => 1500,
59
+ :type => "Ethernet",
60
+ :hwaddr => "00:11:22:33:44:55:66",
61
+ :address => "192.168.1.1",
62
+ :broadcast => "192.168.1.255",
63
+ :netmask => "255.255.255.0",
64
+ :address6 => nil,
65
+ :tx_queue_len => 1000,
66
+ :prefix6_length => 0,
67
+ }
68
+ net_conf=double("Sigar::NetConf")
69
+ @net_interface_conf.each_pair do |k,v|
70
+ net_conf.stub(k).and_return(v)
71
+ end
72
+ @net_interface_stat={
73
+ :rx_bytes=>1369035618,
74
+ :rx_dropped=>0,
75
+ :rx_errors=>0,
76
+ :rx_frame=>0,
77
+ :rx_overruns=>0,
78
+ :rx_packets=>7271669,
79
+ :speed=>-1,
80
+ :tx_bytes=>3482843666,
81
+ :tx_carrier=>0,
82
+ :tx_collisions=>0,
83
+ :tx_dropped=>0,
84
+ :tx_errors=>0,
85
+ :tx_overruns=>0,
86
+ :tx_packets=>4392794
87
+ }
88
+ net_stat=double("Sigar::NetStat")
89
+ @net_interface_stat.each_pair do |k,v|
90
+ net_stat.stub(k).and_return(v)
91
+ end
92
+ @net_arp_conf={
93
+ :address => "192.168.1.5",
94
+ :flags => 2,
95
+ :hwaddr => "00:15:62:96:01:D0",
96
+ :ifname => "eth0",
97
+ :type => "ether",
98
+ }
99
+ net_arp=double("Sigar::NetArp")
100
+ @net_arp_conf.each_pair do |k,v|
101
+ net_arp.stub(k).and_return(v)
102
+ end
103
+ @sigar.stub(:fqdn).and_return("localhost.localdomain")
104
+ @sigar.should_receive(:net_info).at_least(2).times.and_return(net_info)
105
+ @sigar.should_receive(:net_interface_list).once.and_return(["eth0"])
106
+ @sigar.should_receive(:net_interface_config).with("eth0").and_return(net_conf)
107
+ @sigar.should_receive(:net_interface_stat).with("eth0").and_return(net_stat)
108
+ @sigar.should_receive(:arp_list).once.and_return([net_arp])
109
+
110
+ # Since we mock net_route_list here, flags never gets called
111
+ @sigar.should_receive(:net_route_list).once.and_return([net_route])
112
+ Sigar.should_receive(:new).at_least(2).times.and_return(@sigar)
113
+ @ohai.require_plugin("os")
114
+ @ohai[:os]="sigar"
115
+ @ohai.require_plugin("network")
116
+ @ohai.require_plugin("sigar::network_route")
117
+ end
118
+
119
+ it "should set the routes" do
120
+ @ohai[:network][:interfaces][:eth0].should have_key(:route)
121
+ end
122
+
123
+ it "should set the route details" do
124
+ @net_route_conf.each_pair do |k,v|
125
+ # Work around the above mocking of net_route_list skipping the call to flags()
126
+ if k == :flags
127
+ v="U"
128
+ @ohai[:network][:interfaces][:eth0][:route]["192.168.1.0"][k] = v
129
+ end
130
+ @ohai[:network][:interfaces][:eth0][:route]["192.168.1.0"].should have_key(k)
131
+ @ohai[:network][:interfaces][:eth0][:route]["192.168.1.0"][k].should eql(v)
132
+ end
133
+ end
134
+ end
metadata CHANGED
@@ -1,13 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohai
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
- prerelease: false
4
+ hash: 15424069
5
+ prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 4
10
- version: 0.6.4
9
+ - 6
10
+ - rc
11
+ - 0
12
+ version: 0.6.6.rc.0
11
13
  platform: ruby
12
14
  authors:
13
15
  - Adam Jacob
@@ -15,8 +17,7 @@ autorequire:
15
17
  bindir: bin
16
18
  cert_chain: []
17
19
 
18
- date: 2011-04-28 00:00:00 -07:00
19
- default_executable:
20
+ date: 2011-09-21 00:00:00 Z
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
23
  name: yajl-ruby
@@ -130,6 +131,20 @@ dependencies:
130
131
  version: "0"
131
132
  type: :development
132
133
  version_requirements: *id008
134
+ - !ruby/object:Gem::Dependency
135
+ name: sigar
136
+ prerelease: false
137
+ requirement: &id009 !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ hash: 3
143
+ segments:
144
+ - 0
145
+ version: "0"
146
+ type: :development
147
+ version_requirements: *id009
133
148
  description: Ohai profiles your system and emits JSON
134
149
  email: adam@opscode.com
135
150
  executables:
@@ -211,6 +226,7 @@ files:
211
226
  - lib/ohai/plugins/solaris2/uptime.rb
212
227
  - lib/ohai/plugins/solaris2/ssh_host_key.rb
213
228
  - lib/ohai/plugins/solaris2/network.rb
229
+ - lib/ohai/plugins/solaris2/zpools.rb
214
230
  - lib/ohai/plugins/solaris2/kernel.rb
215
231
  - lib/ohai/plugins/solaris2/platform.rb
216
232
  - lib/ohai/plugins/solaris2/ps.rb
@@ -242,6 +258,7 @@ files:
242
258
  - lib/ohai/plugins/sigar/hostname.rb
243
259
  - lib/ohai/plugins/sigar/uptime.rb
244
260
  - lib/ohai/plugins/sigar/network.rb
261
+ - lib/ohai/plugins/sigar/network_route.rb
245
262
  - lib/ohai/plugins/sigar/platform.rb
246
263
  - lib/ohai/plugins/sigar/cpu.rb
247
264
  - lib/ohai/plugins/sigar/filesystem.rb
@@ -288,6 +305,7 @@ files:
288
305
  - spec/ohai/plugins/lua_spec.rb
289
306
  - spec/ohai/plugins/ec2_spec.rb
290
307
  - spec/ohai/plugins/ruby_spec.rb
308
+ - spec/ohai/plugins/fail_spec.rb
291
309
  - spec/ohai/plugins/rackspace_spec.rb
292
310
  - spec/ohai/plugins/freebsd/kernel_spec.rb
293
311
  - spec/ohai/plugins/freebsd/platform_spec.rb
@@ -321,6 +339,7 @@ files:
321
339
  - spec/ohai/plugins/perl_spec.rb
322
340
  - spec/ohai/plugins/c_spec.rb
323
341
  - spec/ohai/plugins/ohai_spec.rb
342
+ - spec/ohai/plugins/sigar/network_route_spec.rb
324
343
  - spec/ohai/plugins/os_spec.rb
325
344
  - spec/ohai/plugins/passwd_spec.rb
326
345
  - spec/ohai/plugins/cloud_spec.rb
@@ -338,7 +357,6 @@ files:
338
357
  - spec/rcov.opts
339
358
  - spec/ohai_spec.rb
340
359
  - bin/ohai
341
- has_rdoc: true
342
360
  homepage: http://wiki.opscode.com/display/ohai
343
361
  licenses: []
344
362
 
@@ -359,16 +377,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
359
377
  required_rubygems_version: !ruby/object:Gem::Requirement
360
378
  none: false
361
379
  requirements:
362
- - - ">="
380
+ - - ">"
363
381
  - !ruby/object:Gem::Version
364
- hash: 3
382
+ hash: 25
365
383
  segments:
366
- - 0
367
- version: "0"
384
+ - 1
385
+ - 3
386
+ - 1
387
+ version: 1.3.1
368
388
  requirements: []
369
389
 
370
390
  rubyforge_project:
371
- rubygems_version: 1.3.7
391
+ rubygems_version: 1.7.2
372
392
  signing_key:
373
393
  specification_version: 3
374
394
  summary: Ohai profiles your system and emits JSON