diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92a1410b3..1967b8505 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,13 +10,13 @@ jobs: Spec: uses: "puppetlabs/cat-github-actions/.github/workflows/module_ci.yml@main" with: - runs_on: "ubuntu-20.04" + runs_on: "ubuntu-24.04" secrets: "inherit" setup_matrix: name: "Setup Test Matrix" needs: "Spec" - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 outputs: matrix: ${{ steps.get-matrix.outputs.matrix }} @@ -24,10 +24,10 @@ jobs: - name: Checkout Source uses: actions/checkout@v3 - - name: Activate Ruby 2.7 + - name: Activate Ruby 3.1 uses: ruby/setup-ruby@v1 with: - ruby-version: "2.7" + ruby-version: "3.1" bundler-cache: true - name: Print bundle environment @@ -47,7 +47,7 @@ jobs: - setup_matrix if: ${{ needs.setup_matrix.outputs.matrix != '{}' }} - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 strategy: fail-fast: false matrix: ${{fromJson(needs.setup_matrix.outputs.matrix)}} @@ -57,13 +57,18 @@ jobs: FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main' steps: + - name: "Install Twingate" + uses: "twingate/github-action@v1" + with: + service-key: ${{ secrets.TWINGATE_PUBLIC_REPO_KEY }} + - name: Checkout Source uses: actions/checkout@v3 - - name: Activate Ruby 2.7 + - name: Activate Ruby 3.1 uses: ruby/setup-ruby@v1 with: - ruby-version: "2.7" + ruby-version: "3.1" bundler-cache: true - name: Print bundle environment diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 795a46372..eeb047a2b 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -9,13 +9,13 @@ jobs: Spec: uses: "puppetlabs/cat-github-actions/.github/workflows/module_ci.yml@main" with: - runs_on: "ubuntu-20.04" + runs_on: "ubuntu-24.04" secrets: "inherit" setup_matrix: name: "Setup Test Matrix" needs: "Spec" - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 outputs: matrix: ${{ steps.get-matrix.outputs.matrix }} @@ -23,10 +23,10 @@ jobs: - name: Checkout Source uses: actions/checkout@v3 - - name: Activate Ruby 2.7 + - name: Activate Ruby 3.1 uses: ruby/setup-ruby@v1 with: - ruby-version: "2.7" + ruby-version: "3.1" bundler-cache: true - name: Print bundle environment @@ -46,7 +46,7 @@ jobs: - setup_matrix if: ${{ needs.setup_matrix.outputs.matrix != '{}' }} - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 strategy: fail-fast: false matrix: ${{fromJson(needs.setup_matrix.outputs.matrix)}} @@ -56,13 +56,18 @@ jobs: FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main' steps: + - name: "Install Twingate" + uses: "twingate/github-action@v1" + with: + service-key: ${{ secrets.TWINGATE_PUBLIC_REPO_KEY }} + - name: Checkout Source uses: actions/checkout@v3 - - name: Activate Ruby 2.7 + - name: Activate Ruby 3.1 uses: ruby/setup-ruby@v1 with: - ruby-version: "2.7" + ruby-version: "3.1" bundler-cache: true - name: Print bundle environment diff --git a/CHANGELOG.md b/CHANGELOG.md index f90f52695..b22dd9d0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org). +## [v16.3.0](https://github.com/puppetlabs/puppetlabs-mysql/tree/v16.3.0) - 2025-07-29 + +[Full Changelog](https://github.com/puppetlabs/puppetlabs-mysql/compare/v16.2.0...v16.3.0) + +### Added + +- Add support for Mariadb 11.x [#1645](https://github.com/puppetlabs/puppetlabs-mysql/pull/1645) ([Marc-DRI](https://github.com/Marc-DRI)) + +### Other + +- ci(MODULES-11557): add Twingate setup step to GitHub Actions workflow [#1678](https://github.com/puppetlabs/puppetlabs-mysql/pull/1678) ([imaqsood](https://github.com/imaqsood)) +- MODULES-11577 chore(ruby): upgrade Ruby from 2.7 to 3.1 [#1671](https://github.com/puppetlabs/puppetlabs-mysql/pull/1671) ([imaqsood](https://github.com/imaqsood)) +- (CAT-2296) Update github runner image to ubuntu-24.04 [#1669](https://github.com/puppetlabs/puppetlabs-mysql/pull/1669) ([shubhamshinde360](https://github.com/shubhamshinde360)) + ## [v16.2.0](https://github.com/puppetlabs/puppetlabs-mysql/tree/v16.2.0) - 2024-12-16 [Full Changelog](https://github.com/puppetlabs/puppetlabs-mysql/compare/v16.1.0...v16.2.0) @@ -195,7 +209,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ### Fixed -- Fix mysql_user parameters update on modern MySQL [#1415](https://github.com/puppetlabs/puppetlabs-mysql/pull/1415) ([weastur](https://github.com/weastur)) +- Fix mysql_user parameters update on modern MySQL [#1415](https://github.com/puppetlabs/puppetlabs-mysql/pull/1415) ([psapezhka](https://github.com/psapezhka)) - (IAC-1677) Fix issue with deprecated rspec [#1414](https://github.com/puppetlabs/puppetlabs-mysql/pull/1414) ([ghoneycutt](https://github.com/ghoneycutt)) - Fix broken link and style in documentation [#1403](https://github.com/puppetlabs/puppetlabs-mysql/pull/1403) ([ghoneycutt](https://github.com/ghoneycutt)) @@ -1184,7 +1198,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - Refactor to put a knob on all parameters [#169](https://github.com/puppetlabs/puppetlabs-mysql/pull/169) ([wolfspyre](https://github.com/wolfspyre)) - Puppet 2.6 fix [#163](https://github.com/puppetlabs/puppetlabs-mysql/pull/163) ([domcleal](https://github.com/domcleal)) - Restrict the versions and add 3.1 [#155](https://github.com/puppetlabs/puppetlabs-mysql/pull/155) ([richardc](https://github.com/richardc)) -- Fix issue with redeclaration of database_user via mysql::db [#154](https://github.com/puppetlabs/puppetlabs-mysql/pull/154) ([pbrit](https://github.com/pbrit)) +- Fix issue with redeclaration of database_user via mysql::db [#154](https://github.com/puppetlabs/puppetlabs-mysql/pull/154) ([paaloeye](https://github.com/paaloeye)) - Update travis config file [#148](https://github.com/puppetlabs/puppetlabs-mysql/pull/148) ([blkperl](https://github.com/blkperl)) ## [0.6.1](https://github.com/puppetlabs/puppetlabs-mysql/tree/0.6.1) - 2013-01-11 @@ -1207,7 +1221,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - allow logging via syslog [#130](https://github.com/puppetlabs/puppetlabs-mysql/pull/130) ([saz](https://github.com/saz)) - Optionally manage the mysqld service [#122](https://github.com/puppetlabs/puppetlabs-mysql/pull/122) ([hunner](https://github.com/hunner)) - Mysql::backup Compression Optional [#117](https://github.com/puppetlabs/puppetlabs-mysql/pull/117) ([hunner](https://github.com/hunner)) -- Add show view privilege for backup user [#108](https://github.com/puppetlabs/puppetlabs-mysql/pull/108) ([pbrit](https://github.com/pbrit)) +- Add show view privilege for backup user [#108](https://github.com/puppetlabs/puppetlabs-mysql/pull/108) ([paaloeye](https://github.com/paaloeye)) - new config define and a small bugfix [#93](https://github.com/puppetlabs/puppetlabs-mysql/pull/93) ([savar](https://github.com/savar)) ### Fixed diff --git a/lib/facter/mysql_version.rb b/lib/facter/mysql_version.rb index 25aae8cbf..e950c69b8 100644 --- a/lib/facter/mysql_version.rb +++ b/lib/facter/mysql_version.rb @@ -1,9 +1,12 @@ # frozen_string_literal: true Facter.add('mysql_version') do - confine { Facter::Core::Execution.which('mysql') } setcode do - mysql_ver = Facter::Core::Execution.execute('mysql --version') + mysql_ver = if Facter::Core::Execution.which('mysql') + Facter::Core::Execution.execute('mysql --version') + elsif Facter::Core::Execution.which('mariadb') + Facter::Core::Execution.execute('mariadb --version') + end 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..6a383190c 100644 --- a/lib/facter/mysqld_version.rb +++ b/lib/facter/mysqld_version.rb @@ -1,9 +1,11 @@ # frozen_string_literal: true Facter.add('mysqld_version') do - confine { Facter::Core::Execution.which('mysqld') || Facter::Core::Execution.which('/usr/libexec/mysqld') } setcode do - # Add /usr/libexec to PATH to find mysqld command - Facter::Core::Execution.execute('env PATH=$PATH:/usr/libexec mysqld --no-defaults -V 2>/dev/null') + if Facter::Core::Execution.which('mysqld') || Facter::Core::Execution.which('/usr/libexec/mysqld') + Facter::Core::Execution.execute('env PATH=$PATH:/usr/libexec mysqld --no-defaults -V 2>/dev/null') + elsif Facter::Core::Execution.which('mariadbd') + Facter::Core::Execution.execute('mariadbd --no-defaults -V 2>/dev/null') + end end end diff --git a/lib/puppet/provider/mysql.rb b/lib/puppet/provider/mysql.rb index ef750039f..e539d9b9c 100644 --- a/lib/puppet/provider/mysql.rb +++ b/lib/puppet/provider/mysql.rb @@ -38,11 +38,35 @@ 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 => 'mariadb-admin' # rubocop:enable Style/HashSyntax + def self.mysql_raw(*args) + if newer_than('mariadb' => '11.0.0') && mysqld_version_string.scan(%r{mariadb}i) + return mariadb_client(*args) + end + mysql_client(*args) + end + + def self.mysqld(*args) + if newer_than('mariadb' => '11.0.0') && mysqld_version_string.scan(%r{mariadb}i) + return mariadb_client(*args) + end + mysqld_service(*args) + end + + def self.mysqladmin(*args) + if newer_than('mariadb' => '11.0.0') && mysqld_version_string.scan(%r{mariadb}i) + return mariadb_client(*args) + end + 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") @@ -62,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/manifests/backup/mysqlbackup.pp b/manifests/backup/mysqlbackup.pp index 5d1427627..cafaa15c7 100644 --- a/manifests/backup/mysqlbackup.pp +++ b/manifests/backup/mysqlbackup.pp @@ -45,7 +45,7 @@ } package { 'meb': - ensure => $ensure, + ensure => $ensure, } # http://dev.mysql.com/doc/mysql-enterprise-backup/3.11/en/mysqlbackup.privileges.html diff --git a/manifests/params.pp b/manifests/params.pp index c53c4f6cd..408cc36ef 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -401,10 +401,16 @@ } } + $skip_ssl = ($facts['os']['name'] == 'SLES' and $facts['os']['release']['major'] =~ /^15/) ? { + true => true, + false => undef, + } + $default_options = { 'client' => { 'port' => '3306', 'socket' => $mysql::params::socket, + 'skip-ssl' => $skip_ssl, }, 'mysqld_safe' => { 'nice' => '0', diff --git a/metadata.json b/metadata.json index 65ee44dcd..b1aac9944 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-mysql", - "version": "16.2.0", + "version": "16.3.0", "author": "puppetlabs", "summary": "Installs, configures, and manages the MySQL service.", "license": "Apache-2.0", diff --git a/spec/acceptance/types/mysql_database_spec.rb b/spec/acceptance/types/mysql_database_spec.rb index eb10136fc..92b5a5c74 100644 --- a/spec/acceptance/types/mysql_database_spec.rb +++ b/spec/acceptance/types/mysql_database_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper_acceptance' describe 'mysql_database' do + mysql_cmd = get_db_cmd describe 'setup' do pp = <<-MANIFEST class { 'mysql::server': } @@ -25,7 +26,7 @@ class { 'mysql::server': } end it 'finds the database #stdout' do - run_shell("mysql -NBe \"SHOW DATABASES LIKE 'spec_db'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"SHOW DATABASES LIKE 'spec_db'\"") do |r| expect(r.stdout).to match(%r{^spec_db$}) expect(r.stderr).to be_empty end @@ -48,14 +49,14 @@ class { 'mysql::server': } end it 'finds latin1 db #stdout' do - run_shell("mysql -NBe \"SHOW VARIABLES LIKE '%_database'\" spec_latin1") do |r| + run_shell("#{mysql_cmd} -NBe \"SHOW VARIABLES LIKE '%_database'\" spec_latin1") do |r| expect(r.stdout).to match(%r{^character_set_database\tlatin1\ncollation_database\tlatin1_swedish_ci$}) expect(r.stderr).to be_empty end end it 'finds utf8 db #stdout' do - run_shell("mysql -NBe \"SHOW VARIABLES LIKE '%_database'\" spec_utf8") do |r| + run_shell("#{mysql_cmd} -NBe \"SHOW VARIABLES LIKE '%_database'\" spec_utf8") do |r| expect(r.stdout).to match(%r{^character_set_database\tutf8(mb3)?\ncollation_database\tutf8(mb3)?_general_ci$}) expect(r.stderr).to be_empty end diff --git a/spec/acceptance/types/mysql_grant_spec.rb b/spec/acceptance/types/mysql_grant_spec.rb index f5ab590c2..402d17fad 100644 --- a/spec/acceptance/types/mysql_grant_spec.rb +++ b/spec/acceptance/types/mysql_grant_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper_acceptance' describe 'mysql_grant' do + mysql_cmd = get_db_cmd + before(:all) do pp = <<-MANIFEST class { 'mysql::server': @@ -31,7 +33,7 @@ class { 'mysql::server': end it 'does not find the user' do - result = run_shell('mysql -NBe "SHOW GRANTS FOR test1@tester"', expect_failures: true) + result = run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR test1@tester\"", expect_failures: true) expect(result.stderr).to contain(%r{There is no such grant defined for user 'test1' on host 'tester'}) end end @@ -53,7 +55,7 @@ class { 'mysql::server': end it 'does not find the user' do - result = run_shell('mysql -NBe "SHOW GRANTS FOR atest@tester"', expect_failures: true) + result = run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR atest@tester\"", expect_failures: true) expect(result.stderr).to contain(%r{There is no such grant defined for user 'atest' on host 'tester'}) end end @@ -76,7 +78,7 @@ class { 'mysql::server': end it 'finds the user #stdout' do - result = run_shell('mysql -NBe "SHOW GRANTS FOR test2@tester"') + result = run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR test2@tester\"") expect(result.stdout).to contain(%r{GRANT SELECT, UPDATE.*TO ['|`]test2['|`]@['|`]tester['|`]}) expect(result.stderr).to be_empty end @@ -100,7 +102,7 @@ class { 'mysql::server': end it 'finds the user #stdout' do - result = run_shell("mysql -NBe \"SHOW GRANTS FOR 'test-2'@tester\"") + result = run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR 'test-2'@tester\"") expect(result.stdout).to contain(%r{GRANT SELECT, UPDATE.*TO ['|`]test-2['|`]@['|`]tester['|`]}) expect(result.stderr).to be_empty end @@ -125,7 +127,7 @@ class { 'mysql::server': end it 'finds the user #stdout' do - result = run_shell('mysql -NBe "SHOW GRANTS FOR test3@tester"') + result = run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR test3@tester\"") expect(result.stdout).to contain(%r{GRANT SELECT, UPDATE ON `test`.* TO ['|`]test3['|`]@['|`]tester['|`] WITH GRANT OPTION$}) expect(result.stderr).to be_empty end @@ -169,7 +171,7 @@ class { 'mysql::server': end it 'finds the user #stdout' do - result = run_shell('mysql -NBe "SHOW GRANTS FOR test4@tester"') + result = run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR test4@tester\"") expect(result.stdout).to contain(%r{GRANT ALL PRIVILEGES ON `test`.* TO ['|`]test4['|`]@['|`]tester['|`] WITH GRANT OPTION}) expect(result.stderr).to be_empty end @@ -234,34 +236,34 @@ class { 'mysql::server': end it 'finds short hostname #stdout' do - result = run_shell('mysql -NBe "SHOW GRANTS FOR test@short"') + result = run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR test@short\"") expect(result.stdout).to contain(%r{GRANT ALL PRIVILEGES ON ['|`]test['|`].* TO ['|`]test['|`]@['|`]short['|`]}) expect(result.stderr).to be_empty end it 'finds long hostname #stdout' do - run_shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'long.hostname.com'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR 'test'@'long.hostname.com'\"") do |r| expect(r.stdout).to match(%r{GRANT ALL PRIVILEGES ON ['|`]test['|`].* TO ['|`]test['|`]@['|`]long.hostname.com['|`]}) expect(r.stderr).to be_empty end end it 'finds ipv4 #stdout' do - run_shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'192.168.5.6'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR 'test'@'192.168.5.6'\"") do |r| expect(r.stdout).to match(%r{GRANT ALL PRIVILEGES ON ['|`]test['|`].* TO ['|`]test['|`]@['|`]192.168.5.6['|`]}) expect(r.stderr).to be_empty end end it 'finds ipv6 #stdout' do - run_shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'2607:f0d0:1002:0051:0000:0000:0000:0004'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR 'test'@'2607:f0d0:1002:0051:0000:0000:0000:0004'\"") do |r| expect(r.stdout).to match(%r{GRANT ALL PRIVILEGES ON ['|`]test['|`].* TO ['|`]test['|`]@['|`]2607:f0d0:1002:0051:0000:0000:0000:0004['|`]}) expect(r.stderr).to be_empty end end it 'finds short ipv6 #stdout' do - run_shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'::1/128'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR 'test'@'::1/128'\"") do |r| expect(r.stdout).to match(%r{GRANT ALL PRIVILEGES ON ['|`]test['|`].* TO ['|`]test['|`]@['|`]::1/128['|`]}) expect(r.stderr).to be_empty end @@ -279,9 +281,9 @@ class { 'mysql::server': } exec { 'mysql-create-table': - command => '/usr/bin/mysql -NBe "CREATE TABLE foo.bar (name VARCHAR(20))"', + command => '/usr/bin/#{mysql_cmd} -NBe "CREATE TABLE foo.bar (name VARCHAR(20))"', environment => "HOME=${::root_home}", - unless => '/usr/bin/mysql -NBe "SELECT 1 FROM foo.bar LIMIT 1;"', + unless => '/usr/bin/#{mysql_cmd} -NBe "SELECT 1 FROM foo.bar LIMIT 1;"', require => Mysql_database['foo'], } @@ -387,7 +389,7 @@ class { 'mysql::server': describe 'adding procedure privileges' do pp = <<-MANIFEST exec { 'simpleproc-create': - command => 'mysql --user="root" --password="password" --database=mysql --delimiter="//" -NBe "CREATE PROCEDURE simpleproc (OUT param1 INT) BEGIN SELECT COUNT(*) INTO param1 FROM t; end//"', + command => "#{mysql_cmd} --user='root' --password='password' --database=mysql --delimiter='//' -NBe \\"CREATE PROCEDURE simpleproc (OUT param1 INT) BEGIN SELECT COUNT(*) INTO param1 FROM t; END//\\"", path => '/usr/bin/', before => Mysql_user['test2@tester'], } @@ -407,7 +409,7 @@ class { 'mysql::server': end it 'finds the user #stdout' do - result = run_shell('mysql -NBe "SHOW GRANTS FOR test2@tester"') + result = run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR test2@tester\"") expect(result.stdout).to match(%r{GRANT EXECUTE ON PROCEDURE `mysql`.`simpleproc` TO ['|`]test2['|`]@['|`]tester['|`]}) expect(result.stderr).to be_empty end @@ -417,7 +419,7 @@ class { 'mysql::server': it 'works without errors' do pp = <<-MANIFEST exec { 'simplefunc-create': - command => '/usr/bin/mysql --user="root" --password="password" --database=mysql -NBe "CREATE FUNCTION simplefunc (s CHAR(20)) RETURNS CHAR(50) DETERMINISTIC RETURN CONCAT(\\'Hello, \\', s, \\'!\\')"', + command => "/usr/bin/#{mysql_cmd} --user='root' --password='password' --database=mysql -NBe \\"CREATE FUNCTION simplefunc (s CHAR(20)) RETURNS CHAR(50) DETERMINISTIC RETURN CONCAT('Hello, ', s, '!')\\"", before => Mysql_user['test3@tester'], } @@ -438,7 +440,7 @@ class { 'mysql::server': end it 'finds the user' do - result = run_shell('mysql -NBe "SHOW GRANTS FOR test3@tester"') + result = run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR test3@tester\"") expect(result.stdout).to match(%r{GRANT EXECUTE ON FUNCTION `mysql`.`simplefunc` TO ['|`]test3['|`]@['|`]tester['|`]}) expect(result.stderr).to be_empty end @@ -463,7 +465,7 @@ class { 'mysql::server': end it 'finds the user #stdout' do - run_shell('mysql -NBe "SHOW GRANTS FOR proxy1@tester"') do |r| + run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR proxy1@tester\"") do |r| expect(r.stdout).to match(%r{GRANT USAGE ON *.* TO ['|`]proxy1['|`]@['|`]tester['|`]\nGRANT PROXY ON ['|`]proxy_user['|`]@['|`]proxy_host['|`] TO ['|`]proxy1['|`]@['|`]tester['|`]\n}) expect(r.stderr).to be_empty end @@ -488,7 +490,7 @@ class { 'mysql::server': end it 'finds the user #stdout' do - run_shell('mysql -NBe "SHOW GRANTS FOR proxy1@tester"') do |r| + run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR proxy1@tester\"") do |r| expect(r.stdout).not_to match(%r{GRANT PROXY ON 'proxy_user'@'proxy_host' TO ['|`]proxy1['|`]@['|`]tester['|`]}) expect(r.stderr).to be_empty end @@ -514,7 +516,7 @@ class { 'mysql::server': end it 'does not find the user' do - result = run_shell('mysql -NBe "SHOW GRANTS FOR proxy2@tester"', expect_failures: true) + result = run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR proxy2@tester\"", expect_failures: true) expect(result.stderr).to match(%r{There is no such grant defined for user 'proxy2' on host 'tester'}) end end @@ -538,7 +540,7 @@ class { 'mysql::server': end it 'does not find the user' do - result = run_shell('mysql -NBe "SHOW GRANTS FOR proxy2@tester"', expect_failures: true) + result = run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR proxy2@tester\"", expect_failures: true) expect(result.stderr).to match(%r{There is no such grant defined for user 'proxy2' on host 'tester'}) end end @@ -562,7 +564,7 @@ class { 'mysql::server': end it 'does not find the user' do - result = run_shell('mysql -NBe "SHOW GRANTS FOR proxy3@tester"', expect_failures: true) + result = run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR proxy3@tester\"", expect_failures: true) expect(result.stderr).to contain(%r{There is no such grant defined for user 'proxy3' on host 'tester'}) end end @@ -609,13 +611,13 @@ class { 'mysql::server': it 'fails with fqdn' do unless Gem::Version.new(mysql_version) > Gem::Version.new('5.7.0') - result = run_shell('mysql -NBe "SHOW GRANTS FOR test@fqdn.com"', expect_failures: true) + result = run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR test@fqdn.com\"", expect_failures: true) expect(result.stderr).to contain(%r{There is no such grant defined for user 'test' on host 'fqdn.com'}) end end it 'finds ipv4 #stdout' do - run_shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'192.168.5.7'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"SHOW GRANTS FOR 'test'@'192.168.5.7'\"") do |r| expect(r.stdout).to match(%r{GRANT ALL PRIVILEGES ON `test`.* TO ['|`]test['|`]@['|`]192.168.5.7['|`]}) expect(r.stderr).to be_empty end @@ -694,7 +696,7 @@ class { 'mysql::server': override_options => { 'root_password' => 'password' } } end it 'has the table' do - result = run_shell("mysql -e 'show tables;' grant_spec_db|grep grant_spec_table") + result = run_shell("#{mysql_cmd} -e 'show tables;' grant_spec_db|grep grant_spec_table") expect(result.exit_code).to be_zero end end diff --git a/spec/acceptance/types/mysql_user_spec.rb b/spec/acceptance/types/mysql_user_spec.rb index 2d7412175..e9d9ceae3 100644 --- a/spec/acceptance/types/mysql_user_spec.rb +++ b/spec/acceptance/types/mysql_user_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper_acceptance' describe 'mysql_user' do + mysql_cmd = get_db_cmd describe 'setup' do pp_one = <<-MANIFEST $ed25519_opts = versioncmp($facts['mysql_version'], '10.1.21') >= 0 ? { @@ -31,14 +32,14 @@ class { 'mysql::server': * => $ed25519_opts } end it 'finds the user #stdout' do - run_shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stdout).to match(%r{^1$}) expect(r.stderr).to be_empty end end it 'has no SSL options #stdout' do - run_shell("mysql -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stdout).to match(%r{^\s*$}) expect(r.stderr).to be_empty end @@ -57,7 +58,7 @@ class { 'mysql::server': * => $ed25519_opts } end it 'has the correct plugin', if: (os[:family] != 'sles' && os[:release].to_i == 15) do - run_shell("mysql -NBe \"select plugin from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| + run_shell("#{mysql_cmd} -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 @@ -69,7 +70,7 @@ class { 'mysql::server': * => $ed25519_opts } else 'password' end - run_shell("mysql -NBe \"select #{table} from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| + run_shell("#{mysql_cmd} -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 @@ -89,7 +90,7 @@ class { 'mysql::server': * => $ed25519_opts } end it 'has the correct plugin' do - run_shell("mysql -NBe \"select plugin from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"select plugin from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stdout.rstrip).to eq('ed25519') expect(r.stderr).to be_empty end @@ -109,7 +110,7 @@ class { 'mysql::server': * => $ed25519_opts } end it 'finds the user #stdout' do - run_shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp-dash@localhost'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp-dash@localhost'\"") do |r| expect(r.stdout).to match(%r{^1$}) expect(r.stderr).to be_empty end @@ -129,7 +130,7 @@ class { 'mysql::server': * => $ed25519_opts } end it 'finds the user #stdout' do - run_shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stdout).to match(%r{^1$}) expect(r.stderr).to be_empty end @@ -160,14 +161,14 @@ class { 'mysql::server': * => $ed25519_opts } end it 'finds the user #stdout' do - run_shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'user-w-ssl@localhost'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'user-w-ssl@localhost'\"") do |r| expect(r.stdout).to match(%r{^1$}) expect(r.stderr).to be_empty end end it 'shows correct ssl_type #stdout' do - run_shell("mysql -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'user-w-ssl@localhost'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'user-w-ssl@localhost'\"") do |r| expect(r.stdout).to match(%r{^ANY$}) expect(r.stderr).to be_empty end @@ -188,14 +189,14 @@ class { 'mysql::server': * => $ed25519_opts } end it 'finds the user #stdout' do - run_shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'user-w-x509@localhost'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'user-w-x509@localhost'\"") do |r| expect(r.stdout).to match(%r{^1$}) expect(r.stderr).to be_empty end end it 'shows correct ssl_type #stdout' do - run_shell("mysql -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'user-w-x509@localhost'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'user-w-x509@localhost'\"") do |r| expect(r.stdout).to match(%r{^X509$}) expect(r.stderr).to be_empty end @@ -219,35 +220,35 @@ class { 'mysql::server': * => $ed25519_opts } end it 'finds the user #stdout' do - run_shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'user-w-subject@localhost'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'user-w-subject@localhost'\"") do |r| expect(r.stdout).to match(%r{^1$}) expect(r.stderr).to be_empty end end it 'shows correct ssl_type #stdout' do - run_shell("mysql -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'user-w-subject@localhost'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'user-w-subject@localhost'\"") do |r| expect(r.stdout).to match(%r{^SPECIFIED$}) expect(r.stderr).to be_empty end end it 'shows correct x509_issuer #stdout' do - run_shell("mysql -NBe \"select X509_ISSUER from mysql.user where CONCAT(user, '@', host) = 'user-w-subject@localhost'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"select X509_ISSUER from mysql.user where CONCAT(user, '@', host) = 'user-w-subject@localhost'\"") do |r| expect(r.stdout).to match(%r{^/CN=Certificate Authority$}) expect(r.stderr).to be_empty end end it 'shows correct x509_subject #stdout' do - run_shell("mysql -NBe \"select X509_SUBJECT from mysql.user where CONCAT(user, '@', host) = 'user-w-subject@localhost'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"select X509_SUBJECT from mysql.user where CONCAT(user, '@', host) = 'user-w-subject@localhost'\"") do |r| expect(r.stdout).to match(%r{^/OU=MySQL Users/CN=username$}) expect(r.stderr).to be_empty end end it 'shows correct ssl_cipher #stdout' do - run_shell("mysql -NBe \"select SSL_CIPHER from mysql.user where CONCAT(user, '@', host) = 'user-w-subject@localhost'\"") do |r| + run_shell("#{mysql_cmd} -NBe \"select SSL_CIPHER from mysql.user where CONCAT(user, '@', host) = 'user-w-subject@localhost'\"") do |r| expect(r.stdout).to match(%r{^EDH-RSA-DES-CBC3-SHA$}) expect(r.stderr).to be_empty end diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index 33f6da341..cb41c5d98 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -44,6 +44,10 @@ def charset @charset ||= (debian_12? || ubuntu_2204? || sles_15?) ? 'utf8mb3' : 'utf8' end +def get_db_cmd + run_shell('mariadb -V', expect_failures: true).stdout.empty? ? 'mysql' : 'mariadb' +end + RSpec.configure do |c| c.before :suite do if os[:family] == 'debian' || os[:family] == 'ubuntu' 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