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
@@ -17,7 +17,7 @@
17
17
  # limitations under the License
18
18
  #
19
19
 
20
- require File.expand_path("../../../spec_helper.rb", __FILE__)
20
+ require_relative "../../spec_helper.rb"
21
21
 
22
22
  shared_examples "Ohai::DSL::Plugin" do
23
23
  context "#initialize" do
@@ -17,7 +17,7 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require File.expand_path(File.dirname(__FILE__) + "/../spec_helper.rb")
20
+ require_relative "../spec_helper.rb"
21
21
 
22
22
  describe "Ohai::Hints" do
23
23
  # We are using the plugins directory infrastructure to test hints
@@ -17,7 +17,7 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require File.expand_path(File.dirname(__FILE__) + "/../spec_helper.rb")
20
+ require_relative "../spec_helper.rb"
21
21
 
22
22
  describe Ohai::Loader do
23
23
  extend IntegrationSupport
@@ -95,6 +95,31 @@ EOF
95
95
  end
96
96
  end
97
97
 
98
+ when_plugins_directory "is an additional plugin path" do
99
+ with_plugin("cookbook_a/alpha.rb", <<EOF)
100
+ Ohai.plugin(:Alpha) do
101
+ provides "alpha"
102
+ end
103
+ EOF
104
+
105
+ with_plugin("cookbook_b/beta.rb", <<EOF)
106
+ Ohai.plugin(:Beta) do
107
+ provides "beta"
108
+ end
109
+ EOF
110
+
111
+ describe "#load_additional" do
112
+ it "adds the plugins to the map" do
113
+ loader.load_additional(@plugins_directory)
114
+ expect(provides_map.map.keys).to include("alpha")
115
+ end
116
+
117
+ it "returns a set of plugins" do
118
+ expect(loader.load_additional(@plugins_directory)).to include(Ohai::NamedPlugin::Alpha)
119
+ end
120
+ end
121
+ end
122
+
98
123
  when_plugins_directory "contains invalid plugins" do
99
124
  with_plugin("extra_s.rb", <<EOF)
100
125
  Ohai.plugins(:ExtraS) do
@@ -17,75 +17,7 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb")
21
-
22
- describe Ohai::Mixin::Command, "popen4" do
23
- break if RUBY_PLATFORM =~ /(win|w)32$/
24
-
25
- it "should default all commands to be run in the POSIX standard C locale" do
26
- Ohai::Mixin::Command.popen4("echo $LC_ALL") do |pid, stdin, stdout, stderr|
27
- stdin.close
28
- expect(stdout.read.strip).to eq("C")
29
- end
30
- end
31
-
32
- it "should respect locale when specified explicitly" do
33
- Ohai::Mixin::Command.popen4("echo $LC_ALL", :environment => { "LC_ALL" => "es" }) do |pid, stdin, stdout, stderr|
34
- stdin.close
35
- expect(stdout.read.strip).to eq("es")
36
- end
37
- end
38
-
39
- if defined?(::Encoding) && "".respond_to?(:force_encoding) #i.e., ruby 1.9
40
- context "when external commands return UTF-8 strings and we are running under LANG=C encoding" do
41
- before do
42
- @saved_default_external = Encoding.default_external
43
- @saved_default_internal = Encoding.default_internal
44
- Encoding.default_external = Encoding::US_ASCII
45
- Encoding.default_internal = Encoding::US_ASCII
46
- end
47
-
48
- after do
49
- Encoding.default_external = @saved_default_external
50
- Encoding.default_internal = @saved_default_internal
51
- end
52
-
53
- it "should force encode the string to UTF-8" do
54
- extend Ohai::Mixin::Command
55
- snowy = run_command(:command => ("echo '" + ("☃" * 8096) + "'"))[1]
56
- expect(snowy.encoding).to eq(Encoding::UTF_8)
57
- end
58
- end
59
-
60
- it "should force encode the string to UTF-8" do
61
- extend Ohai::Mixin::Command
62
- snowy = run_command(:command => ("echo '" + ("☃" * 8096) + "'"))[1]
63
- expect(snowy.encoding).to eq(Encoding::UTF_8)
64
- end
65
- end
66
-
67
- it "reaps zombie processes after exec fails [OHAI-455]" do
68
- # NOTE: depending on ulimit settings, GC, etc., before the OHAI-455 patch,
69
- # ohai could also exhaust the available file descriptors when creating this
70
- # many zombie processes. A regression _could_ cause Errno::EMFILE but this
71
- # probably won't be consistent on different environments.
72
- created_procs = 0
73
- 100.times do
74
- begin
75
- Ohai::Mixin::Command.popen4("/bin/this-is-not-a-real-command") { |p, i, o, e| nil }
76
- rescue Ohai::Exceptions::Exec
77
- created_procs += 1
78
- end
79
- end
80
- expect(created_procs).to eq(100)
81
- reaped_procs = 0
82
- begin
83
- loop { Process.wait(-1); reaped_procs += 1 }
84
- rescue Errno::ECHILD
85
- end
86
- expect(reaped_procs).to eq(0)
87
- end
88
- end
20
+ require_relative "../../spec_helper.rb"
89
21
 
