Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apt::force: Added 2 parameters for automatic configuration file handling... #363

Merged
merged 1 commit into from
Sep 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,21 @@ Installs the build depends of a specified package.
### apt::force

Forces a package to be installed from a specific release. This class is particularly useful when using repositories, like Debian, that are unstable in Ubuntu.
The cfg_files parameter controls wether newer or older configuration files should be used or only unchanged configuration files should be updated. Cfg_missing forces the provider to install all missing configuration files. Both are optional.

apt::force { 'glusterfs-server':
release => 'unstable',
version => '3.0.3',
require => Apt::Source['debian_unstable'],
release => 'unstable',
version => '3.0.3',
cfg_files => 'unchanged',
cfg_missing => true,
require => Apt::Source['debian_unstable'],
}

You can additionally set the following attributes:

* `cfg_files`: "new", "old", "unchanged" or "none" (default). "new" will overwrite all existing configuration files with newer ones, "old" will force usage of all old files and "unchanged" only updates unchanged config files whereas setting "none" will don't do anything but providing backward-compatability with existing puppet manifests.
* `cfg_missing`: "true" or "false". Setting cfg_missing to false will provide backward compatability whereas setting true will add an aptitude/apt-get parameter which checks and installs missing configuration files for the selected package.

### apt_key

A native Puppet type and provider for managing GPG keys for APT is provided by this module.
Expand Down
25 changes: 21 additions & 4 deletions manifests/force.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
# force a package from a specific release

define apt::force(
$release = false,
$version = false,
$timeout = 300
$release = false,
$version = false,
$timeout = 300,
$cfg_files = 'none',
$cfg_missing = false,
) {

validate_re($cfg_files, ['^new', '^old', '^unchanged', '^none'])
validate_bool($cfg_missing)

$provider = $apt::params::provider

$version_string = $version ? {
Expand All @@ -19,6 +24,18 @@
default => "-t ${release}",
}

case $cfg_files {
'new': { $config_files = '-o Dpkg::Options::="--force-confnew"' }
'old': { $config_files = '-o Dpkg::Options::="--force-confold"' }
'unchanged': { $config_files = '-o Dpkg::Options::="--force-confdef"' }
'none': { $config_files = '' }
}

case $cfg_missing {
true: { $config_missing = '-o Dpkg::Options::="--force-confmiss"' }
false: { $config_missing = '' }
}

if $version == false {
if $release == false {
$install_check = "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'"
Expand All @@ -34,7 +51,7 @@
}
}

exec { "${provider} -y ${release_string} install ${name}${version_string}":
exec { "${provider} -y ${config_files} ${config_missing} ${release_string} install ${name}${version_string}":
unless => $install_check,
logoutput => 'on_failure',
timeout => $timeout,
Expand Down
58 changes: 52 additions & 6 deletions spec/defines/force_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@

let :default_params do
{
:release => false,
:version => false
:release => false,
:version => false,
:cfg_files => 'none',
:cfg_missing => false,
}
end

describe "when using default parameters" do
it { should contain_exec("/usr/bin/apt-get -y install #{title}").with(
it { should contain_exec("/usr/bin/apt-get -y install #{title}").with(
:unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'",
:logoutput => 'on_failure',
:timeout => '300'
Expand All @@ -28,7 +30,7 @@
let :params do
default_params.merge(:release => 'testing')
end
it { should contain_exec("/usr/bin/apt-get -y -t #{params[:release]} install #{title}").with(
it { should contain_exec("/usr/bin/apt-get -y -t #{params[:release]} install #{title}").with(
:unless => "/usr/bin/test \$(/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -E 'Installed|Candidate' | /usr/bin/uniq -s 14 | /usr/bin/wc -l) -eq 1"
) }
end
Expand All @@ -37,20 +39,64 @@
let :params do
default_params.merge(:version => '1')
end
it { should contain_exec("/usr/bin/apt-get -y install #{title}=#{params[:version]}").with(
it { should contain_exec("/usr/bin/apt-get -y install #{title}=#{params[:version]}").with(
:unless => "/usr/bin/dpkg -s #{title} | grep -q 'Version: #{params[:version]}'"
) }
end

describe "when specifying cfg_files parameter" do
let :params do
default_params.merge(:cfg_files => 'unchanged')
end
it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confdef" install my_package').with(
:unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'"
) }
end

describe "when specifying cfg_missing parameter" do
let :params do
default_params.merge(:cfg_missing => true)
end
it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confmiss" install my_package').with(
:unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'"
) }
end

describe "when specifying cfg_files and cfg_missing parameter" do
let :params do
default_params.merge(
:cfg_files => 'unchanged',
:cfg_missing => true
)
end
it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confmiss" install my_package').with(
:unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'"
) }
end

describe "when specifying release and version parameters" do
let :params do
default_params.merge(
:release => 'testing',
:version => '1'
)
end
it { should contain_exec("/usr/bin/apt-get -y -t #{params[:release]} install #{title}=1").with(
it { should contain_exec("/usr/bin/apt-get -y -t #{params[:release]} install #{title}=1").with(
:unless => "/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -q 'Installed: #{params[:version]}'"
) }
end

describe "when specifying release, version, cfg_files and cfg_missing parameters" do
let :params do
default_params.merge(
:release => 'testing',
:version => '1',
:cfg_files => 'unchanged',
:cfg_missing => true
)
end
it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confmiss" -t testing install my_package=1').with(
:unless => "/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -q 'Installed: #{params[:version]}'"
) }
end
end