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

Class Method Summary collapse

Class Method Details

.os_release_to_setfile(os, release, use_fqdn: false, pidfile_workaround: false) ⇒ 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

  • 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.

Returns:

  • (nil)

    If no setfile is available

  • (Array<(String, String)>)

    The beaker setfile description with a readable name



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/puppet_metadata/beaker.rb', line 25

def self.os_release_to_setfile(os, release, use_fqdn: false, pidfile_workaround: false)
  return unless os_supported?(os)

  name = "#{os.downcase}#{release.tr('.', '')}-64"

  options = {}
  options[:hostname] = "#{name}.example.com" if use_fqdn

  # Docker messes up cgroups and modern systemd can't deal with that when
  # PIDFile is used.
  if pidfile_workaround && (!pidfile_workaround.is_a?(Array) || pidfile_workaround.include?(os))
    case os
    when 'CentOS'
      case release
      when '7'
        options[:image] = 'centos:7.6.1810'
      when '8'
        # There is no CentOS 8 image that works with PIDFile in systemd
        # unit files
        return
      end
    when 'Ubuntu'
      options[:image] = 'ubuntu:xenial-20191212' if release == '16.04'
    end
  end

  setfile = name
  setfile += "{#{options.map { |key, value| "#{key}=#{value}" }.join(',')}}" if options.any?

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

  [setfile, 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)


61
62
63
# File 'lib/puppet_metadata/beaker.rb', line 61

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