From b91eb27c6e88c8831bffca49bf947c63f30cd306 Mon Sep 17 00:00:00 2001 From: Alessandro Franceschi Date: Wed, 18 Oct 2023 10:01:58 +0200 Subject: [PATCH 01/12] pdk test unit opn Puppet 8, 7 and 6 --- .github/workflows/pr.yml | 16 +++++++++-- README-legacy.md | 2 +- README.md | 2 +- manifests/conf.pp | 2 +- manifests/create_dir.pp | 58 +++++++++++++++++++++++++--------------- 5 files changed, 53 insertions(+), 27 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index db2230f..a0c85f9 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -23,7 +23,19 @@ jobs: container: puppet/puppet-dev-tools:4.x steps: - uses: actions/checkout@v3 - - name: Run unit tests - run: /usr/local/bin/pdk bundle exec rake spec + - name: Run unit tests on Puppet 8 + run: /usr/local/bin/pdk test unit --puppet-version=8 env: BUNDLE_WITHOUT: development:system_tests:release + continue-on-error: true + - name: Run unit tests on Puppet 7 + run: /usr/local/bin/pdk test unit --puppet-version=7 + env: + BUNDLE_WITHOUT: development:system_tests:release + continue-on-error: true + - name: Run unit tests on Puppet 6 + run: /usr/local/bin/pdk test unit --puppet-version=6 + env: + BUNDLE_WITHOUT: development:system_tests:release + continue-on-error: true + \ No newline at end of file diff --git a/README-legacy.md b/README-legacy.md index 293398e..7455796 100644 --- a/README-legacy.md +++ b/README-legacy.md @@ -178,7 +178,7 @@ Configure the application main configuration file a custom erb template which us tp::conf { 'rsyslog': template => 'site/rsyslog/rsyslog.conf.erb', - options_hash => hiera('rsyslog::options_hash'), + options_hash => lookup('rsyslog::options_hash'), } Populate any custom directory from a Git repository (it requires Puppet Labs' vcsrepo module): diff --git a/README.md b/README.md index 98fb2bd..2547299 100644 --- a/README.md +++ b/README.md @@ -195,7 +195,7 @@ Configure the application main configuration file a custom erb template which us tp::conf { 'rsyslog': template => 'site/rsyslog/rsyslog.conf.erb', - options_hash => hiera('rsyslog::options_hash'), + options_hash => lookup('rsyslog::options_hash'), } Populate any custom directory from a Git repository (it requires Puppet Labs' vcsrepo module): diff --git a/manifests/conf.pp b/manifests/conf.pp index a7f7400..7ae32f7 100644 --- a/manifests/conf.pp +++ b/manifests/conf.pp @@ -53,7 +53,7 @@ # # tp::conf { 'openssh': # template => 'site/openssh/sshd_config', -# options_hash => hiera('openssh::options_hash'), +# options_hash => lookup('openssh::options_hash'), # } # # diff --git a/manifests/create_dir.pp b/manifests/create_dir.pp index a34b8f5..7f98b16 100644 --- a/manifests/create_dir.pp +++ b/manifests/create_dir.pp @@ -13,31 +13,45 @@ Optional[String] $mode = undef, Stdlib::AbsolutePath $path = $title, ) { - exec { "mkdir -p ${title}": - command => "mkdir -p ${path}", - path => $facts['path'], - creates => $path, + + $mkdir_command = $facts['os']['family'] ? { + 'windows' => "New-Item -ItemType Directory -Force -Path '${path}'", + default => "mkdir -p '${path}'", } - if $owner { - exec { "chown ${owner} ${title}": - command => "chown ${owner} ${path}", - path => $facts['path'], - onlyif => "[ $(ls -ld ${path} | awk '{ print \$3 }') != ${owner} ]", - } + $command_provider = $facts['os']['family'] ? { + 'windows' => 'powershell', + default => undef, } - if $group { - exec { "chgrp ${group} ${title}": - command => "chgrp ${group} ${path}", - path => $facts['path'], - onlyif => "[ $(ls -ld ${path} | awk '{ print \$4 }') != ${group} ]", - } + + exec { "Create directory ${title}": + command => $mkdir_command, + path => $facts['path'], + creates => $path, + provider => $command_provider, } - if $mode { - exec { "chmod ${mode} ${title}": - command => "chmod ${mode} ${path}", - path => $facts['path'], - subscribe => Exec["mkdir -p ${title}"], - refreshonly => true, + + if $facts['os']['family'] != 'windows' { + if $owner { + exec { "chown ${owner} ${title}": + command => "chown '${owner}' '${path}'", + path => $facts['path'], + onlyif => "[ stat -c '%U' '${path}' != '${owner}' ]", + } + } + if $group { + exec { "chgrp ${group} ${title}": + command => "chgrp '${group}' '${path}'", + path => $facts['path'], + onlyif => "[ stat -c '%G' '${path}' != '${group}' ]", + } + } + if $mode { + exec { "chmod ${mode} ${title}": + command => "chmod '${mode}' '${path}'", + path => '/bin:/sbin:/usr/sbin:/usr/bin', + subscribe => Exec["Create directory ${title}"], + refreshonly => true, + } } } } From 07be61ca0621428ff98a0fdcb18422bb0257a988 Mon Sep 17 00:00:00 2001 From: Alessandro Franceschi Date: Wed, 18 Oct 2023 11:33:17 +0200 Subject: [PATCH 02/12] Test pdk container for github actions --- .github/workflows/pr.yml | 4 ++-- Gemfile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index a0c85f9..717cb15 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -8,7 +8,7 @@ jobs: name: 'Static code analysys' runs-on: ubuntu-latest timeout-minutes: 10 - container: puppet/puppet-dev-tools:4.x + container: puppet/pdk:3.0.0.0 steps: - uses: actions/checkout@v3 - name: Run static validations @@ -20,7 +20,7 @@ jobs: name: 'Unit tests' runs-on: ubuntu-latest timeout-minutes: 60 - container: puppet/puppet-dev-tools:4.x + container: puppet/pdk:3.0.0.0 steps: - uses: actions/checkout@v3 - name: Run unit tests on Puppet 8 diff --git a/Gemfile b/Gemfile index ff9af8b..3ab3510 100644 --- a/Gemfile +++ b/Gemfile @@ -34,7 +34,7 @@ group :development do gem "rubocop", '= 1.48.1', require: false gem "rubocop-performance", '= 1.16.0', require: false gem "rubocop-rspec", '= 2.19.0', require: false - gem "puppet-strings", '~> 3.0', require: false + gem "puppet-strings", '~> 2.0', require: false gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] end group :system_tests do From 6f8c1e841669377a41ac956c5bc32c9c0e741098 Mon Sep 17 00:00:00 2001 From: Alessandro Franceschi Date: Thu, 19 Oct 2023 12:41:46 +0200 Subject: [PATCH 03/12] Fixed Unknown variable: 'real_base_url' --- manifests/install.pp | 54 ++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/manifests/install.pp b/manifests/install.pp index fb3e8e4..52b9ddd 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -239,34 +239,34 @@ $extracted_file = getvar('tp_settings.release.extracted_file') $local_settings = delete_undef_values({ - install_method => $real_install_method, - repo => $repo, - upstream_repo => $upstream_repo, - git_source => $real_install_method ? { - 'source' => $source, - default => undef, - }, - destination => $real_install_method ? { - 'source' => pick($destination, "${tp::data_dir}/source/${app}"), - 'release' => pick($destination, "${tp::data_dir}/download/${app}"), - default => undef, - }, - packages => delete_undef_values({ - main => delete_undef_values({ - name => tp::title_replace(getvar('settings.packages.main.name'),$app), - }), - }), - release => delete_undef_values({ - base_url => pick_default($real_base_url), - file_name => $real_filename, - url => $real_url, - extracted_dir => $extracted_dir, - extracted_file => $extracted_file, - setup => delete_undef_values({ - enable => getvar('tp_settings.release.setup.enable'), - links => getvar('tp_settings.release.setup.links'), - }), + install_method => $real_install_method, + repo => $repo, + upstream_repo => $upstream_repo, + git_source => $real_install_method ? { + 'source' => $source, + default => undef, + }, + destination => $real_install_method ? { + 'source' => pick($destination, "${tp::data_dir}/source/${app}"), + 'release' => pick($destination, "${tp::data_dir}/download/${app}"), + default => undef, + }, + packages => delete_undef_values({ + main => delete_undef_values({ + name => tp::title_replace(getvar('settings.packages.main.name'),$app), + }), + }), + release => delete_undef_values({ + base_url => pick_default(getvar('real_base_url')), + file_name => $real_filename, + url => $real_url, + extracted_dir => $extracted_dir, + extracted_file => $extracted_file, + setup => delete_undef_values({ + enable => getvar('tp_settings.release.setup.enable'), + links => getvar('tp_settings.release.setup.links'), }), + }), }) $settings = deep_merge($tp_settings,$settings_hash,$my_settings,$local_settings) From 5d171cbb6bbc2a687364c2f58979eda57e00bd52 Mon Sep 17 00:00:00 2001 From: Alessandro Franceschi Date: Thu, 19 Oct 2023 14:11:23 +0200 Subject: [PATCH 04/12] Lints --- manifests/conf.pp | 22 +++++++++---------- manifests/dir.pp | 36 +++++++++++++++--------------- manifests/install.pp | 52 +++++++++++++++++++++----------------------- 3 files changed, 54 insertions(+), 56 deletions(-) diff --git a/manifests/conf.pp b/manifests/conf.pp index 7ae32f7..c5dedcc 100644 --- a/manifests/conf.pp +++ b/manifests/conf.pp @@ -300,20 +300,20 @@ $real_path = "${path_prefix}${calculated_path}" $local_file_params = delete_undef_values({ - 'path' => $real_path, - 'mode' => $mode, - 'owner' => $owner, - 'group' => $group, + 'path' => $real_path, + 'mode' => $mode, + 'owner' => $owner, + 'group' => $group, }) $local_settings = delete_undef_values({ - "${prefix}files" => { - "${base_file}" => $local_file_params, - }, - "${base_file}_file_mode" => $mode, - "${base_file}_file_owner" => $owner, - "${base_file}_file_group" => $group, - "${base_file}_file_path" => $real_path, + "${prefix}files" => { + "${base_file}" => $local_file_params, + }, + "${base_file}_file_mode" => $mode, + "${base_file}_file_owner" => $owner, + "${base_file}_file_group" => $group, + "${base_file}_file_path" => $real_path, }) $settings = deep_merge($tp_settings,$settings_hash,$my_settings,$local_settings) diff --git a/manifests/dir.pp b/manifests/dir.pp index bc7d504..f9a8171 100644 --- a/manifests/dir.pp +++ b/manifests/dir.pp @@ -213,26 +213,26 @@ $real_path = "${path_prefix}${calculated_path}" $local_file_params = delete_undef_values({ - 'path' => $real_path, - 'mode' => $mode, - 'owner' => $owner, - 'group' => $group, - 'recurse' => $recurse, - 'purge' => $purge, - 'force' => $force, + 'path' => $real_path, + 'mode' => $mode, + 'owner' => $owner, + 'group' => $group, + 'recurse' => $recurse, + 'purge' => $purge, + 'force' => $force, }) $local_settings = delete_undef_values({ - "${prefix}dirs" => { - "${base_dir}" => $local_file_params, - }, - "${base_dir}_dir_mode" => $mode, - "${base_dir}_dir_owner" => $owner, - "${base_dir}_dir_group" => $group, - "${base_dir}_dir_path" => $real_path, - "${base_dir}_dir_recurse" => $recurse, - "${base_dir}_dir_purge" => $purge, - "${base_dir}_dir_force" => $force, + "${prefix}dirs" => { + "${base_dir}" => $local_file_params, + }, + "${base_dir}_dir_mode" => $mode, + "${base_dir}_dir_owner" => $owner, + "${base_dir}_dir_group" => $group, + "${base_dir}_dir_path" => $real_path, + "${base_dir}_dir_recurse" => $recurse, + "${base_dir}_dir_purge" => $purge, + "${base_dir}_dir_force" => $force, }) $settings = deep_merge($tp_settings,$settings_hash,$my_settings,$local_settings) @@ -314,7 +314,7 @@ notify => $real_notify, recurse => $real_recurse, purge => $real_purge, - # force => $real_force, + # force => $real_force, } file { $real_path: * => $file_params + pick(getvar("settings.${base_dir}_dir_params"),getvar("settings.${prefix}dirs.${base_dir}.params"), {}), diff --git a/manifests/install.pp b/manifests/install.pp index 52b9ddd..3aae709 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -239,34 +239,32 @@ $extracted_file = getvar('tp_settings.release.extracted_file') $local_settings = delete_undef_values({ - install_method => $real_install_method, - repo => $repo, - upstream_repo => $upstream_repo, - git_source => $real_install_method ? { - 'source' => $source, - default => undef, - }, - destination => $real_install_method ? { - 'source' => pick($destination, "${tp::data_dir}/source/${app}"), - 'release' => pick($destination, "${tp::data_dir}/download/${app}"), - default => undef, - }, - packages => delete_undef_values({ - main => delete_undef_values({ - name => tp::title_replace(getvar('settings.packages.main.name'),$app), - }), - }), - release => delete_undef_values({ - base_url => pick_default(getvar('real_base_url')), - file_name => $real_filename, - url => $real_url, - extracted_dir => $extracted_dir, - extracted_file => $extracted_file, - setup => delete_undef_values({ - enable => getvar('tp_settings.release.setup.enable'), - links => getvar('tp_settings.release.setup.links'), + install_method => $real_install_method, + repo => $repo, + upstream_repo => $upstream_repo, + git_source => $real_install_method ? { + 'source' => $source, + default => undef, + }, + destination => $real_install_method ? { + 'source' => pick($destination, "${tp::data_dir}/source/${app}"), + 'release' => pick($destination, "${tp::data_dir}/download/${app}"), + default => undef, + }, + packages => delete_undef_values({ + name => tp::title_replace(getvar('settings.packages.main.name'),$app), + }), + release => delete_undef_values({ + base_url => pick_default(getvar('real_base_url')), + file_name => $real_filename, + url => $real_url, + extracted_dir => $extracted_dir, + extracted_file => $extracted_file, + setup => delete_undef_values({ + enable => getvar('tp_settings.release.setup.enable'), + links => getvar('tp_settings.release.setup.links'), + }), }), - }), }) $settings = deep_merge($tp_settings,$settings_hash,$my_settings,$local_settings) From 4ff40209b52a9c2c7d65daa3aaeae9a27f35e10c Mon Sep 17 00:00:00 2001 From: Alessandro Franceschi Date: Thu, 19 Oct 2023 14:38:53 +0200 Subject: [PATCH 05/12] Lints and undef fixes --- CHANGELOG.md | 6 ++++++ manifests/install.pp | 18 +++++++++--------- metadata.json | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0967f7..4747996 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## 3.10.1 + +- Changed CI containers used +- Added unit tests for Puppet 6, 7 and 8 +- Lints and fix on undefined vars + ## 3.10.0 - Added support for $MAJVERSION variable in tinydata diff --git a/manifests/install.pp b/manifests/install.pp index 3aae709..e8b054c 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -239,11 +239,11 @@ $extracted_file = getvar('tp_settings.release.extracted_file') $local_settings = delete_undef_values({ - install_method => $real_install_method, - repo => $repo, - upstream_repo => $upstream_repo, + install_method => getvar('real_install_method'), + repo => getvar('repo'), + upstream_repo => getvar('upstream_repo'), git_source => $real_install_method ? { - 'source' => $source, + 'source' => getvar('source'), default => undef, }, destination => $real_install_method ? { @@ -255,11 +255,11 @@ name => tp::title_replace(getvar('settings.packages.main.name'),$app), }), release => delete_undef_values({ - base_url => pick_default(getvar('real_base_url')), - file_name => $real_filename, - url => $real_url, - extracted_dir => $extracted_dir, - extracted_file => $extracted_file, + base_url => getvar('real_base_url'), + file_name => getvar('real_filename'), + url => getvar('real_url'), + extracted_dir => getvar('extracted_dir'), + extracted_file => getvar('extracted_file'), setup => delete_undef_values({ enable => getvar('tp_settings.release.setup.enable'), links => getvar('tp_settings.release.setup.links'), diff --git a/metadata.json b/metadata.json index ea9c5dc..a04eb73 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "example42-tp", - "version": "3.10.0", + "version": "3.10.1", "author": "example42", "summary": "Tiny Puppet", "license": "Apache-2.0", From 60f874419933307919fc9a4dd5ab982f9981ee86 Mon Sep 17 00:00:00 2001 From: Alessandro Franceschi Date: Thu, 19 Oct 2023 14:51:52 +0200 Subject: [PATCH 06/12] Lints. Remove unit tests on Puppet 6 --- .github/workflows/pr.yml | 6 +----- CHANGELOG.md | 2 +- manifests/conf.pp | 2 +- manifests/create_dir.pp | 1 - manifests/dir.pp | 2 +- manifests/init.pp | 6 +++--- 6 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 717cb15..1b81869 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -33,9 +33,5 @@ jobs: env: BUNDLE_WITHOUT: development:system_tests:release continue-on-error: true - - name: Run unit tests on Puppet 6 - run: /usr/local/bin/pdk test unit --puppet-version=6 - env: - BUNDLE_WITHOUT: development:system_tests:release - continue-on-error: true + \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 4747996..ae5f68b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## 3.10.1 - Changed CI containers used -- Added unit tests for Puppet 6, 7 and 8 +- Unit tests for Puppet 7 and 8 - Lints and fix on undefined vars ## 3.10.0 diff --git a/manifests/conf.pp b/manifests/conf.pp index c5dedcc..026c83b 100644 --- a/manifests/conf.pp +++ b/manifests/conf.pp @@ -237,7 +237,7 @@ Variant[Undef,String] $owner = undef, Variant[Undef,String] $group = undef, - String $path_prefix = '', + String $path_prefix = '', # lint:ignore:params_empty_string_assignment Boolean $path_parent_create = false, Variant[Boolean,String] $config_file_notify = true, diff --git a/manifests/create_dir.pp b/manifests/create_dir.pp index 7f98b16..ec5174c 100644 --- a/manifests/create_dir.pp +++ b/manifests/create_dir.pp @@ -13,7 +13,6 @@ Optional[String] $mode = undef, Stdlib::AbsolutePath $path = $title, ) { - $mkdir_command = $facts['os']['family'] ? { 'windows' => "New-Item -ItemType Directory -Force -Path '${path}'", default => "mkdir -p '${path}'", diff --git a/manifests/dir.pp b/manifests/dir.pp index f9a8171..d6e8275 100644 --- a/manifests/dir.pp +++ b/manifests/dir.pp @@ -155,7 +155,7 @@ Enum['global','user'] $scope = 'global', - String $path_prefix = '', + String $path_prefix = '', # lint:ignore:params_empty_string_assignment Boolean $path_parent_create = false, Variant[Boolean,String] $config_dir_notify = true, diff --git a/manifests/init.pp b/manifests/init.pp index 226d626..4a77af8 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -34,10 +34,10 @@ String $tp_group = 'root', String $tp_mode = '0755', String $check_service_command = 'puppet resource service', - String $check_service_command_post = '', + String $check_service_command_post = '', # lint:ignore:params_empty_string_assignment String $check_package_command = 'puppet resource package', - String $check_repo_path = '', - String $check_repo_path_post = '', + String $check_repo_path = '', # lint:ignore:params_empty_string_assignment + String $check_repo_path_post = '', # lint:ignore:params_empty_string_assignment #Stdlib::Absolutepath $tp_dir = '/etc/tp', Optional[String] $ruby_path = undef, String $lib_source = 'puppet:///modules/tp/lib/', From 638c40ee2fc1fd822d24436e6264563d8087b323 Mon Sep 17 00:00:00 2001 From: Alessandro Franceschi Date: Thu, 19 Oct 2023 19:44:09 +0200 Subject: [PATCH 07/12] Adapt tp data for spec tests --- manifests/create_dir.pp | 13 ++++++------- manifests/dir.pp | 2 +- spec/tpdata/centos-7-x86_64/elasticsearch | 2 +- spec/tpdata/centos-7-x86_64/gitlab-runner | 2 +- spec/tpdata/centos-7-x86_64/icinga2 | 2 +- spec/tpdata/centos-7-x86_64/openssh | 2 +- spec/tpdata/centos-7-x86_64/postfix | 2 +- spec/tpdata/centos-7-x86_64/puppet | 2 +- spec/tpdata/centos-7-x86_64/puppet-agent | 2 +- spec/tpdata/centos-7-x86_64/rsyslog | 2 +- spec/tpdata/centos-7-x86_64/sysdig | 2 +- spec/tpdata/redhat-8-x86_64/elasticsearch | 2 +- spec/tpdata/redhat-8-x86_64/icinga2 | 2 +- spec/tpdata/redhat-8-x86_64/openssh | 2 +- spec/tpdata/redhat-8-x86_64/rsyslog | 2 +- spec/tpdata/redhat-8-x86_64/sysdig | 2 +- spec/tpdata/ubuntu-16.04-x86_64/elasticsearch | 2 +- spec/tpdata/ubuntu-16.04-x86_64/icinga2 | 2 +- spec/tpdata/ubuntu-16.04-x86_64/openssh | 2 +- spec/tpdata/ubuntu-16.04-x86_64/postfix | 2 +- spec/tpdata/ubuntu-16.04-x86_64/puppet | 2 +- spec/tpdata/ubuntu-16.04-x86_64/puppet-agent | 2 +- spec/tpdata/ubuntu-16.04-x86_64/rsyslog | 2 +- spec/tpdata/ubuntu-16.04-x86_64/sysdig | 2 +- spec/tpdata/ubuntu-22.04-x86_64/elasticsearch | 2 +- spec/tpdata/ubuntu-22.04-x86_64/icinga2 | 2 +- spec/tpdata/ubuntu-22.04-x86_64/openssh | 2 +- spec/tpdata/ubuntu-22.04-x86_64/rsyslog | 2 +- spec/tpdata/ubuntu-22.04-x86_64/sysdig | 2 +- 29 files changed, 34 insertions(+), 35 deletions(-) diff --git a/manifests/create_dir.pp b/manifests/create_dir.pp index ec5174c..24911d6 100644 --- a/manifests/create_dir.pp +++ b/manifests/create_dir.pp @@ -10,7 +10,7 @@ define tp::create_dir ( Optional[String] $owner = undef, Optional[String] $group = undef, - Optional[String] $mode = undef, + Optional[Stdlib::Filemode] $mode = undef, Stdlib::AbsolutePath $path = $title, ) { $mkdir_command = $facts['os']['family'] ? { @@ -34,22 +34,21 @@ exec { "chown ${owner} ${title}": command => "chown '${owner}' '${path}'", path => $facts['path'], - onlyif => "[ stat -c '%U' '${path}' != '${owner}' ]", + onlyif => "[ \$(stat -c '%U' '${path}') != '${owner}' ]", } } if $group { exec { "chgrp ${group} ${title}": command => "chgrp '${group}' '${path}'", path => $facts['path'], - onlyif => "[ stat -c '%G' '${path}' != '${group}' ]", + onlyif => "[ \$(stat -c '%G' '${path}') != '${group}' ]", } } if $mode { exec { "chmod ${mode} ${title}": - command => "chmod '${mode}' '${path}'", - path => '/bin:/sbin:/usr/sbin:/usr/bin', - subscribe => Exec["Create directory ${title}"], - refreshonly => true, + command => "chmod '${mode}' '${path}'", + path => '/bin:/sbin:/usr/sbin:/usr/bin', + onlyif => "[ 0\$(stat -c '%a' '${path}') != '${mode}' ]", } } } diff --git a/manifests/dir.pp b/manifests/dir.pp index d6e8275..6bb4c97 100644 --- a/manifests/dir.pp +++ b/manifests/dir.pp @@ -236,7 +236,7 @@ }) $settings = deep_merge($tp_settings,$settings_hash,$my_settings,$local_settings) - $real_mode = pick_default(getvar("settings.${base_dir}_dir_mode"), getvar("settings.${prefix}dirs.${base_dir}.mode"), getvar('settings.config_dir_mode'), undef) + $real_mode = pick_default(getvar("settings.${base_dir}_dir_mode"), getvar("settings.${prefix}dirs.${base_dir}.mode"), getvar('settings.config_dir_mode'), '0755') $real_owner = pick_default(getvar("settings.${base_dir}_dir_owner"), getvar("settings.${prefix}dirs.${base_dir}.owner"), getvar('settings.config_dir_owner'), undef) $real_group = pick_default(getvar("settings.${base_dir}_dir_group"), getvar("settings.${prefix}dirs.${base_dir}.group"), getvar('settings.config_dir_group'), undef) $real_recurse = pick_default(getvar("settings.${base_dir}_dir_recurse"), getvar("settings.${prefix}dirs.${base_dir}.recurse"), getvar('settings.config__dir_recurse'), undef) diff --git a/spec/tpdata/centos-7-x86_64/elasticsearch b/spec/tpdata/centos-7-x86_64/elasticsearch index 0a6bc21..02665ca 100644 --- a/spec/tpdata/centos-7-x86_64/elasticsearch +++ b/spec/tpdata/centos-7-x86_64/elasticsearch @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true repo_package_provider: rpm diff --git a/spec/tpdata/centos-7-x86_64/gitlab-runner b/spec/tpdata/centos-7-x86_64/gitlab-runner index f7315ae..9dfd28d 100644 --- a/spec/tpdata/centos-7-x86_64/gitlab-runner +++ b/spec/tpdata/centos-7-x86_64/gitlab-runner @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true package_name: gitlab-ci-multi-runner diff --git a/spec/tpdata/centos-7-x86_64/icinga2 b/spec/tpdata/centos-7-x86_64/icinga2 index b5a3503..4cbf44b 100644 --- a/spec/tpdata/centos-7-x86_64/icinga2 +++ b/spec/tpdata/centos-7-x86_64/icinga2 @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0640' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true package_name: icinga2 diff --git a/spec/tpdata/centos-7-x86_64/openssh b/spec/tpdata/centos-7-x86_64/openssh index 41f2e8c..01d05a2 100644 --- a/spec/tpdata/centos-7-x86_64/openssh +++ b/spec/tpdata/centos-7-x86_64/openssh @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0600' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true package_name: openssh-server diff --git a/spec/tpdata/centos-7-x86_64/postfix b/spec/tpdata/centos-7-x86_64/postfix index e403783..a90db5f 100644 --- a/spec/tpdata/centos-7-x86_64/postfix +++ b/spec/tpdata/centos-7-x86_64/postfix @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true package_name: postfix diff --git a/spec/tpdata/centos-7-x86_64/puppet b/spec/tpdata/centos-7-x86_64/puppet index 66bf5e0..ff9dcad 100644 --- a/spec/tpdata/centos-7-x86_64/puppet +++ b/spec/tpdata/centos-7-x86_64/puppet @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true package_name: puppet-agent diff --git a/spec/tpdata/centos-7-x86_64/puppet-agent b/spec/tpdata/centos-7-x86_64/puppet-agent index 66bf5e0..ff9dcad 100644 --- a/spec/tpdata/centos-7-x86_64/puppet-agent +++ b/spec/tpdata/centos-7-x86_64/puppet-agent @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true package_name: puppet-agent diff --git a/spec/tpdata/centos-7-x86_64/rsyslog b/spec/tpdata/centos-7-x86_64/rsyslog index e92edb8..eee4aae 100644 --- a/spec/tpdata/centos-7-x86_64/rsyslog +++ b/spec/tpdata/centos-7-x86_64/rsyslog @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true package_name: rsyslog diff --git a/spec/tpdata/centos-7-x86_64/sysdig b/spec/tpdata/centos-7-x86_64/sysdig index ecb2424..28de23d 100644 --- a/spec/tpdata/centos-7-x86_64/sysdig +++ b/spec/tpdata/centos-7-x86_64/sysdig @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true package_name: sysdig diff --git a/spec/tpdata/redhat-8-x86_64/elasticsearch b/spec/tpdata/redhat-8-x86_64/elasticsearch index da96f74..8c059b2 100644 --- a/spec/tpdata/redhat-8-x86_64/elasticsearch +++ b/spec/tpdata/redhat-8-x86_64/elasticsearch @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true install_method: package diff --git a/spec/tpdata/redhat-8-x86_64/icinga2 b/spec/tpdata/redhat-8-x86_64/icinga2 index b3b531e..81129f0 100644 --- a/spec/tpdata/redhat-8-x86_64/icinga2 +++ b/spec/tpdata/redhat-8-x86_64/icinga2 @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0640' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true install_method: package diff --git a/spec/tpdata/redhat-8-x86_64/openssh b/spec/tpdata/redhat-8-x86_64/openssh index bb0d606..f08f170 100644 --- a/spec/tpdata/redhat-8-x86_64/openssh +++ b/spec/tpdata/redhat-8-x86_64/openssh @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0600' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true install_method: package diff --git a/spec/tpdata/redhat-8-x86_64/rsyslog b/spec/tpdata/redhat-8-x86_64/rsyslog index 06364c0..faae9d2 100644 --- a/spec/tpdata/redhat-8-x86_64/rsyslog +++ b/spec/tpdata/redhat-8-x86_64/rsyslog @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true install_method: package diff --git a/spec/tpdata/redhat-8-x86_64/sysdig b/spec/tpdata/redhat-8-x86_64/sysdig index bce354c..1f663a0 100644 --- a/spec/tpdata/redhat-8-x86_64/sysdig +++ b/spec/tpdata/redhat-8-x86_64/sysdig @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true install_method: package diff --git a/spec/tpdata/ubuntu-16.04-x86_64/elasticsearch b/spec/tpdata/ubuntu-16.04-x86_64/elasticsearch index f4c55e1..27df8fd 100644 --- a/spec/tpdata/ubuntu-16.04-x86_64/elasticsearch +++ b/spec/tpdata/ubuntu-16.04-x86_64/elasticsearch @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true package_name: elasticsearch diff --git a/spec/tpdata/ubuntu-16.04-x86_64/icinga2 b/spec/tpdata/ubuntu-16.04-x86_64/icinga2 index 24155cf..a889925 100644 --- a/spec/tpdata/ubuntu-16.04-x86_64/icinga2 +++ b/spec/tpdata/ubuntu-16.04-x86_64/icinga2 @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true package_name: icinga2 diff --git a/spec/tpdata/ubuntu-16.04-x86_64/openssh b/spec/tpdata/ubuntu-16.04-x86_64/openssh index 104abe4..cc3213a 100644 --- a/spec/tpdata/ubuntu-16.04-x86_64/openssh +++ b/spec/tpdata/ubuntu-16.04-x86_64/openssh @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true package_name: openssh-server diff --git a/spec/tpdata/ubuntu-16.04-x86_64/postfix b/spec/tpdata/ubuntu-16.04-x86_64/postfix index 52bf405..a742ee2 100644 --- a/spec/tpdata/ubuntu-16.04-x86_64/postfix +++ b/spec/tpdata/ubuntu-16.04-x86_64/postfix @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true package_name: postfix diff --git a/spec/tpdata/ubuntu-16.04-x86_64/puppet b/spec/tpdata/ubuntu-16.04-x86_64/puppet index a7cf489..619bce6 100644 --- a/spec/tpdata/ubuntu-16.04-x86_64/puppet +++ b/spec/tpdata/ubuntu-16.04-x86_64/puppet @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true package_name: puppet-agent diff --git a/spec/tpdata/ubuntu-16.04-x86_64/puppet-agent b/spec/tpdata/ubuntu-16.04-x86_64/puppet-agent index a7cf489..619bce6 100644 --- a/spec/tpdata/ubuntu-16.04-x86_64/puppet-agent +++ b/spec/tpdata/ubuntu-16.04-x86_64/puppet-agent @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true package_name: puppet-agent diff --git a/spec/tpdata/ubuntu-16.04-x86_64/rsyslog b/spec/tpdata/ubuntu-16.04-x86_64/rsyslog index f51fb96..29673a6 100644 --- a/spec/tpdata/ubuntu-16.04-x86_64/rsyslog +++ b/spec/tpdata/ubuntu-16.04-x86_64/rsyslog @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true package_name: rsyslog diff --git a/spec/tpdata/ubuntu-16.04-x86_64/sysdig b/spec/tpdata/ubuntu-16.04-x86_64/sysdig index 95483d9..db9102a 100644 --- a/spec/tpdata/ubuntu-16.04-x86_64/sysdig +++ b/spec/tpdata/ubuntu-16.04-x86_64/sysdig @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true repo_package_provider: dpkg diff --git a/spec/tpdata/ubuntu-22.04-x86_64/elasticsearch b/spec/tpdata/ubuntu-22.04-x86_64/elasticsearch index d743658..af86a51 100644 --- a/spec/tpdata/ubuntu-22.04-x86_64/elasticsearch +++ b/spec/tpdata/ubuntu-22.04-x86_64/elasticsearch @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true install_method: package diff --git a/spec/tpdata/ubuntu-22.04-x86_64/icinga2 b/spec/tpdata/ubuntu-22.04-x86_64/icinga2 index d461d38..8a97850 100644 --- a/spec/tpdata/ubuntu-22.04-x86_64/icinga2 +++ b/spec/tpdata/ubuntu-22.04-x86_64/icinga2 @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true install_method: package diff --git a/spec/tpdata/ubuntu-22.04-x86_64/openssh b/spec/tpdata/ubuntu-22.04-x86_64/openssh index d382ac1..8aac5e2 100644 --- a/spec/tpdata/ubuntu-22.04-x86_64/openssh +++ b/spec/tpdata/ubuntu-22.04-x86_64/openssh @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true install_method: package diff --git a/spec/tpdata/ubuntu-22.04-x86_64/rsyslog b/spec/tpdata/ubuntu-22.04-x86_64/rsyslog index af28736..c4274c3 100644 --- a/spec/tpdata/ubuntu-22.04-x86_64/rsyslog +++ b/spec/tpdata/ubuntu-22.04-x86_64/rsyslog @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true install_method: package diff --git a/spec/tpdata/ubuntu-22.04-x86_64/sysdig b/spec/tpdata/ubuntu-22.04-x86_64/sysdig index 9a9aca3..27b78e4 100644 --- a/spec/tpdata/ubuntu-22.04-x86_64/sysdig +++ b/spec/tpdata/ubuntu-22.04-x86_64/sysdig @@ -8,7 +8,7 @@ config_file_group: root config_file_mode: '0644' config_dir_owner: root config_dir_group: root -config_dir_mode: '0755' +config_dir_mode: '0644' config_dir_purge: false config_dir_recurse: true install_method: package From b5b90190aee0921b11b44850c8d17e48778ed241 Mon Sep 17 00:00:00 2001 From: Alessandro Franceschi Date: Thu, 19 Oct 2023 19:57:02 +0200 Subject: [PATCH 08/12] Disable param documentation check in puppet lint --- .puppet-lint.rc | 1 + 1 file changed, 1 insertion(+) diff --git a/.puppet-lint.rc b/.puppet-lint.rc index cc96ece..23fc5f9 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -1 +1,2 @@ --relative +--no-parameter-documentation-check \ No newline at end of file From 27336f90f6c89ef7f385385f7c82fd52aaa23f22 Mon Sep 17 00:00:00 2001 From: Alessandro Franceschi Date: Thu, 19 Oct 2023 20:00:50 +0200 Subject: [PATCH 09/12] Disable param documentation check in puppet lint --- .puppet-lint.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.puppet-lint.rc b/.puppet-lint.rc index 23fc5f9..bcb46cc 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -1,2 +1,2 @@ --relative ---no-parameter-documentation-check \ No newline at end of file +--no-parameter_documentation-check From 76e12d8bcbab0b0db350b557f09108c037fb2e8f Mon Sep 17 00:00:00 2001 From: Alessandro Franceschi Date: Thu, 19 Oct 2023 20:11:15 +0200 Subject: [PATCH 10/12] Lints and fixes --- manifests/cli.pp | 2 +- manifests/create_dir.pp | 6 +++--- manifests/install.pp | 2 +- manifests/install/package.pp | 4 ++-- manifests/repo.pp | 2 +- manifests/setup.pp | 2 +- manifests/stdmod.pp | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifests/cli.pp b/manifests/cli.pp index 528cd63..ebfede9 100644 --- a/manifests/cli.pp +++ b/manifests/cli.pp @@ -4,7 +4,7 @@ class tp::cli ( Enum['present','absent'] $ensure = 'present', Boolean $manage_tp = true, - Hash $tp_commands = lookup('tp::tp_commands', {}), + Hash $tp_commands = pick($tp::tp_commands, {}), Hash $options = {}, Boolean $purge_dirs = true, diff --git a/manifests/create_dir.pp b/manifests/create_dir.pp index 24911d6..01ed386 100644 --- a/manifests/create_dir.pp +++ b/manifests/create_dir.pp @@ -46,9 +46,9 @@ } if $mode { exec { "chmod ${mode} ${title}": - command => "chmod '${mode}' '${path}'", - path => '/bin:/sbin:/usr/sbin:/usr/bin', - onlyif => "[ 0\$(stat -c '%a' '${path}') != '${mode}' ]", + command => "chmod '${mode}' '${path}'", + path => '/bin:/sbin:/usr/sbin:/usr/bin', + onlyif => "[ 0\$(stat -c '%a' '${path}') != '${mode}' ]", } } } diff --git a/manifests/install.pp b/manifests/install.pp index e8b054c..86e094f 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -187,7 +187,7 @@ Hash $tp_repo_params = {}, Boolean $manage_package = true, Boolean $manage_service = true, - Boolean $apt_safe_trusted_key = lookup('tp::apt_safe_trusted_key', Boolean , first, false), + Boolean $apt_safe_trusted_key = pick(getvar('tp::apt_safe_trusted_key'), false), Boolean $cli_enable = pick(getvar('tp::cli_enable'), false), Boolean $puppi_enable = false, diff --git a/manifests/install/package.pp b/manifests/install/package.pp index f0380cc..e12aa2e 100644 --- a/manifests/install/package.pp +++ b/manifests/install/package.pp @@ -104,7 +104,7 @@ Hash $tp_repo_params = {}, Boolean $manage_package = true, Boolean $manage_service = true, - Boolean $apt_safe_trusted_key = lookup('tp::apt_safe_trusted_key', Boolean , first, false), + Boolean $apt_safe_trusted_key = pick(getvar('tp::apt_safe_trusted_key'), false), String[1] $data_module = 'tinydata', @@ -345,7 +345,7 @@ } $services.each |$k| { service { $k: - * => $service_defaults + pick(getvar("settings.services.${kk}.params"), getvar('settings.service_params'), {}), + * => $service_defaults + pick(getvar("settings.services.${k}.params"), getvar('settings.service_params'), {}), } } } diff --git a/manifests/repo.pp b/manifests/repo.pp index 80d4bc3..7884949 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -29,7 +29,7 @@ Variant[Undef,String[1]] $apt_release = undef, Variant[Undef,String[1]] $apt_repos = undef, Variant[Undef,String[1]] $apt_pin = undef, - Boolean $apt_safe_trusted_key = lookup('tp::apt_safe_trusted_key', Boolean , first, false), + Boolean $apt_safe_trusted_key = pick(getvar('tp::apt_safe_trusted_key'), false), Stdlib::Absolutepath $apt_gpg_key_dir = '/etc/apt/keyrings', Variant[Undef,String[1]] $zypper_repofile_url = undef, diff --git a/manifests/setup.pp b/manifests/setup.pp index 9f32711..87340a3 100644 --- a/manifests/setup.pp +++ b/manifests/setup.pp @@ -7,8 +7,8 @@ # tp::setup { 'namevar': } define tp::setup ( Tp::Install_method $install_method, - Optional[StdLib::Absolutepath] $source_dir, String $app, + Optional[StdLib::Absolutepath] $source_dir = undef, Variant[Boolean,String] $ensure = present, Optional[String] $version = undef, Tp::Fail $on_missing_data = pick(getvar('tp::on_missing_data'),'notify'), diff --git a/manifests/stdmod.pp b/manifests/stdmod.pp index 03915bd..f8d9518 100644 --- a/manifests/stdmod.pp +++ b/manifests/stdmod.pp @@ -109,7 +109,7 @@ default => $service_ensure, } $config_dir_ensure = directory - $config_file_ensure = present + $config_file_ensure = file } # Dependency class @@ -173,7 +173,7 @@ if $debug == true { $debug_scope = inline_template('<%= scope.to_hash.reject { |k,v| k.to_s =~ /(uptime.*|path|timestamp|free|.*password.*)/ } %>') file { "tp_stdmod_debug_${title}": - ensure => present, + ensure => $config_file_ensure , content => $debug_scope, path => "${debug_dir}/tp_stdmod_debug_${title}", } From cd82668dd83afd284f547e1f3cf6f9b1c795998a Mon Sep 17 00:00:00 2001 From: Alessandro Franceschi Date: Thu, 19 Oct 2023 23:16:03 +0200 Subject: [PATCH 11/12] Fixing tests --- .github/workflows/pr.yml | 4 ++-- Gemfile | 8 ++++---- manifests/install.pp | 2 +- spec/defines/stdmod_spec.rb | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 1b81869..f724bef 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -24,12 +24,12 @@ jobs: steps: - uses: actions/checkout@v3 - name: Run unit tests on Puppet 8 - run: /usr/local/bin/pdk test unit --puppet-version=8 + run: /usr/local/bin/pdk test unit --puppet-version=8 --parallel env: BUNDLE_WITHOUT: development:system_tests:release continue-on-error: true - name: Run unit tests on Puppet 7 - run: /usr/local/bin/pdk test unit --puppet-version=7 + run: /usr/local/bin/pdk test unit --puppet-version=7 --parallel env: BUNDLE_WITHOUT: development:system_tests:release continue-on-error: true diff --git a/Gemfile b/Gemfile index 3ab3510..eb45bfe 100644 --- a/Gemfile +++ b/Gemfile @@ -37,10 +37,10 @@ group :development do gem "puppet-strings", '~> 2.0', require: false gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] end -group :system_tests do - gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] - gem "serverspec", '~> 2.41', require: false -end +#group :system_tests do +# gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] +# gem "serverspec", '~> 2.41', require: false +#end puppet_version = ENV['PUPPET_GEM_VERSION'] facter_version = ENV['FACTER_GEM_VERSION'] diff --git a/manifests/install.pp b/manifests/install.pp index 86e094f..ac773ff 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -287,7 +287,7 @@ tp::setup { "tp::install::${real_install_method} ${app}": ensure => $ensure, version => $real_version, - install_method => $real_install_method, + install_method => $real_install_method, source_dir => getvar('settings.destination'), app => $app, on_missing_data => $on_missing_data, diff --git a/spec/defines/stdmod_spec.rb b/spec/defines/stdmod_spec.rb index 0aee2bb..54af9ee 100644 --- a/spec/defines/stdmod_spec.rb +++ b/spec/defines/stdmod_spec.rb @@ -19,7 +19,7 @@ 'enable' => true, } default_file_params = { - 'ensure' => 'present', + 'ensure' => 'file', 'owner' => 'root', 'group' => 'root', 'mode' => '0644', From c59cc8f524f456caf169022ade512d86a40081d9 Mon Sep 17 00:00:00 2001 From: Alessandro Franceschi Date: Thu, 19 Oct 2023 23:35:38 +0200 Subject: [PATCH 12/12] unit tests --- CHANGELOG.md | 1 + spec/defines/stdmod_spec.rb | 2 +- spec/functions/tp_lookup_spec.rb | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae5f68b..9361520 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Changed CI containers used - Unit tests for Puppet 7 and 8 - Lints and fix on undefined vars +- Updated tp::create_dir ## 3.10.0 diff --git a/spec/defines/stdmod_spec.rb b/spec/defines/stdmod_spec.rb index 54af9ee..fd23edd 100644 --- a/spec/defines/stdmod_spec.rb +++ b/spec/defines/stdmod_spec.rb @@ -76,7 +76,7 @@ 'debug' => true, 'debug_dir' => '/var/tmp', } end - it { is_expected.to contain_file("tp_stdmod_debug_#{app}").with('ensure' => 'present', 'path' => "/var/tmp/tp_stdmod_debug_#{app}") } + it { is_expected.to contain_file("tp_stdmod_debug_#{app}").with('ensure' => 'file', 'path' => "/var/tmp/tp_stdmod_debug_#{app}") } end end end diff --git a/spec/functions/tp_lookup_spec.rb b/spec/functions/tp_lookup_spec.rb index d9ab910..9c7bbf6 100644 --- a/spec/functions/tp_lookup_spec.rb +++ b/spec/functions/tp_lookup_spec.rb @@ -13,10 +13,10 @@ expect(Puppet::Parser::Functions.function("tp_lookup")).to eq("function_tp_lookup") end - it "should raise a ParseError if there are less than 3 arguments" do - expect { scope.function_tp_lookup(["1"]) }.to( raise_error(Puppet::Error)) - expect { scope.function_tp_lookup(["1","2"]) }.to( raise_error(Puppet::Error)) - end + it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } + it { is_expected.to run.with_params(["1"]).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } + it { is_expected.to run.with_params(["1","2"]).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } + end apps.each do | app | appdata=YAML.safe_load(File.read(File.join(File.dirname(__FILE__), "../tpdata/#{os}/#{app}")))