facter 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of facter might be problematic. Click here for more details.

Files changed (139) hide show
  1. data/COMMITTERS.md +25 -34
  2. data/CONTRIBUTING.md +27 -5
  3. data/README.md +32 -0
  4. data/ext/build_defaults.yaml +1 -1
  5. data/ext/debian/control +3 -2
  6. data/ext/osx/file_mapping.yaml +5 -0
  7. data/ext/redhat/facter.spec.erb +4 -1
  8. data/lib/facter/Cfkey.rb +2 -2
  9. data/lib/facter/architecture.rb +2 -2
  10. data/lib/facter/augeasversion.rb +2 -2
  11. data/lib/facter/blockdevices.rb +12 -12
  12. data/lib/facter/dhcp_servers.rb +4 -4
  13. data/lib/facter/domain.rb +4 -4
  14. data/lib/facter/ec2.rb +17 -0
  15. data/lib/facter/ec2/rest.rb +2 -2
  16. data/lib/facter/facterversion.rb +2 -2
  17. data/lib/facter/filesystems.rb +10 -3
  18. data/lib/facter/fqdn.rb +1 -1
  19. data/lib/facter/gid.rb +16 -0
  20. data/lib/facter/hardwareisa.rb +3 -3
  21. data/lib/facter/hardwaremodel.rb +3 -3
  22. data/lib/facter/hostname.rb +1 -1
  23. data/lib/facter/id.rb +4 -4
  24. data/lib/facter/interfaces.rb +3 -0
  25. data/lib/facter/ipaddress6.rb +9 -9
  26. data/lib/facter/kernel.rb +2 -2
  27. data/lib/facter/kernelmajversion.rb +2 -2
  28. data/lib/facter/kernelrelease.rb +4 -4
  29. data/lib/facter/kernelversion.rb +3 -3
  30. data/lib/facter/ldom.rb +11 -0
  31. data/lib/facter/lsbdistcodename.rb +8 -4
  32. data/lib/facter/lsbdistdescription.rb +6 -10
  33. data/lib/facter/lsbdistid.rb +8 -4
  34. data/lib/facter/lsbdistrelease.rb +8 -4
  35. data/lib/facter/lsbmajdistrelease.rb +7 -12
  36. data/lib/facter/lsbminordistrelease.rb +22 -0
  37. data/lib/facter/lsbrelease.rb +8 -4
  38. data/lib/facter/macaddress.rb +1 -0
  39. data/lib/facter/macosx.rb +1 -1
  40. data/lib/facter/manufacturer.rb +3 -3
  41. data/lib/facter/memory.rb +8 -8
  42. data/lib/facter/netmask.rb +2 -1
  43. data/lib/facter/network.rb +3 -3
  44. data/lib/facter/operatingsystem.rb +9 -126
  45. data/lib/facter/operatingsystem/base.rb +61 -0
  46. data/lib/facter/operatingsystem/cumuluslinux.rb +27 -0
  47. data/lib/facter/operatingsystem/implementation.rb +30 -0
  48. data/lib/facter/operatingsystem/linux.rb +467 -0
  49. data/lib/facter/operatingsystem/sunos.rb +54 -0
  50. data/lib/facter/operatingsystem/vmkernel.rb +11 -0
  51. data/lib/facter/operatingsystem/windows.rb +37 -0
  52. data/lib/facter/operatingsystemmajrelease.rb +14 -33
  53. data/lib/facter/operatingsystemrelease.rb +14 -235
  54. data/lib/facter/os.rb +69 -0
  55. data/lib/facter/osfamily.rb +4 -23
  56. data/lib/facter/partitions.rb +4 -3
  57. data/lib/facter/path.rb +2 -2
  58. data/lib/facter/physicalprocessorcount.rb +10 -74
  59. data/lib/facter/processor.rb +13 -129
  60. data/lib/facter/processors.rb +60 -0
  61. data/lib/facter/processors/os.rb +234 -0
  62. data/lib/facter/ps.rb +5 -4
  63. data/lib/facter/puppetversion.rb +1 -1
  64. data/lib/facter/rackspace.rb +34 -0
  65. data/lib/facter/rubysitedir.rb +3 -0
  66. data/lib/facter/rubyversion.rb +2 -2
  67. data/lib/facter/selinux.rb +57 -2
  68. data/lib/facter/ssh.rb +1 -0
  69. data/lib/facter/system_uptime.rb +42 -0
  70. data/lib/facter/timezone.rb +1 -1
  71. data/lib/facter/uptime.rb +5 -23
  72. data/lib/facter/uptime_days.rb +4 -6
  73. data/lib/facter/uptime_hours.rb +4 -6
  74. data/lib/facter/uptime_seconds.rb +5 -9
  75. data/lib/facter/util/formatter.rb +1 -1
  76. data/lib/facter/util/manufacturer.rb +1 -1
  77. data/lib/facter/util/partitions.rb +3 -1
  78. data/lib/facter/util/partitions/linux.rb +1 -1
  79. data/lib/facter/util/partitions/openbsd.rb +35 -0
  80. data/lib/facter/util/uptime.rb +4 -3
  81. data/lib/facter/util/virtual.rb +3 -1
  82. data/lib/facter/util/xendomains.rb +12 -3
  83. data/lib/facter/version.rb +1 -1
  84. data/lib/facter/virtual.rb +24 -23
  85. data/lib/facter/vlans.rb +1 -1
  86. data/lib/facter/xendomains.rb +1 -1
  87. data/lib/facter/zfs_version.rb +6 -2
  88. data/lib/facter/zones.rb +6 -5
  89. data/lib/facter/zpool_version.rb +1 -1
  90. data/spec/fixtures/cpuinfo/amd64dual-grep +2 -0
  91. data/spec/fixtures/cpuinfo/amd64twentyfour-grep +24 -0
  92. data/spec/fixtures/cpuinfo/two_multicore-grep +4 -0
  93. data/spec/fixtures/cpuinfo/two_singlecore-grep +2 -0
  94. data/spec/fixtures/unit/processors/os/darwin-system-profiler +287 -0
  95. data/spec/fixtures/unit/zfs_version/zfs_new +61 -0
  96. data/spec/fixtures/unit/zfs_version/zfs_old +43 -0
  97. data/spec/fixtures/unit/zfs_version/zfsonlinux_0.6.1 +13 -0
  98. data/spec/fixtures/unit/zpool_version/zfsonlinux_0.6.1 +48 -0
  99. data/spec/unit/ec2/rest_spec.rb +6 -6
  100. data/spec/unit/gid_spec.rb +22 -0
  101. data/spec/unit/hardwaremodel_spec.rb +2 -0
  102. data/spec/unit/lsbdistcodename_spec.rb +22 -17
  103. data/spec/unit/lsbdistdescription_spec.rb +22 -17
  104. data/spec/unit/lsbdistid_spec.rb +23 -18
  105. data/spec/unit/lsbdistrelease_spec.rb +22 -17
  106. data/spec/unit/lsbmajdistrelease_spec.rb +23 -6
  107. data/spec/unit/lsbminordistrelease_spec.rb +31 -0
  108. data/spec/unit/lsbrelease_spec.rb +22 -17
  109. data/spec/unit/macaddress_spec.rb +3 -0
  110. data/spec/unit/operatingsystem/base_spec.rb +76 -0
  111. data/spec/unit/operatingsystem/cumuluslinux_spec.rb +40 -0
  112. data/spec/unit/operatingsystem/implementation_spec.rb +49 -0
  113. data/spec/unit/operatingsystem/linux_spec.rb +538 -0
  114. data/spec/unit/operatingsystem/sunos_spec.rb +144 -0
  115. data/spec/unit/operatingsystem/vmkernel_spec.rb +13 -0
  116. data/spec/unit/operatingsystem/windows_spec.rb +68 -0
  117. data/spec/unit/operatingsystem_spec.rb +10 -153
  118. data/spec/unit/operatingsystemmajrelease_spec.rb +14 -31
  119. data/spec/unit/operatingsystemrelease_spec.rb +13 -229
  120. data/spec/unit/os_spec.rb +131 -0
  121. data/spec/unit/osfamily_spec.rb +9 -54
  122. data/spec/unit/partitions_spec.rb +41 -3
  123. data/spec/unit/physicalprocessorcount_spec.rb +6 -78
  124. data/spec/unit/processor_spec.rb +18 -381
  125. data/spec/unit/processors/os_spec.rb +446 -0
  126. data/spec/unit/processors_spec.rb +203 -0
  127. data/spec/unit/rackspace_spec.rb +40 -0
  128. data/spec/unit/system_uptime_spec.rb +80 -0
  129. data/spec/unit/util/formatter_spec.rb +5 -0
  130. data/spec/unit/util/macaddress_spec.rb +2 -0
  131. data/spec/unit/util/processor_spec.rb +120 -0
  132. data/spec/unit/util/uptime_spec.rb +3 -4
  133. data/spec/unit/util/virtual_spec.rb +8 -0
  134. data/spec/unit/util/xendomains_spec.rb +54 -9
  135. data/spec/unit/virtual_spec.rb +8 -1
  136. data/spec/unit/zfs_version_spec.rb +20 -8
  137. data/spec/unit/zpool_version_spec.rb +5 -0
  138. metadata +652 -589
  139. checksums.yaml +0 -7
