ohai 8.22.1 → 8.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ohai/application.rb +2 -0
  3. data/lib/ohai/mixin/dmi_decode.rb +2 -0
  4. data/lib/ohai/mixin/ec2_metadata.rb +14 -0
  5. data/lib/ohai/plugins/azure.rb +5 -5
  6. data/lib/ohai/plugins/c.rb +118 -46
  7. data/lib/ohai/plugins/cloud.rb +1 -0
  8. data/lib/ohai/plugins/dmi.rb +5 -5
  9. data/lib/ohai/plugins/ec2.rb +1 -0
  10. data/lib/ohai/plugins/erlang.rb +3 -5
  11. data/lib/ohai/plugins/groovy.rb +1 -1
  12. data/lib/ohai/plugins/haskell.rb +4 -4
  13. data/lib/ohai/plugins/hostname.rb +6 -6
  14. data/lib/ohai/plugins/ip_scopes.rb +1 -1
  15. data/lib/ohai/plugins/linux/network.rb +15 -15
  16. data/lib/ohai/plugins/linux/platform.rb +82 -43
  17. data/lib/ohai/plugins/linux/sessions.rb +2 -0
  18. data/lib/ohai/plugins/linux/virtualization.rb +18 -0
  19. data/lib/ohai/plugins/lua.rb +1 -1
  20. data/lib/ohai/plugins/network.rb +10 -10
  21. data/lib/ohai/plugins/scala.rb +2 -2
  22. data/lib/ohai/plugins/solaris2/dmi.rb +5 -5
  23. data/lib/ohai/plugins/sysconf.rb +45 -0
  24. data/lib/ohai/plugins/virtualbox.rb +22 -17
  25. data/lib/ohai/plugins/vmware.rb +2 -2
  26. data/lib/ohai/plugins/windows/virtualization.rb +14 -0
  27. data/lib/ohai/system.rb +0 -4
  28. data/lib/ohai/util/file_helper.rb +2 -2
  29. data/lib/ohai/version.rb +1 -1
  30. data/spec/unit/plugins/c_spec.rb +299 -266
  31. data/spec/unit/plugins/cloud_spec.rb +6 -0
  32. data/spec/unit/plugins/ec2_spec.rb +45 -1
  33. data/spec/unit/plugins/erlang_spec.rb +5 -5
  34. data/spec/unit/plugins/linux/network_spec.rb +1 -1
  35. data/spec/unit/plugins/linux/platform_spec.rb +43 -1
  36. data/spec/unit/plugins/linux/virtualization_spec.rb +19 -0
  37. data/spec/unit/plugins/network_spec.rb +23 -23
  38. data/spec/unit/plugins/sysconf_spec.rb +679 -0
  39. data/spec/unit/plugins/windows/virtualization_spec.rb +67 -0
  40. data/spec/unit/system_spec.rb +0 -1
  41. metadata +5 -3
@@ -28,7 +28,7 @@ Ohai.plugin(:Scala) do
28
28
  scala[:version] = so.stderr.split[4]
29
29
  end
30
30
  rescue Ohai::Exceptions::Exec
31
- Ohai::Log.debug('Scala plugin: Could not shell_out "scala -version". Skipping data')
31
+ Ohai::Log.debug('Plugin Scala: Could not shell_out "scala -version". Skipping data')
32
32
  end
33
33
 
34
34
  # Check for sbt
@@ -40,7 +40,7 @@ Ohai.plugin(:Scala) do
40
40
  scala[:sbt][:version] = so.stdout.split[3]
41
41
  end
42
42
  rescue Ohai::Exceptions::Exec
43
- Ohai::Log.debug('Scala plugin: Could not shell_out "sbt --version". Skipping data')
43
+ Ohai::Log.debug('Plugin Scala: Could not shell_out "sbt --version". Skipping data')
44
44
  end
45
45
 
46
46
  languages[:scala] = scala unless scala.empty?
@@ -153,7 +153,7 @@ Ohai.plugin(:DMI) do
153
153
 
154
154
  elsif data = data_key_value_line.match(line)
155
155
  if dmi_record == nil
156
- Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}")
156
+ Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}")
157
157
  next
158
158
  end
159
159
  dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = data[2]
@@ -161,7 +161,7 @@ Ohai.plugin(:DMI) do
161
161
 
162
162
  elsif data = data_key_only_line.match(line)
163
163
  if dmi_record == nil
164
- Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}")
164
+ Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}")
165
165
  next
166
166
  end
167
167
  dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = ""
@@ -169,11 +169,11 @@ Ohai.plugin(:DMI) do
169
169
 
170
170
  elsif extended_data = extended_data_line.match(line)
171
171
  if dmi_record == nil
172
- Ohai::Log.debug("unexpected extended data line found before header; discarding:\n#{line}")
172
+ Ohai::Log.debug("Plugin DMI: unexpected extended data line found before header; discarding:\n#{line}")
173
173
  next
174
174
  end
175
175
  if field == nil
