Skip to content

Instantly share code, notes, and snippets.

@redivy
Created January 13, 2010 10:05
Show Gist options
  • Save redivy/276081 to your computer and use it in GitHub Desktop.
Save redivy/276081 to your computer and use it in GitHub Desktop.
diff -urN lib/ohai/plugins/linux/platform.rb lib/ohai/plugins/linux/platform.rb
--- lib/ohai/plugins/linux/platform.rb 2010-01-13 12:38:48.000000000 +0300
+++ lib/ohai/plugins/linux/platform.rb 2010-01-13 12:22:04.000000000 +0300
@@ -40,4 +40,14 @@
elsif File.exists?('/etc/gentoo-release')
platform "gentoo"
platform_version IO.read('/etc/gentoo-release').scan(/(\d+|\.+)/).join
+elsif File.exists?("/etc/SuSE-release")
+ platform "suse"
+ File.open("/etc/SuSE-release").each do |line|
+ case line
+ when /version\D+([\d\.]+)/i
+ platform_version $1
+ when /patchlevel\D+([\d\.]+)/i
+ platform_version "#{platform_version}.#{$1}"
+ end
+ end
end
diff -urN spec/ohai/plugins/linux/platform_spec.rb spec/ohai/plugins/linux/platform_spec.rb
--- spec/ohai/plugins/linux/platform_spec.rb 2010-01-13 12:38:48.000000000 +0300
+++ spec/ohai/plugins/linux/platform_spec.rb 2010-01-13 12:26:21.000000000 +0300
@@ -29,6 +29,7 @@
File.stub!(:exists?).with("/etc/debian_version").and_return(false)
File.stub!(:exists?).with("/etc/redhat-release").and_return(false)
File.stub!(:exists?).with("/etc/gentoo-release").and_return(false)
+ File.stub!(:exists?).with("/etc/SuSE-release").and_return(false)
end
it "should require the lsb plugin" do
@@ -77,5 +78,22 @@
end
+ describe "on suse" do
+ before(:each) do
+ @ohai.lsb = nil
+ File.should_receive(:exists?).with("/etc/SuSE-release").and_return(true)
+ end
+
+ it "should check for the existance of SuSE-release" do
+ @ohai._require_plugin("linux::platform")
+ end
+
+ it "should read the version from /etc/SuSE-release" do
+ File.should_receive(:open).with("/etc/SuSE-release").and_return(['version = 11.2'])
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform_version].should == "11.2"
+ end
+ end
+
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment