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|huaweios|cisco_nexus|cisco_ios_xr|(free|open)bsd|osx|centos|fedora|debian|oracle|redhat|redhatfips|scientific|sles|ubuntu|windows|solaris|aix|archlinux|el|eos|cumulus|f5|netscaler)\-.+\-.+$/
PLATFORM_VERSION_CODES =

Platform version numbers vs. codenames conversion hash

{ :debian => { "buster"  => "10",
               "stretch" => "9",
               "jessie"  => "8",
               "wheezy"  => "7",
               "squeeze" => "6",
             },
  :ubuntu => { "focal"   => "2004",
               "eoan"    => "1910",
               "disco"   => "1904",
               "cosmic"  => "1810",
               "bionic"  => "1804",
               "artful"  => "1710",
               "zesty"   => "1704",
               "yakkety" => "1610",
               "xenial"  => "1604",
               "wily"    => "1510",
               "vivid"   => "1504",
               "utopic"  => "1410",
               "trusty"  => "1404",
               "saucy"   => "1310",
               "raring"  => "1304",
               "quantal" => "1210",
               "precise" => "1204",
               "lucid"   => "1004",
             },
  :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:

  • huaweios

  • cisco_nexus

  • cisco_ios_xr

  • freebsd

  • openbsd

  • osx

  • centos

  • fedora

  • debian

  • oracle

  • redhat

  • redhatfips

  • scientific

  • sles

  • ubuntu

  • windows

  • solaris

  • aix

  • el

  • cumulus

  • f5

  • netscaler

  • archlinux



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/beaker/platform.rb', line 81

def initialize(name)
  if name !~ PLATFORMS
    raise ArgumentError, "Unsupported platform name #{name}"
  end

  super

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

  @version = version
  @codename = nil

  if 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
end

Instance Attribute Details

#archObject (readonly)

A string with the cpu architecture of the platform.



53
54
55
# File 'lib/beaker/platform.rb', line 53

def arch
  @arch
end

#codenameObject (readonly)

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



50
51
52
# File 'lib/beaker/platform.rb', line 50

def codename
  @codename
end

#variantObject (readonly)

A string with the name of the platform.



43
44
45
# File 'lib/beaker/platform.rb', line 43

def variant
  @variant
end

#versionObject (readonly)

A string with the version number of the platform.



46
47
48
# File 'lib/beaker/platform.rb', line 46

def version
  @version
end

Instance Method Details

#init_with(coder) ⇒ Object



133
134
135
136
137
138
# File 'lib/beaker/platform.rb', line 133

def init_with(coder)
  coder.map.each do |ivar, value|
    instance_variable_set("@#{ivar}", value)
  end
  replace("#{@variant}-#{@version}-#{@arch}")
end

#to_arrayObject

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



108
109
110
# File 'lib/beaker/platform.rb', line 108

def to_array
  return @variant, @version, @arch, @codename
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



116
117
118
119
120
121
122
# File 'lib/beaker/platform.rb', line 116

def with_version_codename
  version_array = [@variant, @version, @arch]
  if @codename
    version_array = [@variant, @codename, @arch]
  end
  return version_array.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



128
129
130
# File 'lib/beaker/platform.rb', line 128

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