90
22
  describe Ohai::Mixin::Command, "shell_out" do
91
23
  let(:cmd) { "sparkle-dream --version" }
@@ -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
  require "ohai/mixin/ec2_metadata"
21
21
 
22
22
  describe Ohai::Mixin::Ec2Metadata do
@@ -17,7 +17,7 @@
17
17
  # See the License for the specific language governing permissions and
18
18
  # limitations under the License.
19
19
 
20
- require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb")
20
+ require_relative "../../spec_helper.rb"
21
21
  require "ohai/mixin/softlayer_metadata"
22
22
 
23
23
  describe ::Ohai::Mixin::SoftlayerMetadata do
@@ -16,7 +16,6 @@
16
16
  #
17
17
 
18
18
  require_relative "../spec_helper"
19
-
20
19
  require "ohai/plugin_config"
21
20
 
22
21
  describe "Ohai::PluginConfig" do
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb"))
19
+ require_relative "../../spec_helper.rb"
20
20
 
21
21
  tmp = ENV["TMPDIR"] || ENV["TMP"] || ENV["TEMP"] || "/tmp"
22
22
 
@@ -16,7 +16,7 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
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, "AIX cpu plugin" do
22
22
  before(:each) do
@@ -15,7 +15,8 @@
15
15
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
18
- require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
18
+
19
+ require_relative "../../../spec_helper.rb"
19
20
 
20
21
  describe Ohai::System, "AIX filesystem plugin" do
21
22
  before(:each) do
@@ -16,7 +16,7 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
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, "AIX hostname plugin" do
22
22
  before(:each) do
@@ -16,7 +16,7 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
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, "AIX 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, "AIX memory plugin" do
22
22
  before(:each) do
@@ -16,7 +16,7 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
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, "AIX network plugin" do
22
22
 
@@ -15,7 +15,7 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
18
+ require_relative "../../../spec_helper.rb"
19
19
 
20
20
  describe Ohai::System, "AIX os plugin" do
21
21
  before(:each) do
@@ -16,7 +16,7 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
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, "Aix plugin platform" do
22
22
  before(:each) do
@@ -16,7 +16,7 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
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, "Aix plugin uptime" do
22
22
 
@@ -16,7 +16,7 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
18
18
 
19
- require "spec_helper"
19
+ require_relative "../../../spec_helper.rb"
20
20
 
21
21
  describe Ohai::System, "AIX virtualization plugin" do
22
22
 
@@ -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
  require "open-uri"
21
21
 
22
22
  describe Ohai::System, "plugin azure" do
@@ -17,7 +17,7 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
20
+ require_relative "../../../spec_helper.rb"
21
21
 
22
22
  describe Ohai::System, "BSD filesystem plugin" do
23
23
  let(:plugin) { get_plugin("bsd/filesystem") }
@@ -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, "BSD virtualization 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.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb"))
19
+ require_relative "../../spec_helper.rb"
20
20
 
21
21
  C_GCC = <<EOF
22
22
  Using built-in specs.
@@ -19,8 +19,7 @@
19
19
  #
20
20
 
21
21
  begin
22
- require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb")
23
-
22
+ require_relative "../../spec_helper.rb"
24
23
  require "chef/version"
25
24
 
26
25
  describe Ohai::System, "plugin chef" do
