ohai 8.21.0 → 8.22.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9adc486c591d6c788a28df54f4b3019649143fbf
4
- data.tar.gz: 84178b71f088420c0f8aa6162bb8c16ab6ec117c
3
+ metadata.gz: 5450323d46bf0e6a5873dbd19775b0f4b7838c52
4
+ data.tar.gz: b7bc92127e595759e568f5fb9003d72ceecac6f2
5
5
  SHA512:
6
- metadata.gz: ed8f9a5cc316288abffcde24a126b76de94e9160c4c1a4220881759700fdb60ee2a9cb8808f8bd621b8be903b881aa5d62d384e059c3e15b18d652a2f7060d3c
7
- data.tar.gz: c8720f2368a29fab4f218f4035992d07a3b02370a6e121edd5cb0bf9198bf54e7e7c99aea6d1d0238b5e2905d1237ded01cba89d64f793cce6473b72562af432
6
+ metadata.gz: 632c0e8f303df696ab2fa0ce036e29f9b367c761098567e4ece04b1c8f6a886364a46b20fa0cd3e45d341987882acc204825d4e5005646ced30eed1c64a2c88d
7
+ data.tar.gz: 39559a677849038047b04e56eff44975d5d8710b429946926bdecad79a6d36ee4172d48a2d963ffb872f28967fa87113383a1ffd1a4998d9e7eeabb94e48f7d7
data/Gemfile CHANGED
@@ -5,9 +5,17 @@ gemspec
5
5
  group :development do
6
6
  gem "sigar", :platform => "ruby"
7
7
 
8
- gem "chefstyle", "= 0.4.0"
8
+ gem "chefstyle"
9
9
  gem "overcommit", ">= 0.34.1"
10
10
  gem "pry-byebug"
11
11
  gem "pry-stack_explorer"
12
12
  gem "rb-readline"
13
+ gem "rake", ">= 10.1.0", "< 12.0.0"
14
+ gem "rspec-core", "~> 3.0"
15
+ gem "rspec-expectations", "~> 3.0"
16
+ gem "rspec-mocks", "~> 3.0"
17
+ gem "rspec-collection_matchers", "~> 1.0"
18
+ gem "rspec_junit_formatter"
19
+ gem "github_changelog_generator", ">= 1.14"
20
+ gem "activesupport", "< 5.0" if RUBY_VERSION <= "2.2.2" # github_changelog_generator dep
13
21
  end
data/Rakefile CHANGED
@@ -27,6 +27,8 @@ require "github_changelog_generator/task"
27
27
 
28
28
  GitHubChangelogGenerator::RakeTask.new :changelog do |config|
29
29
  config.future_release = Ohai::VERSION
30
+ config.max_issues = 0
31
+ config.add_issues_wo_labels = false
30
32
  config.enhancement_labels = "enhancement,Enhancement,New Feature,Feature".split(",")
31
33
  config.bug_labels = "bug,Bug,Improvement,Upstream Bug".split(",")
32
34
  config.exclude_labels = "duplicate,question,invalid,wontfix,no_changelog,Exclude From Changelog,Question,Discussion".split(",")
@@ -154,8 +154,19 @@ module Ohai
154
154
  end
155
155
  end
156
156
 
157
- def set_attribute(name, *values)
158
- @data[name] = Array18(*values)
157
+ def set_attribute(name, *attrs, value)
158
+ # Initialize the path in the @data Mash with new Mashes, if needed.
159
+ # Will raise a TypeError if we hit a subattribute that is not a
160
+ # Hash, Mash, or Array.
161
+ keys = [name] + attrs
162
+ attribute = keys[0..-2].inject(@data) do |attrs, key|
163
+ attrs[key] ||= Mash.new
164
+ attrs[key]
165
+ end
166
+
167
+ # Set the subattribute to the value.
168
+ attr_name = attrs.empty? ? name : attrs[-1]
169
+ attribute[attr_name] = value
159
170
  @data[name]
160
171
  end
161
172
 
@@ -198,12 +209,6 @@ module Ohai
198
209
  # NoMethodError occurs when trying to access a key on nil
199
210
  nil
200
211
  end
201
-
202
- def Array18(*args)
203
- return nil if args.empty?
204
- return args.first if args.length == 1
205
- return *args
206
- end
207
212
  end
208
213
  end
209
214
  end
