ohai 8.6.0 → 8.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e00fe8c9c7789a01f275184d7cfe7a6bbc4a8631
4
- data.tar.gz: 2368b6c70151bf9b89ee2dc2d3518a8d10add807
3
+ metadata.gz: 48005ef0ac4164194df7bc906291139ce7227895
4
+ data.tar.gz: 24932f3bfaa161f5d97e0131801b7f18e999a636
5
5
  SHA512:
6
- metadata.gz: 9aa2d69b2544e9b270429795f02e3db9e8d2b978c16afba7fecfd377cfac3553c8da4a350a1e8d4edc55577c0a64d8d1d2266dc8135f1d354455494fb7b741c5
7
- data.tar.gz: 523a0112f688c7536c5f4bff387ec0218f4ba8f0c97e995917dba271c2f41137c4793e572c826f3050ca577b4a0483c776c98376bd71a93913b61f388db8a79c
6
+ metadata.gz: f955882f73da2fc4ff1649f0664224bc6878ae78353883e94e08a36c379d2306da9fb2c632c3f0ed58d00a64ea2b271c98670356f0885410fc872695920c3755
7
+ data.tar.gz: 80adff5dccf6c1f7ef8afaefda644fc820bcf13f7919277d89f7c0d93388720dd32e961e5296343ee2456f8a86543f3330133dd31699f6c2baf57988c7dc5053
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "chef", github: "chef/chef", branch: "master"
7
+
8
+ gem "sigar", :platform => "ruby"
9
+ gem 'plist'
10
+
11
+ # gem 'pry-byebug'
12
+ # gem 'pry-stack_explorer'
13
+ end
@@ -1,7 +1,8 @@
1
1
  #
2
2
  # Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>)
3
3
  # Author:: Prabhu Das (<prabhu.das@clogeny.com>)
4
- # Copyright:: Copyright (c) 2013 Opscode, Inc.
4
+ # Author:: Isa Farnik (<isa@chef.io>)
5
+ # Copyright:: Copyright (c) 2015 Chef, Inc.
5
6
  # License:: Apache License, Version 2.0
6
7
  #
7
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -45,76 +46,78 @@ Ohai.plugin(:Network) do
45
46
  network Mash.new unless network
46
47
  network[:interfaces] = Mash.new unless network[:interfaces]
47
48
 
48
- # :default_interface, :default_gateway - route -n get 0
49
- so = shell_out("netstat -rn |grep default")
50
- so.stdout.lines.each do |line|
51
- items = line.split(' ')
52
- if items[0] == "default"
53
- network[:default_gateway] = items[1]
54
- network[:default_interface] = items[5]
49
+ # We unfortunately have to do things a bit different here, if ohai is running
50
+ # within a WPAR. For instance, the WPAR isn't aware of some of its own networking
51
+ # minutia such as default gateway/route.
52
+ unless shell_out("uname -W").stdout.to_i > 0
53
+ # :default_interface, :default_gateway - route -n get 0
54
+ so = shell_out("netstat -rn |grep default")
55
+ so.stdout.lines.each do |line|
56
+ items = line.split(' ')
57
+ if items[0] == "default"
58
+ network[:default_gateway] = items[1]
59
+ network[:default_interface] = items[5]
60
+ end
55
61
  end
56
62
  end
57
63
 
