ohai 7.4.1 → 7.6.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +5 -13
  2. data/README.md +8 -8
  3. data/Rakefile +2 -2
  4. data/lib/ohai/mixin/cloudstack_metadata.rb +88 -0
  5. data/lib/ohai/plugins/aix/kernel.rb +15 -1
  6. data/lib/ohai/plugins/aix/network.rb +5 -2
  7. data/lib/ohai/plugins/aix/virtualization.rb +39 -0
  8. data/lib/ohai/plugins/cloud.rb +32 -0
  9. data/lib/ohai/plugins/cloudstack.rb +43 -0
  10. data/lib/ohai/plugins/darwin/cpu.rb +2 -2
  11. data/lib/ohai/plugins/go.rb +30 -0
  12. data/lib/ohai/plugins/hostname.rb +1 -1
  13. data/lib/ohai/plugins/linux/filesystem.rb +19 -5
  14. data/lib/ohai/plugins/linux/platform.rb +5 -1
  15. data/lib/ohai/plugins/openstack.rb +22 -0
  16. data/lib/ohai/plugins/passwd.rb +5 -1
  17. data/lib/ohai/plugins/python.rb +3 -3
  18. data/lib/ohai/plugins/solaris2/zpools.rb +1 -1
  19. data/lib/ohai/version.rb +1 -1
  20. data/spec/unit/mixin/cloudstack_metadata_spec.rb +33 -0
  21. data/spec/unit/plugins/aix/kernel_spec.rb +6 -3
  22. data/spec/unit/plugins/aix/network_spec.rb +1 -1
  23. data/spec/unit/plugins/aix/virtualization_spec.rb +53 -0
  24. data/spec/unit/plugins/cloud_spec.rb +31 -0
  25. data/spec/unit/plugins/cloudstack_spec.rb +155 -0
  26. data/spec/unit/plugins/darwin/cpu_spec.rb +2 -2
  27. data/spec/unit/plugins/go_spec.rb +44 -0
  28. data/spec/unit/plugins/hostname_spec.rb +12 -0
  29. data/spec/unit/plugins/linux/filesystem_spec.rb +55 -40
  30. data/spec/unit/plugins/linux/platform_spec.rb +36 -0
  31. data/spec/unit/plugins/openstack_spec.rb +55 -0
  32. data/spec/unit/plugins/passwd_spec.rb +3 -2
  33. data/spec/unit/plugins/python_spec.rb +22 -20
  34. data/spec/unit/plugins/solaris2/zpools_spec.rb +153 -0
  35. metadata +75 -59
@@ -55,6 +55,10 @@ Ohai.plugin(:Platform) do
55
55
  end
56
56
  platform_version File.read("/etc/debian_version").chomp
57
57
  end
58
+ elsif File.exists?("/etc/parallels-release")
59
+ contents = File.read("/etc/parallels-release").chomp
60
+ platform get_redhatish_platform(contents)
61
+ platform_version contents.match(/(\d\.\d\.\d)/)[0]
58
62
  elsif File.exists?("/etc/redhat-release")
59
63
  contents = File.read("/etc/redhat-release").chomp
60
64
  platform get_redhatish_platform(contents)
@@ -109,7 +113,7 @@ Ohai.plugin(:Platform) do
109
113
  platform_family "debian"
110
114
  when /fedora/
111
115
  platform_family "fedora"
112
- when /oracle/, /centos/, /redhat/, /scientific/, /enterpriseenterprise/, /amazon/, /xenserver/, /cloudlinux/, /ibm_powerkvm/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID"
116
+ when /oracle/, /centos/, /redhat/, /scientific/, /enterpriseenterprise/, /amazon/, /xenserver/, /cloudlinux/, /ibm_powerkvm/, /parallels/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID"
113
117
  platform_family "rhel"
114
118
  when /suse/
115
119
  platform_family "suse"
@@ -22,6 +22,26 @@ Ohai.plugin(:Openstack) do
22
22
 
