Skip to content

Commit

Permalink
Merge pull request #983 from tphoney/ready_for_others
Browse files Browse the repository at this point in the history
interpolation for ruby & puppet code.
  • Loading branch information
Helen committed Sep 4, 2017
2 parents 300ce88 + fa60d9a commit bcf8e1f
Show file tree
Hide file tree
Showing 22 changed files with 179 additions and 47 deletions.
1 change: 1 addition & 0 deletions .fixtures.yml
Expand Up @@ -2,5 +2,6 @@ fixtures:
repositories:
"stdlib": "https://github.com/puppetlabs/puppetlabs-stdlib"
"staging": "https://github.com/voxpupuli/puppet-staging"
"translate": "https://github.com/puppetlabs/puppetlabs-translate"
symlinks:
"mysql": "#{source_dir}"
1 change: 1 addition & 0 deletions .rubocop.yml
Expand Up @@ -14,6 +14,7 @@ AllCops:
- pkg/**/*
- spec/fixtures/**/*
- vendor/**/*
inherit_from: .rubocop_todo.yml
Metrics/LineLength:
Description: People have wide screens, use them.
Max: 200
Expand Down
123 changes: 123 additions & 0 deletions .rubocop_todo.yml
@@ -0,0 +1,123 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-09-04 11:31:12 +0100 using RuboCop version 0.49.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
Layout/IndentHeredoc:
Exclude:
- 'spec/unit/puppet/provider/mysql_database/mysql_spec.rb'
- 'spec/unit/puppet/provider/mysql_user/mysql_spec.rb'

# Offense count: 1
Lint/AmbiguousRegexpLiteral:
Exclude:
- 'spec/unit/puppet/type/mysql_grant_spec.rb'

# Offense count: 1
Lint/DuplicatedKey:
Exclude:
- 'spec/classes/mysql_server_backup_spec.rb'

# Offense count: 1
Lint/HandleExceptions:
Exclude:
- 'spec/spec_helper.rb'

# Offense count: 1
Lint/ScriptPermission:
Exclude:
- 'spec/unit/puppet/functions/mysql_deepmerge_spec.rb'

# Offense count: 1
Lint/UselessAssignment:
Exclude:
- 'spec/unit/puppet/functions/mysql_deepmerge_spec.rb'

# Offense count: 11
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 351

# Offense count: 1
RSpec/BeforeAfterAll:
Exclude:
- 'spec/acceptance/**/*.rb'
- 'spec/unit/puppet/functions/mysql_password_spec.rb'

# Offense count: 56
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
- 'spec/acceptance/mysql_backup_spec.rb'
- 'spec/acceptance/types/mysql_database_spec.rb'
- 'spec/acceptance/types/mysql_grant_spec.rb'
- 'spec/acceptance/types/mysql_plugin_spec.rb'
- 'spec/acceptance/types/mysql_user_spec.rb'
- 'spec/classes/mysql_server_backup_spec.rb'
- 'spec/classes/mysql_server_monitor_spec.rb'
- 'spec/classes/mysql_server_spec.rb'
- 'spec/unit/puppet/provider/mysql_database/mysql_spec.rb'
- 'spec/unit/puppet/provider/mysql_user/mysql_spec.rb'
- 'spec/unit/puppet/type/mysql_grant_spec.rb'

# Offense count: 3
# Configuration parameters: CustomTransform, IgnoreMethods.
RSpec/FilePath:
Exclude:
- 'spec/unit/facter/mysql_server_id_spec.rb'
- 'spec/unit/facter/mysql_version_spec.rb'
- 'spec/unit/facter/mysqld_version_spec.rb'

# Offense count: 41
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
Exclude:
- 'spec/acceptance/mysql_server_spec.rb'
- 'spec/unit/puppet/type/mysql_database_spec.rb'
- 'spec/unit/puppet/type/mysql_grant_spec.rb'
- 'spec/unit/puppet/type/mysql_plugin_spec.rb'
- 'spec/unit/puppet/type/mysql_user_spec.rb'

