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

.adjusted_os(os) ⇒ String

modifies the operating system name to suit beaker-hostgenerator

Parameters:

  • os (String)

Returns:

  • (String)

    the modified OS name



11
12
13
14
15
16
17
18
19
20
# File 'lib/puppet_metadata/beaker.rb', line 11

def adjusted_os(os)
  case os
  when 'OracleLinux'
    'oracle'
  when 'Amazonlinux', 'AmazonLinux' # Vox Pupuli default is Amazon in metadata.json
    'amazon'
  else
    os.downcase
  end
end

.os_release_to_setfile(os, release, domain: nil, puppet_version: nil, hosts: 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

  • 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

  • hosts (Optional[Hash]) (defaults to: nil)

    Key: hostname, Value: roles (roles string as defined by beaker-hostgenerator ) Override the automatically generated hostname and optionally add roles If more than one entry this will generate multiple hosts in the setfile The domain may still be set via the ‘domain` param.

Returns:

  • (nil)

    If no setfile is available

  • (Array<(String, String)>)

    The beaker setfile description with a readable name



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/puppet_metadata/beaker.rb', line 40

def os_release_to_setfile(os, release, domain: nil, puppet_version: nil, hosts: nil)
  return unless os_supported?(os)

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

  hosts_settings = []
  if hosts
    hosts.each do |hostname, roles|
      hosts_settings << {
        'name' => if roles
                    name + roles
                  elsif hosts.size > 1
                    hosts_settings.empty? ? "#{name}.ma" : "#{name}.a"
                  else
                    name
                  end,
        'hostname' => ((puppet_version.nil? || puppet_version == 'none') ? hostname : "#{hostname}-#{puppet_version}") + (domain ? ".#{domain}" : ''),
      }
    end
  else
    hosts_settings << {
      'name' => name,
      'hostname' => if puppet_version && puppet_version != 'none'
                      "#{name}-#{puppet_version}" + (domain ? ".#{domain}" : '')
                    elsif domain
                      name + (domain ? ".#{domain}" : '')
                    else
                      ''
                    end,
    }
  end

  options = {}

  setfile_parts = []
  hosts_settings.each do |host_settings|
    options[:hostname] = host_settings['hostname'] unless host_settings['hostname'].empty?
    setfile_parts << build_setfile(host_settings['name'], options)
  end

  [setfile_parts.join('-'), 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)


87
88
89
# File 'lib/puppet_metadata/beaker.rb', line 87

def os_supported?(os)
  %w[Amazonlinux Amazon Archlinux CentOS Fedora Debian Ubuntu Rocky AlmaLinux OracleLinux].include?(os)
end