Class: Beaker::Platform

Inherits:
String
  • Object
show all
Defined in:
lib/beaker/platform.rb

Overview

This class create a Platform object inheriting from String. It supports all String methods while adding several platform-specific use cases.

Constant Summary collapse

PLATFORMS =

Supported platforms

/^(alpine|amazon|(free|open)bsd|osx|centos|fedora|debian|oracle|redhat|redhatfips|scientific|opensuse|sles|ubuntu|windows|solaris|aix|archlinux|el)\-.+\-.+$/
PLATFORM_VERSION_CODES =

Platform version numbers vs. codenames conversion hash

{ :debian => { "forky" => "14",
   "trixie" => "13",
   "bookworm" => "12",
   "bullseye" => "11",
   "buster" => "10", },
        :ubuntu => { "noble" => "2404",
   "jammy" => "2204",
   "focal" => "2004",
   "bionic" => "1804", },
        :osx => { "highsierra" => "1013",
"sierra" => "1012",
"elcapitan" => "1011",
"yosemite" => "1010",
"mavericks" => "109", }, }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Platform

Creates the Platform object. Checks to ensure that the platform String provided meets the platform formatting rules. Platforms name must be of the format /^OSFAMILY-VERSION-ARCH.*$/ where OSFAMILY is one of:

  • amazon

  • freebsd

  • openbsd

  • osx

  • centos

  • fedora

  • debian

  • oracle

  • redhat

  • redhatfips

  • scientific

  • opensuse

  • sles

  • ubuntu

  • windows

  • solaris

  • aix

  • el

  • archlinux

Raises:

  • (ArgumentError)


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/beaker/platform.rb', line 59

def initialize(name)
  raise ArgumentError, "Unsupported platform name #{name}" if !PLATFORMS.match?(name)

  super

  @variant, version, @arch = self.split('-', 3)
  codename_version_hash = PLATFORM_VERSION_CODES[@variant.to_sym]

  @version = version
  @codename = nil

  return unless codename_version_hash

  if codename_version_hash[version]
    @codename = version
    @version = codename_version_hash[version]
  else
    version = version.delete('.')
    version_codename_hash = codename_version_hash.invert
    @codename = version_codename_hash[version]
  end
end

Instance Attribute Details

#archObject (readonly)

A string with the cpu architecture of the platform.



35
36
37
# File 'lib/beaker/platform.rb', line 35

def arch
  @arch
end

#codenameObject (readonly)

A string with the codename of the platform+version, nil on platforms without codenames.



32
33
34
# File 'lib/beaker/platform.rb', line 32

def codename
  @codename
end

#variantObject (readonly)

A string with the name of the platform.



25
26
27
# File 'lib/beaker/platform.rb', line 25

def variant
  @variant
end

#versionObject (readonly)

A string with the version number of the platform.



28
29
30
# File 'lib/beaker/platform.rb', line 28

def version
  @version
end

Instance Method Details

#base_packagesArray<String>

Return a list of packages that should always be present.

Returns:

  • (Array<String>)

    A list of packages to install



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/beaker/platform.rb', line 118

def base_packages
  case @variant
  when 'el'
    @version.to_i >= 8 ? ['iputils'] : %w[curl]
  when 'debian'
    %w[curl lsb-release]
  when 'freebsd'
    %w[curl perl5|perl]
  when 'solaris'
    @version.to_i >= 11 ? %w[curl] : %w[CSWcurl wget]
  when 'archlinux'
    %w[curl net-tools openssh]
  when 'amazon', 'fedora'
    ['iputils']
  when 'aix', 'osx', 'windows'
    []
  else
    %w[curl]
  end
end

#timesync_packagesArray<String>

Return a list of packages that are needed for timesync

Returns:

  • (Array<String>)

    A list of packages to install for timesync



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/beaker/platform.rb', line 142

def timesync_packages
  return ['chrony'] if uses_chrony?

  case @variant
  when 'freebsd', 'openbsd', 'windows', 'aix', 'osx'
    []
  when 'archlinux', 'opensuse'
    ['ntp']
  when 'sles'
    @version.to_i >= 11 ? %w[ntp] : []
  when 'solaris'
    @version.to_i >= 11 ? %w[ntp] : %w[CSWntp]
  else
    %w[ntpdate]
  end
end

#to_arrayObject

Returns array of attributes to allow single line assignment to local variables in DSL and test case methods.



84
85
86
# File 'lib/beaker/platform.rb', line 84

def to_array
  return @variant, @version, @arch, @codename
end

#uses_chrony?Boolean

Returns:

  • (Boolean)


104
105
106
107
108
109
110
111
112
113
# File 'lib/beaker/platform.rb', line 104

def uses_chrony?
  case @variant
  when 'amazon', 'fedora'
    true
  when 'el'
    @version.to_i >= 8
  else
    false
  end
end

#with_version_codenameString

Returns the platform string with the platform version as a codename. If no conversion is necessary then the original, unchanged platform String is returned.

Examples:

Platform.new(‘debian-7-xxx’).with_version_codename == ‘debian-wheezy-xxx’

Returns:

  • (String)

    the platform string with the platform version represented as a codename



92
93
94
# File 'lib/beaker/platform.rb', line 92

def with_version_codename
  [@variant, @codename || @version, @arch].join('-')
end

#with_version_numberString

Returns the platform string with the platform version as a number. If no conversion is necessary then the original, unchanged platform String is returned.

Examples:

Platform.new(‘debian-wheezy-xxx’).with_version_number == ‘debian-7-xxx’

Returns:

  • (String)

    the platform string with the platform version represented as a number



100
101
102
# File 'lib/beaker/platform.rb', line 100

def with_version_number
  [@variant, @version, @arch].join('-')
end