Class: PuppetMetadata::Beaker

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

Overview

A class to provide abstractions for integration with beaker

Constant Summary collapse

PIDFILE_COMPATIBLE_IMAGES =

These images have an older systemd, which they work with PIDFile parameter

{
  'CentOS' => {
    '7' => 'centos:7.6.1810',
  },
  'Ubuntu' => {
    '16.04' => 'ubuntu:xenial-20191212',
  },
}.freeze
PIDFILE_INCOMPATIBLE =

There is no CentOS 8 image that works with PIDFile in systemd unit files

{
  'CentOS' => ['8'],
}.freeze

Class Method Summary collapse

Class Method Details

.os_release_to_setfile(os, release, use_fqdn: false, pidfile_workaround: false, domain: nil, puppet_version: nil) ⇒ nil, Array<(String, String)>

Convert an Operating System name with a release to a Beaker setfile

Parameters:

  • os (String)

    The Operating System string as metadata.json knows it, which in turn is based on Facter’s operatingsystem fact.

  • release (String)

    The OS release

  • use_fqdn (Boolean) (defaults to: false)

    Whether or not to use a FQDN, ensuring a domain (deprecated, use domain)

  • pidfile_workaround (Boolean, Array[String]) (defaults to: false)

    Whether or not to apply the systemd PIDFile workaround. This is only needed when the daemon uses PIDFile in its service file and using Docker as a Beaker hypervisor. This is to work around Docker’s limitations. When a boolean, it’s applied on applicable operating systems. On arrays it’s applied only when os is included in the provided array.

  • domain (Optional[String]) (defaults to: nil)

    Enforce a domain to be appended to the hostname, making it an FQDN

  • puppet_version (Optional[String]) (defaults to: nil)

    The desired puppet version. Will be appended to the hostname

Returns:

  • (nil)

    If no setfile is available

  • (Array<(String, String)>)

    The beaker setfile description with a readable name



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/puppet_metadata/beaker.rb', line 46

def os_release_to_setfile(os, release, use_fqdn: false, pidfile_workaround: false, domain: nil, puppet_version: nil)
  return unless os_supported?(os)

  name = "#{os.downcase}#{release.tr('.', '')}-64"
  hostname = puppet_version != nil ? "#{name}-#{puppet_version}" : name
  domain ||= 'example.com' if use_fqdn

  options = {}
  options[:hostname] = "#{hostname}.#{domain}" if domain

  # Docker messes up cgroups and some systemd versions can't deal with
  # that when PIDFile is used.
  if pidfile_workaround?(pidfile_workaround, os)
    return if PIDFILE_INCOMPATIBLE[os]&.include?(release)

    if (image = PIDFILE_COMPATIBLE_IMAGES.dig(os, release))
      options[:image] = image
    end
  end

  human_name = "#{os} #{release}"

  [build_setfile(name, options), human_name]
end

.os_supported?(os) ⇒ Boolean

Return whether a Beaker setfile can be generated for the given OS

Parameters:

  • os (String)

    The operating system

Returns:

  • (Boolean)


73
74
75
# File 'lib/puppet_metadata/beaker.rb', line 73

def os_supported?(os)
  ['Archlinux', 'CentOS', 'Fedora', 'Debian', 'Ubuntu', 'Rocky', 'AlmaLinux'].include?(os)
end