From 548952a6f93d3ed612a4b015eb8f715930a83e90 Mon Sep 17 00:00:00 2001 From: Ray Lehtiniemi Date: Wed, 23 Jul 2014 14:12:00 -0600 Subject: [PATCH] Prevent ERROR 1008 in mysql_database provider Check for database existence when dropping to prevent ERROR 1008 (HY000): Can't drop database 'test'; database doesn't exist Signed-off-by: Ray Lehtiniemi --- lib/puppet/provider/mysql_database/mysql.rb | 2 +- spec/unit/puppet/provider/mysql_database/mysql_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/mysql_database/mysql.rb b/lib/puppet/provider/mysql_database/mysql.rb index ae9ab39..213e0de 100644 --- a/lib/puppet/provider/mysql_database/mysql.rb +++ b/lib/puppet/provider/mysql_database/mysql.rb @@ -41,7 +41,7 @@ Puppet::Type.type(:mysql_database).provide(:mysql, :parent => Puppet::Provider:: end def destroy - mysql([defaults_file, '-NBe', "drop database `#{@resource[:name]}`"].compact) + mysql([defaults_file, '-NBe', "drop database if exists `#{@resource[:name]}`"].compact) @property_hash.clear exists? ? (return false) : (return true) diff --git a/spec/unit/puppet/provider/mysql_database/mysql_spec.rb b/spec/unit/puppet/provider/mysql_database/mysql_spec.rb index 333809f..4bc24b4 100644 --- a/spec/unit/puppet/provider/mysql_database/mysql_spec.rb +++ b/spec/unit/puppet/provider/mysql_database/mysql_spec.rb @@ -64,7 +64,7 @@ test describe 'destroy' do it 'removes a database if present' do - provider.expects(:mysql).with([defaults_file, '-NBe', "drop database `#{resource[:name]}`"]) + provider.expects(:mysql).with([defaults_file, '-NBe', "drop database if exists `#{resource[:name]}`"]) provider.expects(:exists?).returns(false) provider.destroy.should be_truthy end