From 003a498a522b722d891f8f99a106433dc6278d5a Mon Sep 17 00:00:00 2001 From: lionce Date: Fri, 30 Aug 2019 14:40:06 +0300 Subject: [PATCH] rubocop fixes and pdk update --- .rubocop.yml | 2 + .travis.yml | 26 ++++++++---- Gemfile | 4 -- Rakefile | 13 +++++- lib/puppet/provider/firewall/iptables.rb | 1 - metadata.json | 4 +- .../firewall_attributes_exceptions_spec.rb | 7 ++-- spec/acceptance/rules_spec.rb | 7 ++-- spec/spec_helper_acceptance.rb | 40 +++++++++---------- spec/spec_helper_acceptance_local.rb | 6 +-- 10 files changed, 62 insertions(+), 48 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 3cd2b0e..8a9014f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -108,6 +108,8 @@ Metrics/ParameterLists: Enabled: false Metrics/PerceivedComplexity: Enabled: false +Metrics/BlockNesting: + Enabled: false RSpec/DescribeClass: Enabled: false RSpec/ExampleLength: diff --git a/.travis.yml b/.travis.yml index b6064dd..0b2378e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ --- -dist: xenial language: ruby cache: bundler before_install: @@ -24,22 +23,33 @@ matrix: fast_finish: true include: - - bundler_args: + bundler_args: dist: trusty - env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_set=docker/centos-7 BEAKER_TESTMODE=apply + env: PLATFORMS=deb_puppet5 rvm: 2.5.3 - script: bundle exec rake beaker + before_script: + - bundle exec rake 'litmus:provision_list[travis_deb]' + - bundle exec bolt command run 'apt-get install wget -y' --inventoryfile inventory.yaml --nodes='localhost*' + - bundle exec rake 'litmus:install_agent[puppet5]' + - bundle exec rake litmus:install_module + script: + - bundle exec rake litmus:acceptance:parallel services: docker stage: acceptance sudo: required - - bundler_args: + bundler_args: dist: trusty - env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_set=docker/ubuntu-14.04 BEAKER_TESTMODE=apply + env: PLATFORM=deb_puppet6 rvm: 2.5.3 - script: bundle exec rake beaker + before_script: + - bundle exec rake 'litmus:provision_list[travis_deb]' + - bundle exec bolt command run 'apt-get install wget -y' --inventoryfile inventory.yaml --nodes='localhost*' + - bundle exec rake 'litmus:install_agent[puppet6]' + - bundle exec rake litmus:install_module + script: + - bundle exec rake litmus:acceptance:parallel services: docker - stage: acceptance sudo: required - env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" diff --git a/Gemfile b/Gemfile index 9c4c79b..0e395e7 100644 --- a/Gemfile +++ b/Gemfile @@ -30,10 +30,6 @@ group :development do gem "puppet-module-win-dev-r#{minor_version}", '~> 0.3', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') end -group :system_tests do - gem "puppet-module-posix-system-r#{minor_version}", require: false, platforms: [:ruby] - gem "puppet-module-win-system-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] -end puppet_version = ENV['PUPPET_GEM_VERSION'] facter_version = ENV['FACTER_GEM_VERSION'] diff --git a/Rakefile b/Rakefile index d9b223c..395df54 100644 --- a/Rakefile +++ b/Rakefile @@ -15,8 +15,17 @@ end def changelog_project return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = nil || JSON.load(File.read('metadata.json'))['source'].match(%r{.*/([^/]*)})[1] - raise "unable to find the changelog_project in .sync.yml or the name in metadata.json" if returnVal.nil? + + returnVal = nil + returnVal ||= begin + metadata_source = JSON.load(File.read('metadata.json'))['source'] + metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z}) + + metadata_source_match && metadata_source_match[1] + end + + raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil? + puts "GitHubChangelogGenerator project:#{returnVal}" returnVal end diff --git a/lib/puppet/provider/firewall/iptables.rb b/lib/puppet/provider/firewall/iptables.rb index f3a334b..f108b43 100644 --- a/lib/puppet/provider/firewall/iptables.rb +++ b/lib/puppet/provider/firewall/iptables.rb @@ -781,7 +781,6 @@ Puppet::Type.type(:firewall).provide :iptables, parent: Puppet::Provider::Firewa end if should_negate resource_value, wrong_values = resource_value.map { |value| - # rubocop:disable Metrics/BlockNesting if value.is_a?(String) wrong = value unless value =~ %r{^!\s+} [value.sub(%r{^!\s*}, ''), wrong] diff --git a/metadata.json b/metadata.json index 5bc4ce9..a763216 100644 --- a/metadata.json +++ b/metadata.json @@ -76,6 +76,6 @@ } ], "template-url": "https://github.com/puppetlabs/pdk-templates#master", - "template-ref": "1.12.0-0-g55d9ae2", - "pdk-version": "1.12.0" + "template-ref": "tags/1.13.0-0-g66e1443", + "pdk-version": "1.13.0" } diff --git a/spec/acceptance/firewall_attributes_exceptions_spec.rb b/spec/acceptance/firewall_attributes_exceptions_spec.rb index cf1bb10..12650bb 100644 --- a/spec/acceptance/firewall_attributes_exceptions_spec.rb +++ b/spec/acceptance/firewall_attributes_exceptions_spec.rb @@ -357,8 +357,7 @@ describe 'firewall basics', docker: true do end end - - describe 'nflog', unless: get_iptables_version < '1.3.7' do + describe 'nflog', unless: iptables_version < '1.3.7' do describe 'nflog_group' do it 'applies' do pp2 = <<-PUPPETCODE @@ -451,7 +450,7 @@ describe 'firewall basics', docker: true do PUPPETCODE it 'throws an error' do res = apply_manifest(pp1, expect_failures: true) - expect(res[:exit_code]).to eql(0) + expect(res[:exit_code]).to be(0) end end @@ -1131,7 +1130,7 @@ describe 'firewall basics', docker: true do } PUPPETCODE it "changes the value to #{value}" do - apply_manifest(pp1, catch_failures: true, ) + apply_manifest(pp1, catch_failures: true) apply_manifest(pp1, catch_changes: true) run_shell('iptables-save -t raw') do |r| diff --git a/spec/acceptance/rules_spec.rb b/spec/acceptance/rules_spec.rb index ff86d11..b8af799 100644 --- a/spec/acceptance/rules_spec.rb +++ b/spec/acceptance/rules_spec.rb @@ -240,9 +240,8 @@ describe 'rules spec' do PUPPETCODE it 'applies cleanly' do # Run it twice and test for idempotency - r = apply_manifest(pp2, catch_failures: true, expect_failures: true) - - r=apply_manifest(pp2, catch_changes: true, expect_failures: true) + apply_manifest(pp2, catch_failures: true, expect_failures: true) + apply_manifest(pp2, catch_changes: true, expect_failures: true) end regex_values = [ @@ -273,4 +272,4 @@ describe 'rules spec' do end end end -end \ No newline at end of file +end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 7a54362..8c423fb 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -28,26 +28,26 @@ else options[:password] = node_config.dig('ssh', 'password') unless node_config.dig('ssh', 'password').nil? options[:verify_host_key] = if node_config.dig('ssh', 'host-key-check').nil? - # Fall back to SSH behavior. This variable will only be set in net-ssh 5.3+. - if @strict_host_key_checking.nil? || @strict_host_key_checking - Net::SSH::Verifiers::Always.new - else - # SSH's behavior with StrictHostKeyChecking=no: adds new keys to known_hosts. - # If known_hosts points to /dev/null, then equivalent to :never where it - # accepts any key beacuse they're all new. - Net::SSH::Verifiers::AcceptNewOrLocalTunnel.new - end - elsif node_config.dig('ssh', 'host-key-check') - if defined?(Net::SSH::Verifiers::Always) - Net::SSH::Verifiers::Always.new - else - Net::SSH::Verifiers::Secure.new - end - elsif defined?(Net::SSH::Verifiers::Never) - Net::SSH::Verifiers::Never.new - else - Net::SSH::Verifiers::Null.new - end + # Fall back to SSH behavior. This variable will only be set in net-ssh 5.3+. + if @strict_host_key_checking.nil? || @strict_host_key_checking + Net::SSH::Verifiers::Always.new + else + # SSH's behavior with StrictHostKeyChecking=no: adds new keys to known_hosts. + # If known_hosts points to /dev/null, then equivalent to :never where it + # accepts any key beacuse they're all new. + Net::SSH::Verifiers::AcceptNewOrLocalTunnel.new + end + elsif node_config.dig('ssh', 'host-key-check') + if defined?(Net::SSH::Verifiers::Always) + Net::SSH::Verifiers::Always.new + else + Net::SSH::Verifiers::Secure.new + end + elsif defined?(Net::SSH::Verifiers::Never) + Net::SSH::Verifiers::Never.new + else + Net::SSH::Verifiers::Null.new + end host = if ENV['TARGET_HOST'].include?(':') ENV['TARGET_HOST'].split(':').first diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index d0c3f6e..7514c42 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -10,7 +10,7 @@ def ip6tables_flush_all_tables end end -def get_iptables_version - x=run_shell('iptables -V') +def iptables_version + x = run_shell('iptables -V') x.stdout.split(' ')[1][1..-1] -end \ No newline at end of file +end -- 2.45.2