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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# MANAGED BY MODULESYNC
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

FROM ruby:2.7
FROM ruby:2
gdubicki marked this conversation as resolved.
Show resolved Hide resolved

WORKDIR /opt/puppet

Expand Down
2 changes: 1 addition & 1 deletion manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class proxysql::install {
if $proxysql::package_source {
case $facts['os']['family'] {
'Debian': {
/^(Debian|Ubuntu)$/: {
altima marked this conversation as resolved.
Show resolved Hide resolved
$real_package_source = '/root/proxysql-package.deb'

archive { $real_package_source:
Expand Down
58 changes: 56 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$datadir = '/var/lib/proxysql'

case $facts['os']['family'] {
'Debian': {
/^(Debian|Ubuntu)$/: {
altima marked this conversation as resolved.
Show resolved Hide resolved
$package_provider = 'dpkg'
$package_dependencies = []

Expand Down 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
39 changes: 34 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,37 @@
* => $repo,
}

$purge_repo = $proxysql::version ? {
/^2\.0\./ => $proxysql::params::repo14['name'],
/^1\.4\./ => $proxysql::params::repo20['name'],
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