ohey 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +12 -0
- data/README.md +48 -0
- data/Rakefile +13 -0
- data/lib/ohey.rb +65 -0
- data/lib/ohey/aix.rb +30 -0
- data/lib/ohey/darwin.rb +38 -0
- data/lib/ohey/dragonflybsd.rb +31 -0
- data/lib/ohey/freebsd.rb +31 -0
- data/lib/ohey/linux.rb +355 -0
- data/lib/ohey/netbsd.rb +31 -0
- data/lib/ohey/openbsd.rb +31 -0
- data/lib/ohey/solaris2.rb +72 -0
- data/lib/ohey/version.rb +4 -0
- data/lib/ohey/windows.rb +50 -0
- data/ohey.gemspec +19 -0
- data/spec/aix_spec.rb +35 -0
- data/spec/darwin_spec.rb +37 -0
- data/spec/dragonflybsd_spec.rb +34 -0
- data/spec/freebsd_spec.rb +34 -0
- data/spec/linux_spec.rb +739 -0
- data/spec/netbsd_spec.rb +34 -0
- data/spec/ohey_spec.rb +20 -0
- data/spec/openbsd_spec.rb +34 -0
- data/spec/solaris2_spec.rb +256 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/windows_spec.rb +41 -0
- metadata +85 -0
data/lib/ohey/netbsd.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Ohey
|
2
|
+
class NetBSD
|
3
|
+
FAMILY = 'netbsd'.freeze
|
4
|
+
|
5
|
+
def name
|
6
|
+
@name ||= uname_s.strip.downcase
|
7
|
+
end
|
8
|
+
|
9
|
+
def version
|
10
|
+
@version ||= uname_r.strip
|
11
|
+
end
|
12
|
+
|
13
|
+
def build
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def family
|
18
|
+
FAMILY
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def uname_s
|
24
|
+
@uname_s ||= `uname -s`
|
25
|
+
end
|
26
|
+
|
27
|
+
def uname_r
|
28
|
+
@uname_r ||= `uname -r`
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/ohey/openbsd.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Ohey
|
2
|
+
class OpenBSD
|
3
|
+
FAMILY = 'openbsd'.freeze
|
4
|
+
|
5
|
+
def name
|
6
|
+
@name ||= uname_s.strip.downcase
|
7
|
+
end
|
8
|
+
|
9
|
+
def version
|
10
|
+
@version ||= uname_r.strip
|
11
|
+
end
|
12
|
+
|
13
|
+
def build
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def family
|
18
|
+
FAMILY
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def uname_s
|
24
|
+
@uname_s ||= `uname -s`
|
25
|
+
end
|
26
|
+
|
27
|
+
def uname_r
|
28
|
+
@uname_r ||= `uname -r`
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Ohey
|
2
|
+
class Solaris2
|
3
|
+
UNAME_PATH = '/sbin/uname'.freeze
|
4
|
+
RELEASE_PATH = '/etc/release'.freeze
|
5
|
+
|
6
|
+
def name
|
7
|
+
@name ||= release.find do |line|
|
8
|
+
case line
|
9
|
+
when /.*SmartOS.*/
|
10
|
+
break 'smartos'
|
11
|
+
when /^\s*OmniOS.*r(\d+).*$/
|
12
|
+
break 'omnios'
|
13
|
+
when /^\s*OpenIndiana.*(Development oi_|Hipster )(\d\S*)/
|
14
|
+
break 'openindiana'
|
15
|
+
when /^\s*(Oracle Solaris|Solaris)/
|
16
|
+
break 'solaris2'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def version
|
22
|
+
@version ||= version_from_release || version_from_uname
|
23
|
+
end
|
24
|
+
|
25
|
+
def build
|
26
|
+
@build ||= uname.find do |line|
|
27
|
+
case line
|
28
|
+
when /^KernelID =\s+(.+)$/
|
29
|
+
break $1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def family
|
35
|
+
name
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def version_from_uname
|
41
|
+
uname.find do |line|
|
42
|
+
case line
|
43
|
+
when /^Release =\s+(.+)$/
|
44
|
+
break $1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def version_from_release
|
50
|
+
release.find do |line|
|
51
|
+
case line
|
52
|
+
when /^\s*OmniOS.*r(\d+).*$/
|
53
|
+
break $1
|
54
|
+
when /^\s*OpenIndiana.*(Development oi_|Hipster )(\d\S*)/
|
55
|
+
break $2
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def uname
|
61
|
+
@uname ||= `#{uname_exec} -X`.split("\n")
|
62
|
+
end
|
63
|
+
|
64
|
+
def uname_exec
|
65
|
+
@uname_exec ||= File.exist?(UNAME_PATH) ? UNAME_PATH : 'uname'
|
66
|
+
end
|
67
|
+
|
68
|
+
def release
|
69
|
+
@release ||= File.read(RELEASE_PATH).split("\n")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/ohey/version.rb
ADDED
data/lib/ohey/windows.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'wmi-lite/wmi'
|
2
|
+
|
3
|
+
module Ohey
|
4
|
+
class Windows
|
5
|
+
FAMILY = 'windows'.freeze
|
6
|
+
|
7
|
+
def name
|
8
|
+
@name ||= os_type_decode(host['ostype'])
|
9
|
+
end
|
10
|
+
|
11
|
+
def version
|
12
|
+
@version ||= host['version']
|
13
|
+
end
|
14
|
+
|
15
|
+
def build
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def family
|
20
|
+
FAMILY
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# decode the OSType field from WMI Win32_OperatingSystem class
|
26
|
+
# https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
|
27
|
+
# @param [Integer] sys_type OSType value from Win32_OperatingSystem
|
28
|
+
# @return [String] the human consumable OS type value
|
29
|
+
def os_type_decode(sys_type)
|
30
|
+
case sys_type
|
31
|
+
when 18 then "WINNT" # most likely so first
|
32
|
+
when 0 then "Unknown"
|
33
|
+
when 1 then "Other"
|
34
|
+
when 14 then "MSDOS"
|
35
|
+
when 15 then "WIN3x"
|
36
|
+
when 16 then "WIN95"
|
37
|
+
when 17 then "WIN98"
|
38
|
+
when 19 then "WINCE"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def wmi
|
43
|
+
@wmi ||= WmiLite::Wmi.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def host
|
47
|
+
@host ||= wmi.first_of('Win32_OperatingSystem')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/ohey.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), 'lib')
|
2
|
+
require 'ohey/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'ohey'
|
6
|
+
s.version = ::Ohey::VERSION
|
7
|
+
s.authors = ['Cameron Dutro']
|
8
|
+
s.email = ['camertron@gmail.com']
|
9
|
+
s.homepage = 'http://github.com/camertron/ohey'
|
10
|
+
|
11
|
+
s.description = s.summary = 'A rewrite of the platform detection logic in ohai, '\
|
12
|
+
'but with fewer dependencies and 100% less metaprogramming.'
|
13
|
+
s.platform = Gem::Platform::RUBY
|
14
|
+
|
15
|
+
s.add_dependency 'wmi-lite', '~> 1.0'
|
16
|
+
|
17
|
+
s.require_path = 'lib'
|
18
|
+
s.files = Dir['{lib,spec}/**/*', 'Gemfile', 'CHANGELOG.md', 'README.md', 'Rakefile', 'ohey.gemspec']
|
19
|
+
end
|
data/spec/aix_spec.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ohey::Aix do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
before do
|
7
|
+
allow(subject).to receive(:uname_rvp).and_return(
|
8
|
+
"2 7 powerpc".split
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#name' do
|
13
|
+
it 'correctly identifies the platform' do
|
14
|
+
expect(subject.name).to eq('aix')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#family' do
|
19
|
+
it 'correctly identifies the platform family' do
|
20
|
+
expect(subject.family).to eq('aix')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#build' do
|
25
|
+
it 'correctly identifies the platform build' do
|
26
|
+
expect(subject.build).to eq(nil)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#version' do
|
31
|
+
it 'correctly identifies the platform version' do
|
32
|
+
expect(subject.version).to eq('7.2')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/darwin_spec.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ohey::Darwin do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
before do
|
7
|
+
allow(subject).to receive(:sw_vers).and_return([
|
8
|
+
'ProductName: Mac OS X',
|
9
|
+
'ProductVersion: 10.15.6',
|
10
|
+
'BuildVersion: 19G46c'
|
11
|
+
])
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#name' do
|
15
|
+
it 'correctly identifies the platform' do
|
16
|
+
expect(subject.name).to eq('mac_os_x')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#family' do
|
21
|
+
it 'correctly identifies the platform family' do
|
22
|
+
expect(subject.family).to eq('mac_os_x')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#build' do
|
27
|
+
it 'correctly identifies the platform build' do
|
28
|
+
expect(subject.build).to eq('19G46c')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#platform_version' do
|
33
|
+
it 'correctly identifies the platform version' do
|
34
|
+
expect(subject.version).to eq('10.15.6')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ohey::DragonflyBSD.new do
|
4
|
+
subject { described_class }
|
5
|
+
|
6
|
+
before do
|
7
|
+
allow(subject).to receive(:uname_s).and_return("DragonflyBSD\n")
|
8
|
+
allow(subject).to receive(:uname_r).and_return("7.1\n")
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#name' do
|
12
|
+
it 'correctly identifies the platform' do
|
13
|
+
expect(subject.name).to eq('dragonflybsd')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#family' do
|
18
|
+
it 'correctly identifies the platform family' do
|
19
|
+
expect(subject.family).to eq('dragonflybsd')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#build' do
|
24
|
+
it 'correctly identifies the platform build' do
|
25
|
+
expect(subject.build).to eq(nil)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#version' do
|
30
|
+
it 'correctly identifies the platform version' do
|
31
|
+
expect(subject.version).to eq('7.1')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ohey::FreeBSD do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
before do
|
7
|
+
allow(subject).to receive(:uname_s).and_return("FreeBSD\n")
|
8
|
+
allow(subject).to receive(:uname_r).and_return("7.1\n")
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#name' do
|
12
|
+
it 'correctly identifies the platform' do
|
13
|
+
expect(subject.name).to eq('freebsd')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#family' do
|
18
|
+
it 'correctly identifies the platform family' do
|
19
|
+
expect(subject.family).to eq('freebsd')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#build' do
|
24
|
+
it 'correctly identifies the platform build' do
|
25
|
+
expect(subject.build).to eq(nil)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#version' do
|
30
|
+
it 'correctly identifies the platform version' do
|
31
|
+
expect(subject.version).to eq('7.1')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/linux_spec.rb
ADDED
@@ -0,0 +1,739 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ohey::Linux do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe "#family" do
|
7
|
+
%w{oracle centos redhat scientific enterpriseenterprise xenserver cloudlinux ibm_powerkvm parallels nexus_centos clearos bigip}.each do |p|
|
8
|
+
it "returns rhel for #{p} platform" do
|
9
|
+
allow(subject).to receive(:name).and_return(p)
|
10
|
+
expect(subject.family).to eq('rhel')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
%w{suse sles opensuse opensuseleap sled}.each do |p|
|
15
|
+
it "returns suse for #{p} family" do
|
16
|
+
allow(subject).to receive(:name).and_return(p)
|
17
|
+
expect(subject.family).to eq('suse')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
%w{fedora arista_eos}.each do |p|
|
22
|
+
it "returns fedora for #{p} family" do
|
23
|
+
allow(subject).to receive(:name).and_return(p)
|
24
|
+
expect(subject.family).to eq('fedora')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
%w{nexus ios_xr}.each do |p|
|
29
|
+
it "returns wrlinux for #{p} family" do
|
30
|
+
allow(subject).to receive(:name).and_return(p)
|
31
|
+
expect(subject.family).to eq('wrlinux')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
%w{arch manjaro}.each do |p|
|
36
|
+
it "returns arch for #{p} family" do
|
37
|
+
allow(subject).to receive(:name).and_return(p)
|
38
|
+
expect(subject.family).to eq('arch')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
%w{amazon slackware gentoo exherbo alpine clearlinux}.each do |same_name|
|
43
|
+
it "returns #{same_name} for #{same_name} family" do
|
44
|
+
allow(subject).to receive(:name).and_return(same_name)
|
45
|
+
expect(subject.family).to eq(same_name)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns mandriva for mangeia platform' do
|
50
|
+
allow(subject).to receive(:name).and_return('mangeia')
|
51
|
+
expect(subject.family).to eq('mandriva')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'on system with /etc/os-release' do
|
56
|
+
before do
|
57
|
+
allow(File).to receive(:exist?).with('/etc/os-release').and_return(true)
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when os-release data is correct' do
|
61
|
+
let(:os_data) do
|
62
|
+
<<~OS_DATA
|
63
|
+
NAME="Ubuntu"
|
64
|
+
VERSION="14.04.5 LTS, Trusty Tahr"
|
65
|
+
ID=ubuntu
|
66
|
+
ID_LIKE=debian
|
67
|
+
PRETTY_NAME="Ubuntu 14.04.5 LTS"
|
68
|
+
VERSION_ID="14.04"
|
69
|
+
OS_DATA
|
70
|
+
end
|
71
|
+
|
72
|
+
before do
|
73
|
+
allow(File).to receive(:read).with('/etc/os-release').and_return(os_data)
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#platform' do
|
77
|
+
it 'correctly identifies the platform' do
|
78
|
+
expect(subject.name).to eq('ubuntu')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#family' do
|
83
|
+
it 'correctly identifies the platform family' do
|
84
|
+
expect(subject.family).to eq('debian')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#build' do
|
89
|
+
it 'correctly identifies the platform build' do
|
90
|
+
expect(subject.build).to eq(nil)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#version' do
|
95
|
+
it 'correctly identifies the version' do
|
96
|
+
expect(subject.version).to eq('14.04')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'when os-release data is missing a version_id' do
|
102
|
+
let(:os_data) do
|
103
|
+
<<~OS_DATA
|
104
|
+
NAME="Arch Linux"
|
105
|
+
PRETTY_NAME="Arch Linux"
|
106
|
+
ID=arch
|
107
|
+
ID_LIKE=archlinux
|
108
|
+
OS_DATA
|
109
|
+
end
|
110
|
+
|
111
|
+
before do
|
112
|
+
allow(File).to receive(:read).with('/etc/os-release').and_return(os_data)
|
113
|
+
allow(subject).to receive(:uname_r).and_return("3.18.2-2-ARCH\n")
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#name' do
|
117
|
+
it 'correctly identifies the platform' do
|
118
|
+
expect(subject.name).to eq('arch')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe '#family' do
|
123
|
+
it 'correctly identifies the platform family' do
|
124
|
+
expect(subject.family).to eq('arch')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe '#build' do
|
129
|
+
it 'correctly identifies the platform build' do
|
130
|
+
expect(subject.build).to eq(nil)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#version' do
|
135
|
+
it 'correctly identifies the version' do
|
136
|
+
expect(subject.version).to eq('3.18.2-2-ARCH')
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'when platform requires remapping' do
|
142
|
+
let(:os_data) do
|
143
|
+
<<~OS_DATA
|
144
|
+
NAME="openSUSE Leap"
|
145
|
+
VERSION="15.0"
|
146
|
+
ID="opensuse-leap"
|
147
|
+
ID_LIKE="suse opensuse"
|
148
|
+
VERSION_ID="15.0"
|
149
|
+
PRETTY_NAME="openSUSE Leap 15.0"
|
150
|
+
OS_DATA
|
151
|
+
end
|
152
|
+
|
153
|
+
before do
|
154
|
+
allow(File).to receive(:read).with('/etc/os-release').and_return(os_data)
|
155
|
+
end
|
156
|
+
|
157
|
+
describe '#name' do
|
158
|
+
it 'correctly identifies the platform' do
|
159
|
+
expect(subject.name).to eq('opensuseleap')
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe '#family' do
|
164
|
+
it 'correctly identifies the family' do
|
165
|
+
expect(subject.family).to eq('suse')
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe '#build' do
|
170
|
+
it 'correctly identifies the platform build' do
|
171
|
+
expect(subject.build).to eq(nil)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe '#version' do
|
176
|
+
it 'correctly identifies the platform version' do
|
177
|
+
expect(subject.version).to eq('15.0')
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'when on centos where version data in os-release is wrong' do
|
183
|
+
let(:os_data) do
|
184
|
+
<<~OS_DATA
|
185
|
+
NAME="CentOS Linux"
|
186
|
+
VERSION="7 (Core)"
|
187
|
+
ID="centos"
|
188
|
+
ID_LIKE="rhel fedora"
|
189
|
+
VERSION_ID="7"
|
190
|
+
PRETTY_NAME="CentOS Linux 7 (Core)"
|
191
|
+
OS_DATA
|
192
|
+
end
|
193
|
+
|
194
|
+
let(:redhat_data) { 'CentOS Linux release 7.5.1804 (Core)' }
|
195
|
+
|
196
|
+
before do
|
197
|
+
allow(File).to receive(:read).with('/etc/os-release').and_return(os_data)
|
198
|
+
allow(File).to receive(:read).with('/etc/redhat-release').and_return(redhat_data)
|
199
|
+
end
|
200
|
+
|
201
|
+
describe '#platform' do
|
202
|
+
it 'correctly identifies the platform' do
|
203
|
+
expect(subject.name).to eq('centos')
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe '#family' do
|
208
|
+
it 'correctly identifies the platform family' do
|
209
|
+
expect(subject.family).to eq('rhel')
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe '#build' do
|
214
|
+
it 'correctly identifies the platform build' do
|
215
|
+
expect(subject.build).to eq(nil)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe '#version' do
|
220
|
+
it 'correctly identifies the version' do
|
221
|
+
expect(subject.version).to eq('7.5.1804')
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
context 'when on debian and version data in os-release is missing' do
|
227
|
+
let(:os_data) do
|
228
|
+
<<~OS_DATA
|
229
|
+
PRETTY_NAME="Debian GNU/Linux bullseye/sid"
|
230
|
+
NAME="Debian GNU/Linux"
|
231
|
+
ID=debian
|
232
|
+
HOME_URL="https://www.debian.org/"
|
233
|
+
SUPPORT_URL="https://www.debian.org/support"
|
234
|
+
BUG_REPORT_URL="https://bugs.debian.org/"
|
235
|
+
OS_DATA
|
236
|
+
end
|
237
|
+
|
238
|
+
let(:debian_data) { 'bullseye/sid' }
|
239
|
+
|
240
|
+
before do
|
241
|
+
allow(File).to receive(:read).with('/etc/os-release').and_return(os_data)
|
242
|
+
allow(File).to receive(:read).with('/etc/debian_version').and_return(debian_data)
|
243
|
+
end
|
244
|
+
|
245
|
+
describe '#platform' do
|
246
|
+
it 'correctly identifies the platform' do
|
247
|
+
expect(subject.name).to eq('debian')
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
describe '#family' do
|
252
|
+
it 'correctly identifies the platform family' do
|
253
|
+
expect(subject.family).to eq('debian')
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
describe '#build' do
|
258
|
+
it 'correctly identifies the platform build' do
|
259
|
+
expect(subject.build).to eq(nil)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
describe '#version' do
|
264
|
+
it 'correctly identifies the platform version' do
|
265
|
+
expect(subject.version).to eq('bullseye/sid')
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
context "when on system without /etc/os-release (legacy)" do
|
272
|
+
let(:have_debian_version) { false }
|
273
|
+
let(:have_redhat_release) { false }
|
274
|
+
let(:have_exherbo_release) { false }
|
275
|
+
let(:have_eos_release) { false }
|
276
|
+
let(:have_suse_release) { false }
|
277
|
+
let(:have_system_release) { false }
|
278
|
+
let(:have_slackware_version) { false }
|
279
|
+
let(:have_enterprise_release) { false }
|
280
|
+
let(:have_oracle_release) { false }
|
281
|
+
let(:have_parallels_release) { false }
|
282
|
+
let(:have_os_release) { false }
|
283
|
+
let(:have_os_release) { false }
|
284
|
+
let(:have_usr_lib_os_release) { false }
|
285
|
+
let(:have_cisco_release) { false }
|
286
|
+
let(:have_f5_release) { false }
|
287
|
+
|
288
|
+
before do
|
289
|
+
allow(File).to receive(:exist?).with('/etc/debian_version').and_return(have_debian_version)
|
290
|
+
allow(File).to receive(:exist?).with('/etc/redhat-release').and_return(have_redhat_release)
|
291
|
+
allow(File).to receive(:exist?).with('/etc/exherbo-release').and_return(have_exherbo_release)
|
292
|
+
allow(File).to receive(:exist?).with('/etc/Eos-release').and_return(have_eos_release)
|
293
|
+
allow(File).to receive(:exist?).with('/etc/SuSE-release').and_return(have_suse_release)
|
294
|
+
allow(File).to receive(:exist?).with('/etc/system-release').and_return(have_system_release)
|
295
|
+
allow(File).to receive(:exist?).with('/etc/slackware-version').and_return(have_slackware_version)
|
296
|
+
allow(File).to receive(:exist?).with('/etc/enterprise-release').and_return(have_enterprise_release)
|
297
|
+
allow(File).to receive(:exist?).with('/etc/oracle-release').and_return(have_oracle_release)
|
298
|
+
allow(File).to receive(:exist?).with('/etc/parallels-release').and_return(have_parallels_release)
|
299
|
+
allow(File).to receive(:exist?).with('/etc/os-release').and_return(have_os_release)
|
300
|
+
allow(File).to receive(:exist?).with('/etc/f5-release').and_return(have_f5_release)
|
301
|
+
allow(File).to receive(:exist?).with('/usr/lib/os-release').and_return(have_usr_lib_os_release)
|
302
|
+
allow(File).to receive(:exist?).with('/etc/shared/os-release').and_return(have_cisco_release)
|
303
|
+
|
304
|
+
allow(File).to receive(:read).with("PLEASE STUB ALL plugin.read CALLS")
|
305
|
+
end
|
306
|
+
|
307
|
+
context "on lsb compliant distributions" do
|
308
|
+
context 'ubuntu' do
|
309
|
+
before do
|
310
|
+
allow(subject).to receive(:lsb).and_return({ id: 'Ubuntu', release: '18.04' })
|
311
|
+
end
|
312
|
+
|
313
|
+
it 'sets platform to lowercased lsb[:id]' do
|
314
|
+
expect(subject.name).to eq('ubuntu')
|
315
|
+
end
|
316
|
+
|
317
|
+
it 'sets platform_version to lsb[:release]' do
|
318
|
+
expect(subject.version).to eq('18.04')
|
319
|
+
end
|
320
|
+
|
321
|
+
it 'sets platform to ubuntu and platform_family to debian lsb[:id] contains Ubuntu' do
|
322
|
+
expect(subject.name).to eq('ubuntu')
|
323
|
+
expect(subject.family).to eq('debian')
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
context 'debian' do
|
328
|
+
before do
|
329
|
+
allow(subject).to receive(:lsb).and_return({ id: 'Debian', release: '18.04' })
|
330
|
+
end
|
331
|
+
|
332
|
+
it 'sets platform to debian and platform_family to debian lsb[:id] contains Debian' do
|
333
|
+
expect(subject.name).to eq('debian')
|
334
|
+
expect(subject.family).to eq('debian')
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
context 'red hat' do
|
339
|
+
before do
|
340
|
+
allow(subject).to receive(:lsb).and_return({ id: 'RedHatEnterpriseServer', release: '7.5' })
|
341
|
+
end
|
342
|
+
|
343
|
+
it "sets platform to redhat and platform_family to rhel when lsb[:id] contains Redhat" do
|
344
|
+
expect(subject.name).to eq('redhat')
|
345
|
+
expect(subject.family).to eq('rhel')
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
context 'amazon' do
|
350
|
+
before do
|
351
|
+
allow(subject).to receive(:lsb).and_return({ id: 'AmazonAMI', release: '2018.03' })
|
352
|
+
end
|
353
|
+
|
354
|
+
it 'sets platform to amazon and platform_family to rhel when lsb[:id] contains Amazon' do
|
355
|
+
expect(subject.name).to eq('amazon')
|
356
|
+
expect(subject.family).to eq('amazon')
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
context 'scientific' do
|
361
|
+
before do
|
362
|
+
allow(subject).to receive(:lsb).and_return({ id: 'ScientificSL', release: '7.5' })
|
363
|
+
end
|
364
|
+
|
365
|
+
it 'sets platform to scientific when lsb[:id] contains ScientificSL' do
|
366
|
+
expect(subject.name).to eq('scientific')
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
context 'ibm' do
|
371
|
+
before do
|
372
|
+
allow(subject).to receive(:lsb).and_return({ id: 'IBM_PowerKVM', release: '2.1' })
|
373
|
+
end
|
374
|
+
|
375
|
+
it 'sets platform to ibm_powerkvm and platform_family to rhel when lsb[:id] contains IBM_PowerKVM' do
|
376
|
+
expect(subject.name).to eq('ibm_powerkvm')
|
377
|
+
expect(subject.family).to eq('rhel')
|
378
|
+
end
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
context 'on debian' do
|
383
|
+
let(:have_debian_version) { true }
|
384
|
+
let(:lsb) { {} }
|
385
|
+
|
386
|
+
before do
|
387
|
+
expect(subject).to receive(:lsb).and_return(lsb)
|
388
|
+
end
|
389
|
+
|
390
|
+
it 'reads the version from /etc/debian_version' do
|
391
|
+
expect(File).to receive(:read).with('/etc/debian_version').and_return('9.5')
|
392
|
+
expect(subject.version).to eq('9.5')
|
393
|
+
end
|
394
|
+
|
395
|
+
it 'correctly strips any newlines' do
|
396
|
+
expect(File).to receive(:read).with('/etc/debian_version').and_return("9.5\n")
|
397
|
+
expect(subject.version).to eq('9.5')
|
398
|
+
end
|
399
|
+
|
400
|
+
context 'ubuntu' do
|
401
|
+
let(:lsb) { { id: 'Ubuntu', release: '18.04' } }
|
402
|
+
|
403
|
+
# Ubuntu has /etc/debian_version as well
|
404
|
+
it 'detects Ubuntu as itself rather than debian' do
|
405
|
+
expect(subject.name).to eq('ubuntu')
|
406
|
+
end
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
context 'on slackware' do
|
411
|
+
let(:have_slackware_version) { true }
|
412
|
+
let(:lsb) { {} }
|
413
|
+
|
414
|
+
before do
|
415
|
+
allow(subject).to receive(:lsb).and_return(lsb)
|
416
|
+
end
|
417
|
+
|
418
|
+
it 'sets platform and platform_family to slackware' do
|
419
|
+
allow(File).to receive(:read).with('/etc/slackware-version').and_return('Slackware 12.0.0')
|
420
|
+
expect(subject.name).to eq('slackware')
|
421
|
+
expect(subject.family).to eq('slackware')
|
422
|
+
end
|
423
|
+
|
424
|
+
it 'sets platform_version on slackware' do
|
425
|
+
allow(File).to receive(:read).with('/etc/slackware-version').and_return('Slackware 12.0.0')
|
426
|
+
expect(subject.version).to eq('12.0.0')
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
context 'on arista eos' do
|
431
|
+
let(:have_system_release) { true }
|
432
|
+
let(:have_redhat_release) { true }
|
433
|
+
let(:have_eos_release) { true }
|
434
|
+
let(:lsb) { {} }
|
435
|
+
|
436
|
+
before do
|
437
|
+
allow(subject).to receive(:lsb).and_return(lsb)
|
438
|
+
end
|
439
|
+
|
440
|
+
it 'sets platform to arista_eos' do
|
441
|
+
expect(File).to receive(:read).with('/etc/Eos-release').and_return('Arista Networks EOS 4.21.1.1F')
|
442
|
+
expect(subject.name).to eq("arista_eos")
|
443
|
+
expect(subject.family).to eq("fedora")
|
444
|
+
expect(subject.version).to eq("4.21.1.1F")
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
context 'on f5 big-ip' do
|
449
|
+
let(:have_f5_release) { true }
|
450
|
+
let(:lsb) { {} }
|
451
|
+
|
452
|
+
before do
|
453
|
+
allow(subject).to receive(:lsb).and_return(lsb)
|
454
|
+
end
|
455
|
+
|
456
|
+
it "sets platform to bigip" do
|
457
|
+
expect(File).to receive(:read).with('/etc/f5-release').and_return('BIG-IP release 13.0.0 (Final)')
|
458
|
+
expect(subject.name).to eq('bigip')
|
459
|
+
expect(subject.family).to eq('rhel')
|
460
|
+
expect(subject.version).to eq('13.0.0')
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
context 'on exherbo' do
|
465
|
+
let(:have_exherbo_release) { true }
|
466
|
+
let(:lsb) { {} }
|
467
|
+
|
468
|
+
before do
|
469
|
+
allow(subject).to receive(:uname_r).and_return("3.18.2-2-ARCH\n")
|
470
|
+
allow(subject).to receive(:lsb).and_return(lsb)
|
471
|
+
end
|
472
|
+
|
473
|
+
it 'sets platform and platform_family to exherbo' do
|
474
|
+
expect(subject.name).to eq('exherbo')
|
475
|
+
expect(subject.family).to eq('exherbo')
|
476
|
+
end
|
477
|
+
|
478
|
+
it 'sets platform_version to kernel release' do
|
479
|
+
expect(subject.version).to eq('3.18.2-2-ARCH')
|
480
|
+
end
|
481
|
+
end
|
482
|
+
|
483
|
+
context 'on redhat breeds' do
|
484
|
+
let(:lsb) { {} }
|
485
|
+
|
486
|
+
before do
|
487
|
+
allow(subject).to receive(:lsb).and_return(lsb)
|
488
|
+
end
|
489
|
+
|
490
|
+
context 'with lsb_release results' do
|
491
|
+
context 'red hat' do
|
492
|
+
let(:lsb) { { id: 'RedHatEnterpriseServer', release: '7.5' } }
|
493
|
+
|
494
|
+
it 'sets the platform to redhat and platform_family to rhel even if the LSB name is something absurd but redhat-like' do
|
495
|
+
expect(subject.name).to eq('redhat')
|
496
|
+
expect(subject.version).to eq('7.5')
|
497
|
+
expect(subject.family).to eq('rhel')
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
501
|
+
context 'centos' do
|
502
|
+
let(:lsb) { { id: 'CentOS', release: '7.5' } }
|
503
|
+
|
504
|
+
it 'sets the platform to centos and platform_family to rhel' do
|
505
|
+
expect(subject.name).to eq('centos')
|
506
|
+
expect(subject.version).to eq('7.5')
|
507
|
+
expect(subject.family).to eq('rhel')
|
508
|
+
end
|
509
|
+
end
|
510
|
+
end
|
511
|
+
|
512
|
+
context 'without lsb_release results' do
|
513
|
+
let(:have_redhat_release) { true }
|
514
|
+
|
515
|
+
it 'reads the platform as centos and version as 7.5' do
|
516
|
+
expect(File).to receive(:read).with('/etc/redhat-release').and_return('CentOS Linux release 7.5.1804 (Core)')
|
517
|
+
expect(subject.name).to eq('centos')
|
518
|
+
expect(subject.version).to eq('7.5.1804')
|
519
|
+
end
|
520
|
+
|
521
|
+
it 'reads platform of Red Hat with a space' do
|
522
|
+
expect(File).to receive(:read).with('/etc/redhat-release').and_return('Red Hat Enterprise Linux Server release 6.5 (Santiago)')
|
523
|
+
expect(subject.name).to eq('redhat')
|
524
|
+
end
|
525
|
+
|
526
|
+
it 'reads the platform as redhat without a space' do
|
527
|
+
expect(File).to receive(:read).with('/etc/redhat-release').and_return('RedHat release 5.3')
|
528
|
+
expect(subject.name).to eq('redhat')
|
529
|
+
expect(subject.version).to eq('5.3')
|
530
|
+
end
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
534
|
+
context 'on pcs linux' do
|
535
|
+
let(:have_redhat_release) { true }
|
536
|
+
let(:have_parallels_release) { true }
|
537
|
+
let(:lsb) { {} }
|
538
|
+
|
539
|
+
before do
|
540
|
+
allow(subject).to receive(:lsb).and_return(lsb)
|
541
|
+
end
|
542
|
+
|
543
|
+
context 'with lsb_result' do
|
544
|
+
let(:lsb) { { id: 'CloudLinuxServer', release: '6.5' } }
|
545
|
+
|
546
|
+
it 'reads the platform as parallels and version as 6.0.5' do
|
547
|
+
allow(File).to receive(:read).with('/etc/redhat-release').and_return('CloudLinux Server release 6.5 (Pavel Popovich)')
|
548
|
+
expect(File).to receive(:read).with('/etc/parallels-release').and_return('Parallels Cloud Server 6.0.5 (20007)')
|
549
|
+
expect(subject.name).to eq('parallels')
|
550
|
+
expect(subject.version).to eq('6.0.5')
|
551
|
+
expect(subject.family).to eq('rhel')
|
552
|
+
end
|
553
|
+
end
|
554
|
+
|
555
|
+
context 'without lsb_results' do
|
556
|
+
it 'reads the platform as parallels and version as 6.0.5' do
|
557
|
+
allow(File).to receive(:read).with('/etc/redhat-release').and_return('CloudLinux Server release 6.5 (Pavel Popovich)')
|
558
|
+
expect(File).to receive(:read).with('/etc/parallels-release').and_return('Parallels Cloud Server 6.0.5 (20007)')
|
559
|
+
expect(subject.name).to eq('parallels')
|
560
|
+
expect(subject.version).to eq('6.0.5')
|
561
|
+
expect(subject.family).to eq('rhel')
|
562
|
+
end
|
563
|
+
end
|
564
|
+
end
|
565
|
+
|
566
|
+
context 'on oracle enterprise linux' do
|
567
|
+
let(:have_redhat_release) { true }
|
568
|
+
let(:lsb) { {} }
|
569
|
+
|
570
|
+
before do
|
571
|
+
allow(subject).to receive(:lsb).and_return(lsb)
|
572
|
+
end
|
573
|
+
|
574
|
+
context 'with lsb_results' do
|
575
|
+
context 'when on version 5.x' do
|
576
|
+
let(:have_enterprise_release) { true }
|
577
|
+
let(:lsb) { { id: 'EnterpriseEnterpriseServer', release: '5.7' } }
|
578
|
+
|
579
|
+
it 'reads the platform as oracle and version as 5.7' do
|
580
|
+
allow(File).to receive(:read).with('/etc/redhat-release').and_return('Red Hat Enterprise Linux Server release 5.7 (Tikanga)')
|
581
|
+
expect(File).to receive(:read).with('/etc/enterprise-release').and_return('Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)')
|
582
|
+
expect(subject.name).to eq('oracle')
|
583
|
+
expect(subject.version).to eq('5.7')
|
584
|
+
end
|
585
|
+
end
|
586
|
+
|
587
|
+
context 'when on version 6.x' do
|
588
|
+
let(:have_oracle_release) { true }
|
589
|
+
let(:lsb) { { id: 'OracleServer', release: '6.1' } }
|
590
|
+
|
591
|
+
it 'reads the platform as oracle and version as 6.1' do
|
592
|
+
allow(File).to receive(:read).with('/etc/redhat-release').and_return('Red Hat Enterprise Linux Server release 6.1 (Santiago)')
|
593
|
+
expect(File).to receive(:read).with('/etc/oracle-release').and_return('Oracle Linux Server release 6.1')
|
594
|
+
expect(subject.name).to eq('oracle')
|
595
|
+
expect(subject.version).to eq('6.1')
|
596
|
+
end
|
597
|
+
end
|
598
|
+
end
|
599
|
+
|
600
|
+
context 'without lsb_results' do
|
601
|
+
context 'when on version 5.x' do
|
602
|
+
let(:have_enterprise_release) { true }
|
603
|
+
|
604
|
+
it 'reads the platform as oracle and version as 5' do
|
605
|
+
allow(File).to receive(:read).with('/etc/redhat-release').and_return('Enterprise Linux Enterprise Linux Server release 5 (Carthage)')
|
606
|
+
expect(File).to receive(:read).with('/etc/enterprise-release').and_return('Enterprise Linux Enterprise Linux Server release 5 (Carthage)')
|
607
|
+
expect(subject.name).to eq('oracle')
|
608
|
+
expect(subject.version).to eq('5')
|
609
|
+
end
|
610
|
+
|
611
|
+
it 'reads the platform as oracle and version as 5.1' do
|
612
|
+
allow(File).to receive(:read).with('/etc/redhat-release').and_return('Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)')
|
613
|
+
expect(File).to receive(:read).with('/etc/enterprise-release').and_return('Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)')
|
614
|
+
expect(subject.name).to eq('oracle')
|
615
|
+
expect(subject.version).to eq('5.1')
|
616
|
+
end
|
617
|
+
|
618
|
+
it 'reads the platform as oracle and version as 5.7' do
|
619
|
+
allow(File).to receive(:read).with('/etc/redhat-release').and_return('Red Hat Enterprise Linux Server release 5.7 (Tikanga)')
|
620
|
+
expect(File).to receive(:read).with('/etc/enterprise-release').and_return('Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)')
|
621
|
+
expect(subject.name).to eq('oracle')
|
622
|
+
expect(subject.version).to eq('5.7')
|
623
|
+
end
|
624
|
+
end
|
625
|
+
|
626
|
+
context 'when on version 6.x' do
|
627
|
+
let(:have_oracle_release) { true }
|
628
|
+
|
629
|
+
it 'reads the platform as oracle and version as 6.0' do
|
630
|
+
allow(File).to receive(:read).with('/etc/redhat-release').and_return('Red Hat Enterprise Linux Server release 6.0 (Santiago)')
|
631
|
+
expect(File).to receive(:read).with('/etc/oracle-release').and_return('Oracle Linux Server release 6.0')
|
632
|
+
expect(subject.name).to eq('oracle')
|
633
|
+
expect(subject.version).to eq('6.0')
|
634
|
+
end
|
635
|
+
|
636
|
+
it 'reads the platform as oracle and version as 6.1' do
|
637
|
+
allow(File).to receive(:read).with('/etc/redhat-release').and_return('Red Hat Enterprise Linux Server release 6.1 (Santiago)')
|
638
|
+
expect(File).to receive(:read).with('/etc/oracle-release').and_return('Oracle Linux Server release 6.1')
|
639
|
+
expect(subject.name).to eq('oracle')
|
640
|
+
expect(subject.version).to eq('6.1')
|
641
|
+
end
|
642
|
+
end
|
643
|
+
end
|
644
|
+
end
|
645
|
+
|
646
|
+
context 'on suse' do
|
647
|
+
context 'when on versions that have no /etc/os-release but /etc/SuSE-release (e.g. SLES12.1)' do
|
648
|
+
let(:have_suse_release) { true }
|
649
|
+
let(:have_os_release) { false }
|
650
|
+
let(:lsb) { {} }
|
651
|
+
|
652
|
+
before do
|
653
|
+
allow(subject).to receive(:lsb).and_return(lsb)
|
654
|
+
end
|
655
|
+
|
656
|
+
describe 'with lsb_release results' do
|
657
|
+
let(:lsb) { { id: 'SUSE LINUX', release: '2.1' } }
|
658
|
+
|
659
|
+
it 'reads the platform as opensuse on openSUSE' do
|
660
|
+
expect(File).to receive(:read).with('/etc/SuSE-release').and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n")
|
661
|
+
expect(subject.name).to eq('opensuse')
|
662
|
+
expect(subject.family).to eq('suse')
|
663
|
+
end
|
664
|
+
end
|
665
|
+
end
|
666
|
+
|
667
|
+
context 'when on openSUSE and older SLES versions' do
|
668
|
+
let(:have_suse_release) { true }
|
669
|
+
|
670
|
+
describe 'without lsb_release results' do
|
671
|
+
it 'sets platform and platform_family to suse and bogus verion to 10.0' do
|
672
|
+
expect(File).to receive(:read).with('/etc/SuSE-release').at_least(:once).and_return('VERSION = 10.0')
|
673
|
+
expect(subject.name).to eq('suse')
|
674
|
+
expect(subject.family).to eq('suse')
|
675
|
+
end
|
676
|
+
|
677
|
+
it 'reads the version as 11.2' do
|
678
|
+
expect(File).to receive(:read).with('/etc/SuSE-release').and_return("SUSE Linux Enterprise Server 11.2 (i586)\nVERSION = 11\nPATCHLEVEL = 2\n")
|
679
|
+
expect(subject.name).to eq('suse')
|
680
|
+
expect(subject.version).to eq('11.2')
|
681
|
+
expect(subject.family).to eq('suse')
|
682
|
+
end
|
683
|
+
|
684
|
+
it '[OHAI-272] should read the version as 11.3' do
|
685
|
+
expect(File).to receive(:read).with('/etc/SuSE-release').once.and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3")
|
686
|
+
expect(subject.name).to eq('opensuse')
|
687
|
+
expect(subject.version).to eq('11.3')
|
688
|
+
expect(subject.family).to eq('suse')
|
689
|
+
end
|
690
|
+
|
691
|
+
it '[OHAI-272] should read the version as 11.4' do
|
692
|
+
expect(File).to receive(:read).with('/etc/SuSE-release').once.and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon")
|
693
|
+
expect(subject.name).to eq('opensuse')
|
694
|
+
expect(subject.version).to eq('11.4')
|
695
|
+
expect(subject.family).to eq('suse')
|
696
|
+
end
|
697
|
+
|
698
|
+
it 'reads the platform as opensuse on openSUSE' do
|
699
|
+
expect(File).to receive(:read).with('/etc/SuSE-release').and_return("openSUSE 12.2 (x86_64)\nVERSION = 12.2\nCODENAME = Mantis\n")
|
700
|
+
expect(subject.name).to eq('opensuse')
|
701
|
+
expect(subject.family).to eq('suse')
|
702
|
+
end
|
703
|
+
|
704
|
+
it 'reads the platform as opensuseleap on openSUSE Leap' do
|
705
|
+
expect(File).to receive(:read).with('/etc/SuSE-release').and_return("openSUSE 42.1 (x86_64)\nVERSION = 42.1\nCODENAME = Malachite\n")
|
706
|
+
expect(subject.name).to eq('opensuseleap')
|
707
|
+
expect(subject.family).to eq('suse')
|
708
|
+
end
|
709
|
+
end
|
710
|
+
end
|
711
|
+
end
|
712
|
+
|
713
|
+
context 'on clearlinux' do
|
714
|
+
let(:lsb) { {} }
|
715
|
+
let(:have_usr_lib_os_release) { true }
|
716
|
+
let(:os_release_content) do
|
717
|
+
<<~CLEARLINUX_RELEASE
|
718
|
+
NAME="Clear Linux OS"
|
719
|
+
VERSION=1
|
720
|
+
ID=clear-linux-os
|
721
|
+
ID_LIKE=clear-linux-os
|
722
|
+
VERSION_ID=26290
|
723
|
+
PRETTY_NAME="Clear Linux OS"
|
724
|
+
CLEARLINUX_RELEASE
|
725
|
+
end
|
726
|
+
|
727
|
+
before do
|
728
|
+
expect(File).to receive(:read).with('/usr/lib/os-release').and_return(os_release_content)
|
729
|
+
allow(subject).to receive(:lsb).and_return(lsb)
|
730
|
+
end
|
731
|
+
|
732
|
+
it 'sets platform to clearlinux and platform_family to clearlinux' do
|
733
|
+
expect(subject.name).to eq('clearlinux')
|
734
|
+
expect(subject.family).to eq('clearlinux')
|
735
|
+
expect(subject.version).to eq('26290')
|
736
|
+
end
|
737
|
+
end
|
738
|
+
end
|
739
|
+
end
|