Skip to content

Commit 9419870

Browse files
authored
Merge pull request #1003 from puppetlabs/i18nTesting
merge i18nTesting to master
2 parents f32f2e3 + 1498842 commit 9419870

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1449
-989
lines changed

.fixtures.yml

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ fixtures:
22
repositories:
33
"stdlib": "https://github.com/puppetlabs/puppetlabs-stdlib"
44
"staging": "https://github.com/voxpupuli/puppet-staging"
5+
"translate": "https://github.com/puppetlabs/puppetlabs-translate"
56
symlinks:
67
"mysql": "#{source_dir}"

.rubocop.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
2-
require: rubocop-rspec
2+
require:
3+
- rubocop-rspec
4+
- rubocop-i18n
35
AllCops:
46
TargetRubyVersion: '2.1'
57
Include:
@@ -12,6 +14,7 @@ AllCops:
1214
- pkg/**/*
1315
- spec/fixtures/**/*
1416
- vendor/**/*
17+
inherit_from: .rubocop_todo.yml
1518
Metrics/LineLength:
1619
Description: People have wide screens, use them.
1720
Max: 200
@@ -94,3 +97,7 @@ Style/IfUnlessModifier:
9497
Enabled: false
9598
Style/SymbolProc:
9699
Enabled: false
100+
GetText/DecorateString:
101+
Enabled: false
102+
GetText/DecorateFunctionMessage:
103+
Enabled: true

.rubocop_todo.yml

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2017-09-04 11:31:12 +0100 using RuboCop version 0.49.1.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 2
10+
# Cop supports --auto-correct.
11+
# Configuration parameters: EnforcedStyle, SupportedStyles.
12+
# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
13+
Layout/IndentHeredoc:
14+
Exclude:
15+
- 'spec/unit/puppet/provider/mysql_database/mysql_spec.rb'
16+
- 'spec/unit/puppet/provider/mysql_user/mysql_spec.rb'
17+
18+
# Offense count: 1
19+
Lint/AmbiguousRegexpLiteral:
20+
Exclude:
21+
- 'spec/unit/puppet/type/mysql_grant_spec.rb'
22+
23+
# Offense count: 1
24+
Lint/DuplicatedKey:
25+
Exclude:
26+
- 'spec/classes/mysql_server_backup_spec.rb'
27+
28+
# Offense count: 1
29+
Lint/HandleExceptions:
30+
Exclude:
31+
- 'spec/spec_helper.rb'
32+
33+
# Offense count: 1
34+
Lint/ScriptPermission:
35+
Exclude:
36+
- 'spec/unit/puppet/functions/mysql_deepmerge_spec.rb'
37+
38+
# Offense count: 1
39+
Lint/UselessAssignment:
40+
Exclude:
41+
- 'spec/unit/puppet/functions/mysql_deepmerge_spec.rb'
42+
43+
# Offense count: 11
44+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
45+
# URISchemes: http, https
46+
Metrics/LineLength:
47+
Max: 351
48+
49+
# Offense count: 1
50+
RSpec/BeforeAfterAll:
51+
Exclude:
52+
- 'spec/acceptance/**/*.rb'
53+
- 'spec/unit/puppet/functions/mysql_password_spec.rb'
54+
55+
# Offense count: 56
56+
# Configuration parameters: Max.
57+
RSpec/ExampleLength:
58+
Exclude:
59+
- 'spec/acceptance/mysql_backup_spec.rb'
60+
- 'spec/acceptance/types/mysql_database_spec.rb'
61+
- 'spec/acceptance/types/mysql_grant_spec.rb'
62+
- 'spec/acceptance/types/mysql_plugin_spec.rb'
63+
- 'spec/acceptance/types/mysql_user_spec.rb'
64+
- 'spec/classes/mysql_server_backup_spec.rb'
65+
- 'spec/classes/mysql_server_monitor_spec.rb'
66+
- 'spec/classes/mysql_server_spec.rb'
67+
- 'spec/unit/puppet/provider/mysql_database/mysql_spec.rb'
68+
- 'spec/unit/puppet/provider/mysql_user/mysql_spec.rb'
69+
- 'spec/unit/puppet/type/mysql_grant_spec.rb'
70+
71+
# Offense count: 3
72+
# Configuration parameters: CustomTransform, IgnoreMethods.
73+
RSpec/FilePath:
74+
Exclude:
75+
- 'spec/unit/facter/mysql_server_id_spec.rb'
76+
- 'spec/unit/facter/mysql_version_spec.rb'
77+
- 'spec/unit/facter/mysqld_version_spec.rb'
78+
79+
# Offense count: 41
80+
# Configuration parameters: AssignmentOnly.
81+
RSpec/InstanceVariable:
82+
Exclude:
83+
- 'spec/acceptance/mysql_server_spec.rb'
84+
- 'spec/unit/puppet/type/mysql_database_spec.rb'
85+
- 'spec/unit/puppet/type/mysql_grant_spec.rb'
86+
- 'spec/unit/puppet/type/mysql_plugin_spec.rb'
87+
- 'spec/unit/puppet/type/mysql_user_spec.rb'
88+
89+
# Offense count: 38
90+
RSpec/MultipleExpectations:
91+
Max: 4
92+
93+
# Offense count: 42
94+
# Configuration parameters: Max.
95+
RSpec/NestedGroups:
96+
Exclude:
97+
- 'spec/acceptance/mysql_backup_spec.rb'
98+
- 'spec/classes/mycnf_template_spec.rb'
99+
- 'spec/classes/mysql_server_backup_spec.rb'
100+
- 'spec/classes/mysql_server_spec.rb'
101+
102+
# Offense count: 2
103+
RSpec/RepeatedExample:
104+
Exclude:
105+
- 'spec/classes/mysql_server_account_security_spec.rb'
106+
107+
# Offense count: 3
108+
RSpec/ScatteredLet:
109+
Exclude:
110+
- 'spec/unit/puppet/provider/mysql_database/mysql_spec.rb'
111+
- 'spec/unit/puppet/provider/mysql_plugin/mysql_spec.rb'
112+
- 'spec/unit/puppet/provider/mysql_user/mysql_spec.rb'
113+
114+
# Offense count: 7
115+
# Cop supports --auto-correct.
116+
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
117+
# SupportedStyles: slashes, percent_r, mixed
118+
Style/RegexpLiteral:
119+
Exclude:
120+
- 'spec/acceptance/types/mysql_grant_spec.rb'
121+
- 'spec/classes/mycnf_template_spec.rb'
122+
- 'spec/classes/mysql_server_backup_spec.rb'
123+
- 'spec/unit/puppet/type/mysql_grant_spec.rb'