58
- # List the interfaces in system.
59
- so = shell_out("lsdev -Cc if | grep Available")
60
- so.stdout.lines.each do |line|
61
- if line =~ /(\S+) (\S+)\s+(.+)/
62
- interface = $1
63
- iface[interface] = Mash.new unless iface[interface]
64
- iface[interface][:state] = ($2 == 'Available' ? 'up' : 'down')
65
- iface[interface][:description] = $3
66
-
67
- # Query the interface information
68
- if_so = shell_out("ifconfig #{interface}")
69
- if_so.stdout.lines.each do |line|
70
- case line
71
- when /^#{interface}:\sflags=\S+<(\S+)>/
72
- iface[interface][:flags] = $1.split(',')
73
- iface[interface][:metric] = $1 if line =~ /metric\s(\S+)/
74
- else
75
- # We have key value pairs.
76
- if line =~ /inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(\/(\d{1,2}))?/
77
- tmp_addr, tmp_prefix = $1, $3
78
- if tmp_prefix.nil?
79
- netmask = hex_to_dec_netmask($1) if line =~ /netmask\s(\S+)\s/
80
- unless netmask
81
- tmp_prefix ||= "32"
82
- netmask = IPAddr.new("255.255.255.255").mask(tmp_prefix.to_i).to_s
83
- end
84
- else
64
+ # Splits the ifconfig output to 1 line per interface
65
+ if_so = shell_out("ifconfig -a")
66
+ if_so.stdout.gsub(/\n(\w+\d+)/, '___\1').split("___").each do |intraface|
67
+ splat = intraface.split(":")
68
+ interface = splat[0]
69
+ line = splat[1..-1][0]
70
+ iface[interface] = Mash.new
71
+ iface[interface][:state] = (line.include?("<UP,") ? 'up' : 'down')
72
+
73
+ intraface.lines.each do |lin|
74
+ case lin
75
+ when /flags=\S+<(\S+)>/
76
+ iface[interface][:flags] = $1.split(',')
77
+ iface[interface][:metric] = $1 if lin =~ /metric\s(\S+)/
78
+ else
79
+ # We have key value pairs.
80
+ if lin =~ /inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(\/(\d{1,2}))?/
81
+ tmp_addr, tmp_prefix = $1, $3
82
+ if tmp_prefix.nil?
83
+ netmask = hex_to_dec_netmask($1) if lin =~ /netmask\s(\S+)\s/
84
+ unless netmask
85
+ tmp_prefix ||= "32"
85
86
  netmask = IPAddr.new("255.255.255.255").mask(tmp_prefix.to_i).to_s
86
87
  end
87
-
88
- iface[interface][:addresses] = Mash.new unless iface[interface][:addresses]
89
- iface[interface][:addresses][tmp_addr] = { "family" => "inet", "prefixlen" => tmp_prefix }
90
- iface[interface][:addresses][tmp_addr][:netmask] = netmask
91
-
92
- if line =~ /broadcast\s(\S+)\s/
93
- iface[interface][:addresses][tmp_addr][:broadcast] = $1
94
- end
95
- elsif line =~ /inet6 ([a-f0-9\:]+)%?([\d]*)\/?(\d*)/
96
- # TODO do we have more properties on inet6 in aix? broadcast
97
- iface[interface][:addresses] = Mash.new unless iface[interface][:addresses]
98
- iface[interface][:addresses][$1] = { "family" => "inet6", "zone_index" => $2, "prefixlen" => $3 }
99
88
  else
100
- # load all key-values, example "tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1"
101
- properties = line.split
102
- n = properties.length/2 - 1
103
- (0..n).each do |i|
104
- iface[interface][properties[i*2]] = properties[(i*2+1)]
105
- end
89
+ netmask = IPAddr.new("255.255.255.255").mask(tmp_prefix.to_i).to_s
106
90
  end
107
- end
108
- end #ifconfig stdout
109
91
 
110
- # Query macaddress
111
- e_so = shell_out("entstat -d #{interface} | grep \"Hardware Address\"")
112
- iface[interface][:addresses] = Mash.new unless iface[interface][:addresses]
113
- e_so.stdout.lines.each do |line|
114
- iface[interface][:addresses][$1.upcase] = { "family" => "lladdr" } if line =~ /Hardware Address: (\S+)/
92
+ iface[interface][:addresses] = Mash.new unless iface[interface][:addresses]
93
+ iface[interface][:addresses][tmp_addr] = { "family" => "inet", "prefixlen" => tmp_prefix }
94
+ iface[interface][:addresses][tmp_addr][:netmask] = netmask
95
+
96
+ if lin =~ /broadcast\s(\S+)\s/
97
+ iface[interface][:addresses][tmp_addr][:broadcast] = $1
98
+ end
99
+ elsif lin =~ /inet6 ([a-f0-9\:]+)%?([\d]*)\/?(\d*)?/
100
+ # TODO do we have more properties on inet6 in aix? broadcast
101
+ iface[interface][:addresses] = Mash.new unless iface[interface][:addresses]
102
+ iface[interface][:addresses][$1] = { "family" => "inet6", "zone_index" => $2, "prefixlen" => $3 }
103
+ else
104
+ # load all key-values, example "tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1"
105
+ properties = lin.split
106
+ n = properties.length/2 - 1
107
+ (0..n).each do |i|
108
+ iface[interface][properties[i*2]] = properties[(i*2+1)]
109
+ end
110
+ end
115
111
  end