@@ -0,0 +1,95 @@
1
+ # Author:: Chris Dituri (<csdituri@gmail.com>)
2
+ # Copyright:: Copyright (c) 2016 Chris Dituri
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ Ohai.plugin(:Haskell) do
18
+
19
+ provides "languages/haskell",
20
+ "languages/haskell/ghc",
21
+ "languages/haskell/ghci",
22
+ "languages/haskell/cabal",
23
+ "languages/haskell/stack"
24
+
25
+ depends "languages"
26
+
27
+ collect_data(:default) do
28
+ haskell = Mash.new
29
+
30
+ # Check for ghc
31
+ begin
32
+ so = shell_out("ghc --version")
33
+
34
+ # Sample output:
35
+ # The Glorious Glasgow Haskell Compilation System, version 7.6.3
36
+ if so.exitstatus == 0
37
+ haskell[:ghc] = Mash.new
38
+ haskell[:ghc][:version] = so.stdout.split[-1]
39
+ haskell[:ghc][:description] = so.stdout.chomp
40
+ end
41
+ rescue Ohai::Exceptions::Exec
42
+ Ohai::Log.debug('Haskell plugin: Could not shell_out "ghc --version". Skipping data')
43
+ end
44
+
45
+ # Check for ghci
46
+ begin
47
+ so = shell_out("ghci --version")
48
+
49
+ # Sample output:
50
+ # The Glorious Glasgow Haskell Compilation System, version 7.6.3
51
+ if so.exitstatus == 0
52
+ haskell[:ghci] = Mash.new
53
+ haskell[:ghci][:version] = so.stdout.split[-1]
54
+ haskell[:ghci][:description] = so.stdout.chomp
55
+ end
56
+ rescue Ohai::Exceptions::Exec
57
+ Ohai::Log.debug('Haskell plugin: Could not shell_out "ghci --version". Skipping data')
58
+ end
59
+
60
+ # Check for cabal
61
+ begin
62
+ so = shell_out("cabal --version")
63
+
64
+ # Sample output:
65
+ # cabal-install version 1.16.0.2
66
+ # using version 1.16.0 of the Cabal library
67
+ if so.exitstatus == 0
68
+ haskell[:cabal] = Mash.new
69
+ haskell[:cabal][:version] = so.stdout.split("\n")[0].split[-1]
70
+ haskell[:cabal][:description] = so.stdout.split("\n")[0].chomp
71
+ end
72
+ rescue Ohai::Exceptions::Exec
73
+ Ohai::Log.debug('Haskell plugin: Could not shell_out "cabal --version". Skipping data')
74
+ end
75
+
76
+ # Check for stack
77
+ begin
78
+ so = shell_out("stack --version")
79
+
80
+ # Sample output:
81
+ # Version 1.1.0, Git revision 0e9430aad55841b5ff2c6c2851f0548c16bce7cf (3540 commits) x86_64 hpack-0.13.0
82
+ # or
83
+ # Version 1.2.0 x86_64 hpack-0.14.0
84
+ if so.exitstatus == 0
85
+ haskell[:stack] = Mash.new
86
+ haskell[:stack][:version] = /Version ([^\s,]*)/.match(so.stdout)[1] rescue nil
87
+ haskell[:stack][:description] = so.stdout.chomp
88
+ end
89
+ rescue Ohai::Exceptions::Exec
90
+ Ohai::Log.debug('Haskell plugin: Could not shell_out "stack --version". Skipping data')
91
+ end
92
+
93
+ languages[:haskell] = haskell unless haskell.empty?
94
+ end
95
+ end
@@ -105,13 +105,38 @@ Ohai.plugin(:Hostname) do
105
105
  collect_domain
106
106
  end
107
107
 
108
- collect_data(:darwin, :netbsd, :openbsd, :dragonflybsd) do
108
+ collect_data(:netbsd, :openbsd, :dragonflybsd) do
109
109
  hostname from_cmd("hostname -s")
110
110
  fqdn resolve_fqdn
111
111
  machinename from_cmd("hostname")
112
112
  collect_domain
113
113
  end
114
114
 
115
+ collect_data(:darwin) do
116
+ hostname from_cmd("hostname -s")
117
+ machinename from_cmd("hostname")
118
+ begin
119
+ ourfqdn = resolve_fqdn
120
+ # Sometimes... very rarely, but sometimes, 'hostname --fqdn' falsely
121
+ # returns a blank string. WTF.
122
+ if ourfqdn.nil? || ourfqdn.empty?
123
+ Ohai::Log.debug("hostname returned an empty string, retrying once.")
124
+ ourfqdn = resolve_fqdn
125
+ end
126
+
127
+ if ourfqdn.nil? || ourfqdn.empty?
128
+ Ohai::Log.debug("hostname returned an empty string twice and will" +
129
+ "not be set.")
130
+ else
131
+ fqdn ourfqdn
132
+ end
133
+ rescue
134
+ Ohai::Log.debug(
135
+ "hostname returned an error, probably no domain set")
136
+ end
137
+ domain collect_domain
138
+ end
139
+
115
140
  collect_data(:freebsd) do
116
141
  hostname from_cmd("hostname -s")
117
142
  machinename from_cmd("hostname")
@@ -32,7 +32,7 @@ Ohai.plugin(:IpScopes) do
32
32
  begin
33
33
  attrs["ip_scope"] = address.to_ip.scope
34
34
 
35
- if private_addr?(address) && !tunnel_iface?(interface)
35
+ if private_addr?(address) && !tunnel_iface?(interface) && !ppp_iface?(interface) && !docker_iface?(interface)
36
36
  privateaddress(address)
37
37
  end
38
38
  rescue ArgumentError
@@ -51,7 +51,15 @@ Ohai.plugin(:IpScopes) do
51
51
  address.to_ip.scope =~ /PRIVATE/
52
52
  end
53
53
 
54
- def tunnel_iface?(interface)
54
+ def ppp_iface?(interface)
55
55
  interface["type"] == "ppp"
56
56
  end
57
+
58
+ def tunnel_iface?(interface)
59
+ interface["type"] == "tunl"
60
+ end
61
+
62
+ def docker_iface?(interface)
63
+ interface["type"] == "docker"
64
+ end
57
65
  end
@@ -25,23 +25,18 @@ Ohai.plugin(:Joyent) do
25
25
  depends "os", "platform", "virtualization"
26
26
 
27
27
  def collect_product_file
28
- lines = []
29
- if ::File.exists?("/etc/product")
30
- ::File.open("/etc/product") do |file|
31
- while line = file.gets
32
- lines << line
33
- end
34
- end
28
+ data = ::File.read("/etc/product") rescue nil
29
+ if data
30
+ data.strip.split("\n")
31
+ else
32
+ []
35
33
  end