23
23
  include Ohai::Mixin::Ec2Metadata
24
24
 
25
+ def collect_openstack_metadata(addr = Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, api_version = '2013-04-04')
26
+ path = "/openstack/#{api_version}/meta_data.json"
27
+ uri = "http://#{addr}#{path}"
28
+ begin
29
+ response = http_client.get_response(URI.parse(uri),nil,nil)
30
+ case response.code
31
+ when '200'
32
+ FFI_Yajl::Parser.parse(response.body)
33
+ when '404'
34
+ Ohai::Log.debug("Encountered 404 response retreiving OpenStack specific metadata path: #{path} ; continuing.")
35
+ nil
36
+ else
37
+ raise "Encountered error retrieving OpenStack specific metadata (#{path} returned #{response.code} response)"
38
+ end
39
+ rescue => e
40
+ Ohai::Log.debug("Encountered error retrieving OpenStack specific metadata (#{uri}), due to #{e.class}")
41
+ nil
42
+ end
43
+ end
44
+
25
45
  collect_data do
26
46
  # Adds openstack Mash
27
47
  if hint?('openstack') || hint?('hp')
@@ -36,6 +56,8 @@ Ohai.plugin(:Openstack) do
36
56
  openstack['provider'] = 'hp'
37
57
  else
38
58
  openstack['provider'] = 'openstack'
59
+ Ohai::Log.debug("connecting to the OpenStack specific metadata service")
60
+ openstack['metadata'] = collect_openstack_metadata
39
61
  end
40
62
 
41
63
  else
@@ -32,7 +32,11 @@ Ohai.plugin(:Passwd) do
32
32
  end
33
33
 
34
34
  unless current_user
35
- current_user fix_encoding(Etc.getlogin)
35
+ current_user fix_encoding(Etc.getpwuid(Process.euid).name)
36
36
  end
37
37
  end
38
+
39
+ collect_data(:windows) do
40
+ # Etc returns nil on Windows
41
+ end
38
42
  end
@@ -6,9 +6,9 @@
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
8
8
  # You may obtain a copy of the License at
9
- #
9
+ #
10
10
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
  # Unless required by applicable law or agreed to in writing, software
13
13
  # distributed under the License is distributed on an "AS IS" BASIS,
14
14
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,7 +26,7 @@ Ohai.plugin(:Python) do
26
26
 
27
27
  python = Mash.new
28
28
 
29
- so = shell_out("python -c \"import sys; print sys.version\"")
29
+ so = shell_out("python -c \"import sys; print (sys.version)\"")
30
30
 
31
31
  if so.exitstatus == 0
32
32
  output = so.stdout.split
@@ -26,7 +26,7 @@ Ohai.plugin(:Zpools) do
26
26
  so = shell_out("zpool list -H -o name,size,alloc,free,cap,dedup,health,version")
27
27
  so.stdout.lines do |line|
28
28
  case line
29
- when /^([-_0-9A-Za-z]*)\s+([.0-9]+[MGTPE])\s+([.0-9]+[MGTPE])\s+([.0-9]+[MGTPE])\s+(\d+%)\s+([.0-9]+x)\s+([-_0-9A-Za-z]+)\s+(\d+)$/
29
+ when /^([-_0-9A-Za-z]*)\s+([.0-9]+[MGTPE])\s+([.0-9]+[MGTPE])\s+([.0-9]+[MGTPE])\s+(\d+%)\s+([.0-9]+x)\s+([-_0-9A-Za-z]+)\s+(\d+|-)$/
30
30
  pools[$1] = Mash.new
31
31
  pools[$1][:pool_size] = $2
32
32
  pools[$1][:pool_allocated] = $3
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = '7.4.1'
21
+ VERSION = '7.6.0.rc.0'
22
22
  end