@@ -15,7 +15,62 @@
15
15
  # limitations under the License.
16
16
  #
17
17
 
18
- require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb")
18
+ require_relative "../../spec_helper.rb"
19
+ require "ipaddr"
20
+
21
+ describe "CloudAttrs object" do
22
+ before(:each) do
23
+ @plugin = get_plugin("cloud")
24
+ end
25
+
26
+ let(:cloud_node) do
27
+ { "public_ipv4_addrs" => ["1.2.3.1"],
28
+ "local_ipv4_addrs" => ["1.2.4.1"],
29
+ "public_ipv6_addrs" => ["3ffe:505:2::1"],
30
+ "local_ipv6_addrs" => ["3ffe:506:2::1"],
31
+ "public_ipv4" => "1.2.3.1",
32
+ "local_ipv4" => "1.2.4.1",
33
+ "public_ipv6" => "3ffe:505:2::1",
34
+ "local_ipv6" => "3ffe:506:2::1",
35
+ "public_hostname" => "myhost.somewhere.com",
36
+ "local_hostname" => "my-localhost",
37
+ "provider" => "my_awesome_cloud",
38
+ }
39
+ end
40
+
41
+ it "populates cloud mash" do
42
+ @cloud_attr_obj = ::CloudAttrs.new()
43
+ @cloud_attr_obj.add_ipv4_addr("1.2.3.1", :public)
44
+ @cloud_attr_obj.add_ipv4_addr("1.2.4.1", :private)
45
+ @cloud_attr_obj.add_ipv6_addr("3ffe:505:2::1", :public)
46
+ @cloud_attr_obj.add_ipv6_addr("3ffe:506:2::1", :private)
47
+ @cloud_attr_obj.public_hostname = "myhost.somewhere.com"
48
+ @cloud_attr_obj.local_hostname = "my-localhost"
49
+ @cloud_attr_obj.provider = "my_awesome_cloud"
50
+ expect(@cloud_attr_obj.cloud_mash).to eq(cloud_node)
51
+ end
52
+
53
+ it "throws exception with a bad ipv4 address" do
54
+ @cloud_attr_obj = ::CloudAttrs.new()
55
+ expect { @cloud_attr_obj.add_ipv6_addr("somebogusstring", :public) }.to raise_error(RuntimeError)
56
+ end
57
+
58
+ it "throws exception with a bad ipv6 address" do
59
+ @cloud_attr_obj = ::CloudAttrs.new()
60
+ expect { @cloud_attr_obj.add_ipv6_addr("FEED:B0B:DEAD:BEEF", :public) }.to raise_error(RuntimeError)
61
+ end
62
+
63
+ it "throws exception with ipv6 address passed to ipv4" do
64
+ @cloud_attr_obj = ::CloudAttrs.new()
65
+ expect { @cloud_attr_obj.add_ipv4_addr("3ffe:506:2::1", :public) }.to raise_error(RuntimeError)
66
+ end
67
+
68
+ it "throws exception with ipv4 address passed to ipv6" do
69
+ @cloud_attr_obj = ::CloudAttrs.new()
70
+ expect { @cloud_attr_obj.add_ipv6_addr("1.2.3.4", :public) }.to raise_error(RuntimeError)
71
+ end
72
+
73
+ end
19
74
 
20
75
  describe Ohai::System, "plugin cloud" do
21
76
  before(:each) do
@@ -29,27 +84,40 @@ describe Ohai::System, "plugin cloud" do
29
84
  @plugin[:eucalyptus] = nil
30
85
  @plugin[:linode] = nil
31
86
  @plugin[:azure] = nil
87
+ @plugin[:gce] = nil
32
88
  @plugin[:digital_ocean] = nil
33
89
  @plugin.run
34
90
  expect(@plugin[:cloud]).to be_nil
91
+ expect(@plugin[:cloud_v2]).to be_nil
92
+ end
93
+ end
94
+
95
+ describe "with a cloud mash" do
96
+ before do
97
+ @plugin[:ec2] = Mash.new
98
+ end
99
+
100
+ it "populates cloud public ip" do
101
+ @plugin.run
102
+ expect(@plugin[:cloud]).to eq(@plugin[:cloud_v2])
35
103
  end
36
104
  end
37
105
 