176
- Ohai::Log.debug("unexpected extended data line found outside data section; discarding:\n#{line}")
176
+ Ohai::Log.debug("Plugin DMI: unexpected extended data line found outside data section; discarding:\n#{line}")
177
177
  next
178
178
  end
179
179
  # overwrite "raw" value with a new Mash
@@ -181,7 +181,7 @@ Ohai.plugin(:DMI) do
181
181
  dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field][extended_data[1]] = extended_data[2]
182
182
 
183
183
  else
184
- Ohai::Log.debug("unrecognized output line; discarding:\n#{line}")
184
+ Ohai::Log.debug("Plugin DMI: unrecognized output line; discarding:\n#{line}")
185
185
 
186
186
  end
187
187
  end
@@ -0,0 +1,45 @@
1
+ #
2
+ # Author:: Davide Cavalca <dcavalca@fb.com>
3
+ # Copyright:: Copyright (c) 2016 Facebook
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
+ Ohai.plugin(:Sysconf) do
20
+ provides "sysconf"
21
+
22
+ collect_data(:aix, :linux, :solaris2) do
23
+ getconf_path = which("getconf")
24
+ if getconf_path
25
+ getconf = shell_out("#{getconf_path} -a")
26
+
27
+ if getconf.exitstatus == 0
28
+ sysconf Mash.new unless sysconf
29
+
30
+ getconf.stdout.split("\n").each do |line|
31
+ key, val = /^(\S+)\s*(.*)?$/.match(line).captures
32
+ if val && !val.empty?
33
+ begin
34
+ sysconf[key] = Integer(val)
35
+ rescue
36
+ sysconf[key] = val
37
+ end
38
+ else
39
+ sysconf[key] = nil
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -20,25 +20,30 @@ Ohai.plugin(:Virtualbox) do
20
20
  provides "virtualbox"
21
21
 
22
22
  collect_data do
23
- so = shell_out("VBoxControl guestproperty enumerate")
24
- if so.exitstatus == 0
25
- virtualbox Mash.new
26
- virtualbox[:host] = Mash.new
27
- virtualbox[:guest] = Mash.new
28
- so.stdout.lines.each do |line|
29
- case line
30
- when /LanguageID, value: (\S*),/
31
- virtualbox[:host][:language] = Regexp.last_match(1)
32
- when /VBoxVer, value: (\S*),/
33
- virtualbox[:host][:version] = Regexp.last_match(1)
34
- when /VBoxRev, value: (\S*),/
35
- virtualbox[:host][:revision] = Regexp.last_match(1)
36
- when /GuestAdd\/VersionExt, value: (\S*),/
37
- virtualbox[:guest][:guest_additions_version] = Regexp.last_match(1)
38
- when /GuestAdd\/Revision, value: (\S*),/
39
- virtualbox[:guest][:guest_additions_revision] = Regexp.last_match(1)
23
+ begin
24
+ so = shell_out("VBoxControl guestproperty enumerate")
25
+
26
+ if so.exitstatus == 0
27
+ virtualbox Mash.new
28
+ virtualbox[:host] = Mash.new
29
+ virtualbox[:guest] = Mash.new
30
+ so.stdout.lines.each do |line|
31
+ case line
32
+ when /LanguageID, value: (\S*),/
33
+ virtualbox[:host][:language] = Regexp.last_match(1)
34
+ when /VBoxVer, value: (\S*),/
35
+ virtualbox[:host][:version] = Regexp.last_match(1)
36
+ when /VBoxRev, value: (\S*),/
37
+ virtualbox[:host][:revision] = Regexp.last_match(1)
38
+ when /GuestAdd\/VersionExt, value: (\S*),/
39
+ virtualbox[:guest][:guest_additions_version] = Regexp.last_match(1)
40
+ when /GuestAdd\/Revision, value: (\S*),/
41
+ virtualbox[:guest][:guest_additions_revision] = Regexp.last_match(1)
42
+ end
40
43
  end
41
44
  end
45
+ rescue Ohai::Exceptions::Exec
46
+ Ohai::Log.debug('Plugin Virtualbox: Could not execute "VBoxControl guestproperty enumerate". Skipping data')
42
47
  end
43
48
  end
44
49
  end
@@ -42,7 +42,7 @@ Ohai.plugin(:VMware) do
42
42
 
43
43
  def get_vm_attributes(vmtools_path)
44
44
  if !File.exist?(vmtools_path)
45
- Ohai::Log.debug("#{vmtools_path} not found")
45
+ Ohai::Log.debug("Plugin VMware: #{vmtools_path} not found")
46
46
  else
47
47
  vmware Mash.new
48
48
  begin
@@ -62,7 +62,7 @@ Ohai.plugin(:VMware) do
62
62
  vmware[param] = from_cmd("#{vmtools_path} #{param} status")
63
63
  end
64
64
  rescue
65
- Ohai::Log.debug("Error while collecting VMware guest attributes")
65
+ Ohai::Log.debug("Plugin VMware: Error while collecting VMware guest attributes")
66
66
  end
67
67
  end
68
68
  end