# Offense count: 38
RSpec/MultipleExpectations:
Max: 4

# Offense count: 42
# Configuration parameters: Max.
RSpec/NestedGroups:
Exclude:
- 'spec/acceptance/mysql_backup_spec.rb'
- 'spec/classes/mycnf_template_spec.rb'
- 'spec/classes/mysql_server_backup_spec.rb'
- 'spec/classes/mysql_server_spec.rb'

# Offense count: 2
RSpec/RepeatedExample:
Exclude:
- 'spec/classes/mysql_server_account_security_spec.rb'

# Offense count: 3
RSpec/ScatteredLet:
Exclude:
- 'spec/unit/puppet/provider/mysql_database/mysql_spec.rb'
- 'spec/unit/puppet/provider/mysql_plugin/mysql_spec.rb'
- 'spec/unit/puppet/provider/mysql_user/mysql_spec.rb'

# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Exclude:
- 'spec/acceptance/types/mysql_grant_spec.rb'
- 'spec/classes/mycnf_template_spec.rb'
- 'spec/classes/mysql_server_backup_spec.rb'
- 'spec/unit/puppet/type/mysql_grant_spec.rb'
2 changes: 1 addition & 1 deletion .sync.yml
Expand Up @@ -7,4 +7,4 @@ spec/spec_helper.rb:
extras:
- rvm: 2.1.9
bundler_args: --without system_tests
script: bundle exec rubocop lib
script: bundle exec rake rubocop
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -30,6 +30,6 @@ matrix:
env: PUPPET_GEM_VERSION="~> 4.0"
- rvm: 2.1.9
bundler_args: --without system_tests
script: bundle exec rubocop lib
script: bundle exec rake rubocop
notifications:
email: false
4 changes: 2 additions & 2 deletions lib/puppet/parser/functions/mysql_deepmerge.rb
Expand Up @@ -19,15 +19,15 @@ module Puppet::Parser::Functions
ENDHEREDOC

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

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

# Now we have to traverse our hash assigning our non-hash values
Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/mysql_dirname.rb
Expand Up @@ -6,13 +6,10 @@ module Puppet::Parser::Functions
) do |arguments|

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

path = arguments[0]
return File.dirname(path)
end
end

# vim: set ts=2 sw=2 et :
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/mysql_password.rb
Expand Up @@ -8,8 +8,7 @@ module Puppet::Parser::Functions
) do |args|

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