38
106
  describe "with EC2 mash" do
39
107
  before do
40
- @plugin[:ec2] = Mash.new()
108
+ @plugin[:ec2] = Mash.new
41
109
  end
42
110
 
43
111
  it "populates cloud public ip" do
44
112
  @plugin[:ec2]["public_ipv4"] = "174.129.150.8"
45
113
  @plugin.run
46
- expect(@plugin[:cloud][:public_ips][0]).to eq(@plugin[:ec2]["public_ipv4"])
114
+ expect(@plugin[:cloud][:public_ipv4_addrs][0]).to eq(@plugin[:ec2]["public_ipv4"])
47
115
  end
48
116
 
49
117
  it "populates cloud private ip" do
50
118
  @plugin[:ec2]["local_ipv4"] = "10.252.42.149"
51
119
  @plugin.run
52
- expect(@plugin[:cloud][:private_ips][0]).to eq(@plugin[:ec2]["local_ipv4"])
120
+ expect(@plugin[:cloud][:local_ipv4_addrs][0]).to eq(@plugin[:ec2]["local_ipv4"])
53
121
  end
54
122
 
55
123
  it "populates cloud provider" do
@@ -58,9 +126,69 @@ describe Ohai::System, "plugin cloud" do
58
126
  end
59
127
  end
60
128
 
129
+ describe "with GCE mash" do
130
+ describe "with a public IP" do
131
+ before do
132
+ @plugin[:gce] = Mash.new
133
+ @plugin[:gce]["instance"] = Mash.new
134
+ @plugin[:gce]["instance"]["networkInterfaces"] = [
135
+ {
136
+ "accessConfigs" => [ { "externalIp" => "8.35.198.173", "type" => "ONE_TO_ONE_NAT" } ],
137
+ "ip" => "10.240.0.102",
138
+ "network" => "projects/foo/networks/default",
139
+ },
140
+ ]
141
+ end
142
+
143
+ it "populates cloud public ip" do
144
+ @plugin.run
145
+ expect(@plugin[:cloud][:public_ipv4_addrs][0]).to eq("8.35.198.173")
146
+ end
147
+
148
+ it "populates cloud private ip" do
149
+ @plugin.run
150
+ expect(@plugin[:cloud][:local_ipv4_addrs][0]).to eq("10.240.0.102")
151
+ end
152
+
153
+ it "populates cloud provider" do
154
+ @plugin.run
155
+ expect(@plugin[:cloud][:provider]).to eq("gce")
156
+ end
157
+ end
158
+
159
+ describe "with no public IP" do
160
+ before do
161
+ @plugin[:gce] = Mash.new
162
+ @plugin[:gce]["instance"] = Mash.new
163
+ @plugin[:gce]["instance"]["networkInterfaces"] = [
164
+ {
165
+ "accessConfigs" => [ { "externalIp" => "", "type" => "ONE_TO_ONE_NAT" } ],
166
+ "ip" => "10.240.0.102",
167
+ "network" => "projects/foo/networks/default",
168
+ },
169
+ ]
170
+ end
171
+
172
+ it "does not populate cloud public ip" do
173
+ @plugin.run
174
+ expect(@plugin[:cloud][:public_ipv4_addrs]).to be_nil
175
+ end
176
+
177
+ it "populates cloud private ip" do
178
+ @plugin.run
179
+ expect(@plugin[:cloud][:local_ipv4_addrs][0]).to eq("10.240.0.102")
180
+ end
181
+
182
+ it "populates cloud provider" do
183
+ @plugin.run
184
+ expect(@plugin[:cloud][:provider]).to eq("gce")
185
+ end
186
+ end
187
+ end
188
+
61
189
  describe "with rackspace" do
62
190
  before do
63
- @plugin[:rackspace] = Mash.new()
191
+ @plugin[:rackspace] = Mash.new
64
192
  end
65
193
 
66
194
  it "populates cloud public ip" do
@@ -90,13 +218,13 @@ describe Ohai::System, "plugin cloud" do
90
218
  it "populates first cloud public ip" do
91
219
  @plugin[:rackspace][:public_ipv4] = "174.129.150.8"
92
220
  @plugin.run
