forked from evolvingweb/puppet-apt
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: Add apt::setting defined type. #428
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
define apt::setting ( | ||
$type, | ||
$priority = 50, | ||
$ensure = file, | ||
$source = undef, | ||
$content = undef, | ||
$file_perms = {}, | ||
) { | ||
|
||
$_file = merge($::apt::file_defaults, $file_perms) | ||
|
||
if $content and $source { | ||
fail('apt::setting cannot have both content and source') | ||
} | ||
|
||
if !$content and !$source { | ||
fail('apt::setting needs either of content or source') | ||
} | ||
|
||
validate_re($type, ['conf', 'pref', 'list']) | ||
validate_re($ensure, ['file', 'present', 'absent']) | ||
|
||
unless is_integer($priority) { | ||
fail('apt::setting priority must be an integer') | ||
} | ||
|
||
if $source { | ||
validate_string($source) | ||
} | ||
|
||
if $content { | ||
validate_string($content) | ||
} | ||
|
||
if $type == 'list' { | ||
$_priority = '' | ||
} else { | ||
$_priority = $priority | ||
} | ||
|
||
$_path = $::apt::config_files[$type]['path'] | ||
$_ext = $::apt::config_files[$type]['ext'] | ||
|
||
file { "${_path}/${_priority}${title}${_ext}": | ||
ensure => $ensure, | ||
owner => $_file['owner'], | ||
group => $_file['group'], | ||
mode => $_file['mode'], | ||
content => $content, | ||
source => $source, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
require 'spec_helper' | ||
|
||
describe 'apt::setting' do | ||
let(:pre_condition) { 'class { "apt": }' } | ||
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } | ||
let(:title) { 'teddybear' } | ||
|
||
let(:default_params) { { :type => 'conf', :content => 'di' } } | ||
|
||
describe 'when using the defaults' do | ||
context 'without type' do | ||
it do | ||
expect { should compile }.to raise_error(Puppet::Error, /Must pass type /) | ||
end | ||
end | ||
|
||
context 'without source or content' do | ||
let(:params) { { :type => 'conf' } } | ||
it do | ||
expect { should compile }.to raise_error(Puppet::Error, /needs either of /) | ||
end | ||
end | ||
|
||
context 'with type=conf' do | ||
let(:params) { default_params } | ||
it { should contain_file('/etc/apt/apt.conf.d/50teddybear') } | ||
end | ||
|
||
context 'with type=pref' do | ||
let(:params) { { :type => 'pref', :content => 'di' } } | ||
it { should contain_file('/etc/apt/preferences.d/50teddybear') } | ||
end | ||
|
||
context 'with type=list' do | ||
let(:params) { { :type => 'list', :content => 'di' } } | ||
it { should contain_file('/etc/apt/sources.list.d/teddybear.list') } | ||
end | ||
|
||
context 'with source' do | ||
let(:params) { { :type => 'conf', :source => 'puppet:///la/die/dah' } } | ||
it { | ||
should contain_file('/etc/apt/apt.conf.d/50teddybear').with({ | ||
:ensure => 'file', | ||
:owner => 'root', | ||
:group => 'root', | ||
:mode => '0644', | ||
:source => "#{params[:source]}", | ||
})} | ||
end | ||
|
||
context 'with content' do | ||
let(:params) { default_params } | ||
it { should contain_file('/etc/apt/apt.conf.d/50teddybear').with({ | ||
:ensure => 'file', | ||
:owner => 'root', | ||
:group => 'root', | ||
:mode => '0644', | ||
:content => "#{params[:content]}", | ||
})} | ||
end | ||
end | ||
|
||
describe 'when trying to pull one over' do | ||
context 'with source and content' do | ||
let(:params) { default_params.merge({ :source => 'la' }) } | ||
it do | ||
expect { should compile }.to raise_error(Puppet::Error, /cannot have both /) | ||
end | ||
end | ||
|
||
context 'with type=ext' do | ||
let(:params) { default_params.merge({ :type => 'ext' }) } | ||
it do | ||
expect { should compile }.to raise_error(Puppet::Error, /"ext" does not /) | ||
end | ||
end | ||
|
||
context 'with ensure=banana' do | ||
let(:params) { default_params.merge({ :ensure => 'banana' }) } | ||
it do | ||
expect { should compile }.to raise_error(Puppet::Error, /"banana" does not /) | ||
end | ||
end | ||
|
||
context 'with priority=1.2' do | ||
let(:params) { default_params.merge({ :priority => 1.2 }) } | ||
it do | ||
expect { should compile }.to raise_error(Puppet::Error, /be an integer /) | ||
end | ||
end | ||
end | ||
|
||
describe 'with priority=100' do | ||
let(:params) { default_params.merge({ :priority => 100 }) } | ||
it { should contain_file('/etc/apt/apt.conf.d/100teddybear') } | ||
end | ||
|
||
describe 'with ensure=absent' do | ||
let(:params) { default_params.merge({ :ensure => 'absent' }) } | ||
it { should contain_file('/etc/apt/apt.conf.d/50teddybear').with({ | ||
:ensure => 'absent', | ||
})} | ||
end | ||
|
||
describe 'with file_perms' do | ||
context "{'owner' => 'roosevelt'}" do | ||
let(:params) { default_params.merge({ :file_perms => {'owner' => 'roosevelt'} }) } | ||
it { should contain_file('/etc/apt/apt.conf.d/50teddybear').with({ | ||
:owner => 'roosevelt', | ||
:group => 'root', | ||
:mode => '0644', | ||
})} | ||
end | ||
|
||
context "'group' => 'roosevelt'}" do | ||
let(:params) { default_params.merge({ :file_perms => {'group' => 'roosevelt'} }) } | ||
it { should contain_file('/etc/apt/apt.conf.d/50teddybear').with({ | ||
:owner => 'root', | ||
:group => 'roosevelt', | ||
:mode => '0644', | ||
})} | ||
end | ||
|
||
context "'owner' => 'roosevelt'}" do | ||
let(:params) { default_params.merge({ :file_perms => {'mode' => '0600'} }) } | ||
it { should contain_file('/etc/apt/apt.conf.d/50teddybear').with({ | ||
:owner => 'root', | ||
:group => 'root', | ||
:mode => '0600', | ||
})} | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a warning if
$type == 'list' and $priority
, or is this obvious to apt users?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Priority doesn't make sense for list, it's not a concept that sources recognise so there's no real use or need for it. We should document that we ignore priority in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, cool. At some point there will be massive doc updates, I ... haven't been keeping up with that.