@@ -44,6 +44,20 @@ Ohai.plugin(:Virtualization) do
44
44
  virtualization[:system] = "kvm"
45
45
  virtualization[:role] = "guest"
46
46
  virtualization[:systems][:kvm] = "guest"
47
+ when "American Megatrends Inc."
48
+ if bios[0]["version"] =~ /VRTUAL -/
49
+ virtualization[:system] = "hyper-v"
50
+ virtualization[:role] = "guest"
51
+ virtualization[:systems][:hyperv] = "guest"
52
+ end
53
+ when "Xen"
54
+ virtualization[:system] = "xen"
55
+ virtualization[:role] = "guest"
56
+ virtualization[:systems][:xen] = "guest"
57
+ when "Veertu"
58
+ virtualization[:system] = "veertu"
59
+ virtualization[:role] = "guest"
60
+ virtualization[:systems][:veertu] = "guest"
47
61
  end
48
62
 
49
63
  # vmware fusion detection
@@ -220,10 +220,6 @@ module Ohai
220
220
  end
221
221
 
222
222
  def configure_logging
223
- return if Ohai::Log.configured?
224
-
225
- Ohai::Log.init(Ohai.config[:log_location])
226
-
227
223
  if Ohai.config[:log_level] == :auto
228
224
  Ohai::Log.level = :info
229
225
  else
@@ -26,11 +26,11 @@ module Ohai
26
26
  paths.each do |path|
27
27
  filename = File.join(path, cmd)
28
28
  if File.executable?(filename)
29
- Ohai::Log.debug("#{self.name} plugin: found #{cmd} at #{filename}")
29
+ Ohai::Log.debug("Plugin #{self.name}: found #{cmd} at #{filename}")
30
30
  return filename
31
31
  end
32
32
  end
33
- Ohai::Log.debug("#{self.name} plugin: did not find #{cmd}")
33
+ Ohai::Log.debug("Plugin #{self.name}: did not find #{cmd}")
34
34
  false
35
35
  end
36
36
  end
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = "8.22.1"
21
+ VERSION = "8.23.0"
22
22
  end
@@ -16,41 +16,19 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "rbconfig"
20
-
21
19
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb"))
22
20
 
23
21
  C_GCC = <<EOF
24
- Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
25
- Configured with: ../configure --prefix=/usr ... --host=x86_64-redhat-linux
22
+ Using built-in specs.
23
+ COLLECT_GCC=gcc
24
+ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
25
+ Target: x86_64-linux-gnu
26
+ Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
26
27
  Thread model: posix
27
- gcc version 3.4.6 20060404 (Red Hat 3.4.6-3)
28
- EOF
29
-
30
- C_GLIBC_2_3_4 = <<EOF
31
- GNU C Library stable release version 2.3.4, by Roland McGrath et al.
32
- Copyright (C) 2005 Free Software Foundation, Inc.
33
- This is free software; see the source for copying conditions.
34
- There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
35
- PARTICULAR PURPOSE.
36
- Compiled by GNU CC version 3.4.6 20060404 (Red Hat 3.4.6-3).
37
- Compiled on a Linux 2.4.20 system on 2006-08-12.
38
- Available extensions:
39
- GNU libio by Per Bothner
40
- crypt add-on version 2.1 by Michael Glad and others
41
- linuxthreads-0.10 by Xavier Leroy
42
- The C stubs add-on version 2.1.2.
43
- BIND-8.2.3-T5B
44
- NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
45
- Glibc-2.0 compatibility add-on by Cristian Gafton
46
- GNU Libidn by Simon Josefsson
47
- libthread_db work sponsored by Alpha Processor Inc
48
- Thread-local storage support included.
49
- For bug reporting instructions, please see:
50
- <http://www.gnu.org/software/libc/bugs.html>.
28
+ gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
51
29
  EOF
52
30
 
53
- C_GLIBC_2_5 = <<EOF
31
+ C_GLIBC = <<EOF
54
32
  GNU C Library stable release version 2.5, by Roland McGrath et al.
55
33
  Copyright (C) 2006 Free Software Foundation, Inc.
56
34
  This is free software; see the source for copying conditions.
@@ -109,251 +87,306 @@ describe Ohai::System, "plugin c" do
109
87
  plugin[:languages] = Mash.new
110
88
  #gcc
111
89
  allow(plugin).to receive(:shell_out).with("gcc -v").and_return(mock_shell_out(0, "", C_GCC))
