Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS and Version update #184

Closed
wants to merge 16 commits into from
56 changes: 55 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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")
Expand All @@ -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')
Expand Down
36 changes: 31 additions & 5 deletions manifests/repo.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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,
}
}
Expand Down
5 changes: 4 additions & 1 deletion manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
98 changes: 97 additions & 1 deletion spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class { 'proxysql':
pp = <<-EOS
class { 'proxysql':
package_ensure => latest,
version => '2.0.7',
version => '2.0.6',
}
EOS

Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions spec/classes/proxysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down