Skip to content

Commit 31d78c3

Browse files
author
tphoney
committed
add interpolation for ruby code
1 parent 0e7646c commit 31d78c3

File tree

8 files changed

+27
-19
lines changed

8 files changed

+27
-19
lines changed

lib/puppet/parser/functions/mysql_deepmerge.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ module Puppet::Parser::Functions
1919
ENDHEREDOC
2020

2121
if args.length < 2
22-
raise Puppet::ParseError, "mysql_deepmerge(): wrong number of arguments (#{args.length}; must be at least 2)"
22+
raise Puppet::ParseError, _('mysql_deepmerge(): wrong number of arguments (%{args_length}; must be at least 2)') % { args_length: args.length }
2323
end
2424

2525
result = {}
2626
args.each do |arg|
2727
next if arg.is_a?(String) && arg.empty? # empty string is synonym for puppet's undef
2828
# If the argument was not a hash, skip it.
2929
unless arg.is_a?(Hash)
30-
raise Puppet::ParseError, "mysql_deepmerge: unexpected argument type #{arg.class}, only expects hash arguments"
30+
raise Puppet::ParseError, _('mysql_deepmerge: unexpected argument type %{arg_class}, only expects hash arguments') % { args_class: args.class }
3131
end
3232

3333
# Now we have to traverse our hash assigning our non-hash values

lib/puppet/parser/functions/mysql_dirname.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ module Puppet::Parser::Functions
66
) do |arguments|
77

88
if arguments.empty?
9-
raise(Puppet::ParseError, 'mysql_dirname(): Wrong number of arguments ' \
10-
"given (#{arguments.size} for 1)")
9+
raise Puppet::ParseError, _('mysql_dirname(): Wrong number of arguments given (%{args_length} for 1)') % { args_length: args.length }
1110
end
1211

1312
path = arguments[0]
1413
return File.dirname(path)
1514
end
1615
end
17-
18-
# vim: set ts=2 sw=2 et :

lib/puppet/parser/functions/mysql_password.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ module Puppet::Parser::Functions
88
) do |args|
99

1010
if args.size != 1
11-
raise(Puppet::ParseError, 'mysql_password(): Wrong number of arguments ' \
12-
"given (#{args.size} for 1)")
11+
raise Puppet::ParseError, _('mysql_password(): Wrong number of arguments given (%{args_length} for 1)') % { args_length: args.length }
1312
end
1413

1514
return '' if args[0].empty?

lib/puppet/provider/mysql_datadir/mysql.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def create
2121
# rubocop:enable Lint/UselessAssignment
2222
unless defaults_extra_file.nil?
2323
unless File.exist?(defaults_extra_file)
24-
raise ArgumentError, "Defaults-extra-file #{defaults_extra_file} is missing"
24+
raise ArgumentError, _('Defaults-extra-file %{file} is missing') % { file: defaults_extra_file }
2525
end
2626
defaults_extra_file = "--defaults-extra-file=#{defaults_extra_file}"
2727
end

lib/puppet/provider/mysql_grant/mysql.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ def self.instances
1616
# of myhost.mydomain.my: [email protected], when MySQL is started
1717
# with --skip-name-resolve.
1818
next if e.inspect =~ %r{There is no such grant defined for user}
19-
raise Puppet::Error, "#mysql had an error -> #{e.inspect}"
19+
raise Puppet::Error, _('#mysql had an error -> %{inspect}') % { inspect: e.inspect }
2020
end
2121
# Once we have the list of grants generate entries for each.
2222
grants.each_line do |grant|
2323
# Match the munges we do in the type.
2424
munged_grant = grant.delete("'").delete('`').delete('"')
2525
# Matching: GRANT (SELECT, UPDATE) PRIVILEGES ON (*.*) TO ('root')@('127.0.0.1') (WITH GRANT OPTION)
26-
# rubocop:disable Lint/AssignmentInCondition
27-
next unless match = munged_grant.match(%r{^GRANT\s(.+)\sON\s(.+)\sTO\s(.*)@(.*?)(\s.*)?$})
28-
# rubocop:enable Lint/AssignmentInCondition
26+
next unless match = munged_grant.match(%r{^GRANT\s(.+)\sON\s(.+)\sTO\s(.*)@(.*?)(\s.*)?$}) # rubocop:disable Lint/AssignmentInCondition
2927
privileges, table, user, host, rest = match.captures
3028
table.gsub!('\\\\', '\\')
3129

lib/puppet/type/mysql_grant.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def initialize(*args)
5454
validate do |value|
5555
mysql_version = Facter.value(:mysql_version)
5656
if value =~ %r{proxy}i && Puppet::Util::Package.versioncmp(mysql_version, '5.5.0') < 0
57-
raise(ArgumentError, "PROXY user not supported on mysql versions < 5.5.0. Current version #{mysql_version}")
57+
raise(ArgumentError, _('PROXY user not supported on mysql versions < 5.5.0. Current version %{version}') % { version: mysql_version })
5858
end
5959
end
6060
end
@@ -93,7 +93,7 @@ def initialize(*args)
9393
user_part = matches[1]
9494
host_part = matches[2]
9595
else
96-
raise(ArgumentError, "Invalid database user #{value}")
96+
raise(ArgumentError, _('Invalid database user %{user}') % { user: value })
9797
end
9898
# rubocop:enable Lint/AssignmentInCondition
9999
# rubocop:enable Lint/UselessAssignment

lib/puppet/type/mysql_user.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
user_part = matches[1]
2727
host_part = matches[2]
2828
else
29-
raise(ArgumentError, "Invalid database user #{value}")
29+
raise ArgumentError, _('Invalid database user %{user}') % { user: value }
3030
end
3131
# rubocop:enable Lint/AssignmentInCondition
3232
# rubocop:enable Lint/UselessAssignment
@@ -84,7 +84,7 @@
8484
else
8585
value.each do |opt|
8686
o = opt.match(%r{^(CIPHER|ISSUER|SUBJECT)}i)
87-
raise(ArgumentError, "Invalid tls option #{o}") unless o
87+
raise(ArgumentError, _('Invalid tls option %{option}') % { option: o }) unless o
8888
end
8989
end
9090
end

spec/acceptance/locales_spec.rb

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper_acceptance'
22
require 'beaker/i18n_helper'
33

4-
describe 'mysql localization', unless: fact('operatingsystem') == 'Debian' do
4+
describe 'mysql localization', if: fact('osfamily') == 'Debian' do
55
before :all do
66
hosts.each do |host|
77
on(host, "sed -i \"96i FastGettext.locale='ja'\" /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet.rb")
@@ -37,7 +37,7 @@ class { 'mysql::server':
3737
end
3838
end
3939

40-
context 'when triggering ruby string warning' do
40+
context 'when triggering ruby simple string warning' do
4141
let(:pp) do
4242
<<-EOS
4343
mysql::db { 'mydb':
@@ -57,6 +57,20 @@ class { 'mysql::server':
5757
end
5858
end
5959

60+
context 'when triggering ruby interpolated string warning' do
61+
let(:pp) do
62+
<<-EOS
63+
$password_hash = mysql_password('new_password', 'should not have second parameter')
64+
EOS
65+
end
66+
67+
it 'displays Japanese error' do
68+
apply_manifest(pp, expect_failures: true) do |r|
69+
expect(r.stderr).not_to match(%r{mysql_password(): Wrong number of arguments given (2 for 1)}i)
70+
end
71+
end
72+
end
73+
6074
after :all do
6175
hosts.each do |host|
6276
on(host, 'sed -i "96d" /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet.rb')

0 commit comments

Comments
 (0)