112
- #glibc
113
- allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC_2_3_4, ""))
114
- #ms cl
115
- allow(plugin).to receive(:shell_out).with("cl /\?").and_return(mock_shell_out(0, "", C_CL))
116
- #ms vs
117
- allow(plugin).to receive(:shell_out).with("devenv.com /\?").and_return(mock_shell_out(0, C_VS, ""))
118
- #ibm xlc
119
- allow(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(0, C_XLC, ""))
120
- #sun pro
121
- allow(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", C_SUN))
122
- #hpux cc
123
- allow(plugin).to receive(:shell_out).with("what /opt/ansic/bin/cc").and_return(mock_shell_out(0, C_HPUX, ""))
124
- end
125
-
126
- #gcc
127
- it "gets the gcc version from running gcc -v" do
128
- expect(plugin).to receive(:shell_out).with("gcc -v").and_return(mock_shell_out(0, "", C_GCC))
129
- plugin.run
130
- end
131
-
132
- it "sets languages[:c][:gcc][:version]" do
133
- plugin.run
134
- expect(plugin.languages[:c][:gcc][:version]).to eql("3.4.6")
135
- end
136
-
137
- it "sets languages[:c][:gcc][:description]" do
138
- plugin.run
139
- expect(plugin.languages[:c][:gcc][:description]).to eql(C_GCC.split($/).last)
140
- end
141
-
142
- it "does not set the languages[:c][:gcc] tree up if gcc command exits nonzero" do
143
- allow(plugin).to receive(:shell_out).with("gcc -v").and_return(mock_shell_out(1, "", ""))
144
- plugin.run
145
- expect(plugin[:languages][:c]).not_to have_key(:gcc)
146
- end
147
-
148
- it "does not set the languages[:c][:gcc] tree up if gcc command fails" do
149
- allow(plugin).to receive(:shell_out).with("gcc -v").and_raise(Ohai::Exceptions::Exec)
150
- plugin.run
151
- expect(plugin[:languages][:c]).not_to have_key(:gcc)
152
- expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
153
- end
154
-
155
- #glibc
156
- it "gets the glibc x.x.x version from running /lib/libc.so.6", :unix_only do
157
- expect(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC_2_3_4, ""))
158
- plugin.run
159
- end
160
-
161
- it "sets languages[:c][:glibc][:version]", :unix_only do
162
- plugin.run
163
- expect(plugin.languages[:c][:glibc][:version]).to eql("2.3.4")
164
- end
165
-
166
- it "sets languages[:c][:glibc][:description]", :unix_only do
167
- plugin.run
168
- expect(plugin.languages[:c][:glibc][:description]).to eql(C_GLIBC_2_3_4.split($/).first)
169
- end
170
-
171
- it "does not set the languages[:c][:glibc] tree up if glibc exits nonzero" do
172
- allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(1, "", ""))
173
- allow(plugin).to receive(:shell_out).with("/lib64/libc.so.6").and_return(mock_shell_out(1, "", ""))
174
- plugin.run
175
- expect(plugin[:languages][:c]).not_to have_key(:glibc)
176
- end
177
-
178
- it "does not set the languages[:c][:glibc] tree up if glibc fails" do
179
- allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_raise(Ohai::Exceptions::Exec)
180
- allow(plugin).to receive(:shell_out).with("/lib64/libc.so.6").and_raise(Ohai::Exceptions::Exec)
181
- plugin.run
182
- expect(plugin[:languages][:c]).not_to have_key(:glibc)
183
- expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
184
- end
185
-
186
- it "gets the glibc x.x version from running /lib/libc.so.6", :unix_only do
187
- allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC_2_5, ""))
188
- expect(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC_2_5, ""))
189
- plugin.run
190
- expect(plugin.languages[:c][:glibc][:version]).to eql("2.5")
191
- end
192
-
193
- #ms cl
194
- it "gets the cl version from running cl /?" do
195
- expect(plugin).to receive(:shell_out).with("cl /\?").and_return(mock_shell_out(0, "", C_CL))
196
- plugin.run
197
- end
198
-
199
- it "sets languages[:c][:cl][:version]" do
200
- plugin.run
201
- expect(plugin.languages[:c][:cl][:version]).to eql("14.00.50727.762")
202
- end
203
-
204
- it "sets languages[:c][:cl][:description]" do
205
- plugin.run
206
- expect(plugin.languages[:c][:cl][:description]).to eql(C_CL.split($/).first)
207
- end
208
-
209
- it "does not set the languages[:c][:cl] tree up if cl command exits nonzero" do
210
- allow(plugin).to receive(:shell_out).with("cl /\?").and_return(mock_shell_out(1, "", ""))
211
- plugin.run
212
- expect(plugin[:languages][:c]).not_to have_key(:cl)
213
- end
214
-
215
- it "does not set the languages[:c][:cl] tree up if cl command fails" do
216
- allow(plugin).to receive(:shell_out).with("cl /\?").and_raise(Ohai::Exceptions::Exec)
217
- plugin.run
218
- expect(plugin[:languages][:c]).not_to have_key(:cl)
219
- expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
220
- end
221
-
222
- #ms vs
223
- it "gets the vs version from running devenv.com /?" do
224
- expect(plugin).to receive(:shell_out).with("devenv.com /\?").and_return(mock_shell_out(0, C_VS, ""))
225
- plugin.run
226
- end
227
-
228
- it "sets languages[:c][:vs][:version]" do
229
- plugin.run
230
- expect(plugin.languages[:c][:vs][:version]).to eql("8.0.50727.762")
231
- end
232
-
233
- it "sets languages[:c][:vs][:description]" do
234
- plugin.run
235
- expect(plugin.languages[:c][:vs][:description]).to eql(C_VS.split($/)[1])
236
- end
237
-
238
- it "does not set the languages[:c][:vs] tree up if devenv command exits nonzero" do
239
- allow(plugin).to receive(:shell_out).with("devenv.com /\?").and_return(mock_shell_out(1, "", ""))
240
- plugin.run
241
- expect(plugin[:languages][:c]).not_to have_key(:vs)
242
- end
243
-
244
- it "does not set the languages[:c][:vs] tree up if devenv command fails" do
245
- allow(plugin).to receive(:shell_out).with("devenv.com /\?").and_raise(Ohai::Exceptions::Exec)
246
- plugin.run
247
- expect(plugin[:languages][:c]).not_to have_key(:vs)
248
- expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
249
- end
250
-
251
- #ibm xlc
252
- it "gets the xlc version from running xlc -qversion" do
253
- expect(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(0, C_XLC, ""))
254
- plugin.run
255
- end
256
-
257
- it "sets languages[:c][:xlc][:version]" do
258
- plugin.run
259
- expect(plugin.languages[:c][:xlc][:version]).to eql("9.0")
260
- end
261
-
262
- it "sets languages[:c][:xlc][:description]" do
263
- plugin.run
264
- expect(plugin.languages[:c][:xlc][:description]).to eql(C_XLC.split($/).first)
265
- end
266
-
267
- it "does not set the languages[:c][:xlc] tree up if xlc command exits nonzero" do
268
- allow(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(1, "", ""))
269
- plugin.run
270
- expect(plugin[:languages][:c]).not_to have_key(:xlc)
271
- end
272
-
273
- it "does not set the languages[:c][:xlc] tree up if xlc command fails" do
274
- allow(plugin).to receive(:shell_out).with("xlc -qversion").and_raise(Ohai::Exceptions::Exec)
275
- plugin.run
276
- expect(plugin[:languages][:c]).not_to have_key(:xlc)
277
- expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
278
90
  end