@@ -0,0 +1,33 @@
1
+ #
2
+ # Author:: Olle Lundberg (<geek@nerd.sh>)
3
+ # Copyright:: Copyright (c) 2013 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDIT"Net::HTTP Response"NS 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
+ require 'ohai/mixin/cloudstack_metadata'
21
+
22
+ describe Ohai::Mixin::CloudstackMetadata do
23
+ let(:mixin) {
24
+ metadata_object = Object.new.extend(Ohai::Mixin::CloudstackMetadata)
25
+ metadata_object
26
+ }
27
+
28
+ context "#best_api_version" do
29
+ it "returns the string latest" do
30
+ mixin.best_api_version.should == "latest"
31
+ end
32
+ end
33
+ end
@@ -25,8 +25,7 @@ describe Ohai::System, "AIX kernel plugin" do
25
25
  @plugin.stub(:shell_out).with("uname -r").and_return(mock_shell_out(0, "1", nil))
26
26
  @plugin.stub(:shell_out).with("uname -v").and_return(mock_shell_out(0, "6", nil))
27
27
  @plugin.stub(:shell_out).with("uname -p").and_return(mock_shell_out(0, "powerpc", nil))
28
- @modules = Mash.new
29
- @plugin.stub(:modules).and_return(@modules)
28
+ @plugin.stub(:shell_out).with("genkex -d").and_return(mock_shell_out(0, " Text address Size Data address Size File\nf1000000c0338000 77000 f1000000c0390000 1ec8c /usr/lib/drivers/cluster\n 6390000 20000 63a0000 ba8 /usr/lib/drivers/if_en", nil))
30
29
  @plugin.run
31
30
  end
32
31
 
@@ -47,6 +46,10 @@ describe Ohai::System, "AIX kernel plugin" do
47
46
  end
48
47
 
49
48
  it "detects the modules" do
50
- @plugin[:kernel][:modules].should == @modules
49
+ @plugin[:kernel][:modules]["/usr/lib/drivers/cluster"]["text"].should == { "address" => "f1000000c0338000", "size" => "77000" }
50
+ @plugin[:kernel][:modules]["/usr/lib/drivers/cluster"]["data"].should == { "address" => "f1000000c0390000", "size" => "1ec8c" }
51
+ @plugin[:kernel][:modules]["/usr/lib/drivers/if_en"]["text"].should == { "address" => "6390000", "size" => "20000"}
52
+ @plugin[:kernel][:modules]["/usr/lib/drivers/if_en"]["data"].should == { "address" => "63a0000", "size" => "ba8"}
53
+
51
54
  end
52
55
  end
@@ -183,7 +183,7 @@ ARP_AN
183
183
  before do
184
184
  @plugin.stub(:shell_out).with("ifconfig en0").and_return(mock_shell_out(0, "inet6 ::1%1/0", nil))
185
185
  @plugin.run
186
- @inet_entry = @plugin['network']['interfaces']['en0'][:addresses]["::1%1"]
186
+ @inet_entry = @plugin['network']['interfaces']['en0'][:addresses]["::1"]
187
187
  end
188
188
 
189
189
  it "detects the prefixlen" do
@@ -0,0 +1,53 @@
1
+ #
2
+ # Author:: Julian C. Dunn (<jdunn@getchef.com>)
3
+ # Copyright:: Copyright (c) 2014 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
+ require 'spec_helper'
19
+
20
+ describe Ohai::System, "AIX virtualization plugin" do
21
+
22
+ context "inside an LPAR" do
23
+ let(:plugin) do
24
+ p = get_plugin("aix/virtualization")
25
+ allow(p).to receive(:collect_os).and_return(:aix)
26
+ allow(p).to receive(:shell_out).with("uname -L").and_return(mock_shell_out(0, "29 l273pp027", nil))
27
+ allow(p).to receive(:shell_out).with("uname -W").and_return(mock_shell_out(0, "0", nil))
28
+ p.run
29
+ p
30
+ end
31
+
32
+ it "uname -L detects the LPAR number and name" do
33
+ plugin[:virtualization][:lpar_no].should == "29"
34
+ plugin[:virtualization][:lpar_name].should == "l273pp027"
35
+ end
36
+ end
37
+
38
+ context "inside a WPAR" do
39
+ let(:plugin) do
40
+ p = get_plugin("aix/virtualization")
41
+ allow(p).to receive(:collect_os).and_return(:aix)
42
+ allow(p).to receive(:shell_out).with("uname -L").and_return(mock_shell_out(0, "43 l33t", nil))
43
+ allow(p).to receive(:shell_out).with("uname -W").and_return(mock_shell_out(0, "42", nil))
44
+ p.run
45
+ p
46
+ end
47
+
48
+ it "uname -W detects the WPAR number" do
49
+ plugin[:virtualization][:wpar_no].should == "42"
50
+ end
51
+ end
52
+
53
+ end
@@ -29,6 +29,7 @@ describe Ohai::System, "plugin cloud" do
29
29
  @plugin[:eucalyptus] = nil