return '' if args[0].empty?
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/mysql_datadir/mysql.rb
Expand Up @@ -21,7 +21,7 @@ def create
# rubocop:enable Lint/UselessAssignment
unless defaults_extra_file.nil?
unless File.exist?(defaults_extra_file)
raise ArgumentError, "Defaults-extra-file #{defaults_extra_file} is missing"
raise ArgumentError, _('Defaults-extra-file %{file} is missing') % { file: defaults_extra_file }
end
defaults_extra_file = "--defaults-extra-file=#{defaults_extra_file}"
end
Expand Down
6 changes: 2 additions & 4 deletions lib/puppet/provider/mysql_grant/mysql.rb
Expand Up @@ -16,16 +16,14 @@ def self.instances
# of myhost.mydomain.my: root@myhost.mydomain.my, when MySQL is started
# with --skip-name-resolve.
next if e.inspect =~ %r{There is no such grant defined for user}
raise Puppet::Error, "#mysql had an error -> #{e.inspect}"
raise Puppet::Error, _('#mysql had an error -> %{inspect}') % { inspect: e.inspect }
end
# Once we have the list of grants generate entries for each.
grants.each_line do |grant|
# Match the munges we do in the type.
munged_grant = grant.delete("'").delete('`').delete('"')
# Matching: GRANT (SELECT, UPDATE) PRIVILEGES ON (*.*) TO ('root')@('127.0.0.1') (WITH GRANT OPTION)
# rubocop:disable Lint/AssignmentInCondition
next unless match = munged_grant.match(%r{^GRANT\s(.+)\sON\s(.+)\sTO\s(.*)@(.*?)(\s.*)?$})
# rubocop:enable Lint/AssignmentInCondition
next unless match = munged_grant.match(%r{^GRANT\s(.+)\sON\s(.+)\sTO\s(.*)@(.*?)(\s.*)?$}) # rubocop:disable Lint/AssignmentInCondition
privileges, table, user, host, rest = match.captures
table.gsub!('\\\\', '\\')

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/mysql_grant.rb
Expand Up @@ -54,7 +54,7 @@ def initialize(*args)
validate do |value|
mysql_version = Facter.value(:mysql_version)
if value =~ %r{proxy}i && Puppet::Util::Package.versioncmp(mysql_version, '5.5.0') < 0
raise(ArgumentError, "PROXY user not supported on mysql versions < 5.5.0. Current version #{mysql_version}")
raise(ArgumentError, _('PROXY user not supported on mysql versions < 5.5.0. Current version %{version}') % { version: mysql_version })
end
end
end
Expand Down Expand Up @@ -93,7 +93,7 @@ def initialize(*args)
user_part = matches[1]
host_part = matches[2]
else
raise(ArgumentError, "Invalid database user #{value}")
raise(ArgumentError, _('Invalid database user %{user}') % { user: value })
end
# rubocop:enable Lint/AssignmentInCondition
# rubocop:enable Lint/UselessAssignment
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/mysql_user.rb
Expand Up @@ -26,7 +26,7 @@
user_part = matches[1]
host_part = matches[2]
else
raise(ArgumentError, "Invalid database user #{value}")
raise ArgumentError, _('Invalid database user %{user}') % { user: value }
end
# rubocop:enable Lint/AssignmentInCondition
# rubocop:enable Lint/UselessAssignment
Expand Down Expand Up @@ -84,7 +84,7 @@
else
value.each do |opt|
o = opt.match(%r{^(CIPHER|ISSUER|SUBJECT)}i)
raise(ArgumentError, "Invalid tls option #{o}") unless o
raise(ArgumentError, _('Invalid tls option %{option}') % { option: o }) unless o
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions manifests/bindings.pp
Expand Up @@ -35,11 +35,11 @@

case $::osfamily {
'Archlinux': {
if $java_enable { fail("::mysql::bindings::java cannot be managed by puppet on ${::osfamily} as it is not in official repositories. Please disable java mysql binding.") }
if $java_enable { fail(translate("::mysql::bindings::java cannot be managed by puppet on ${::osfamily} as it is not in official repositories. Please disable java mysql binding.")) }
if $perl_enable { include '::mysql::bindings::perl' }
if $php_enable { warning("::mysql::bindings::php does not need to be managed by puppet on ${::osfamily} as it is included in mysql package by default.") }
if $php_enable { warning(translate("::mysql::bindings::php does not need to be managed by puppet on ${::osfamily} as it is included in mysql package by default.")) }
if $python_enable { include '::mysql::bindings::python' }
if $ruby_enable { fail("::mysql::bindings::ruby cannot be managed by puppet on ${::osfamily} as it is not in official repositories. Please disable ruby mysql binding.") }
if $ruby_enable { fail(translate("::mysql::bindings::ruby cannot be managed by puppet on ${::osfamily} as it is not in official repositories. Please disable ruby mysql binding.")) }
}

default: {
Expand Down
2 changes: 1 addition & 1 deletion manifests/bindings/client_dev.pp
Expand Up @@ -9,7 +9,7 @@
provider => $mysql::bindings::client_dev_package_provider,
}
} else {
warning("No MySQL client development package configured for ${::operatingsystem}.")
warning(translate("No MySQL client development package configured for ${::operatingsystem}."))
}

}
2 changes: 1 addition & 1 deletion manifests/bindings/daemon_dev.pp
Expand Up @@ -9,7 +9,7 @@
provider => $mysql::bindings::daemon_dev_package_provider,
}
} else {
warning("No MySQL daemon development package configured for ${::operatingsystem}.")
warning(translate("No MySQL daemon development package configured for ${::operatingsystem}."))
}

}
6 changes: 3 additions & 3 deletions manifests/params.pp
Expand Up @@ -121,7 +121,7 @@
}
}
default: {
fail("Unsupported platform: puppetlabs-${module_name} currently doesn't support ${::operatingsystem}")
fail(translate("Unsupported platform: puppetlabs-${module_name} currently doesn't support ${::operatingsystem}"))
}
}
$config_file = '/etc/my.cnf'
Expand Down Expand Up @@ -378,7 +378,7 @@
}

