Codebase list facter / 49e94df
(fact-155) Add operatingsystemmajrelease fact for Solaris Stefan Schulte authored 10 years ago Adrien Thebo committed 10 years ago
2 changed file(s) with 37 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
11 #
22 # Purpose: Returns the major release of the operating system.
33 #
4 # Resolution: splits down the operatingsystemrelease fact at decimal point for
5 # osfamily RedHat derivatives and Debian.
4 # Resolution:
5 # Splits down the operatingsystemrelease fact at decimal point for
6 # osfamily RedHat derivatives and Debian.
7 # Uses operatingsystemrelease to the first non decimal character for
8 # operatingsystem Solaris
69 #
710 # This should be the same as lsbmajdistrelease, but on minimal systems there
811 # are too many dependencies to use LSB
1215 #"Debian" "Fedora" "Gentoo" "Mandrake" "Mandriva" "MeeGo" "OEL" "OpenSuSE"
1316 #"OracleLinux" "OVS" "PSBM" "RedHat" "Scientific" "Slackware" "Slamd64" "SLC"
1417 #"SLED" "SLES" "SuSE" "Ubuntu" "VMWareESX"
18
1519 Facter.add(:operatingsystemmajrelease) do
1620 confine :operatingsystem => [
1721 :Amazon,
3034 Facter.value('operatingsystemrelease').split('.').first
3135 end
3236 end
37
38 Facter.add(:operatingsystemmajrelease) do
39 confine :operatingsystem => :solaris
40 setcode do
41 if match = Facter.value(:operatingsystemrelease).match(/^(\d+)/)
42 match.captures[0]
43 end
44 end
45 end
1212 end
1313 end
1414 end
15
16 context "on Solaris operatingsystems" do
17 before :each do
18 Facter.fact(:kernel).stubs(:value).returns("SunOS")
19 Facter.fact(:operatingsystem).stubs(:value).returns("Solaris")
20 end
21
22 it "should correctly derive from operatingsystemrelease on solaris 10" do
23 Facter.fact(:operatingsystemrelease).expects(:value).returns("10_u8")
24 Facter.fact(:operatingsystemmajrelease).value.should == "10"
25 end
26
27 it "should correctly derive from operatingsystemrelease on solaris 11 (old version scheme)" do
28 Facter.fact(:operatingsystemrelease).expects(:value).returns("11 11/11")
29 Facter.fact(:operatingsystemmajrelease).value.should == "11"
30 end
31
32 it "should correctly derive from operatingsystemrelease on solaris 11 (new version scheme)" do
33 Facter.fact(:operatingsystemrelease).expects(:value).returns("11.1")
34 Facter.fact(:operatingsystemmajrelease).value.should == "11"
35 end
36 end
1537 end