93
- expect(@plugin[:cloud][:public_ips].first).to eq(@plugin[:rackspace][:public_ipv4])
221
+ expect(@plugin[:cloud][:public_ipv4_addrs].first).to eq(@plugin[:rackspace][:public_ipv4])
94
222
  end
95
223
 
96
224
  it "populates first cloud public ip" do
97
225
  @plugin[:rackspace][:local_ipv4] = "174.129.150.8"
98
226
  @plugin.run
99
- expect(@plugin[:cloud][:private_ips].first).to eq(@plugin[:rackspace][:local_ipv4])
227
+ expect(@plugin[:cloud][:local_ipv4_addrs].first).to eq(@plugin[:rackspace][:local_ipv4])
100
228
  end
101
229
 
102
230
  it "populates cloud provider" do
@@ -107,25 +235,25 @@ describe Ohai::System, "plugin cloud" do
107
235
 
108
236
  describe "with linode mash" do
109
237
  before do
110
- @plugin[:linode] = Mash.new()
238
+ @plugin[:linode] = Mash.new
111
239
  end
112
240
 
113
241
  it "populates cloud public ip" do
114
242
  @plugin[:linode]["public_ip"] = "174.129.150.8"
115
243
  @plugin.run
116
- expect(@plugin[:cloud][:public_ips][0]).to eq(@plugin[:linode][:public_ip])
244
+ expect(@plugin[:cloud][:public_ipv4_addrs][0]).to eq(@plugin[:linode][:public_ip])
117
245
  end
118
246
 
119
247
  it "populates cloud private ip" do
120
248
  @plugin[:linode]["private_ip"] = "10.252.42.149"
121
249
  @plugin.run
122
- expect(@plugin[:cloud][:private_ips][0]).to eq(@plugin[:linode][:private_ip])
250
+ expect(@plugin[:cloud][:local_ipv4_addrs][0]).to eq(@plugin[:linode][:private_ip])
123
251
  end
124
252
 
125
253
  it "populates first cloud public ip" do
126
254
  @plugin[:linode]["public_ip"] = "174.129.150.8"
127
255
  @plugin.run
128
- expect(@plugin[:cloud][:public_ips].first).to eq(@plugin[:linode][:public_ip])
256
+ expect(@plugin[:cloud][:public_ipv4_addrs].first).to eq(@plugin[:linode][:public_ip])
129
257
  end
130
258
 
131
259
  it "populates cloud provider" do
@@ -136,19 +264,19 @@ describe Ohai::System, "plugin cloud" do
136
264
 
137
265
  describe "with eucalyptus mash" do
138
266
  before do
139
- @plugin[:eucalyptus] = Mash.new()
267
+ @plugin[:eucalyptus] = Mash.new
140
268
  end
141
269
 
142
270
  it "populates cloud public ip" do
143
271
  @plugin[:eucalyptus]["public_ipv4"] = "174.129.150.8"
144
272
  @plugin.run
145
- expect(@plugin[:cloud][:public_ips][0]).to eq(@plugin[:eucalyptus]["public_ipv4"])
273
+ expect(@plugin[:cloud][:public_ipv4_addrs][0]).to eq(@plugin[:eucalyptus]["public_ipv4"])
146
274
  end
147
275
 
148
276
  it "populates cloud private ip" do
149
277
  @plugin[:eucalyptus]["local_ipv4"] = "10.252.42.149"
150
278
  @plugin.run
151
- expect(@plugin[:cloud][:private_ips][0]).to eq(@plugin[:eucalyptus]["local_ipv4"])
279
+ expect(@plugin[:cloud][:local_ipv4_addrs][0]).to eq(@plugin[:eucalyptus]["local_ipv4"])
152
280
  end
153
281
 
154
282
  it "populates cloud provider" do
@@ -159,39 +287,31 @@ describe Ohai::System, "plugin cloud" do
159
287
 
160
288
  describe "with Azure mash" do
161
289
  before do
162
- @plugin[:azure] = Mash.new()
163
- end
164
-
165
- it "populates cloud private ip" do
166
- @plugin[:azure]["private_ip"] = "10.0.0.1"
167
- @plugin.run
168
- expect(@plugin[:cloud][:private_ips][0]).to eq(@plugin[:azure]["private_ip"])
290
+ @plugin[:azure] = Mash.new
169
291
  end
