diff --git a/manifests/db.pp b/manifests/db.pp index 29181eee9..ce7db7d10 100644 --- a/manifests/db.pp +++ b/manifests/db.pp @@ -2,20 +2,21 @@ define mysql::db ( $user, $password, - $dbname = $name, - $charset = 'utf8', - $collate = 'utf8_general_ci', - $host = 'localhost', - $grant = 'ALL', - $sql = undef, - $enforce_sql = false, - $ensure = 'present', + $dbname = $name, + $charset = 'utf8', + $collate = 'utf8_general_ci', + $host = 'localhost', + $grant = 'ALL', + $sql = undef, + $enforce_sql = false, + $ensure = 'present', $import_timeout = 300, ) { #input validation validate_re($ensure, '^(present|absent)$', "${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.") $table = "${dbname}.*" + $sql_inputs = join(any2array($sql), ' ') include '::mysql::client' @@ -49,10 +50,11 @@ if $sql { exec{ "${dbname}-import": - command => "/usr/bin/mysql ${dbname} < ${sql}", + command => "cat ${sql_inputs} | mysql ${dbname}", logoutput => true, environment => "HOME=${::root_home}", refreshonly => $refresh, + path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin', require => Mysql_grant["${user}@${host}/${table}"], subscribe => Mysql_database[$dbname], timeout => $import_timeout, diff --git a/spec/defines/mysql_db_spec.rb b/spec/defines/mysql_db_spec.rb index 15f433bb5..4f9c9c2db 100644 --- a/spec/defines/mysql_db_spec.rb +++ b/spec/defines/mysql_db_spec.rb @@ -35,6 +35,11 @@ is_expected.to contain_exec('test_db-import').with_refreshonly(false) end + it 'should import sql scripts when more than one is specified' do + params.merge!({'sql' => ['test_sql', 'test_2_sql']}) + is_expected.to contain_exec('test_db-import').with_command('cat test_sql test_2_sql | mysql test_db') + end + it 'should not create database and database user' do params.merge!({'ensure' => 'absent', 'host' => 'localhost'}) is_expected.to contain_mysql_database('test_db').with_ensure('absent')