summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-01-31 13:21:22 -0800
committerDaniel Pittman <daniel@rimspace.net>2011-01-31 13:21:22 -0800
commitfa06a388cd3fd91b62d4e65bbe4ff74bcfe46ad0 (patch)
tree04369523bed9f9ce292ada8503e4183f0da84d31
parente717fed872f68c52fc0193bab2095a12f03433ac (diff)
parentd9b8f2ad68626b8655d98a8d9037283f671f86bb (diff)
downloadfacter-fa06a388cd3fd91b62d4e65bbe4ff74bcfe46ad0.tar.gz
facter-fa06a388cd3fd91b62d4e65bbe4ff74bcfe46ad0.tar.xz
facter-fa06a388cd3fd91b62d4e65bbe4ff74bcfe46ad0.zip
Merge commit 'd9b8f2a'
-rw-r--r--Rakefile14
-rw-r--r--lib/facter/manufacturer.rb7
-rw-r--r--lib/facter/memory.rb51
-rw-r--r--lib/facter/util/manufacturer.rb17
-rw-r--r--lib/facter/util/memory.rb12
-rw-r--r--lib/facter/util/uptime.rb12
-rw-r--r--spec/Rakefile18
-rw-r--r--spec/fixtures/uptime/kstat_boot_time1
-rwxr-xr-xspec/integration/facter_spec.rb (renamed from spec/integration/facter.rb)2
-rw-r--r--spec/spec_helper.rb4
-rwxr-xr-xspec/unit/facter_spec.rb (renamed from spec/unit/facter.rb)2
-rwxr-xr-x[-rw-r--r--]spec/unit/interfaces_spec.rb (renamed from spec/unit/interfaces.rb)2
-rwxr-xr-x[-rw-r--r--]spec/unit/operatingsystem_spec.rb (renamed from spec/unit/operatingsystem.rb)2
-rwxr-xr-x[-rw-r--r--]spec/unit/operatingsystemrelease_spec.rb (renamed from spec/unit/operatingsystemrelease.rb)4
-rwxr-xr-x[-rw-r--r--]spec/unit/selinux_spec.rb (renamed from spec/unit/selinux.rb)2
-rwxr-xr-x[-rw-r--r--]spec/unit/uptime_spec.rb (renamed from spec/unit/uptime.rb)8
-rwxr-xr-xspec/unit/util/collection_spec.rb (renamed from spec/unit/util/collection.rb)2
-rwxr-xr-xspec/unit/util/confine_spec.rb (renamed from spec/unit/util/confine.rb)2
-rwxr-xr-xspec/unit/util/fact_spec.rb (renamed from spec/unit/util/fact.rb)2
-rwxr-xr-xspec/unit/util/ip_spec.rb (renamed from spec/unit/util/ip.rb)2
-rwxr-xr-xspec/unit/util/loader_spec.rb (renamed from spec/unit/util/loader.rb)2
-rwxr-xr-x[-rw-r--r--]spec/unit/util/macaddress_spec.rb (renamed from spec/unit/util/macaddress.rb)12
-rwxr-xr-xspec/unit/util/macosx_spec.rb (renamed from spec/unit/util/macosx.rb)2
-rw-r--r--spec/unit/util/manufacturer_spec.rb (renamed from spec/unit/util/manufacturer.rb)2
-rwxr-xr-xspec/unit/util/resolution_spec.rb (renamed from spec/unit/util/resolution.rb)2
-rw-r--r--spec/unit/util/uptime.rb53
-rwxr-xr-xspec/unit/util/uptime_spec.rb73
-rw-r--r--spec/unit/util/virtual_spec.rb (renamed from spec/unit/util/virtual.rb)4
-rwxr-xr-x[-rw-r--r--]spec/unit/util/vlans_spec.rb (renamed from spec/unit/util/vlans.rb)2
-rwxr-xr-x[-rw-r--r--]spec/unit/util/xendomains_spec.rb (renamed from spec/unit/util/xendomains.rb)4
-rw-r--r--spec/unit/virtual_spec.rb (renamed from spec/unit/virtual.rb)2
31 files changed, 206 insertions, 118 deletions
diff --git a/Rakefile b/Rakefile
index ba939be..9d7d906 100644
--- a/Rakefile
+++ b/Rakefile
@@ -4,8 +4,8 @@ $: << File.expand_path('lib')
$LOAD_PATH << File.join(File.dirname(__FILE__), 'tasks')
require 'rubygems'
-require 'spec'
-require 'spec/rake/spectask'
+require 'rspec'
+require 'rspec/core/rake_task'
begin
require 'rcov'
rescue LoadError
@@ -62,12 +62,14 @@ task :default do
sh %{rake -T}
end
-Spec::Rake::SpecTask.new(:spec) do |t|
- t.spec_files = FileList['spec/**/*.rb']
+RSpec::Core::RakeTask.new do |t|
+ t.pattern ='spec/{unit,integration}/**/*_spec.rb'
+ t.fail_on_error = false
end
-Spec::Rake::SpecTask.new('spec:rcov') do |t|
- t.spec_files = FileList['spec/**/*.rb']
+RSpec::Core::RakeTask.new('spec:rcov') do |t|
+ t.pattern ='spec/{unit,integration}/**/*_spec.rb'
+ t.fail_on_error = false
if defined?(Rcov)
t.rcov = true
t.rcov_opts = ['--exclude', 'spec/*,test/*,results/*,/usr/lib/*,/usr/local/lib/*,gems/*']
diff --git a/lib/facter/manufacturer.rb b/lib/facter/manufacturer.rb
index cbbb88b..4f2df98 100644
--- a/lib/facter/manufacturer.rb
+++ b/lib/facter/manufacturer.rb
@@ -15,6 +15,13 @@ if Facter.value(:kernel) == "OpenBSD"
Facter::Manufacturer.sysctl_find_system_info(mfg_keys)
elsif Facter.value(:kernel) == "SunOS" and Facter.value(:hardwareisa) == "sparc"
Facter::Manufacturer.prtdiag_sparc_find_system_info()
+elsif Facter.value(:kernel) == "windows"
+ win32_keys = {
+ 'manufacturer' => ['Manufacturer', 'Bios'],
+ 'serialNumber' => ['Serialnumber', 'Bios'],
+ 'productname' => ['Name', 'ComputerSystemProduct']
+ }
+ Facter::Manufacturer.win32_find_system_info(win32_keys)
else
query = {
'[Ss]ystem [Ii]nformation' => [
diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb
index 06640e6..f744c3f 100644
--- a/lib/facter/memory.rb
+++ b/lib/facter/memory.rb
@@ -69,13 +69,7 @@ if Facter.value(:kernel) == "OpenBSD"
end
end
- Facter.add("MemoryFree") do
- confine :kernel => :openbsd
- memfree = Facter::Util::Resolution.exec("vmstat | tail -n 1 | awk '{ print $5 }'")
- setcode do
- Facter::Memory.scale_number(memfree.to_f,"kB")
- end
- end
+ Facter::Memory.vmstat_find_free_memory()
Facter.add("MemoryTotal") do
confine :kernel => :openbsd
@@ -85,3 +79,46 @@ if Facter.value(:kernel) == "OpenBSD"
end
end
end
+
+if Facter.value(:kernel) == "SunOS"
+ swap = Facter::Util::Resolution.exec('/usr/sbin/swap -l')
+ swapfree, swaptotal = 0, 0
+ swap.each do |dev|
+ if dev =~ /^\/\S+\s.*\s+(\d+)\s+(\d+)$/
+ swaptotal += $1.to_i / 2
+ swapfree += $2.to_i / 2
+ end
+ end
+
+ Facter.add("SwapSize") do
+ confine :kernel => :sunos
+ setcode do
+ Facter::Memory.scale_number(swaptotal.to_f,"kB")
+ end
+ end
+
+ Facter.add("SwapFree") do
+ confine :kernel => :sunos
+ setcode do
+ Facter::Memory.scale_number(swapfree.to_f,"kB")
+ end
+ end
+
+ # Total memory size available from prtconf
+ pconf = Facter::Util::Resolution.exec('/usr/sbin/prtconf')
+ phymem = ""
+ pconf.each do |line|
+ if line =~ /^Memory size:\s+(\d+) Megabytes/
+ phymem = $1
+ end
+ end
+
+ Facter.add("MemorySize") do
+ confine :kernel => :sunos
+ setcode do
+ Facter::Memory.scale_number(phymem.to_f,"MB")
+ end
+ end
+
+ Facter::Memory.vmstat_find_free_memory()
+end
diff --git a/lib/facter/util/manufacturer.rb b/lib/facter/util/manufacturer.rb
index 5ac0585..22359ea 100644
--- a/lib/facter/util/manufacturer.rb
+++ b/lib/facter/util/manufacturer.rb
@@ -80,4 +80,21 @@ module Facter::Manufacturer
end
end
end
+
+ def self.win32_find_system_info(name)
+ require 'win32ole'
+ value = ""
+ wmi = WIN32OLE.connect("winmgmts://")
+ name.each do |facterkey, win32key|
+ query = wmi.ExecQuery("select * from Win32_#{win32key.last}")
+ Facter.add(facterkey) do
+ confine :kernel => :windows
+ setcode do
+ query.each { |x| value = x.__send__( (win32key.first).to_sym) }
+ value
+ end
+ end
+ end
+ end
+
end
diff --git a/lib/facter/util/memory.rb b/lib/facter/util/memory.rb
index 2004491..43abec6 100644
--- a/lib/facter/util/memory.rb
+++ b/lib/facter/util/memory.rb
@@ -50,5 +50,17 @@ module Facter::Memory
return "%.2f %s" % [size, s]
end
+
+ def self.vmstat_find_free_memory()
+ row = Facter::Util::Resolution.exec('vmstat').split("\n")[-1]
+ if row =~ /^\s*\d+\s*\d+\s*\d+\s*\d+\s*(\d+)/
+ Facter.add("MemoryFree") do
+ memfree = $1
+ setcode do
+ Facter::Memory.scale_number(memfree.to_f, "kB")
+ end
+ end
+ end
+ end
end
diff --git a/lib/facter/util/uptime.rb b/lib/facter/util/uptime.rb
index 9a59d30..4e6a7b6 100644
--- a/lib/facter/util/uptime.rb
+++ b/lib/facter/util/uptime.rb
@@ -4,7 +4,7 @@ require 'time'
#
module Facter::Util::Uptime
def self.get_uptime_seconds_unix
- uptime_proc_uptime or uptime_sysctl or uptime_who_dash_b
+ uptime_proc_uptime or uptime_sysctl or uptime_kstat or uptime_who_dash_b
end
def self.get_uptime_seconds_win
@@ -30,6 +30,12 @@ module Facter::Util::Uptime
end
end
+ def self.uptime_kstat
+ if output = Facter::Util::Resolution.exec("#{uptime_kstat_cmd} 2>/dev/null")
+ compute_uptime(Time.at(output.chomp.split(/\s/).last.to_i))
+ end
+ end
+
def self.uptime_who_dash_b
if output = Facter::Util::Resolution.exec("#{uptime_who_cmd} 2>/dev/null")
compute_uptime(Time.parse(output))
@@ -48,6 +54,10 @@ module Facter::Util::Uptime
'sysctl -b kern.boottime'
end
+ def self.uptime_kstat_cmd
+ 'kstat -p unix:::boot_time'
+ end
+
def self.uptime_who_cmd
'who -b'
end
diff --git a/spec/Rakefile b/spec/Rakefile
deleted file mode 100644
index e2996f6..0000000
--- a/spec/Rakefile
+++ /dev/null
@@ -1,18 +0,0 @@
-require File.join(File.dirname(__FILE__), "spec_helper.rb")
-require 'rake'
-require 'spec/rake/spectask'
-
-basedir = File.dirname(__FILE__)
-puppetlibdir = File.join(basedir, "../lib")
-puppettestlibdir = File.join(basedir, "../test/lib")
-speclibdir = File.join(basedir, "lib")
-
-libs = [puppetlibdir, puppettestlibdir, speclibdir]
-desc "Run all specs"
-Spec::Rake::SpecTask.new('all') do |t|
- t.spec_files = FileList['integration/**/*.rb', 'unit/**/*.rb']
- t.libs = libs
- t.spec_opts = ['--options', 'spec.opts']
-end
-
-task :default => [:all]
diff --git a/spec/fixtures/uptime/kstat_boot_time b/spec/fixtures/uptime/kstat_boot_time
new file mode 100644
index 0000000..1c0a9c5
--- /dev/null
+++ b/spec/fixtures/uptime/kstat_boot_time
@@ -0,0 +1 @@
+unix:0:system_misc:boot_time 1236919980
diff --git a/spec/integration/facter.rb b/spec/integration/facter_spec.rb
index 79a1f0f..8351de1 100755
--- a/spec/integration/facter.rb
+++ b/spec/integration/facter_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Facter do
before do
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index c8bd547..d9db445 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -7,12 +7,12 @@ $LOAD_PATH.unshift("#{dir}/../lib")
require 'rubygems'
require 'mocha'
-require 'spec'
+require 'rspec'
require 'facter'
# load any monkey-patches
Dir["#{dir}/monkey_patches/*.rb"].map { |file| require file }
-Spec::Runner.configure do |config|
+RSpec.configure do |config|
config.mock_with :mocha
end
diff --git a/spec/unit/facter.rb b/spec/unit/facter_spec.rb
index 20f9ed1..e63bc76 100755
--- a/spec/unit/facter.rb
+++ b/spec/unit/facter_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Facter do
diff --git a/spec/unit/interfaces.rb b/spec/unit/interfaces_spec.rb
index 49d5d1f..8b295d6 100644..100755
--- a/spec/unit/interfaces.rb
+++ b/spec/unit/interfaces_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'facter'
diff --git a/spec/unit/operatingsystem.rb b/spec/unit/operatingsystem_spec.rb
index de86230..be83916 100644..100755
--- a/spec/unit/operatingsystem.rb
+++ b/spec/unit/operatingsystem_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'facter'
diff --git a/spec/unit/operatingsystemrelease.rb b/spec/unit/operatingsystemrelease_spec.rb
index 31d4ae8..1cfb4ac 100644..100755
--- a/spec/unit/operatingsystemrelease.rb
+++ b/spec/unit/operatingsystemrelease_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'facter'
@@ -26,7 +26,7 @@ describe "Operating System Release fact" do
}
test_cases.each do |system, file|
- context "with operatingsystem reported as #{system.inspect}" do
+ describe "with operatingsystem reported as #{system.inspect}" do
it "should read the #{file.inspect} file" do
Facter.fact(:operatingsystem).stubs(:value).returns(system)
diff --git a/spec/unit/selinux.rb b/spec/unit/selinux_spec.rb
index 8afa463..43fd5bf 100644..100755
--- a/spec/unit/selinux.rb
+++ b/spec/unit/selinux_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'facter'
diff --git a/spec/unit/uptime.rb b/spec/unit/uptime_spec.rb
index 19a55fe..bd695fa 100644..100755
--- a/spec/unit/uptime.rb
+++ b/spec/unit/uptime_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'facter'
require 'facter/util/uptime'
@@ -9,7 +9,7 @@ describe "uptime facts:" do
before { Facter.clear }
after { Facter.clear }
- context "when uptime information is available" do
+ describe "when uptime information is available" do
describe "uptime" do
test_cases = [
[60 * 60 * 24 * 3, '3 days'],
@@ -34,7 +34,7 @@ describe "uptime facts:" do
end
- context "when uptime information is available" do
+ describe "when uptime information is available" do
before do
Facter::Util::Uptime.stubs(:get_uptime_seconds_unix).returns(60 * 60 * 24 + 23)
Facter::Util::Uptime.stubs(:get_uptime_seconds_win).returns(60 * 60 * 24 + 23)
@@ -59,7 +59,7 @@ describe "uptime facts:" do
end
end
- context "when uptime information is not available" do
+ describe "when uptime information is not available" do
before do
Facter::Util::Uptime.stubs(:get_uptime_seconds_unix).returns(nil)
Facter::Util::Uptime.stubs(:get_uptime_seconds_win).returns(nil)
diff --git a/spec/unit/util/collection.rb b/spec/unit/util/collection_spec.rb
index 7baef96..86b602f 100755
--- a/spec/unit/util/collection.rb
+++ b/spec/unit/util/collection_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'facter/util/collection'
diff --git a/spec/unit/util/confine.rb b/spec/unit/util/confine_spec.rb
index 757ca26..147c70d 100755
--- a/spec/unit/util/confine.rb
+++ b/spec/unit/util/confine_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'facter/util/confine'
require 'facter/util/values'
diff --git a/spec/unit/util/fact.rb b/spec/unit/util/fact_spec.rb
index 1652032..db08670 100755
--- a/spec/unit/util/fact.rb
+++ b/spec/unit/util/fact_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'facter/util/fact'
diff --git a/spec/unit/util/ip.rb b/spec/unit/util/ip_spec.rb
index a9aae76..d87b4b9 100755
--- a/spec/unit/util/ip.rb
+++ b/spec/unit/util/ip_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'facter/util/ip'
diff --git a/spec/unit/util/loader.rb b/spec/unit/util/loader_spec.rb
index 0a28020..0bb823e 100755
--- a/spec/unit/util/loader.rb
+++ b/spec/unit/util/loader_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'facter/util/loader'
diff --git a/spec/unit/util/macaddress.rb b/spec/unit/util/macaddress_spec.rb
index 1ccca18..98215c4 100644..100755
--- a/spec/unit/util/macaddress.rb
+++ b/spec/unit/util/macaddress_spec.rb
@@ -1,10 +1,10 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'facter/util/macaddress'
-context "Darwin" do
+describe "Darwin" do
test_cases = [
# version, iface, real macaddress, fallback macaddress
["9.8.0", 'en0', "00:17:f2:06:e4:2e", "00:17:f2:06:e4:2e"],
@@ -17,12 +17,12 @@ context "Darwin" do
ifconfig_file_no_iface = File.join(SPECDIR, "fixtures", "ifconfig", "darwin_#{version.tr('.', '_')}")
ifconfig_file = "#{ifconfig_file_no_iface}_#{default_iface}"
- context "version #{version}" do
+ describe "version #{version}" do
describe Facter::Util::Macaddress::Darwin do
describe ".default_interface" do
- context "when netstat has a default interface" do
+ describe "when netstat has a default interface" do
before do
Facter::Util::Macaddress::Darwin.stubs(:netstat_command).returns("cat \"#{netstat_file}\"")
@@ -36,7 +36,7 @@ context "Darwin" do
end
describe ".macaddress" do
- context "when netstat has a default interface" do
+ describe "when netstat has a default interface" do
before do
Facter.stubs(:warn)
Facter::Util::Macaddress::Darwin.stubs(:default_interface).returns('')
@@ -49,7 +49,7 @@ context "Darwin" do
end
- context "when netstat does not have a default interface" do
+ describe "when netstat does not have a default interface" do
before do
Facter::Util::Macaddress::Darwin.stubs(:default_interface).returns("")
Facter::Util::Macaddress::Darwin.stubs(:ifconfig_command).returns("cat \"#{ifconfig_file_no_iface}\"")
diff --git a/spec/unit/util/macosx.rb b/spec/unit/util/macosx_spec.rb
index 283fe75..44ba460 100755
--- a/spec/unit/util/macosx.rb
+++ b/spec/unit/util/macosx_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'facter/util/macosx'
diff --git a/spec/unit/util/manufacturer.rb b/spec/unit/util/manufacturer_spec.rb
index 291a6ff..07473db 100644
--- a/spec/unit/util/manufacturer.rb
+++ b/spec/unit/util/manufacturer_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'facter/util/manufacturer'
diff --git a/spec/unit/util/resolution.rb b/spec/unit/util/resolution_spec.rb
index 396f800..581d0e1 100755
--- a/spec/unit/util/resolution.rb
+++ b/spec/unit/util/resolution_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'facter/util/resolution'
diff --git a/spec/unit/util/uptime.rb b/spec/unit/util/uptime.rb
deleted file mode 100644
index 72c97ed..0000000
--- a/spec/unit/util/uptime.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../../spec_helper'
-
-require 'facter/util/uptime'
-
-describe Facter::Util::Uptime do
-
- describe ".get_uptime_seconds_unix" do
- context "when /proc/uptime is available" do
- before do
- uptime_file = File.join(SPECDIR, "fixtures", "uptime", "ubuntu_proc_uptime")
- Facter::Util::Uptime.stubs(:uptime_file).returns("\"#{uptime_file}\"")
- end
-
- it "should return the uptime in seconds as an integer" do
- Facter::Util::Uptime.get_uptime_seconds_unix.should == 5097686
- end
-
- end
-
- it "should use sysctl kern.boottime when /proc/uptime not available" do
- nonexistent_file = '/non/existent/file'
- File.exists?(nonexistent_file).should == false
- Facter::Util::Uptime.stubs(:uptime_file).returns(nonexistent_file)
- sysctl_output_file = File.join(SPECDIR, 'fixtures', 'uptime', 'sysctl_kern_boottime') # Aug 01 14:13:47 -0700 2010
- Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat \"#{sysctl_output_file}\"")
- Time.stubs(:now).returns Time.parse("Aug 01 15:13:47 -0700 2010") # one hour later
- Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60
- end
-
- it "should use who -b when neither /proc/uptime nor sysctl kern.boottime is available" do
- nonexistent_file = '/non/existent/file'
- File.exists?(nonexistent_file).should == false
- Facter::Util::Uptime.stubs(:uptime_file).returns(nonexistent_file)
- Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat #{nonexistent_file}")
- who_b_output_file = File.join(SPECDIR, 'fixtures', 'uptime', 'who_b_boottime') # Aug 1 14:13
- Facter::Util::Uptime.stubs(:uptime_who_cmd).returns("cat \"#{who_b_output_file}\"")
- Time.stubs(:now).returns Time.parse("Aug 01 15:13") # one hour later
- Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60
- end
-
- it "should return nil when none of /proc/uptime, sysctl kern.boottime, or who -b is available" do
- nonexistent_file = '/non/existent/file'
- File.exists?(nonexistent_file).should == false
- Facter::Util::Uptime.stubs(:uptime_file).returns(nonexistent_file)
- Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat #{nonexistent_file}")
- Facter::Util::Uptime.stubs(:uptime_who_cmd).returns("cat #{nonexistent_file}")
- Facter::Util::Uptime.get_uptime_seconds_unix.should == nil
- end
- end
-
-end
diff --git a/spec/unit/util/uptime_spec.rb b/spec/unit/util/uptime_spec.rb
new file mode 100755
index 0000000..8d3980c
--- /dev/null
+++ b/spec/unit/util/uptime_spec.rb
@@ -0,0 +1,73 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+
+require 'facter/util/uptime'
+
+describe Facter::Util::Uptime do
+
+ describe ".get_uptime_seconds_unix" do
+ describe "when /proc/uptime is available" do
+ before do
+ uptime_file = File.join(SPECDIR, "fixtures", "uptime", "ubuntu_proc_uptime")
+ Facter::Util::Uptime.stubs(:uptime_file).returns("\"#{uptime_file}\"")
+ end
+
+ it "should return the uptime in seconds as an integer" do
+ Facter::Util::Uptime.get_uptime_seconds_unix.should == 5097686
+ end
+
+ end
+
+ describe "when /proc/uptime is not available" do
+ before :each do
+ @nonexistent_file = '/non/existent/file'
+ File.exists?(@nonexistent_file).should == false
+ Facter::Util::Uptime.stubs(:uptime_file).returns(@nonexistent_file)
+ end
+
+ it "should use 'sysctl kern.boottime'" do
+ sysctl_output_file = File.join(SPECDIR, 'fixtures', 'uptime', 'sysctl_kern_boottime') # Aug 01 14:13:47 -0700 2010
+ Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat \"#{sysctl_output_file}\"")
+ Time.stubs(:now).returns Time.parse("Aug 01 15:13:47 -0700 2010") # one hour later
+ Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60
+ end
+
+ describe "nor is 'sysctl kern.boottime'" do
+ before :each do
+ Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat \"#{@nonexistent_file}\"")
+ end
+
+ it "should use 'kstat -p unix:::boot_time'" do
+ kstat_output_file = File.join(SPECDIR, 'fixtures', 'uptime', 'kstat_boot_time') # unix:0:system_misc:boot_time 1236919980
+ Facter::Util::Uptime.stubs(:uptime_kstat_cmd).returns("cat \"#{kstat_output_file}\"")
+ Time.stubs(:now).returns Time.at(1236923580) #one hour later
+ Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60
+ end
+
+ describe "nor is 'kstat -p unix:::boot_time'" do
+ before :each do
+ Facter::Util::Uptime.stubs(:uptime_kstat_cmd).returns("cat \"#{@nonexistent_file}\"")
+ end
+
+ it "should use 'who -b'" do
+ who_b_output_file = File.join(SPECDIR, 'fixtures', 'uptime', 'who_b_boottime') # Aug 1 14:13
+ Facter::Util::Uptime.stubs(:uptime_who_cmd).returns("cat \"#{who_b_output_file}\"")
+ Time.stubs(:now).returns Time.parse("Aug 01 15:13") # one hour later
+ Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60
+ end
+
+ describe "nor is 'who -b'" do
+ before :each do
+ Facter::Util::Uptime.stubs(:uptime_who_cmd).returns("cat \"#{@nonexistent_file}\"")
+ end
+
+ it "should return nil" do
+ Facter::Util::Uptime.get_uptime_seconds_unix.should == nil
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/unit/util/virtual.rb b/spec/unit/util/virtual_spec.rb
index 72186f7..12ba0ac 100644
--- a/spec/unit/util/virtual.rb
+++ b/spec/unit/util/virtual_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'facter/util/virtual'
@@ -67,7 +67,7 @@ describe Facter::Util::Virtual do
]
test_cases.each do |status_file, expected, description|
- context "with /proc/self/status from #{description}" do
+ describe "with /proc/self/status from #{description}" do
it "should detect vserver as #{expected.inspect}" do
status = File.read(status_file)
FileTest.stubs(:exists?).with("/proc/self/status").returns(true)
diff --git a/spec/unit/util/vlans.rb b/spec/unit/util/vlans_spec.rb
index e06a2af..0331234 100644..100755
--- a/spec/unit/util/vlans.rb
+++ b/spec/unit/util/vlans_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'facter/util/vlans'
diff --git a/spec/unit/util/xendomains.rb b/spec/unit/util/xendomains_spec.rb
index a0fa345..dc7e178 100644..100755
--- a/spec/unit/util/xendomains.rb
+++ b/spec/unit/util/xendomains_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'facter/util/xendomains'
@@ -13,7 +13,7 @@ describe Facter::Util::Xendomains do
Facter::Util::Xendomains.get_domains.should == %{web01,mailserver}
end
- context "when xm list isn't executable" do
+ describe "when xm list isn't executable" do
it "should be nil" do
Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/xm list').returns(nil)
Facter::Util::Xendomains.get_domains.should == nil
diff --git a/spec/unit/virtual.rb b/spec/unit/virtual_spec.rb
index 9e8e358..a152b40 100644
--- a/spec/unit/virtual.rb
+++ b/spec/unit/virtual_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'facter'
require 'facter/util/virtual'