Skip to content

Commit

Permalink
Fix managed dirs (#1305)
Browse files Browse the repository at this point in the history
* Added a case statement to include executing manage_dirs on the class config only for Debian, because
there's dependency of Debian tool
unless  => "/usr/bin/dpkg -s ${mysql::server::package_name}",
Created the parameter managed_dirs for the class mysql::server to allow use the class mysql::server::managed_dirs

* Updated REFERENCES for the new parameter managed_dirs.

* Added a default case for the case statement of managing dirs for Debian in mysql::server::config

* Fixed a default value for the parameter $managed_dirs from undef to $mysql::params::managed_dirs.
Updated REFERENCE.md

* (maint) Add tests to verify mariadb

Co-authored-by: Eugeny Kisel <ekisel@objectstyle.com>
Co-authored-by: sheena <sheena@puppet.com>
  • Loading branch information
3 people committed Jun 23, 2020
1 parent ddca3f9 commit 6af116c
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 12 deletions.
9 changes: 9 additions & 0 deletions REFERENCE.md
Expand Up @@ -465,6 +465,15 @@ Whether the MySQL configuration file should be managed. Valid values are `true`,

Default value: $mysql::params::manage_config_file

##### `managed_dirs`

Data type: `Any`

Manage MySQL system directories which described in the section `[mysqld]` of the configuration file
`my.cnf`

Default value: `$mysql::params::managed_dirs`

##### `options`

Data type: `Mysql::Options`
Expand Down
1 change: 1 addition & 0 deletions manifests/server.pp
Expand Up @@ -88,6 +88,7 @@
$remove_default_accounts = false,
$restart = $mysql::params::restart,
$root_group = $mysql::params::root_group,
$managed_dirs = $mysql::params::managed_dirs,
$mysql_group = $mysql::params::mysql_group,
$mycnf_owner = $mysql::params::mycnf_owner,
$mycnf_group = $mysql::params::mycnf_group,
Expand Down
29 changes: 17 additions & 12 deletions manifests/server/config.pp
Expand Up @@ -36,21 +36,26 @@
}

#Debian: Creating world readable directories before installing.
if $managed_dirs {
$managed_dirs.each | $entry | {
$dir = $options['mysqld']["${entry}"]
if ( $dir and $dir != '/usr' and $dir != '/tmp' ) {
exec {"${entry}-managed_dir-mkdir":
command => "/bin/mkdir -p ${dir}",
unless => "/usr/bin/dpkg -s ${mysql::server::package_name}",
notify => Exec["${entry}-managed_dir-chmod"],
}
exec {"${entry}-managed_dir-chmod":
command => "/bin/chmod 777 ${dir}",
refreshonly => true,
case $::operatingsystem {
'Debian': {
if $managed_dirs {
$managed_dirs.each | $entry | {
$dir = $options['mysqld']["${entry}"]
if ( $dir and $dir != '/usr' and $dir != '/tmp' ) {
exec {"${entry}-managed_dir-mkdir":
command => "/bin/mkdir -p ${dir}",
unless => "/usr/bin/dpkg -s ${mysql::server::package_name}",
notify => Exec["${entry}-managed_dir-chmod"],
}
exec {"${entry}-managed_dir-chmod":
command => "/bin/chmod 777 ${dir}",
refreshonly => true,
}
}
}
}
}
default: {}
}

if $mysql::server::manage_config_file {
Expand Down
44 changes: 44 additions & 0 deletions spec/acceptance/mysql_mariadb_spec.rb
@@ -0,0 +1,44 @@
require 'spec_helper_acceptance'

describe 'mysql server class', if: ((os[:family] == 'debian' && os[:release].to_i > 8) || (os[:family] == 'redhat' && os[:release].to_i > 6)) do
describe 'mariadb' do
let(:pp) do
<<-MANIFEST
$osname = $facts['os']['name'].downcase
yumrepo {'mariadb':
baseurl => "http://yum.mariadb.org/10.4/$osname${facts['os']['release']['major']}-aarch64/",
gpgkey => 'https://yum.mariadb.org/RPM-GPG-KEY-MariaDB',
descr => "MariaDB 10.4",
enabled => 1,
gpgcheck => 1,
}->
class { '::mysql::server':
require => Yumrepo['mariadb'],
package_name => 'mariadb-server',
service_name => 'mariadb',
root_password => 'strongpassword',
remove_default_accounts => true,
managed_dirs => ['/var/log','/var/run/mysql'],
override_options => {
mysqld => {
log-error => '/var/log/mariadb.log',
pid-file => '/var/run/mysql/mysqld.pid',
},
mysqld_safe => {
log-error => '/var/log/mariadb.log',
},
},
}
MANIFEST
end

it 'apply manifest' do
apply_manifest(pp)
end
it 'mariadb connection' do
result = run_shell('mysql --user="root" --password="strongpassword" -e "status"')
expect(result.stdout).to match(%r{MariaDB})
expect(result.stderr).to be_empty
end
end
end

0 comments on commit 6af116c

Please sign in to comment.