Skip to content

Commit

Permalink
Bring train platform data more in line with ohai's platform data
Browse files Browse the repository at this point in the history
This includes

- `family` refers to the distribuion family while `name` refers to the
  spcific distribution. For example, the family attribute for ubuntu is
  `debian`.

- The `redhat` family has been renamed `rhel`

- Fedora is not listed as a `rhel` platform.
  • Loading branch information
stevendanna committed Aug 1, 2016
1 parent b644f6f commit b79f0f7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
15 changes: 5 additions & 10 deletions lib/train/extras/os_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,10 @@ def to_hash
end

OS = { # rubocop:disable Style/MutableConstant
'redhat' => %w{
redhat oracle centos fedora amazon scientific xenserver wrlinux
},
'debian' => %w{
debian ubuntu linuxmint raspbian
},
'suse' => %w{
suse opensuse
},
'redhat' => REDHAT_FAMILY,
'debian' => DEBIAN_FAMILY,
'suse' => SUSE_FAMILY,
'fedora' => %w{fedora},
'bsd' => %w{
freebsd netbsd openbsd darwin
},
Expand All @@ -67,7 +62,7 @@ def to_hash
},
}

OS['linux'] = %w{linux alpine arch coreos exherbo gentoo slackware} + OS['redhat'] + OS['debian'] + OS['suse']
OS['linux'] = %w{linux alpine arch coreos exherbo gentoo slackware fedora} + OS['redhat'] + OS['debian'] + OS['suse']

OS['unix'] = %w{unix aix hpux} + OS['linux'] + OS['solaris'] + OS['bsd']

Expand Down
2 changes: 1 addition & 1 deletion lib/train/extras/os_detect_darwin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def detect_darwin
# TODO: ditto on error
return false if cmd.stdout.empty?

uname_m = @backend.run_command("uname -m").stdout.chomp
uname_m = @backend.run_command('uname -m').stdout.chomp
return false if uname_m.empty?

name = cmd.stdout[/^ProductName:\s+(.+)$/, 1]
Expand Down
13 changes: 10 additions & 3 deletions lib/train/extras/os_detect_linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

module Train::Extras
module DetectLinux # rubocop:disable Metrics/ModuleLength
DEBIAN_FAMILY = %w{debian ubuntu linuxmint raspbian}.freeze
REDHAT_FAMILY = %w{centos redhat oracle scientific enterpriseenterprise amazon xenserver cloudlinux ibm_powerkvm nexus_centos wrlinux}.freeze
SUSE_FAMILY = %w{suse opensuse}.freeze

include Train::Extras::LinuxLSB

def detect_linux_via_config # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
Expand Down Expand Up @@ -85,7 +89,7 @@ def detect_linux_via_config # rubocop:disable Metrics/AbcSize, Metrics/Cyclomati
@platform[:release] = meta[:release]
elsif !(os_info = fetch_os_release).nil?
if os_info['ID_LIKE'] =~ /wrlinux/
@platform[:name] = 'wrlinux'
@platform[:name] = 'wrlinux'
@platform[:release] = os_info['VERSION']
end
end
Expand All @@ -96,9 +100,12 @@ def detect_linux_via_config # rubocop:disable Metrics/AbcSize, Metrics/Cyclomati
end

def family_for_platform
case @platform[:name]
when 'centos'
if DEBIAN_FAMILY.include?(@platform[:name])
'debian'
elsif REDHAT_FAMILY.include?(@platform[:name])
'redhat'
elsif SUSE_FAMILY.include?(@platform[:name])
'suse'
else
@platform[:name] || @platform[:family]
end
Expand Down
3 changes: 2 additions & 1 deletion test/unit/extras/os_common_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def mock_platform(x)

describe 'with platform set to fedora' do
let(:os) { mock_platform('fedora') }
it { os.redhat?.must_equal(true) }
it { os.fedora?.must_equal(true) }
it { os.redhat?.must_equal(false) }
it { os.debian?.must_equal(false) }
it { os.suse?.must_equal(false) }
it { os.linux?.must_equal(true) }
Expand Down
18 changes: 12 additions & 6 deletions test/unit/extras/os_detect_linux_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize
detector.stubs(:backend).returns(be)
be.stubs(:run_command).with("uname -m").returns(mock("Output", stdout: "x86_64\n"))
detector.detect_linux_architecture.must_equal(true)
detector.platform[:arch].must_equal("x84_64")
detector.platform[:arch].must_equal("x86_64")
end
end

Expand All @@ -37,7 +37,8 @@ def initialize
detector.stubs(:get_config).with('/etc/enterprise-release').returns('data')

detector.detect_linux_via_config.must_equal(true)
detector.platform[:family].must_equal('oracle')
detector.platform[:name].must_equal('oracle')
detector.platform[:family].must_equal('redhat')
detector.platform[:release].must_equal('redhat-version')
end
end
Expand All @@ -64,7 +65,8 @@ def initialize
detector.stubs(:lsb).returns({ id: 'ubuntu', release: 'ubuntu-release' })

detector.detect_linux_via_config.must_equal(true)
detector.platform[:family].must_equal('ubuntu')
detector.platform[:name].must_equal('ubuntu')
detector.platform[:family].must_equal('debian')
detector.platform[:release].must_equal('ubuntu-release')
end
end
Expand All @@ -74,7 +76,8 @@ def initialize
detector.stubs(:lsb).returns({ id: 'linuxmint', release: 'mint-release' })

detector.detect_linux_via_config.must_equal(true)
detector.platform[:family].must_equal('linuxmint')
detector.platform[:name].must_equal('linuxmint')
detector.platform[:family].must_equal('debian')
detector.platform[:release].must_equal('mint-release')
end
end
Expand All @@ -85,7 +88,8 @@ def initialize
detector.expects(:unix_file?).with('/usr/bin/raspi-config').returns(true)

detector.detect_linux_via_config.must_equal(true)
detector.platform[:family].must_equal('raspbian')
detector.platform[:name].must_equal('raspbian')
detector.platform[:family].must_equal('debian')
detector.platform[:release].must_equal('deb-version')
end
end
Expand All @@ -96,6 +100,7 @@ def initialize
detector.expects(:unix_file?).with('/usr/bin/raspi-config').returns(false)

detector.detect_linux_via_config.must_equal(true)
detector.platform[:name].must_equal('debian')
detector.platform[:family].must_equal('debian')
detector.platform[:release].must_equal('deb-version')
end
Expand Down Expand Up @@ -125,7 +130,8 @@ def initialize
detector.stubs(:fetch_os_release).returns(data)

detector.detect_linux_via_config.must_equal(true)
detector.platform[:family].must_equal('wrlinux')
detector.platform[:name].must_equal('wrlinux')
detector.platform[:family].must_equal('redhat')
detector.platform[:release].must_equal('cisco123')
end
end
Expand Down

0 comments on commit b79f0f7

Please sign in to comment.