From 941427a53636d8c19d3a9af485a27f69aae0f00b Mon Sep 17 00:00:00 2001 From: OxCom Date: Fri, 29 Mar 2024 15:32:07 +0100 Subject: [PATCH 1/4] Reolse #1580: support mariadb 11.x --- lib/puppet/provider/mysql.rb | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/puppet/provider/mysql.rb b/lib/puppet/provider/mysql.rb index ef750039f..e6ec5dad0 100644 --- a/lib/puppet/provider/mysql.rb +++ b/lib/puppet/provider/mysql.rb @@ -38,11 +38,29 @@ class Puppet::Provider::Mysql < Puppet::Provider ].join(':') # rubocop:disable Style/HashSyntax - commands :mysql_raw => 'mysql' - commands :mysqld => 'mysqld' - commands :mysqladmin => 'mysqladmin' + commands :mysql_client => 'mysql' + commands :mariadb_client => 'mariadb' + commands :mysqld_service => 'mysqld' + commands :mariadbd_service => 'mariadbd' + commands :mysql_admin => 'mysqladmin' + commands :mariadb_admin => 'mysqladmin' # rubocop:enable Style/HashSyntax + def self.mysql_raw(*args) + mysqld_version_string.scan(%r{mariadb}i) { return mariadb_client(*args) } + mysql_client(*args) + end + + def self.mysqld(*args) + mysqld_version_string.scan(%r{mariadb}i) { return mariadbd_service(*args) } + mysqld_service(*args) + end + + def self.mysqladmin(*args) + mysqld_version_string.scan(%r{mariadb}i) { return mariadb_admin(*args) } + mysql_admin(*args) + end + # Optional defaults file def self.defaults_file "--defaults-extra-file=#{Facter.value(:root_home)}/.my.cnf" if File.file?("#{Facter.value(:root_home)}/.my.cnf") From b3f3cd78bbfe7a5d1d1eb0a260e78228ae979a67 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 4 Apr 2024 17:10:31 +0200 Subject: [PATCH 2/4] Update mysql.rb --- lib/puppet/provider/mysql.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/mysql.rb b/lib/puppet/provider/mysql.rb index e6ec5dad0..192bb92e8 100644 --- a/lib/puppet/provider/mysql.rb +++ b/lib/puppet/provider/mysql.rb @@ -43,7 +43,7 @@ class Puppet::Provider::Mysql < Puppet::Provider commands :mysqld_service => 'mysqld' commands :mariadbd_service => 'mariadbd' commands :mysql_admin => 'mysqladmin' - commands :mariadb_admin => 'mysqladmin' + commands :mariadb_admin => 'mariadb-admin' # rubocop:enable Style/HashSyntax def self.mysql_raw(*args) From 69ab329893eeae3a8e0480c557a600c495dafc61 Mon Sep 17 00:00:00 2001 From: Malik Parvez <84777619+malikparvez@users.noreply.github.com> Date: Tue, 2 Apr 2024 21:09:39 +0530 Subject: [PATCH 3/4] Fix mend to run on cron --- .github/workflows/mend.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/mend.yml b/.github/workflows/mend.yml index b4100a5af..8b5b40184 100644 --- a/.github/workflows/mend.yml +++ b/.github/workflows/mend.yml @@ -1,9 +1,10 @@ name: "mend" on: - pull_request: - branches: - - "main" + pull_request_target: + types: + - opened + - synchronize schedule: - cron: "0 0 * * *" workflow_dispatch: From f71ac803a8e1055e7e655ead3f7ca99cf4e4ced5 Mon Sep 17 00:00:00 2001 From: Marc Simonetti Date: Tue, 27 Aug 2024 10:42:59 +0200 Subject: [PATCH 4/4] (#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 Co-authored-by: Nicolas Le Gaillart --- lib/facter/mysql_version.rb | 8 ++++++++ lib/facter/mysqld_version.rb | 7 +++++++ lib/puppet/provider/mysql.rb | 16 +++++++++++----- spec/unit/facter/mysql_version_spec.rb | 17 +++++++++++++++-- spec/unit/facter/mysqld_version_spec.rb | 17 ++++++++++++++++- 5 files changed, 57 insertions(+), 8 deletions(-) diff --git a/lib/facter/mysql_version.rb b/lib/facter/mysql_version.rb index 25aae8cbf..3d1d33afd 100644 --- a/lib/facter/mysql_version.rb +++ b/lib/facter/mysql_version.rb @@ -7,3 +7,11 @@ mysql_ver.match(%r{\d+\.\d+\.\d+})[0] if mysql_ver end end + +Facter.add('mysql_version') do + confine { Facter::Core::Execution.which('mariadb') } + setcode do + mysql_ver = Facter::Core::Execution.execute('mariadb --version') + mysql_ver.match(%r{\d+\.\d+\.\d+})[0] if mysql_ver + end +end diff --git a/lib/facter/mysqld_version.rb b/lib/facter/mysqld_version.rb index 249b71fd9..e57e33b42 100644 --- a/lib/facter/mysqld_version.rb +++ b/lib/facter/mysqld_version.rb @@ -7,3 +7,10 @@ Facter::Core::Execution.execute('env PATH=$PATH:/usr/libexec mysqld --no-defaults -V 2>/dev/null') end end + +Facter.add('mysqld_version') do + confine { Facter::Core::Execution.which('mariadbd') } + setcode do + Facter::Core::Execution.execute('mariadbd --no-defaults -V 2>/dev/null') + end +end diff --git a/lib/puppet/provider/mysql.rb b/lib/puppet/provider/mysql.rb index 192bb92e8..d1f5203d1 100644 --- a/lib/puppet/provider/mysql.rb +++ b/lib/puppet/provider/mysql.rb @@ -47,17 +47,23 @@ class Puppet::Provider::Mysql < Puppet::Provider # rubocop:enable Style/HashSyntax def self.mysql_raw(*args) - mysqld_version_string.scan(%r{mariadb}i) { return mariadb_client(*args) } + if self.newer_than('mariadb' => '11.0.0') and mysqld_version_string.scan(%r{mariadb}i) + return mariadb_client(*args) + end mysql_client(*args) end def self.mysqld(*args) - mysqld_version_string.scan(%r{mariadb}i) { return mariadbd_service(*args) } + if self.newer_than('mariadb' => '11.0.0') and mysqld_version_string.scan(%r{mariadb}i) + return mariadb_client(*args) + end mysqld_service(*args) end def self.mysqladmin(*args) - mysqld_version_string.scan(%r{mariadb}i) { return mariadb_admin(*args) } + if self.newer_than('mariadb' => '11.0.0') and mysqld_version_string.scan(%r{mariadb}i) + return mariadb_client(*args) + end mysql_admin(*args) end @@ -80,8 +86,8 @@ def mysqld_type def self.mysqld_version_string # As the possibility of the mysqld being remote we need to allow the version string to be overridden, # this can be done by facter.value as seen below. In the case that it has not been set and the facter - # value is nil we use the mysql -v command to ensure we report the correct version of mysql for later use cases. - @mysqld_version_string ||= Facter.value(:mysqld_version) || mysqld('-V') + # value is nil we use an empty string so that default client/service are used. + @mysqld_version_string ||= Facter.value(:mysqld_version) || "" end def mysqld_version_string diff --git a/spec/unit/facter/mysql_version_spec.rb b/spec/unit/facter/mysql_version_spec.rb index 2b6ef7fcd..b13994889 100644 --- a/spec/unit/facter/mysql_version_spec.rb +++ b/spec/unit/facter/mysql_version_spec.rb @@ -8,9 +8,10 @@ end describe 'mysql_version' do - context 'with value' do + context 'with mysql' do before :each do - allow(Facter::Core::Execution).to receive(:which).and_return('fake_mysql_path') + allow(Facter::Core::Execution).to receive(:which).with('mysql').and_return('fake_mysql_path') + allow(Facter::Core::Execution).to receive(:which).with('mariadb').and_return(false) 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') end @@ -18,5 +19,17 @@ expect(Facter.fact(:mysql_version).value).to eq('5.0.95') } end + + context 'with mariadb' do + before :each do + allow(Facter::Core::Execution).to receive(:which).with('mysql').and_return(false) + allow(Facter::Core::Execution).to receive(:which).with('mariadb').and_return('/usr/bin/mariadb') + 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') + end + + it { + expect(Facter.fact(:mysql_version).value).to eq('11.4.2') + } + end end end diff --git a/spec/unit/facter/mysqld_version_spec.rb b/spec/unit/facter/mysqld_version_spec.rb index 6b3330f08..6a029d1c2 100644 --- a/spec/unit/facter/mysqld_version_spec.rb +++ b/spec/unit/facter/mysqld_version_spec.rb @@ -8,9 +8,10 @@ end describe 'mysqld_version' do - context 'with value' do + context 'with mysqld' do before :each do allow(Facter::Core::Execution).to receive(:which).with('mysqld').and_return('/usr/sbin/mysqld') + allow(Facter::Core::Execution).to receive(:which).with('mariadbd').and_return(false) allow(Facter::Core::Execution).to receive(:execute).with('env PATH=$PATH:/usr/libexec mysqld --no-defaults -V 2>/dev/null') .and_return('mysqld Ver 5.5.49-37.9 for Linux on x86_64 (Percona Server (GPL), Release 37.9, Revision efa0073)') end @@ -19,5 +20,19 @@ 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)') } end + + context 'with mariadb' do + before :each do + allow(Facter::Core::Execution).to receive(:which).with('mysqld').and_return(false) + allow(Facter::Core::Execution).to receive(:which).with('/usr/libexec/mysqld').and_return(false) + allow(Facter::Core::Execution).to receive(:which).with('mariadbd').and_return('/usr/sbin/mariadbd') + allow(Facter::Core::Execution).to receive(:execute).with('mariadbd --no-defaults -V 2>/dev/null') + .and_return('mariadbd Ver 11.4.2-MariaDB-ubu2404 for debian-linux-gnu on x86_64 (mariadb.org binary distribution)') + end + + it { + 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)') + } + end end end