ohai 8.26.1 → 13.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +3 -4
  3. data/Rakefile +14 -0
  4. data/lib/ohai/application.rb +1 -0
  5. data/lib/ohai/config.rb +2 -88
  6. data/lib/ohai/dsl/plugin.rb +0 -4
  7. data/lib/ohai/exception.rb +0 -1
  8. data/lib/ohai/loader.rb +11 -2
  9. data/lib/ohai/log.rb +3 -1
  10. data/lib/ohai/mixin/command.rb +1 -318
  11. data/lib/ohai/mixin/do_metadata.rb +47 -0
  12. data/lib/ohai/mixin/ec2_metadata.rb +2 -29
  13. data/lib/ohai/mixin/gce_metadata.rb +0 -37
  14. data/lib/ohai/mixin/http_helper.rb +56 -0
  15. data/lib/ohai/mixin/network_constants.rb +0 -5
  16. data/lib/ohai/plugins/cloud.rb +144 -157
  17. data/lib/ohai/plugins/darwin/filesystem.rb +68 -22
  18. data/lib/ohai/plugins/digital_ocean.rb +24 -42
  19. data/lib/ohai/plugins/dmi.rb +81 -77
  20. data/lib/ohai/plugins/ec2.rb +33 -60
  21. data/lib/ohai/plugins/gce.rb +3 -1
  22. data/lib/ohai/plugins/hostname.rb +1 -16
  23. data/lib/ohai/plugins/linux/filesystem.rb +130 -81
  24. data/lib/ohai/plugins/linux/mdadm.rb +3 -45
  25. data/lib/ohai/plugins/linux/network.rb +1 -26
  26. data/lib/ohai/plugins/linux/platform.rb +4 -2
  27. data/lib/ohai/plugins/linux/virtualization.rb +1 -5
  28. data/lib/ohai/plugins/scala.rb +1 -13
  29. data/lib/ohai/plugins/solaris2/network.rb +1 -2
  30. data/lib/ohai/plugins/uptime.rb +0 -9
  31. data/lib/ohai/plugins/windows/cpu.rb +2 -1
  32. data/lib/ohai/plugins/windows/network.rb +1 -1
  33. data/lib/ohai/runner.rb +0 -5
  34. data/lib/ohai/system.rb +38 -8
  35. data/lib/ohai/version.rb +2 -2
  36. data/ohai.gemspec +1 -1
  37. data/spec/functional/application_spec.rb +0 -40
  38. data/spec/functional/plugins/powershell_spec.rb +1 -1
  39. data/spec/functional/plugins/root_group_spec.rb +1 -1
  40. data/spec/functional/plugins/windows/uptime_spec.rb +1 -1
  41. data/spec/ohai_spec.rb +1 -1
  42. data/spec/support/integration_helper.rb +17 -0
  43. data/spec/support/platform_helpers.rb +17 -0
  44. data/spec/unit/application_spec.rb +0 -1
  45. data/spec/unit/config_spec.rb +0 -111
  46. data/spec/unit/dsl/plugin_spec.rb +1 -1
  47. data/spec/unit/hints_spec.rb +1 -1
  48. data/spec/unit/loader_spec.rb +26 -1
  49. data/spec/unit/mixin/command_spec.rb +1 -69
  50. data/spec/unit/mixin/ec2_metadata_spec.rb +1 -1
  51. data/spec/unit/mixin/softlayer_metadata_spec.rb +1 -1
  52. data/spec/unit/plugin_config_spec.rb +0 -1
  53. data/spec/unit/plugins/abort_spec.rb +1 -1
  54. data/spec/unit/plugins/aix/cpu_spec.rb +1 -1
  55. data/spec/unit/plugins/aix/filesystem_spec.rb +2 -1
  56. data/spec/unit/plugins/aix/hostname_spec.rb +1 -1
  57. data/spec/unit/plugins/aix/kernel_spec.rb +1 -1
  58. data/spec/unit/plugins/aix/memory_spec.rb +1 -1
  59. data/spec/unit/plugins/aix/network_spec.rb +1 -1
  60. data/spec/unit/plugins/aix/os_spec.rb +1 -1
  61. data/spec/unit/plugins/aix/platform_spec.rb +1 -1
  62. data/spec/unit/plugins/aix/uptime_spec.rb +1 -1
  63. data/spec/unit/plugins/aix/virtualization_spec.rb +1 -1
  64. data/spec/unit/plugins/azure_spec.rb +1 -1
  65. data/spec/unit/plugins/bsd/filesystem_spec.rb +1 -1
  66. data/spec/unit/plugins/bsd/virtualization_spec.rb +1 -1
  67. data/spec/unit/plugins/c_spec.rb +1 -1
  68. data/spec/unit/plugins/chef_spec.rb +1 -2
  69. data/spec/unit/plugins/cloud_spec.rb +210 -50
  70. data/spec/unit/plugins/darwin/cpu_spec.rb +1 -1
  71. data/spec/unit/plugins/darwin/filesystem_spec.rb +62 -13
  72. data/spec/unit/plugins/darwin/hardware_spec.rb +2 -2
  73. data/spec/unit/plugins/darwin/hostname_spec.rb +1 -1
  74. data/spec/unit/plugins/darwin/kernel_spec.rb +1 -1
  75. data/spec/unit/plugins/darwin/memory_spec.rb +1 -1
  76. data/spec/unit/plugins/darwin/network_spec.rb +1 -1
  77. data/spec/unit/plugins/darwin/platform_spec.rb +1 -1
  78. data/spec/unit/plugins/darwin/system_profiler_spec.rb +2 -9
  79. data/spec/unit/plugins/darwin/virtualization_spec.rb +1 -1
  80. data/spec/unit/plugins/digital_ocean_spec.rb +39 -110
  81. data/spec/unit/plugins/dmi_spec.rb +1 -1
  82. data/spec/unit/plugins/ec2_spec.rb +10 -62
  83. data/spec/unit/plugins/elixir_spec.rb +1 -1
  84. data/spec/unit/plugins/erlang_spec.rb +1 -1
  85. data/spec/unit/plugins/eucalyptus_spec.rb +1 -1
  86. data/spec/unit/plugins/fail_spec.rb +1 -1
  87. data/spec/unit/plugins/freebsd/cpu_spec.rb +1 -1
  88. data/spec/unit/plugins/freebsd/hostname_spec.rb +1 -1
  89. data/spec/unit/plugins/freebsd/kernel_spec.rb +1 -1
  90. data/spec/unit/plugins/freebsd/os_spec.rb +1 -1
  91. data/spec/unit/plugins/freebsd/platform_spec.rb +1 -1
  92. data/spec/unit/plugins/gce_spec.rb +1 -1
  93. data/spec/unit/plugins/go_spec.rb +1 -1
  94. data/spec/unit/plugins/groovy_spec.rb +1 -1
  95. data/spec/unit/plugins/haskell_spec.rb +1 -1
  96. data/spec/unit/plugins/hostname_spec.rb +16 -41
  97. data/spec/unit/plugins/init_package_spec.rb +1 -1
  98. data/spec/unit/plugins/ip_scopes_spec.rb +18 -6
  99. data/spec/unit/plugins/java_spec.rb +1 -1
  100. data/spec/unit/plugins/joyent_spec.rb +17 -1
  101. data/spec/unit/plugins/kernel_spec.rb +1 -1
  102. data/spec/unit/plugins/linode_spec.rb +1 -1
  103. data/spec/unit/plugins/linux/block_device_spec.rb +1 -1
  104. data/spec/unit/plugins/linux/cpu_spec.rb +1 -2
  105. data/spec/unit/plugins/linux/filesystem_spec.rb +207 -201
  106. data/spec/unit/plugins/linux/fips_spec.rb +1 -1
  107. data/spec/unit/plugins/linux/hostname_spec.rb +1 -1
  108. data/spec/unit/plugins/linux/hostnamectl_spec.rb +1 -1
  109. data/spec/unit/plugins/linux/kernel_spec.rb +1 -1
  110. data/spec/unit/plugins/linux/lsb_spec.rb +1 -1
  111. data/spec/unit/plugins/linux/machineid_spec.rb +1 -1
  112. data/spec/unit/plugins/linux/mdadm_spec.rb +2 -68
  113. data/spec/unit/plugins/linux/memory_spec.rb +1 -1
  114. data/spec/unit/plugins/linux/network_spec.rb +3 -44
  115. data/spec/unit/plugins/linux/platform_spec.rb +4 -4
  116. data/spec/unit/plugins/linux/sessions_spec.rb +1 -1
  117. data/spec/unit/plugins/linux/uptime_spec.rb +1 -1
  118. data/spec/unit/plugins/linux/virtualization_spec.rb +1 -28
  119. data/spec/unit/plugins/lua_spec.rb +1 -1
  120. data/spec/unit/plugins/mono_spec.rb +1 -1
  121. data/spec/unit/plugins/netbsd/hostname_spec.rb +1 -1
  122. data/spec/unit/plugins/netbsd/kernel_spec.rb +1 -1
  123. data/spec/unit/plugins/netbsd/platform_spec.rb +1 -1
  124. data/spec/unit/plugins/network_spec.rb +1 -1
  125. data/spec/unit/plugins/nodejs_spec.rb +1 -1
  126. data/spec/unit/plugins/ohai_spec.rb +1 -1
  127. data/spec/unit/plugins/ohai_time_spec.rb +1 -1
  128. data/spec/unit/plugins/openbsd/hostname_spec.rb +1 -1
  129. data/spec/unit/plugins/openbsd/kernel_spec.rb +1 -1
  130. data/spec/unit/plugins/openbsd/platform_spec.rb +1 -1
  131. data/spec/unit/plugins/openstack_spec.rb +2 -3
  132. data/spec/unit/plugins/os_spec.rb +1 -1
  133. data/spec/unit/plugins/packages_spec.rb +1 -1
  134. data/spec/unit/plugins/passwd_spec.rb +17 -1
  135. data/spec/unit/plugins/perl_spec.rb +1 -1
  136. data/spec/unit/plugins/php_spec.rb +1 -1
  137. data/spec/unit/plugins/platform_spec.rb +1 -1
  138. data/spec/unit/plugins/powershell_spec.rb +1 -1
  139. data/spec/unit/plugins/python_spec.rb +1 -1
  140. data/spec/unit/plugins/rackspace_spec.rb +1 -2
  141. data/spec/unit/plugins/root_group_spec.rb +2 -2
  142. data/spec/unit/plugins/ruby_spec.rb +1 -1
  143. data/spec/unit/plugins/rust_spec.rb +1 -1
  144. data/spec/unit/plugins/scala_spec.rb +3 -37
  145. data/spec/unit/plugins/shard_spec.rb +1 -1
  146. data/spec/unit/plugins/shells_spec.rb +1 -1
  147. data/spec/unit/plugins/softlayer_spec.rb +1 -1
  148. data/spec/unit/plugins/solaris2/cpu_spec.rb +1 -1
  149. data/spec/unit/plugins/solaris2/dmi_spec.rb +1 -1
  150. data/spec/unit/plugins/solaris2/hostname_spec.rb +1 -1
  151. data/spec/unit/plugins/solaris2/kernel_spec.rb +1 -1
  152. data/spec/unit/plugins/solaris2/memory_spec.rb +1 -1
  153. data/spec/unit/plugins/solaris2/network_spec.rb +7 -4
  154. data/spec/unit/plugins/solaris2/platform_spec.rb +1 -1
  155. data/spec/unit/plugins/solaris2/virtualization_spec.rb +1 -1
  156. data/spec/unit/plugins/solaris2/zpools_spec.rb +1 -1
  157. data/spec/unit/plugins/ssh_host_keys_spec.rb +1 -1
  158. data/spec/unit/plugins/sysconf_spec.rb +1 -1
  159. data/spec/unit/plugins/timezone_spec.rb +1 -1
  160. data/spec/unit/plugins/virtualbox_spec.rb +1 -1
  161. data/spec/unit/plugins/vmware_spec.rb +2 -1
  162. data/spec/unit/plugins/windows/cpu_spec.rb +9 -2
  163. data/spec/unit/plugins/windows/fips_spec.rb +1 -1
  164. data/spec/unit/plugins/windows/memory_spec.rb +1 -1
  165. data/spec/unit/plugins/windows/uptime_spec.rb +1 -1
  166. data/spec/unit/plugins/windows/virtualization_spec.rb +1 -1
  167. data/spec/unit/provides_map_spec.rb +1 -1
  168. data/spec/unit/runner_spec.rb +1 -1
  169. data/spec/unit/system_spec.rb +68 -76
  170. data/spec/unit/util/file_helper_spec.rb +1 -1
  171. data/spec/unit/util/ip_helper_spec.rb +1 -1
  172. metadata +6 -20
  173. data/lib/ohai/plugins/cloud_v2.rb +0 -315
  174. data/lib/ohai/plugins/darwin/filesystem2.rb +0 -107
  175. data/lib/ohai/plugins/linux/filesystem2.rb +0 -223
  176. data/lib/ohai/plugins/linux/lspci.rb +0 -76
  177. data/lib/ohai/plugins/network_listeners.rb +0 -60
  178. data/lib/ohai/plugins/sigar/cpu.rb +0 -44
  179. data/lib/ohai/plugins/sigar/filesystem.rb +0 -50
  180. data/lib/ohai/plugins/sigar/memory.rb +0 -39
  181. data/lib/ohai/plugins/sigar/network.rb +0 -168
  182. data/lib/ohai/plugins/sigar/network_route.rb +0 -64
  183. data/lib/ohai/plugins/sigar/platform.rb +0 -30
  184. data/spec/unit/plugins/cloud_v2_spec.rb +0 -389
  185. data/spec/unit/plugins/darwin/filesystem2_spec.rb +0 -139
  186. data/spec/unit/plugins/linux/filesystem2_spec.rb +0 -437
  187. data/spec/unit/plugins/linux/lspci_spec.rb +0 -133
  188. data/spec/unit/plugins/sigar/network_route_spec.rb +0 -148
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
19
+ require_relative "../../../spec_helper.rb"
20
20
 
