From 9df597bd21ab031858fa2cd384b0cd4deeb819dd Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Sun, 29 Oct 2023 13:00:18 +0100 Subject: [PATCH] add dnfmodule repo implementation --- manifests/repo/dnfmodule.pp | 24 +++++++++++++++++++ spec/acceptance/class_spec.rb | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 manifests/repo/dnfmodule.pp diff --git a/manifests/repo/dnfmodule.pp b/manifests/repo/dnfmodule.pp new file mode 100644 index 00000000..3026aad6 --- /dev/null +++ b/manifests/repo/dnfmodule.pp @@ -0,0 +1,24 @@ +# @summary Manage the DNF module +# +# On EL8+ DNF can manage modules. +# This is a method of providing multiple versions on the same OS. +# Only one DNF module stream can be active at the same time. +# +# @param ensure +# Value of ensure parameter for nodejs dnf module package +# +# @param module +# Name of the nodejs dnf package +# +# @api private +class nodejs::repo::dnfmodule ( + String[1] $ensure = $nodejs::repo_version, + String[1] $module = 'nodejs', +) { + package { 'nodejs dnf module': + ensure => $ensure, + name => $module, + enable_only => true, + provider => 'dnfmodule', + } +} diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 9e26e738..a57e1298 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -65,6 +65,49 @@ class { 'nodejs': end end + context 'RedHat with repo_class => nodejs::repo::dnfmodule', if: fact('os.family') == 'RedHat' && %w[8 9].include?(fact('os.release.major')) do + include_examples 'cleanup' + + # Node 20 is only available in Stream yet, not in a released EL + # So we're testing 18 here + nodejs_version = '18' + + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + class { 'nodejs': + nodejs_dev_package_ensure => installed, + npm_package_ensure => installed, + repo_class => 'nodejs::repo::dnfmodule', + repo_version => '#{nodejs_version}', + } + PUPPET + end + end + + %w[ + npm + nodejs + nodejs-devel + ].each do |pkg| + describe package(pkg) do + it do + is_expected.to be_installed + end + + it 'comes from the expected source' do + pkg_output = shell(pkg_cmd) + expect(pkg_output.stdout).to match 'appstream' + end + end + end + + describe command('node --version') do + its(:exit_status) { is_expected.to eq 0 } + its(:stdout) { is_expected.to match(%r{^v#{nodejs_version}}) } + end + end + context 'Debian distribution packages', if: fact('os.family') == 'Debian' do before(:context) { purge_node }