Skip to content

(maint) Plugins don't exist on 5.1; password field name changed #1047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2018
Merged
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
48 changes: 14 additions & 34 deletions spec/acceptance/mysql_backup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

Expand Down
4 changes: 4 additions & 0 deletions spec/acceptance/types/mysql_grant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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
Expand Down
23 changes: 17 additions & 6 deletions spec/acceptance/types/mysql_user_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper_acceptance'
require_relative '../mysql_helper.rb'

describe 'mysql_user' do
describe 'setup' do
Expand Down Expand Up @@ -44,31 +45,41 @@ class { 'mysql::server': }
end
end

describe 'changing authentication plugin' do
it 'should work without errors' do
pre_run

# rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations
describe 'changing authentication plugin', if: version_is_greater_than('5.5.0') 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
shell("mysql -NBe \"select password from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r|
it 'does not have a password' do
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
end
end
# rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations
end

context 'using ashp-dash@localhost' do
Expand Down
10 changes: 6 additions & 4 deletions spec/unit/puppet/provider/mysql_user/mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,12 @@
end

describe 'plugin=' do
# rubocop:disable RSpec/NestedGroups
context 'auth_socket' do
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'
Expand All @@ -292,7 +293,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'
Expand All @@ -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.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') # rubocop:disable Metrics/LineLength

provider.expects(:plugin).returns('mysql_native_password')
provider.plugin = 'mysql_native_password'
Expand All @@ -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.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') # 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
Expand Down
6 changes: 3 additions & 3 deletions tasks/export.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hunner This wasn't a hurtful cop. There's a misplaced " on the line below. That's why rubocop was complaining about stderr not being used.

raise Puppet::Error, _("stderr: ' %{stderr}') % { stderr: stderr }") if status != 0
{ status: stdout.strip }
end

Expand Down