21
21
  describe Ohai::System, "Darwin cpu plugin" do
22
22
  before(:each) do
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
19
+ require_relative "../../../spec_helper.rb"
20
20
 
21
21
  describe Ohai::System, "darwin filesystem plugin" do
22
22
  let (:plugin) { get_plugin("darwin/filesystem") }
@@ -27,6 +27,11 @@ describe Ohai::System, "darwin filesystem plugin" do
27
27
  allow(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, "", ""))
28
28
  end
29
29
 
30
+ it "sets both filesystem and filesystem2 attributes" do
31
+ plugin.run
32
+ expect(plugin[:filesystem]).to eq(plugin[:filesystem2])
33
+ end
34
+
30
35
  describe "when gathering filesystem usage data from df" do
31
36
  before(:each) do
32
37
  @stdout = <<-DF
@@ -48,22 +53,23 @@ DF
48
53
 
49
54
  it "should set size to value from df -i" do
50
55
  plugin.run
51
- expect(plugin[:filesystem]["/dev/disk0s2"][:kb_size]).to eq(244277768)
52
- expect(plugin[:filesystem]["/dev/disk0s2"][:kb_used]).to eq(156848224)
53
- expect(plugin[:filesystem]["/dev/disk0s2"][:kb_available]).to eq(87173544)
54
- expect(plugin[:filesystem]["/dev/disk0s2"][:percent_used]).to eq("65%")
56
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:kb_size]).to eq("244277768")
57
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:kb_used]).to eq("156848224")
58
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:kb_available]).to eq("87173544")
59
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:percent_used]).to eq("65%")
55
60
  end