116
- end #lsdev stdout
117
- end
112
+ end
113
+
114
+ # Query macaddress
115
+ e_so = shell_out("entstat -d #{interface} | grep \"Hardware Address\"")
116
+ iface[interface][:addresses] = Mash.new unless iface[interface][:addresses]
117
+ e_so.stdout.lines.each do |line|
118
+ iface[interface][:addresses][$1.upcase] = { "family" => "lladdr" } if line =~ /Hardware Address: (\S+)/
119
+ end
120
+ end #ifconfig stdout
118
121
 
119
122
  # Query routes information
120
123
  %w{inet inet6}.each do |family|
@@ -124,7 +127,7 @@ Ohai.plugin(:Network) do
124
127
  interface = $6
125
128
  iface[interface][:routes] = Array.new unless iface[interface][:routes]
126
129
  iface[interface][:routes] << Mash.new( :destination => $1, :family => family,
127
- :via => $2, :flags => $3)
130
+ :via => $2, :flags => $3)
128
131
  end
129
132
  end
130
133
  end
@@ -142,7 +145,8 @@ Ohai.plugin(:Network) do
142
145
  count += 1
143
146
  end
144
147
  end
145
-
148
+
146
149
  network["interfaces"] = iface
147
150
  end
148
151
  end
152
+
@@ -80,5 +80,6 @@ Ohai.plugin(:CPU) do
80
80
  cpu cpuinfo
81
81
  cpu[:total] = cpu_number
82
82
  cpu[:real] = real_cpu.keys.length
83
+ cpu[:cores] = real_cpu.keys.length * cpu["0"]["cores"].to_i
83
84
  end
84
85
  end
@@ -143,9 +143,18 @@ Ohai.plugin(:Platform) do
143
143
  # kernel release will be used - ex. 3.13
144
144
  platform_version `uname -r`.strip
145
145
  elsif os_release_file_is_cisco?
146
- raise "unknown Cisco /etc/os-release ID field" unless os_release_info['ID'].include?('nexus')
147
- raise "unknown Cisco /etc/os-release ID-LIKE field" unless os_release_info['ID_LIKE'].include?('wrlinux')
148
- platform 'nexus'
146
+ raise 'unknown Cisco /etc/os-release or /etc/cisco-release ID_LIKE field' if
147
+ os_release_info['ID_LIKE'].nil? || ! os_release_info['ID_LIKE'].include?('wrlinux')
148
+
149
+ case os_release_info['ID']
150
+ when 'nexus'
151
+ platform 'nexus'
152
+ when 'ios_xr'
153
+ platform 'ios_xr'
154
+ else
155
+ raise 'unknown Cisco /etc/os-release or /etc/cisco-release ID field'
156
+ end
157
+
149
158
  platform_family 'wrlinux'
150
159
  platform_version os_release_info['VERSION']
151
160
  elsif lsb[:id] =~ /RedHat/i
@@ -29,7 +29,7 @@ Ohai.plugin(:CPU) do
29
29
  wmi = WmiLite::Wmi.new
30
30
  processors = wmi.instances_of('Win32_Processor')
31
31
 
32
- processors.find(:all).each do |processor|
32
+ processors.each do |processor|
33
33
  #
34
34
  # On Windows Server 2003 R2 (i.e. 5.2.*), numberofcores property
35
35
  # doesn't exist on the Win32_Processor class unless the user has
@@ -48,6 +48,8 @@ module Ohai
48
48
  end
49
49
  rescue Ohai::Exceptions::Error
50
50
  raise
51
+ rescue SystemExit # abort or exit from plug-in should exit Ohai with failure code
52
+ raise
51
53
  rescue Exception,Errno::ENOENT => e
52
54
  Ohai::Log.debug("Plugin #{plugin.name} threw exception #{e.inspect} #{e.backtrace.join("\n")}")
53
55
  end
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = '8.6.0'
21
+ VERSION = '8.7.0'
22
22
  end
