Skip to content

Commit 5f1ee44

Browse files
committed
added helper method in mysql provider to pick mysql or mariadb binary variant based on version
changed commands to use the new helper method
1 parent 1e55070 commit 5f1ee44

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

lib/puppet/provider/mysql.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,33 @@ class Puppet::Provider::Mysql < Puppet::Provider
3737
'/usr/mysql/5.7/lib64',
3838
].join(':')
3939

40+
def self.pick_correct_binary(mysql_variant, mariadb_variant)
41+
version = Facter.value(:mysqld_version)
42+
if version.scan(%r{mariadb}i) && Puppet::Util::Package.versioncmp(version&.scan(%r{\d+\.\d+\.\d+})&.first, '11.0.0') >= 0
43+
return mariadb_variant
44+
end
45+
mysql_variant
46+
end
47+
48+
def pick_correct_binary(mysql_variant, mariadb_variant)
49+
self.class.pick_correct_binary(mysql_variant, mariadb_variant)
50+
end
51+
4052
# rubocop:disable Style/HashSyntax
41-
commands :mysql_client => 'mysql'
42-
commands :mariadb_client => 'mariadb'
43-
commands :mysqld_service => 'mysqld'
44-
commands :mariadbd_service => 'mariadbd'
45-
commands :mysql_admin => 'mysqladmin'
46-
commands :mariadb_admin => 'mariadb-admin'
53+
commands :mysql_client => pick_correct_binary('mysql', 'mariadb')
54+
commands :mysqld_service => pick_correct_binary('mysqld', 'mariadbd')
55+
commands :mysql_admin => pick_correct_binary('mysqladmin', 'mariadb-admin')
4756
# rubocop:enable Style/HashSyntax
4857

4958
def self.mysql_raw(*args)
50-
if newer_than('mariadb' => '11.0.0') && mysqld_version_string.scan(%r{mariadb}i)
51-
return mariadb_client(*args)
52-
end
5359
mysql_client(*args)
5460
end
5561

5662
def self.mysqld(*args)
57-
if newer_than('mariadb' => '11.0.0') && mysqld_version_string.scan(%r{mariadb}i)
58-
return mariadb_client(*args)
59-
end
6063
mysqld_service(*args)
6164
end
6265

6366
def self.mysqladmin(*args)
64-
if newer_than('mariadb' => '11.0.0') && mysqld_version_string.scan(%r{mariadb}i)
65-
return mariadb_client(*args)
66-
end
6767
mysql_admin(*args)
6868
end
6969

lib/puppet/provider/mysql_database/mysql.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Puppet::Type.type(:mysql_database).provide(:mysql, parent: Puppet::Provider::Mysql) do
55
desc 'Manages MySQL databases.'
66

7-
commands mysql_raw: 'mysql'
7+
commands mysql_raw: pick_correct_binary('mysql', 'mariadb')
88

99
def self.instances
1010
mysql_caller('show databases', 'regular').split("\n").map do |name|

lib/puppet/provider/mysql_datadir/mysql.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
'/usr/mysql/5.7/bin',
3535
].join(':')
3636

37-
commands mysqld: 'mysqld'
38-
optional_commands mysql_install_db: 'mysql_install_db'
37+
commands mysqld: pick_correct_binary('mysqld', 'mariadbd')
38+
optional_commands mysql_install_db: pick_correct_binary('mysql_install_db', 'mariadb-install-db')
3939
# rubocop:disable Lint/UselessAssignment
4040
def create
4141
name = @resource[:name]

lib/puppet/provider/mysql_grant/mysql.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Puppet::Type.type(:mysql_grant).provide(:mysql, parent: Puppet::Provider::Mysql) do
55
desc 'Set grants for users in MySQL.'
66

7-
commands mysql_raw: 'mysql'
7+
commands mysql_raw: pick_correct_binary('mysql', 'mariadb')
88

99
def self.instances
1010
instance_configs = {}

lib/puppet/provider/mysql_plugin/mysql.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Puppet::Type.type(:mysql_plugin).provide(:mysql, parent: Puppet::Provider::Mysql) do
55
desc 'Manages MySQL plugins.'
66

7-
commands mysql_raw: 'mysql'
7+
commands mysql_raw: pick_correct_binary('mysql', 'mariadb')
88

99
def self.instances
1010
mysql_caller('show plugins', 'regular').split("\n").map do |line|

lib/puppet/provider/mysql_user/mysql.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'mysql'))
44
Puppet::Type.type(:mysql_user).provide(:mysql, parent: Puppet::Provider::Mysql) do
55
desc 'manage users for a mysql database.'
6-
commands mysql_raw: 'mysql'
6+
commands mysql_raw: pick_correct_binary('mysql', 'mariadb')
77

88
# Build a property_hash containing all the discovered information about MySQL
99
# users.

0 commit comments

Comments
 (0)