279
91
 
280
- it "sets the languages[:c][:xlc] tree up if xlc exit status is 249" do
281
- allow(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(63744, "", ""))
282
- plugin.run
283
- expect(plugin[:languages][:c]).not_to have_key(:xlc)
284
- end
285
-
286
- #sun pro
287
- it "gets the cc version from running cc -V -flags" do
288
- expect(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", C_SUN))
289
- plugin.run
290
- end
92
+ context "on AIX" do
93
+ before(:each) do
94
+ allow(plugin).to receive(:collect_os).and_return(:aix)
95
+ allow(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(0, C_XLC, ""))
96
+ end
291
97
 
292
- it "sets languages[:c][:sunpro][:version]" do
293
- plugin.run
294
- expect(plugin.languages[:c][:sunpro][:version]).to eql("5.8")
295
- end
296
-
297
- it "sets languages[:c][:sunpro][:description]" do
298
- plugin.run
299
- expect(plugin.languages[:c][:sunpro][:description]).to eql(C_SUN.chomp)
300
- end
301
-
302
- it "does not set the languages[:c][:sunpro] tree up if cc command exits nonzero" do
303
- allow(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(1, "", ""))
304
- plugin.run
305
- expect(plugin[:languages][:c]).not_to have_key(:sunpro)
306
- end
307
-
308
- it "does not set the languages[:c][:sunpro] tree up if cc command fails" do
309
- allow(plugin).to receive(:shell_out).with("cc -V -flags").and_raise(Ohai::Exceptions::Exec)
310
- plugin.run
311
- expect(plugin[:languages][:c]).not_to have_key(:sunpro)
312
- expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
313
- end
314
-
315
- it "does not set the languages[:c][:sunpro] tree if the corresponding cc command fails on linux" do
316
- fedora_error_message = "cc: error trying to exec 'i686-redhat-linux-gcc--flags': execvp: No such file or directory"
317
-
318
- allow(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", fedora_error_message))
319
- plugin.run
320
- expect(plugin[:languages][:c]).not_to have_key(:sunpro)
321
- end
98
+ #ibm xlc
99
+ it "gets the xlc version from running xlc -qversion" do
100
+ expect(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(0, C_XLC, ""))
101
+ plugin.run
102
+ end
103
+
104
+ it "sets languages[:c][:xlc][:version]" do
105
+ plugin.run
106
+ expect(plugin.languages[:c][:xlc][:version]).to eql("9.0")
107
+ end
108
+
109
+ it "sets languages[:c][:xlc][:description]" do
110
+ plugin.run
111
+ expect(plugin.languages[:c][:xlc][:description]).to eql("IBM XL C/C++ Enterprise Edition for AIX, V9.0")
112
+ end
113
+
114
+ it "does not set the languages[:c][:xlc] tree up if xlc command exits nonzero" do
115
+ allow(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(1, "", ""))
116
+ plugin.run
117
+ expect(plugin[:languages][:c]).not_to have_key(:xlc)
118
+ end
119
+
120
+ it "does not set the languages[:c][:xlc] tree up if xlc command fails" do
121
+ allow(plugin).to receive(:shell_out).with("xlc -qversion").and_raise(Ohai::Exceptions::Exec)
122
+ plugin.run
123
+ expect(plugin[:languages][:c]).not_to have_key(:xlc)
124
+ expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
125
+ end
126
+
127
+ it "sets the languages[:c][:xlc] tree up if xlc exit status is 249" do
128
+ allow(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(63744, "", ""))
129
+ plugin.run
130
+ expect(plugin[:languages][:c]).not_to have_key(:xlc)
131
+ end
132
+
133
+ end
134
+
135
+ context "on HPUX" do
136
+ before(:each) do
137
+ allow(plugin).to receive(:collect_os).and_return(:hpux)
138
+ allow(plugin).to receive(:shell_out).with("what /opt/ansic/bin/cc").and_return(mock_shell_out(0, C_HPUX, ""))
139
+ end
322
140
 
323
- it "does not set the languages[:c][:sunpro] tree if the corresponding cc command fails on hpux" do
324
- hpux_error_message = "cc: warning 901: unknown option: `-flags': use +help for online documentation.\ncc: HP C/aC++ B3910B A.06.25 [Nov 30 2009]"
325
- allow(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", hpux_error_message))
326
- plugin.run
327
- expect(plugin[:languages][:c]).not_to have_key(:sunpro)
328
- end
141
+ #hpux cc
142
+ it "gets the cc version from running what cc" do
143
+ expect(plugin).to receive(:shell_out).with("what /opt/ansic/bin/cc").and_return(mock_shell_out(0, C_HPUX, ""))
144
+ plugin.run
145
+ end
146
+
147
+ it "sets languages[:c][:hpcc][:version]" do
148
+ plugin.run
149
+ expect(plugin.languages[:c][:hpcc][:version]).to eql("B.11.11.16")
150
+ end
151
+
152
+ it "sets languages[:c][:hpcc][:description]" do
153
+ plugin.run
154
+ expect(plugin.languages[:c][:hpcc][:description]).to eql("HP92453-01 B.11.11.16 HP C Compiler")
155
+ end
156
+
157
+ it "does not set the languages[:c][:hpcc] tree up if cc command exits nonzero" do
158
+ allow(plugin).to receive(:shell_out).with("what /opt/ansic/bin/cc").and_return(mock_shell_out(1, "", ""))
159
+ plugin.run
160
+ expect(plugin[:languages][:c]).not_to have_key(:hpcc)
161
+ end
162
+
163
+ it "does not set the languages[:c][:hpcc] tree up if cc command fails" do
164
+ allow(plugin).to receive(:shell_out).with("what /opt/ansic/bin/cc").and_raise(Ohai::Exceptions::Exec)
165
+ plugin.run
166
+ expect(plugin[:languages][:c]).not_to have_key(:hpcc)
167
+ expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
168
+ end
169
+ end
170
+
171
+ context "on Darwin" do
172
+ before(:each) do
173
+ allow(plugin).to receive(:shell_out).with("/usr/bin/xcode-select -p").and_return(mock_shell_out(0, "", ""))
174
+ allow(plugin).to receive(:collect_os).and_return(:darwin)
175
+ end
176
+
177
+ it "shells out to see if xcode is installed" do
178
+ expect(plugin).to receive(:shell_out).with("/usr/bin/xcode-select -p")
179
+ plugin.run
180
+ end
181
+
182
+ it "doesnt shellout to gcc if xcode isn't installed" do
183
+ allow(plugin).to receive(:shell_out).with("/usr/bin/xcode-select -p").and_return(mock_shell_out(1, "", ""))
184
+ expect(plugin).not_to receive(:shell_out).with("gcc -v")
185
+ plugin.run
186
+ end
187
+
188
+ end
189
+
190
+ context "on Windows" do
191
+ before(:each) do
192
+ allow(plugin).to receive(:collect_os).and_return(:windows)
193
+ allow(plugin).to receive(:shell_out).with("cl /\?").and_return(mock_shell_out(0, "", C_CL))
194
+ allow(plugin).to receive(:shell_out).with("devenv.com /\?").and_return(mock_shell_out(0, C_VS, ""))
195
+ end
329
196
 
330
- #hpux cc
331
- it "gets the cc version from running what cc" do
332
- expect(plugin).to receive(:shell_out).with("what /opt/ansic/bin/cc").and_return(mock_shell_out(0, C_HPUX, ""))
333
- plugin.run
334
- end
197
+ #ms cl
198
+ it "gets the cl version from running cl /?" do
199
+ expect(plugin).to receive(:shell_out).with("cl /\?")
200
+ plugin.run
201
+ end
202
+
203
+ it "sets languages[:c][:cl][:version]" do
204
+ plugin.run
205
+ expect(plugin.languages[:c][:cl][:version]).to eql("14.00.50727.762")
206
+ end
207
+
208
+ it "sets languages[:c][:cl][:description]" do
209
+ plugin.run
210
+ expect(plugin.languages[:c][:cl][:description]).to eql("Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86")
211
+ end
212
+
213
+ it "does not set the languages[:c][:cl] tree up if cl command exits nonzero" do
214
+ allow(plugin).to receive(:shell_out).with("cl /\?").and_return(mock_shell_out(1, "", ""))
215
+ plugin.run
216
+ expect(plugin[:languages][:c]).not_to have_key(:cl)
217
+ end
218
+
219
+ it "does not set the languages[:c][:cl] tree up if cl command fails" do
220
+ allow(plugin).to receive(:shell_out).with("cl /\?").and_raise(Ohai::Exceptions::Exec)
221
+ plugin.run
222
+ expect(plugin[:languages][:c]).not_to have_key(:cl)
223
+ expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
224
+ end
335
225
 
336
- it "sets languages[:c][:hpcc][:version]" do
337
- plugin.run
338
- expect(plugin.languages[:c][:hpcc][:version]).to eql("B.11.11.16")
339
- end
226
+ #ms vs
227
+ it "gets the vs version from running devenv.com /?" do
228
+ expect(plugin).to receive(:shell_out).with("devenv.com /\?").and_return(mock_shell_out(0, C_VS, ""))
229
+ plugin.run
230
+ end
231
+
232
+ it "sets languages[:c][:vs][:version]" do
233
+ plugin.run
234
+ expect(plugin.languages[:c][:vs][:version]).to eql("8.0.50727.762")
235
+ end
236
+
237
+ it "sets languages[:c][:vs][:description]" do
238
+ plugin.run
239
+ expect(plugin.languages[:c][:vs][:description]).to eql("Microsoft (R) Visual Studio Version 8.0.50727.762.")
240
+ end
241
+
242
+ it "does not set the languages[:c][:vs] tree up if devenv command exits nonzero" do
243
+ allow(plugin).to receive(:shell_out).with("devenv.com /\?").and_return(mock_shell_out(1, "", ""))
244
+ plugin.run
245
+ expect(plugin[:languages][:c]).not_to have_key(:vs)
246
+ end
247
+
248
+ it "does not set the languages[:c][:vs] tree up if devenv command fails" do
249
+ allow(plugin).to receive(:shell_out).with("devenv.com /\?").and_raise(Ohai::Exceptions::Exec)
250
+ plugin.run
251
+ expect(plugin[:languages][:c]).not_to have_key(:vs)
252
+ expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
253
+ end
254
+ end
255
+
256
+ context "on Linux" do
257
+ before(:each) do
258
+ allow(plugin).to receive(:collect_os).and_return(:linux)
259
+ # glibc
260
+ allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC, ""))
261
+ allow(plugin).to receive(:shell_out).with("/lib64/libc.so.6").and_return(mock_shell_out(0, C_GLIBC, ""))
262
+ #sun pro
263
+ allow(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", C_SUN))
264
+ end
340
265
 
341
- it "sets languages[:c][:hpcc][:description]" do
342
- plugin.run
343
- expect(plugin.languages[:c][:hpcc][:description]).to eql(C_HPUX.split($/)[3].strip)
344
- end
266
+ #gcc
267
+ it "gets the gcc version from running gcc -v" do
268
+ expect(plugin).to receive(:shell_out).with("gcc -v")
269
+ plugin.run
270
+ end
271
+
272
+ it "sets languages[:c][:gcc][:version]" do
273
+ plugin.run
274
+ expect(plugin.languages[:c][:gcc][:version]).to eql("5.4.0")
275
+ end
276
+
277
+ it "sets languages[:c][:gcc][:description]" do
278
+ plugin.run
279
+ expect(plugin.languages[:c][:gcc][:description]).to eql("gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)")
280
+ end
281
+
282
+ it "sets languages[:c][:gcc][:configured_with]" do
283
+ plugin.run
284
+ expect(plugin.languages[:c][:gcc][:configured_with]).to eql("../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu")
285
+ end
286
+
287
+ it "sets languages[:c][:gcc][:target]" do
288
+ plugin.run
289
+ expect(plugin.languages[:c][:gcc][:target]).to eql("x86_64-linux-gnu")
290
+ end
291
+
292
+ it "sets languages[:c][:gcc][:thread_model]" do
293
+ plugin.run
294
+ expect(plugin.languages[:c][:gcc][:thread_model]).to eql("posix")
295
+ end
296
+
297
+ it "does not set the languages[:c][:gcc] tree up if gcc command exits nonzero" do
298
+ allow(plugin).to receive(:shell_out).with("gcc -v").and_return(mock_shell_out(1, "", ""))
299
+ plugin.run
300
+ expect(plugin[:languages][:c]).not_to have_key(:gcc)
301
+ end
302
+
303
+ it "does not set the languages[:c][:gcc] tree up if gcc command fails" do
304
+ allow(plugin).to receive(:shell_out).with("gcc -v").and_raise(Ohai::Exceptions::Exec)
305
+ plugin.run
306
+ expect(plugin[:languages][:c]).not_to have_key(:gcc)
307
+ expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
308
+ end
345
309
 
346
- it "does not set the languages[:c][:hpcc] tree up if cc command exits nonzero" do
347
- allow(plugin).to receive(:shell_out).with("what /opt/ansic/bin/cc").and_return(mock_shell_out(1, "", ""))
348
- plugin.run
349
- expect(plugin[:languages][:c]).not_to have_key(:hpcc)
350
- end
310
+ #glibc
311
+ it "gets the glibc x.x.x version from running /lib/libc.so.6" do
312
+ expect(plugin).to receive(:shell_out).with("/lib/libc.so.6")
313
+ plugin.run
314
+ end
315
+
316
+ it "sets languages[:c][:glibc][:version]", :unix_only do
317
+ plugin.run
318
+ expect(plugin.languages[:c][:glibc][:version]).to eql("2.5")
319
+ end
320
+
321
+ it "sets languages[:c][:glibc][:description]" do
322
+ plugin.run
323
+ expect(plugin.languages[:c][:glibc][:description]).to eql("GNU C Library stable release version 2.5, by Roland McGrath et al.")
324
+ end
325
+
326
+ it "does not set the languages[:c][:glibc] tree up if glibc exits nonzero" do
327
+ allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(1, "", ""))
328
+ allow(plugin).to receive(:shell_out).with("/lib64/libc.so.6").and_return(mock_shell_out(1, "", ""))
329
+ plugin.run
330
+ expect(plugin[:languages][:c]).not_to have_key(:glibc)
331
+ end
332
+
333
+ it "does not set the languages[:c][:glibc] tree up if glibc fails" do
334
+ allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_raise(Ohai::Exceptions::Exec)
335
+ allow(plugin).to receive(:shell_out).with("/lib64/libc.so.6").and_raise(Ohai::Exceptions::Exec)
336
+ plugin.run
337
+ expect(plugin[:languages][:c]).not_to have_key(:glibc)
338
+ expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
339
+ end
340
+
341
+ it "gets the glibc x.x version from running /lib/libc.so.6" do
342
+ allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC, ""))
343
+ expect(plugin).to receive(:shell_out).with("/lib/libc.so.6")
344
+ plugin.run
345
+ expect(plugin.languages[:c][:glibc][:version]).to eql("2.5")
346
+ end
351
347
 