@@ -0,0 +1,69 @@
1
+ #
2
+ # Author:: Salim Alam (salam@chef.io)
3
+ # Copyright:: Copyright (c) 2015 Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb'))
20
+
21
+ tmp = ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] || '/tmp'
22
+
23
+ abortstr = <<EOF
24
+ Ohai.plugin(:Abort) do
25
+ provides "abort_test"
26
+ collect_data do
27
+ abort
28
+ end
29
+ end
30
+ EOF
31
+
32
+ describe "a plug-in that aborts execution" do
33
+ before(:all) do
34
+ begin
35
+ Dir.mkdir("#{tmp}/plugins")
36
+ rescue Errno::EEXIST
37
+ # ignore
38
+ end
39
+ end
40
+
41
+ before(:each) do
42
+ fail_file = File.open("#{tmp}/plugins/abort.rb", "w+")
43
+ fail_file.write(abortstr)
44
+ fail_file.close
45
+ end
46
+
47
+ after(:each) do
48
+ File.delete("#{tmp}/plugins/abort.rb")
49
+ end
50
+
51
+ after(:all) do
52
+ begin
53
+ Dir.delete("#{tmp}/plugins")
54
+ rescue
55
+ # ignore
56
+ end
57
+ end
58
+
59
+ before(:each) do
60
+ @ohai = Ohai::System.new
61
+ @loader = Ohai::Loader.new(@ohai)
62
+ @runner = Ohai::Runner.new(@ohai)
63
+ end
64
+
65
+ it "should raise SystemExit" do
66
+ @plugin = @loader.load_plugin("#{tmp}/plugins/abort.rb")
67
+ expect { @runner.run_plugin(@plugin) }.to raise_error(SystemExit)
68
+ end
69
+ end
@@ -24,18 +24,21 @@ describe Ohai::System, "AIX network plugin" do
24
24
  default 172.31.8.1 UG 2 121789 en0 - -
25
25
  NETSTAT_RN_GREP_DEFAULT
26
26
 
27
- @lsdev_Cc_if = <<-LSDEV_CC_IF
28
- en0 Available Standard Ethernet Network Interface
29
- LSDEV_CC_IF
30
-
31
- @ifconfig_en0 = <<-IFCONFIG_EN0
27
+ @ifconfig = <<-IFCONFIG
32
28
  en0: flags=1e080863,480<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),CHAIN> metric 1
33
29
  inet 172.29.174.58 netmask 0xffffc000 broadcast 172.29.191.255
34
30
  inet 172.29.174.59 broadcast 172.29.191.255
35
31
  inet 172.29.174.60 netmask 0xffffc000 broadcast 172.29.191.255
36
32
  inet6 ::1%1/0
37
33
  tcp_sendspace 262144 tcp_recvspace 262144 rfc1323 1
38
- IFCONFIG_EN0
34
+ en1: flags=1e084863,480<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),CHAIN>
35
+ inet 172.31.10.211 netmask 0xfffffc00 broadcast 172.31.11.255
36
+ tcp_sendspace 262144 tcp_recvspace 262144 rfc1323 1
37
+ lo0: flags=e08084b,c0<UP,BROADCAST,LOOPBACK,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,LARGESEND,CHAIN>
38
+ inet 127.0.0.1 netmask 0xff000000 broadcast 127.255.255.255
39
+ inet6 ::1%1/0
40
+ tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1
41
+ IFCONFIG
39
42
 
40
43
  @netstat_nrf_inet = <<-NETSTAT_NRF_INET
41
44
  Destination Gateway Flags Refs Use If Exp Groups
@@ -46,6 +49,13 @@ default 172.29.128.13 UG 0 587683 en0 - -
46
49
  172.29.191.255 172.29.174.58 UHSb 0 1 en0 - -
47
50
  NETSTAT_NRF_INET
48
51
 
52
+ @entstat_err = <<-ENSTAT_ERR
53
+
54
+
55
+ entstat: 0909-002 Unable to open device en0, errno = 13
56
+ grep: 0652-033 Cannot open Address".
57
+ ENSTAT_ERR
58
+
49
59
  @aix_arp_an = <<-ARP_AN
50
60
  ? (172.29.131.16) at 6e:87:70:0:40:3 [ethernet] stored in bucket 16
51
61
 
@@ -66,10 +76,12 @@ ARP_AN
66
76
  @plugin = get_plugin("aix/network")
67
77
  allow(@plugin).to receive(:collect_os).and_return(:aix)
68
78
  @plugin[:network] = Mash.new
79
+ allow(@plugin).to receive(:shell_out).with("uname -W").and_return(mock_shell_out(0, "0", nil))
69
80
  allow(@plugin).to receive(:shell_out).with("netstat -rn |grep default").and_return(mock_shell_out(0, @netstat_rn_grep_default, nil))
