Page MenuHomePhabricator
Paste P14478

(An Untitled Masterwork)
ArchivedPublic

Authored by Kormat on Feb 25 2021, 10:06 AM.
Tags
None
Referenced Files
F34122056: raw-paste-data.txt
Feb 25 2021, 10:08 AM
F34122051: raw-paste-data.txt
Feb 25 2021, 10:06 AM
Subscribers
# Somewhere in heira:
section_params:
s1:
writeable_dc: mw_primary
replication_type: unidir
m1:
writeable_dc: eqiad
replication_type: unidir
x2:
writeable_dc: both
replication_type: circular

Event Timeline

Kormat updated the paste's language from autodetect to yaml.
Kormat edited the content of this paste. (Show Details)

Puppet functions:

in_writeable_dc(section):
  sec_params = lookup(section_params)
  dc = sec_params[section].writeable_dc
  if dc == 'both':
    return True
  if dc == ::domain:
   return True
  if dc == mw_primary and mediawiki::state('primary_dc') == ::domain:
    return True
  return False
is_replica(section):
  sec_params = lookup(section_params)
  rep_type = sec_params[section].replication_type
  if rep_type == circular:
    return True
  if rep_type == none:
   return False
  # unidir
  if not in_writeable_dc(section):
    return True

Puppet profile:

if is_master:
  monitor_read_only(read_only=!in_writeable_dc(section))
else:
  monitor_read_only(read_only=True)

if is_master:
  monitor_master_replication(section)

Expression is not valid as a resource, resource-default, or resource-override (line: 4, column: 5)

function profile::mariadb::section_params::load_params(String $section) >> Hash {
    $all_sections = lookup('profile::mariadb::section_params')
    $def_params = $all_sections["defaults"]
    if $all_sections.has_key($section) {
        $sec_params = $all_sections[$section]
        $writeable_dc = case $sec_params.has_key['writeable_dc'] {
            undef: { $def_params["writeable_dc"] }
            default: { $sec_params["writeable_dc"] }
        }
        $replication_type = case $sec_params.has_key['replication_type'] {
            undef: { $def_params["replication_type"] }
            default: { $sec_params["replication_type"] }
        }
    } else {
        $writeable_dc = $def_params["writeable_dc"]
        $replication_type = $def_params["replication_type"]
    }
    {
        writeable_dc => $writeable_dc,
        replication_type => $replication_type,
    }
}

note its not the if statment that is causing the error it is the hash at the end. im not sure whay yet however the following works (note i changed the case to a ternary)

function profile::mariadb::section_params::load_params(String $section) >> Hash {
    $all_sections = lookup('profile::mariadb::section_params')
    $def_params = $all_sections["defaults"]
    if $all_sections.has_key($section) {
        $sec_params = $all_sections[$section]
        $writeable_dc = $sec_params.has_key['writeable_dc'] ? {
            false   => $def_params["writeable_dc"],
            default => $sec_params["writeable_dc"],
        }
        $replication_type = $sec_params.has_key['replication_type'] ? {
            false   => $def_params["replication_type"],
            default => $sec_params["replication_type"],
        }
    } else {
        $writeable_dc = $def_params["writeable_dc"]
        $replication_type = $def_params["replication_type"]
    }
    $foo = {
        'writeable_dc' => $writeable_dc,
        'replication_type' => $replication_type,
    }
    $foo
}
function profile::mariadb::section_params::load_writeable_dc(String $section) >> Profile::Mariadb::Writeable_DC {
    $all_sections = lookup('profile::mariadb::section_params')
    $def_params = $all_sections["defaults"]
    if has_key($all_sections, $section) {
        stdlib::pick($all_sections[$section]['writeable_dc'], $def_params['writeable_dc'])
    } else {
        $def_params['writeable_dc']
    }
}