@@ -1,13 +1,30 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
- require 'facter'
5
4
 
6
5
  describe "LSB distribution major release fact" do
7
- it "should be derived from lsb_release" do
8
- Facter.fact(:kernel).stubs(:value).returns("Linux")
9
- Facter.stubs(:value).with(:lsbdistrelease).returns("10.10")
6
+ let(:os_hash) { { "name" => "SomeOS",
7
+ "family" => "SomeFamily",
8
+ "release" => {
9
+ "major" => "1",
10
+ "minor" => "2",
11
+ "full" => "1.2.3"
12
+ },
13
+ "lsb" => {
14
+ "distcodename" => "SomeCodeName",
15
+ "distid" => "SomeID",
16
+ "distdescription" => "SomeDesc",
17
+ "distrelease" => "1.2.3",
18
+ "release" => "1.2.3",
19
+ "majdistrelease" => "1",
20
+ "minordistrelease" => "2"
21
+ },
22
+ }
23
+ }
10
24
 
11
- Facter.fact(:lsbmajdistrelease).value.should == "10"
12
- end
25
+ it "should use the 'minordistrelease' key of the 'os' fact" do
26
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
27
+ Facter.fact("os").stubs(:value).returns(os_hash)
28
+ Facter.fact(:lsbminordistrelease).value.should eq "2"
29
+ end
13
30
  end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'spec_helper'
4
+ require 'facter'
5
+
6
+ describe "LSB distribution major release fact" do
7
+ let(:os_hash) { { "name" => "SomeOS",
8
+ "family" => "SomeFamily",
9
+ "release" => {
10
+ "major" => "1",
11
+ "minor" => "2",
12
+ "full" => "1.2.3"
13
+ },
14
+ "lsb" => {
15
+ "distcodename" => "SomeCodeName",
16
+ "distid" => "SomeID",
17
+ "distdescription" => "SomeDesc",
18
+ "distrelease" => "1.2.3",
19
+ "release" => "1.2.3",
20
+ "majdistrelease" => "1",
21
+ "minordistrelease" => "2"
22
+ },
23
+ }
24
+ }
25
+
26
+ it "should use the 'majdistrelease' key of the 'os' fact" do
27
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
28
+ Facter.fact("os").stubs(:value).returns(os_hash)
29
+ Facter.fact(:lsbmajdistrelease).value.should eq "1"
30
+ end
31
+ end
@@ -3,23 +3,28 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe "lsbrelease fact" do
6
+ let(:os_hash) { { "name" => "SomeOS",
7
+ "family" => "SomeFamily",
8
+ "release" => {
9
+ "major" => "1",
10
+ "minor" => "2",
11
+ "full" => "1.2.3"
12
+ },
13
+ "lsb" => {
14
+ "distcodename" => "SomeCodeName",
15
+ "distid" => "SomeID",
16
+ "distdescription" => "SomeDesc",
17
+ "distrelease" => "1.2.3",
18
+ "release" => "1.2.3",
19
+ "majdistrelease" => "1",
20
+ "minordistrelease" => "2"
21
+ },
22
+ }
23
+ }
6
24
 