70
- allow(@plugin).to receive(:shell_out).with("lsdev -Cc if | grep Available").and_return(mock_shell_out(0, @lsdev_Cc_if, nil))
71
- allow(@plugin).to receive(:shell_out).with("ifconfig en0").and_return(mock_shell_out(0, @ifconfig_en0, nil))
81
+ allow(@plugin).to receive(:shell_out).with("ifconfig -a").and_return(mock_shell_out(0, @ifconfig, nil))
72
82
  allow(@plugin).to receive(:shell_out).with("entstat -d en0 | grep \"Hardware Address\"").and_return(mock_shell_out(0, "Hardware Address: be:42:80:00:b0:05", nil))
83
+ allow(@plugin).to receive(:shell_out).with("entstat -d en1 | grep \"Hardware Address\"").and_return(mock_shell_out(0, @entstat_err, nil))
84
+ allow(@plugin).to receive(:shell_out).with("entstat -d lo0 | grep \"Hardware Address\"").and_return(mock_shell_out(0, @entstat_err, nil))
73
85
  allow(@plugin).to receive(:shell_out).with("netstat -nrf inet").and_return(mock_shell_out(0, @netstat_nrf_inet, nil))
74
86
  allow(@plugin).to receive(:shell_out).with("netstat -nrf inet6").and_return(mock_shell_out(0, "::1%1 ::1%1 UH 1 109392 en0 - -", nil))
75
87
  allow(@plugin).to receive(:shell_out).with("arp -an").and_return(mock_shell_out(0, @aix_arp_an, nil))
@@ -85,7 +97,7 @@ ARP_AN
85
97
  end
86
98
 
87
99
  it "detects the interfaces" do
88
- expect(@plugin['network']['interfaces'].keys.sort).to eq(["en0"])
100
+ expect(@plugin['network']['interfaces'].keys.sort).to eq(["en0", "en1", "lo0"])
89
101
  end
90
102
 
91
103
  it "detects the ip addresses of the interfaces" do
@@ -93,17 +105,34 @@ ARP_AN
93
105
  end
94
106
  end
95
107
 
96
- describe "netstat -rn |grep default" do
108
+ describe "when running on an LPAR" do
109
+ describe "netstat -rn |grep default" do
110
+ before do
111
+ @plugin.run
112
+ end
113
+
114
+ it "returns the default gateway of the system's network" do
115
+ expect(@plugin[:network][:default_gateway]).to eq('172.31.8.1')
116
+ end
117
+
118
+ it "returns the default interface of the system's network" do
119
+ expect(@plugin[:network][:default_interface]).to eq('en0')
120
+ end
121
+ end
122
+ end
123
+
124
+ describe "when running on a WPAR" do
97
125
  before do
126
+ allow(@plugin).to receive(:shell_out).with("uname -W").and_return(mock_shell_out(0, "6", nil))
98
127
  @plugin.run
99
128
  end
100
129
 
101
- it "returns the default gateway of the system's network" do
102
- expect(@plugin[:network][:default_gateway]).to eq('172.31.8.1')
130
+ it "avoids collecting routing information" do
131
+ expect(@plugin[:network][:default_gateway]).to be_nil
103
132
  end
104
133
 
105
- it "returns the default interface of the system's network" do
106
- expect(@plugin[:network][:default_interface]).to eq('en0')
134
+ it "avoids collecting default interface" do
135
+ expect(@plugin[:network][:default_gateway]).to be_nil
107
136
  end
108
137
  end
109
138
 
@@ -113,11 +142,6 @@ ARP_AN
113
142
  expect(@plugin['network']['interfaces']['en0'][:state]).to eq("up")
114
143
  end
115
144
 
116
- it "detects the description of the interfaces in the system" do
117
- @plugin.run
118
- expect(@plugin['network']['interfaces']['en0'][:description]).to eq("Standard Ethernet Network Interface")
119
- end
120
-
121
145
  describe "ifconfig interface" do
122
146
  it "detects the CHAIN network flag" do
123
147
  @plugin.run
@@ -173,7 +197,6 @@ ARP_AN
173
197
 
174
198
  context "inet6 entries" do
175
199
  before do
176
- allow(@plugin).to receive(:shell_out).with("ifconfig en0").and_return(mock_shell_out(0, "inet6 ::1%1/0", nil))
177
200
  @plugin.run
178
201
  @inet_entry = @plugin['network']['interfaces']['en0'][:addresses]["::1"]