56
61
 
57
- it "should set mount to value from df -i" do
62
+ it "should set device and mount to value from df -i" do
58
63
  plugin.run
59
- expect(plugin[:filesystem]["/dev/disk0s2"][:mount]).to eq("/")
64
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:mount]).to eq("/")
65
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:device]).to eq("/dev/disk0s2")
60
66
  end
61
67
 
62
68
  it "should set inode info to value from df -i" do
63
69
  plugin.run
64
- expect(plugin[:filesystem]["/dev/disk0s2"][:total_inodes]).to eq("61069440")
65
- expect(plugin[:filesystem]["/dev/disk0s2"][:inodes_used]).to eq("39276054")
66
- expect(plugin[:filesystem]["/dev/disk0s2"][:inodes_available]).to eq("21793386")
70
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:total_inodes]).to eq("61069440")
71
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:inodes_used]).to eq("39276054")
72
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:inodes_available]).to eq("21793386")
67
73
  end
68
74
  end
69
75
 
@@ -87,9 +93,52 @@ MOUNT
87
93
 
88
94
  it "should set values from mount" do
89
95
  plugin.run
90
- expect(plugin[:filesystem]["/dev/disk0s2"][:mount]).to eq("/")
91
- expect(plugin[:filesystem]["/dev/disk0s2"][:fs_type]).to eq("hfs")
92
- expect(plugin[:filesystem]["/dev/disk0s2"][:mount_options]).to eq(%w{local journaled})
96
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:mount]).to eq("/")
97
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:fs_type]).to eq("hfs")
98
+ expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:mount_options]).to eq(%w{local journaled})
99
+ end
100
+ end
101
+
102
+ describe "when gathering filesystem data with devices mounted more than once" do
103
+ before(:each) do
104
+ @dfstdout = <<-DF
105
+ Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on
106
+ /dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% /
107
+ devfs 385 385 0 100% 666 0 100% /dev
108
+ map /etc/auto.direct 0 0 0 100% 0 0 100% /mnt/vol
109
+ map -hosts 0 0 0 100% 0 0 100% /net
110
+ map -static 0 0 0 100% 0 0 100% /mobile_symbol
111
+ deweyfs@osxfuse0 0 0 0 100% 0 0 100% /mnt/dewey
112
+ /dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% /another/mountpoint
113
+ DF
114
+ allow(plugin).to receive(:shell_out).with("df -i").and_return(mock_shell_out(0, @dfstdout, ""))
115
+ end
116
+
117
+ it "should provide a devices view with all mountpoints" do
118
+ plugin.run
119
+ expect(plugin[:filesystem]["by_device"]["/dev/disk0s2"][:mounts]).to eq(["/", "/another/mountpoint"])
120
+ end
121
+ end
122
+
123
+ describe "when gathering filesystem data with double-mounts" do
124
+ before(:each) do
125
+ @dfstdout = <<-DF
126
+ Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on
127
+ /dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% /
128
+ devfs 385 385 0 100% 666 0 100% /dev
129
+ map /etc/auto.direct 0 0 0 100% 0 0 100% /mnt/vol
130
+ map -hosts 0 0 0 100% 0 0 100% /net
131
+ map -static 0 0 0 100% 0 0 100% /mobile_symbol
132
+ deweyfs@osxfuse0 0 0 0 100% 0 0 100% /mnt/dewey
133
+ /dev/disk0s3 488555536 313696448 174347088 65% 39276054 21793386 64% /mnt
134
+ /dev/disk0s4 488555536 313696448 174347088 65% 39276054 21793386 64% /mnt
135
+ DF
136
+ allow(plugin).to receive(:shell_out).with("df -i").and_return(mock_shell_out(0, @dfstdout, ""))
137
+ end
138
+
139
+ it "should provide a mounts view with all devices" do
140
+ plugin.run
141
+ expect(plugin[:filesystem]["by_mountpoint"]["/mnt"][:devices]).to eq(["/dev/disk0s3", "/dev/disk0s4"])
93
142
  end