352
- it "does not set the languages[:c][:hpcc] tree up if cc command fails" do
353
- allow(plugin).to receive(:shell_out).with("what /opt/ansic/bin/cc").and_raise(Ohai::Exceptions::Exec)
354
- plugin.run
355
- expect(plugin[:languages][:c]).not_to have_key(:hpcc)
356
- expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
348
+ #sun pro
349
+ it "gets the cc version from running cc -V -flags" do
350
+ expect(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", C_SUN))
351
+ plugin.run
352
+ end
353
+
354
+ it "sets languages[:c][:sunpro][:version]" do
355
+ plugin.run
356
+ expect(plugin.languages[:c][:sunpro][:version]).to eql("5.8")
357
+ end
358
+
359
+ it "sets languages[:c][:sunpro][:description]" do
360
+ plugin.run
361
+ expect(plugin.languages[:c][:sunpro][:description]).to eql("cc: Sun C 5.8 Patch 121016-06 2007/08/01")
362
+ end
363
+
364
+ it "does not set the languages[:c][:sunpro] tree up if cc command exits nonzero" do
365
+ allow(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(1, "", ""))
366
+ plugin.run
367
+ expect(plugin[:languages][:c]).not_to have_key(:sunpro)
368
+ end
369
+
370
+ it "does not set the languages[:c][:sunpro] tree up if cc command fails" do
371
+ allow(plugin).to receive(:shell_out).with("cc -V -flags").and_raise(Ohai::Exceptions::Exec)
372
+ plugin.run
373
+ expect(plugin[:languages][:c]).not_to have_key(:sunpro)
374
+ expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
375
+ end
376
+
377
+ it "does not set the languages[:c][:sunpro] tree if the corresponding cc command fails on linux" do
378
+ fedora_error_message = "cc: error trying to exec 'i686-redhat-linux-gcc--flags': execvp: No such file or directory"
379
+
380
+ allow(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", fedora_error_message))
381
+ plugin.run
382
+ expect(plugin[:languages][:c]).not_to have_key(:sunpro)
383
+ end
384
+
385
+ it "does not set the languages[:c][:sunpro] tree if the corresponding cc command fails on hpux" do
386
+ hpux_error_message = "cc: warning 901: unknown option: `-flags': use +help for online documentation.\ncc: HP C/aC++ B3910B A.06.25 [Nov 30 2009]"
387
+ allow(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", hpux_error_message))
388
+ plugin.run
389
+ expect(plugin[:languages][:c]).not_to have_key(:sunpro)
390
+ end
357
391
  end
358
-
359
392
  end