179
202
  end
@@ -89,6 +89,11 @@ describe Ohai::System, "General Linux cpu plugin" do
89
89
  end
90
90
 
91
91
  it_behaves_like "Common cpu info", 1, 0
92
+
93
+ it "gets total cores" do
94
+ @plugin.run
95
+ expect(@plugin[:cpu][:cores]).to eql(0)
96
+ end
92
97
 
93
98
  it "doesn't have a cpu 1" do
94
99
  @plugin.run
@@ -650,17 +650,116 @@ CISCO_RELEASE
650
650
  end
651
651
  end
652
652
 
653
- describe "on Wind River Linux for Cisco Nexus" do
653
+ describe '#read_os_release_info' do
654
+ let(:file_contents) { "COW=MOO\nDOG=\"BARK\"" }
655
+ it 'returns nil if the file does not exist' do
656
+ allow(File).to receive(:exist?).with('/etc/test-release').and_return(false)
657
+ expect(@plugin.read_os_release_info('/etc/test-release')).to be nil
658
+ end
659
+
660
+ it 'returns a hash of expected contents' do
661
+ allow(File).to receive(:exist?).with('/etc/test-release').and_return(true)
662
+ allow(File).to receive(:read).with('/etc/test-release').and_return(file_contents)
663
+ release_info = @plugin.read_os_release_info('/etc/test-release')
664
+
665
+ expect(release_info['COW']).to eq('MOO')
666
+ expect(release_info['DOG']).to eq('BARK')
667
+ end
668
+ end
669
+
670
+ describe '#os_release_info' do
671
+ context 'when CISCO_RELEASE_INFO is not populated' do
672
+ let(:release_info) { { 'ID' => 'os_id' } }
673
+
674
+ before do
675
+ allow(File).to receive(:exist?).with('/etc/os-release').and_return(true)
676
+ allow(@plugin).to receive(:read_os_release_info).with('/etc/os-release').and_return(release_info)
677
+ end
654
678
 
679
+ it 'reads the os-release file' do
680
+ expect(@plugin).to receive(:read_os_release_info).with('/etc/os-release').and_return(release_info)
681
+ @plugin.os_release_info
682
+ end
683
+
684
+ it 'returns a hash of expected contents' do
685
+ expect(@plugin.os_release_info['ID']).to eq('os_id')
686
+ end
687
+ end
688
+
689
+ context 'when CISCO_RELEASE_INFO is populated' do
690
+ let(:release_info) { { 'ID' => 'os_id', 'CISCO_RELEASE_INFO' => '/etc/cisco-release' } }
691
+ let(:cisco_release_info) { { 'ID' => 'cisco_id' } }
692
+
693
+ before do
694
+ allow(File).to receive(:exist?).with('/etc/os-release').and_return(true)
695
+ allow(File).to receive(:exist?).with('/etc/cisco-release').and_return(true)
696
+ allow(@plugin).to receive(:read_os_release_info).with('/etc/os-release').and_return(release_info)
697
+ allow(@plugin).to receive(:read_os_release_info).with('/etc/cisco-release').and_return(cisco_release_info)
698
+ end
699
+
700
+ it 'reads the os-release AND the cisco-release file' do
701
+ expect(@plugin).to receive(:read_os_release_info).with('/etc/os-release').and_return(release_info)
702
+ expect(@plugin).to receive(:read_os_release_info).with('/etc/cisco-release').and_return(release_info)
703
+ @plugin.os_release_info
704
+ end
705
+
706
+ it 'returns the ID from the cisco-release file instead of the os-release file' do
707
+ expect(@plugin.os_release_info['ID']).to eq('cisco_id')
708
+ end
709
+ end
710
+ end
711
+
712
+ describe 'on Wind River Linux 5 for Cisco Nexus' do
655
713
  let(:have_os_release) { true }
714
+ let(:os_release_info) do
715
+ {
716
+ 'ID' => 'nexus',
717
+ 'ID_LIKE' => 'wrlinux',
718
+ 'NAME' => 'Nexus',
719
+ 'VERSION' => '7.0(3)I2(0.475E.6)',
720
+ 'VERSION_ID' => '7.0(3)I2',
721
+ 'PRETTY_NAME' => 'Nexus 7.0(3)I2',
722
+ 'HOME_URL' => 'http://www.cisco.com',
723
+ 'BUILD_ID' => '6',
724
+ 'CISCO_RELEASE_INFO' => '/etc/os-release'
725
+ }
726
+ end
727
+
728
+ it 'should set platform to nexus and platform_family to wrlinux' do
729
+ allow(@plugin).to receive(:os_release_info).and_return(os_release_info)
730
+ @plugin.lsb = nil
731
+ @plugin.run
656
732
 
