diff --git a/manifests/params.pp b/manifests/params.pp index 367d79d0..76555d5f 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -36,6 +36,36 @@ 'server' => 'keyserver.ubuntu.com', }, } + $repo21 = { + comment => 'ProxySQL 2.1.x APT repository', + location => "http://repo.proxysql.com/ProxySQL/proxysql-2.1.x/${facts['os']['distro']['codename']}/", + release => './', + repos => '', + key => { + 'id' => '1448BF693CA600C799EB935804A562FB79953B49', + 'server' => 'keyserver.ubuntu.com', + }, + } + $repo22 = { + comment => 'ProxySQL 2.2.x APT repository', + location => "http://repo.proxysql.com/ProxySQL/proxysql-2.2.x/${facts['os']['distro']['codename']}/", + release => './', + repos => '', + key => { + 'id' => '1448BF693CA600C799EB935804A562FB79953B49', + 'server' => 'keyserver.ubuntu.com', + }, + } + $repo23 = { + comment => 'ProxySQL 2.3.x APT repository', + location => "http://repo.proxysql.com/ProxySQL/proxysql-2.3.x/${facts['os']['distro']['codename']}/", + release => './', + repos => '', + key => { + 'id' => '1448BF693CA600C799EB935804A562FB79953B49', + 'server' => 'keyserver.ubuntu.com', + }, + } } 'RedHat': { $package_provider = 'rpm' @@ -60,6 +90,30 @@ gpgcheck => true, gpgkey => 'http://repo.proxysql.com/ProxySQL/repo_pub_key', } + $repo21 = { + name => 'proxysql_2_1', + descr => 'ProxySQL 2.1.x YUM repository', + baseurl => "http://repo.proxysql.com/ProxySQL/proxysql-2.1.x/centos/${repo_os_major_version}", + enabled => true, + gpgcheck => true, + gpgkey => 'http://repo.proxysql.com/ProxySQL/repo_pub_key', + } + $repo22 = { + name => 'proxysql_2_2', + descr => 'ProxySQL 2.2.x YUM repository', + baseurl => "http://repo.proxysql.com/ProxySQL/proxysql-2.2.x/centos/${repo_os_major_version}", + enabled => true, + gpgcheck => true, + gpgkey => 'http://repo.proxysql.com/ProxySQL/repo_pub_key', + } + $repo23 = { + name => 'proxysql_2_3', + descr => 'ProxySQL 2.3.x YUM repository', + baseurl => "http://repo.proxysql.com/ProxySQL/proxysql-2.3.x/centos/${repo_os_major_version}", + enabled => true, + gpgcheck => true, + gpgkey => 'http://repo.proxysql.com/ProxySQL/repo_pub_key', + } } default: { fail("osfamily ${facts['os']['family']} is not supported") @@ -71,7 +125,7 @@ } else { $short_proxysql_version_fact = undef } - $version = pick($short_proxysql_version_fact,'2.0.7') + $version = pick($short_proxysql_version_fact,'2.3.2') $listen_socket = pick(getvar('_listen_socket'),'/tmp/proxysql.sock') $admin_listen_socket = pick(getvar('_admin_listen_socket'),'/tmp/proxysql_admin.sock') diff --git a/manifests/repo.pp b/manifests/repo.pp index d307fbab..55897775 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -6,12 +6,15 @@ if $proxysql::manage_repo and !$proxysql::package_source { $repo = $proxysql::version ? { + /^2\.3\./ => $proxysql::params::repo23, + /^2\.2\./ => $proxysql::params::repo22, + /^2\.1\./ => $proxysql::params::repo21, /^2\.0\./ => $proxysql::params::repo20, /^1\.4\./ => $proxysql::params::repo14, default => fail("Unsupported `proxysql::version` ${proxysql::version}") } case $facts['os']['family'] { - 'Debian': { + /^(Debian|Ubuntu)$/: { apt::source { 'proxysql_repo': * => $repo, } @@ -22,11 +25,34 @@ * => $repo, } - $purge_repo = $proxysql::version ? { - /^2\.0\./ => $proxysql::params::repo14['name'], - /^1\.4\./ => $proxysql::params::repo20['name'], + # Purge old/unnecessary repos. + if ($proxysql::version !~ /^2\.3\./) { + yumrepo { $proxysql::params::repo23['name']: + ensure => absent, + } } - yumrepo { ['proxysql_repo', $purge_repo]: + if ($proxysql::version !~ /^2\.2\./) { + yumrepo { $proxysql::params::repo22['name']: + ensure => absent, + } + } + if ($proxysql::version !~ /^2\.1\./) { + yumrepo { $proxysql::params::repo21['name']: + ensure => absent, + } + } + if ($proxysql::version !~ /^2\.0\./) { + yumrepo { $proxysql::params::repo20['name']: + ensure => absent, + } + } + if ($proxysql::version !~ /^1\.4\./) { + yumrepo { $proxysql::params::repo14['name']: + ensure => absent, + } + } + + yumrepo { 'proxysql_repo': ensure => absent, } } diff --git a/manifests/service.pp b/manifests/service.pp index 6e113f2f..8ea90688 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -6,8 +6,11 @@ # systemd unit files replaced use of `init.d` in version 2.0.0 for some operating systems but only in 2.0.7 for CentOS/Redhat if (versioncmp($proxysql::version, '2.0.7') >= 0 and fact('os.family') == 'RedHat' and fact('os.name') != 'Amazon' and versioncmp(fact('os.release.major'),'7') >= 0) + or (versioncmp($proxysql::version, '2') >= 0 and fact('os.family') == 'RedHat' and fact('os.name') != 'Amazon' and versioncmp(fact('os.release.major'),'8') >= 0) or (versioncmp($proxysql::version, '2') >= 0 and fact('os.name') == 'Ubuntu' and versioncmp(fact('os.release.major'),'18.04') >= 0) - or (versioncmp($proxysql::version, '2') >= 0 and fact('os.name') == 'Debian' and versioncmp(fact('os.release.major'),'9') >= 0) { + or (versioncmp($proxysql::version, '2') >= 0 and fact('os.name') == 'Debian' and versioncmp(fact('os.release.major'),'9') >= 0) + or (versioncmp($proxysql::version, '2') >= 0 and fact('os.name') == 'Debian' and versioncmp(fact('os.release.major'),'10') >= 0) + or (versioncmp($proxysql::version, '2') >= 0 and fact('os.name') == 'Debian' and versioncmp(fact('os.release.major'),'11') >= 0) { $drop_in_ensure = $proxysql::restart ? { true => 'present', false => 'absent', diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 059b11a7..649b88bb 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -37,7 +37,7 @@ class { 'proxysql': pp = <<-EOS class { 'proxysql': package_ensure => latest, - version => '2.0.7', + version => '2.0.6', } EOS @@ -64,6 +64,102 @@ class { 'proxysql': end end + context 'Upgrading to version 2.1' do + it 'works idempotently with no errors' do + pp = <<-EOS + class { 'proxysql': + package_ensure => latest, + version => '2.1.1', + } + EOS + + # Run it twice and test for idempotency + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + + # Run it again, this time relying on proxysql_version fact + apply_manifest('class { \'proxysql\':}', catch_changes: true) + end + + describe package('proxysql') do + it { is_expected.to be_installed } + end + + describe service('proxysql') do + it { is_expected.to be_enabled } + it { is_expected.to be_running } + end + + describe command('proxysql --version') do + its(:exit_status) { is_expected.to eq 0 } + its(:stdout) { is_expected.to match %r{^ProxySQL version 2\.1\.} } + end + end + + context 'Upgrading to version 2.2' do + it 'works idempotently with no errors' do + pp = <<-EOS + class { 'proxysql': + package_ensure => latest, + version => '2.2.2', + } + EOS + + # Run it twice and test for idempotency + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + + # Run it again, this time relying on proxysql_version fact + apply_manifest('class { \'proxysql\':}', catch_changes: true) + end + + describe package('proxysql') do + it { is_expected.to be_installed } + end + + describe service('proxysql') do + it { is_expected.to be_enabled } + it { is_expected.to be_running } + end + + describe command('proxysql --version') do + its(:exit_status) { is_expected.to eq 0 } + its(:stdout) { is_expected.to match %r{^ProxySQL version 2\.2\.} } + end + end + + context 'Upgrading to version 2.3' do + it 'works idempotently with no errors' do + pp = <<-EOS + class { 'proxysql': + package_ensure => latest, + version => '2.3.2', + } + EOS + + # Run it twice and test for idempotency + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + + # Run it again, this time relying on proxysql_version fact + apply_manifest('class { \'proxysql\':}', catch_changes: true) + end + + describe package('proxysql') do + it { is_expected.to be_installed } + end + + describe service('proxysql') do + it { is_expected.to be_enabled } + it { is_expected.to be_running } + end + + describe command('proxysql --version') do + its(:exit_status) { is_expected.to eq 0 } + its(:stdout) { is_expected.to match %r{^ProxySQL version 2\.3\.} } + end + end + context 'extended testing' do # Using puppet_apply as a helper it 'works idempotently with no errors' do diff --git a/spec/classes/proxysql_spec.rb b/spec/classes/proxysql_spec.rb index 4f739006..ab7b3242 100644 --- a/spec/classes/proxysql_spec.rb +++ b/spec/classes/proxysql_spec.rb @@ -32,12 +32,13 @@ if facts[:osfamily] == 'RedHat' if facts[:operatingsystem] == 'Amazon' && facts[:operatingsystemmajrelease] == '2016' - it { is_expected.to contain_yumrepo('proxysql_2_0').with_baseurl('http://repo.proxysql.com/ProxySQL/proxysql-2.0.x/centos/6') } + it { is_expected.to contain_yumrepo('proxysql_2_3').with_baseurl('http://repo.proxysql.com/ProxySQL/proxysql-2.3.x/centos/6') } + elsif facts[:operatingsystemmajrelease] =~ %r{^(5)$} + it { is_expected.to contain_yumrepo('proxysql_2_2').with_baseurl("http://repo.proxysql.com/ProxySQL/proxysql-2.2.x/centos/#{facts[:operatingsystemmajrelease]}") } else - it { is_expected.to contain_yumrepo('proxysql_2_0').with_baseurl("http://repo.proxysql.com/ProxySQL/proxysql-2.0.x/centos/#{facts[:operatingsystemmajrelease]}") } + it { is_expected.to contain_yumrepo('proxysql_2_3').with_baseurl("http://repo.proxysql.com/ProxySQL/proxysql-2.3.x/centos/#{facts[:operatingsystemmajrelease]}") } end it { is_expected.to contain_yumrepo('proxysql_repo').with_ensure('absent') } - it { is_expected.to contain_yumrepo('proxysql_1_4').with_ensure('absent') } end it do @@ -98,9 +99,9 @@ end end - unless (facts[:osfamily] == 'RedHat' && facts[:operatingsystemmajrelease] == '7') || + unless (facts[:osfamily] == 'RedHat' && facts[:operatingsystemmajrelease] =~ %r{^(7|8)$}) || (facts[:operatingsystem] == 'Ubuntu' && ['18.04', '20.04'].include?(facts[:operatingsystemmajrelease])) || - (facts[:operatingsystem] == 'Debian' && facts[:operatingsystemmajrelease] =~ %r{^(9|10)$}) + (facts[:operatingsystem] == 'Debian' && facts[:operatingsystemmajrelease] =~ %r{^(9|10|11)$}) it { is_expected.to contain_service('proxysql').with_hasstatus(true) } it { is_expected.to contain_service('proxysql').with_hasrestart(true) } end