summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-10-28 22:38:59 -0700
committerTim Smith <tsmith84@gmail.com>2020-10-28 22:38:59 -0700
commit0fdd4a397ed396d861dab8314580518aec1fde53 (patch)
treec268e6b5168a19b06f54ef51864619e201962d8f
parentd7afbc38fafe295c8c8fb45b197d226070eb71b8 (diff)
downloadohai-0fdd4a397ed396d861dab8314580518aec1fde53.tar.gz
Properly detect OpenIndiana and its version numbers
1) Our regexes for the most part here were more complex than they needed to be 2) OpenIndiana's is now called OpenIndiana Hipster so the old regex was not working 3) Even the old regex only detected the major releae instead of the full 3 point version I doubt anyone is using the non-Hipster release at this point, but we detect it properly now and we have specs in place. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/solaris2/platform.rb12
-rw-r--r--spec/unit/plugins/solaris2/platform_spec.rb71
2 files changed, 77 insertions, 6 deletions
diff --git a/lib/ohai/plugins/solaris2/platform.rb b/lib/ohai/plugins/solaris2/platform.rb
index e8a02e2a..be258dc7 100644
--- a/lib/ohai/plugins/solaris2/platform.rb
+++ b/lib/ohai/plugins/solaris2/platform.rb
@@ -38,17 +38,17 @@ Ohai.plugin(:Platform) do
file_open("/etc/release") do |file|
while ( line = file.gets )
case line
- when /^.*(SmartOS).*$/
+ when /.*SmartOS.*/
platform "smartos"
- when /^\s*(OmniOS).*r(\d+).*$/
+ when /^\s*OmniOS.*r(\d+).*$/
platform "omnios"
- platform_version $2
- when /^\s*(OpenIndiana).*oi_(\d+).*$/
+ platform_version $1
+ when /^\s*OpenIndiana.*(Development oi_|Hipster )(\d\S*)/ # https://rubular.com/r/iMtOBwbnyqDz7u
platform "openindiana"
platform_version $2
- when /^\s*(Oracle Solaris)/
+ when /^\s*Oracle Solaris/
platform "solaris2"
- when /^\s*(Solaris)\s.*$/
+ when /^\s*Solaris\s.*$/
platform "solaris2"
end
end
diff --git a/spec/unit/plugins/solaris2/platform_spec.rb b/spec/unit/plugins/solaris2/platform_spec.rb
index 08bbec74..8fc5b1e7 100644
--- a/spec/unit/plugins/solaris2/platform_spec.rb
+++ b/spec/unit/plugins/solaris2/platform_spec.rb
@@ -139,4 +139,75 @@ describe Ohai::System, "Solaris plugin platform" do
end
+ describe "on OpenIndiana Hipster" do
+ before do
+ @uname_x = <<~UNAME_X
+ System = SunOS
+ Node = openindiana
+ Release = 5.11
+ KernelID = illumos-c3e16711de
+ Machine = i86pc
+ BusType = <unknown>
+ Serial = <unknown>
+ Users = <unknown>
+ OEM# = 0
+ Origin# = 1
+ NumCPU = 1
+ UNAME_X
+
+ allow(File).to receive(:exist?).with("/sbin/uname").and_return(true)
+ allow(@plugin).to receive(:shell_out).with("/sbin/uname -X").and_return(mock_shell_out(0, @uname_x, ""))
+
+ @release = StringIO.new(" OpenIndiana Hipster 2020.04 (powered by illumos)\n OpenIndiana Project, part of The Illumos Foundation (C) 2010-2020\n Use is subject to license terms.\n Assembled 03 May 2020")
+ allow(File).to receive(:open).with("/etc/release").and_yield(@release)
+ @plugin.run
+ end
+
+ it "runs uname and set platform and build" do
+ expect(@plugin[:platform_build]).to eq("illumos-c3e16711de")
+ end
+
+ it "sets the platform" do
+ expect(@plugin[:platform]).to eq("openindiana")
+ end
+
+ it "sets the platform_version" do
+ expect(@plugin[:platform_version]).to eq("2020.04")
+ end
+
+ end
+
+ describe "on OpenIndiana pre-Hipster" do
+ before do
+ @uname_x = <<~UNAME_X
+ System = SunOS
+ Node = openindiana
+ Release = 5.11
+ KernelID = illumos-cf2fa55
+ Machine = i86pc
+ BusType = <unknown>
+ Serial = <unknown>
+ Users = <unknown>
+ OEM# = 0
+ Origin# = 1
+ NumCPU = 2
+ UNAME_X
+
+ allow(File).to receive(:exist?).with("/sbin/uname").and_return(true)
+ allow(@plugin).to receive(:shell_out).with("/sbin/uname -X").and_return(mock_shell_out(0, @uname_x, ""))
+ @release = StringIO.new(" OpenIndiana Development oi_151.1.8 (powered by illumos)\n Copyright 2011 Oracle and/or its affiliates. All rights reserved\n Use is subject to license terms.\n Assembled 20 July 2013")
+ allow(File).to receive(:open).with("/etc/release").and_yield(@release)
+ @plugin.run
+ end
+
+ it "sets the platform" do
+ expect(@plugin[:platform]).to eq("openindiana")
+ end
+
+ it "sets the platform_version" do
+ expect(@plugin[:platform_version]).to eq("151.1.8")
+ end
+
+ end
+
end