From f7b6b99b5e9e7ea140815b5c8cfb5211e5c1290a Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Mon, 23 Oct 2023 19:10:57 +0000 Subject: [PATCH] Move subclasses into main class --- manifests/container.pp | 2 - manifests/image.pp | 2 - manifests/init.pp | 75 +++++++++++- manifests/install.pp | 57 --------- manifests/network.pp | 2 - manifests/options.pp | 14 --- manifests/pod.pp | 2 - manifests/rootless.pp | 3 + manifests/service.pp | 16 --- manifests/volume.pp | 2 +- spec/classes/init_spec.rb | 189 ++++++++++++++++++++-------- spec/classes/install_spec.rb | 217 --------------------------------- spec/classes/options_spec.rb | 89 -------------- spec/classes/service_spec.rb | 68 ----------- spec/defines/container_spec.rb | 65 ++++------ spec/defines/image_spec.rb | 55 ++++----- spec/defines/network_spec.rb | 46 +++---- spec/defines/pod_spec.rb | 44 +++---- spec/defines/rootless_spec.rb | 28 ++--- spec/defines/volume_spec.rb | 44 +++---- 20 files changed, 321 insertions(+), 699 deletions(-) delete mode 100644 manifests/install.pp delete mode 100644 manifests/options.pp delete mode 100644 manifests/service.pp delete mode 100644 spec/classes/install_spec.rb delete mode 100644 spec/classes/options_spec.rb delete mode 100644 spec/classes/service_spec.rb diff --git a/manifests/container.pp b/manifests/container.pp index f19baaa..3ff8d88 100644 --- a/manifests/container.pp +++ b/manifests/container.pp @@ -75,8 +75,6 @@ Boolean $update = true, Optional[Stdlib::Unixpath] $ruby = undef, ) { - require podman::install - $installed_ruby = $facts['ruby']['sitedir'] ? { /^\/opt\/puppetlabs\// => '/opt/puppetlabs/puppet/bin/ruby', default => '/usr/bin/ruby', diff --git a/manifests/image.pp b/manifests/image.pp index 498e5ce..c295349 100644 --- a/manifests/image.pp +++ b/manifests/image.pp @@ -36,8 +36,6 @@ Optional[String] $user = undef, Array $exec_env = [], ) { - require podman::install - # Convert $flags hash to command arguments $_flags = $flags.reduce('') |$mem, $flag| { if $flag[1] =~ String { diff --git a/manifests/init.pp b/manifests/init.pp index 2165e9a..95f61ac 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -130,10 +130,6 @@ Hash $containers = {}, Hash $networks = {}, ) { - include podman::install - include podman::options - include podman::service - # Create resources from parameter hashes $pods.each |$name, $properties| { Resource['Podman::Pod'] { $name: * => $properties, } } $volumes.each |$name, $properties| { Resource['Podman::Volume'] { $name: * => $properties, } } @@ -141,6 +137,13 @@ $containers.each |$name, $properties| { Resource['Podman::Container'] { $name: * => $properties, } } $networks.each |$name, $properties| { Resource['Podman::Network'] { $name: * => $properties, } } + ensure_resource('Package', $podman_pkg, { 'ensure' => 'installed' }) + ensure_resource('Package', $skopeo_pkg, { 'ensure' => 'installed' }) + ensure_resource('Package', $buildah_pkg, { 'ensure' => $buildah_pkg_ensure }) + ensure_resource('Package', $podman_docker_pkg, { 'ensure' => $podman_docker_pkg_ensure }) + ensure_resource('Package', $compose_pkg, { 'ensure' => $compose_pkg_ensure }) + ensure_resource('Package', $machinectl_pkg, { 'ensure' => $machinectl_pkg_ensure }) + $rootless_users.each |$user| { unless defined(Podman::Rootless[$user]) { podman::rootless { $user: } @@ -148,4 +151,68 @@ User <| title == $user |> -> Podman::Rootless <| title == $user |> } + + if $manage_subuid { + concat { ['/etc/subuid', '/etc/subgid']: + owner => 'root', + group => 'root', + mode => '0644', + order => 'alpha', + ensure_newline => true, + } + + concat_fragment { 'subuid_header': + target => '/etc/subuid', + order => 1, + content => $file_header, + } + + concat_fragment { 'subgid_header': + target => '/etc/subgid', + order => 1, + content => $file_header, + } + + if $match_subuid_subgid { + $podman::subid.each |$name, $properties| { + Resource['Podman::Subuid'] { $name: * => $properties } + $subgid = { subgid => $properties['subuid'], count => $properties['count'] } + Resource['Podman::Subgid'] { $name: * => $subgid } + } + } + } + + if $facts['os']['selinux']['enabled'] == true { + selboolean { 'container_manage_cgroup': + persistent => true, + value => on, + require => Package[$podman_pkg], + } + } + + file { '/etc/containers/nodocker': + ensure => $podman::nodocker, + group => 'root', + owner => 'root', + mode => '0644', + require => Package[$podman::podman_pkg], + } + + unless $storage_options.empty { + $storage_defaults = { + 'ensure' => present, + 'path' => '/etc/containers/storage.conf', + } + inifile::create_ini_settings($storage_options, $storage_defaults) + } + + $ensure = $enable_api_socket ? { + true => 'running', + default => 'stopped', + } + + service { 'podman.socket': + ensure => $ensure, + enable => $enable_api_socket, + } } diff --git a/manifests/install.pp b/manifests/install.pp deleted file mode 100644 index 4bd0401..0000000 --- a/manifests/install.pp +++ /dev/null @@ -1,57 +0,0 @@ -# @summary Install podman packages -# @api private -# -class podman::install { - ensure_resource('Package', $podman::podman_pkg, { 'ensure' => 'installed' }) - ensure_resource('Package', $podman::skopeo_pkg, { 'ensure' => 'installed' }) - ensure_resource('Package', $podman::buildah_pkg, { 'ensure' => $podman::buildah_pkg_ensure }) - ensure_resource('Package', $podman::podman_docker_pkg, { 'ensure' => $podman::podman_docker_pkg_ensure }) - ensure_resource('Package', $podman::compose_pkg, { 'ensure' => $podman::compose_pkg_ensure }) - ensure_resource('Package', $podman::machinectl_pkg, { 'ensure' => $podman::machinectl_pkg_ensure }) - - if $podman::manage_subuid { - concat { ['/etc/subuid', '/etc/subgid']: - owner => 'root', - group => 'root', - mode => '0644', - order => 'alpha', - ensure_newline => true, - } - - concat_fragment { 'subuid_header': - target => '/etc/subuid', - order => 1, - content => $podman::file_header, - } - - concat_fragment { 'subgid_header': - target => '/etc/subgid', - order => 1, - content => $podman::file_header, - } - - if $podman::match_subuid_subgid { - $podman::subid.each |$name, $properties| { - Resource['Podman::Subuid'] { $name: * => $properties } - $subgid = { subgid => $properties['subuid'], count => $properties['count'] } - Resource['Podman::Subgid'] { $name: * => $subgid } - } - } - } - - if $facts['os']['selinux']['enabled'] == true { - selboolean { 'container_manage_cgroup': - persistent => true, - value => on, - require => Package[$podman::podman_pkg], - } - } - - file { '/etc/containers/nodocker': - ensure => $podman::nodocker, - group => 'root', - owner => 'root', - mode => '0644', - require => Package[$podman::podman_pkg], - } -} diff --git a/manifests/network.pp b/manifests/network.pp index 630d639..7960918 100644 --- a/manifests/network.pp +++ b/manifests/network.pp @@ -56,8 +56,6 @@ Boolean $ipv6 = false, Optional[String] $user = undef, ) { - require podman::install - # Convert opts list to command arguments $_opts = $opts.reduce('') |$mem, $opt| { "${mem} --flag ${opt}" diff --git a/manifests/options.pp b/manifests/options.pp deleted file mode 100644 index daa0070..0000000 --- a/manifests/options.pp +++ /dev/null @@ -1,14 +0,0 @@ -# @summary edit container options in /etc/containers -# @api private -# -class podman::options { - require podman::install - - unless $podman::storage_options.empty { - $storage_defaults = { - 'ensure' => present, - 'path' => '/etc/containers/storage.conf', - } - inifile::create_ini_settings($podman::storage_options, $storage_defaults) - } -} diff --git a/manifests/pod.pp b/manifests/pod.pp index a6382ef..181e719 100644 --- a/manifests/pod.pp +++ b/manifests/pod.pp @@ -25,8 +25,6 @@ Hash $flags = {}, Optional[String] $user = undef, ) { - require podman::install - # The resource name will be the pod name by default $pod_name = $title $name_flags = merge({ name => $title }, $flags ) diff --git a/manifests/rootless.pp b/manifests/rootless.pp index af01d62..305770a 100644 --- a/manifests/rootless.pp +++ b/manifests/rootless.pp @@ -1,6 +1,8 @@ # @summary Enable a given user to run rootless podman containers as a systemd user service. # define podman::rootless { + include podman + exec { "loginctl_linger_${name}": path => '/sbin:/usr/sbin:/bin:/usr/bin', command => "loginctl enable-linger ${name}", @@ -9,6 +11,7 @@ require => User[$name], notify => Service['podman systemd-logind'], } + ensure_resource('Service', 'podman systemd-logind', { name => 'systemd-logind.service', ensure => 'running' }) # Ensure the systemd directory tree exists for user services diff --git a/manifests/service.pp b/manifests/service.pp deleted file mode 100644 index 46a17e2..0000000 --- a/manifests/service.pp +++ /dev/null @@ -1,16 +0,0 @@ -# @summary Manage the podman.socket service -# @api private -# -class podman::service { - require podman::install - - $ensure = $podman::enable_api_socket ? { - true => 'running', - default => 'stopped', - } - - service { 'podman.socket': - ensure => $ensure, - enable => $podman::enable_api_socket, - } -} diff --git a/manifests/volume.pp b/manifests/volume.pp index ddfd915..610a303 100644 --- a/manifests/volume.pp +++ b/manifests/volume.pp @@ -26,7 +26,7 @@ Hash $flags = {}, Optional[String] $user = undef, ) { - require podman::install +# require podman::install # Convert $flags hash to command arguments $_flags = $flags.reduce('') |$mem, $flag| { diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 3ba0c1c..ea5ea19 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -6,33 +6,59 @@ let(:facts) { os_facts } it { is_expected.to compile } - it { is_expected.to contain_class('podman::install') } - it { is_expected.to contain_class('podman::options') } - it { is_expected.to contain_class('podman::service') } it { is_expected.to have_package_resource_count(6) } it { is_expected.to have_podman__pod_resource_count(0) } it { is_expected.to have_podman__volume_resource_count(0) } it { is_expected.to have_podman__image_resource_count(0) } it { is_expected.to have_podman__container_resource_count(0) } it { is_expected.to have_podman__network_resource_count(0) } - it { is_expected.to have_podman__rootless_resource_count(0) } - # only here to reach 100% resource coverage - it { is_expected.to contain_file('/etc/containers/nodocker') } # from podman::install - it { is_expected.to contain_package('buildah') } # from podman::install - it { is_expected.to contain_package('podman-compose') } # from podman::install - it { is_expected.to contain_package('podman-docker') } # from podman::install - it { is_expected.to contain_package('podman') } # from podman::install - it { is_expected.to contain_package('skopeo') } # from podman::install + it { is_expected.to contain_package('buildah').with_ensure('absent') } + it { is_expected.to contain_package('podman-compose').with_ensure('absent') } + it { is_expected.to contain_package('podman-docker').with_ensure('installed') } + it { is_expected.to contain_package('podman').with_ensure('installed') } + it { is_expected.to contain_package('skopeo').with_ensure('installed') } + if os_facts[:os]['family'] == 'Archlinux' - it { is_expected.to contain_package('systemd') } # from podman::install + it { is_expected.to contain_package('systemd').with_ensure('installed') } else - it { is_expected.to contain_package('systemd-container') } # from podman::install + it { is_expected.to contain_package('systemd-container').with_ensure('installed') } end + + it { is_expected.to have_podman__rootless_resource_count(0) } + if os_facts[:os]['selinux']['enabled'] == true - it { is_expected.to contain_selboolean('container_manage_cgroup') } # from podman::install + it do + is_expected.to contain_selboolean('container_manage_cgroup').only_with( + { + 'persistent' => true, + 'value' => 'on', + 'require' => 'Package[podman]', + }, + ) + end + end + + it do + is_expected.to contain_file('/etc/containers/nodocker').only_with( + { + 'ensure' => 'absent', + 'group' => 'root', + 'owner' => 'root', + 'mode' => '0644', + 'require' => 'Package[podman]', + }, + ) + end + + it do + is_expected.to contain_service('podman.socket').only_with( + { + 'ensure' => 'stopped', + 'enable' => false, + }, + ) end - it { is_expected.to contain_service('podman.socket') } # from podman::service end end @@ -49,66 +75,66 @@ on_supported_os(redhat).each do |_os, os_facts| let(:facts) { os_facts } - context 'with podman_pkg set to valid testing' do - let(:params) { { podman_pkg: 'testing' } } # parameter used in podman::install + context 'when podman_pkg is set to valid testing' do + let(:params) { { podman_pkg: 'testing' } } - it { is_expected.to contain_package('testing') } + it { is_expected.to contain_package('testing').with_ensure('installed') } end - context 'with skopeo_pkg set to valid testing' do - let(:params) { { skopeo_pkg: 'testing' } } # parameter used in podman::install + context 'when skopeo_pkg is set to valid testing' do + let(:params) { { skopeo_pkg: 'testing' } } - it { is_expected.to contain_package('testing') } + it { is_expected.to contain_package('testing').with_ensure('installed') } end - context 'with buildah_pkg set to valid testing' do - let(:params) { { buildah_pkg: 'testing' } } # parameter used in podman::install + context 'when buildah_pkg is set to valid testing' do + let(:params) { { buildah_pkg: 'testing' } } - it { is_expected.to contain_package('testing') } + it { is_expected.to contain_package('testing').with_ensure('absent') } end - context 'with podman_docker_pkg set to valid testing' do - let(:params) { { podman_docker_pkg: 'testing' } } # parameter used in podman::install + context 'when podman_docker_pkg is set to valid testing' do + let(:params) { { podman_docker_pkg: 'testing' } } - it { is_expected.to contain_package('testing') } + it { is_expected.to contain_package('testing').with_ensure('installed') } end - context 'with compose_pkg set to valid testing' do - let(:params) { { compose_pkg: 'testing' } } # parameter used in podman::install + context 'when compose_pkg is set to valid testing' do + let(:params) { { compose_pkg: 'testing' } } - it { is_expected.to contain_package('testing') } + it { is_expected.to contain_package('testing').with_ensure('absent') } end - context 'with machinectl_pkg set to valid testing' do - let(:params) { { machinectl_pkg: 'testing' } } # parameter used in podman::install + context 'when machinectl_pkg is set to valid testing' do + let(:params) { { machinectl_pkg: 'testing' } } - it { is_expected.to contain_package('testing') } + it { is_expected.to contain_package('testing').with_ensure('installed') } end context 'with buildah_pkg_ensure set to valid installed' do - let(:params) { { buildah_pkg_ensure: 'installed' } } # parameter used in podman::install + let(:params) { { buildah_pkg_ensure: 'installed' } } it { is_expected.to contain_package('buildah').with_ensure('installed') } end context 'with podman_docker_pkg_ensure set to valid absent' do - let(:params) { { podman_docker_pkg_ensure: 'absent' } } # parameter used in podman::install + let(:params) { { podman_docker_pkg_ensure: 'absent' } } it { is_expected.to contain_package('podman-docker').with_ensure('absent') } end context 'with compose_pkg_ensure set to valid installed' do - let(:params) { { compose_pkg_ensure: 'installed' } } # parameter used in podman::install + let(:params) { { compose_pkg_ensure: 'installed' } } it { is_expected.to contain_package('podman-compose').with_ensure('installed') } end context 'with machinectl_pkg_ensure set to valid absent' do - let(:params) { { machinectl_pkg_ensure: 'absent' } } # parameter used in podman::install + let(:params) { { machinectl_pkg_ensure: 'absent' } } it { is_expected.to contain_package('systemd-container').with_ensure('absent') } end context 'with nodocker set to valid file' do - let(:params) { { nodocker: 'file' } } # parameter used in podman::install + let(:params) { { nodocker: 'file' } } it { is_expected.to contain_file('/etc/containers/nodocker').with_ensure('file') } end @@ -194,7 +220,7 @@ context 'with enable_api_socket set to valid true' do let(:params) { { enable_api_socket: true } } - it do # parameter used in podman::service + it do is_expected.to contain_service('podman.socket').with( { 'ensure' => 'running', @@ -205,7 +231,7 @@ end context 'with enable_api_socket set to valid true when rootless_users is set to valid [dummy]' do - let(:params) { { enable_api_socket: true, rootless_users: ['dummy'] } } # parameter used in podman::service & podman::rootless + let(:params) { { enable_api_socket: true, rootless_users: ['dummy'] } } let(:pre_condition) do "# user & file needed by podman::rootless user { 'dummy': @@ -251,23 +277,78 @@ end context 'with manage_subuid set to valid true' do - let(:params) { { manage_subuid: true } } # parameter used in podman::install + let(:params) { { manage_subuid: true } } + + it do + is_expected.to contain_concat('/etc/subuid').with( + { + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'order' => 'alpha', + 'ensure_newline' => true, + }, + ) + end + + it do + is_expected.to contain_concat('/etc/subgid').with( + { + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'order' => 'alpha', + 'ensure_newline' => true, + }, + ) + end + + it do + is_expected.to contain_concat_fragment('subuid_header').only_with( + { + 'target' => '/etc/subuid', + 'order' => '1', + 'content' => '# FILE MANAGED BY PUPPET', + }, + ) + end - it { is_expected.to contain_concat('/etc/subuid') } - it { is_expected.to contain_concat('/etc/subgid') } - it { is_expected.to contain_concat_fragment('subuid_header') } - it { is_expected.to contain_concat_fragment('subgid_header') } + it do + is_expected.to contain_concat_fragment('subgid_header').only_with( + { + 'target' => '/etc/subgid', + 'order' => '1', + 'content' => '# FILE MANAGED BY PUPPET', + }, + ) + end + + it { is_expected.to have_podman__subuid_resource_count(0) } + it { is_expected.to have_podman__subgid_resource_count(0) } end context 'with manage_subuid set to valid true when subid is a valid hash' do - let(:params) { { manage_subuid: true, subid: { dummy: { subuid: 242, count: 1 } } } } # parameter used in podman::install + let(:params) { { manage_subuid: true, subid: { dummy: { subuid: 242, count: 1 } } } } - it { is_expected.to contain_concat('/etc/subuid') } - it { is_expected.to contain_concat('/etc/subgid') } - it { is_expected.to contain_concat_fragment('subuid_header') } - it { is_expected.to contain_concat_fragment('subgid_header') } - it { is_expected.to contain_podman__subuid('dummy') } - it { is_expected.to contain_podman__subgid('dummy') } + it do + is_expected.to contain_podman__subuid('dummy').only_with( + { + 'subuid' => 242, + 'count' => 1, + 'order' => 10, + }, + ) + end + + it do + is_expected.to contain_podman__subgid('dummy').only_with( + { + 'subgid' => 242, + 'count' => 1, + 'order' => 10, + }, + ) + end # only here to reach 100% resource coverage it { is_expected.to contain_concat__fragment('subgid_fragment_dummy') } # from podman::subgid @@ -275,14 +356,14 @@ end context 'with match_subuid_subgid set to valid false when manage_subuid is true and subid is a valid hash' do - let(:params) { { match_subuid_subgid: false, manage_subuid: true, subid: { dummy: { subuid: 242, count: 1 } } } } # parameter used in podman::install + let(:params) { { match_subuid_subgid: false, manage_subuid: true, subid: { dummy: { subuid: 242, count: 1 } } } } it { is_expected.not_to contain_podman__subuid('dummy') } it { is_expected.not_to contain_podman__subgid('dummy') } end context 'with file_header set to valid #testing when manage_subuid is true' do - let(:params) { { file_header: '#testing', manage_subuid: true } } # parameter used in podman::install + let(:params) { { file_header: '#testing', manage_subuid: true } } it { is_expected.to contain_concat_fragment('subuid_header').with_content('#testing') } it { is_expected.to contain_concat_fragment('subgid_header').with_content('#testing') } diff --git a/spec/classes/install_spec.rb b/spec/classes/install_spec.rb deleted file mode 100644 index bf523b4..0000000 --- a/spec/classes/install_spec.rb +++ /dev/null @@ -1,217 +0,0 @@ -require 'spec_helper' - -describe 'podman::install' do - let(:pre_condition) { 'include podman' } - - on_supported_os.each do |os, os_facts| - context "on #{os} with defaults for all parameters" do - let(:facts) { os_facts } - - it { is_expected.to compile } - it { is_expected.to contain_package('buildah').with_ensure('absent') } - it { is_expected.to contain_package('podman-compose').with_ensure('absent') } - it { is_expected.to contain_package('podman-docker').with_ensure('installed') } - it { is_expected.to contain_package('podman').with_ensure('installed') } - it { is_expected.to contain_package('skopeo').with_ensure('installed') } - - if os_facts[:os]['family'] == 'Archlinux' - it { is_expected.to contain_package('systemd').with_ensure('installed') } - else - it { is_expected.to contain_package('systemd-container').with_ensure('installed') } - end - - if os_facts[:os]['selinux']['enabled'] == true - it do - is_expected.to contain_selboolean('container_manage_cgroup').only_with( - { - 'persistent' => true, - 'value' => 'on', - 'require' => 'Package[podman]', - }, - ) - end - end - - it do - is_expected.to contain_file('/etc/containers/nodocker').only_with( - { - 'ensure' => 'absent', - 'group' => 'root', - 'owner' => 'root', - 'mode' => '0644', - 'require' => 'Package[podman]', - }, - ) - end - - # only here to reach 100% resource coverage - it { is_expected.to contain_class('podman') } # from pre_condition - it { is_expected.to contain_class('podman::options') } # from podman - it { is_expected.to contain_class('podman::service') } # from podman - it { is_expected.to contain_service('podman.socket') } # from podman::service - end - end - - # The following tests are OS independent, so we only test one supported OS - redhat = { - supported_os: [ - { - 'operatingsystem' => 'RedHat', - 'operatingsystemrelease' => ['9'], - }, - ], - } - - on_supported_os(redhat).each do |_os, os_facts| - let(:facts) { os_facts } - - context 'when podman::podman_pkg is set to valid testing' do - let(:pre_condition) { 'class { "podman": podman_pkg => "testing" }' } - - it { is_expected.to contain_package('testing') } - end - - context 'when podman::skopeo_pkg is set to valid testing' do - let(:pre_condition) { 'class { "podman": skopeo_pkg => "testing" }' } - - it { is_expected.to contain_package('testing') } - end - - context 'when podman::buildah_pkg is set to valid testing' do - let(:pre_condition) { 'class { "podman": buildah_pkg => "testing" }' } - - it { is_expected.to contain_package('testing') } - end - - context 'when podman::buildah_pkg_ensure is set to valid installed' do - let(:pre_condition) { 'class { "podman": buildah_pkg_ensure => "installed" }' } - - it { is_expected.to contain_package('buildah').with_ensure('installed') } - end - - context 'when podman::podman_docker_pkg is set to valid testing' do - let(:pre_condition) { 'class { "podman": podman_docker_pkg => "testing" }' } - - it { is_expected.to contain_package('testing') } - end - - context 'when podman::podman_docker_pkg_ensure is set to valid absent' do - let(:pre_condition) { 'class { "podman": podman_docker_pkg_ensure => "absent" }' } - - it { is_expected.to contain_package('podman-docker').with_ensure('absent') } - end - - context 'when podman::compose_pkg is set to valid testing' do - let(:pre_condition) { 'class { "podman": compose_pkg => "testing" }' } - - it { is_expected.to contain_package('testing') } - end - - context 'when podman::compose_pkg_ensure is set to valid installed' do - let(:pre_condition) { 'class { "podman": compose_pkg_ensure => "installed" }' } - - it { is_expected.to contain_package('podman-compose').with_ensure('installed') } - end - - context 'when podman::machinectl_pkg is set to valid testing' do - let(:pre_condition) { 'class { "podman": machinectl_pkg => "testing" }' } - - it { is_expected.to contain_package('testing') } - end - - context 'when podman::machinectl_pkg_ensure is set to valid absent' do - let(:pre_condition) { 'class { "podman": machinectl_pkg_ensure => "absent" }' } - - it { is_expected.to contain_package('systemd-container').with_ensure('absent') } - end - - context 'when podman::manage_subuid is set to valid true' do - let(:pre_condition) { 'class { "podman": manage_subuid => true }' } - - it do - is_expected.to contain_concat('/etc/subuid').with( - { - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - 'order' => 'alpha', - 'ensure_newline' => true, - }, - ) - end - - it do - is_expected.to contain_concat('/etc/subgid').with( - { - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - 'order' => 'alpha', - 'ensure_newline' => true, - }, - ) - end - - it do - is_expected.to contain_concat_fragment('subuid_header').only_with( - { - 'target' => '/etc/subuid', - 'order' => '1', - 'content' => '# FILE MANAGED BY PUPPET', - }, - ) - end - - it do - is_expected.to contain_concat_fragment('subgid_header').only_with( - { - 'target' => '/etc/subgid', - 'order' => '1', - 'content' => '# FILE MANAGED BY PUPPET', - }, - ) - end - - it { is_expected.to have_podman__subuid_resource_count(0) } - it { is_expected.to have_podman__subgid_resource_count(0) } - end - - context 'when podman::manage_subuid is set to valid true when podman::subid is a valid hash' do - let(:pre_condition) { 'class { "podman": manage_subuid => true, subid => { dummy => { subuid => 242, count => 1 } } }' } - - it do - is_expected.to contain_podman__subuid('dummy').only_with( - { - 'subuid' => 242, - 'count' => 1, - 'order' => 10, - }, - ) - end - - it do - is_expected.to contain_podman__subgid('dummy').only_with( - { - 'subgid' => 242, - 'count' => 1, - 'order' => 10, - }, - ) - end - - it { is_expected.to have_podman__subuid_resource_count(1) } - it { is_expected.to have_podman__subgid_resource_count(1) } - - # only here to reach 100% resource coverage - it { is_expected.to contain_concat__fragment('subgid_fragment_dummy') } # from podman::subgid - it { is_expected.to contain_concat__fragment('subuid_fragment_dummy') } # from podman::subuid - end - - context 'when podman::manage_subuid is set to valid true when match_subuid_subgid is false and podman::subid is a valid hash' do - let(:pre_condition) { 'class { "podman": manage_subuid => true, match_subuid_subgid => false, subid => { dummy => { subuid => 242, count => 1 } } }' } - - it { is_expected.to have_podman__subuid_resource_count(0) } - it { is_expected.to have_podman__subgid_resource_count(0) } - end - end -end diff --git a/spec/classes/options_spec.rb b/spec/classes/options_spec.rb deleted file mode 100644 index f07ec63..0000000 --- a/spec/classes/options_spec.rb +++ /dev/null @@ -1,89 +0,0 @@ -require 'spec_helper' - -describe 'podman::options' do - let(:pre_condition) { 'include podman' } - - on_supported_os.each do |os, os_facts| - context "on #{os} with defaults for all parameters" do - let(:facts) { os_facts } - - it { is_expected.to compile } - it { is_expected.to contain_class('podman::options') } - it { is_expected.to have_ini_setting_resource_count(0) } - - # only here to reach 100% resource coverage - it { is_expected.to contain_class('podman') } # from pre_condition - it { is_expected.to contain_class('podman::install') } # from podman - it { is_expected.to contain_class('podman::service') } # from podman - it { is_expected.to contain_file('/etc/containers/nodocker') } # from podman::install - it { is_expected.to contain_package('buildah') } # from podman::install - it { is_expected.to contain_package('podman-compose') } # from podman::install - it { is_expected.to contain_package('podman-docker') } # from podman::install - it { is_expected.to contain_package('podman') } # from podman::install - it { is_expected.to contain_package('skopeo') } # from podman::install - if os_facts[:os]['family'] == 'Archlinux' - it { is_expected.to contain_package('systemd') } # from podman::install - else - it { is_expected.to contain_package('systemd-container') } # from podman::install - end - if os_facts[:os]['selinux']['enabled'] == true - it { is_expected.to contain_selboolean('container_manage_cgroup') } # from podman::install - end - it { is_expected.to contain_service('podman.socket') } # from podman::service - end - end - - # The following tests are OS independent, so we only test one supported OS - redhat = { - supported_os: [ - { - 'operatingsystem' => 'RedHat', - 'operatingsystemrelease' => ['9'], - }, - ], - } - - on_supported_os(redhat).each do |_os, os_facts| - let(:facts) { os_facts } - - context 'when podman::storage_options is set to valid hash' do - let(:pre_condition) { 'class { "podman": storage_options => { testing1 => { option1 => "value1", option2 => "value2" }, testing2 => { option3 => "value3" } } }' } - - it do - is_expected.to contain_ini_setting('/etc/containers/storage.conf [testing1] option1').only_with( - { - 'section' => 'testing1', - 'setting' => 'option1', - 'value' => 'value1', - 'ensure' => 'present', - 'path' => '/etc/containers/storage.conf', - }, - ) - end - - it do - is_expected.to contain_ini_setting('/etc/containers/storage.conf [testing1] option2').only_with( - { - 'section' => 'testing1', - 'setting' => 'option2', - 'value' => 'value2', - 'ensure' => 'present', - 'path' => '/etc/containers/storage.conf', - }, - ) - end - - it do - is_expected.to contain_ini_setting('/etc/containers/storage.conf [testing2] option3').only_with( - { - 'section' => 'testing2', - 'setting' => 'option3', - 'value' => 'value3', - 'ensure' => 'present', - 'path' => '/etc/containers/storage.conf', - }, - ) - end - end - end -end diff --git a/spec/classes/service_spec.rb b/spec/classes/service_spec.rb deleted file mode 100644 index 359f9f9..0000000 --- a/spec/classes/service_spec.rb +++ /dev/null @@ -1,68 +0,0 @@ -require 'spec_helper' - -describe 'podman::service' do - let(:pre_condition) { 'include podman' } - - on_supported_os.each do |os, os_facts| - context "on #{os} with defaults for all parameters" do - let(:facts) { os_facts } - - it { is_expected.to compile } - it { is_expected.to contain_class('podman::install') } - - it do - is_expected.to contain_service('podman.socket').only_with( - { - 'ensure' => 'stopped', - 'enable' => false, - }, - ) - end - - # only here to reach 100% resource coverage - it { is_expected.to contain_class('podman') } # from pre_condition - it { is_expected.to contain_class('podman::options') } # from podman - it { is_expected.to contain_file('/etc/containers/nodocker') } # from podman::install - it { is_expected.to contain_package('buildah') } # from podman::install - it { is_expected.to contain_package('podman-compose') } # from podman::install - it { is_expected.to contain_package('podman-docker') } # from podman::install - it { is_expected.to contain_package('podman') } # from podman::install - it { is_expected.to contain_package('skopeo') } # from podman::install - if os_facts[:os]['family'] == 'Archlinux' - it { is_expected.to contain_package('systemd') } # from podman::install - else - it { is_expected.to contain_package('systemd-container') } # from podman::install - end - if os_facts[:os]['selinux']['enabled'] == true - it { is_expected.to contain_selboolean('container_manage_cgroup') } # from podman::install - end - end - end - - # The following tests are OS independent, so we only test one supported OS - redhat = { - supported_os: [ - { - 'operatingsystem' => 'RedHat', - 'operatingsystemrelease' => ['9'], - }, - ], - } - - on_supported_os(redhat).each do |_os, os_facts| - let(:facts) { os_facts } - - context 'when podman::enable_api_socket is set to valid true' do - let(:pre_condition) { 'class { "podman": enable_api_socket => true }' } - - it do - is_expected.to contain_service('podman.socket').only_with( - { - 'ensure' => 'running', - 'enable' => true, - }, - ) - end - end - end -end diff --git a/spec/defines/container_spec.rb b/spec/defines/container_spec.rb index fda5fff..486bc57 100644 --- a/spec/defines/container_spec.rb +++ b/spec/defines/container_spec.rb @@ -3,15 +3,12 @@ describe 'podman::container' do let(:title) { 'namevar' } let(:params) { { image: 'registry:latest' } } - let(:pre_condition) { 'include podman' } on_supported_os.each do |os, os_facts| context "on #{os} with defaults for all parameters and image set to valid value" do let(:facts) { os_facts } it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_class('podman') } - it { is_expected.to contain_class('podman::install') } it do is_expected.to contain_exec('podman_systemd_reload').only_with( @@ -158,28 +155,6 @@ }, ) end - - # only here to reach 100% resource coverage] - context 'cover additional resource from other classes' do - it { is_expected.to contain_class('podman::options') } # from podman - it { is_expected.to contain_class('podman::service') } # from podman - it { is_expected.to contain_service('podman.socket') } # from podman::service - it { is_expected.to contain_file('/etc/containers/nodocker') } # from podman::install - it { is_expected.to contain_package('buildah') } # from podman::install - it { is_expected.to contain_package('podman-compose') } # from podman::install - it { is_expected.to contain_package('podman-docker') } # from podman::install - it { is_expected.to contain_package('podman') } # from podman::install - it { is_expected.to contain_package('skopeo') } # from podman::install - if os_facts[:os]['family'] == 'Archlinux' - it { is_expected.to contain_package('systemd') } # from podman::install - else - it { is_expected.to contain_package('systemd-container') } # from podman::install - end - - if os_facts[:os]['selinux']['enabled'] == true - it { is_expected.to contain_selboolean('container_manage_cgroup') } # from podman::install - end - end end end @@ -243,8 +218,7 @@ context 'with user set to valid testing' do let(:params) { { user: 'testing', image: 'mandatory:latest', } } let(:pre_condition) do - "include podman - # user & file needed by podman::rootless + "# user & file needed by podman::rootless user { 'testing': ensure => 'present', gid => 1111, @@ -354,20 +328,36 @@ # only here to reach 100% resource coverage context 'cover additional resource from other classes' do + it { is_expected.to contain_class('podman') } # from podman::rootless it { is_expected.to contain_exec('loginctl_linger_testing') } # from podman::rootless it { is_expected.to contain_service('podman systemd-logind') } # from podman::rootless it { is_expected.to contain_file('/home/testing/.config') } # from podman::rootless it { is_expected.to contain_file('/home/testing/.config/systemd') } # from podman::rootless it { is_expected.to contain_file('/home/testing/.config/systemd/user') } # from podman::rootless it { is_expected.to contain_exec('start_testing.slice') } # from podman::rootless + it { is_expected.to contain_service('podman.socket') } # from podman + it { is_expected.to contain_file('/etc/containers/nodocker') } # from podman + it { is_expected.to contain_package('buildah') } # from podman + it { is_expected.to contain_package('podman-compose') } # from podman + it { is_expected.to contain_package('podman-docker') } # from podman + it { is_expected.to contain_package('podman') } # from podman + it { is_expected.to contain_package('skopeo') } # from podman + if os_facts[:os]['family'] == 'Archlinux' + it { is_expected.to contain_package('systemd') } # from podman + else + it { is_expected.to contain_package('systemd-container') } # from podman + end + + if os_facts[:os]['selinux']['enabled'] == true + it { is_expected.to contain_selboolean('container_manage_cgroup') } # from podman + end end end context 'with user set to valid testing when ensure is set to valid absent' do let(:params) { { user: 'testing', ensure: 'absent', image: 'mandatory:latest', } } let(:pre_condition) do - "include podman - # user & file needed by podman::rootless + "# user & file needed by podman::rootless user { 'testing': ensure => 'present', gid => 1111, @@ -434,7 +424,6 @@ context 'with flags set to valid hash' do let(:params) { { flags: { publish: ['242:242'], volume: 'jenkins:/test/ing' }, image: 'mandatory:latest' } } - let(:pre_condition) { 'include podman' } unless_flags = <<-END.gsub(%r{^\s+\|}, '') |if podman container exists namevar @@ -468,7 +457,6 @@ context 'with flags set to valid hash containing a label' do let(:params) { { flags: { publish: ['242:242'], volume: 'jenkins:/test/ing', label: 'test' }, image: 'mandatory:latest' } } - let(:pre_condition) { 'include podman' } unless_flags = <<-END.gsub(%r{^\s+\|}, '') |if podman container exists namevar @@ -503,8 +491,7 @@ context 'with flags set to valid hash when user is set to valid testing' do let(:params) { { flags: { publish: ['242:242'], volume: 'jenkins:/test/ing' }, user: 'testing', image: 'mandatory:latest' } } let(:pre_condition) do - "include podman - # user & file needed by podman::rootless + "# user & file needed by podman::rootless user { 'testing': ensure => 'present', gid => 1111, @@ -556,7 +543,6 @@ context 'with command set to valid /test/ing' do let(:params) { { command: '/test/ing', image: 'mandatory:latest' } } - let(:pre_condition) { 'include podman' } it do is_expected.to contain_exec('podman_create_namevar').with( @@ -569,7 +555,6 @@ context 'with ensure set to valid absent' do let(:params) { { ensure: 'absent', image: 'mandatory:latest' } } - let(:pre_condition) { 'include podman' } it do is_expected.to contain_exec('service_podman_namevar').only_with( @@ -621,8 +606,7 @@ context 'with ensure set to valid absent when user is set to valid value' do let(:params) { { ensure: 'absent', user: 'user', image: 'mandatory:latest' } } let(:pre_condition) do - "include podman - # user & file needed by podman::rootless + "# user & file needed by podman::rootless user { 'user': ensure => 'present', gid => 1111, @@ -716,7 +700,6 @@ context 'with enable set to valid false' do let(:params) { { enable: false, image: 'mandatory:latest' } } - let(:pre_condition) { 'include podman' } it do is_expected.to contain_service('podman-namevar').only_with( @@ -731,8 +714,7 @@ context 'with enable set to valid false when user is set to valid value' do let(:params) { { enable: false, user: 'user', image: 'mandatory:latest' } } let(:pre_condition) do - "include podman - # user & file needed by podman::rootless + "# user & file needed by podman::rootless user { 'user': ensure => 'present', gid => 1111, @@ -759,7 +741,6 @@ context 'with update set to valid false' do let(:params) { { update: false, image: 'mandatory:latest' } } - let(:pre_condition) { 'include podman' } unless_image = <<-END.gsub(%r{^\s+\|}, '') |if podman container exists namevar @@ -789,7 +770,6 @@ context 'with ruby set to valid /test/ing' do let(:params) { { ruby: '/test/ing', image: 'mandatory:latest' } } - let(:pre_condition) { 'include podman' } unless_ruby = <<-END.gsub(%r{^\s+\|}, '') |if podman container exists namevar @@ -814,7 +794,6 @@ context 'with ruby set to valid /test/ing when update is false' do let(:params) { { ruby: '/test/ing', update: false, image: 'mandatory:latest' } } - let(:pre_condition) { 'include podman' } unless_ruby = <<-END.gsub(%r{^\s+\|}, '') |if podman container exists namevar diff --git a/spec/defines/image_spec.rb b/spec/defines/image_spec.rb index 546111f..0db947b 100644 --- a/spec/defines/image_spec.rb +++ b/spec/defines/image_spec.rb @@ -2,7 +2,6 @@ describe 'podman::image' do let(:title) { 'title' } - let(:pre_condition) { 'include podman' } on_supported_os.each do |os, os_facts| context "on #{os} with defaults for all parameters and image set to valid value" do @@ -10,7 +9,6 @@ let(:params) { { image: 'image:test' } } it { is_expected.to compile } - it { is_expected.to contain_class('podman::install') } it do is_expected.to contain_exec('pull_image_title').only_with( @@ -22,27 +20,6 @@ }, ) end - - # only here to reach 100% resource coverage - it { is_expected.to contain_class('podman') } # from pre_condition - it { is_expected.to contain_class('podman::options') } # from podman - it { is_expected.to contain_class('podman::service') } # from podman - it { is_expected.to contain_service('podman.socket') } # from podman::service - it { is_expected.to contain_file('/etc/containers/nodocker') } # from podman::install - it { is_expected.to contain_package('buildah') } # from podman::install - it { is_expected.to contain_package('podman-compose') } # from podman::install - it { is_expected.to contain_package('podman-docker') } # from podman::install - it { is_expected.to contain_package('podman') } # from podman::install - it { is_expected.to contain_package('skopeo') } # from podman::install - if os_facts[:os]['family'] == 'Archlinux' - it { is_expected.to contain_package('systemd') } # from podman::install - else - it { is_expected.to contain_package('systemd-container') } # from podman::install - end - - if os_facts[:os]['selinux']['enabled'] == true - it { is_expected.to contain_selboolean('container_manage_cgroup') } # from podman::install - end end end @@ -77,8 +54,7 @@ context 'with ensure set to valid absent when user is set to valid dummy' do let(:params) { { ensure: 'absent', user: 'dummy', image: 'image:test' } } let(:pre_condition) do - "include podman - # user & file needed by podman::rootless + "# user & file needed by podman::rootless user { 'dummy': ensure => 'present', gid => 1111, @@ -112,13 +88,29 @@ it { is_expected.to contain_file('/home/dummy/.config') } # from podman::rootless it { is_expected.to contain_file('/home/dummy/.config/systemd') } # from podman::rootless it { is_expected.to contain_file('/home/dummy/.config/systemd/user') } # from podman::rootless + it { is_expected.to contain_class('podman') } # from podmna::rootless + it { is_expected.to contain_service('podman.socket') } # from podman + it { is_expected.to contain_file('/etc/containers/nodocker') } # from podman + it { is_expected.to contain_package('buildah') } # from podman + it { is_expected.to contain_package('podman-compose') } # from podman + it { is_expected.to contain_package('podman-docker') } # from podman + it { is_expected.to contain_package('podman') } # from podman + it { is_expected.to contain_package('skopeo') } # from podman + if os_facts[:os]['family'] == 'Archlinux' + it { is_expected.to contain_package('systemd') } # from podman + else + it { is_expected.to contain_package('systemd-container') } # from podman + end + + if os_facts[:os]['selinux']['enabled'] == true + it { is_expected.to contain_selboolean('container_manage_cgroup') } # from podman + end end context 'with ensure set to valid present when user is set to valid dummy' do let(:params) { { ensure: 'present', user: 'dummy', image: 'image:test' } } let(:pre_condition) do - "include podman - # user & file needed by podman::rootless + "# user & file needed by podman::rootless user { 'dummy': ensure => 'present', gid => 1111, @@ -174,8 +166,7 @@ context 'with user set to valid testing' do let(:params) { { user: 'testing', image: 'image:test' } } let(:pre_condition) do - "include podman - # user & file needed by podman::rootless + "# user & file needed by podman::rootless user { 'testing': ensure => 'present', gid => 1111, @@ -215,8 +206,7 @@ context 'with user set to valid testing when ensure is set to valid absent' do let(:params) { { user: 'testing', ensure: 'absent', image: 'image:test' } } let(:pre_condition) do - "include podman - # user & file needed by podman::rootless + "# user & file needed by podman::rootless user { 'testing': ensure => 'present', gid => 1111, @@ -260,8 +250,7 @@ context 'with exec_env set to valid [TEST=/test/ing] when user is set to valid dummy' do let(:params) { { exec_env: ['TEST=/test/ing'], user: 'dummy', image: 'image:test' } } let(:pre_condition) do - "include podman - # user & file needed by podman::rootless + "# user & file needed by podman::rootless user { 'dummy': ensure => 'present', gid => 1111, diff --git a/spec/defines/network_spec.rb b/spec/defines/network_spec.rb index 7311f53..d51d7a8 100644 --- a/spec/defines/network_spec.rb +++ b/spec/defines/network_spec.rb @@ -2,14 +2,12 @@ describe 'podman::network' do let(:title) { 'testing-title' } - let(:pre_condition) { 'include podman' } on_supported_os.each do |os, os_facts| context "on #{os} with defaults for all parameters" do let(:facts) { os_facts } it { is_expected.to compile } - it { is_expected.to contain_class('podman::install') } it do is_expected.to contain_exec('podman_create_network_testing-title').only_with( @@ -21,27 +19,6 @@ }, ) end - - # only here to reach 100% resource coverage - it { is_expected.to contain_class('podman') } # from pre_condition - it { is_expected.to contain_class('podman::options') } # from podman - it { is_expected.to contain_class('podman::service') } # from podman - it { is_expected.to contain_service('podman.socket') } # from podman::service - it { is_expected.to contain_file('/etc/containers/nodocker') } # from podman::install - it { is_expected.to contain_package('buildah') } # from podman::install - it { is_expected.to contain_package('podman-compose') } # from podman::install - it { is_expected.to contain_package('podman-docker') } # from podman::install - it { is_expected.to contain_package('podman') } # from podman::install - it { is_expected.to contain_package('skopeo') } # from podman::install - if os_facts[:os]['family'] == 'Archlinux' - it { is_expected.to contain_package('systemd') } # from podman::install - else - it { is_expected.to contain_package('systemd-container') } # from podman::install - end - - if os_facts[:os]['selinux']['enabled'] == true - it { is_expected.to contain_selboolean('container_manage_cgroup') } # from podman::install - end end end @@ -76,8 +53,7 @@ context 'with ensure set to valid absent when user is set to valid dummy' do let(:params) { { ensure: 'absent', user: 'dummy' } } let(:pre_condition) do - "include podman - ensure_resource('podman::rootless', 'dummy', {}) + "ensure_resource('podman::rootless', 'dummy', {}) # user & file needed by podman::rootless user { 'dummy': ensure => 'present', @@ -110,6 +86,23 @@ it { is_expected.to contain_file('/home/dummy/.config/systemd') } # from podman::rootless it { is_expected.to contain_file('/home/dummy/.config/systemd/user') } # from podman::rootless it { is_expected.to contain_service('podman systemd-logind') } # from podman::rootless + it { is_expected.to contain_class('podman') } # from podman::rootless + it { is_expected.to contain_service('podman.socket') } # from podman + it { is_expected.to contain_file('/etc/containers/nodocker') } # from podman + it { is_expected.to contain_package('buildah') } # from podman + it { is_expected.to contain_package('podman-compose') } # from podman + it { is_expected.to contain_package('podman-docker') } # from podman + it { is_expected.to contain_package('podman') } # from podman + it { is_expected.to contain_package('skopeo') } # from podman + if os_facts[:os]['family'] == 'Archlinux' + it { is_expected.to contain_package('systemd') } # from podman + else + it { is_expected.to contain_package('systemd-container') } # from podman + end + + if os_facts[:os]['selinux']['enabled'] == true + it { is_expected.to contain_selboolean('container_manage_cgroup') } # from podman + end end context 'with driver set to valid macvlan' do @@ -218,8 +211,7 @@ context 'with user set to valid testing' do let(:params) { { user: 'testing' } } let(:pre_condition) do - "include podman - ensure_resource('podman::rootless', 'testing', {}) + "ensure_resource('podman::rootless', 'testing', {}) # user & file needed by podman::rootless user { 'testing': ensure => 'present', diff --git a/spec/defines/pod_spec.rb b/spec/defines/pod_spec.rb index 735c0d7..635f820 100644 --- a/spec/defines/pod_spec.rb +++ b/spec/defines/pod_spec.rb @@ -2,14 +2,12 @@ describe 'podman::pod' do let(:title) { 'testing-title' } - let(:pre_condition) { 'include podman' } on_supported_os.each do |os, os_facts| context "on #{os} with defaults for all parameters" do let(:facts) { os_facts } it { is_expected.to compile } - it { is_expected.to contain_class('podman::install') } it do is_expected.to contain_exec('create_pod_testing-title').only_with( @@ -21,26 +19,6 @@ }, ) end - - # only here to reach 100% resource coverage - it { is_expected.to contain_class('podman::options') } # from podman - it { is_expected.to contain_class('podman::service') } # from podman - it { is_expected.to contain_class('podman') } # from pre_condition - it { is_expected.to contain_file('/etc/containers/nodocker') } # from podman::install - it { is_expected.to contain_package('buildah') } # from podman::install - it { is_expected.to contain_package('podman-compose') } # from podman::install - it { is_expected.to contain_package('podman-docker') } # from podman::install - it { is_expected.to contain_package('podman') } # from podman::install - it { is_expected.to contain_package('skopeo') } # from podman::install - if os_facts[:os]['family'] == 'Archlinux' - it { is_expected.to contain_package('systemd') } # from podman::install - else - it { is_expected.to contain_package('systemd-container') } # from podman::install - end - if os_facts[:os]['selinux']['enabled'] == true - it { is_expected.to contain_selboolean('container_manage_cgroup') } # from podman::install - end - it { is_expected.to contain_service('podman.socket') } # from podman::service end end @@ -75,8 +53,7 @@ context 'with ensure set to valid absent when user is set to valid dummy' do let(:params) { { ensure: 'absent', user: 'dummy' } } let(:pre_condition) do - "include podman - ensure_resource('podman::rootless', 'dummy', {}) + "ensure_resource('podman::rootless', 'dummy', {}) # user & file needed by podman::rootless user { 'dummy': ensure => 'present', @@ -110,6 +87,22 @@ it { is_expected.to contain_file('/home/dummy/.config/systemd') } # from podman::rootless it { is_expected.to contain_file('/home/dummy/.config/systemd/user') } # from podman::rootless it { is_expected.to contain_service('podman systemd-logind') } # from podman::rootless + it { is_expected.to contain_class('podman') } # from podman::rootless + it { is_expected.to contain_file('/etc/containers/nodocker') } # from podman + it { is_expected.to contain_package('buildah') } # from podman + it { is_expected.to contain_package('podman-compose') } # from podman + it { is_expected.to contain_package('podman-docker') } # from podman + it { is_expected.to contain_package('podman') } # from podman + it { is_expected.to contain_package('skopeo') } # from podman + if os_facts[:os]['family'] == 'Archlinux' + it { is_expected.to contain_package('systemd') } # from podman + else + it { is_expected.to contain_package('systemd-container') } # from podman + end + if os_facts[:os]['selinux']['enabled'] == true + it { is_expected.to contain_selboolean('container_manage_cgroup') } # from podman + end + it { is_expected.to contain_service('podman.socket') } # from podman end context 'with flags set to valid hash' do @@ -127,8 +120,7 @@ context 'with user set to valid value testing' do let(:params) { { user: 'testing' } } let(:pre_condition) do - "include podman - ensure_resource('podman::rootless', 'testing', {}) + "ensure_resource('podman::rootless', 'testing', {}) # user & file needed by podman::rootless user { 'testing': ensure => 'present', diff --git a/spec/defines/rootless_spec.rb b/spec/defines/rootless_spec.rb index fe8725c..0b9df84 100644 --- a/spec/defines/rootless_spec.rb +++ b/spec/defines/rootless_spec.rb @@ -3,8 +3,7 @@ describe 'podman::rootless' do let(:title) { 'testing-title' } let(:pre_condition) do - "include podman - # user & file needed by podman::rootless + "# user & file needed by podman::rootless user { 'testing-title': ensure => 'present', gid => 1111, @@ -20,6 +19,7 @@ let(:facts) { os_facts } it { is_expected.to compile } + it { is_expected.to contain_class('podman') } it do is_expected.to contain_exec('loginctl_linger_testing-title').only_with( @@ -91,25 +91,21 @@ end # only here to reach 100% resource coverage - it { is_expected.to contain_class('podman::install') } # from podman - it { is_expected.to contain_class('podman::options') } # from podman - it { is_expected.to contain_class('podman::service') } # from podman - it { is_expected.to contain_class('podman') } # from pre_condition - it { is_expected.to contain_file('/etc/containers/nodocker') } # from podman::install - it { is_expected.to contain_package('buildah') } # from podman::install - it { is_expected.to contain_package('podman-compose') } # from podman::install - it { is_expected.to contain_package('podman-docker') } # from podman::install - it { is_expected.to contain_package('podman') } # from podman::install - it { is_expected.to contain_package('skopeo') } # from podman::install + it { is_expected.to contain_file('/etc/containers/nodocker') } # from podman + it { is_expected.to contain_package('buildah') } # from podman + it { is_expected.to contain_package('podman-compose') } # from podman + it { is_expected.to contain_package('podman-docker') } # from podman + it { is_expected.to contain_package('podman') } # from podman + it { is_expected.to contain_package('skopeo') } # from podman if os_facts[:os]['family'] == 'Archlinux' - it { is_expected.to contain_package('systemd') } # from podman::install + it { is_expected.to contain_package('systemd') } # from podman else - it { is_expected.to contain_package('systemd-container') } # from podman::install + it { is_expected.to contain_package('systemd-container') } # from podman end if os_facts[:os]['selinux']['enabled'] == true - it { is_expected.to contain_selboolean('container_manage_cgroup') } # from podman::install + it { is_expected.to contain_selboolean('container_manage_cgroup') } # from podman end - it { is_expected.to contain_service('podman.socket') } # from podman::service + it { is_expected.to contain_service('podman.socket') } # from podman end end diff --git a/spec/defines/volume_spec.rb b/spec/defines/volume_spec.rb index a1c110f..0073cf0 100644 --- a/spec/defines/volume_spec.rb +++ b/spec/defines/volume_spec.rb @@ -2,14 +2,12 @@ describe 'podman::volume' do let(:title) { 'testing-title' } - let(:pre_condition) { 'include podman' } on_supported_os.each do |os, os_facts| context "on #{os} with defaults for all parameters" do let(:facts) { os_facts } it { is_expected.to compile } - it { is_expected.to contain_class('podman::install') } it do is_expected.to contain_exec('podman_create_volume_testing-title').only_with( @@ -20,26 +18,6 @@ }, ) end - - # only here to reach 100% resource coverage - it { is_expected.to contain_class('podman::options') } # from podman - it { is_expected.to contain_class('podman::service') } # from podman - it { is_expected.to contain_class('podman') } # from pre_condition - it { is_expected.to contain_file('/etc/containers/nodocker') } # from podman::install - it { is_expected.to contain_package('buildah') } # from podman::install - it { is_expected.to contain_package('podman-compose') } # from podman::install - it { is_expected.to contain_package('podman-docker') } # from podman::install - it { is_expected.to contain_package('podman') } # from podman::install - it { is_expected.to contain_package('skopeo') } # from podman::install - if os_facts[:os]['family'] == 'Archlinux' - it { is_expected.to contain_package('systemd') } # from podman::install - else - it { is_expected.to contain_package('systemd-container') } # from podman::install - end - if os_facts[:os]['selinux']['enabled'] == true - it { is_expected.to contain_selboolean('container_manage_cgroup') } # from podman::install - end - it { is_expected.to contain_service('podman.socket') } # from podman::service end end @@ -87,8 +65,7 @@ context 'with user set to valid testing' do let(:params) { { user: 'testing' } } let(:pre_condition) do - "include podman - # user & file needed by podman::rootless + "# user & file needed by podman::rootless user { 'testing': ensure => 'present', gid => 1111, @@ -123,13 +100,28 @@ it { is_expected.to contain_file('/home/testing/.config/systemd') } # from podman::rootless it { is_expected.to contain_file('/home/testing/.config/systemd/user') } # from podman::rootless it { is_expected.to contain_service('podman systemd-logind') } # from podman::rootless + it { is_expected.to contain_class('podman') } # from podman::rootless + it { is_expected.to contain_file('/etc/containers/nodocker') } # from podman + it { is_expected.to contain_package('buildah') } # from podman + it { is_expected.to contain_package('podman-compose') } # from podman + it { is_expected.to contain_package('podman-docker') } # from podman + it { is_expected.to contain_package('podman') } # from podman + it { is_expected.to contain_package('skopeo') } # from podman + if os_facts[:os]['family'] == 'Archlinux' + it { is_expected.to contain_package('systemd') } # from podman + else + it { is_expected.to contain_package('systemd-container') } # from podman + end + if os_facts[:os]['selinux']['enabled'] == true + it { is_expected.to contain_selboolean('container_manage_cgroup') } # from podman + end + it { is_expected.to contain_service('podman.socket') } # from podman end context 'with user set to valid testing when ensure is set to valid absent' do let(:params) { { user: 'testing', ensure: 'absent' } } let(:pre_condition) do - "include podman - # user & file needed by podman::rootless + "# user & file needed by podman::rootless user { 'testing': ensure => 'present', gid => 1111,