diff --git a/.fixtures.yml b/.fixtures.yml index 93feb0de..b6548cb0 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -4,15 +4,7 @@ fixtures: facts: 'https://github.com/puppetlabs/puppetlabs-facts.git' "stdlib": "https://github.com/puppetlabs/puppetlabs-stdlib.git" provision: "https://github.com/puppetlabs/provision.git" - puppet_agent: - repo: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' - ref: v4.25.0 - package: "https://github.com/puppetlabs/puppetlabs-package.git" - deploy_pe: "https://github.com/jarretlavallee/puppet-deploy_pe" - sign_cert: "https://github.com/m0dular/sign_cert" - ruby_task_helper: "https://git@github.com/puppetlabs/puppetlabs-ruby_task_helper" - bootstrap: "https://github.com/puppetlabs/puppetlabs-bootstrap" - puppet_conf: "https://github.com/puppetlabs/puppetlabs-puppet_conf" + puppet_agent: "https://github.com/puppetlabs/puppetlabs-puppet_agent.git" symlinks: "ntp": "#{source_dir}" "my_ntp": "#{source_dir}/spec/fixtures/my_ntp" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22742aea..94f0ac6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,7 @@ jobs: uses: "puppetlabs/cat-github-actions/.github/workflows/module_ci.yml@main" with: runs_on: "ubuntu-24.04" + flags: "--nightly" secrets: "inherit" Acceptance: @@ -18,5 +19,5 @@ jobs: uses: "puppetlabs/cat-github-actions/.github/workflows/module_acceptance.yml@main" with: runs_on: "ubuntu-24.04" - flags: "--nightly" + flags: "--nightly --platform-exclude centos-7 --platform-exclude oraclelinux-7 --platform-exclude scientific-7" secrets: "inherit" diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml deleted file mode 100644 index 3a32443e..00000000 --- a/.github/workflows/integration_test.yml +++ /dev/null @@ -1,107 +0,0 @@ -name: "Integration Testing" - -on: - pull_request: - branches: - - "main" - workflow_call: - workflow_dispatch: - -jobs: - setup_matrix: - name: "Setup Test Matrix" - runs-on: ubuntu-24.04 - outputs: - matrix: ${{ steps.get-matrix.outputs.matrix }} - - steps: - - name: Checkout Source - uses: actions/checkout@v3 - if: ${{ github.repository_owner == 'puppetlabs' }} - - - name: Activate Ruby 3.2 - uses: ruby/setup-ruby@v1 - if: ${{ github.repository_owner == 'puppetlabs' }} - with: - ruby-version: "3.2" - bundler-cache: true - - - name: Print bundle environment - if: ${{ github.repository_owner == 'puppetlabs' }} - run: | - echo ::group::bundler environment - bundle env - echo ::endgroup:: - - - name: Setup Integration Test Matrix - id: get-matrix - run: | - if [ '${{ github.repository_owner }}' == 'puppetlabs' ]; then - echo "matrix={'platform':['ubuntu-2204-lts'],'collection':['puppet7-nightly', 'puppet8-nightly']}" >> $GITHUB_OUTPUT - else - echo "matrix={}" >> $GITHUB_OUTPUT - fi - - Integration: - needs: - - setup_matrix - if: ${{ needs.setup_matrix.outputs.matrix != '{}' }} - - runs-on: ubuntu-24.04 - strategy: - fail-fast: false - matrix: ${{fromJson(needs.setup_matrix.outputs.matrix)}} - - env: - PUPPET_GEM_VERSION: '~> 7.24' - FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main' # why is this set? - - steps: - - - name: Checkout Source - uses: actions/checkout@v3 - - - name: Activate Ruby 3.2 - uses: ruby/setup-ruby@v1 - with: - ruby-version: "3.2" - bundler-cache: true - - - name: Print bundle environment - run: | - echo ::group::bundler environment - bundle env - echo ::endgroup:: - - - name: Create the fixtures directory - run: | - bundle exec rake spec_prep - - - name: Provision test environment - run: | - bundle exec bolt --modulepath spec/fixtures/modules plan run ntp::acceptance::provision_integration image=${{ matrix.platform }} - # Redact password - FILE='spec/fixtures/litmus_inventory.yaml' - sed -e 's/password: .*/password: "[redacted]"/' < $FILE || true - - - name: Install PE - run: | - bundle exec bolt --modulepath spec/fixtures/modules -i ./spec/fixtures/litmus_inventory.yaml plan run ntp::acceptance::pe_server - - - name: Install Agents - run: | - bundle exec bolt --modulepath spec/fixtures/modules -i ./spec/fixtures/litmus_inventory.yaml plan run ntp::acceptance::pe_agent - - - name: Install module - run: | - bundle exec rake 'litmus:install_module' - - - name: Run integration tests - run: | - bundle exec rake ntp:integration - - - name: Remove test environment - if: ${{ always() }} - continue-on-error: true - run: | - bundle exec rake 'litmus:tear_down' diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index b08ff3ad..eb4e6b3d 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -10,6 +10,7 @@ jobs: uses: "puppetlabs/cat-github-actions/.github/workflows/module_ci.yml@main" with: runs_on: "ubuntu-24.04" + flags: "--nightly" secrets: "inherit" Acceptance: @@ -17,7 +18,7 @@ jobs: uses: "puppetlabs/cat-github-actions/.github/workflows/module_acceptance.yml@main" with: runs_on: "ubuntu-24.04" - flags: "--nightly" + flags: "--nightly --platform-exclude centos-7 --platform-exclude oraclelinux-7 --platform-exclude scientific-7" secrets: "inherit" Integration: diff --git a/.puppet-lint.rc b/.puppet-lint.rc index cc96ece0..9e15c6e0 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -1 +1,9 @@ +--fail-on-warnings --relative +--no-80chars-check +--no-140chars-check +--no-class_inherits_from_params_class-check +--no-autoloader_layout-check +--no-documentation-check +--no-single_quote_string_with_variables-check +--ignore-paths=.vendor/**/*.pp,.bundle/**/*.pp,pkg/**/*.pp,spec/**/*.pp,tests/**/*.pp,types/**/*.pp,vendor/**/*.pp diff --git a/.rubocop.yml b/.rubocop.yml index 439ea84e..47b1aadb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,7 +5,7 @@ require: AllCops: NewCops: enable DisplayCopNames: true - TargetRubyVersion: '2.6' + TargetRubyVersion: 3.1 Include: - "**/*.rb" Exclude: diff --git a/.sync.yml b/.sync.yml index f62c286c..8088e280 100644 --- a/.sync.yml +++ b/.sync.yml @@ -13,15 +13,6 @@ Gemfile: version: '= 1.15.2' Rakefile: changelog_user: puppetlabs - extras: - - | - require 'rspec/core/rake_task' - namespace :ntp do - RSpec::Core::RakeTask.new(:integration) do |t| - t.pattern = 'spec/acceptance/**{,/*/**}/*_spec.rb' - t.rspec_opts = "--tag integration" - end - end spec/spec_helper.rb: mock_with: ":rspec" coverage_report: true diff --git a/Gemfile b/Gemfile index d097a4c4..f0fd6709 100644 --- a/Gemfile +++ b/Gemfile @@ -1,22 +1,41 @@ -source ENV['GEM_SOURCE'] || 'https://rubygems.org' +# frozen_string_literal: true -def location_for(place_or_version, fake_version = nil) - git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} - file_url_regex = %r{\Afile:\/\/(?.*)} +# For puppetcore, set GEM_SOURCE_PUPPETCORE = 'https://rubygems-puppetcore.puppet.com' +gemsource_default = ENV['GEM_SOURCE'] || 'https://rubygems.org' +gemsource_puppetcore = if ENV['PUPPET_FORGE_TOKEN'] + 'https://rubygems-puppetcore.puppet.com' +else + ENV['GEM_SOURCE_PUPPETCORE'] || gemsource_default +end +source gemsource_default + +def location_for(place_or_constraint, fake_constraint = nil, opts = {}) + git_url_regex = /\A(?(?:https?|git)[:@][^#]*)(?:#(?.*))?/ + file_url_regex = %r{\Afile://(?.*)} + + if place_or_constraint && (git_url = place_or_constraint.match(git_url_regex)) + # Git source → ignore :source, keep fake_constraint + [fake_constraint, { git: git_url[:url], branch: git_url[:branch], require: false }].compact + + elsif place_or_constraint && (file_url = place_or_constraint.match(file_url_regex)) + # File source → ignore :source, keep fake_constraint or default >= 0 + [fake_constraint || '>= 0', { path: File.expand_path(file_url[:path]), require: false }] - if place_or_version && (git_url = place_or_version.match(git_url_regex)) - [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact - elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) - ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] else - [place_or_version, { require: false }] + # Plain version constraint → merge opts (including :source if provided) + [place_or_constraint, { require: false }.merge(opts)] + end +end + +# Print debug information if DEBUG_GEMS or VERBOSE is set +def print_gem_statement_for(gems) + puts 'DEBUG: Gem definitions that will be generated:' + gems.each do |gem_name, gem_params| + puts "DEBUG: gem #{([gem_name.inspect] + gem_params.map(&:inspect)).join(', ')}" end end group :development do - gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "racc", '~> 1.4.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) @@ -43,6 +62,7 @@ end group :development, :release_prep do gem "puppet-strings", '~> 4.0', require: false gem "puppetlabs_spec_helper", '~> 8.0', require: false + gem "puppet-blacksmith", '~> 7.0', require: false end group :system_tests do gem "puppet_litmus", '~> 2.0', require: false, platforms: [:ruby, :x64_mingw] if !ENV['PUPPET_FORGE_TOKEN'].to_s.empty? @@ -51,28 +71,17 @@ group :system_tests do gem "serverspec", '~> 2.41', require: false end -puppet_version = ENV['PUPPET_GEM_VERSION'] -facter_version = ENV['FACTER_GEM_VERSION'] -hiera_version = ENV['HIERA_GEM_VERSION'] - gems = {} - puppet_version = ENV.fetch('PUPPET_GEM_VERSION', nil) facter_version = ENV.fetch('FACTER_GEM_VERSION', nil) hiera_version = ENV.fetch('HIERA_GEM_VERSION', nil) -# If PUPPET_FORGE_TOKEN is set then use authenticated source for both puppet and facter, since facter is a transitive dependency of puppet -# Otherwise, do as before and use location_for to fetch gems from the default source -if !ENV['PUPPET_FORGE_TOKEN'].to_s.empty? - gems['puppet'] = ['~> 8.11', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }] - gems['facter'] = ['~> 4.11', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }] -else - gems['puppet'] = location_for(puppet_version) - gems['facter'] = location_for(facter_version) if facter_version -end - -gems['hiera'] = location_for(hiera_version) if hiera_version +gems['puppet'] = location_for(puppet_version, nil, { source: gemsource_puppetcore }) +gems['facter'] = location_for(facter_version, nil, { source: gemsource_puppetcore }) +gems['hiera'] = location_for(hiera_version, nil, {}) if hiera_version +# Generate the gem definitions +print_gem_statement_for(gems) if ENV['DEBUG'] gems.each do |gem_name, gem_params| gem gem_name, *gem_params end @@ -80,12 +89,14 @@ end # Evaluate Gemfile.local and ~/.gemfile if they exist extra_gemfiles = [ "#{__FILE__}.local", - File.join(Dir.home, '.gemfile'), + File.join(Dir.home, '.gemfile') ] extra_gemfiles.each do |gemfile| - if File.file?(gemfile) && File.readable?(gemfile) - eval(File.read(gemfile), binding) - end + next unless File.file?(gemfile) && File.readable?(gemfile) + + # rubocop:disable Security/Eval + eval(File.read(gemfile), binding) + # rubocop:enable Security/Eval end # vim: syntax=ruby diff --git a/Rakefile b/Rakefile index f011e698..85222267 100644 --- a/Rakefile +++ b/Rakefile @@ -7,11 +7,11 @@ require 'puppet-syntax/tasks/puppet-syntax' require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings' PuppetLint.configuration.send('disable_relative') - -require 'rspec/core/rake_task' -namespace :ntp do - RSpec::Core::RakeTask.new(:integration) do |t| - t.pattern = 'spec/acceptance/**{,/*/**}/*_spec.rb' - t.rspec_opts = "--tag integration" - end -end +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.send('disable_140chars') +PuppetLint.configuration.send('disable_class_inherits_from_params_class') +PuppetLint.configuration.send('disable_autoloader_layout') +PuppetLint.configuration.send('disable_documentation') +PuppetLint.configuration.send('disable_single_quote_string_with_variables') +PuppetLint.configuration.fail_on_warnings = true +PuppetLint.configuration.ignore_paths = [".vendor/**/*.pp", ".bundle/**/*.pp", "pkg/**/*.pp", "spec/**/*.pp", "tests/**/*.pp", "types/**/*.pp", "vendor/**/*.pp"] diff --git a/metadata.json b/metadata.json index 908d2fbd..ec209fa7 100644 --- a/metadata.json +++ b/metadata.json @@ -83,6 +83,6 @@ ], "description": "NTP Module for Debian, Ubuntu, CentOS, RHEL, OEL, Fedora, FreeBSD, ArchLinux, Amazon Linux and Gentoo.", "template-url": "https://github.com/puppetlabs/pdk-templates.git#main", - "template-ref": "tags/3.2.0.4-0-g5d17ec1", - "pdk-version": "3.2.0" + "template-ref": "heads/main-0-g9d5b193", + "pdk-version": "3.5.0" } diff --git a/plans/acceptance/pe_agent.pp b/plans/acceptance/pe_agent.pp deleted file mode 100644 index 83530109..00000000 --- a/plans/acceptance/pe_agent.pp +++ /dev/null @@ -1,18 +0,0 @@ -# @summary Install PE -# -# Install PE Agent -# -# @example -# ntp::acceptance::pe_agent -plan ntp::acceptance::pe_agent() { - #identify pe server and agent nodes - $puppet_server = get_targets('*').filter |$n| { $n.vars['role'] == 'ntpserver' } - $puppet_agent = get_targets('*').filter |$n| { $n.vars['role'] == 'ntpclient' } - - # install pe server - run_plan( - 'deploy_pe::provision_agent', - $puppet_agent, - 'master' => $puppet_server, - ) -} diff --git a/plans/acceptance/pe_server.pp b/plans/acceptance/pe_server.pp deleted file mode 100644 index ae53098c..00000000 --- a/plans/acceptance/pe_server.pp +++ /dev/null @@ -1,21 +0,0 @@ -# @summary Install PE Server -# -# Install PE Server -# -# @example -# ntp::acceptance::pe_server -plan ntp::acceptance::pe_server( - Optional[String] $version = '2021.7.9', - Optional[Hash] $pe_settings = { password => 'puppetlabs' } -) { - #identify pe server node - $puppet_server = get_targets('*').filter |$n| { $n.vars['role'] == 'ntpserver' } - - # install pe server - run_plan( - 'deploy_pe::provision_master', - $puppet_server, - 'version' => $version, - 'pe_settings' => $pe_settings - ) -} diff --git a/plans/acceptance/provision_integration.pp b/plans/acceptance/provision_integration.pp deleted file mode 100644 index 8a5cd5e3..00000000 --- a/plans/acceptance/provision_integration.pp +++ /dev/null @@ -1,14 +0,0 @@ -# @summary Provisions machines -# -# Provisions machines for integration testing -# -# @example -# ntp::acceptance::provision_integration -plan ntp::acceptance::provision_integration( - Optional[String] $image = 'centos-7', - Optional[String] $provision_type = 'provision_service', -) { - #provision server machine, set role - run_task("provision::${provision_type}", 'localhost', action => 'provision', platform => $image, vars => 'role: ntpserver') - run_task("provision::${provision_type}", 'localhost', action => 'provision', platform => $image, vars => 'role: ntpclient') -} diff --git a/spec/acceptance/integration_ntp_spec.rb b/spec/acceptance/integration_ntp_spec.rb deleted file mode 100644 index c57da2e6..00000000 --- a/spec/acceptance/integration_ntp_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper_acceptance' -require 'json' -require 'pry' - -describe 'we are able to setup an ntp server, and connect a client to it', :integration do - context 'when setting up the server' do - before(:all) { change_target_host('ntpserver') } - after(:all) { reset_target_host } - - describe 'set up ntpserver' do - pp = <<-MANIFEST - class { 'ntp': } - MANIFEST - - it 'check the date is current and set up the service' do - idempotent_apply(pp) - result = run_shell('date') - expect(result.stdout).to match(%r{#{Time.now.year}}) - end - end - end - - context 'when setting up the client' do - before(:all) { change_target_host('ntpclient') } - after(:all) { reset_target_host } - - describe 'go to the future' do - it 'install ntpdate and check the year is current' do - apply_manifest("package { 'ntpdate': ensure => present }") - result = run_shell('date') - expect(result.stdout).to match(%r{#{Time.now.year}}) - end - - it 'disable ntp auto-sync' do - result = run_shell('timedatectl set-ntp false') - expect(result.exit_code).to eq(0) - end - - it 'go forward to to next year' do - result = run_shell('date --set="$(date --date="next year")"') - expect(result.stdout).to match(%r{#{Time.now.year + 1}}) - expect(result.exit_code).to eq(0) - end - - it 'changed to next year' do - result = run_shell('date') - expect(result.stdout).to match(%r{#{Time.now.year + 1}}) - end - end - end -end diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index c0be02ff..1a0d9f63 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -3,32 +3,3 @@ include PuppetLitmus UNSUPPORTED_PLATFORMS = ['windows', 'darwin'].freeze - -def inventory_hash - @inventory_hash ||= inventory_hash_from_inventory_file -end - -def target_roles(roles) - inventory_hash['groups'].map { |group| - group['targets'].filter_map do |node| - { name: node['uri'], role: node['vars']['role'] } if roles.include? node['vars']['role'] - end - }.flatten -end - -RSpec.configure do |config| - if config.filter.rules.key? :integration - ENV['TARGET_HOST'] = target_roles('ntpserver')[0][:name] - else - config.filter_run_excluding :integration - end -end - -def change_target_host(role) - @orig_target_host = ENV.fetch('TARGET_HOST', nil) - ENV['TARGET_HOST'] = target_roles(role)[0][:name] -end - -def reset_target_host - ENV['TARGET_HOST'] = @orig_target_host -end