.sync.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ spec/spec_helper.rb:
66
.travis.yml:
77
extras:
88
- rvm: 2.1.9
9-
bundler_args: --without system_tests
10-
script: bundle exec rubocop lib
9+
script: bundle exec rake rubocop

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ matrix:
2929
bundler_args: --without system_tests
3030
env: PUPPET_GEM_VERSION="~> 4.0"
3131
- rvm: 2.1.9
32-
bundler_args: --without system_tests
3332
script: bundle exec rubocop lib
3433
notifications:
3534
email: false

Gemfile

+7-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ end
3131
supports_windows = false
3232
ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments
3333
minor_version = "#{ruby_version_segments[0]}.#{ruby_version_segments[1]}"
34-
3534
group :development do
3635
gem "puppet-module-posix-default-r#{minor_version}", :require => false, :platforms => "ruby"
3736
gem "puppet-module-win-default-r#{minor_version}", :require => false, :platforms => ["mswin", "mingw", "x64_mingw"]
@@ -45,12 +44,16 @@ end
4544
group :system_tests do
4645
gem "puppet-module-posix-system-r#{minor_version}", :require => false, :platforms => "ruby"
4746
gem "puppet-module-win-system-r#{minor_version}", :require => false, :platforms => ["mswin", "mingw", "x64_mingw"]
48-
gem "beaker", *location_for(ENV['BEAKER_VERSION'] || '>= 3')
47+
gem "beaker", *location_for(ENV['BEAKER_VERSION'] || '>= 3')
4948
gem "beaker-pe", :require => false
50-
gem "beaker-rspec", *location_for(ENV['BEAKER_RSPEC_VERSION'])
49+
gem "beaker-rspec", *location_for(ENV['BEAKER_RSPEC_VERSION'])
5150
gem "beaker-hostgenerator", *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION'])
52-
gem "beaker-abs", *location_for(ENV['BEAKER_ABS_VERSION'] || '~> 0.1')
51+
gem "beaker-abs", *location_for(ENV['BEAKER_ABS_VERSION'] || '~> 0.1')
5352
gem "puppet-blacksmith", '~> 3.4', :require => false
53+
gem "puppet-lint-i18n"
54+
gem "puppet_pot_generator"
55+
gem "rubocop-i18n", '~> 1.0'
56+
gem "beaker-i18n_helper"
5457
end
5558

