Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifests/db.pp
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@

if $sql{
exec{"${dbname}-import":
command => "${import_cat_cmd} ${shell_join($sql)} | mysql ${dbname}",
command => "${import_cat_cmd} ${shell_join($sql)} | ${mysql::params::provider} ${dbname}",
logoutput => true,
environment => "HOME=${facts['root_home']}",
refreshonly => ! $enforce_sql,
Expand Down
7 changes: 7 additions & 0 deletions manifests/params.pp
Original file line numberDiff line numberDiff line change
Expand Up@@ -129,6 +129,7 @@
fail("Unsupported platform: puppetlabs-${module_name} currently doesn\'t support ${facts['os']['name']}.")
}
}
$provider = 'mariadb'
$config_file = '/etc/my.cnf'
$includedir = '/etc/my.cnf.d'
$datadir = '/var/lib/mysql'
Expand DownExpand Up@@ -227,6 +228,7 @@
}

'Archlinux':{
$provider = 'mariadb'
$daemon_dev_package_name = undef
$client_dev_package_name = undef
$includedir = undef
Expand DownExpand Up@@ -255,6 +257,7 @@
}

'Gentoo':{
$provider = 'mysql'
$client_package_name = 'virtual/mysql'
$includedir = undef
$server_package_name = 'virtual/mysql'
Expand All@@ -281,6 +284,7 @@
}

'FreeBSD':{
$provider = 'mysql'
$client_package_name = 'databases/mysql57-client'
$server_package_name = 'databases/mysql57-server'
$basedir = '/usr/local'
Expand DownExpand Up@@ -310,6 +314,7 @@
}

'OpenBSD':{
$provider = 'mariadb'
$client_package_name = 'mariadb-client'
$server_package_name = 'mariadb-server'
$basedir = '/usr/local'
Expand DownExpand Up@@ -341,6 +346,7 @@
default:{
case $facts['os']['name']{
'Alpine':{
$provider = 'mariadb'
$client_package_name = 'mariadb-client'
$server_package_name = 'mariadb'
$basedir = '/usr'
Expand All@@ -366,6 +372,7 @@
$daemon_dev_package_name = undef
}
'Amazon':{
$provider = 'mysql'
$client_package_name = 'mysql'
$server_package_name = 'mysql-server'
$basedir = '/usr'
Expand Down
23 changes: 19 additions & 4 deletions spec/defines/mysql_db_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,21 @@
describe 'mysql::db', type: :define do
on_supported_os.each do |os, facts|
context "on #{os}" do
provider = if facts[:os]['family'] == 'RedHat'
'mariadb'
elsif facts[:os]['family'] == 'Suse'
'mariadb'
elsif facts[:os]['name'] == 'Debian'
'mariadb'
elsif facts[:os]['name'] == 'Ubuntu'
if Puppet::Util::Package.versioncmp(facts[:os]['release']['major'], '20') < 0 &&
Puppet::Util::Package.versioncmp(facts[:os]['release']['major'], '16') >= 0
'mysql'
else
'mariadb'
end
end

let(:facts) do
facts.merge(root_home: '/root')
end
Expand DownExpand Up@@ -39,20 +54,20 @@
# ' if enforcing #refreshonly'
expect(subject).to contain_exec('test_db-import').with_refreshonly(false)
# 'if enforcing #command'
expect(subject).to contain_exec('test_db-import').with_command('cat /tmp/test.sql | mysql test_db')
expect(subject).to contain_exec('test_db-import').with_command("cat /tmp/test.sql | #{provider} test_db")
end

it 'imports sql script with custom command on creation' do
params.merge!('sql' => sql, 'enforce_sql' => true, 'import_cat_cmd' => 'zcat')
# if enforcing #refreshonly
expect(subject).to contain_exec('test_db-import').with_refreshonly(false)
# if enforcing #command
expect(subject).to contain_exec('test_db-import').with_command('zcat /tmp/test.sql | mysql test_db')
expect(subject).to contain_exec('test_db-import').with_command("zcat /tmp/test.sql | #{provider} test_db")
end

it 'imports sql scripts when more than one is specified' do
params['sql'] = ['/tmp/test.sql', '/tmp/test_2.sql']
expect(subject).to contain_exec('test_db-import').with_command('cat /tmp/test.sql /tmp/test_2.sql | mysql test_db')
expect(subject).to contain_exec('test_db-import').with_command("cat /tmp/test.sql /tmp/test_2.sql | #{provider} test_db")
end

it 'does not create database' do
Expand DownExpand Up@@ -111,7 +126,7 @@
].each do |path|
it "succeeds when provided '#{path}' as a value to the 'sql' parameter" do
params['sql'] = [path]
expect(subject).to contain_exec('test_db-import').with_command("cat #{path} | mysql test_db")
expect(subject).to contain_exec('test_db-import').with_command("cat #{path} | #{provider} test_db")
end
end

Expand Down