170
292
 
171
293
  it "populates cloud public ip" do
172
294
  @plugin[:azure]["public_ip"] = "174.129.150.8"
173
295
  @plugin.run
174
- expect(@plugin[:cloud][:public_ips][0]).to eq(@plugin[:azure]["public_ip"])
175
- expect(@plugin[:cloud][:public_ipv4]).to eq(@plugin[:azure]["public_ip"])
296
+ expect(@plugin[:cloud][:public_ipv4_addrs][0]).to eq(@plugin[:azure]["public_ip"])
176
297
  end
177
298
 
178
- it "populates cloud vm_name" do
299
+ it "doesn't populates cloud vm_name" do
179
300
  @plugin[:azure]["vm_name"] = "linux-vm"
180
301
  @plugin.run
181
- expect(@plugin[:cloud][:vm_name]).to eq(@plugin[:azure]["vm_name"])
302
+ expect(@plugin[:cloud][:vm_name]).not_to eq(@plugin[:azure]["vm_name"])
182
303
  end
183
304
 
184
- it "populates cloud public_fqdn" do
305
+ it "populates cloud public_hostname" do
185
306
  @plugin[:azure]["public_fqdn"] = "linux-vm-svc.cloudapp.net"
186
307
  @plugin.run
187
- expect(@plugin[:cloud][:public_fqdn]).to eq(@plugin[:azure]["public_fqdn"])
188
308
  expect(@plugin[:cloud][:public_hostname]).to eq(@plugin[:azure]["public_fqdn"])
189
309
  end
190
310
 
191
- it "populates cloud public_ssh_port" do
311
+ it "doesn't populate cloud public_ssh_port" do
192
312
  @plugin[:azure]["public_ssh_port"] = "22"
193
313
  @plugin.run
194
- expect(@plugin[:cloud][:public_ssh_port]).to eq(@plugin[:azure]["public_ssh_port"])
314
+ expect(@plugin[:cloud][:public_ssh_port]).to be_nil
195
315
  end
196
316
 
197
317
  it "should not populate cloud public_ssh_port when winrm is used" do
@@ -203,7 +323,7 @@ describe Ohai::System, "plugin cloud" do
203
323
  it "populates cloud public_winrm_port" do
204
324
  @plugin[:azure]["public_winrm_port"] = "5985"
205
325
  @plugin.run
206
- expect(@plugin[:cloud][:public_winrm_port]).to eq(@plugin[:azure]["public_winrm_port"])
326
+ expect(@plugin[:cloud][:public_winrm_port]).to be_nil
207
327
  end
208
328
 
209
329
  it "populates cloud provider" do
@@ -215,54 +335,94 @@ describe Ohai::System, "plugin cloud" do
215
335
  describe "with digital_ocean mash" do
216
336
  before do
217
337
  @plugin[:digital_ocean] = Mash.new
218
- @plugin[:digital_ocean][:name] = "public.example.com"
219
- @plugin[:digital_ocean][:networks] = Mash.new
220
- @plugin[:digital_ocean][:networks][:v4] = [{ "ip_address" => "1.2.3.4", "type" => "public" },
221
- { "ip_address" => "5.6.7.8", "type" => "private" }]
222
- @plugin[:digital_ocean][:networks][:v6] = [{ "ip_address" => "fe80::4240:95ff:fe47:6eee", "type" => "public" },
223
- { "ip_address" => "fdf8:f53b:82e4::53", "type" => "private" }]
338
+ @plugin[:digital_ocean][:interfaces] = Mash.new
339
+ @plugin[:digital_ocean][:interfaces] = {
340
+ "private" =>
341
+ [
342
+ {
343
+ "ipv4" =>
344
+ {
345
+ "ip_address" => "10.135.32.4",
346
+ "netmask" => "255.255.0.0",
347
+ "gateway" => "10.135.0.1",
348
+ },
349
+ "mac" => "36:9e:23:65:c1:fe",
350
+ "type" => "private",
351
+ },
352
+ ],
353
+ "public" =>
354
+ [
355
+ {
356
+ "ipv4" =>
357
+ {
358
+ "ip_address" => "207.154.221.42",
359
+ "netmask" => "255.255.240.0",
360
+ "gateway" => "207.154.208.1",
361
+ },
362
+ "ipv6" =>
363
+ {
364
+ "ip_address" => "2A03:B0C0:0003:00D0:0000:0000:3B15:B001",
365
+ "cidr" => 64,
366
+ "gateway" => "2A03:B0C0:0003:00D0:0000:0000:0000:0001",
367
+ },
368
+ "anchor_ipv4" =>
369
+ {
370
+ "ip_address" => "10.19.0.5",
371
+ "netmask" => "255.255.0.0",
372
+ "gateway" => "10.19.0.1",
373
+ },
374
+ "mac" => "9a:80:15:02:7a:c1",
375
+ "type" => "public",
376
+ },
377
+ ],
378
+ }
224
379
  end