94
143
  end
95
144
  end
@@ -16,8 +16,8 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
20
- require File.expand_path("#{File.dirname(__FILE__)}/hardware_system_profiler_output.rb")
19
+ require_relative "../../../spec_helper.rb"
20
+ require_relative "hardware_system_profiler_output.rb"
21
21
 
22
22
  describe Ohai::System, "Darwin hardware plugin", :unix_only do
23
23
  let (:plugin) { get_plugin("darwin/hardware") }
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
19
+ require_relative "../../../spec_helper.rb"
20
20
 
21
21
  describe Ohai::System, "Darwin hostname plugin" do
22
22
  before(:each) do
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
19
+ require_relative "../../../spec_helper.rb"
20
20
 
21
21
  describe Ohai::System, "Darwin kernel plugin" do
22
22
  before(:each) do
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
19
+ require_relative "../../../spec_helper.rb"
20
20
 
21
21
  describe Ohai::System, "Darwin Memory Plugin" do
22
22
  before(:each) do
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
19
+ require_relative "../../../spec_helper.rb"
20
20
 
21
21
  describe Ohai::System, "Darwin Network Plugin" do
22
22
  before(:each) do
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
19
+ require_relative "../../../spec_helper.rb"
20
20
 
21
21
  describe Ohai::System, "Darwin plugin platform" do
