Skip to content

Commit 057e3f6

Browse files
Marc-DRIsyl20-drinlegaillart-dri
authored and
Romuald Conty
committed
(#1580) Add support for MariaDB 11.x
From MariaDB 11.x, mysql* names are deprecated (cf. https://jira.mariadb.org/browse/MDEV-29582). Use mariadb* names instead, to set factors accordingly. Use these factors to return the proper client binary. Co-authored-by: Sylvain Luce <[email protected]> Co-authored-by: Nicolas Le Gaillart <[email protected]>
1 parent c0c8aee commit 057e3f6

File tree

5 files changed

+57
-8
lines changed

5 files changed

+57
-8
lines changed

lib/facter/mysql_version.rb

+8
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@
77
mysql_ver.match(%r{\d+\.\d+\.\d+})[0] if mysql_ver
88
end
99
end
10+
11+
Facter.add('mysql_version') do
12+
confine { Facter::Core::Execution.which('mariadb') }
13+
setcode do
14+
mysql_ver = Facter::Core::Execution.execute('mariadb --version')
15+
mysql_ver.match(%r{\d+\.\d+\.\d+})[0] if mysql_ver
16+
end
17+
end

lib/facter/mysqld_version.rb

+7
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@
77
Facter::Core::Execution.execute('env PATH=$PATH:/usr/libexec mysqld --no-defaults -V 2>/dev/null')
88
end
99
end
10+
11+
Facter.add('mysqld_version') do
12+
confine { Facter::Core::Execution.which('mariadbd') }
13+
setcode do
14+
Facter::Core::Execution.execute('mariadbd --no-defaults -V 2>/dev/null')
15+
end
16+
end

lib/puppet/provider/mysql.rb

+11-5
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,23 @@ class Puppet::Provider::Mysql < Puppet::Provider
4747
# rubocop:enable Style/HashSyntax
4848

4949
def self.mysql_raw(*args)
50-
mysqld_version_string.scan(%r{mariadb}i) { return mariadb_client(*args) }
50+
if self.newer_than('mariadb' => '11.0.0') and mysqld_version_string.scan(%r{mariadb}i)
51+
return mariadb_client(*args)
52+
end
5153
mysql_client(*args)
5254
end
5355

5456
def self.mysqld(*args)
55-
mysqld_version_string.scan(%r{mariadb}i) { return mariadbd_service(*args) }
57+
if self.newer_than('mariadb' => '11.0.0') and mysqld_version_string.scan(%r{mariadb}i)
58+
return mariadb_client(*args)
59+
end
5660
mysqld_service(*args)
5761
end
5862

5963
def self.mysqladmin(*args)
60-
mysqld_version_string.scan(%r{mariadb}i) { return mariadb_admin(*args) }
64+
if self.newer_than('mariadb' => '11.0.0') and mysqld_version_string.scan(%r{mariadb}i)
65+
return mariadb_client(*args)
66+
end
6167
mysql_admin(*args)
6268
end
6369

@@ -80,8 +86,8 @@ def mysqld_type
8086
def self.mysqld_version_string
8187
# As the possibility of the mysqld being remote we need to allow the version string to be overridden,
8288
# this can be done by facter.value as seen below. In the case that it has not been set and the facter
83-
# value is nil we use the mysql -v command to ensure we report the correct version of mysql for later use cases.
84-
@mysqld_version_string ||= Facter.value(:mysqld_version) || mysqld('-V')
89+
# value is nil we use an empty string so that default client/service are used.
90+
@mysqld_version_string ||= Facter.value(:mysqld_version) || ""
8591
end
8692

8793
def mysqld_version_string

spec/unit/facter/mysql_version_spec.rb

+15-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,28 @@
88
end
99

1010
describe 'mysql_version' do
11-
context 'with value' do
11+
context 'with mysql' do
1212
before :each do
13-
allow(Facter::Core::Execution).to receive(:which).and_return('fake_mysql_path')
13+
allow(Facter::Core::Execution).to receive(:which).with('mysql').and_return('fake_mysql_path')
14+
allow(Facter::Core::Execution).to receive(:which).with('mariadb').and_return(false)
1415
allow(Facter::Core::Execution).to receive(:execute).with('mysql --version').and_return('mysql Ver 14.12 Distrib 5.0.95, for redhat-linux-gnu (x86_64) using readline 5.1')
1516
end
1617

1718
it {
1819
expect(Facter.fact(:mysql_version).value).to eq('5.0.95')
1920
}
2021
end
22+
23+
context 'with mariadb' do
24+
before :each do
25+
allow(Facter::Core::Execution).to receive(:which).with('mysql').and_return(false)
26+
allow(Facter::Core::Execution).to receive(:which).with('mariadb').and_return('/usr/bin/mariadb')
27+
allow(Facter::Core::Execution).to receive(:execute).with('mariadb --version').and_return('mariadb from 11.4.2-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using EditLine wrapper')
28+
end
29+
30+
it {
31+
expect(Facter.fact(:mysql_version).value).to eq('11.4.2')
32+
}
33+
end
2134
end
2235
end

spec/unit/facter/mysqld_version_spec.rb

+16-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
end
99

1010
describe 'mysqld_version' do
11-
context 'with value' do
11+
context 'with mysqld' do
1212
before :each do
1313
allow(Facter::Core::Execution).to receive(:which).with('mysqld').and_return('/usr/sbin/mysqld')
14+
allow(Facter::Core::Execution).to receive(:which).with('mariadbd').and_return(false)
1415
allow(Facter::Core::Execution).to receive(:execute).with('env PATH=$PATH:/usr/libexec mysqld --no-defaults -V 2>/dev/null')
1516
.and_return('mysqld Ver 5.5.49-37.9 for Linux on x86_64 (Percona Server (GPL), Release 37.9, Revision efa0073)')
1617
end
@@ -19,5 +20,19 @@
1920
expect(Facter.fact(:mysqld_version).value).to eq('mysqld Ver 5.5.49-37.9 for Linux on x86_64 (Percona Server (GPL), Release 37.9, Revision efa0073)')
2021
}
2122
end
23+
24+
context 'with mariadb' do
25+
before :each do
26+
allow(Facter::Core::Execution).to receive(:which).with('mysqld').and_return(false)
27+
allow(Facter::Core::Execution).to receive(:which).with('/usr/libexec/mysqld').and_return(false)
28+
allow(Facter::Core::Execution).to receive(:which).with('mariadbd').and_return('/usr/sbin/mariadbd')
29+
allow(Facter::Core::Execution).to receive(:execute).with('mariadbd --no-defaults -V 2>/dev/null')
30+
.and_return('mariadbd Ver 11.4.2-MariaDB-ubu2404 for debian-linux-gnu on x86_64 (mariadb.org binary distribution)')
31+
end
32+
33+
it {
34+
expect(Facter.fact(:mysqld_version).value).to eq('mariadbd Ver 11.4.2-MariaDB-ubu2404 for debian-linux-gnu on x86_64 (mariadb.org binary distribution)')
35+
}
36+
end
2237
end
2338
end

0 commit comments

Comments
 (0)