7
- [ "Linux", "GNU/kFreeBSD"].each do |kernel|
8
- describe "on #{kernel}" do
9
- before :each do
10
- Facter.fact(:kernel).stubs(:value).returns kernel
11
- end
12
-
13
- it "returns the release through lsb_release -v -s 2>/dev/null" do
14
- Facter::Core::Execution.impl.stubs(:execute).with('lsb_release -v -s 2>/dev/null', anything).returns 'n/a'
15
- expect(Facter.fact(:lsbrelease).value).to eq 'n/a'
16
- end
17
-
18
- it "returns nil if lsb_release is not installed" do
19
- Facter::Core::Execution.impl.stubs(:expand_command).with('lsb_release -v -s 2>/dev/null').returns nil
20
- expect(Facter.fact(:lsbrelease).value).to be_nil
21
- end
22
- end
25
+ it "should use the 'distrelease' key from the 'os' fact" do
26
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
27
+ Facter.fact("os").stubs(:value).returns(os_hash)
28
+ Facter.fact(:lsbrelease).value.should eq "1.2.3"
23
29
  end
24
-
25
30
  end
@@ -50,6 +50,7 @@ describe "macaddress fact" do
50
50
  describe "when run on BSD" do
51
51
  it "should return macaddress information" do
52
52
  Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
53
+ Facter.fact(:operatingsystem).stubs(:value).returns("FreeBSD")
53
54
  Facter::Util::IP.stubs(:get_ifconfig).returns("/sbin/ifconfig")
54
55
  Facter::Util::IP.stubs(:exec_ifconfig).
55
56
  returns(ifconfig_fixture('bsd_ifconfig_all_with_multiple_interfaces'))
@@ -61,6 +62,8 @@ describe "macaddress fact" do
61
62
  describe "when run on OpenBSD with bridge(4) rules" do
62
63
  it "should return macaddress information" do
63
64
  Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
65
+ Facter.fact(:operatingsystem).stubs(:value).returns("OpenBSD")
66
+ Facter.fact(:osfamily).stubs(:value).returns("OpenBSD")
64
67
  Facter::Util::IP.stubs(:get_ifconfig).returns("/sbin/ifconfig")
65
68
  Facter::Util::IP.stubs(:exec_ifconfig).