default: {
fail("Unsupported platform: puppetlabs-${module_name} currently doesn't support ${::osfamily} or ${::operatingsystem}")
fail(translate("Unsupported platform: puppetlabs-${module_name} currently doesn't support ${::osfamily} or ${::operatingsystem}"))
}
}
}
Expand Down Expand Up @@ -462,6 +462,6 @@

## Additional graceful failures
if $::osfamily == 'RedHat' and $::operatingsystemmajrelease == '4' and $::operatingsystem != 'Amazon' {
fail("Unsupported platform: puppetlabs-${module_name} only supports RedHat 5.0 and beyond")
fail(translate("Unsupported platform: puppetlabs-${module_name} only supports RedHat 5.0 and beyond"))
}
}
2 changes: 1 addition & 1 deletion manifests/server/backup.pp
Expand Up @@ -25,7 +25,7 @@
) {

if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ {
warning("The \$prescript option is not currently implemented for the ${provider} backup provider.")
warning(translate("The \$prescript option is not currently implemented for the ${provider} backup provider."))
}

create_resources('class', {
Expand Down
25 changes: 19 additions & 6 deletions spec/acceptance/locales_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper_acceptance'
require 'beaker/i18n_helper'

describe 'mysql localization', unless: fact('operatingsystem') == 'Debian' do
describe 'mysql localization', if: fact('osfamily') == 'Debian' do
before :all do
hosts.each do |host|
on(host, "sed -i \"96i FastGettext.locale='ja'\" /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet.rb")
Expand Down Expand Up @@ -30,14 +30,13 @@ class { 'mysql::server':
end

it 'displays Japanese error' do
pending('waiting on japanese translation in the po file')
apply_manifest(pp, catch_error: true) do |r|
expect(r.stderr).not_to match(%r{The `old_root_password` attribute is no longer used and will be removed}i)
expect(r.stderr).to match(%r{`old_root_password`属性は廃止予定であり、今後のリリースで廃止されます。}i)
end
end
end

context 'when triggering ruby string warning' do
context 'when triggering ruby simple string warning' do
let(:pp) do
<<-EOS
mysql::db { 'mydb':
Expand All @@ -50,9 +49,23 @@ class { 'mysql::server':
end

it 'displays Japanese error' do
pending('waiting on japanese translation in the po file')
apply_manifest(pp, expect_failures: true) do |r|
expect(r.stderr).not_to match(%r{MySQL usernames are limited to a maximum of 16 characters.}i)
expect(r.stderr).to match(%r{MySQLユーザ名は最大16文字に制限されています。}i)
end
end
end

context 'when triggering ruby interpolated string warning' do
let(:pp) do
<<-EOS
$password_hash = mysql_password('new_password', 'should not have second parameter')
EOS
end

it 'displays Japanese error' do
pending 'waiting on japanese translation in the po file'
apply_manifest(pp, catch_error: true) do |r|
expect(r.stderr).not_to match(%r{mysql_password(): Wrong number of arguments given (2 for 1)}i)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/graceful_failures_spec.rb
Expand Up @@ -9,7 +9,7 @@
}
end

it 'gracefullies fail' do
it 'gracefully fails' do
is_expected.to compile.and_raise_error(%r{Unsupported platform:})
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/puppet/functions/mysql_password_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'

describe 'the mysql_password function' do
before :all do
before :all do # rubocop:disable RSpec/BeforeAfterAll
Puppet::Parser::Functions.autoloader.loadall
end

Expand Down

0 comments on commit bcf8e1f

Please sign in to comment.