Puppet Class: galera::validate

Defined in:
manifests/validate.pp

Summary

Validate that the cluster can accept connections.

Overview

This validation is done at the point where the ‘mysql::server` resource is marked as complete. This is used because after returning success, the service is still not quite ready.

Parameters:

  • action (String)

    Specifies the MySQL/MariaDB command to run. Valid options: a string. Default: ‘select count(1);`

  • catch (String)

    Specifies a string that if present indicates failure. Valid options: a string. Default: ‘ERROR`

  • delay (Integer)

    Specifies the seconds to sleep between attempts. Valid options: an integer: Default: ‘3`

  • inv_catch (Optional[String])

    Specifies a string that if not present indicates failure. Valid options: a string. Default: ‘undef`

  • retries (Integer)

    Specifies the number of times to retry connection. Valid options: an integer. Default: ‘20`



20
21
22
23
24
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
58
59
60
61
# File 'manifests/validate.pp', line 20

class galera::validate (
  String $action,
  String $catch,
  Integer $delay,
  Integer $retries,
  Optional[String] $inv_catch,
) {
  if $galera::status_check {
    $validate_host     = $galera::status_host
    $validate_user     = $galera::status_user
    $validate_password = $galera::status_password
  } elsif $galera::root_password =~ String {
    $validate_host     = 'localhost'
    $validate_user     = 'root'
    $validate_password = $galera::root_password
  }
  else {
    fail('Cannot validate connection without $root_password or $status_check')
  }

  if $catch {
    $truecatch = " -v ${catch}"
  } elsif $inv_catch {
    $truecatch = $inv_catch
  } else {
    fail('No catch method specified in galera validation script')
  }

  $cmd = "mysql --host=${validate_host} --user=${validate_user} --password=${validate_password} -e '${action}' | grep -q ${truecatch}"
  exec { 'validate_connection':
    path        => '/usr/bin:/bin:/usr/local/bin:/usr/sbin:/sbin:/usr/local/sbin',
    provider    => shell,
    command     => $cmd,
    tries       => $retries,
    try_sleep   => $delay,
    subscribe   => Service[$galera::mysql_service_name],
    refreshonly => true,
  }

  # Ensure that the cluster was bootstrapped, then notify to trigger a validation.
  Exec<| title == 'bootstrap_galera_cluster' |> ~> Exec['validate_connection']
}