30
30
  @plugin[:linode] = nil
31
31
  @plugin[:azure] = nil
32
+ @plugin[:cloudstack] = nil
32
33
  @plugin.run
33
34
  @plugin[:cloud].should be_nil
34
35
  end
@@ -205,4 +206,34 @@ describe Ohai::System, "plugin cloud" do
205
206
  end
206
207
  end
207
208
 
209
+ describe "with cloudstack mash" do
210
+ before do
211
+ @plugin[:cloudstack] = Mash.new()
212
+ end
213
+
214
+ it "populates cloud public ip" do
215
+ @plugin[:cloudstack]['public_ipv4'] = "174.129.150.8"
216
+ @plugin.run
217
+ @plugin[:cloud][:public_ips][0].should == @plugin[:cloudstack]['public_ipv4']
218
+ end
219
+
220
+ it "populates cloud private ip" do
221
+ @plugin[:cloudstack]['local_ipv4'] = "10.252.42.149"
222
+ @plugin.run
223
+ @plugin[:cloud][:private_ips][0].should == @plugin[:cloudstack]['local_ipv4']
224
+ end
225
+
226
+ it "populates cloud provider" do
227
+ @plugin.run
228
+ @plugin[:cloud][:provider].should == "cloudstack"
229
+ end
230
+
231
+ it "populates vm id" do
232
+ @plugin[:cloudstack]['vm_id'] = "8983fb85-fb7f-46d6-8af1-c1b6666fec39"
233
+ @plugin.run
234
+ @plugin[:cloud][:vm_id].should == @plugin[:cloudstack]['vm_id']
235
+ end
236
+ end
237
+
238
+
208
239
  end