5659
gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION'])

Rakefile

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'puppetlabs_spec_helper/rake_tasks'
22
require 'puppet-lint/tasks/puppet-lint'
3+
require 'puppet_pot_generator/rake_tasks' if Bundler.rubygems.find_name('puppet_pot_generator').any?
34
require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any?
45

56
PuppetLint.configuration.fail_on_warnings = true

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/parser/functions/mysql_strip_hash.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Puppet::Parser::Functions
88

99
hash = args[0]
1010
unless hash.is_a?(Hash)
11-
raise(Puppet::ParseError, 'mysql_strip_hash(): Requires hash to work with')
11+
raise(Puppet::ParseError, _('mysql_strip_hash(): Requires a hash to work.'))
1212
end
1313

1414
# Filter out all the top level blanks.

lib/puppet/provider/mysql_datadir/mysql.rb

+2-2
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
@@ -56,7 +56,7 @@ def create
5656

5757
def destroy
5858
name = @resource[:name] # rubocop:disable Lint/UselessAssignment
59-
raise ArgumentError, 'ERROR: Resource can not be removed'
59+
raise ArgumentError, _('ERROR: `Resource` can not be removed.')
6060
end
6161

6262
def exists?

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/provider/mysql_user/mysql.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def password_hash=(string)
122122
# default ... if mysqld_version does not work
123123
mysql([defaults_file, system_database, '-e', "SET PASSWORD FOR #{merged_name} = '#{string}'"].compact)
124124
elsif (mysqld_type == 'mysql' || mysqld_type == 'percona') && Puppet::Util::Package.versioncmp(mysqld_version, '5.7.6') >= 0
125-
raise ArgumentError, 'Only mysql_native_password (*ABCD...XXX) hashes are supported' unless string =~ %r{^\*}
125+
raise ArgumentError, _('Only mysql_native_password (*ABCD...XXX) hashes are supported.') unless string =~ %r{^\*}
126126
mysql([defaults_file, system_database, '-e', "ALTER USER #{merged_name} IDENTIFIED WITH mysql_native_password AS '#{string}'"].compact)
127127
else
128128
mysql([defaults_file, system_database, '-e', "SET PASSWORD FOR #{merged_name} = '#{string}'"].compact)

lib/puppet/type/mysql_grant.rb

+13-11
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ def initialize(*args)
3131
end
3232
# rubocop:enable Style/MultilineBlockChain
3333
validate do
34-
raise('privileges parameter is required.') if self[:ensure] == :present && self[:privileges].nil?
35-
raise('PROXY must be the only privilege specified.') if Array(self[:privileges]).count > 1 && Array(self[:privileges]).include?('PROXY')
36-
raise('table parameter is required.') if self[:ensure] == :present && self[:table].nil?
37-
raise('user parameter is required.') if self[:ensure] == :present && self[:user].nil?
34+
raise(_('`privileges` `parameter` is required.')) if self[:ensure] == :present && self[:privileges].nil?
35+
raise(_('`privileges` `parameter`: PROXY can only be specified by itself.')) if Array(self[:privileges]).count > 1 && Array(self[:privileges]).include?('PROXY')
36+
raise(_('`table` `parameter` is required.')) if self[:ensure] == :present && self[:table].nil?
37+
raise(_('`user` `parameter` is required.')) if self[:ensure] == :present && self[:user].nil?
3838
if self[:user] && self[:table]
39-
raise('name must match user@host/table format') if self[:name] != "#{self[:user]}/#{self[:table]}"
39+
raise(_('`name` `parameter` must match user@host/table format.')) if self[:name] != "#{self[:user]}/#{self[:table]}"
4040
end
4141
end
4242