22
22
  before(:each) do
@@ -16,15 +16,8 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
20
- require File.expand_path("#{File.dirname(__FILE__)}/system_profiler_output.rb")
21
-
22
- begin
23
- require "plist"
24
- rescue LoadError => e
25
- puts "The darwin systemprofile plugin spec tests will fail without the 'plist' library/gem.\n\n"
26
- raise e
27
- end
19
+ require_relative "../../../spec_helper.rb"
20
+ require_relative "system_profiler_output.rb"
28
21
 
29
22
  describe Ohai::System, "Darwin system_profiler plugin", :unix_only do
30
23
  before(:each) do
@@ -18,7 +18,7 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
- require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
21
+ require_relative "../../../spec_helper.rb"
22
22
 
23
23
  describe Ohai::System, "Darwin virtualization platform" do
24
24
  let(:plugin) { get_plugin("darwin/virtualization") }
@@ -1,4 +1,5 @@
1
1
  #
2
+ # Author:: Dylan Page (<dpage@digitalocean.com>)
2
3
  # Author:: Stafford Brunk (<stafford.brunk@gmail.com>)
3
4
  # License:: Apache License, Version 2.0
4
5
  #
@@ -15,12 +16,10 @@
15
16
  # limitations under the License.
16
17
  #
17
18
 
18
- require "ipaddress"
19
19
  require "spec_helper"
20
20
 
21
21
  describe Ohai::System, "plugin digital_ocean" do
22
22
  let(:plugin) { get_plugin("digital_ocean") }
23
- let(:digitalocean_path) { "/etc/digitalocean" }
24
23
  let(:hint) do
25
24
  {
26
25
  "droplet_id" => 12345678,
@@ -35,141 +34,71 @@ describe Ohai::System, "plugin digital_ocean" do
35
34
  }
36
35
  end
37
36
 
38
- before do
39
- plugin[:network] = {
40
- "interfaces" => {
41
- "eth0" => {
42
- "addresses" => {
43
- "00:D3:AD:B3:3F:00" => {
44
- "family" => "lladdr",
45
- },
46
- "1.2.3.4" => {
47
- "netmask" => "255.255.255.0",
48
- },
49
- "2400:6180:0000:00d0:0000:0000:0009:7001" => {},
50
- },
51
- },
52
- },
53
- }
54
-
55
- allow(plugin).to receive(:hint?).with("digital_ocean").and_return(hint)
37
+ before(:each) do
38
+ allow(plugin).to receive(:hint?).with("digital_ocean").and_return(false)
56
39
  end
57
40
 
58
41
  shared_examples_for "!digital_ocean" do
59
- before(:each) do
60
- plugin.run
61
- end
62
-
63
- it "does not create the digital_ocean mash" do
42
+ it "should NOT attempt to fetch the digital_ocean metadata" do
43
+ expect(plugin).not_to receive(:http_client)
64
44
  expect(plugin[:digital_ocean]).to be_nil
45
+ plugin.run
65
46
  end
66
47
  end
67
48
 
68
- shared_examples_for "digital_ocean_networking" do
69
- it "creates the networks attribute" do
70
- expect(plugin[:digital_ocean][:networks]).not_to be_nil
49
+ shared_examples_for "digital_ocean" do
50
+ before(:each) do
51
+ @http_client = double("Net::HTTP client")
52
+ allow(plugin).to receive(:http_client).and_return(@http_client)
53
+ allow(IO).to receive(:select).and_return([[], [1], []])
54
+ t = double("connection")
55
+ allow(t).to receive(:connect_nonblock).and_raise(Errno::EINPROGRESS)
56
+ allow(Socket).to receive(:new).and_return(t)
57
+ allow(Socket).to receive(:pack_sockaddr_in).and_return(nil)
71
58
  end