@@ -0,0 +1,155 @@
1
+ #
2
+ # Author:: Olle Lundberg (<geek@nerd.sh>)
3
+ # Copyright:: Copyright (c) 2014 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 CONDIT"Net::HTTP Response"NS 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 'spec_helper'
20
+ require 'ohai/plugins/cloudstack'
21
+
22
+ describe "Cloudstack Plugin" do
23
+
24
+ let(:cloudstack_hint) { false }
25
+
26
+ let(:ohai_system) { Ohai::System.new }
27
+ let(:ohai_data) { ohai_system.data }
28
+
29
+ let(:cloudstack_plugin) do
30
+ plugin = get_plugin("cloudstack", ohai_system)
31
+ plugin.stub(:hint?).with("cloudstack").and_return(cloudstack_hint)
32
+ plugin
33
+ end
34
+
35
+ before do
36
+ stub_const("Ohai::Mixin::CloudstackMetadata::CLOUDSTACK_METADATA_ADDR", '10.10.10.10')
37
+ end
38
+
39
+ context "when there is no relevant hint" do
40
+
41
+ it "does not set any cloudstack data" do
42
+ cloudstack_plugin.run
43
+ expect(ohai_data).to_not have_key("cloudstack")
44
+ end
45
+
46
+ end
47
+
48
+ context "when there is a `cloudstack` hint" do
49
+ let(:cloudstack_hint) { true }
50
+
51
+ context "and the metadata service is not available" do
52
+
53
+ before do
54
+ cloudstack_plugin.should_receive(:can_metadata_connect?).
55
+ with(Ohai::Mixin::CloudstackMetadata::CLOUDSTACK_METADATA_ADDR,80).
56
+ and_return(false)
57
+ end
58
+
59
+ it "does not set any cloudstack data" do
60
+ cloudstack_plugin.run
61
+ expect(ohai_data).to_not have_key("cloudstack")
62
+ end
63
+ end
64
+
65
+ context "and the metadata service is available" do
66
+
67
+ let(:metadata_version) { "latest" }
68
+
69
+ let(:metadata_root) do
70
+ <<EOM
71
+ availability-zone
72
+ cloud-identifier
73
+ instance-id
74
+ local-hostname
75
+ local-ipv4
76
+ public-hostname
77
+ public-ipv4
78
+ service-offering
79
+ vm-id
80
+ EOM
81
+ end
82
+
83
+ let(:metadata_values) do
84
+ {
85
+ "local-ipv4" =>"10.235.34.23",
86
+ "local-hostname" =>"VM-8983fb85-fb7f-46d6-8af1-c1b6666fec39",
87
+ "public-hostname" =>"awesome-doge",
88
+ "availability-zone" =>"TCS7",
89
+ "service-offering" =>"2vCPU, 1GHz, 2GB RAM",
90
+ "public-ipv4" =>"10.235.34.23",
91
+ "vm-id"=>"8983fb85-fb7f-46d6-8af1-c1b6666fec39",
92
+ "cloud-identifier"=>"CloudStack-{e84ff39d-ef64-4812-a8a9-7932f7b67f17}",
93
+ "instance-id"=>"8983fb85-fb7f-46d6-8af1-c1b6666fec39"
94
+ }
95
+ end
96
+
97
+ let(:http_client) { double("Net::HTTP", :read_timeout= => nil) }
98
+
99
+ def expect_get(url, response_body)
100
+ http_client.should_receive(:get).
101
+ with(url).
102
+ and_return(double("HTTP Response", :code => "200", :body => response_body))
103
+ end
104
+
105
+ before do
106
+ cloudstack_plugin.should_receive(:can_metadata_connect?).
107
+ with(Ohai::Mixin::CloudstackMetadata::CLOUDSTACK_METADATA_ADDR,80).
108
+ and_return(true)
109
+
110
+ Net::HTTP.stub(:start).
111
+ with(Ohai::Mixin::CloudstackMetadata::CLOUDSTACK_METADATA_ADDR).
112
+ and_return(http_client)
113
+
114
+ cloudstack_plugin.stub(:best_api_version).and_return(metadata_version)
115
+
116
+ expect_get("/#{metadata_version}/meta-data/", metadata_root)
117
+
118
+ metadata_values.each do |md_id, md_value|
119
+ expect_get("/#{metadata_version}/meta-data/#{md_id}", md_value)
120
+ end
121
+
122
+ cloudstack_plugin.run
123
+ end
124
+
125
+ it "reads the local ipv4 from the metadata service" do
126
+ expect(ohai_data['cloudstack']['local_ipv4']).to eq("10.235.34.23")
127
+ end
128
+ it "reads the local hostname from the metadata service" do
129
+ expect(ohai_data['cloudstack']['local_hostname']).to eq("VM-8983fb85-fb7f-46d6-8af1-c1b6666fec39")
130
+ end
131
+ it "reads the public hostname from the metadata service" do
132
+ expect(ohai_data['cloudstack']['public_hostname']).to eq("awesome-doge")
133
+ end
134
+ it "reads the availability zone from the metadata service" do
135
+ expect(ohai_data['cloudstack']['availability_zone']).to eq("TCS7")
136
+ end
137
+ it "reads the service offering from the metadata service" do
138
+ expect(ohai_data['cloudstack']['service_offering']).to eq("2vCPU, 1GHz, 2GB RAM")
139
+ end
140
+ it "reads the public ipv4 from the metadata service" do
141
+ expect(ohai_data['cloudstack']['public_ipv4']).to eq("10.235.34.23")
142
+ end
143
+ it "reads the vm id from the metadata service" do
144
+ expect(ohai_data['cloudstack']['vm_id']).to eq("8983fb85-fb7f-46d6-8af1-c1b6666fec39")
145
+ end
146
+ it "reads the cloud identifier from the metadata service" do
147
+ expect(ohai_data['cloudstack']['cloud_identifier']).to eq("CloudStack-{e84ff39d-ef64-4812-a8a9-7932f7b67f17}")
148
+ end
149
+ it "reads the instance id from the metadata service" do
150
+ expect(ohai_data['cloudstack']['instance_id']).to eq("8983fb85-fb7f-46d6-8af1-c1b6666fec39")
151
+ end
152
+ end
153
+ end
154
+ end
155
+
@@ -26,8 +26,8 @@ describe Ohai::System, "Darwin cpu plugin" do
26
26
  @plugin.stub(:shell_out).with("sysctl -n hw.physicalcpu").and_return(mock_shell_out(0, "4", ""))
