From 0dce05adaec1b3f789302dfec026b79aeded220c Mon Sep 17 00:00:00 2001 From: Robert Drake Date: Tue, 1 Sep 2015 12:00:24 -0400 Subject: [PATCH] Add support for creating pins from main class This lets you create apt::pin resources as an apt param hash. It also supplies appropriate tests and documentation. --- README.md | 4 +++- manifests/init.pp | 7 +++++++ spec/classes/apt_spec.rb | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b2b5546..1c9591d 100644 --- a/README.md +++ b/README.md @@ -243,7 +243,9 @@ Main class, includes all other classes. * `settings`: Creates new `apt::setting` resources. Valid options: a hash to be passed to the [`create_resources` function](https://docs.puppetlabs.com/references/latest/function.html#createresources). Default: {}. -* `sources`: Creates new `apt::setting` resources. Valid options: a hash to be passed to the [`create_resources` function](https://docs.puppetlabs.com/references/latest/function.html#createresources). Default: {}. +* `sources`: Creates new `apt::source` resources. Valid options: a hash to be passed to the [`create_resources` function](https://docs.puppetlabs.com/references/latest/function.html#createresources). Default: {}. + +* `pins`: Creates new `apt::pin` resources. Valid options: a hash to be passed to the [`create_resources` function](https://docs.puppetlabs.com/references/latest/function.html#createresources). Default: {}. * `update`: Configures various update settings. Valid options: a hash made up from the following keys: diff --git a/manifests/init.pp b/manifests/init.pp index b9087cf..2e82502 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -6,6 +6,7 @@ class apt( $sources = {}, $keys = {}, $ppas = {}, + $pins = {}, $settings = {}, ) inherits ::apt::params { @@ -66,6 +67,7 @@ class apt( validate_hash($keys) validate_hash($settings) validate_hash($ppas) + validate_hash($pins) if $_proxy['ensure'] == 'absent' or $_proxy['host'] { apt::setting { 'conf-proxy': @@ -153,4 +155,9 @@ class apt( if $settings { create_resources('apt::setting', $settings) } + + # manage pins if present + if $pins { + create_resources('apt::pin', $pins) + } } diff --git a/spec/classes/apt_spec.rb b/spec/classes/apt_spec.rb index 7578d2e..5aded56 100644 --- a/spec/classes/apt_spec.rb +++ b/spec/classes/apt_spec.rb @@ -237,6 +237,23 @@ describe 'apt' do it { is_expected.to contain_apt__setting('pref-banana')} end + context 'with pins defined on valid osfamily' do + let :facts do + { :osfamily => 'Debian', + :lsbdistcodename => 'precise', + :lsbdistid => 'Debian', + :puppetversion => Puppet.version, + } + end + let(:params) { { :pins => { + 'stable' => { 'priority' => 600, 'order' => 50 }, + 'testing' => { 'priority' => 700, 'order' => 100 }, + } } } + + it { is_expected.to contain_apt__pin('stable') } + it { is_expected.to contain_apt__pin('testing') } + end + describe 'failing tests' do context "purge['sources.list']=>'banana'" do let(:params) { { :purge => { 'sources.list' => 'banana' }, } } -- 2.32.3