66
69
  returns(ifconfig_fixture('openbsd_bridge_rules'))
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+ require 'facter/operatingsystem/base'
3
+
4
+ describe Facter::Operatingsystem::Base do
5
+ subject { described_class.new }
6
+
7
+ before :each do
8
+ Facter.fact(:kernel).stubs(:value).returns("Nutmeg")
9
+ end
10
+
11
+ describe "Operating system fact" do
12
+ it "should default to the kernel name" do
13
+ os = subject.get_operatingsystem
14
+ expect(os).to eq "Nutmeg"
15
+ end
16
+ end
17
+
18
+ describe "Osfamily fact" do
19
+ it "should default to the kernel name" do
20
+ osfamily = subject.get_osfamily
21
+ expect(osfamily).to eq "Nutmeg"
22
+ end
23
+ end
24
+
25
+ describe "Operatingsystemrelease fact" do
26
+ it "should return the kernel fact by default" do
27
+ Facter.fact(:kernelrelease).stubs(:value).returns("1.2.3")
28
+ operatingsystemrelease = subject.get_operatingsystemrelease
29
+ expect(operatingsystemrelease).to eq "1.2.3"
30
+ end
31
+ end
32
+
33
+ describe "Operatingsystemmajrelease fact" do
34
+ it "should base major release on release fact if available" do
35
+ subject.expects(:get_operatingsystemrelease).returns("1.2.3")
36
+ operatingsystemmajrelease = subject.get_operatingsystemmajorrelease
37
+ expect(operatingsystemmajrelease).to eq "1"
38
+ end
39
+
40
+ it "should return nil if release fact not available" do
41
+ subject.expects(:get_operatingsystemrelease).returns(nil)
42
+ operatingsystemmajrelease = subject.get_operatingsystemmajorrelease
43
+ expect(operatingsystemmajrelease).to be_nil
44
+ end
45
+ end
46
+
47
+ describe "Operatingsystemminorrelease" do
48
+ it "should base minor release on release fact if available" do
49
+ subject.expects(:get_operatingsystemrelease).returns("1.2.3")
50
+ operatingsystemminorrelease = subject.get_operatingsystemminorrelease
51
+ expect(operatingsystemminorrelease).to eq "2"
52
+ end
53
+
54
+ it "should strip off the patch release if appended with a '-'" do
55
+ subject.stubs(:get_operatingsystem).returns("FreeBSD")
56
+ subject.expects(:get_operatingsystemrelease).returns("10.0-RELEASE")
57
+ release = subject.get_operatingsystemminorrelease
58
+ expect(release).to eq "0"
59
+ end
60
+
61
+ it "should return nil if release fact not available" do
62
+ subject.expects(:get_operatingsystemrelease).returns(nil)
63
+ operatingsystemmajrelease = subject.get_operatingsystemminorrelease
64
+ expect(operatingsystemmajrelease).to be_nil
65
+ end
66
+ end
67
+
68
+
69
+ describe "Operatingsystemrelease hash" do
70
+ it "should return a hash of release values" do
71
+ subject.expects(:get_operatingsystemrelease).at_least_once.returns("1.2.3")
72
+ release_hash = subject.get_operatingsystemrelease_hash
73
+ expect(release_hash).to eq({"major" => "1", "minor" => "2", "full" => "1.2.3" })
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+ require 'facter/operatingsystem/cumuluslinux'
3
+
4
+ describe Facter::Operatingsystem::CumulusLinux do
5
+ subject { described_class.new }
6
+
7
+ before :all do
8
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
9
+ end
10
+
11
+ describe "Operating system fact" do
12
+ it "should identify Cumulus Linux" do
13
+ os = subject.get_operatingsystem
14
+ expect(os).to eq "CumulusLinux"
15
+ end
16
+ end
17
+
18
+ describe "Osfamily fact" do
19
+ it "should return Debian" do
20
+ osfamily = subject.get_osfamily
21
+ expect(osfamily).to eq "Debian"
22
+ end
23
+ end
24
+
25
+ describe "Operatingsystemrelease fact" do
26
+ it "uses '/etc/os-release" do
27
+ Facter::Util::Operatingsystem.expects(:os_release).returns({"VERSION_ID" => "1.5.0"})
28
+ release = subject.get_operatingsystemrelease
29
+ expect(release).to eq "1.5.0"
30
+ end
31
+ end
32
+
33
+ describe "Operatingsystemmajrelease fact" do
34
+ it "should return the majrelease value based on its operatingsystemrelease" do
35
+ subject.expects(:get_operatingsystemrelease).returns("1.5.0")
36
+ release = subject.get_operatingsystemmajrelease
37
+ expect(release).to eq "1"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ require 'facter/operatingsystem/implementation'
3
+ require 'facter/operatingsystem/base'
4
+ require 'facter/operatingsystem/cumuluslinux'
5
+ require 'facter/operatingsystem/linux'
6
+ require 'facter/operatingsystem/sunos'
7
+ require 'facter/operatingsystem/vmkernel'
8
+ require 'facter/operatingsystem/windows'
9
+
10
+ describe Facter::Operatingsystem do
11
+ it "should return an object of type Linux for linux kernels that are not Cumulus Linux" do
12
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
13
+ Facter::Util::Operatingsystem.expects(:os_release).at_least_once.returns({'NAME' => 'Some Linux'})
14
+ object = described_class.implementation
15
+ object.should be_a_kind_of(Facter::Operatingsystem::Linux)
16
+ end
17
+
18
+ it "should return an object of type Linux for gnu/kfreebsd kernels" do
19
+ Facter.fact(:kernel).stubs(:value).returns("GNU/kFreeBSD")
20
+ Facter::Util::Operatingsystem.expects(:os_release).at_least_once.returns({'NAME' => 'Some Linux'})
21
+ object = described_class.implementation
22
+ object.should be_a_kind_of(Facter::Operatingsystem::Linux)
23
+ end
24
+
25
+ it "should identify Cumulus Linux when a Linux kernel is encountered" do
26
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
27
+ Facter::Util::Operatingsystem.expects(:os_release).at_least_once.returns({'NAME' => 'Cumulus Linux'})
28
+ object = described_class.implementation
29
+ object.should be_a_kind_of(Facter::Operatingsystem::CumulusLinux)
30
+ end
31
+
32
+ it "should return an object of type SunOS for SunOS kernels" do
33
+ Facter.fact(:kernel).stubs(:value).returns("SunOS")
34
+ object = described_class.implementation
35
+ object.should be_a_kind_of(Facter::Operatingsystem::SunOS)
36
+ end
37
+
38
+ it "should return an object of type VMkernel for VMkernel kernels" do
39
+ Facter.fact(:kernel).stubs(:value).returns("VMkernel")
40
+ object = described_class.implementation
41
+ object.should be_a_kind_of(Facter::Operatingsystem::VMkernel)
42
+ end
43
+
44
+ it "should return an object of type Base for other kernels" do
45
+ Facter.fact(:kernel).stubs(:value).returns("Nutmeg")
46
+ object = described_class.implementation
47
+ object.should be_a_kind_of(Facter::Operatingsystem::Base)
48
+ end
49
+ end
@@ -0,0 +1,538 @@
1
+ require 'spec_helper'
2
+ require 'facter/operatingsystem/linux'
3
+
4
+ describe Facter::Operatingsystem::Linux do
5
+ subject { described_class.new }
6
+
7
+ describe "Operating system fact" do
8
+ describe "On gnu/kfreebsd" do
9
+ it "should return 'GNU/kFreeBSD'" do
10
+ Facter.expects(:value).with(:kernel).returns("GNU/kFreeBSD")
11
+ os = subject.get_operatingsystem
12
+ expect(os).to eq "GNU/kFreeBSD"
13
+ end
14
+ end
15
+
16
+ describe "When lsbdistid is available" do
17
+ it "on Ubuntu should use the lsbdistid fact" do
18
+ subject.expects(:get_lsbdistid).returns("Ubuntu")
19
+ os = subject.get_operatingsystem
20
+ expect(os).to eq "Ubuntu"
21
+ end
22
+
23
+ it "on LinuxMint should use the lsbdistid fact" do
24
+ subject.expects(:get_lsbdistid).returns("LinuxMint")
25
+ os = subject.get_operatingsystem
26
+ expect(os).to eq "LinuxMint"
27
+ end
28
+ end
29
+
30
+ describe "When lsbdistid is not available" do
31
+ {
32
+ "Debian" => "/etc/debian_version",
33
+ "Gentoo" => "/etc/gentoo-release",
34
+ "Fedora" => "/etc/fedora-release",
35
+ "Mageia" => "/etc/mageia-release",
36
+ "Mandriva" => "/etc/mandriva-release",
37
+ "Mandrake" => "/etc/mandrake-release",
38
+ "MeeGo" => "/etc/meego-release",
39
+ "Archlinux" => "/etc/arch-release",
40
+ "OracleLinux" => "/etc/oracle-release",
41
+ "OpenWrt" => "/etc/openwrt_release",
42
+ "Alpine" => "/etc/alpine-release",
43
+ "VMWareESX" => "/etc/vmware-release",
44
+ "Bluewhite64" => "/etc/bluewhite64-version",
45
+ "Slamd64" => "/etc/slamd64-version",
46
+ "Slackware" => "/etc/slackware-version",
47
+ "Amazon" => "/etc/system-release"
48
+ }.each_pair do |distribution, releasefile|
49
+ it "should be #{distribution} if #{releasefile} exists" do
50
+ subject.expects(:get_lsbdistid).returns(nil)
51
+ FileTest.expects(:exists?).at_least_once.returns false
52
+ FileTest.expects(:exists?).with(releasefile).returns true
53
+ os = subject.get_operatingsystem
54
+ expect(os).to eq distribution
55
+ end
56
+ end
57
+ end
58
+
59
+ describe "on distributions that rely on the contents of /etc/redhat-release" do
60
+ before :each do
61
+ subject.expects(:get_lsbdistid).returns(nil)
62
+ end
63
+
64
+ {
65
+ "RedHat" => "Red Hat Enterprise Linux Server release 6.0 (Santiago)",
66
+ "CentOS" => "CentOS release 5.6 (Final)",
67
+ "Scientific" => "Scientific Linux release 6.0 (Carbon)",
68
+ "SLC" => "Scientific Linux CERN SLC release 5.7 (Boron)",
69
+ "Ascendos" => "Ascendos release 6.0 (Nameless)",
70
+ "CloudLinux" => "CloudLinux Server release 5.5",
71
+ "XenServer" => "XenServer release 5.6.0-31188p (xenenterprise)",
72
+ "XCP" => "XCP release 1.6.10-61809c",
73
+ }.each_pair do |operatingsystem, string|
74
+ it "should be #{operatingsystem} based on /etc/redhat-release contents #{string}" do
75
+ FileTest.expects(:exists?).at_least_once.returns false
76
+ FileTest.expects(:exists?).with("/etc/enterprise-release").returns false
77
+ FileTest.expects(:exists?).with("/etc/redhat-release").returns true
78
+ File.expects(:read).with("/etc/redhat-release").at_least_once.returns string
79
+ os = subject.get_operatingsystem
80
+ expect(os).to eq operatingsystem
81
+ end
82
+ end
83
+
84
+ it "should be OEL if /etc/ovs-release doesn't exist" do
85
+ FileTest.expects(:exists?).at_least_once.returns false
86
+ FileTest.expects(:exists?).with("/etc/enterprise-release").returns true
87
+ FileTest.expects(:exists?).with("/etc/ovs-release").returns false
88
+ os = subject.get_operatingsystem
89
+ expect(os).to eq "OEL"
90
+ end
91
+
92
+ it "should differentiate between Scientific Linux CERN and Scientific Linux" do
93
+ FileTest.expects(:exists?).at_least_once.returns false
94
+ FileTest.expects(:exists?).with("/etc/redhat-release").returns true
95
+ FileTest.expects(:exists?).with("/etc/enterprise-release").returns false
96
+ File.expects(:read).with("/etc/redhat-release").at_least_once.returns("Scientific Linux CERN SLC 5.7 (Boron)")
97
+ os = subject.get_operatingsystem
98
+ expect(os).to eq "SLC"
99
+ end
100
+
101
+ it "should default to RedHat" do
102
+ FileTest.expects(:exists?).at_least_once.returns false
103
+ FileTest.expects(:exists?).with("/etc/redhat-release").returns true
104
+ FileTest.expects(:exists?).with("/etc/enterprise-release").returns false
105
+ File.expects(:read).with("/etc/redhat-release").at_least_once.returns("Mystery RedHat")
106
+ os = subject.get_operatingsystem
107
+ expect(os).to eq "RedHat"
108
+ end
109
+
110
+ describe "on Oracle variants" do
111
+ it "should be OVS if /etc/ovs-release exists" do
112
+ FileTest.expects(:exists?).at_least_once.returns false
113
+ FileTest.expects(:exists?).with("/etc/enterprise-release").returns true
114
+ FileTest.expects(:exists?).with("/etc/ovs-release").returns true
115
+ os = subject.get_operatingsystem
116
+ expect(os).to eq "OVS"
117
+ end
118
+
119
+ it "should be OEL if /etc/ovs-release doesn't exist" do
120
+ FileTest.expects(:exists?).at_least_once.returns false
121
+ FileTest.expects(:exists?).with("/etc/enterprise-release").returns true
122
+ FileTest.expects(:exists?).with("/etc/ovs-release").returns false
123
+ os = subject.get_operatingsystem
124
+ expect(os).to eq "OEL"
125
+ end
126
+ end
127
+ end
128
+
129
+ describe "on distributions that rely on the contents of /etc/SuSE-release" do
130
+ before :each do
131
+ subject.expects(:get_lsbdistid).returns(nil)
132
+ end
133
+
134
+ {
135
+ "SLES" => "SUSE LINUX Enterprise Server",
136
+ "SLED" => "SUSE LINUX Enterprise Desktop",
137
+ "OpenSuSE" => "openSUSE"
138
+ }.each_pair do |operatingsystem, string|
139
+ it "should be #{operatingsystem} based on /etc/SuSE-release contents #{string}" do
140
+ FileTest.expects(:exists?).at_least_once.returns false
141
+ FileTest.expects(:exists?).with("/etc/enterprise-release").returns false
142
+ FileTest.expects(:exists?).with("/etc/redhat-release").returns false
143
+ FileTest.expects(:exists?).with("/etc/SuSE-release").returns true
144
+ File.expects(:read).with("/etc/SuSE-release").at_least_once.returns string
145
+ os = subject.get_operatingsystem
146
+ expect(os).to eq operatingsystem
147
+ end
148
+ end
149
+ end
150
+ end
151
+
152
+ describe "Osfamily fact" do
153
+ {
154
+ 'Archlinux' => 'Archlinux',
155
+ 'Ubuntu' => 'Debian',
156
+ 'Debian' => 'Debian',
157
+ 'LinuxMint' => 'Debian',
158
+ 'Gentoo' => 'Gentoo',
159
+ 'Fedora' => 'RedHat',
160
+ 'Amazon' => 'RedHat',
161
+ 'OracleLinux' => 'RedHat',
162
+ 'OVS' => 'RedHat',
163
+ 'OEL' => 'RedHat',
164
+ 'CentOS' => 'RedHat',
165
+ 'SLC' => 'RedHat',
166
+ 'Scientific' => 'RedHat',
167
+ 'CloudLinux' => 'RedHat',
168
+ 'PSBM' => 'RedHat',
169
+ 'Ascendos' => 'RedHat',
170
+ 'XenServer' => 'RedHat',
171
+ 'RedHat' => 'RedHat',
172
+ 'SLES' => 'Suse',
173
+ 'SLED' => 'Suse',
174
+ 'OpenSuSE' => 'Suse',
175
+ 'SuSE' => 'Suse',
176
+ 'Mageia' => 'Mandrake',
177
+ 'Mandriva' => 'Mandrake',
178
+ 'Mandrake' => 'Mandrake',
179
+ }.each do |os,family|
180
+ it "should return #{family} on operatingsystem #{os}" do
181
+ subject.expects(:get_operatingsystem).returns(os)
182
+ osfamily = subject.get_osfamily
183
+ expect(osfamily).to eq family
184
+ end
185
+ end
186
+
187
+ [
188
+ 'MeeGo',
189
+ 'VMWareESX',
190
+ 'Bluewhite64',
191
+ 'Slamd64',
192
+ 'Slackware',
193
+ 'Alpine',
194
+ ].each do |os|
195
+ it "should return the kernel fact on operatingsystem #{os}" do
196
+ Facter.expects(:value).with("kernel").returns "Linux"
197
+ subject.expects(:get_operatingsystem).returns(os)
198
+ osfamily = subject.get_osfamily
199
+ expect(osfamily).to eq "Linux"
200
+ end
201
+ end
202
+
203
+ it "should return the kernel value on gnu/kfreebsd" do
204
+ Facter.expects(:value).with("kernel").returns "gnu/kfreebsd"
205
+ subject.expects(:get_operatingsystem).returns("Gnu/kfreebsd")
206
+ osfamily = subject.get_osfamily
207
+ expect(osfamily).to eq "gnu/kfreebsd"
208
+ end
209
+ end
210
+
211
+ describe "Operatingsystemrelease fact" do
212
+ test_cases = {
213
+ "OpenWrt" => "/etc/openwrt_version",
214
+ "CentOS" => "/etc/redhat-release",
215
+ "RedHat" => "/etc/redhat-release",
216
+ "LinuxMint" => "/etc/linuxmint/info",
217
+ "Scientific" => "/etc/redhat-release",
218
+ "Fedora" => "/etc/fedora-release",
219
+ "MeeGo" => "/etc/meego-release",
220
+ "OEL" => "/etc/enterprise-release",
221
+ "oel" => "/etc/enterprise-release",
222
+ "OVS" => "/etc/ovs-release",
223
+ "ovs" => "/etc/ovs-release",
224
+ "OracleLinux" => "/etc/oracle-release",
225
+ "Ascendos" => "/etc/redhat-release",
226
+ }
227
+
228
+ test_cases.each do |system, file|
229
+ describe "with operatingsystem reported as #{system}" do
230
+ it "should read #{file}" do
231
+ subject.expects(:get_operatingsystem).at_least_once.returns(system)
232
+ Facter::Util::FileRead.expects(:read).with(file).at_least_once
233
+ release = subject.get_operatingsystemrelease
234
+ end
235
+ end
236
+ end
237
+
238
+ it "should not include trailing whitespace on Debian" do
239
+ subject.expects(:get_operatingsystem).returns("Debian")
240
+ Facter::Util::FileRead.expects(:read).returns("6.0.6\n")
241
+ release = subject.get_operatingsystemrelease
242
+ expect(release).to eq "6.0.6"
243
+ end
244
+
245
+ it "should run the vmware -v command in VMWareESX" do
246
+ Facter.fact(:kernel).stubs(:value).returns("VMkernel")
247
+ Facter.fact(:kernelrelease).stubs(:value).returns("4.1.0")
248
+ subject.expects(:get_operatingsystem).returns("VMwareESX")
249
+ Facter::Core::Execution.expects(:exec).with('vmware -v').returns("VMware ESX 4.1.0")
250
+ release = subject.get_operatingsystemrelease
251
+ expect(release).to eq "4.1.0"
252
+ end
253
+
254
+ it "should use the contents of /etc/alpine-release in Alpine" do
255
+ subject.expects(:get_operatingsystem).returns("Alpine")
256
+ File.expects(:read).with("/etc/alpine-release").returns("foo")
257
+ release = subject.get_operatingsystemrelease
258
+ expect(release).to eq "foo"
259
+ end
260
+
261
+ it "should fall back to parsing /etc/system-release if lsb facts are not available in Amazon" do
262
+ subject.expects(:get_operatingsystem).returns("Amazon")
263
+ subject.expects(:get_lsbdistrelease).returns(nil)
264
+ Facter::Util::FileRead.expects(:read).with('/etc/system-release').returns("Amazon Linux AMI release 2014.03")
265
+ release = subject.get_operatingsystemrelease
266
+ expect(release).to eq "2014.03"
267
+ end
268
+
269
+ it "should fall back to kernelrelease fact for gnu/kfreebsd" do
270
+ Facter.fact(:kernelrelease).stubs(:value).returns("1.2.3")
271
+ subject.expects(:get_operatingsystem).returns("GNU/kFreeBSD")
272
+ release = subject.get_operatingsystemrelease
273
+ expect(release).to eq "1.2.3"
274
+ end
275
+
276
+ describe "with operatingsystem reported as Ubuntu" do
277
+ let(:lsbrelease) { 'DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=10.04\nDISTRIB_CODENAME=lucid\nDISTRIB_DESCRIPTION="Ubuntu 10.04.4 LTS"'}
278
+
279
+ it "Returns only the major and minor version (not patch version)" do
280
+ Facter::Util::FileRead.expects(:read).with("/etc/lsb-release").returns(lsbrelease)
281
+ subject.expects(:get_operatingsystem).returns("Ubuntu")
282
+ release = subject.get_operatingsystemrelease
283
+ expect(release).to eq "10.04"
284
+ end
285
+ end
286
+ end
287
+
288
+ describe "Operatingsystemmajrelease key" do
289
+ ['Amazon','CentOS','CloudLinux','Debian','Fedora','OEL','OracleLinux','OVS','RedHat','Scientific','SLC','CumulusLinux'].each do |operatingsystem|
290
+ describe "on #{operatingsystem} operatingsystems" do
291
+ it "should be derived from operatingsystemrelease" do
292
+ subject.stubs(:get_operatingsystem).returns(operatingsystem)
293
+ subject.expects(:get_operatingsystemrelease).returns("6.3")
294
+ release = subject.get_operatingsystemmajorrelease
295
+ expect(release).to eq "6"
296
+ end
297
+ end
298
+ end
299
+
300
+ it "should derive major release properly in Ubuntu" do
301
+ subject.stubs(:get_operatingsystem).returns("Ubuntu")
302
+ subject.expects(:get_operatingsystemrelease).returns("10.04")
303
+ release = subject.get_operatingsystemmajorrelease
304
+ expect(release).to eq "10.04"
305
+ end
306
+ end
307
+
308
+ describe "Operatingsystem minor release key" do
309
+ it "should strip off the patch release if appended with a '-'" do
310
+ subject.stubs(:get_operatingsystem).returns("FreeBSD")
311
+ subject.expects(:get_operatingsystemrelease).returns("10.0-RELEASE")
312
+ release = subject.get_operatingsystemminorrelease
313
+ expect(release).to eq "0"
314
+ end
315
+ end
316
+
317
+ describe "Lsb facts" do
318
+ let(:raw_lsb_data) { "Distributor ID:\tSomeID\nDescription:\tSome Desc\nRelease:\t14.04\nCodename:\tSomeCodeName\nLSB Version:\t1.2.3" }
319
+
320
+ let(:lsb_data) { { "Distributor ID" => "SomeID",
321
+ "Description" => "Some Desc",
322
+ "Release" => "14.04",
323
+ "Codename" => "SomeCodeName",
324
+ "LSB Version" => "1.2.3"
325
+ }
326
+ }
327
+
328
+ let(:lsb_hash) { { "distcodename" => "SomeCodeName",
329
+ "distid" => "SomeID",
330
+ "distdescription" => "Some Desc",
331
+ "distrelease" => "14.04",
332
+ "release" => "1.2.3",
333
+ "majdistrelease" => "1",
334
+ "minordistrelease" => "2"
335
+ }
336
+ }
337
+
338
+ describe "collecting LSB data" do
339
+ it "should properly parse the lsb_release command" do
340
+ Facter::Core::Execution.expects(:exec).with('lsb_release -cidvr 2>/dev/null', anything).returns raw_lsb_data
341
+ lsb_hash = subject.collect_lsb_information
342
+ expect(lsb_hash).to eq lsb_data
343
+ end
344
+ end
345
+
346
+ describe "lsbdistcodename fact" do
347
+ [ "Linux", "GNU/kFreeBSD"].each do |kernel|
348
+ describe "on #{kernel}" do
349
+ it "returns the codename" do
350
+ subject.expects(:collect_lsb_information).returns lsb_data
351
+ lsbdistcodename = subject.get_lsbdistcodename
352
+ expect(lsbdistcodename).to eq 'SomeCodeName'
353
+ end
354
+
355
+ it "returns nil if lsb_release is not installed" do
356
+ subject.expects(:collect_lsb_information).returns nil
357
+ lsbdistcodename = subject.get_lsbdistcodename
358
+ expect(lsbdistcodename).to be_nil
359
+ end
360
+ end
361
+ end
362
+
363
+ it "should return the lsbdistcodename in the lsb facts hash" do
364
+ subject.expects(:get_lsb_facts_hash).returns(lsb_hash)
365
+ lsbdistcodename = subject.get_lsb_facts_hash["distcodename"]
366
+ expect(lsbdistcodename).to eq "SomeCodeName"
367
+ end
368
+ end
369
+
370
+ describe "lsbdistid fact" do
371
+ [ "Linux", "GNU/kFreeBSD"].each do |kernel|
372
+ describe "on #{kernel}" do
373
+ it "returns the id" do
374
+ subject.expects(:collect_lsb_information).returns lsb_data
375
+ lsbdistid = subject.get_lsbdistid
376
+ expect(lsbdistid).to eq 'SomeID'
377
+ end
378
+
379
+ it "returns nil if lsb_release is not installed" do
380
+ subject.expects(:collect_lsb_information).returns nil
381
+ lsbdistid = subject.get_lsbdistid
382
+ expect(lsbdistid).to be_nil
383
+ end
384
+ end
385
+ end
386
+
387
+ it "should return the lsbdistid in the lsb facts hash" do
388
+ subject.expects(:get_lsb_facts_hash).returns(lsb_hash)
389
+ lsbdistid = subject.get_lsb_facts_hash["distid"]
390
+ expect(lsbdistid).to eq "SomeID"
391
+ end
392
+ end
393
+
394
+ describe "lsbdistdescription fact" do
395
+ [ "Linux", "GNU/kFreeBSD"].each do |kernel|
396
+ describe "on #{kernel}" do
397
+ it "returns the description" do
398
+ subject.expects(:collect_lsb_information).returns lsb_data
399
+ lsbdistdescription = subject.get_lsbdistdescription
400
+ expect(lsbdistdescription).to eq 'Some Desc'
401
+ end
402
+
403
+ it "returns nil if lsb_release is not installed" do
404
+ subject.expects(:collect_lsb_information).returns nil
405
+ lsbdistdescription = subject.get_lsbdistdescription
406
+ expect(lsbdistdescription).to be_nil
407
+ end
408
+ end
409
+ end
410
+
411
+ it "should return the lsbdistdescription in the lsb facts hash" do
412
+ subject.expects(:get_lsb_facts_hash).returns(lsb_hash)
413
+ lsbdistdescription = subject.get_lsb_facts_hash["distdescription"]
414
+ expect(lsbdistdescription).to eq "Some Desc"
415
+ end
416
+ end
417
+
418
+ describe "lsbrelease fact" do
419
+ [ "Linux", "GNU/kFreeBSD"].each do |kernel|
420
+ describe "on #{kernel}" do
421
+ it "returns the LSB release" do
422
+ subject.expects(:collect_lsb_information).returns lsb_data
423
+ lsbrelease = subject.get_lsbrelease
424
+ expect(lsbrelease).to eq '1.2.3'
425
+ end
426
+
427
+ it "returns nil if lsb_release is not installed" do
428
+ subject.expects(:collect_lsb_information).returns nil
429
+ lsbrelease = subject.get_lsbrelease
430
+ expect(lsbrelease).to be_nil
431
+ end
432
+ end
433
+ end
434
+
435
+ it "should return the lsbrelease in the lsb facts hash" do
436
+ subject.expects(:get_lsb_facts_hash).returns(lsb_hash)
437
+ lsbrelease = subject.get_lsb_facts_hash["release"]
438
+ expect(lsbrelease).to eq '1.2.3'
439
+ end
440
+ end
441
+
442
+ describe "lsbdistrelease fact" do
443
+ [ "Linux", "GNU/kFreeBSD"].each do |kernel|
444
+ describe "on #{kernel}" do
445
+ it "should return the dist release" do
446
+ subject.expects(:collect_lsb_information).returns lsb_data
447
+ lsbdistrelease = subject.get_lsbdistrelease
448
+ expect(lsbdistrelease).to eq '14.04'
449
+ end
450
+
451
+ it "should return nil if lsb_release is not installed" do
452
+ subject.expects(:collect_lsb_information).returns nil
453
+ lsbdistrelease = subject.get_lsbdistrelease
454
+ expect(lsbdistrelease).to be_nil
455
+ end
456
+ end
457
+ end
458
+
459
+ it "should return the lsbdistrelease in the lsb facts hash" do
460
+ subject.expects(:get_lsb_facts_hash).returns(lsb_hash)
461
+ lsbdistrelease = subject.get_lsb_facts_hash["distrelease"]
462
+ expect(lsbdistrelease).to eq '14.04'
463
+ end
464
+ end
465
+
466
+ describe "lsbmajdistrelease fact" do
467
+ it "should be derived from lsb_release" do
468
+ subject.expects(:get_operatingsystem).returns("Amazon")
469
+ subject.expects(:get_lsbdistrelease).returns("10.04")
470
+ lsbmajdistrelease = subject.get_lsbmajdistrelease
471
+ expect(lsbmajdistrelease).to eq "10"
472
+ end
473
+
474
+ it "should derive correctly in Ubuntu" do
475
+ subject.expects(:get_operatingsystem).returns("Ubuntu")
476
+ subject.expects(:get_lsbdistrelease).returns("10.04")
477
+ lsbmajdistrelease = subject.get_lsbmajdistrelease
478
+ expect(lsbmajdistrelease).to eq "10.04"
479
+ end
480
+
481
+ it "should return the lsbmajdistrelease" do
482
+ subject.expects(:get_lsb_facts_hash).returns(lsb_hash)
483
+ lsbmajdistrelease = subject.get_lsb_facts_hash["majdistrelease"]
484
+ expect(lsbmajdistrelease).to eq "1"
485
+ end
486
+ end
487
+
488
+ describe "lsbminordistrelease fact" do
489
+ it "should be derived from lsb_release" do
490
+ subject.expects(:get_operatingsystem).returns("Amazon")
491
+ subject.expects(:get_lsbdistrelease).returns("10.04")
492
+ lsbminordistrelease = subject.get_lsbminordistrelease
493
+ expect(lsbminordistrelease).to eq "04"
494
+ end
495
+
496
+ it "should derive correctly in Ubuntu" do
497
+ subject.expects(:get_operatingsystem).returns("Ubuntu")
498
+ subject.expects(:get_lsbdistrelease).returns("10.04.02")
499
+ lsbminordistrelease = subject.get_lsbminordistrelease
500
+ expect(lsbminordistrelease).to eq "02"
501
+ end
502
+
503
+ it 'should be derived from lsbdistrelease and take Y from version X.Y' do
504
+ subject.expects(:get_operatingsystem).returns("Amazon")
505
+ subject.expects(:get_lsbdistrelease).returns("6.4")
506
+ lsbminordistrelease = subject.get_lsbminordistrelease
507
+ expect(lsbminordistrelease).to eq "4"
508
+ end
509
+
510
+ it 'should be derived from lsbdistrelease and take Y from version X.Y.Z' do
511
+ subject.expects(:get_operatingsystem).returns("Amazon")
512
+ subject.expects(:get_lsbdistrelease).returns("6.4.1")
513
+ lsbminordistrelease = subject.get_lsbminordistrelease
514
+ expect(lsbminordistrelease).to eq "4"
515
+ end
516
+
517
+ it 'should be derived from lsbdistrelease and take Y from version X.Y.Z where multiple digits exist' do
518
+ subject.expects(:get_operatingsystem).returns("Amazon")
519
+ subject.expects(:get_lsbdistrelease).returns("10.20.30")
520
+ lsbminordistrelease = subject.get_lsbminordistrelease
521
+ expect(lsbminordistrelease).to eq "20"
522
+ end
523
+
524
+ it 'should not be present if lsbdistrelease is only X and is missing .Y' do
525
+ subject.expects(:get_operatingsystem).returns("Amazon")
526
+ subject.expects(:get_lsbdistrelease).returns("6")
527
+ lsbminordistrelease = subject.get_lsbminordistrelease
528
+ expect(lsbminordistrelease).to be_nil
529
+ end
530
+
531
+ it "should return the lsbmajdistrelease" do
532
+ subject.expects(:get_lsb_facts_hash).returns(lsb_hash)
533
+ lsbminordistrelease = subject.get_lsb_facts_hash["minordistrelease"]
534
+ expect(lsbminordistrelease).to eq "2"
535
+ end
536
+ end
537
+ end
538
+ end