Skip to content

Commit 780e0ac

Browse files
authored
Merge pull request #1712 from puppetlabs/MODULES-11802
(MODULES-11802) Add support for RHEL 10
2 parents 3347ec2 + 349169c commit 780e0ac

3 files changed

Lines changed: 58 additions & 1 deletion

File tree

lib/puppet/type/mysql_database.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,33 @@
1414
desc 'The name of the MySQL database to manage.'
1515
end
1616

17+
# `utf8` is a deprecated alias for `utf8mb3` in both MySQL and MariaDB. Newer
18+
# servers (e.g. MariaDB 11 on RHEL 10) report the canonical `utf8mb3` name back,
19+
# while users typically request `utf8`. Treat the two spellings as equivalent so
20+
# the resource stays idempotent regardless of which the server reports. Charset
21+
# and collation names are case-insensitive and the server reports them
22+
# lowercased, so downcase first to also match user input such as `UTF8`.
23+
def self.normalise_utf8(value)
24+
value.to_s.downcase.sub(%r{^utf8mb3}, 'utf8')
25+
end
26+
1727
newproperty(:charset) do
1828
desc 'The CHARACTER SET setting for the database'
1929
defaultto :utf8
2030
newvalue(%r{^\S+$})
31+
32+
def insync?(is)
33+
resource.class.normalise_utf8(is) == resource.class.normalise_utf8(should)
34+
end
2135
end
2236

2337
newproperty(:collate) do
2438
desc 'The COLLATE setting for the database'
2539
defaultto :utf8_general_ci
2640
newvalue(%r{^\S+$})
41+
42+
def insync?(is)
43+
resource.class.normalise_utf8(is) == resource.class.normalise_utf8(should)
44+
end
2745
end
2846
end

metadata.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"operatingsystemrelease": [
2020
"7",
2121
"8",
22-
"9"
22+
"9",
23+
"10"
2324
]
2425
},
2526
{

spec/unit/puppet/type/mysql_database_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,42 @@
2424
Puppet::Type.type(:mysql_database).new({})
2525
}.to raise_error(Puppet::Error, 'Title or name must be provided')
2626
end
27+
28+
describe 'utf8/utf8mb3 alias equivalence' do
29+
# MariaDB 11 (RHEL 10) reports the canonical `utf8mb3`, users request `utf8`.
30+
it 'treats charset utf8 and utf8mb3 as in sync' do
31+
resource = Puppet::Type.type(:mysql_database).new(name: 'test', charset: 'utf8')
32+
expect(resource.property(:charset).insync?('utf8mb3')).to be true
33+
end
34+
35+
it 'treats charset utf8mb3 and utf8 as in sync' do
36+
resource = Puppet::Type.type(:mysql_database).new(name: 'test', charset: 'utf8mb3')
37+
expect(resource.property(:charset).insync?('utf8')).to be true
38+
end
39+
40+
it 'treats collate utf8_general_ci and utf8mb3_general_ci as in sync' do
41+
resource = Puppet::Type.type(:mysql_database).new(name: 'test', collate: 'utf8_general_ci')
42+
expect(resource.property(:collate).insync?('utf8mb3_general_ci')).to be true
43+
end
44+
45+
it 'still reports drift for a genuinely different charset' do
46+
resource = Puppet::Type.type(:mysql_database).new(name: 'test', charset: 'utf8')
47+
expect(resource.property(:charset).insync?('utf8mb4')).to be false
48+
end
49+
50+
it 'still reports drift for a genuinely different collate' do
51+
resource = Puppet::Type.type(:mysql_database).new(name: 'test', collate: 'utf8_general_ci')
52+
expect(resource.property(:collate).insync?('latin1_swedish_ci')).to be false
53+
end
54+
55+
it 'treats uppercase charset input as in sync with the lowercase server value' do
56+
resource = Puppet::Type.type(:mysql_database).new(name: 'test', charset: 'UTF8')
57+
expect(resource.property(:charset).insync?('utf8mb3')).to be true
58+
end
59+
60+
it 'treats uppercase collate input as in sync with the lowercase server value' do
61+
resource = Puppet::Type.type(:mysql_database).new(name: 'test', collate: 'UTF8_GENERAL_CI')
62+
expect(resource.property(:collate).insync?('utf8mb3_general_ci')).to be true
63+
end
64+
end
2765
end

0 commit comments

Comments
 (0)