@@ -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
@@ -63,7 +63,9 @@ def initialize(*args)
6363
desc 'Table to apply privileges to.'
6464

6565
validate do |value|
66-
raise(ArgumentError, '"table" for PROXY should be specified as proxy_user@proxy_host') if Array(@resource[:privileges]).include?('PROXY') && !%r{^[0-9a-zA-Z$_]*@[\w%\.:\-/]*$}.match(value)
66+
if Array(@resource[:privileges]).include?('PROXY') && !%r{^[0-9a-zA-Z$_]*@[\w%\.:\-\/]*$}.match(value)
67+
raise(ArgumentError, _('`table` `property` for PROXY should be specified as proxy_user@proxy_host.'))
68+
end
6769
end
6870

6971
munge do |value|
@@ -91,15 +93,15 @@ def initialize(*args)
9193
user_part = matches[1]
9294
host_part = matches[2]
9395
else
94-
raise(ArgumentError, "Invalid database user #{value}")
96+
raise(ArgumentError, _('Invalid database user %{user}.') % { user: value })
9597
end
9698
# rubocop:enable Lint/AssignmentInCondition
9799
# rubocop:enable Lint/UselessAssignment
98100
mysql_version = Facter.value(:mysql_version)
99101
unless mysql_version.nil?
100-
raise(ArgumentError, 'MySQL usernames are limited to a maximum of 16 characters') if Puppet::Util::Package.versioncmp(mysql_version, '5.7.8') < 0 && user_part.size > 16
101-
raise(ArgumentError, 'MySQL usernames are limited to a maximum of 32 characters') if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') < 0 && user_part.size > 32
102-
raise(ArgumentError, 'MySQL usernames are limited to a maximum of 80 characters') if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') > 0 && user_part.size > 80
102+
raise(ArgumentError, _('MySQL usernames are limited to a maximum of 16 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '5.7.8') < 0 && user_part.size > 16
103+
raise(ArgumentError, _('MySQL usernames are limited to a maximum of 32 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') < 0 && user_part.size > 32
104+
raise(ArgumentError, _('MySQL usernames are limited to a maximum of 80 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') > 0 && user_part.size > 80
103105
end
104106
end
105107

lib/puppet/type/mysql_user.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
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
3333
unless mysql_version.nil?
34-
raise(ArgumentError, 'MySQL usernames are limited to a maximum of 16 characters') if Puppet::Util::Package.versioncmp(mysql_version, '5.7.8') < 0 && user_part.size > 16
35-
raise(ArgumentError, 'MySQL usernames are limited to a maximum of 32 characters') if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') < 0 && user_part.size > 32
36-
raise(ArgumentError, 'MySQL usernames are limited to a maximum of 80 characters') if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') > 0 && user_part.size > 80
34+
raise(ArgumentError, _('MySQL usernames are limited to a maximum of 16 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '5.7.8') < 0 && user_part.size > 16
35+
raise(ArgumentError, _('MySQL usernames are limited to a maximum of 32 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') < 0 && user_part.size > 32
36+
raise(ArgumentError, _('MySQL usernames are limited to a maximum of 80 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') > 0 && user_part.size > 80
3737
end
3838
end
3939

@@ -79,12 +79,12 @@
7979
value = [value] unless value.is_a?(Array)
8080
if value.include?('NONE') || value.include?('SSL') || value.include?('X509')
8181
if value.length > 1
82-
raise(ArgumentError, 'REQUIRE tls options NONE, SSL and X509 cannot be used with other options, you may only use one of them.')
82+
raise(ArgumentError, _('`tls_options` `property`: The values NONE, SSL and X509 cannot be used with other options, you may only pick one of them.'))
8383
end
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

0 commit comments

Comments
 (0)