summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Vidner <martin@vidner.net>2013-03-19 16:07:52 +0100
committerBryan McLellan <btm@opscode.com>2013-06-24 16:49:42 -0700
commitdd15a6c6fe09fc1ef83b84cd0ff3d0c01a3bede4 (patch)
treeea600efddadf27c04a24f03056ec5f5fda279c95
parent03b9c28c27e42ad3e3dd8e4a6a1772ef96bf5483 (diff)
downloadohai-dd15a6c6fe09fc1ef83b84cd0ff3d0c01a3bede4.tar.gz
suse platform: read /etc/SuSE-release only once.
doing it twice is (slightly) inefficient and complicates the tests
-rw-r--r--lib/ohai/plugins/linux/platform.rb5
-rw-r--r--spec/unit/plugins/linux/platform_spec.rb8
2 files changed, 7 insertions, 6 deletions
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb
index 65ce5344..3bc6e3a3 100644
--- a/lib/ohai/plugins/linux/platform.rb
+++ b/lib/ohai/plugins/linux/platform.rb
@@ -70,8 +70,9 @@ elsif File.exists?('/etc/gentoo-release')
platform_version File.read('/etc/gentoo-release').scan(/(\d+|\.+)/).join
elsif File.exists?('/etc/SuSE-release')
platform "suse"
- platform_version File.read("/etc/SuSE-release").scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join(".")
- platform_version File.read("/etc/SuSE-release").scan(/VERSION = ([\d\.]{2,})/).flatten.join(".") if platform_version == ""
+ suse_release = File.read("/etc/SuSE-release")
+ platform_version suse_release.scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join(".")
+ platform_version suse_release.scan(/VERSION = ([\d\.]{2,})/).flatten.join(".") if platform_version == ""
elsif File.exists?('/etc/slackware-version')
platform "slackware"
platform_version File.read("/etc/slackware-version").scan(/(\d+|\.+)/).join
diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb
index 869f8a47..189b3430 100644
--- a/spec/unit/plugins/linux/platform_spec.rb
+++ b/spec/unit/plugins/linux/platform_spec.rb
@@ -386,7 +386,7 @@ describe Ohai::System, "Linux plugin platform" do
it "should read the platform as suse" do
@ohai[:lsb][:release] = "12.1"
- File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n")
+ File.should_receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n")
@ohai._require_plugin("linux::platform")
@ohai[:platform].should == "suse"
@ohai[:platform_version].should == "12.1"
@@ -427,7 +427,7 @@ describe Ohai::System, "Linux plugin platform" do
end
it "[OHAI-272] should read the version as 11.3" do
- File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3")
+ File.should_receive(:read).with("/etc/SuSE-release").and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3")
@ohai._require_plugin("linux::platform")
@ohai[:platform].should == "suse"
@ohai[:platform_version].should == "11.3"
@@ -435,7 +435,7 @@ describe Ohai::System, "Linux plugin platform" do
end
it "[OHAI-272] should read the version as 9.1" do
- File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("SuSE Linux 9.1 (i586)\nVERSION = 9.1")
+ File.should_receive(:read).with("/etc/SuSE-release").and_return("SuSE Linux 9.1 (i586)\nVERSION = 9.1")
@ohai._require_plugin("linux::platform")
@ohai[:platform].should == "suse"
@ohai[:platform_version].should == "9.1"
@@ -443,7 +443,7 @@ describe Ohai::System, "Linux plugin platform" do
end
it "[OHAI-272] should read the version as 11.4" do
- File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon")
+ File.should_receive(:read).with("/etc/SuSE-release").and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon")
@ohai._require_plugin("linux::platform")
@ohai[:platform].should == "suse"
@ohai[:platform_version].should == "11.4"