72
59
 
73
- it "pulls ip addresses from the network interfaces" do
74
- expect(plugin[:digital_ocean][:networks][:v4]).to eq([{ "ip_address" => "1.2.3.4",
75
- "type" => "public",
76
- "netmask" => "255.255.255.0" }])
77
- expect(plugin[:digital_ocean][:networks][:v6]).to eq([{ "ip_address" => "2400:6180:0000:00d0:0000:0000:0009:7001",
78
- "type" => "public",
79
- "cidr" => 128 }])
60
+ let(:body) do
61
+ '{"droplet_id":2756924,"hostname":"sample-droplet","vendor_data":"#cloud-config\ndisable_root: false\nmanage_etc_hosts: true\n\n# The modules that run in the \'init\' stage\ncloud_init_modules:\n - migrator\n - ubuntu-init-switch\n - seed_random\n - bootcmd\n - write-files\n - growpart\n - resizefs\n - set_hostname\n - update_hostname\n - [ update_etc_hosts, once-per-instance ]\n - ca-certs\n - rsyslog\n - users-groups\n - ssh\n\n# The modules that run in the \'config\' stage\ncloud_config_modules:\n - disk_setup\n - mounts\n - ssh-import-id\n - locale\n - set-passwords\n - grub-dpkg\n - apt-pipelining\n - apt-configure\n - package-update-upgrade-install\n - landscape\n - timezone\n - puppet\n - chef\n - salt-minion\n - mcollective\n - disable-ec2-metadata\n - runcmd\n - byobu\n\n# The modules that run in the \'final\' stage\ncloud_final_modules:\n - rightscale_userdata\n - scripts-vendor\n - scripts-per-once\n - scripts-per-boot\n - scripts-per-instance\n - scripts-user\n - ssh-authkey-fingerprints\n - keys-to-console\n - phone-home\n - final-message\n - power-state-change\n","public_keys":["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDAkMD3PYKHaH0KbDiXrRE6KCBo/OKcFqhM+fmnnb0+LUh4RalJWX4edeJmnT5bxLeqmLV/Yggjlpfq73R+Dy7JB4pbBLuM959mSM9ohBCSnByAGoT2iUPev4aZFZZ/ahUzTCylNxXrhZV/bopD399CvYREt7Q+FlauBv0O8MMuMGR8aC69Z3jNL+r+fGWNq98JVHGFO/UgoNL15wGCaidMhzfRqkt1u+m1nY77SFM5qWJz2R0CEC4fMlOiCg8mWBklnryV4yDEPgiXp2I8Rli1Eu2GHwuY1YX9elMeQS7n3Pzq7l6aIQmSgvcEWx6TgMD2V7nQUWpfcud/8dpp/t7z9UyfzLmNwnULHNmUeEp52sejcH5lYzISnkkWa1LzlKSeIrhF3y45m9AyxIfjEqyh/mlKQtUaW3NVXXLPwrNitxHtMIZPU5b16BODn0wb8bqPxpDNpUYrQd/BS7mWDxNpICP2ObLPhd9LW9KIYRNTzryE+uKwxm9NkMlhRku2fu415fH0G0+7aURsHviNN9SO4zct3Pj6QE5rnbVHqxt3biplUTOScdWxSk2Nv3V2dGdt/lBfu6iRPAV9IAS31s7Po3qK1t2jpEPCJwstaCBOM80kmoi3zAgotiAW50X8CelaWsHNrq5jBBgeHUZWgn/c8BkcI61pUE9l34Q6gsiEMQ== tsmith84@gmail.com"],"region":"nyc3","interfaces":{"public":[{"ipv4":{"ip_address":"159.203.92.161","netmask":"255.255.240.0","gateway":"159.203.80.1"},"ipv6":{"ip_address":"2604:A880:0800:00A1:0000:0000:0201:0001","cidr":64,"gateway":"2604:A880:0800:00A1:0000:0000:0000:0001"},"anchor_ipv4":{"ip_address":"10.17.0.5","netmask":"255.255.0.0","gateway":"10.17.0.1"},"mac":"04:01:e5:14:03:01","type":"public"}]},"floating_ip":{"ipv4":{"active":false}},"dns":{"nameservers":["2001:4860:4860::8844","2001:4860:4860::8888","8.8.8.8"]}}'
80
62
  end
81
- end
82
63
 
83
- shared_examples_for "digital_ocean" do
84
- before(:each) do
64
+ it "should fetch and properly parse json metadata" do
65
+ expect(@http_client).to receive(:get).
66
+ with("/metadata/v1.json").
67
+ and_return(double("Net::HTTP Response", :body => body, :code => "200"))
85
68
  plugin.run
86
- end
87
69
 
88
- it "creates a digital_ocean mash" do
89
70
  expect(plugin[:digital_ocean]).not_to be_nil
71
+ expect(plugin[:digital_ocean]["droplet_id"]).to eq(2756924)
72
+ expect(plugin[:digital_ocean]["hostname"]).to eq("sample-droplet")
90
73
  end
91
74
 
92
- it "has all hint attributes" do
93
- expect(plugin[:digital_ocean][:droplet_id]).not_to be_nil
94
- expect(plugin[:digital_ocean][:name]).not_to be_nil
95
- expect(plugin[:digital_ocean][:image_id]).not_to be_nil
96
- expect(plugin[:digital_ocean][:size_id]).not_to be_nil
97
- expect(plugin[:digital_ocean][:region_id]).not_to be_nil
98
- end
99
-
100
- it "skips the ip_addresses hint attribute" do
101
- expect(plugin[:digital_ocean][:ip_addresses]).to be_nil
102
- end
75
+ it "should complete the run despite unavailable metadata" do
76
+ expect(@http_client).to receive(:get).
77
+ with("/metadata/v1.json").
78
+ and_return(double("Net::HTTP Response", :body => "", :code => "404"))
79
+ plugin.run
103
80
 
104
- it "has correct values for all hint attributes" do
105
- expect(plugin[:digital_ocean][:droplet_id]).to eq(12345678)
106
- expect(plugin[:digital_ocean][:name]).to eq("example.com")
107
- expect(plugin[:digital_ocean][:image_id]).to eq(3240036)
108
- expect(plugin[:digital_ocean][:size_id]).to eq(66)
109
- expect(plugin[:digital_ocean][:region_id]).to eq(4)
81
+ expect(plugin[:digitalocean]).to be_nil
110
82
  end
83
+ end
111
84
 
112
- include_examples "digital_ocean_networking"
85
+ describe "without hint or dmi data" do
86
+ it_should_behave_like "!digital_ocean"
113
87
  end
114
88
 
115
89
  describe "with digital_ocean hint file" do
116
- before do
117
- allow(plugin).to receive(:hint?).with("digital_ocean").and_return(hint)
118
- end
119
-
120
- context "without private networking enabled" do
121
- it_behaves_like "digital_ocean"
122
- end
90
+ it_should_behave_like "digital_ocean"
123
91
 
124
- context "with private networking enabled" do
125
- before do
126
- plugin[:network][:interfaces][:eth1] = {
127
- "addresses" => {
128
- "10.128.142.89" => {
129
- "netmask" => "255.255.255.0",
130
- },
131
- "fdf8:f53b:82e4:0000:0000:0000:0000:0053" => {},
132
- },
133
- }
134
-
135
- plugin.run
136
- end
137
-
138
- it "extracts the private networking ips" do
139
- expect(plugin[:digital_ocean][:networks][:v4]).to eq([{ "ip_address" => "1.2.3.4",
140
- "type" => "public",
141
- "netmask" => "255.255.255.0" },
142
- { "ip_address" => "10.128.142.89",
143
- "type" => "private",
144
- "netmask" => "255.255.255.0" }])
145
- expect(plugin[:digital_ocean][:networks][:v6]).to eq([{ "ip_address" => "2400:6180:0000:00d0:0000:0000:0009:7001",
146
- "type" => "public",
147
- "cidr" => 128 },
148
- { "ip_address" => "fdf8:f53b:82e4:0000:0000:0000:0000:0053",
149
- "type" => "private",
150
- "cidr" => 128 }])
151
- end
92
+ before(:each) do
93
+ allow(plugin).to receive(:hint?).with("digital_ocean").and_return(true)
152
94
  end
153
95
  end
154
96
 
155
- describe "without digital_ocean hint file" do
156
- before do
157
- allow(plugin).to receive(:hint?).with("digital_ocean").and_return(false)
158
- end
97
+ describe "with digital_ocean DMI data" do
98
+ it_should_behave_like "digital_ocean"
159
99
 
160
- describe "with the /etc/digitalocean file" do
161
- before do
162
- allow(File).to receive(:exist?).with(digitalocean_path).and_return(true)
163
- plugin.run
164
- end
165
- it_behaves_like "digital_ocean_networking"
166
- end
167
-
168
- describe "without the /etc/digitalocean file" do
169
- before do
170
- allow(File).to receive(:exist?).with(digitalocean_path).and_return(false)
171
- end
172
- it_behaves_like "!digital_ocean"
100
+ before(:each) do
101
+ plugin[:dmi] = { :bios => { :all_records => [ { :Vendor => "DigitalOcean" } ] } }
173
102
  end
174
103
  end
175
104
  end
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb")
19
+ require_relative "../../spec_helper.rb"
20
20
 
21
21
  # NOTE: These data lines must be prefixed with one or two tabs, not spaces.
22
22
  DMI_OUT = <<-EOS
@@ -23,16 +23,14 @@ require "base64"
23
23
 
24
24
  describe Ohai::System, "plugin ec2" do
25
25
 