657
- it "should set platform to nexus and platform_family to wrlinux" do
733
+ expect(@plugin[:platform]).to eq('nexus')
734
+ expect(@plugin[:platform_family]).to eq('wrlinux')
735
+ expect(@plugin[:platform_version]).to eq('7.0(3)I2(0.475E.6)')
736
+ end
737
+ end
738
+
739
+ describe 'on Wind River Linux 7 for Cisco IOS-XR' do
740
+ let(:have_os_release) { true }
741
+ let(:os_release_info) do
742
+ {
743
+ 'ID' => 'ios_xr',
744
+ 'ID_LIKE' => 'cisco-wrlinux wrlinux',
745
+ 'NAME' => 'IOS XR',
746
+ 'VERSION' => '6.0.0.14I',
747
+ 'VERSION_ID' => '6.0.0.14I',
748
+ 'PRETTY_NAME' => 'Cisco IOS XR Software, Version 6.0.0.14I',
749
+ 'BUILD_ID' => '2015-09-10-15-50-17',
750
+ 'HOME_URL' => 'http://www.cisco.com',
751
+ 'CISCO_RELEASE_INFO' => '/etc/os-release'
752
+ }
753
+ end
754
+
755
+ it 'should set platform to ios_xr and platform_family to wrlinux' do
756
+ allow(@plugin).to receive(:os_release_info).and_return(os_release_info)
658
757
  @plugin.lsb = nil
659
- expect(File).to receive(:read).twice.with("/etc/os-release").and_return("ID=nexus\nID_LIKE=wrlinux\nNAME=Nexus\nVERSION=\"7.0(3)I2(0.475E.6)\"\nVERSION_ID=\"7.0(3)I2\"\nPRETTY_NAME=\"Nexus 7.0(3)I2\"\nHOME_URL=http://www.cisco.com\nBUILD_ID=6\nCISCO_RELEASE_INFO=/etc/os-release")
660
758
  @plugin.run
661
- expect(@plugin[:platform]).to eq("nexus")
662
- expect(@plugin[:platform_family]).to eq("wrlinux")
663
- expect(@plugin[:platform_version]).to eq("7.0(3)I2(0.475E.6)")
759
+
760
+ expect(@plugin[:platform]).to eq('ios_xr')
761
+ expect(@plugin[:platform_family]).to eq('wrlinux')
762
+ expect(@plugin[:platform_version]).to eq('6.0.0.14I')
664
763
  end
665
764
  end
666
765
  end