225
380
 
226
381
  before(:each) do
227
382
  @plugin.run
228
383
  end
229
384
 
230
- it "populates cloud public hostname" do
231
- expect(@plugin[:cloud][:public_hostname]).to eq("public.example.com")
232
- end
233
-
234
385
  it "populates cloud local hostname" do
235
386
  expect(@plugin[:cloud][:local_hostname]).to be_nil
236
387
  end
237
388
 
238
- it "populates cloud public ips" do
239
- expect(@plugin[:cloud][:public_ips]).to eq(@plugin[:digital_ocean][:networks][:v4].select { |ip| ip["type"] == "public" } +
240
- @plugin[:digital_ocean][:networks][:v6].select { |ip| ip["type"] == "public" })
389
+ it "populates cloud public_ipv4_addrs" do
390
+ expect(@plugin[:cloud][:public_ipv4_addrs]).to eq(["207.154.221.42"])
391
+
241
392
  end
242
393
 
243
- it "populates cloud private ips" do
244
- expect(@plugin[:cloud][:private_ips]).to eq(@plugin[:digital_ocean][:networks][:v4].select { |ip| ip["type"] == "private" } +
245
- @plugin[:digital_ocean][:networks][:v6].select { |ip| ip["type"] == "private" })
394
+ it "populates cloud local_ipv4_addrs" do
395
+ expect(@plugin[:cloud][:local_ipv4_addrs]).to eq(["10.135.32.4"])
396
+
246
397
  end
247
398
 
248
399
  it "populates cloud public_ipv4" do
249
- expect(@plugin[:cloud][:public_ipv4]).to eq(@plugin[:digital_ocean][:networks][:v4].find { |ip| ip["type"] == "public" })
400
+ expect(@plugin[:cloud][:public_ipv4]).to eq("207.154.221.42")
250
401
  end
251
402
 
252
403
  it "populates cloud local_ipv4" do
253
- expect(@plugin[:cloud][:local_ipv4]).to eq(@plugin[:digital_ocean][:networks][:v4].find { |ip| ip["type"] == "private" })
404
+ expect(@plugin[:cloud][:local_ipv4]).to eq("10.135.32.4")
405
+ end
406
+
407
+ it "populates cloud public_ipv6_addrs" do
408
+ expect(@plugin[:cloud][:public_ipv6_addrs]).to eq(["2a03:b0c0:3:d0::3b15:b001"])
409
+ end
410
+
411
+ it "populates cloud local_ipv6_addrs" do
412
+ expect(@plugin[:cloud][:local_ipv6_addrs]).to be_nil
254
413
  end
255
414
 
256
415
  it "populates cloud public_ipv6" do
257
- expect(@plugin[:cloud][:public_ipv6]).to eq(@plugin[:digital_ocean][:networks][:v6].find { |ip| ip["type"] == "public" })
416
+ expect(@plugin[:cloud][:public_ipv6]).to eq("2a03:b0c0:3:d0::3b15:b001")
258
417
  end
259
418
 
260
419
  it "populates cloud local_ipv6" do
261
- expect(@plugin[:cloud][:local_ipv6]).to eq(@plugin[:digital_ocean][:networks][:v6].find { |ip| ip["type"] == "private" })
420
+ expect(@plugin[:cloud][:local_ipv6]).to be_nil
262
421
  end
263
422
 
264
423
  it "populates cloud provider" do
265
424
  expect(@plugin[:cloud][:provider]).to eq("digital_ocean")
266
425
  end
267
426
  end
427
+
268
428
  end