26
- let(:plugin) { get_plugin("ec2") }
27
-
28
26
  before(:each) do
29
27
  allow(plugin).to receive(:hint?).with("ec2").and_return(false)
30
28
  allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(false)
31
- allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(false)
32
- allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(false)
33
29
  end
34
30
 
35
31
  shared_examples_for "!ec2" do
32
+ let(:plugin) { get_plugin("ec2") }
33
+
36
34
  it "DOESN'T attempt to fetch the ec2 metadata or set ec2 attribute" do
37
35
  expect(plugin).not_to receive(:http_client)
38
36
  expect(plugin[:ec2]).to be_nil
@@ -41,6 +39,8 @@ describe Ohai::System, "plugin ec2" do
41
39
  end
42
40
 
43
41
  shared_examples_for "ec2" do
42
+ let(:plugin) { get_plugin("ec2") }
43
+
44
44
  before(:each) do
45
45
  @http_client = double("Net::HTTP client")
46
46
  allow(plugin).to receive(:http_client).and_return(@http_client)
@@ -334,39 +334,19 @@ describe Ohai::System, "plugin ec2" do
334
334
  end
335
335
  end # shared examples for ec2
336
336
 
337
- describe "with amazon dmi bios version data" do
337
+ describe "with ec2 dmi data" do
338
338
  it_behaves_like "ec2"
339
339
 
340
340
  before(:each) do
341
- allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(true)
342
- allow(File).to receive(:read).with("/sys/class/dmi/id/bios_version").and_return("4.2.amazon\n")
341
+ plugin[:dmi] = { :bios => { :all_records => [ { :Version => "4.2.amazon" } ] } }
343
342
  end
344
343
  end
345
344
 
346
- describe "with non-amazon dmi bios version data" do
347
- it_behaves_like "!ec2"
348
-
349
- before(:each) do
350
- allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(true)
351
- allow(File).to receive(:read).with("/sys/class/dmi/id/bios_version").and_return("1.0\n")
352
- end
353
- end
354
-
355
- describe "with amazon dmi bios vendor data" do
345
+ describe "with amazon kernel data" do
356
346
  it_behaves_like "ec2"
357
347
 
358
348
  before(:each) do
359
- allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(true)
360
- allow(File).to receive(:read).with("/sys/class/dmi/id/bios_vendor").and_return("Amazon EC2\n")
361
- end
362
- end
363
-
364
- describe "with non-amazon dmi bios vendor data" do
365
- it_behaves_like "!ec2"
366
-
367
- before(:each) do
368
- allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(true)
369
- allow(File).to receive(:read).with("/sys/class/dmi/id/bios_vendor").and_return("Xen\n")
349
+ plugin[:kernel] = { :os_info => { :organization => "Amazon.com" } }
370
350
  end
371
351
  end
372
352
 
@@ -375,7 +355,7 @@ describe Ohai::System, "plugin ec2" do
375
355
 
376
356
  before(:each) do
377
357
  allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(true)
378
- allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("ec2a0561-e4d6-8e15-d9c8-2e0e03adcde8\n")
358
+ allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("ec2a0561-e4d6-8e15-d9c8-2e0e03adcde8")
379
359
  end
380
360
  end
381
361
 
@@ -384,39 +364,7 @@ describe Ohai::System, "plugin ec2" do
384
364
 
385
365
  before(:each) do
386
366
  allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(true)
387
- allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("123a0561-e4d6-8e15-d9c8-2e0e03adcde8\n")
388
- end
389
- end
390
-
391
- describe "with EC2 Identifying Number", :windows_only do
392
- it_behaves_like "ec2"
393
-
394
- before do
395
- allow_any_instance_of(WmiLite::Wmi).to receive(:first_of).and_return(
396
- { "caption" => "Computer System Product",
397
- "description" => "Computer System Product",
398
- "identifyingnumber" => "ec2a355a-91cd-5fe8-bbfc-cc891d0bf9d6",
399
- "name" => "HVM domU",
400
- "skunumber" => nil,
401
- "uuid" => "5A352AEC-CD91-E85F-BBFC-CC891D0BF9D6",
402
- "vendor" => "Xen",
403
- "version" => "4.2.amazon" })
404
- end
405
- end
406
-
407
- describe "without EC2 Identifying Number", :windows_only do
408
- it_behaves_like "!ec2"
409
-
410
- before do
411
- allow_any_instance_of(WmiLite::Wmi).to receive(:first_of).and_return(
412
- { "caption" => "Computer System Product",
413
- "description" => "Computer System Product",
414
- "identifyingnumber" => "1234",
415
- "name" => "HVM domU",
416
- "skunumber" => nil,
417
- "uuid" => "5A352AEC-CD91-E85F-BBFC-CC891D0BF9D6",
418
- "vendor" => "Xen",
419
- "version" => "1.2.3" })
367
+ allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("123a0561-e4d6-8e15-d9c8-2e0e03adcde8")
420
368
  end
421
369
  end
422
370