From 04e5cc0312b6ad9e14521a9df29cae985de9a7f3 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 23 Jan 2018 14:10:43 -0800 Subject: [PATCH 1/2] (maint) Plugins don't exist before 5.5; password field name changed --- spec/acceptance/types/mysql_user_spec.rb | 13 +++++++++++-- spec/unit/puppet/provider/mysql_user/mysql_spec.rb | 8 ++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/spec/acceptance/types/mysql_user_spec.rb b/spec/acceptance/types/mysql_user_spec.rb index 1c6ff3d9b..f63e7fc4e 100644 --- a/spec/acceptance/types/mysql_user_spec.rb +++ b/spec/acceptance/types/mysql_user_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper_acceptance' +require_relative '../mysql_helper.rb' describe 'mysql_user' do describe 'setup' do @@ -44,7 +45,9 @@ class { 'mysql::server': } end end - describe 'changing authentication plugin' do + pre_run + + describe 'changing authentication plugin', if: version_is_greater_than('5.5.0') do it 'should work without errors' do pp = <<-EOS mysql_user { 'ashp@localhost': @@ -63,7 +66,13 @@ class { 'mysql::server': } end it 'should not have a password' do - shell("mysql -NBe \"select password from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| + pre_run + table = if version_is_greater_than('5.7.0') + "authentication_string" + else + "password" + end + shell("mysql -NBe \"select #{table} from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stdout.rstrip).to be_empty expect(r.stderr).to be_empty end diff --git a/spec/unit/puppet/provider/mysql_user/mysql_spec.rb b/spec/unit/puppet/provider/mysql_user/mysql_spec.rb index 87da9af47..68785ef4c 100644 --- a/spec/unit/puppet/provider/mysql_user/mysql_spec.rb +++ b/spec/unit/puppet/provider/mysql_user/mysql_spec.rb @@ -282,7 +282,7 @@ context 'MySQL < 5.7.6' do it 'changes the authentication plugin' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.1'][:string]) - provider.expects(:mysql).with([defaults_file, system_database, '-e', "UPDATE mysql.user SET plugin = 'auth_socket', password = '' WHERE CONCAT(user, '@', host) = 'joe@localhost'"]).returns('0') + provider.class.expects(:mysql_caller).with("UPDATE mysql.user SET plugin = 'auth_socket', password = '' WHERE CONCAT(user, '@', host) = 'joe@localhost'", 'system').returns('0') provider.expects(:plugin).returns('auth_socket') provider.plugin = 'auth_socket' @@ -292,7 +292,7 @@ context 'MySQL >= 5.7.6' do it 'changes the authentication plugin' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.6'][:string]) - provider.expects(:mysql).with([defaults_file, system_database, '-e', "ALTER USER 'joe'@'localhost' IDENTIFIED WITH 'auth_socket'"]).returns('0') + provider.class.expects(:mysql_caller).with("ALTER USER 'joe'@'localhost' IDENTIFIED WITH 'auth_socket'", 'system').returns('0') provider.expects(:plugin).returns('auth_socket') provider.plugin = 'auth_socket' @@ -304,7 +304,7 @@ context 'MySQL < 5.7.6' do it 'changes the authentication plugin' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.1'][:string]) - provider.expects(:mysql).with([defaults_file, system_database, '-e', "UPDATE mysql.user SET plugin = 'mysql_native_password', password = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4' WHERE CONCAT(user, '@', host) = 'joe@localhost'"]).returns('0') + provider.class.expects(:mysql_caller).with("UPDATE mysql.user SET plugin = 'mysql_native_password', password = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4' WHERE CONCAT(user, '@', host) = 'joe@localhost'", 'system').returns('0') provider.expects(:plugin).returns('mysql_native_password') provider.plugin = 'mysql_native_password' @@ -314,7 +314,7 @@ context 'MySQL >= 5.7.6' do it 'changes the authentication plugin' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.6'][:string]) - provider.expects(:mysql).with([defaults_file, system_database, '-e', "ALTER USER 'joe'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'"]).returns('0') + provider.class.expects(:mysql_caller).with("ALTER USER 'joe'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'", 'system').returns('0') provider.expects(:plugin).returns('mysql_native_password') provider.plugin = 'mysql_native_password' From 4a35815ce55ac9037b76f17a9cc2360aa89b31cb Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 23 Jan 2018 15:32:54 -0800 Subject: [PATCH 2/2] (maint) Fix helpful rubocops and disable hurtful cops --- spec/acceptance/mysql_backup_spec.rb | 48 ++++++------------- spec/acceptance/types/mysql_grant_spec.rb | 4 ++ spec/acceptance/types/mysql_user_spec.rb | 14 +++--- .../puppet/provider/mysql_user/mysql_spec.rb | 6 ++- tasks/export.rb | 6 +-- 5 files changed, 33 insertions(+), 45 deletions(-) mode change 100644 => 100755 tasks/export.rb diff --git a/spec/acceptance/mysql_backup_spec.rb b/spec/acceptance/mysql_backup_spec.rb index 9fefba865..b7b31971f 100644 --- a/spec/acceptance/mysql_backup_spec.rb +++ b/spec/acceptance/mysql_backup_spec.rb @@ -35,7 +35,8 @@ class { 'mysql::server::backup': end describe 'mysqlbackup.sh' do - before(:each) do + # rubocop:disable RSpec/MultipleExpectations, RSpec/ExampleLength + before(:all) do pre_run end @@ -47,16 +48,10 @@ class { 'mysql::server::backup': end end - it 'dumps all databases to single file #stdout' do + it 'dumps all databases to single file' do unless version_is_greater_than('5.7.0') shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r| expect(r.stdout).to match(%r{1}) - end - end - end - it 'dumps all databases to single file #exit code' do - if version_is_greater_than('5.7.0') - shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r| expect(r.exit_code).to be_zero end end @@ -70,21 +65,16 @@ class { 'mysql::server::backup': end end - it 'creates at least one backup tarball #stdout' do + it 'creates at least one backup tarball' do unless version_is_greater_than('5.7.0') shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r| expect(r.stdout).to match(%r{2}) - end - end - end - it 'creates at least one backup tarball #exit code' do - unless version_is_greater_than('5.7.0') - shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r| expect(r.exit_code).to be_zero end end end end + # rubocop:enable RSpec/MultipleExpectations, RSpec/ExampleLength end context 'with one file per database' do @@ -121,7 +111,8 @@ class { 'mysql::server::backup': end describe 'mysqlbackup.sh' do - before(:each) do + # rubocop:disable RSpec/MultipleExpectations, RSpec/ExampleLength + before(:all) do pre_run end @@ -133,17 +124,11 @@ class { 'mysql::server::backup': end end - %w[backup1 backup2].each do |database| - it 'creates one file per database #stdout' do - unless version_is_greater_than('5.7.0') + it 'creates one file per database' do + unless version_is_greater_than('5.7.0') + %w[backup1 backup2].each do |database| shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r| expect(r.stdout).to match(%r{1}) - end - end - end - it 'wcreates one file per database #exit code' do # rubocop:disable RSpec/RepeatedExample - unless version_is_greater_than('5.7.0') - shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r| expect(r.exit_code).to be_zero end end @@ -157,22 +142,17 @@ class { 'mysql::server::backup': end end - %w[backup1 backup2].each do |database| - it 'has one file per database per run #stdout' do - unless version_is_greater_than('5.7.0') + it 'has one file per database per run' do + unless version_is_greater_than('5.7.0') + %w[backup1 backup2].each do |database| shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r| expect(r.stdout).to match(%r{2}) - end - end - end - it 'has one file per database per run #exit code' do # rubocop:disable RSpec/RepeatedExample - unless version_is_greater_than('5.7.0') - shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r| expect(r.exit_code).to be_zero end end end end + # rubocop:enable RSpec/MultipleExpectations, RSpec/ExampleLength end end diff --git a/spec/acceptance/types/mysql_grant_spec.rb b/spec/acceptance/types/mysql_grant_spec.rb index 46aaf7866..6fc067ce8 100644 --- a/spec/acceptance/types/mysql_grant_spec.rb +++ b/spec/acceptance/types/mysql_grant_spec.rb @@ -455,6 +455,7 @@ class { 'mysql::server': end describe 'adding function privileges' do + # rubocop:disable RSpec/ExampleLength it 'works without errors' do pp = <<-EOS exec { 'simplefunc-create': @@ -477,13 +478,16 @@ class { 'mysql::server': apply_manifest(pp, catch_failures: true) end + # rubocop:enable RSpec/ExampleLength + # rubocop:disable RSpec/MultipleExpectations it 'finds the user' do shell('mysql -NBe "SHOW GRANTS FOR test3@tester"') do |r| expect(r.stdout).to match(%r{GRANT EXECUTE ON FUNCTION `mysql`.`simplefunc` TO 'test3'@'tester'}) expect(r.stderr).to be_empty end end + # rubocop:enable RSpec/MultipleExpectations end describe 'proxy privilieges' do diff --git a/spec/acceptance/types/mysql_user_spec.rb b/spec/acceptance/types/mysql_user_spec.rb index f63e7fc4e..8cfabf2ad 100644 --- a/spec/acceptance/types/mysql_user_spec.rb +++ b/spec/acceptance/types/mysql_user_spec.rb @@ -47,30 +47,31 @@ class { 'mysql::server': } pre_run + # rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations describe 'changing authentication plugin', if: version_is_greater_than('5.5.0') do - it 'should work without errors' do + it 'works without errors' do pp = <<-EOS mysql_user { 'ashp@localhost': plugin => 'auth_socket', } EOS - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, catch_failures: true) end - it 'should have correct plugin' do + it 'has the correct plugin' do shell("mysql -NBe \"select plugin from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stdout.rstrip).to eq('auth_socket') expect(r.stderr).to be_empty end end - it 'should not have a password' do + it 'does not have a password' do pre_run table = if version_is_greater_than('5.7.0') - "authentication_string" + 'authentication_string' else - "password" + 'password' end shell("mysql -NBe \"select #{table} from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stdout.rstrip).to be_empty @@ -78,6 +79,7 @@ class { 'mysql::server': } end end end + # rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations end context 'using ashp-dash@localhost' do diff --git a/spec/unit/puppet/provider/mysql_user/mysql_spec.rb b/spec/unit/puppet/provider/mysql_user/mysql_spec.rb index 68785ef4c..61ca048c9 100644 --- a/spec/unit/puppet/provider/mysql_user/mysql_spec.rb +++ b/spec/unit/puppet/provider/mysql_user/mysql_spec.rb @@ -278,6 +278,7 @@ end describe 'plugin=' do + # rubocop:disable RSpec/NestedGroups context 'auth_socket' do context 'MySQL < 5.7.6' do it 'changes the authentication plugin' do @@ -304,7 +305,7 @@ context 'MySQL < 5.7.6' do it 'changes the authentication plugin' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.1'][:string]) - provider.class.expects(:mysql_caller).with("UPDATE mysql.user SET plugin = 'mysql_native_password', password = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4' WHERE CONCAT(user, '@', host) = 'joe@localhost'", 'system').returns('0') + provider.class.expects(:mysql_caller).with("UPDATE mysql.user SET plugin = 'mysql_native_password', password = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4' WHERE CONCAT(user, '@', host) = 'joe@localhost'", 'system').returns('0') # rubocop:disable Metrics/LineLength provider.expects(:plugin).returns('mysql_native_password') provider.plugin = 'mysql_native_password' @@ -314,13 +315,14 @@ context 'MySQL >= 5.7.6' do it 'changes the authentication plugin' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.6'][:string]) - provider.class.expects(:mysql_caller).with("ALTER USER 'joe'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'", 'system').returns('0') + provider.class.expects(:mysql_caller).with("ALTER USER 'joe'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'", 'system').returns('0') # rubocop:disable Metrics/LineLength provider.expects(:plugin).returns('mysql_native_password') provider.plugin = 'mysql_native_password' end end end + # rubocop:enable RSpec/NestedGroups end describe 'tls_options=' do diff --git a/tasks/export.rb b/tasks/export.rb old mode 100644 new mode 100755 index 0f3f64706..efd9d8126 --- a/tasks/export.rb +++ b/tasks/export.rb @@ -4,13 +4,13 @@ require 'puppet' def get(file, database, user, password) - cmd_string = "mysqldump" + cmd_string = 'mysqldump' cmd_string << " --databases #{database}" unless database.nil? cmd_string << " --user=#{user}" unless user.nil? cmd_string << " --password=#{password}" unless password.nil? cmd_string << " > #{file}" unless file.nil? - stdout, stderr, status = Open3.capture3(cmd_string) - raise Puppet::Error, _("stderr: '#{stderr}'") if status != 0 + stdout, _stderr, status = Open3.capture3(cmd_string) + raise Puppet::Error, _("stderr: ' %{stderr}') % { stderr: stderr }") if status != 0 { status: stdout.strip } end