36
- lines
37
34
  end
38
35
 
39
36
  def collect_pkgsrc
40
- if File.exist?("/opt/local/etc/pkg_install.conf")
41
- sm_pkgsrc = ::File.read("/opt/local/etc/pkg_install.conf").split("=")
42
- sm_pkgsrc[1].chomp
43
- else
44
- nil
37
+ data = ::File.read("/opt/local/etc/pkg_install.conf") rescue nil
38
+ if data
39
+ /PKG_PATH=(.*)/.match(data)[1] rescue nil
45
40
  end
46
41
  end
47
42
 
@@ -76,7 +71,7 @@ Ohai.plugin(:Joyent) do
76
71
  end
77
72
 
78
73
  ## retrieve pkgsrc
79
- joyent[:sm_pkgsrc] = collect_pkgsrc if collect_pkgsrc
74
+ joyent[:sm_pkgsrc] = collect_pkgsrc
80
75
  end
81
76
  end
82
77
  end
@@ -22,21 +22,8 @@ Ohai.plugin(:LSB) do
22
22
  collect_data(:linux) do
23
23
  lsb Mash.new
24
24
 
25
- if File.exists?("/etc/lsb-release")
26
- File.open("/etc/lsb-release").each do |line|
27
- case line
28
- when /^DISTRIB_ID=["']?(.+?)["']?$/
29
- lsb[:id] = $1
30
- when /^DISTRIB_RELEASE=["']?(.+?)["']?$/
31
- lsb[:release] = $1
32
- when /^DISTRIB_CODENAME=["']?(.+?)["']?$/
33
- lsb[:codename] = $1
34
- when /^DISTRIB_DESCRIPTION=["']?(.+?)["']?$/
35
- lsb[:description] = $1
36
- end
37
- end
38
- elsif File.exists?("/usr/bin/lsb_release")
39
- # Fedora/Redhat, requires redhat-lsb package
25
+ if File.exists?("/usr/bin/lsb_release")
26
+ # From package redhat-lsb on Fedora/Redhat, lsb-release on Debian/Ubuntu
40
27
  so = shell_out("lsb_release -a")
41
28
  so.stdout.lines do |line|
42
29
  case line
@@ -52,6 +39,20 @@ Ohai.plugin(:LSB) do
52
39
  lsb[:id] = line
53
40
  end
54
41
  end
42
+ elsif File.exists?("/etc/lsb-release")
43
+ # Old, non-standard Debian support
44
+ File.open("/etc/lsb-release").each do |line|
45
+ case line
46
+ when /^DISTRIB_ID=["']?(.+?)["']?$/
47
+ lsb[:id] = $1
48
+ when /^DISTRIB_RELEASE=["']?(.+?)["']?$/
49
+ lsb[:release] = $1
50
+ when /^DISTRIB_CODENAME=["']?(.+?)["']?$/
51
+ lsb[:codename] = $1
52
+ when /^DISTRIB_DESCRIPTION=["']?(.+?)["']?$/
53
+ lsb[:description] = $1
54
+ end
55
+ end
55
56
  else
56
57
  Ohai::Log.debug("Skipping LSB, cannot find /etc/lsb-release or /usr/bin/lsb_release")
57
58
  end
@@ -74,7 +74,11 @@ Ohai.plugin(:Virtualization) do
74
74
 
75
75
  if zones.length == 1
76
76
  first_zone = zones.keys[0]
77
- unless first_zone == "global"
77
+ if first_zone == "global"
78
+ virtualization[:system] = "zone"
79
+ virtualization[:role] = "host"
80
+ virtualization[:systems][:zone] = "host"
81
+ else
78
82
  virtualization[:system] = "zone"
79
83
  virtualization[:role] = "guest"
80
84
  virtualization[:systems][:zone] = "guest"
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = "8.21.0"
21
+ VERSION = "8.22.0"
22
22
  end
@@ -35,18 +35,6 @@ Gem::Specification.new do |s|
35
35
  # Chef 13 starts, otherwise builds will break.
36
36
  s.add_dependency "chef-config", ">= 12.5.0.alpha.1", "< 13"
37
37
 
38
- s.add_development_dependency "rake", ">= 10.1.0", "< 12.0.0"
39
- s.add_development_dependency "rspec-core", "~> 3.0"
40
- s.add_development_dependency "rspec-expectations", "~> 3.0"
41
- s.add_development_dependency "rspec-mocks", "~> 3.0"
42
- s.add_development_dependency "rspec-collection_matchers", "~> 1.0"
43
- s.add_development_dependency "rspec_junit_formatter"
44
- s.add_development_dependency "github_changelog_generator", "1.13.1"
45
-
46
- # github_changelog_generator -> github-api -> oauth2 -> rack
47
- # rack being unconstrained breaks Ruby 2.1 installs
48
- s.add_development_dependency "rack", "~> 1.0"
49
-
50
38
  s.bindir = "bin"
51
39
  s.executables = %w{ohai}
52
40
 
@@ -109,8 +109,6 @@ RSpec.configure do |config|
109
109
 
110
110
  config.filter_run_excluding :windows_only => true unless windows?
111
111
  config.filter_run_excluding :unix_only => true unless unix?
112
- config.filter_run_excluding :ruby_18_only => true unless ruby_18?
113
- config.filter_run_excluding :ruby_19_only => true unless ruby_19?
114
112
  config.filter_run_excluding :requires_root => true unless ENV["USER"] == "root"
115
113
  config.filter_run_excluding :requires_unprivileged_user => true if ENV["USER"] == "root"
116
114
 
@@ -1,17 +1,7 @@
1
- def ruby_19?
2
- !!(RUBY_VERSION =~ /^1.9/)
3
- end
4
-
5
- def ruby_18?
6
- !!(RUBY_VERSION =~ /^1.8/)
7
- end
8
-
9
1
  def windows?
10
2
  !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
11
3
  end
12
4
 
13
- # def jruby?
14
-
15
5
  def unix?
16
6
  !windows?
17
7
  end
@@ -90,11 +90,68 @@ shared_examples "Ohai::DSL::Plugin" do
90
90
  end
91
91
  end
92
92
 
93
- context "when setting attributes" do
93
+ describe "set_attribute" do
94
+ it "raises an ArgumentError when given one argument" do
95
+ expect { plugin.set_attribute(:tea) }.to raise_error(ArgumentError)
96
+ end
97
+
94
98
  it "lets you set an attribute" do
95
99
  plugin.set_attribute(:tea, "is soothing")
96
100
  expect(plugin.data["tea"]).to eql("is soothing")
97
101
  end
102
+
103
+ it "lets you set an attribute to an empty array" do
104
+ plugin.set_attribute(:tea, [])
105
+ expect(plugin.data["tea"]).to eql([])
106
+ end
107
+
108
+ it "lets you set an attribute to an empty Mash" do
109
+ plugin.set_attribute(:tea, {})
110
+ expect(plugin.data["tea"]).to eql({})
111
+ end
112
+
113
+ it "lets you modify an attribute" do
114
+ plugin.data["tea"] = "is soothing"
115
+ plugin.set_attribute(:tea, "tastes like plants")
116
+ expect(plugin.data["tea"]).to eql("tastes like plants")
117
+ end
118
+
119
+ it "lets you set a subattribute" do
120
+ plugin.data["tea"] = Mash.new
121
+ plugin.set_attribute(:tea, :green, "tastes like green")
122
+ expect(plugin.data["tea"]["green"]).to eql("tastes like green")
123
+ end
124
+
125
+ it "lets you set a subattribute to an empty array" do
126
+ plugin.set_attribute(:tea, :green, [])
127
+ expect(plugin.data["tea"]["green"]).to eql([])
128
+ end
129
+
130
+ it "lets you set a subattribute to an empty Mash" do
131
+ plugin.set_attribute(:tea, :green, {})
132
+ expect(plugin.data["tea"]["green"]).to eql({})
133
+ end
134
+
135
+ it "lets you modify a subattribute" do
136
+ plugin.data["tea"] = Mash.new
137
+ plugin.data["tea"]["green"] = "tastes like green"
138
+ plugin.set_attribute(:tea, :green, "made from leaves")
139
+ expect(plugin.data["tea"]["green"]).to eql("made from leaves")
140
+ end
141
+
142
+ it "raises a TypeError when modifying an attribute that is not a Mash" do
143
+ plugin.data["tea"] = Mash.new
144
+ plugin.data["tea"] = "is soothing"
145
+ expect { plugin.set_attribute(:tea, :green, "tastes like green") }.to raise_error(TypeError)
146
+ end
147
+
148
+ it "lets you modify a subattribute with an array" do
149
+ green = { flavor: "tastes like green" }
150
+ black = { flavor: "tastes like black" }
151
+ plugin.data[:tea] = [green, black]
152
+ plugin.set_attribute(:tea, 0, :source, "made from leaves")
153
+ expect(plugin.data[:tea][0][:source]).to eq("made from leaves")
154
+ end
98
155
  end
99
156
 
100
157
  context "when getting attributes" do
@@ -0,0 +1,231 @@
1
+ # Author:: Chris Dituri (<csdituri@gmail.com>)
2
+ # Copyright:: Copyright (c) 2016 Chris Dituri
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb"))
18
+
19
+ describe Ohai::System, "plugin haskell" do
20
+
21
+ let(:plugin) do
22
+ plugin = get_plugin("haskell").tap do |plugin|
23
+ plugin[:languages] = Mash.new
24
+ end
25
+ end
26
+
27
+ let(:ghc_out) { "The Glorious Glasgow Haskell Compilation System, version 7.6.3" }
28
+ let(:ghci_out) { "The Glorious Glasgow Haskell Compilation System, version 7.6.3" }
29
+ let(:cabal_out) { "cabal-install version 1.16.0.2\nusing version 1.16.0 of the Cabal library" }
30
+ let(:stack_out) { "Version 1.2.0 x86_64 hpack-0.14.0" }
31
+ let(:stack_out_git) { "Version 1.1.0, Git revision 0e9430aad55841b5ff2c6c2851f0548c16bce7cf (3540 commits) x86_64 hpack-0.13.0" }
32
+
33
+ def setup_plugin
34
+ allow(plugin).to receive(:shell_out)
35
+ .with("ghc --version")
36
+ .and_return(mock_shell_out(0, ghc_out, ""))
37
+ allow(plugin).to receive(:shell_out)
38
+ .with("ghci --version")
39
+ .and_return(mock_shell_out(0, ghci_out, ""))
40
+ allow(plugin).to receive(:shell_out)
41
+ .with("cabal --version")
42
+ .and_return(mock_shell_out(0, cabal_out, ""))
43
+ allow(plugin).to receive(:shell_out)
44
+ .with("stack --version")
45
+ .and_return(mock_shell_out(0, stack_out, ""))
46
+ end
47
+
48
+ context "if haskell/ghc is installed" do
49
+
50
+ before(:each) do
51
+ setup_plugin
52
+ plugin.run
53
+ end
54
+
55
+ it "set languages[:haskell][:ghc][:version]" do
56
+ expect(plugin[:languages][:haskell][:ghc][:version]).to eql("7.6.3")
57
+ end
58
+
59
+ it "set languages[:haskell][:ghc][:description]" do
60
+ expect(plugin[:languages][:haskell][:ghc][:description]).to eql(ghc_out)
61
+ end
62
+ end
63
+
64
+ context "if haskell/ghci is installed" do
65
+
66
+ before(:each) do
67
+ setup_plugin
68
+ plugin.run
69
+ end
70
+
71
+ it "set languages[:haskell][:ghci][:version]" do
72
+ expect(plugin[:languages][:haskell][:ghci][:version]).to eql("7.6.3")
73
+ end
74
+
75
+ it "set languages[:haskell][:ghci][:description]" do
76
+ expect(plugin[:languages][:haskell][:ghci][:description]).to eql(ghci_out)
77
+ end
78
+ end
79
+
80
+ context "if haskell/cabal is installed" do
81
+
82
+ before(:each) do
83
+ setup_plugin
84
+ plugin.run
85
+ end
86
+
87
+ it "set languages[:haskell][:cabal][:version]" do
88
+ expect(plugin[:languages][:haskell][:cabal][:version]).to eql("1.16.0.2")
89
+ end
90
+
91
+ it "set languages[:haskell][:cabal][:description]" do
92
+ expect(plugin[:languages][:haskell][:cabal][:description]).to eql(cabal_out.split("\n")[0].chomp)
93
+ end
94
+ end
95
+
96
+ context "if haskell/stack is installed" do
97
+
98
+ before(:each) do
99
+ setup_plugin
100
+ plugin.run
101
+ end
102
+
103
+ it "set languages[:haskell][:stack][:version]" do
104
+ expect(plugin[:languages][:haskell][:stack][:version]).to eql("1.2.0")
105
+ end
106
+
107
+ it "set languages[:haskell][:stack][:description]" do
108
+ expect(plugin[:languages][:haskell][:stack][:description]).to eql(stack_out)
109
+ end
110
+ end
111
+
112
+ context "if haskell/stack prerelease is installed" do
113
+
114
+ before(:each) do
115
+ setup_plugin
116
+ allow(plugin).to receive(:shell_out)
117
+ .with("stack --version")
118
+ .and_return(mock_shell_out(0, stack_out_git, ""))
119
+ plugin.run
120
+ end
121
+
122
+ it "set languages[:haskell][:stack][:version]" do
123
+ expect(plugin[:languages][:haskell][:stack][:version]).to eql("1.1.0")
124
+ end
125
+
126
+ it "set languages[:haskell][:stack][:description]" do
127
+ expect(plugin[:languages][:haskell][:stack][:description]).to eql(stack_out_git)
128
+ end
129
+ end
130
+
131
+ context "if haskell is NOT installed" do
132
+
133
+ before(:each) do
134
+ allow(plugin).to receive(:shell_out)
135
+ .and_raise( Ohai::Exceptions::Exec )
136
+ plugin.run
137
+ end
138
+
139
+ it "do NOT set languages[:haskell]" do
140
+ expect(plugin[:languages]).not_to have_key(:haskell)
141
+ end
142
+ end
143
+
144
+ context "if haskell/ghc is NOT installed" do
145
+ before(:each) do
146
+ allow(plugin).to receive(:shell_out)
147
+ .with("ghc --version")
148
+ .and_raise( Ohai::Exceptions::Exec )
149
+ allow(plugin).to receive(:shell_out)
150
+ .with("ghci --version")
151
+ .and_return(mock_shell_out(0, ghci_out, ""))
152
+ allow(plugin).to receive(:shell_out)
153
+ .with("cabal --version")
154
+ .and_return(mock_shell_out(0, cabal_out, ""))
155
+ allow(plugin).to receive(:shell_out)
156
+ .with("stack --version")
157
+ .and_return(mock_shell_out(0, stack_out, ""))
158
+ plugin.run
159
+ end
160
+
161
+ it "do NOT set languages[:haskell][:ghc]" do
162
+ expect(plugin[:languages][:haskell]).not_to have_key(:ghc)
163
+ end
164
+ end
165
+
166
+ context "if haskell/ghci is NOT installed" do
167
+ before(:each) do
168
+ allow(plugin).to receive(:shell_out)
169
+ .with("ghc --version")
170
+ .and_return(mock_shell_out(0, ghc_out, ""))
171
+ allow(plugin).to receive(:shell_out)
172
+ .with("ghci --version")
173
+ .and_raise( Ohai::Exceptions::Exec )
174
+ allow(plugin).to receive(:shell_out)
175
+ .with("cabal --version")
176
+ .and_return(mock_shell_out(0, cabal_out, ""))
177
+ allow(plugin).to receive(:shell_out)
178
+ .with("stack --version")
179
+ .and_return(mock_shell_out(0, stack_out, ""))
180
+ plugin.run
181
+ end
182
+
183
+ it "do NOT set languages[:haskell][:ghci]" do
184
+ expect(plugin[:languages][:haskell]).not_to have_key(:ghci)
185
+ end
186
+ end
187
+
188
+ context "if haskell/cabal is NOT installed" do
189
+ before(:each) do
190
+ allow(plugin).to receive(:shell_out)
191
+ .with("ghc --version")
192
+ .and_return(mock_shell_out(0, ghc_out, ""))
193
+ allow(plugin).to receive(:shell_out)
194
+ .with("ghci --version")
195
+ .and_return(mock_shell_out(0, ghci_out, ""))
196
+ allow(plugin).to receive(:shell_out)
197
+ .with("cabal --version")
198
+ .and_raise( Ohai::Exceptions::Exec )
199
+ allow(plugin).to receive(:shell_out)
200
+ .with("stack --version")
201
+ .and_return(mock_shell_out(0, stack_out, ""))
202
+ plugin.run
203
+ end
204
+
205
+ it "do NOT set languages[:haskell][:cabal]" do
206
+ expect(plugin[:languages][:haskell]).not_to have_key(:cabal)
207
+ end
208
+ end
209
+
210
+ context "if haskell/stack is NOT installed" do
211
+ before(:each) do
212
+ allow(plugin).to receive(:shell_out)
213
+ .with("ghc --version")
214
+ .and_return(mock_shell_out(0, ghc_out, ""))
215
+ allow(plugin).to receive(:shell_out)
216
+ .with("ghci --version")
217
+ .and_return(mock_shell_out(0, ghci_out, ""))
218
+ allow(plugin).to receive(:shell_out)
219
+ .with("cabal --version")
220
+ .and_return(mock_shell_out(0, cabal_out, ""))
221
+ allow(plugin).to receive(:shell_out)
222
+ .with("stack --version")
223
+ .and_raise( Ohai::Exceptions::Exec )
224
+ plugin.run
225
+ end
226
+
227
+ it "do NOT set languages[:haskell][:stack]" do
228
+ expect(plugin[:languages][:haskell]).not_to have_key(:stack)
229
+ end
230
+ end
231
+ end
@@ -11,13 +11,17 @@ describe Ohai::System, "plugin ip_scopes" do
11
11
  let(:interfaces) do
12
12
  Hash[
13
13
  interface1, { :addresses => addresses1, :type => interface1_type },
14
- interface2, { :addresses => addresses2, :type => interface2_type }] end
14
+ interface2, { :addresses => addresses2, :type => interface2_type },
15
+ interface3, { :addresses => addresses3, :type => interface3_type }] end
15
16
  let(:interface1) { :eth0 }
16
17
  let(:interface2) { :eth1 }
18
+ let(:interface3) { :eth2 }
17
19
  let(:addresses1) { {} }
18
20
  let(:addresses2) { {} }
21
+ let(:addresses3) { {} }
19
22
  let(:interface1_type) { "eth" }
20
23
  let(:interface2_type) { "eth" }
24
+ let(:interface3_type) { "eth" }
21
25
 
22
26
  before { plugin[:network] = network }
23
27
 
@@ -62,11 +66,36 @@ describe Ohai::System, "plugin ip_scopes" do
62
66
  end
63
67
  end
64
68
 
69
+ context "when host has tunl" do
70
+ let(:ip1) { "10.0.0.1" }
71
+ let(:ip2) { "192.168.1.1" }
72
+ let(:interface1_type) { "eth" }
73
+ let(:interface2_type) { "tunl" }
74
+
75
+ it "picks the non-virtual address" do
76
+ expect(plugin[:privateaddress]).to eq("10.0.0.1")
77
+ end
78
+ end
79
+
80
+ context "when host has docker" do
81
+ let(:ip1) { "10.0.0.1" }
82
+ let(:ip2) { "192.168.1.1" }
83
+ let(:interface1_type) { "eth" }
84
+ let(:interface2_type) { "docker" }
85
+
86
+ it "picks the non-virtual address" do
87
+ expect(plugin[:privateaddress]).to eq("10.0.0.1")
88
+ end
89
+ end
90
+
65
91
  context "when host only has virtual RFC1918 addresses" do
66
92
  let(:ip1) { "10.0.0.1" }
67
93
  let(:ip2) { "192.168.1.1" }
94
+ let(:ip3) { "172.16.1.1" }
95
+
68
96
  let(:interface1_type) { "ppp" }
69
- let(:interface2_type) { "ppp" }
97
+ let(:interface2_type) { "tunl" }
98
+ let(:interface3_type) { "docker" }
70
99
 
71
100
  it "ignores them" do
72
101
  expect(plugin[:privateaddress]).to be nil
@@ -1,71 +1,83 @@
1
- require "spec_helper"
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb"))
2
2
 
3
3
  describe Ohai::System, "plugin joyent" do
4
- before(:each) do
5
- @plugin = get_plugin("joyent")
6
- end
4
+ let(:plugin) { get_plugin("joyent") }
7
5
 
8
6
  describe "without joyent" do
9
7
  before(:each) do
10
- allow(@plugin).to receive(:is_smartos?).and_return(false)
8
+ allow(plugin).to receive(:is_smartos?).and_return(false)
11
9
  end
12
10
 
13
- it "should NOT create joyent" do
14
- @plugin.run
15
- expect(@plugin[:joyent]).to be_nil
11
+ it "DOES NOT create joyent mash" do
12
+ plugin.run
13
+ expect(plugin[:joyent]).to be_nil
16
14
  end
17
15
  end
18
16
 
19
17
  describe "with joyent" do
20
18
  before(:each) do
21
- allow(@plugin).to receive(:is_smartos?).and_return(true)
22
- @plugin[:virtualization] = Mash.new
23
- @plugin[:virtualization][:guest_uuid] = "global"
19
+ allow(plugin).to receive(:is_smartos?).and_return(true)
20
+ plugin[:virtualization] = Mash.new
21
+ plugin[:virtualization][:guest_uuid] = "global"
24
22
  end
25
23
 
26
- it "should create joyent" do
27
- @plugin.run
28
- expect(@plugin[:joyent]).not_to be_nil
24
+ it "creates joyent mash" do
25
+ plugin.run
26
+ expect(plugin[:joyent]).not_to be_nil
29
27
  end
30
28
 
31
29
  describe "under global zone" do
32
30
  before(:each) do
33
- @plugin.run
31
+ plugin.run
34
32
  end
35
33
 
36
- it "should ditect global zone" do
37
- expect(@plugin[:joyent][:sm_uuid]).to eql "global"
34
+ it "detects global zone" do
35
+ expect(plugin[:joyent][:sm_uuid]).to eql "global"
38
36
  end
39
37
 
40
- it "should NOT create sm_id" do
41
- expect(@plugin[:joyent][:sm_id]).to be_nil
38
+ it "DOES NOT create sm_id" do
39
+ expect(plugin[:joyent][:sm_id]).to be_nil
42
40
  end
43
41
  end
44
42
 
45
43
  describe "under smartmachine" do
46
44
  before(:each) do
47
- @plugin[:virtualization][:guest_uuid] = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"
48
- @plugin[:virtualization][:guest_id] = "30"
49
- allow(@plugin).to receive(:collect_product_file).and_return(["Name: Joyent Instance", "Image: base64 13.4.2", "Documentation: http://wiki.joyent.com/jpc2/SmartMachine+Base"])
50
- allow(@plugin).to receive(:collect_pkgsrc).and_return("http://pkgsrc.joyent.com/packages/SmartOS/2013Q4/x86_64/All")
51
- @plugin.run
45
+ plugin[:virtualization][:guest_uuid] = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"
46
+ plugin[:virtualization][:guest_id] = "30"
47
+
48
+ etc_product = <<-EOS
49
+ Name: Joyent Instance
50
+ Image: pkgbuild 16.3.1
51
+ Documentation: https://docs.joyent.com/images/smartos/pkgbuild
52
+ EOS
53
+
54
+ pkg_install_conf = <<-EOS
55
+ GPG_KEYRING_VERIFY=/opt/local/etc/gnupg/pkgsrc.gpg
56
+ GPG_KEYRING_PKGVULN=/opt/local/share/gnupg/pkgsrc-security.gpg
57
+ PKG_PATH=https://pkgsrc.joyent.com/packages/SmartOS/2016Q3/x86_64/All
58
+ VERIFIED_INSTALLATION=trusted
59
+ EOS
60
+
61
+ allow(::File).to receive(:read).with("/etc/product").and_return(etc_product)
62
+ allow(::File).to receive(:read).with("/opt/local/etc/pkg_install.conf").and_return(pkg_install_conf)
63
+ plugin.run
52
64
  end
53
65
 
54
- it "should retrive zone uuid" do
55
- expect(@plugin[:joyent][:sm_uuid]).to eql "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"
66
+ it "retrieves zone uuid" do
67
+ expect(plugin[:joyent][:sm_uuid]).to eql "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"
56
68
  end
57
69
 
58
- it "should collect sm_id" do
59
- expect(@plugin[:joyent][:sm_id]).to eql "30"
70
+ it "collects sm_id" do
71
+ expect(plugin[:joyent][:sm_id]).to eql "30"
60
72
  end
61
73
 
62
- it "should collect images" do
63
- expect(@plugin[:joyent][:sm_image_id]).not_to be_nil
64
- expect(@plugin[:joyent][:sm_image_ver]).not_to be_nil
74
+ it "collects images" do
75
+ expect(plugin[:joyent][:sm_image_id]).to eql "pkgbuild"
76
+ expect(plugin[:joyent][:sm_image_ver]).to eql "16.3.1"
65
77
  end
66
78
 
67
- it "should collect pkgsrc" do
68
- expect(@plugin[:joyent][:sm_pkgsrc]).to eql "http://pkgsrc.joyent.com/packages/SmartOS/2013Q4/x86_64/All"
79
+ it "collects pkgsrc" do
80
+ expect(plugin[:joyent][:sm_pkgsrc]).to eql "https://pkgsrc.joyent.com/packages/SmartOS/2016Q3/x86_64/All"
69
81
  end
70
82
  end
71
83
  end
@@ -35,6 +35,7 @@ describe Ohai::System, "Linux lsb plugin" do
35
35
  and_yield("DISTRIB_CODENAME=hardy").
36
36
  and_yield('DISTRIB_DESCRIPTION="Ubuntu 8.04"')
37
37
  allow(File).to receive(:open).with("/etc/lsb-release").and_return(@double_file)
38
+ allow(File).to receive(:exists?).with("/usr/bin/lsb_release").and_return(false)
38
39
  allow(File).to receive(:exists?).with("/etc/lsb-release").and_return(true)
39
40
  end
40
41
 
@@ -61,7 +62,6 @@ describe Ohai::System, "Linux lsb plugin" do
61
62
 
62
63
  describe "on systems with /usr/bin/lsb_release" do
63
64
  before(:each) do
64
- allow(File).to receive(:exists?).with("/etc/lsb-release").and_return(false)
65
65
  allow(File).to receive(:exists?).with("/usr/bin/lsb_release").and_return(true)
66
66
 
67
67
  @stdin = double("STDIN", { :close => true })
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.21.0
4
+ version: 8.22.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: 2016-10-18 00:00:00.000000000 Z
11
+ date: 2016-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: systemu
@@ -176,124 +176,6 @@ dependencies:
176
176
  - - "<"
177
177
  - !ruby/object:Gem::Version
178
178
  version: '13'
179
- - !ruby/object:Gem::Dependency
180
- name: rake
181
- requirement: !ruby/object:Gem::Requirement
182
- requirements:
183
- - - ">="
184
- - !ruby/object:Gem::Version
185
- version: 10.1.0
186
- - - "<"
187
- - !ruby/object:Gem::Version
188
- version: 12.0.0
189
- type: :development
190
- prerelease: false
191
- version_requirements: !ruby/object:Gem::Requirement
192
- requirements:
193
- - - ">="
194
- - !ruby/object:Gem::Version
195
- version: 10.1.0
196
- - - "<"
197
- - !ruby/object:Gem::Version
198
- version: 12.0.0
199
- - !ruby/object:Gem::Dependency
200
- name: rspec-core
201
- requirement: !ruby/object:Gem::Requirement
202
- requirements:
203
- - - "~>"
204
- - !ruby/object:Gem::Version
205
- version: '3.0'
206
- type: :development
207
- prerelease: false
208
- version_requirements: !ruby/object:Gem::Requirement
209
- requirements:
210
- - - "~>"
211
- - !ruby/object:Gem::Version
212
- version: '3.0'
213
- - !ruby/object:Gem::Dependency
214
- name: rspec-expectations
215
- requirement: !ruby/object:Gem::Requirement
216
- requirements:
217
- - - "~>"
218
- - !ruby/object:Gem::Version
219
- version: '3.0'
220
- type: :development
221
- prerelease: false
222
- version_requirements: !ruby/object:Gem::Requirement
223
- requirements:
224
- - - "~>"
225
- - !ruby/object:Gem::Version
226
- version: '3.0'
227
- - !ruby/object:Gem::Dependency
228
- name: rspec-mocks
229
- requirement: !ruby/object:Gem::Requirement
230
- requirements:
231
- - - "~>"
232
- - !ruby/object:Gem::Version
233
- version: '3.0'
234
- type: :development
235
- prerelease: false
236
- version_requirements: !ruby/object:Gem::Requirement
237
- requirements:
238
- - - "~>"
239
- - !ruby/object:Gem::Version
240
- version: '3.0'
241
- - !ruby/object:Gem::Dependency
242
- name: rspec-collection_matchers
243
- requirement: !ruby/object:Gem::Requirement
244
- requirements:
245
- - - "~>"
246
- - !ruby/object:Gem::Version
247
- version: '1.0'
248
- type: :development
249
- prerelease: false
250
- version_requirements: !ruby/object:Gem::Requirement
251
- requirements:
252
- - - "~>"
253
- - !ruby/object:Gem::Version
254
- version: '1.0'
255
- - !ruby/object:Gem::Dependency
256
- name: rspec_junit_formatter
257
- requirement: !ruby/object:Gem::Requirement
258
- requirements:
259
- - - ">="
260
- - !ruby/object:Gem::Version
261
- version: '0'
262
- type: :development
263
- prerelease: false
264
- version_requirements: !ruby/object:Gem::Requirement
265
- requirements:
266
- - - ">="
267
- - !ruby/object:Gem::Version
268
- version: '0'
269
- - !ruby/object:Gem::Dependency
270
- name: github_changelog_generator
271
- requirement: !ruby/object:Gem::Requirement
272
- requirements:
273
- - - '='
274
- - !ruby/object:Gem::Version
275
- version: 1.13.1
276
- type: :development
277
- prerelease: false
278
- version_requirements: !ruby/object:Gem::Requirement
279
- requirements:
280
- - - '='
281
- - !ruby/object:Gem::Version
282
- version: 1.13.1
283
- - !ruby/object:Gem::Dependency
284
- name: rack
285
- requirement: !ruby/object:Gem::Requirement
286
- requirements:
287
- - - "~>"
288
- - !ruby/object:Gem::Version
289
- version: '1.0'
290
- type: :development
291
- prerelease: false
292
- version_requirements: !ruby/object:Gem::Requirement
293
- requirements:
294
- - - "~>"
295
- - !ruby/object:Gem::Version
296
- version: '1.0'
297
179
  description: Ohai profiles your system and emits JSON
298
180
  email: adam@chef.io
299
181
  executables:
@@ -376,6 +258,7 @@ files:
376
258
  - lib/ohai/plugins/gce.rb
377
259
  - lib/ohai/plugins/go.rb
378
260
  - lib/ohai/plugins/groovy.rb
261
+ - lib/ohai/plugins/haskell.rb
379
262
  - lib/ohai/plugins/hostname.rb
380
263
  - lib/ohai/plugins/init_package.rb
381
264
  - lib/ohai/plugins/ip_scopes.rb
@@ -562,6 +445,7 @@ files:
562
445
  - spec/unit/plugins/gce_spec.rb
563
446
  - spec/unit/plugins/go_spec.rb
564
447
  - spec/unit/plugins/groovy_spec.rb
448
+ - spec/unit/plugins/haskell_spec.rb
565
449
  - spec/unit/plugins/hostname_spec.rb
566
450
  - spec/unit/plugins/init_package_spec.rb
567
451
  - spec/unit/plugins/ip_scopes_spec.rb
@@ -660,7 +544,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
660
544
  version: '0'
661
545
  requirements: []
662
546
  rubyforge_project:
663
- rubygems_version: 2.6.7
547
+ rubygems_version: 2.6.8
664
548
  signing_key:
665
549
  specification_version: 4
666
550
  summary: Ohai profiles your system and emits JSON