diff --git a/.gitignore b/.gitignore index f86acb60c..49bc2a401 100644 --- a/.gitignore +++ b/.gitignore @@ -13,11 +13,11 @@ /Gemfile.lock /junit/ /log/ -/log/ /pkg/ /spec/fixtures/manifests/ /spec/fixtures/modules/ /tmp/ /vendor/ /convert_report.txt +/update_report.txt .DS_Store diff --git a/.pdkignore b/.pdkignore new file mode 100644 index 000000000..49bc2a401 --- /dev/null +++ b/.pdkignore @@ -0,0 +1,23 @@ +.*.sw[op] +.metadata +.yardoc +.yardwarns +*.iml +/.bundle/ +/.idea/ +/.vagrant/ +/coverage/ +/bin/ +/doc/ +/Gemfile.local +/Gemfile.lock +/junit/ +/log/ +/pkg/ +/spec/fixtures/manifests/ +/spec/fixtures/modules/ +/tmp/ +/vendor/ +/convert_report.txt +/update_report.txt +.DS_Store diff --git a/.rubocop.yml b/.rubocop.yml index bd272d16a..c7cc04847 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,11 +10,14 @@ AllCops: Exclude: - bin/* - ".vendor/**/*" - - Gemfile - - Rakefile + - "**/Gemfile" + - "**/Rakefile" - pkg/**/* - spec/fixtures/**/* - vendor/**/* + - "**/Puppetfile" + - "**/Vagrantfile" + - "**/Guardfile" Metrics/LineLength: Description: People have wide screens, use them. Max: 200 @@ -66,6 +69,13 @@ Style/SymbolArray: Description: Using percent style obscures symbolic intent of array's contents. EnforcedStyle: brackets inherit_from: ".rubocop_todo.yml" +RSpec/MessageSpies: + EnforcedStyle: receive +Style/Documentation: + Exclude: + - lib/puppet/parser/functions/**/* +Style/WordArray: + EnforcedStyle: brackets Style/CollectionMethods: Enabled: true Style/MethodCalledOnDoEndBlock: diff --git a/.travis.yml b/.travis.yml index 14288376f..76b202cef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ before_install: - bundle -v - rm -f Gemfile.lock - gem update --system - - gem update bundler - gem --version - bundle -v script: @@ -16,14 +15,15 @@ bundler_args: --without system_tests rvm: - 2.4.1 env: - - PUPPET_GEM_VERSION="~> 5.0" CHECK=spec + global: + - BEAKER_PUPPET_COLLECTION=puppet5 PUPPET_GEM_VERSION="~> 5.0" matrix: fast_finish: true include: - bundler_args: dist: trusty - env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_set=docker/centos-7 + env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_set=docker/centos-7 rvm: 2.4.1 script: bundle exec rake beaker services: docker @@ -31,23 +31,17 @@ matrix: - bundler_args: dist: trusty - env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_set=docker/ubuntu-14.04 + env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_set=docker/ubuntu-14.04 rvm: 2.4.1 script: bundle exec rake beaker services: docker sudo: required - - env: CHECK=rubocop + env: CHECK="syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop" - - env: CHECK="syntax lint" + env: CHECK=parallel_spec - - env: CHECK=metadata_lint - - - env: CHECK=release_checks - - - env: CHECK=spec - - - env: PUPPET_GEM_VERSION="~> 4.0" CHECK=spec + env: PUPPET_GEM_VERSION="~> 4.0" CHECK=parallel_spec rvm: 2.1.9 branches: only: diff --git a/.yardopts b/.yardopts new file mode 100644 index 000000000..29c933bcf --- /dev/null +++ b/.yardopts @@ -0,0 +1 @@ +--markup markdown diff --git a/Gemfile b/Gemfile index 2ededb50a..102102e7f 100644 --- a/Gemfile +++ b/Gemfile @@ -28,11 +28,12 @@ group :development do gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9') + gem "json", '<= 2.0.4', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.4.4') gem "puppet-module-posix-default-r#{minor_version}", require: false, platforms: [:ruby] gem "puppet-module-posix-dev-r#{minor_version}", require: false, platforms: [:ruby] gem "puppet-module-win-default-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "puppet-module-win-dev-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-blacksmith", '~> 3.4', require: false + gem "puppet-blacksmith", '~> 3.4', require: false, platforms: [:ruby] gem "puppet-lint-i18n", require: false end group :system_tests do @@ -50,73 +51,24 @@ puppet_type = gem_type(puppet_version) facter_version = ENV['FACTER_GEM_VERSION'] hiera_version = ENV['HIERA_GEM_VERSION'] -def puppet_older_than?(version) - puppet_version = ENV['PUPPET_GEM_VERSION'] - !puppet_version.nil? && - Gem::Version.correct?(puppet_version) && - Gem::Requirement.new("< #{version}").satisfied_by?(Gem::Version.new(puppet_version.dup)) -end - gems = {} gems['puppet'] = location_for(puppet_version) # If facter or hiera versions have been specified via the environment -# variables, use those versions. If not, and if the puppet version is < 3.5.0, -# use known good versions of both for puppet < 3.5.0. -if facter_version - gems['facter'] = location_for(facter_version) -elsif puppet_type == :gem && puppet_older_than?('3.5.0') - gems['facter'] = ['>= 1.6.11', '<= 1.7.5', require: false] -end - -if hiera_version - gems['hiera'] = location_for(ENV['HIERA_GEM_VERSION']) -elsif puppet_type == :gem && puppet_older_than?('3.5.0') - gems['hiera'] = ['>= 1.0.0', '<= 1.3.0', require: false] -end +# variables -if Gem.win_platform? && (puppet_type != :gem || puppet_older_than?('3.5.0')) - # For Puppet gems < 3.5.0 (tested as far back as 3.0.0) on Windows - if puppet_type == :gem - gems['ffi'] = ['1.9.0', require: false] - gems['minitar'] = ['0.5.4', require: false] - gems['win32-eventlog'] = ['0.5.3', '<= 0.6.5', require: false] - gems['win32-process'] = ['0.6.5', '<= 0.7.5', require: false] - gems['win32-security'] = ['~> 0.1.2', '<= 0.2.5', require: false] - gems['win32-service'] = ['0.7.2', '<= 0.8.8', require: false] - else - gems['ffi'] = ['~> 1.9.0', require: false] - gems['minitar'] = ['~> 0.5.4', require: false] - gems['win32-eventlog'] = ['~> 0.5', '<= 0.6.5', require: false] - gems['win32-process'] = ['~> 0.6', '<= 0.7.5', require: false] - gems['win32-security'] = ['~> 0.1', '<= 0.2.5', require: false] - gems['win32-service'] = ['~> 0.7', '<= 0.8.8', require: false] - end - - gems['win32-dir'] = ['~> 0.3', '<= 0.4.9', require: false] - - if RUBY_VERSION.start_with?('1.') - gems['win32console'] = ['1.3.2', require: false] - # sys-admin was removed in Puppet 3.7.0 and doesn't compile under Ruby 2.x - gems['sys-admin'] = ['1.5.6', require: false] - end +gems['facter'] = location_for(facter_version) if facter_version +gems['hiera'] = location_for(hiera_version) if hiera_version - # Puppet < 3.7.0 requires these. - # Puppet >= 3.5.0 gem includes these as requirements. - # The following versions are tested to work with 3.0.0 <= puppet < 3.7.0. - gems['win32-api'] = ['1.4.8', require: false] - gems['win32-taskscheduler'] = ['0.2.2', require: false] - gems['windows-api'] = ['0.4.3', require: false] - gems['windows-pr'] = ['1.2.3', require: false] -elsif Gem.win_platform? +if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)} # If we're using a Puppet gem on Windows which handles its own win32-xxx gem # dependencies (>= 3.5.0), set the maximum versions (see PUP-6445). gems['win32-dir'] = ['<= 0.4.9', require: false] gems['win32-eventlog'] = ['<= 0.6.5', require: false] gems['win32-process'] = ['<= 0.7.5', require: false] gems['win32-security'] = ['<= 0.2.5', require: false] - gems['win32-service'] = ['<= 0.8.8', require: false] + gems['win32-service'] = ['0.8.8', require: false] end gems.each do |gem_name, gem_params| diff --git a/Rakefile b/Rakefile index f39d8351c..abcc71e02 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,7 @@ require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-syntax/tasks/puppet-syntax' -require 'puppet_blacksmith/rake_tasks' +require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? require 'puppet_pot_generator/rake_tasks' + +PuppetLint.configuration.send('disable_relative') + diff --git a/lib/puppet/parser/functions/mysql_deepmerge.rb b/lib/puppet/parser/functions/mysql_deepmerge.rb index 87db63c53..766028e89 100644 --- a/lib/puppet/parser/functions/mysql_deepmerge.rb +++ b/lib/puppet/parser/functions/mysql_deepmerge.rb @@ -1,4 +1,4 @@ -module Puppet::Parser::Functions # rubocop:disable Style/Documentation +module Puppet::Parser::Functions newfunction(:mysql_deepmerge, type: :rvalue, doc: <<-'ENDHEREDOC') do |args| @summary Recursively merges two or more hashes together and returns the resulting hash. diff --git a/lib/puppet/parser/functions/mysql_dirname.rb b/lib/puppet/parser/functions/mysql_dirname.rb index 272d29464..40a8ad64f 100644 --- a/lib/puppet/parser/functions/mysql_dirname.rb +++ b/lib/puppet/parser/functions/mysql_dirname.rb @@ -1,4 +1,4 @@ -module Puppet::Parser::Functions # rubocop:disable Style/Documentation +module Puppet::Parser::Functions newfunction(:mysql_dirname, type: :rvalue, doc: <<-EOS @summary Returns the dirname of a path diff --git a/lib/puppet/parser/functions/mysql_password.rb b/lib/puppet/parser/functions/mysql_password.rb index d896a3e1f..53ba580b2 100644 --- a/lib/puppet/parser/functions/mysql_password.rb +++ b/lib/puppet/parser/functions/mysql_password.rb @@ -1,5 +1,5 @@ require 'digest/sha1' -module Puppet::Parser::Functions # rubocop:disable Style/Documentation +module Puppet::Parser::Functions newfunction(:mysql_password, type: :rvalue, doc: <<-EOS @summary Hash a string as mysql's "PASSWORD()" function would do it diff --git a/lib/puppet/provider/mysql_datadir/mysql.rb b/lib/puppet/provider/mysql_datadir/mysql.rb index ec5f32b32..1b2bc5a7b 100644 --- a/lib/puppet/provider/mysql_datadir/mysql.rb +++ b/lib/puppet/provider/mysql_datadir/mysql.rb @@ -52,7 +52,7 @@ def create end opts = [defaults_extra_file] - %w[basedir datadir user].each do |opt| + ['basedir', 'datadir', 'user'].each do |opt| val = eval(opt) # rubocop:disable Security/Eval opts << "--#{opt}=#{val}" unless val.nil? end @@ -80,7 +80,7 @@ def destroy def exists? datadir = @resource[:datadir] - File.directory?("#{datadir}/mysql") && (Dir.entries("#{datadir}/mysql") - %w[. ..]).any? + File.directory?("#{datadir}/mysql") && (Dir.entries("#{datadir}/mysql") - ['.', '..']).any? end ## diff --git a/metadata.json b/metadata.json index 6a86aad08..3c10e1135 100644 --- a/metadata.json +++ b/metadata.json @@ -84,6 +84,7 @@ } ], "description": "MySQL module", - "template-url": "file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git", - "template-ref": "1.3.2-0-g07678c8" + "template-url": "https://github.com/puppetlabs/pdk-templates", + "template-ref": "heads/master-0-g34e3266", + "pdk-version": "1.5.0" } diff --git a/spec/acceptance/mysql_backup_spec.rb b/spec/acceptance/mysql_backup_spec.rb index b0fecb0ca..cb82ade10 100644 --- a/spec/acceptance/mysql_backup_spec.rb +++ b/spec/acceptance/mysql_backup_spec.rb @@ -124,7 +124,7 @@ class { 'mysql::server::backup': it 'creates one file per database' do unless version_is_greater_than('5.7.0') - %w[backup1 backup2].each do |database| + ['backup1', 'backup2'].each do |database| shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r| expect(r.stdout).to match(%r{1}) expect(r.exit_code).to be_zero @@ -142,7 +142,7 @@ class { 'mysql::server::backup': it 'has one file per database per run' do unless version_is_greater_than('5.7.0') - %w[backup1 backup2].each do |database| + ['backup1', 'backup2'].each do |database| shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r| expect(r.stdout).to match(%r{2}) expect(r.exit_code).to be_zero diff --git a/spec/classes/mycnf_template_spec.rb b/spec/classes/mycnf_template_spec.rb index 63ec2e32d..ddc8c7827 100644 --- a/spec/classes/mycnf_template_spec.rb +++ b/spec/classes/mycnf_template_spec.rb @@ -17,7 +17,7 @@ end describe 'array entry' do - let(:params) { { override_options: { 'mysqld' => { 'replicate-do-db' => %w[base1 base2] } } } } + let(:params) { { override_options: { 'mysqld' => { 'replicate-do-db' => ['base1', 'base2'] } } } } it do is_expected.to contain_file('mysql-config-file').with_content( diff --git a/spec/classes/mysql_server_monitor_spec.rb b/spec/classes/mysql_server_monitor_spec.rb index 3a64ac3c8..1a79ad789 100644 --- a/spec/classes/mysql_server_monitor_spec.rb +++ b/spec/classes/mysql_server_monitor_spec.rb @@ -27,7 +27,7 @@ it { is_expected.to contain_mysql_grant('monitoruser@monitorhost/*.*').with( ensure: 'present', user: 'monitoruser@monitorhost', - table: '*.*', privileges: %w[PROCESS SUPER], + table: '*.*', privileges: ['PROCESS', 'SUPER'], require: 'Mysql_user[monitoruser@monitorhost]' ) } diff --git a/spec/classes/mysql_server_spec.rb b/spec/classes/mysql_server_spec.rb index 07d4917a0..209f40f4f 100644 --- a/spec/classes/mysql_server_spec.rb +++ b/spec/classes/mysql_server_spec.rb @@ -205,7 +205,7 @@ 'foo@localhost/somedb.*' => { 'user' => 'foo@localhost', 'table' => 'somedb.*', - 'privileges' => %w[SELECT UPDATE], + 'privileges' => ['SELECT', 'UPDATE'], 'options' => ['GRANT'], }, 'foo2@localhost/*.*' => { @@ -219,7 +219,7 @@ it { is_expected.to contain_mysql_grant('foo@localhost/somedb.*').with( user: 'foo@localhost', table: 'somedb.*', - privileges: %w[SELECT UPDATE], options: ['GRANT'] + privileges: ['SELECT', 'UPDATE'], options: ['GRANT'] ) } it { diff --git a/spec/defines/mysql_db_spec.rb b/spec/defines/mysql_db_spec.rb index ab2550867..3d2d63dd6 100644 --- a/spec/defines/mysql_db_spec.rb +++ b/spec/defines/mysql_db_spec.rb @@ -47,7 +47,7 @@ end it 'imports sql scripts when more than one is specified' do - params['sql'] = %w[test_sql test_2_sql] + params['sql'] = ['test_sql', 'test_2_sql'] is_expected.to contain_exec('test_db-import').with_command('cat test_sql test_2_sql | mysql test_db') end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c20a31773..8554b4332 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,13 @@ + require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' + +begin + require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) +rescue LoadError => loaderror + warn "Could not require spec_helper_local: #{loaderror.message}" +end + include RspecPuppetFacts default_facts = { @@ -20,5 +28,10 @@ RSpec.configure do |c| c.default_facts = default_facts + c.before :each do + # set to strictest setting for testing + # by default Puppet runs at warning level + Puppet.settings[:strict] = :warning + end end require 'spec_helper_local' diff --git a/spec/unit/puppet/functions/mysql_deepmerge_spec.rb b/spec/unit/puppet/functions/mysql_deepmerge_spec.rb index c2ad8895d..0d86b9628 100644 --- a/spec/unit/puppet/functions/mysql_deepmerge_spec.rb +++ b/spec/unit/puppet/functions/mysql_deepmerge_spec.rb @@ -28,8 +28,8 @@ expect { scope.function_mysql_deepmerge([{}, '']) }.not_to raise_error end - index_values = %w[one two three] - expected_values_one = %w[1 2 2] + index_values = ['one', 'two', 'three'] + expected_values_one = ['1', '2', '2'] it 'is able to mysql_deepmerge two hashes' do new_hash = scope.function_mysql_deepmerge([{ 'one' => '1', 'two' => '1' }, { 'two' => '2', 'three' => '2' }]) index_values.each_with_index do |index, expected| @@ -67,7 +67,7 @@ end end - index_values_two = %w[key1 key2] + index_values_two = ['key1', 'key2'] expected_values_four = [{ 'a' => 1, 'b' => 99 }, 'c' => 3] it 'appends to subhashes 3' do hash = scope.function_mysql_deepmerge([{ 'key1' => { 'a' => 1, 'b' => 2 }, 'key2' => { 'c' => 3 } }, { 'key1' => { 'b' => 99 } }]) diff --git a/spec/unit/puppet/functions/mysql_password_spec.rb b/spec/unit/puppet/functions/mysql_password_spec.rb index b1794f8b1..85c4d44a2 100644 --- a/spec/unit/puppet/functions/mysql_password_spec.rb +++ b/spec/unit/puppet/functions/mysql_password_spec.rb @@ -16,11 +16,11 @@ end it 'raises a ParseError if there is more than 1 arguments' do - expect { scope.function_mysql_password(%w[foo bar]) }.to(raise_error(Puppet::ParseError)) + expect { scope.function_mysql_password(['foo', 'bar']) }.to(raise_error(Puppet::ParseError)) end it 'converts password into a hash' do - result = scope.function_mysql_password(%w[password]) + result = scope.function_mysql_password(['password']) expect(result).to(eq('*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19')) end diff --git a/spec/unit/puppet/provider/mysql_database/mysql_spec.rb b/spec/unit/puppet/provider/mysql_database/mysql_spec.rb index ffa624444..caddeebb1 100644 --- a/spec/unit/puppet/provider/mysql_database/mysql_spec.rb +++ b/spec/unit/puppet/provider/mysql_database/mysql_spec.rb @@ -2,7 +2,7 @@ describe Puppet::Type.type(:mysql_database).provider(:mysql) do let(:defaults_file) { '--defaults-extra-file=/root/.my.cnf' } - let(:parsed_databases) { %w[information_schema mydb mysql performance_schema test] } + let(:parsed_databases) { ['information_schema', 'mydb', 'mysql', 'performance_schema', 'test'] } let(:provider) { resource.provider } let(:instance) { provider.class.instances.first } let(:resource) do diff --git a/spec/unit/puppet/provider/mysql_user/mysql_spec.rb b/spec/unit/puppet/provider/mysql_user/mysql_spec.rb index 84d7b63b3..ba8bc2e8a 100644 --- a/spec/unit/puppet/provider/mysql_user/mysql_spec.rb +++ b/spec/unit/puppet/provider/mysql_user/mysql_spec.rb @@ -65,7 +65,7 @@ # rubocop:enable Layout/IndentHeredoc end - let(:parsed_users) { %w[root@127.0.0.1 root@::1 @localhost debian-sys-maint@localhost root@localhost usvn_user@localhost @vagrant-ubuntu-raring-64] } + let(:parsed_users) { ['root@127.0.0.1', 'root@::1', '@localhost', 'debian-sys-maint@localhost', 'root@localhost', 'usvn_user@localhost', '@vagrant-ubuntu-raring-64'] } let(:provider) { resource.provider } let(:instance) { provider.class.instances.first } let(:resource) do @@ -362,9 +362,7 @@ end end - %w[max_user_connections max_connections_per_hour max_queries_per_hour - max_updates_per_hour].each do |property| - + ['max_user_connections', 'max_connections_per_hour', 'max_queries_per_hour', 'max_updates_per_hour'].each do |property| describe property do it "returns #{property}" do expect(instance.send(property.to_s.to_sym)).to eq('10') diff --git a/spec/unit/puppet/type/mysql_grant_spec.rb b/spec/unit/puppet/type/mysql_grant_spec.rb index 793f1a029..acf47a2dd 100644 --- a/spec/unit/puppet/type/mysql_grant_spec.rb +++ b/spec/unit/puppet/type/mysql_grant_spec.rb @@ -86,9 +86,9 @@ it 'to upcase and ordered' do user = Puppet::Type.type(:mysql_grant).new( name: 'foo@localhost/*.*', table: ['*.*'], user: 'foo@localhost', - privileges: %w[select Insert] + privileges: ['select', 'Insert'] ) - expect(user[:privileges]).to eq(%w[INSERT SELECT]) + expect(user[:privileges]).to eq(['INSERT', 'SELECT']) end it 'ordered including column privileges' do