ohai 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. data/LICENSE +201 -0
  2. data/README.rdoc +98 -0
  3. data/Rakefile +61 -0
  4. data/bin/ohai +24 -0
  5. data/lib/ohai.rb +27 -0
  6. data/lib/ohai/application.rb +113 -0
  7. data/lib/ohai/config.rb +29 -0
  8. data/lib/ohai/exception.rb +23 -0
  9. data/lib/ohai/log.rb +26 -0
  10. data/lib/ohai/mixin/command.rb +208 -0
  11. data/lib/ohai/mixin/from_file.rb +36 -0
  12. data/lib/ohai/mixin/string.rb +29 -0
  13. data/lib/ohai/plugins/command.rb +21 -0
  14. data/lib/ohai/plugins/darwin/filesystem.rb +57 -0
  15. data/lib/ohai/plugins/darwin/hostname.rb +22 -0
  16. data/lib/ohai/plugins/darwin/kernel.rb +37 -0
  17. data/lib/ohai/plugins/darwin/network.rb +187 -0
  18. data/lib/ohai/plugins/darwin/platform.rb +36 -0
  19. data/lib/ohai/plugins/darwin/ps.rb +23 -0
  20. data/lib/ohai/plugins/darwin/ssh_host_key.rb +25 -0
  21. data/lib/ohai/plugins/darwin/system_profiler.rb +33 -0
  22. data/lib/ohai/plugins/darwin/uptime.rb +32 -0
  23. data/lib/ohai/plugins/dmi.rb +59 -0
  24. data/lib/ohai/plugins/ec2.rb +100 -0
  25. data/lib/ohai/plugins/erlang.rb +40 -0
  26. data/lib/ohai/plugins/freebsd/cpu.rb +52 -0
  27. data/lib/ohai/plugins/freebsd/filesystem.rb +57 -0
  28. data/lib/ohai/plugins/freebsd/hostname.rb +22 -0
  29. data/lib/ohai/plugins/freebsd/kernel.rb +37 -0
  30. data/lib/ohai/plugins/freebsd/memory.rb +50 -0
  31. data/lib/ohai/plugins/freebsd/network.rb +112 -0
  32. data/lib/ohai/plugins/freebsd/platform.rb +23 -0
  33. data/lib/ohai/plugins/freebsd/ps.rb +24 -0
  34. data/lib/ohai/plugins/freebsd/ssh_host_key.rb +26 -0
  35. data/lib/ohai/plugins/freebsd/uptime.rb +32 -0
  36. data/lib/ohai/plugins/freebsd/virtualization.rb +66 -0
  37. data/lib/ohai/plugins/hostname.rb +27 -0
  38. data/lib/ohai/plugins/java.rb +36 -0
  39. data/lib/ohai/plugins/kernel.rb +33 -0
  40. data/lib/ohai/plugins/keys.rb +22 -0
  41. data/lib/ohai/plugins/languages.rb +21 -0
  42. data/lib/ohai/plugins/linux/block_device.rb +38 -0
  43. data/lib/ohai/plugins/linux/cpu.rb +60 -0
  44. data/lib/ohai/plugins/linux/filesystem.rb +57 -0
  45. data/lib/ohai/plugins/linux/hostname.rb +26 -0
  46. data/lib/ohai/plugins/linux/kernel.rb +33 -0
  47. data/lib/ohai/plugins/linux/lsb.rb +38 -0
  48. data/lib/ohai/plugins/linux/memory.rb +83 -0
  49. data/lib/ohai/plugins/linux/network.rb +112 -0
  50. data/lib/ohai/plugins/linux/platform.rb +43 -0
  51. data/lib/ohai/plugins/linux/ps.rb +23 -0
  52. data/lib/ohai/plugins/linux/ssh_host_key.rb +26 -0
  53. data/lib/ohai/plugins/linux/uptime.rb +28 -0
  54. data/lib/ohai/plugins/linux/virtualization.rb +77 -0
  55. data/lib/ohai/plugins/netbsd/cpu.rb +48 -0
  56. data/lib/ohai/plugins/netbsd/filesystem.rb +57 -0
  57. data/lib/ohai/plugins/netbsd/hostname.rb +22 -0
  58. data/lib/ohai/plugins/netbsd/kernel.rb +35 -0
  59. data/lib/ohai/plugins/netbsd/memory.rb +98 -0
  60. data/lib/ohai/plugins/netbsd/network.rb +111 -0
  61. data/lib/ohai/plugins/netbsd/platform.rb +22 -0
  62. data/lib/ohai/plugins/netbsd/ps.rb +24 -0
  63. data/lib/ohai/plugins/netbsd/ssh_host_key.rb +26 -0
  64. data/lib/ohai/plugins/netbsd/uptime.rb +31 -0
  65. data/lib/ohai/plugins/netbsd/virtualization.rb +65 -0
  66. data/lib/ohai/plugins/network.rb +52 -0
  67. data/lib/ohai/plugins/ohai_time.rb +21 -0
  68. data/lib/ohai/plugins/openbsd/cpu.rb +38 -0
  69. data/lib/ohai/plugins/openbsd/filesystem.rb +57 -0
  70. data/lib/ohai/plugins/openbsd/hostname.rb +22 -0
  71. data/lib/ohai/plugins/openbsd/kernel.rb +35 -0
  72. data/lib/ohai/plugins/openbsd/memory.rb +98 -0
  73. data/lib/ohai/plugins/openbsd/network.rb +111 -0
  74. data/lib/ohai/plugins/openbsd/platform.rb +23 -0
  75. data/lib/ohai/plugins/openbsd/ps.rb +24 -0
  76. data/lib/ohai/plugins/openbsd/ssh_host_key.rb +26 -0
  77. data/lib/ohai/plugins/openbsd/uptime.rb +32 -0
  78. data/lib/ohai/plugins/openbsd/virtualization.rb +66 -0
  79. data/lib/ohai/plugins/os.rb +48 -0
  80. data/lib/ohai/plugins/perl.rb +37 -0
  81. data/lib/ohai/plugins/platform.rb +25 -0
  82. data/lib/ohai/plugins/python.rb +37 -0
  83. data/lib/ohai/plugins/ruby.rb +39 -0
  84. data/lib/ohai/plugins/solaris2/cpu.rb +33 -0
  85. data/lib/ohai/plugins/solaris2/hostname.rb +25 -0
  86. data/lib/ohai/plugins/solaris2/kernel.rb +40 -0
  87. data/lib/ohai/plugins/solaris2/network.rb +141 -0
  88. data/lib/ohai/plugins/solaris2/platform.rb +33 -0
  89. data/lib/ohai/plugins/solaris2/ps.rb +23 -0
  90. data/lib/ohai/plugins/solaris2/ssh_host_key.rb +26 -0
  91. data/lib/ohai/plugins/uptime.rb +42 -0
  92. data/lib/ohai/plugins/virtualization.rb +86 -0
  93. data/lib/ohai/plugins/windows/filesystem.rb +44 -0
  94. data/lib/ohai/plugins/windows/hostname.rb +25 -0
  95. data/lib/ohai/plugins/windows/kernel.rb +75 -0
  96. data/lib/ohai/plugins/windows/network.rb +114 -0
  97. data/lib/ohai/plugins/windows/platform.rb +26 -0
  98. data/lib/ohai/system.rb +241 -0
  99. data/spec/ohai/mixin/command_spec.rb +37 -0
  100. data/spec/ohai/mixin/from_file_spec.rb +53 -0
  101. data/spec/ohai/plugins/darwin/hostname_spec.rb +34 -0
  102. data/spec/ohai/plugins/darwin/kernel_spec.rb +46 -0
  103. data/spec/ohai/plugins/darwin/platform_spec.rb +67 -0
  104. data/spec/ohai/plugins/dmi_spec.rb +73 -0
  105. data/spec/ohai/plugins/ec2_spec.rb +81 -0
  106. data/spec/ohai/plugins/erlang_spec.rb +63 -0
  107. data/spec/ohai/plugins/freebsd/hostname_spec.rb +34 -0
  108. data/spec/ohai/plugins/freebsd/kernel_spec.rb +37 -0
  109. data/spec/ohai/plugins/freebsd/platform_spec.rb +40 -0
  110. data/spec/ohai/plugins/hostname_spec.rb +39 -0
  111. data/spec/ohai/plugins/java_spec.rb +70 -0
  112. data/spec/ohai/plugins/kernel_spec.rb +43 -0
  113. data/spec/ohai/plugins/linux/cpu_spec.rb +128 -0
  114. data/spec/ohai/plugins/linux/hostname_spec.rb +52 -0
  115. data/spec/ohai/plugins/linux/kernel_spec.rb +31 -0
  116. data/spec/ohai/plugins/linux/lsb_spec.rb +60 -0
  117. data/spec/ohai/plugins/linux/platform_spec.rb +81 -0
  118. data/spec/ohai/plugins/linux/uptime_spec.rb +61 -0
  119. data/spec/ohai/plugins/linux/virtualization_spec.rb +131 -0
  120. data/spec/ohai/plugins/netbsd/hostname_spec.rb +34 -0
  121. data/spec/ohai/plugins/netbsd/kernel_spec.rb +36 -0
  122. data/spec/ohai/plugins/netbsd/platform_spec.rb +40 -0
  123. data/spec/ohai/plugins/ohai_time_spec.rb +46 -0
  124. data/spec/ohai/plugins/openbsd/hostname_spec.rb +34 -0
  125. data/spec/ohai/plugins/openbsd/kernel_spec.rb +37 -0
  126. data/spec/ohai/plugins/openbsd/platform_spec.rb +40 -0
  127. data/spec/ohai/plugins/os_spec.rb +69 -0
  128. data/spec/ohai/plugins/perl_spec.rb +89 -0
  129. data/spec/ohai/plugins/platform_spec.rb +56 -0
  130. data/spec/ohai/plugins/python_spec.rb +53 -0
  131. data/spec/ohai/plugins/ruby_spec.rb +51 -0
  132. data/spec/ohai/plugins/solaris2/hostname_spec.rb +43 -0
  133. data/spec/ohai/plugins/solaris2/kernel_spec.rb +164 -0
  134. data/spec/ohai/system_spec.rb +130 -0
  135. data/spec/ohai_spec.rb +27 -0
  136. data/spec/rcov.opts +2 -0
  137. data/spec/spec.opts +2 -0
  138. data/spec/spec_helper.rb +68 -0
  139. metadata +240 -0
