From 54af7f5b8fc5520b6d61dab57fdb2690404a4ede Mon Sep 17 00:00:00 2001 From: Martin Alfke Date: Fri, 20 Sep 2019 15:29:45 +0200 Subject: [PATCH] Add apt::markdefined type --- manifests/mark.pp | 24 +++++++++++++++++++++++ spec/defines/mark_spec.rb | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 manifests/mark.pp create mode 100644 spec/defines/mark_spec.rb diff --git a/manifests/mark.pp b/manifests/mark.pp new file mode 100644 index 0000000..e439162 --- /dev/null +++ b/manifests/mark.pp @@ -0,0 +1,24 @@ +# defined typeapt::mark +# +# @param setting +# auto, manual, hold, unhold +# specifies the behavior of apt in case of no more dependencies installed +# https://manpages.debian.org/sretch/apt/apt-mark.8.en.html +# +define apt::mark ( + Enum['auto','manual','hold','unhold'] $setting, +){ + case $setting { + 'unhold': { + $unless_cmd = undef + } + default: { + $unless_cmd = "/usr/bin/apt-mark showm${setting} ${title} | /bin/fgrep -qs ${title}" + } + } + exec { "/usr/bin/apt-mark ${setting} ${title}": + onlyif => "/usr/bin/dpkg -l ${title}", + unless => $unless_cmd, + } +} + diff --git a/spec/defines/mark_spec.rb b/spec/defines/mark_spec.rb new file mode 100644 index 0000000..f776039 --- /dev/null +++ b/spec/defines/mark_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'apt::mark', type: :define do + let :title do + 'my_source' + end + + let :facts do + { + os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } }, + lsbdistid: 'Debian', + lsbdistcodename: 'jessie', + osfamily: 'Debian', + } + end + + context 'with correct seting' do + let :params do + { + 'setting' => 'manual', + } + end + + it { + is_expected.to contain_exec('/usr/bin/apt-mark manual my_source') + } + end + + describe 'with wrong setting' do + let :params do + { + 'setting' => 'foobar', + } + end + + it do + is_expected.to raise_error(Puppet::PreformattedError, %r{expects a match for Enum\['auto', 'hold', 'manual', 'unhold'\], got 'foobar'}) + end + end +end -- 2.32.3