27
27
  @plugin.stub(:shell_out).with("sysctl -n hw.logicalcpu").and_return(mock_shell_out(0, "8", ""))
28
28
  @plugin.stub(:shell_out).with("sysctl -n hw.cpufrequency").and_return(mock_shell_out(0, "2300000000", ""))
29
- @plugin.stub(:shell_out).with("sysctl -n machdep.cpu.vendor").and_return(mock_shell_out(0, "GenuineIntel", ""))
30
- @plugin.stub(:shell_out).with("sysctl -n machdep.cpu.brand_string").and_return(mock_shell_out(0, "Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz", ""))
29
+ @plugin.stub(:shell_out).with("sysctl -n machdep.cpu.vendor").and_return(mock_shell_out(0, "GenuineIntel\n", ""))
30
+ @plugin.stub(:shell_out).with("sysctl -n machdep.cpu.brand_string").and_return(mock_shell_out(0, "Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz\n", ""))
31
31
  @plugin.stub(:shell_out).with("sysctl -n machdep.cpu.model").and_return(mock_shell_out(0, "58", ""))
32
32
  @plugin.stub(:shell_out).with("sysctl -n machdep.cpu.family").and_return(mock_shell_out(0, "6", ""))
33
33
  @plugin.stub(:shell_out).with("sysctl -n machdep.cpu.stepping").and_return(mock_shell_out(0, "9", ""))
@@ -0,0 +1,44 @@
1
+ # Author:: Christian Vozar (<christian@rogueethic.com>)
2
+ # License:: Apache License, Version 2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb'))
17
+
18
+ describe Ohai::System, "plugin go" do
19
+
20
+ before(:each) do
21
+ @plugin = get_plugin("go")
22
+ @plugin[:languages] = Mash.new
23
+ @stdout = "go version go1.1.2 darwin/amd64\n"
24
+ @plugin.stub(:shell_out).with("go version").and_return(mock_shell_out(0, @stdout, ""))
25
+ end
26
+
27
+ it "should get the go version" do
28
+ @plugin.should_receive(:shell_out).with("go version").and_return(mock_shell_out(0, @stdout, ""))
29
+ @plugin.run
30
+ end
31
+
32
+ it "should set languages[:go][:version]" do
33
+ @plugin.run
34
+ @plugin.languages[:go][:version].should eql("1.1.2")
35
+ end
36
+
37
+ it "should not set the languages[:go] tree up if go command fails" do
38
+ @stdout = "go version go1.1.2 darwin/amd64\n"
39
+ @plugin.stub(:shell_out).with("go version").and_return(mock_shell_out(1, @stdout, ""))
40
+ @plugin.run
41
+ @plugin.languages.should_not have_key(:go)
42
+ end
43
+
44
+ end