@@ -0,0 +1,61 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 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
+
20
+ require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb')
21
+
22
+ describe Ohai::System, "Linux plugin uptime" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ @ohai[:os] = "linux"
27
+ @ohai._require_plugin("uptime")
28
+ @mock_file = mock("/proc/uptime", { :gets => "18423 989" })
29
+ File.stub!(:open).with("/proc/uptime").and_return(@mock_file)
30
+ end
31
+
32
+ it "should check /proc/uptime for the uptime and idletime" do
33
+ File.should_receive(:open).with("/proc/uptime").and_return(@mock_file)
34
+ @ohai._require_plugin("linux::uptime")
35
+ end
36
+
37
+ it "should split the value of /proc uptime" do
38
+ @mock_file.gets.should_receive(:split).with(" ").and_return(["18423", "989"])
39
+ @ohai._require_plugin("linux::uptime")
40
+ end
41
+
42
+ it "should set uptime_seconds to uptime" do
43
+ @ohai._require_plugin("linux::uptime")
44
+ @ohai[:uptime_seconds].should == 18423
45
+ end
46
+
47
+ it "should set uptime to a human readable date" do
48
+ @ohai._require_plugin("linux::uptime")
49
+ @ohai[:uptime].should == "5 hours 07 minutes 03 seconds"
50
+ end
51
+
52
+ it "should set idletime_seconds to uptime" do
53
+ @ohai._require_plugin("linux::uptime")
54
+ @ohai[:idletime_seconds].should == 989
55
+ end
56
+
57
+ it "should set idletime to a human readable date" do
58
+ @ohai._require_plugin("linux::uptime")
59
+ @ohai[:idletime].should == "16 minutes 29 seconds"
60
+ end
61
+ end
@@ -0,0 +1,131 @@
1
+ #
2
+ # Author:: Thom May (<thom@clearairturbulence.org>)
3
+ # Copyright:: Copyright (c) 2009 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.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb')
20
+
21
+ describe Ohai::System, "Linux virtualization platform" do
22
+ before(:each) do
23
+ @ohai = Ohai::System.new
24
+ @ohai[:os] = "linux"
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ @ohai.extend(SimpleFromFile)
27
+
28
+ # default to all requested Files not existing
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
+ File.stub!(:exists?).with("/proc/modules").and_return(false)
32
+ File.stub!(:exists?).with("/proc/cpuinfo").and_return(false)
33
+ File.stub!(:exists?).with("/usr/sbin/dmidecode").and_return(false)
34
+ end
35
+
36
+ describe "when we are checking for xen" do
37
+ it "should set xen host if /proc/xen/capabilities contains control_d" do
38
+ File.should_receive(:exists?).with("/proc/xen/capabilities").and_return(true)
39
+ File.stub!(:read).with("/proc/xen/capabilities").and_return("control_d")
40
+ @ohai._require_plugin("linux::virtualization")
41
+ @ohai[:virtualization][:emulator].should == "xen"
42
+ @ohai[:virtualization][:role].should == "host"
43
+ end
44
+
45
+ it "should set xen guest if /proc/sys/xen/independent_wallclock exists" do
46
+ File.should_receive(:exists?).with("/proc/sys/xen/independent_wallclock").and_return(true)
47
+ @ohai._require_plugin("linux::virtualization")
48
+ @ohai[:virtualization][:emulator].should == "xen"
49
+ @ohai[:virtualization][:role].should == "guest"
50
+ end
51
+
52
+ it "should not set virtualization if xen isn't there" do
53
+ File.should_receive(:exists?).at_least(:once).and_return(false)
54
+ @ohai._require_plugin("linux::virtualization")
55
+ @ohai[:virtualization].should == {}
56
+ end
57
+ end
58
+
59
+ describe "when we are checking for kvm" do
60
+ it "should set kvm host if /proc/modules contains kvm" do
61
+ File.should_receive(:exists?).with("/proc/modules").and_return(true)
62
+ File.stub!(:read).with("/proc/modules").and_return("kvm 165872 1 kvm_intel")
63
+ @ohai._require_plugin("linux::virtualization")
64
+ @ohai[:virtualization][:emulator].should == "kvm"
65
+ @ohai[:virtualization][:role].should == "host"
66
+ end
67
+
68
+ it "should set kvm guest if /proc/cpuinfo contains QEMU Virtual CPU" do
69
+ File.should_receive(:exists?).with("/proc/cpuinfo").and_return(true)
70
+ File.stub!(:read).with("/proc/cpuinfo").and_return("QEMU Virtual CPU")
71
+ @ohai._require_plugin("linux::virtualization")
72
+ @ohai[:virtualization][:emulator].should == "kvm"
73
+ @ohai[:virtualization][:role].should == "guest"
74
+ end
75
+
76
+ it "should not set virtualization if kvm isn't there" do
77
+ File.should_receive(:exists?).at_least(:once).and_return(false)
78
+ @ohai._require_plugin("linux::virtualization")
79
+ @ohai[:virtualization].should == {}
80
+ end
81
+ end
82
+
83
+ describe "when we are parsing dmidecode" do
84
+ before(:each) do
85
+ File.should_receive(:exists?).with("/usr/sbin/dmidecode").and_return(true)
86
+ @stdin = mock("STDIN", { :close => true })
87
+ @pid = 10
88
+ @stderr = mock("STDERR")
89
+ @stdout = mock("STDOUT")
90
+ @status = 0
91
+ end
92
+
93
+ it "should run dmidecode" do
94
+ @ohai.should_receive(:popen4).with("dmidecode").and_return(true)
95
+ @ohai._require_plugin("linux::virtualization")
96
+ end
97
+
98
+ it "should set virtualpc guest if dmidecode detects Microsoft Virtual Machine" do
99
+ @stdout.stub!(:each).
100
+ and_yield("Manufacturer: Microsoft").
101
+ and_yield(" Product Name: Virtual Machine")
102
+ @ohai.stub!(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
103
+ @ohai._require_plugin("linux::virtualization")
104
+ @ohai[:virtualization][:emulator].should == "virtualpc"
105
+ @ohai[:virtualization][:role].should == "guest"
106
+ end
107
+
108
+ it "should set vmware guest if dmidecode detects VMware Virtual Platform" do
109
+ @stdout.stub!(:each).
110
+ and_yield("Manufacturer: VMware").
111
+ and_yield("Product Name: VMware Virtual Platform")
112
+ @ohai.stub!(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
113
+ @ohai._require_plugin("linux::virtualization")
114
+ @ohai[:virtualization][:emulator].should == "vmware"
115
+ @ohai[:virtualization][:role].should == "guest"
116
+ end
117
+
118
+ it "should run dmidecode and not set virtualization if nothing is detected" do
119
+ @ohai.should_receive(:popen4).with("dmidecode").and_return(true)
120
+ @ohai._require_plugin("linux::virtualization")
121
+ @ohai[:virtualization].should == {}
122
+ end
123
+ end
124
+
125
+ it "should not set virtualization if no tests match" do
126
+ @ohai._require_plugin("linux::virtualization")
127
+ @ohai[:virtualization].should == {}
128
+ end
129
+ end
130
+
131
+
@@ -0,0 +1,34 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 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
+
20
+ require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb')
21
+
22
+ describe Ohai::System, "NetBSD hostname plugin" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ @ohai[:os] = "netbsd"
27
+ @ohai.stub!(:from).with("hostname -s").and_return("katie")
28
+ @ohai.stub!(:from).with("hostname").and_return("katie.bethell")
29
+ end
30
+
31
+ it_should_check_from("netbsd::hostname", "hostname", "hostname -s", "katie")
32
+
33
+ it_should_check_from("netbsd::hostname", "fqdn", "hostname", "katie.bethell")
34
+ end
@@ -0,0 +1,36 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 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
+
20
+ require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb')
21
+
22
+ describe Ohai::System, "NetBSD kernel plugin" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ @ohai.stub!(:from).with("uname -i").and_return("foo")
27
+ @ohai.stub!(:from_with_regex).with("sysctl kern.securelevel").and_return("kern.securelevel: 1")
28
+ @ohai[:kernel] = Mash.new
29
+ @ohai[:kernel][:name] = "netbsd"
30
+ end
31
+
32
+ it "should set the kernel_os to the kernel_name value" do
33
+ @ohai._require_plugin("netbsd::kernel")
34
+ @ohai[:kernel][:os].should == @ohai[:kernel][:name]
35
+ end
36
+ end
@@ -0,0 +1,40 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 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
+
20
+ require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb')
21
+
22
+ describe Ohai::System, "NetBSD plugin platform" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ @ohai.stub!(:from).with("uname -s").and_return("NetBSD")
27
+ @ohai.stub!(:from).with("uname -r").and_return("4.5")
28
+ @ohai[:os] = "netbsd"
29
+ end
30
+
31
+ it "should set platform to lowercased lsb[:id]" do
32
+ @ohai._require_plugin("netbsd::platform")
33
+ @ohai[:platform].should == "netbsd"
34
+ end
35
+
36
+ it "should set platform_version to lsb[:release]" do
37
+ @ohai._require_plugin("netbsd::platform")
38
+ @ohai[:platform_version].should == "4.5"
39
+ end
40
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 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
+
20
+ require File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb')
21
+
22
+ describe Ohai::System, "plugin ohai_time" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ end
27
+
28
+ it "should get the current time" do
29
+ Time.should_receive(:now)
30
+ @ohai._require_plugin("ohai_time")
31
+ end
32
+
33
+ it "should turn the time into a floating point number" do
34
+ time = Time.now
35
+ time.should_receive(:to_f)
36
+ Time.stub!(:now).and_return(time)
37
+ @ohai._require_plugin("ohai_time")
38
+ end
39
+
40
+ it "should set ohai_time to the current time" do
41
+ time = Time.now
42
+ Time.stub!(:now).and_return(time)
43
+ @ohai._require_plugin("ohai_time")
44
+ @ohai[:ohai_time].should == time.to_f
45
+ end
46
+ end
@@ -0,0 +1,34 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 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
+
20
+ require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb')
21
+
22
+ describe Ohai::System, "OpenBSD hostname plugin" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ @ohai[:os] = "openbsd"
27
+ @ohai.stub!(:from).with("hostname -s").and_return("katie")
28
+ @ohai.stub!(:from).with("hostname").and_return("katie.bethell")
29
+ end
30
+
31
+ it_should_check_from("openbsd::hostname", "hostname", "hostname -s", "katie")
32
+
33
+ it_should_check_from("openbsd::hostname", "fqdn", "hostname", "katie.bethell")
34
+ end
@@ -0,0 +1,37 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 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
+
20
+ require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb')
21
+
22
+ describe Ohai::System, "OpenBSD kernel plugin" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ @ohai.stub!(:from).with("uname -i").and_return("foo")
27
+ @ohai.stub!(:from_with_regex).with("sysctl kern.securelevel").and_return("kern.securelevel: 1")
28
+ @ohai[:kernel] = Mash.new
29
+ @ohai[:kernel][:name] = "openbsd"
30
+ end
31
+
32
+ it "should set the kernel_os to the kernel_name value" do
33
+ @ohai._require_plugin("openbsd::kernel")
34
+ @ohai[:kernel][:os].should == @ohai[:kernel][:name]
35
+ end
36
+
37
+ end
@@ -0,0 +1,40 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 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
+
20
+ require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb')
21
+
22
+ describe Ohai::System, "OpenBSD plugin platform" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ @ohai.stub!(:from).with("uname -s").and_return("OpenBSD")
27
+ @ohai.stub!(:from).with("uname -r").and_return("4.5")
28
+ @ohai[:os] = "openbsd"
29
+ end
30
+
31
+ it "should set platform to lowercased lsb[:id]" do
32
+ @ohai._require_plugin("openbsd::platform")
33
+ @ohai[:platform].should == "openbsd"
34
+ end
35
+
36
+ it "should set platform_version to lsb[:release]" do
37
+ @ohai._require_plugin("openbsd::platform")
38
+ @ohai[:platform_version].should == "4.5"
39
+ end
40
+ end