@@ -0,0 +1,112 @@
1
+ #
2
+ # Author:: Salim Alam (<salam@chef.io>)
3
+ # Copyright:: Copyright (c) 2015 Chef Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
20
+
21
+ shared_examples 'a cpu' do |cpu_no|
22
+ describe "cpu #{cpu_no}" do
23
+ it "should set physical_id to CPU#{cpu_no}" do
24
+ expect(@plugin[:cpu]["#{cpu_no}"][:physical_id]).to eq("CPU#{cpu_no}")
25
+ end
26
+
27
+ it 'should set mhz to 2793' do
28
+ expect(@plugin[:cpu]["#{cpu_no}"][:mhz]).to eq('2793')
29
+ end
30
+
31
+ it 'should set vendor_id to GenuineIntel' do
32
+ expect(@plugin[:cpu]["#{cpu_no}"][:vendor_id]).to eq('GenuineIntel')
33
+ end
34
+
35
+ it 'should set model_name to Intel64 Family 6 Model 70 Stepping 1' do
36
+ expect(@plugin[:cpu]["#{cpu_no}"][:model_name])
37
+ .to eq('Intel64 Family 6 Model 70 Stepping 1')
38
+ end
39
+
40
+ it 'should set model to 17921' do
41
+ expect(@plugin[:cpu]["#{cpu_no}"][:model]).to eq('17921')
42
+ end
43
+
44
+ it 'should set family to 2' do
45
+ expect(@plugin[:cpu]["#{cpu_no}"][:family]).to eq('2')
46
+ end
47
+
48
+ it 'should set stepping to 9' do
49
+ expect(@plugin[:cpu]["#{cpu_no}"][:stepping]).to eq(9)
50
+ end
51
+
52
+ it 'should set cache_size to 64 KB' do
53
+ expect(@plugin[:cpu]["#{cpu_no}"][:cache_size]).to eq('64 KB')
54
+ end
55
+ end
56
+ end
57
+
58
+ describe Ohai::System, 'Windows cpu plugin' do
59
+ before(:each) do
60
+ @plugin = get_plugin('windows/cpu')
61
+ allow(@plugin).to receive(:collect_os).and_return(:windows)
62
+
63
+ @double_wmi = double(WmiLite::Wmi)
64
+ @double_wmi_instance = instance_double(WmiLite::Wmi)
65
+
66
+ @processors = [{ 'description' => 'Intel64 Family 6 Model 70 Stepping 1',
67
+ 'deviceid' => 'CPU0',
68
+ 'family' => 2,
69
+ 'l2cachesize' => 0,
70
+ 'manufacturer' => 'GenuineIntel',
71
+ 'maxclockspeed' => 2793,
72
+ 'numberofcores' => 1,
73
+ 'revision' => 17_921,
74
+ 'stepping' => 9,
75
+ 'l2cachesize' => 64 },
76
+
77
+ { 'description' => 'Intel64 Family 6 Model 70 Stepping 1',
78
+ 'deviceid' => 'CPU1',
79
+ 'family' => 2,
80
+ 'l2cachesize' => 0,
81
+ 'manufacturer' => 'GenuineIntel',
82
+ 'maxclockspeed' => 2793,
83
+ 'numberofcores' => 1,
84
+ 'revision' => 17_921,
85
+ 'stepping' => 9,
86
+ 'l2cachesize' => 64 }]
87
+
88
+ allow(WmiLite::Wmi).to receive(:new).and_return(@double_wmi_instance)
89
+
90
+ allow(@double_wmi_instance).to receive(:instances_of)
91
+ .with('Win32_Processor')
92
+ .and_return(@processors)
93
+
94
+ @plugin.run
95
+ end
96
+
97
+ it 'should set total cpu to 2' do
98
+ expect(@plugin[:cpu][:total]).to eq(2)
99
+ end
100
+
101
+ it 'should set real cpu to 2' do
102
+ expect(@plugin[:cpu][:real]).to eq(2)
103
+ end
104
+
105
+ it 'should set 2 distinct cpus numbered 0 and 1' do
106
+ expect(@plugin[:cpu]).to have_key('0')
107
+ expect(@plugin[:cpu]).to have_key('1')
108
+ end
109
+
110
+ it_behaves_like 'a cpu', 0
111
+ it_behaves_like 'a cpu', 1
112
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohai
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.6.0
4
+ version: 8.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-02 00:00:00.000000000 Z
11
+ date: 2015-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types
@@ -275,6 +275,7 @@ executables:
275
275
  extensions: []
276
276
  extra_rdoc_files: []
277
277
  files:
278
+ - Gemfile
278
279
  - LICENSE
279
280
  - README.md
280
281
  - Rakefile
@@ -465,6 +466,7 @@ files:
465
466
  - spec/unit/mixin/ec2_metadata_spec.rb
466
467
  - spec/unit/mixin/softlayer_metadata_spec.rb
467
468
  - spec/unit/plugin_config_spec.rb
469
+ - spec/unit/plugins/abort_spec.rb
468
470
  - spec/unit/plugins/aix/cpu_spec.rb
469
471
  - spec/unit/plugins/aix/filesystem_spec.rb
470
472
  - spec/unit/plugins/aix/hostname_spec.rb
@@ -562,6 +564,7 @@ files:
562
564
  - spec/unit/plugins/solaris2/zpools_spec.rb
563
565
  - spec/unit/plugins/ssh_host_keys_spec.rb
564
566
  - spec/unit/plugins/vmware_spec.rb
567
+ - spec/unit/plugins/windows/cpu_spec.rb
565
568
  - spec/unit/plugins/windows/memory_spec.rb
566
569
  - spec/unit/plugins/windows/virtualization_spec.rb
567
570
  - spec/unit/provides_map_spec.rb
@@ -594,4 +597,3 @@ signing_key:
594
597
  specification_version: 4
595
598
  summary: Ohai profiles your system and emits JSON
596
599
  test_files: []
597
- has_rdoc: