From: Daniele Sluijters Date: Thu, 16 Oct 2014 08:07:25 +0000 (+0200) Subject: Merge pull request #375 from raphink/dev/facts_perfs X-Git-Tag: 1.7.0~1^2~1^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=5d96da0c6aac8f0f9192fe6ce63548bdaee149b5;hp=d090ae4ebb9041bc46e161f698732a6bc9d28399;p=puppet-modules%2Fpuppetlabs-apt.git Merge pull request #375 from raphink/dev/facts_perfs Refactor facts to improve performance. --- diff --git a/.travis.yml b/.travis.yml index a40ae50..66e90e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,7 @@ matrix: fast_finish: true include: - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" + env: PUPPET_GEM_VERSION="~> 3.0" - rvm: 1.9.3 env: PUPPET_GEM_VERSION="~> 3.0" - rvm: 2.0.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index bf8553d..4a325f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,43 @@ +##2014-08-20 - Supported Release 1.6.0 +###Summary + +####Features +- Allow URL or domain name for key_server parameter +- Allow custom comment for sources list +- Enable auto-update for Debian squeeze LTS +- Add facts showing available updates +- Test refactoring + +####Bugfixes +- Allow dashes in URL or domain for key_server parameter + +##2014-08-13 - Supported Release 1.5.3 +###Summary + +This is a bugfix releases. It addresses a bad regex, failures with unicode +characters, and issues with the $proxy_host handling in apt::ppa. + +####Features +- Synced files from Modulesync + +####Bugfixes +- Fix regex to follow APT requirements in apt::pin +- Fix for unicode characters +- Fix inconsistent $proxy_host handling in apt and apt::ppa +- Fix typo in README +- Fix broken acceptance tests + +##2014-07-15 - Supported Release 1.5.2 +###Summary + +This release merely updates metadata.json so the module can be uninstalled and +upgraded via the puppet module command. + +##2014-07-10 - Supported Release 1.5.1 +###Summary + +This release has added tests to ensure graceful failure on OSX. + ##2014-06-04 - Release 1.5.0 ###Summary diff --git a/Modulefile b/Modulefile deleted file mode 100644 index 45169b3..0000000 --- a/Modulefile +++ /dev/null @@ -1,14 +0,0 @@ -name 'puppetlabs-apt' -version '1.5.0' -source 'https://github.com/puppetlabs/puppetlabs-apt' -author 'Evolving Web / Puppet Labs' -license 'Apache License 2.0' -summary 'Puppet Labs Apt Module' -description 'APT Module for Puppet' -project_page 'https://github.com/puppetlabs/puppetlabs-apt' - -## Add dependencies, if any: -#dependency 'puppetlabs/stdlib', '2.x' -# The dependency should be written as above but librarian-puppet -# does not support the expression as the PMT does. -dependency 'puppetlabs/stdlib', '>= 2.2.1' diff --git a/README.md b/README.md index 9c52c77..991e961 100644 --- a/README.md +++ b/README.md @@ -1,292 +1,330 @@ -apt -=== +# apt [![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-apt.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-apt) -Overview --------- +## Overview -The APT module provides a simple interface for managing APT source, key, and definitions with Puppet. +The apt module provides a simple interface for managing Apt source, key, and definitions with Puppet. -Module Description ------------------- +## Module Description -APT automates obtaining and installing software packages on \*nix systems. +The apt module automates obtaining and installing software packages on \*nix systems. -***Note:** While this module allows the use of short keys, we STRONGLY RECOMMEND that you DO NOT USE short keys, as they pose a serious security issue in that they open you up to collision attacks.* +**Note**: While this module allows the use of short keys, **we urge you NOT to use short keys**, as they pose a serious security issue by opening you up to collision attacks. -Setup ------ +## Setup -**What APT affects:** +### What apt affects: -* package/service/configuration files for APT - * NOTE: Setting the `purge_preferences` or `purge_preferences_d` parameters to 'true' will destroy any existing configuration that was not declared with puppet. The default for these parameters is 'false'. -* your system's `sources.list` file and `sources.list.d` directory - * NOTE: Setting the `purge_sources_list` and `purge_sources_list_d` parameters to 'true' will destroy any existing content that was not declared with Puppet. The default for these parameters is 'false'. -* system repositories -* authentication keys +* Package/service/configuration files for Apt +* Your system's `sources.list` file and `sources.list.d` directory +* System repositories +* Authentication keys -### Beginning with APT +**Note**: Setting the apt module's `purge_sources_list` and `purge_sources_list_d` parameters to 'true' will **destroy** any existing content that was not declared with Puppet. The default for these parameters is 'false'. -To begin using the APT module with default parameters, declare the class +### Beginning with apt - include apt +To begin using the apt module with default parameters, declare the class with `include apt`. -Puppet code that uses anything from the APT module requires that the core apt class be declared/\s\+$//e +Any Puppet code that uses anything from the apt module requires that the core apt class be declared. -Usage ------ +## Usage -Using the APT module consists predominantly in declaring classes that provide desired functionality and features. +Using the apt module consists predominantly of declaring classes and defined types that provide the desired functionality and features. This module provides common resources and options that are shared by the various defined types in the apt module, so you **must always** include this class in your manifests. -### apt +``` +class { 'apt': + always_apt_update => false, + apt_update_frequency => undef, + disable_keys => undef, + proxy_host => false, + proxy_port => '8080', + purge_sources_list => false, + purge_sources_list_d => false, + purge_preferences_d => false, + update_timeout => undef, + fancy_progress => undef +} +``` -`apt` provides a number of common resources and options that are shared by the various defined types in this module, so you MUST always include this class in your manifests. +## Reference -The parameters for `apt` are not required in general and are predominantly for development environment use-cases. +### Classes - class { 'apt': - always_apt_update => false, - disable_keys => undef, - proxy_host => false, - proxy_port => '8080', - purge_sources_list => false, - purge_sources_list_d => false, - purge_preferences_d => false, - update_timeout => undef, - fancy_progress => undef - } - -Puppet will manage your system's `sources.list` file and `sources.list.d` directory but will do its best to respect existing content. - -If you declare your apt class with `purge_sources_list`, `purge_sources_list_d`, `purge_preferences` and `purge_preferences_d` set to 'true', Puppet will unapologetically purge any existing content it finds that wasn't declared with Puppet. - -### apt::builddep - -Installs the build depends of a specified package. - - apt::builddep { 'glusterfs-server': } - -### 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. - - apt::force { 'glusterfs-server': - release => 'unstable', - version => '3.0.3', - require => Apt::Source['debian_unstable'], - } - -### apt_key - -A native Puppet type and provider for managing GPG keys for APT is provided by -this module. - - apt_key { 'puppetlabs': - ensure => 'present', - id => '4BD6EC30', - } - -You can additionally set the following attributes: - - * `source`: HTTP, HTTPS or FTP location of a GPG key or path to a file on the - target host; - * `content`: Instead of pointing to a file, pass the key in as a string; - * `server`: The GPG key server to use. It defaults to *keyserver.ubuntu.com*; - * `keyserver_options`: Additional options to pass to `--keyserver`. - -Because it is a native type it can be used in and queried for with MCollective. - -### apt::key - -Adds a key to the list of keys used by APT to authenticate packages. This type -uses the aforementioned `apt_key` native type. As such it no longer requires -the wget command that the old implementation depended on. - - apt::key { 'puppetlabs': - key => '4BD6EC30', - key_server => 'pgp.mit.edu', - } - - apt::key { 'jenkins': - key => 'D50582E6', - key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key', - } - -### apt::pin - -Adds an apt pin for a certain release. +* `apt`: Main class, provides common resources and options. Allows Puppet to manage your system's sources.list file and sources.list.d directory, but it does its best to respect existing content. - apt::pin { 'karmic': priority => 700 } - apt::pin { 'karmic-updates': priority => 700 } - apt::pin { 'karmic-security': priority => 700 } + If you declare your apt class with `purge_sources_list`, `purge_sources_list_d`, `purge_preferences` and `purge_preferences_d` set to 'true', Puppet will unapologetically purge any existing content it finds that wasn't declared with Puppet. + +* `apt::backports`: This class adds the necessary components to get backports for Ubuntu and Debian. The release name defaults to `$lsbdistcodename`. Setting this manually can cause undefined and potentially serious behavior. -Note you can also specifying more complex pins using distribution properties. + By default, this class drops a pin-file for backports, pinning it to a priority of 200. This is lower than the normal Debian archive, which gets a priority of 500 to ensure that packages with `ensure => latest` don't get magically upgraded from backports without your explicit permission. - apt::pin { 'stable': - priority => -10, - originator => 'Debian', - release_version => '3.0', - component => 'main', - label => 'Debian' - } - -If you wish to pin a number of packages you may specify the packages as a space -delimited string using the `packages` attribute or pass in an array of package -names. + If you raise the priority through the `pin_priority` parameter to 500---identical to the rest of the Debian mirrors---normal policy goes into effect, and Apt installs or upgrades to the newest version. This means that if a package is available from backports, it and its dependencies are pulled in from backports unless you explicitly set the `ensure` attribute of the `package` resource to `installed`/`present` or a specific version. -### apt::hold +* `apt::params`: Sets defaults for the apt module parameters. -When you wish to hold a package in Puppet is should be done by passing in -'held' as the ensure attribute to the package resource. However, a lot of -public modules do not take this into account and generally do not work well -with an ensure of 'held'. +* `apt::release`: Sets the default Apt release. This class is particularly useful when using repositories that are unstable in Ubuntu, such as Debian. -There is an additional issue that when Puppet is told to hold a package, it -will hold it at the current version installed, there is no way to tell it in -one go to install a specific version and then hold that version without using -an exec resource that wraps `dpkg --set-selections` or `apt-mark`. + ``` + class { 'apt::release': + release_id => 'precise', + } + ``` -At first glance this could also be solved by just passing the version required -to the ensure attribute but that only means that Puppet will install that -version once it processes that package. It does not inform apt that we want -this package to be held. In other words; if another package somehow wants to -upgrade this one (because of a version requirement in a dependency), apt -should not allow it. +* `apt::unattended_updates`: This class manages the unattended-upgrades package and related configuration files for Ubuntu and Debian systems. You can configure the class to automatically upgrade all new package releases or just security releases. -In order to solve this you can use apt::hold. It's implemented by creating -a preferences file with a priority of 1001, meaning that under normal -circumstances this preference will always win. Because the priority is > 1000 -apt will interpret this as 'this should be the version installed and I am -allowed to downgrade the current package if needed'. + ``` + apt::unattended_upgrades { + origins = $::apt::params::origins, + blacklist = [], + update = '1', + download = '1', + upgrade = '1', + autoclean = '7', + } + ``` + +* `apt::update`: Runs `apt-get update`, updating the list of available packages and their versions without installing or upgrading any packages. The update runs on the first Puppet run after you include the class, then whenever `notify => Exec['apt_update']` occurs; i.e., whenever config files get updated or other relevant changes occur. If you set the `always_apt_update` parameter to 'true', the update runs on every Puppet run. -With this you can now set a package's ensure attribute to 'latest' but still -get the version specified by apt::hold. You can do it like this: +### Types - apt::hold { 'vim': - version => '2:7.3.547-7', - } +* `apt_key` -Since you might just want to hold Vim at version 7.3 and not care about the -rest you can also pass in a version with a glob: - - apt::hold { 'vim': - version => '2:7.3.*', - } + A native Puppet type and provider for managing GPG keys for Apt is provided by this module. -### apt::ppa + ``` + apt_key { 'puppetlabs': + ensure => 'present', + id => '1054B7A24BD6EC30', + } + ``` -Adds a ppa repository using `add-apt-repository`. + You can additionally set the following attributes: - apt::ppa { 'ppa:drizzle-developers/ppa': } + * `source`: HTTP, HTTPS or FTP location of a GPG key or path to a file on the target host. + * `content`: Instead of pointing to a file, pass the key in as a string. + * `server`: The GPG key server to use. It defaults to *keyserver.ubuntu.com*. + * `keyserver_options`: Additional options to pass to `--keyserver`. -### apt::release + Because apt_key is a native type, you can use it and query for it with MCollective. -Sets the default apt release. This class is particularly useful when using repositories, like Debian, that are unstable in Ubuntu. +### Defined Types - class { 'apt::release': - release_id => 'precise', - } +* `apt::builddep`: Installs the build dependencies of a specified package. -### apt::source + `apt::builddep { 'glusterfs-server': }` + +* `apt::conf`: Specifies a custom configuration file. The priority defaults to 50, but you can set the priority parameter to load the file earlier or later. The content parameter passes specified content, if any, into the file resource. -Adds an apt source to `/etc/apt/sources.list.d/`. +* `apt::hold`: Holds a specific version of a package. You can hold a package to a full version or a partial version. - apt::source { 'debian_unstable': - comment => 'This is the iWeb Debian unstable mirror', - location => 'http://debian.mirror.iweb.ca/debian/', - release => 'unstable', - repos => 'main contrib non-free', - required_packages => 'debian-keyring debian-archive-keyring', - key => '46925553', - key_server => 'subkeys.pgp.net', - pin => '-10', - include_src => true - } + To set a package's ensure attribute to 'latest' but get the version specified by `apt::hold`: -If you would like to configure your system so the source is the Puppet Labs APT repository + ``` + apt::hold { 'vim': + version => '2:7.3.547-7', + } + ``` + + Alternatively, if you want to hold your package at a partial version, you can use a wildcard. For example, you can hold Vim at version 7.3.*: + + + ``` + apt::hold { 'vim': + version => '2:7.3.*', + } + ``` + +* `apt::force`: Forces a package to be installed from a specific release. This is particularly useful when using repositories that are unstable in Ubuntu, such as Debian. + + ``` + apt::force { 'glusterfs-server': + release => 'unstable', + version => '3.0.3', + cfg_files => 'unchanged', + cfg_missing => true, + require => Apt::Source['debian_unstable'], + } + ``` - apt::source { 'puppetlabs': - location => 'http://apt.puppetlabs.com', - repos => 'main', - key => '4BD6EC30', - key_server => 'pgp.mit.edu', + Valid values for `cfg_files` are: + * 'new': Overwrites all existing configuration files with newer ones. + * 'old': Forces usage of all old files. + * 'unchanged: Updates only unchanged config files. + * 'none': Provides backward-compatibility with existing Puppet manifests. + + Valid values for `cfg_missing` are 'true', 'false'. Setting this to 'false' provides backward compatability; setting it to 'true' checks for and installs missing configuration files for the selected package. + +* `apt::key`: Adds a key to the list of keys used by Apt to authenticate packages. This type uses the aforementioned `apt_key` native type. As such, it no longer requires the `wget` command on which the old implementation depended. + + ``` + apt::key { 'puppetlabs': + key => '1054B7A24BD6EC30', + key_server => 'pgp.mit.edu', + } + + apt::key { 'jenkins': + key => '9B7D32F2D50582E6', + key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key', + } + ``` + +* `apt::pin`: Defined type that adds an Apt pin for a certain release. + + ``` + apt::pin { 'karmic': priority => 700 } + apt::pin { 'karmic-updates': priority => 700 } + apt::pin { 'karmic-security': priority => 700 } + ``` + + Note that you can also specify more complex pins using distribution properties. + + ``` + apt::pin { 'stable': + priority => -10, + originator => 'Debian', + release_version => '3.0', + component => 'main', + label => 'Debian' + } + ``` + + If you want to pin a number of packages, you can specify the packages as a space-delimited string using the `packages` attribute, or you can pass in an array of package names. + +* `apt::ppa`: Adds a PPA repository using `add-apt-repository`. For example, `apt::ppa { 'ppa:drizzle-developers/ppa': }`. + +* `apt::source`: Adds an Apt source to `/etc/apt/sources.list.d/`. For example: + + ``` + apt::source { 'debian_unstable': + comment => 'This is the iWeb Debian unstable mirror', + location => 'http://debian.mirror.iweb.ca/debian/', + release => 'unstable', + repos => 'main contrib non-free', + required_packages => 'debian-keyring debian-archive-keyring', + key => '8B48AD6246925553', + key_server => 'subkeys.pgp.net', + pin => '-10', + include_src => true, + include_deb => true + } + ``` + + For example, to configure your system so the source is the Puppet Labs Apt repository: + + ``` + apt::source { 'puppetlabs': + location => 'http://apt.puppetlabs.com', + repos => 'main', + key => '1054B7A24BD6EC30', + key_server => 'pgp.mit.edu', } + ``` ### Facts -There are a few facts included within the apt module describing the state of the apt system: +The apt module includes a few facts to describe the state of the Apt system: + +* `apt_updates`: The number of updates available on the system +* `apt_security_updates`: The number of updates which are security updates +* `apt_package_updates`: The package names that are available for update. In Facter 2.0 and later, this will be a list type; in earlier versions, it is a comma-delimited string. +* `apt_update_last_success`: The date, in epochtime, of the most recent successful `apt-get update` run. This is determined by reading the mtime of /var/lib/apt/periodic/update-success-stamp. -* `apt_updates` - the number of updates available on the system -* `apt_security_updates` - the number of updates which are security updates -* `apt_package_updates` - the package names that are available for update. On Facter 2.0 and newer this will be a list type, in earlier versions it is a comma delimitered string. +**Note:** The facts depend on 'update-notifier' being installed on your system. Though this is a GNOME daemon only the support files are needed so the package 'update-notifier-common' is enough to enable this functionality. #### Hiera example + +```
 apt::sources:
   'debian_unstable':
-      location: 'http://debian.mirror.iweb.ca/debian/'
-      release: 'unstable'
-      repos: 'main contrib non-free'
-      required_packages: 'debian-keyring debian-archive-keyring'
-      key: '55BE302B'
-      key_server: 'subkeys.pgp.net'
-      pin: '-10'
-      include_src: 'true'
+    location: 'http://debian.mirror.iweb.ca/debian/'
+    release: 'unstable'
+    repos: 'main contrib non-free'
+    required_packages: 'debian-keyring debian-archive-keyring'
+    key: '9AA38DCD55BE302B'
+    key_server: 'subkeys.pgp.net'
+    pin: '-10'
+    include_src: 'true'
+    include_deb: 'true'
 
   'puppetlabs':
-      location: 'http://apt.puppetlabs.com'
-      repos: 'main'
-      key: '4BD6EC30'
-      key_server: 'pgp.mit.edu'
+    location: 'http://apt.puppetlabs.com'
+    repos: 'main'
+    key: '1054B7A24BD6EC30'
+    key_server: 'pgp.mit.edu'
 
+``` + +### Parameters + +#### apt + +* `always_apt_update`: Set to 'true' to update Apt on every run. This setting is intended for development environments where package updates are frequent. Defaults to 'false'. +* `apt_update_frequency`: Sets the run frequency for `apt-get update`. Defaults to 'reluctantly'. Accepts the following values: + * 'always': Runs update at every Puppet run. + * 'daily': Runs update daily; that is, `apt-get update` runs if the value of `apt_update_last_success` is less than current epoch time - 86400. If the exec resource `apt_update` is notified, `apt-get update` runs regardless of this value. + * 'weekly': Runs update weekly; that is, `apt-get update` runs if the value of `apt_update_last_success` is less than current epoch time - 604800. If the exec resource `apt_update` is notified, `apt-get update` runs regardless of this value. + * 'reluctantly': Only runs `apt-get update` if the exec resource `apt_update` is notified. This is the default setting. +* `disable_keys`: Disables the requirement for all packages to be signed. +* `proxy_host`: Configures a proxy host and stores the configuration in /etc/apt/apt.conf.d/01proxy. +* `proxy_port`: Configures a proxy port and stores the configuration in /etc/apt/apt.conf.d/01proxy. +* `purge_sources_list`: If set to 'true', Puppet purges all unmanaged entries from sources.list. Accepts 'true' or 'false'. Defaults to 'false'. +* `purge_sources_list_d`: If set to 'true', Puppet purges all unmanaged entries from sources.list.d. Accepts 'true' or 'false'. Defaults to 'false'. +* `update_timeout`: Overrides the exec timeout in seconds for `apt-get update`. Defaults to exec default (300). +* `update_tries`: Sets how many times to attempt running `apt-get update`. Use this to work around transient DNS and HTTP errors. By default, the command runs only once. +* `sources`: Passes a hash to create_resource to make new `apt::source` resources. +* `fancy_progress`: Enables fancy progress bars for apt. Accepts 'true', 'false'. Defaults to 'false'. + +####apt::unattended_upgrades + +* `origins`: The repositories from which to automatically upgrade included packages. +* `blacklist`: A list of packages to **not** automatically upgrade. +* `update`: How often, in days, to run `apt-get update`. +* `download`: How often, in days, to run `apt-get upgrade --download-only`. +* `upgrade`: How often, in days, to upgrade packages included in the origins list. +* `autoclean`: How often, in days, to run `apt-get autoclean`. +* `randomsleep`: How long, in seconds, to randomly wait before applying upgrades. ### Testing -The APT module is mostly a collection of defined resource types, which provide reusable logic that can be leveraged to manage APT. It does provide smoke tests for testing functionality on a target system, as well as spec tests for checking a compiled catalog against an expected set of resources. +The apt module is mostly a collection of defined resource types, which provide reusable logic for managing Apt. It provides smoke tests for testing functionality on a target system, as well as spec tests for checking a compiled catalog against an expected set of resources. #### Example Test -This test will set up a Puppet Labs apt repository. Start by creating a new smoke test in the apt module's test folder. Call it puppetlabs-apt.pp. Inside, declare a single resource representing the Puppet Labs APT source and gpg key - - apt::source { 'puppetlabs': - location => 'http://apt.puppetlabs.com', - repos => 'main', - key => '4BD6EC30', - key_server => 'pgp.mit.edu', - } - -This resource creates an apt source named puppetlabs and gives Puppet information about the repository's location and key used to sign its packages. Puppet leverages Facter to determine the appropriate release, but you can set it directly by adding the release type. - -Check your smoke test for syntax errors - - $ puppet parser validate tests/puppetlabs-apt.pp - -If you receive no output from that command, it means nothing is wrong. Then apply the code +This test sets up a Puppet Labs Apt repository. Start by creating a new smoke test, called puppetlabs-apt.pp, in the apt module's test folder. In this test, declare a single resource representing the Puppet Labs Apt source and GPG key: - $ puppet apply --verbose tests/puppetlabs-apt.pp - notice: /Stage[main]//Apt::Source[puppetlabs]/File[puppetlabs.list]/ensure: defined content as '{md5}3be1da4923fb910f1102a233b77e982e' - info: /Stage[main]//Apt::Source[puppetlabs]/File[puppetlabs.list]: Scheduling refresh of Exec[puppetlabs apt update] - notice: /Stage[main]//Apt::Source[puppetlabs]/Exec[puppetlabs apt update]: Triggered 'refresh' from 1 events> +``` +apt::source { 'puppetlabs': + location => 'http://apt.puppetlabs.com', + repos => 'main', + key => '1054B7A24BD6EC30', + key_server => 'pgp.mit.edu', +} +``` -The above example used a smoke test to easily lay out a resource declaration and apply it on your system. In production, you may want to declare your APT sources inside the classes where they’re needed. +This resource creates an Apt source named puppetlabs and gives Puppet information about the repository's location and the key used to sign its packages. Puppet leverages Facter to determine the appropriate release, but you can set this directly by adding the release type. -Implementation --------------- +Check your smoke test for syntax errors: -### apt::backports +`$ puppet parser validate tests/puppetlabs-apt.pp` -Adds the necessary components to get backports for Ubuntu and Debian. The release name defaults to `$lsbdistcodename`. Setting this manually can cause undefined behavior (read: universe exploding). +If you receive no output from that command, it means nothing is wrong. Then, apply the code: -By default this class drops a Pin-file for Backports pinning it to a priority of 200, lower than the normal Debian archive which gets a priority of 500 to ensure your packages with `ensure => latest` don't get magically upgraded from Backports without your explicit say-so. +``` +$ puppet apply --verbose tests/puppetlabs-apt.pp +notice: /Stage[main]//Apt::Source[puppetlabs]/File[puppetlabs.list]/ensure: defined content as '{md5}3be1da4923fb910f1102a233b77e982e' +info: /Stage[main]//Apt::Source[puppetlabs]/File[puppetlabs.list]: Scheduling refresh of Exec[puppetlabs apt update] +notice: /Stage[main]//Apt::Source[puppetlabs]/Exec[puppetlabs apt update]: Triggered 'refresh' from 1 events> +``` -If you raise the priority through the `pin_priority` parameter to *500*, identical to the rest of the Debian mirrors, normal policy goes into effect and the newest version wins/becomes the candidate apt will want to install or upgrade to. This means that if a package is available from Backports it and its dependencies will be pulled in from Backports unless you explicitly set the `ensure` attribute of the `package` resource to `installed`/`present` or a specific version. +The above example uses a smoke test to lay out a resource declaration and apply it on your system. In production, you might want to declare your Apt sources inside the classes where they’re needed. Limitations ----------- -This module should work across all versions of Debian/Ubuntu and support all major APT repository management features. +This module should work across all versions of Debian/Ubuntu and support all major Apt repository management features. Development ------------ @@ -330,3 +368,4 @@ A lot of great people have contributed to this module. A somewhat current list f * Zach Leslie * Daniele Sluijters * Daniel Paulus +* Wolf Noble diff --git a/lib/facter/apt_update_last_success.rb b/lib/facter/apt_update_last_success.rb new file mode 100644 index 0000000..21c33d5 --- /dev/null +++ b/lib/facter/apt_update_last_success.rb @@ -0,0 +1,18 @@ +require 'facter' + +#This is derived from the file /var/lib/apt/periodic/update-success-stamp +# This is generated upon a successful apt-get update run natively in ubuntu. +# the Puppetlabs-apt module deploys this same functionality for other debian-ish OSes +Facter.add('apt_update_last_success') do + confine :osfamily => 'Debian' + setcode do + if File.exists?('/var/lib/apt/periodic/update-success-stamp') + #get epoch time + lastsuccess = File.mtime('/var/lib/apt/periodic/update-success-stamp').to_i + lastsuccess + else + lastsuccess = -1 + lastsuccess + end + end +end diff --git a/lib/puppet/provider/apt_key/apt_key.rb b/lib/puppet/provider/apt_key/apt_key.rb index 1d3c174..3ef9431 100644 --- a/lib/puppet/provider/apt_key/apt_key.rb +++ b/lib/puppet/provider/apt_key/apt_key.rb @@ -31,7 +31,7 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do else key_output = apt_key('list') end - key_array = apt_key('list').split("\n").collect do |line| + key_array = key_output.split("\n").collect do |line| line_hash = key_line_hash(line) next unless line_hash expired = false @@ -57,7 +57,12 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do def self.prefetch(resources) apt_keys = instances resources.keys.each do |name| - if provider = apt_keys.find{ |key| key.name == name } + if name.length == 16 + shortname=name[8..-1] + else + shortname=name + end + if provider = apt_keys.find{ |key| key.name == shortname } resources[name].provider = provider end end diff --git a/lib/puppet/type/apt_key.rb b/lib/puppet/type/apt_key.rb index e2cb8d9..f552473 100644 --- a/lib/puppet/type/apt_key.rb +++ b/lib/puppet/type/apt_key.rb @@ -36,11 +36,7 @@ Puppet::Type.newtype(:apt_key) do else id = value.upcase end - if id.length == 16 - id[8..-1] - else - id - end + id end end diff --git a/manifests/backports.pp b/manifests/backports.pp index eafa506..ee46209 100644 --- a/manifests/backports.pp +++ b/manifests/backports.pp @@ -38,12 +38,30 @@ class apt::backports( fail('$pin_priority must be an integer') } - $release_real = downcase($release) - $key = $::lsbdistid ? { + if $::lsbdistid == 'LinuxMint' { + if $::lsbdistcodename == 'debian' { + $distid = 'debian' + $release_real = 'wheezy' + } else { + $distid = 'ubuntu' + $release_real = $::lsbdistcodename ? { + 'qiana' => 'trusty', + 'petra' => 'saucy', + 'olivia' => 'raring', + 'nadia' => 'quantal', + 'maya' => 'precise', + } + } + } else { + $distid = $::lsbdistid + $release_real = downcase($release) + } + + $key = $distid ? { 'debian' => '46925553', 'ubuntu' => '437D05B5', } - $repos = $::lsbdistid ? { + $repos = $distid ? { 'debian' => 'main contrib non-free', 'ubuntu' => 'main universe multiverse restricted', } diff --git a/manifests/builddep.pp b/manifests/builddep.pp index 3294f71..3beadeb 100644 --- a/manifests/builddep.pp +++ b/manifests/builddep.pp @@ -6,7 +6,7 @@ define apt::builddep() { exec { "apt-builddep-${name}": command => "/usr/bin/apt-get -y --force-yes build-dep ${name}", logoutput => 'on_failure', - notify => Exec['apt_update'], + require => Exec['apt_update'], } # Need anchor to provide containment for dependencies. diff --git a/manifests/force.pp b/manifests/force.pp index 152bb67..a73f7ab 100644 --- a/manifests/force.pp +++ b/manifests/force.pp @@ -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 ? { @@ -19,6 +24,18 @@ define apt::force( 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'" @@ -34,7 +51,7 @@ define apt::force( } } - 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, diff --git a/manifests/hold.pp b/manifests/hold.pp index c4016c6..61e8afc 100644 --- a/manifests/hold.pp +++ b/manifests/hold.pp @@ -40,13 +40,13 @@ define apt::hold( } if $ensure == 'present' { - ::apt::pin { "hold ${package} at ${version}": + ::apt::pin { "hold_${package}": packages => $package, version => $version, priority => $priority, } } else { - ::apt::pin { "hold ${package} at ${version}": + ::apt::pin { "hold_${package}": ensure => 'absent', } } diff --git a/manifests/init.pp b/manifests/init.pp index 597774c..89fb684 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -5,15 +5,32 @@ # Parameters: # The parameters listed here are not required in general and were # added for use cases related to development environments. +# # disable_keys - disables the requirement for all packages to be signed +# # always_apt_update - rather apt should be updated on every run (intended # for development environments where package updates are frequent) +# +# apt_update_frequency - *string* Supported values: +# **always**: Will fire `apt-get update` at every puppet run. Intended to +# deprecate the `always_apt_update` parameter. +# **daily**: Trigger `apt-get update` if the value of the fact +# `apt_update_last_success` is less than current epoch time - 86400. +# *notifying the apt_update exec will trigger apt-get update regardless* +# **weekly**: Trigger `apt-get update` if the value of the fact +# `apt_update_last_success` is less than current epoch time - 604800. +# *notifying the apt_update exec will trigger apt-get update regardless* +# **reluctantly**: *Default* only run apt-get update if the exec resource `apt_update` is notified. +# # purge_sources_list - Accepts true or false. Defaults to false If set to # true, Puppet will purge all unmanaged entries from sources.list +# # purge_sources_list_d - Accepts true or false. Defaults to false. If set # to true, Puppet will purge all unmanaged entries from sources.list.d +# # update_timeout - Overrides the exec timeout in seconds for apt-get update. # If not set defaults to Exec's default (300) +# # update_tries - Number of times that `apt-get update` will be tried. Use this # to work around transient DNS and HTTP errors. By default, the command # will only be run once. @@ -27,6 +44,7 @@ class apt( $always_apt_update = false, + $apt_update_frequency = 'reluctantly', $disable_keys = undef, $proxy_host = undef, $proxy_port = '8080', @@ -44,6 +62,8 @@ class apt( fail('This module only works on Debian or derivatives like Ubuntu') } + $frequency_options = ['always','daily','weekly','reluctantly'] + validate_re($apt_update_frequency, $frequency_options) include apt::params include apt::update @@ -61,6 +81,14 @@ class apt( } } + file { '/etc/apt/apt.conf.d/15update-stamp': + ensure => 'file', + content => 'APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};', + group => 'root', + mode => '0644', + owner => 'root', + } + $root = $apt::params::root $apt_conf_d = $apt::params::apt_conf_d $sources_list_d = $apt::params::sources_list_d @@ -89,8 +117,8 @@ class apt( if $purge_preferences { file { 'apt-preferences': - ensure => absent, - path => "${root}/preferences", + ensure => absent, + path => "${root}/preferences", } } @@ -113,8 +141,8 @@ class apt( } false: { file { '99progressbar': - ensure => absent, - path => "${apt_conf_d}/99progressbar", + ensure => absent, + path => "${apt_conf_d}/99progressbar", } } undef: {} # do nothing @@ -139,25 +167,31 @@ class apt( default: { fail('Valid values for disable_keys are true or false') } } - $proxy_set = $proxy_host ? { - undef => absent, - default => present - } - - file { '01proxy': - ensure => $proxy_set, - path => "${apt_conf_d}/01proxy", - content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";\n", - notify => Exec['apt_update'], - mode => '0644', - owner => root, - group => root, + case $proxy_host { + false, '', undef: { + file { '01proxy': + ensure => absent, + path => "${apt_conf_d}/01proxy", + notify => Exec['apt_update'], + } + } + default: { + file { '01proxy': + ensure => present, + path => "${apt_conf_d}/01proxy", + content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";\n", + notify => Exec['apt_update'], + mode => '0644', + owner => root, + group => root, + } + } } file { 'old-proxy-file': - ensure => absent, - path => "${apt_conf_d}/proxy", - notify => Exec['apt_update'], + ensure => absent, + path => "${apt_conf_d}/proxy", + notify => Exec['apt_update'], } # Need anchor to provide containment for dependencies. diff --git a/manifests/params.pp b/manifests/params.pp index f635b58..d33a401 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -6,14 +6,41 @@ class apt::params { $preferences_d = "${root}/preferences.d" case $::lsbdistid { + 'ubuntu', 'debian': { + $distid = $::lsbdistid + $distcodename = $::lsbdistcodename + } + 'linuxmint': { + if $::lsbdistcodename == 'debian' { + $distid = 'debian' + $distcodename = 'wheezy' + } else { + $distid = 'ubuntu' + $distcodename = $::lsbdistcodename ? { + 'qiana' => 'trusty', + 'petra' => 'saucy', + 'olivia' => 'raring', + 'nadia' => 'quantal', + 'maya' => 'precise', + } + } + } + '': { + fail('Unable to determine lsbdistid, is lsb-release installed?') + } + default: { + fail("Unsupported lsbdistid (${::lsbdistid})") + } + } + case $distid { 'debian': { - case $::lsbdistcodename { + case $distcodename { 'squeeze': { $backports_location = 'http://backports.debian.org/debian-backports' $legacy_origin = true - $origins = ['${distro_id} oldstable', - '${distro_id} ${distro_codename}-security', - '${distro_id} ${distro_codename}-lts'] + $origins = ['${distro_id} oldstable', #lint:ignore:single_quote_string_with_variables + '${distro_id} ${distro_codename}-security', #lint:ignore:single_quote_string_with_variables + '${distro_id} ${distro_codename}-lts'] #lint:ignore:single_quote_string_with_variables } 'wheezy': { $backports_location = 'http://ftp.debian.org/debian/' @@ -28,29 +55,26 @@ class apt::params { } } 'ubuntu': { - case $::lsbdistcodename { + case $distcodename { 'lucid': { $backports_location = 'http://us.archive.ubuntu.com/ubuntu' $ppa_options = undef $legacy_origin = true - $origins = ['${distro_id} ${distro_codename}-security'] + $origins = ['${distro_id} ${distro_codename}-security'] #lint:ignore:single_quote_string_with_variables } 'precise', 'trusty': { $backports_location = 'http://us.archive.ubuntu.com/ubuntu' $ppa_options = '-y' $legacy_origin = true - $origins = ['${distro_id}:${distro_codename}-security'] + $origins = ['${distro_id}:${distro_codename}-security'] #lint:ignore:single_quote_string_with_variables } default: { $backports_location = 'http://old-releases.ubuntu.com/ubuntu' $ppa_options = '-y' $legacy_origin = true - $origins = ['${distro_id}:${distro_codename}-security'] + $origins = ['${distro_id}:${distro_codename}-security'] #lint:ignore:single_quote_string_with_variables } } } - default: { - fail("Unsupported lsbdistid (${::lsbdistid})") - } } } diff --git a/manifests/pin.pp b/manifests/pin.pp index 2ce81fd..54961ec 100644 --- a/manifests/pin.pp +++ b/manifests/pin.pp @@ -16,7 +16,6 @@ define apt::pin( $originator = '', # o= $label = '' # l= ) { - include apt::params $preferences_d = $apt::params::preferences_d @@ -35,7 +34,7 @@ define apt::pin( $pin_release = join($pin_release_array, '') # Read the manpage 'apt_preferences(5)', especially the chapter - # 'Thea Effect of APT Preferences' to understand the following logic + # 'The Effect of APT Preferences' to understand the following logic # and the difference between specific and general form if is_array($packages) { $packages_string = join($packages, ' ') @@ -44,24 +43,17 @@ define apt::pin( } if $packages_string != '*' { # specific form - if ( $pin_release != '' and ( $origin != '' or $version != '' )) or - ( $origin != '' and ( $pin_release != '' or $version != '' )) or ( $version != '' and ( $pin_release != '' or $origin != '' )) { fail('parameters release, origin, and version are mutually exclusive') } - } else { # general form - if $version != '' { fail('parameter version cannot be used in general form') } - - if ( $pin_release != '' and $origin != '' ) or - ( $origin != '' and $pin_release != '' ) { - fail('parmeters release and origin are mutually exclusive') + if ( $pin_release != '' and $origin != '' ) { + fail('parameters release and origin are mutually exclusive') } - } diff --git a/manifests/ppa.pp b/manifests/ppa.pp index a55e1e0..0fdcc95 100644 --- a/manifests/ppa.pp +++ b/manifests/ppa.pp @@ -36,23 +36,25 @@ define apt::ppa( if defined(Class[apt]) { $proxy_host = $apt::proxy_host $proxy_port = $apt::proxy_port - case $proxy_host { - false, '': { + case $proxy_host { + false, '', undef: { $proxy_env = [] - } - default: {$proxy_env = ["http_proxy=http://${proxy_host}:${proxy_port}", "https_proxy=http://${proxy_host}:${proxy_port}"]} + } + default: { + $proxy_env = ["http_proxy=http://${proxy_host}:${proxy_port}", "https_proxy=http://${proxy_host}:${proxy_port}"] + } } } else { $proxy_env = [] } exec { "add-apt-repository-${name}": - environment => $proxy_env, - command => "/usr/bin/add-apt-repository ${options} ${name}", - unless => "/usr/bin/test -s ${sources_list_d}/${sources_list_d_filename}", - user => 'root', - logoutput => 'on_failure', - notify => Exec['apt_update'], - require => [ + environment => $proxy_env, + command => "/usr/bin/add-apt-repository ${options} ${name}", + unless => "/usr/bin/test -s ${sources_list_d}/${sources_list_d_filename}", + user => 'root', + logoutput => 'on_failure', + notify => Exec['apt_update'], + require => [ File['sources.list.d'], Package[$package], ], @@ -67,9 +69,6 @@ define apt::ppa( file { "${sources_list_d}/${sources_list_d_filename}": ensure => 'absent', - mode => '0644', - owner => 'root', - group => 'root', notify => Exec['apt_update'], } } diff --git a/manifests/source.pp b/manifests/source.pp index dd00adc..259d0eb 100644 --- a/manifests/source.pp +++ b/manifests/source.pp @@ -8,6 +8,7 @@ define apt::source( $release = 'UNDEF', $repos = 'main', $include_src = true, + $include_deb = true, $required_packages = false, $key = undef, $key_server = 'keyserver.ubuntu.com', diff --git a/manifests/unattended_upgrades.pp b/manifests/unattended_upgrades.pp index 7e3ccc4..069c359 100644 --- a/manifests/unattended_upgrades.pp +++ b/manifests/unattended_upgrades.pp @@ -28,6 +28,7 @@ class apt::unattended_upgrades ( $remove_unused = true, $auto_reboot = false, $dl_limit = 'NONE', + $randomsleep = undef, $enable = '1', $backup_interval = '0', $backup_level = '3', @@ -48,22 +49,31 @@ class apt::unattended_upgrades ( ) validate_array($origins) + if $randomsleep { + unless is_numeric($randomsleep) { + fail('randomsleep must be numeric') + } + } + package { 'unattended-upgrades': ensure => present, } - File { + file { '/etc/apt/apt.conf.d/50unattended-upgrades': ensure => file, owner => 'root', group => 'root', mode => '0644', + content => template('apt/50unattended-upgrades.erb'), require => Package['unattended-upgrades'], } - file { - '/etc/apt/apt.conf.d/50unattended-upgrades': - content => template('apt/50unattended-upgrades.erb'); - '/etc/apt/apt.conf.d/10periodic': - content => template('apt/10periodic.erb'); + file { '/etc/apt/apt.conf.d/10periodic': + ensure => file, + owner => 'root', + group => 'root', + mode => '0644', + content => template('apt/10periodic.erb'), + require => Package['unattended-upgrades'], } } diff --git a/manifests/update.pp b/manifests/update.pp index 725bb3b..d9b338d 100644 --- a/manifests/update.pp +++ b/manifests/update.pp @@ -1,10 +1,66 @@ class apt::update { include apt::params + #TODO: to catch if $::apt_update_last_success has the value of -1 here. If we + #opt to do this, a info/warn would likely be all you'd need likely to happen + #on the first run, but if it's not run in awhile something is likely borked + #with apt and we'd want to know about it. + if $::apt::always_apt_update == false { + #if always_apt_update is true there's no point in parsing this logic. + + case $apt::apt_update_frequency { + 'always': { + $_kick_apt = true + } + 'daily': { + #compare current date with the apt_update_last_success fact to determine + #if we should kick apt_update. + $daily_threshold = (strftime('%s') - 86400) + if $::apt_update_last_success { + if $::apt_update_last_success < $daily_threshold { + $_kick_apt = true + } else { + $_kick_apt = false + } + } else { + #if apt-get update has not successfully run, we should kick apt_update + $_kick_apt = true + } + } + 'weekly':{ + #compare current date with the apt_update_last_success fact to determine + #if we should kick apt_update. + $weekly_threshold = (strftime('%s') - 604800) + if $::apt_update_last_success { + if ( $::apt_update_last_success < $weekly_threshold ) { + $_kick_apt = true + } else { + $_kick_apt = false + } + } else { + #if apt-get update has not successfully run, we should kick apt_update + $_kick_apt = true + } + } + default: { + #catches 'recluctantly', and any other value (which should not occur). + #do nothing. + $_kick_apt = false + } + } + } else { + $_kick_apt = false + } + + if $_kick_apt { + $_refresh = false + } else { + $_refresh = true + } exec { 'apt_update': command => "${apt::params::provider} update", logoutput => 'on_failure', - refreshonly => true, + refreshonly => $_refresh, timeout => $apt::update_timeout, tries => $apt::update_tries, try_sleep => 1 diff --git a/metadata.json b/metadata.json index 7365c67..1403e14 100644 --- a/metadata.json +++ b/metadata.json @@ -1,31 +1,43 @@ { - "name": "puppetlabs-apt", - "version": "1.5.0", - "source": "https://github.com/puppetlabs/puppetlabs-apt", - "author": "Puppet Labs", - "license": "Apache-2.0", - "project_page": "https://github.com/puppetlabs/puppetlabs-apt", - "summary": "Puppet Labs Apt Module", - "operatingsystem_support": [ - { - "operatingsystem": "Debian", - "operatingsystemrelease": [ - "6", - "7" - ] - }, - { - "operatingsystem": "Ubuntu", - "operatingsystemrelease": [ - "10.04", - "12.04", - "14.04" - ] - } - ], - "requirements": [ - { "name": "pe", "version_requirement": ">= 3.2.0 < 3.4.0" }, - { "name": "puppet", "version_requirement": "3.x" } - ], - "dependencies": [] + "name": "puppetlabs-apt", + "version": "1.6.0", + "author": "Puppet Labs", + "summary": "Puppet Labs Apt Module", + "license": "Apache-2.0", + "source": "https://github.com/puppetlabs/puppetlabs-apt", + "project_page": "https://github.com/puppetlabs/puppetlabs-apt", + "issues_url": "https://github.com/puppetlabs/puppetlabs-apt/issues", + "operatingsystem_support": [ + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "10.04", + "12.04", + "14.04" + ] + } + ], + "requirements": [ + { + "name": "pe", + "version_requirement": "3.x" + }, + { + "name": "puppet", + "version_requirement": "3.x" + } + ], + "dependencies": [ + { + "name": "puppetlabs/stdlib", + "version_requirement": ">= 2.2.1" + } + ] } diff --git a/spec/acceptance/apt_builddep_spec.rb b/spec/acceptance/apt_builddep_spec.rb deleted file mode 100644 index 1e35e4a..0000000 --- a/spec/acceptance/apt_builddep_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'apt::builddep', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do - - context 'reset' do - it 'removes packages' do - shell('apt-get -y remove znc') - shell('apt-get -y remove g++') - end - end - - context 'apt::builddep' do - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::builddep { 'znc': } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe 'should install g++ as a dependency' do - describe package('g++') do - it { should be_installed } - end - end - end - - context 'reset' do - it 'removes packages' do - shell('apt-get -y remove znc') - shell('apt-get -y remove g++') - end - end - -end diff --git a/spec/acceptance/apt_key_provider_spec.rb b/spec/acceptance/apt_key_provider_spec.rb index d9c2c0d..3f2536c 100644 --- a/spec/acceptance/apt_key_provider_spec.rb +++ b/spec/acceptance/apt_key_provider_spec.rb @@ -1,14 +1,19 @@ require 'spec_helper_acceptance' -PUPPETLABS_GPG_KEY_ID = '4BD6EC30' -PUPPETLABS_APT_URL = 'apt.puppetlabs.com' -PUPPETLABS_GPG_KEY_FILE = 'pubkey.gpg' -CENTOS_GPG_KEY_ID = 'C105B9DE' -CENTOS_REPO_URL = 'ftp.cvut.cz/centos' -CENTOS_GPG_KEY_FILE = 'RPM-GPG-KEY-CentOS-6' - -describe 'apt_key', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do +PUPPETLABS_GPG_KEY_ID = '4BD6EC30' +PUPPETLABS_GPG_LONG_KEY_ID = '1054B7A24BD6EC30' +PUPPETLABS_APT_URL = 'apt.puppetlabs.com' +PUPPETLABS_GPG_KEY_FILE = 'pubkey.gpg' +CENTOS_GPG_KEY_ID = 'C105B9DE' +CENTOS_REPO_URL = 'ftp.cvut.cz/centos' +CENTOS_GPG_KEY_FILE = 'RPM-GPG-KEY-CentOS-6' + +describe 'apt_key' do before(:each) do + # Delete twice to make sure everything is cleaned + # up after the short key collision + shell("apt-key del #{PUPPETLABS_GPG_KEY_ID}", + :acceptable_exit_codes => [0,1,2]) shell("apt-key del #{PUPPETLABS_GPG_KEY_ID}", :acceptable_exit_codes => [0,1,2]) end @@ -36,7 +41,7 @@ describe 'apt_key', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) EOS apply_manifest(pp, :catch_failures => true) - expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero + apply_manifest(pp, :catch_changes => true) shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}") end end @@ -59,6 +64,32 @@ describe 'apt_key', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) describe 'ensure =>' do context 'absent' do + it 'is removed' do + pp = <<-EOS + apt_key { 'centos': + id => '#{CENTOS_GPG_KEY_ID}', + ensure => 'absent', + } + EOS + + # Install the key first + shell("apt-key adv --keyserver keyserver.ubuntu.com \ + --recv-keys #{CENTOS_GPG_KEY_ID}") + shell("apt-key list | grep #{CENTOS_GPG_KEY_ID}") + + # Time to remove it using Puppet + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_failures => true) + + shell("apt-key list | grep #{CENTOS_GPG_KEY_ID}", + :acceptable_exit_codes => [1]) + + shell("apt-key adv --keyserver keyserver.ubuntu.com \ + --recv-keys #{CENTOS_GPG_KEY_ID}") + end + end + + context 'absent, added with long key', :unless => (fact('operatingsystem') == 'Debian' and fact('operatingsystemmajrelease') == '6') do it 'is removed' do pp = <<-EOS apt_key { 'puppetlabs': @@ -69,12 +100,12 @@ describe 'apt_key', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) # Install the key first shell("apt-key adv --keyserver keyserver.ubuntu.com \ - --recv-keys #{PUPPETLABS_GPG_KEY_ID}") + --recv-keys #{PUPPETLABS_GPG_LONG_KEY_ID}") shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}") # Time to remove it using Puppet apply_manifest(pp, :catch_failures => true) - expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero + apply_manifest(pp, :catch_failures => true) shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}", :acceptable_exit_codes => [1]) @@ -153,7 +184,7 @@ ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU= EOS apply_manifest(pp, :catch_failures => true) - expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero + apply_manifest(pp, :catch_failures => true) shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}") end end @@ -187,7 +218,7 @@ ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU= EOS apply_manifest(pp, :catch_failures => true) - expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero + apply_manifest(pp, :catch_failures => true) shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}") end end @@ -203,7 +234,7 @@ ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU= EOS apply_manifest(pp, :catch_failures => true) - expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero + apply_manifest(pp, :catch_failures => true) shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}") end end @@ -253,7 +284,7 @@ ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU= EOS apply_manifest(pp, :catch_failures => true) - expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero + apply_manifest(pp, :catch_failures => true) shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}") end @@ -302,7 +333,7 @@ ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU= EOS apply_manifest(pp, :catch_failures => true) - expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero + apply_manifest(pp, :catch_failures => true) shell("apt-key list | grep #{CENTOS_GPG_KEY_ID}") end @@ -346,7 +377,7 @@ ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU= EOS apply_manifest(pp, :catch_failures => true) - expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero + apply_manifest(pp, :catch_failures => true) shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}") end @@ -399,7 +430,7 @@ ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU= EOS apply_manifest(pp, :catch_failures => true) - expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero + apply_manifest(pp, :catch_failures => true) shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}") end end @@ -456,7 +487,7 @@ ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU= EOS apply_manifest(pp, :catch_failures => true) - expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero + apply_manifest(pp, :catch_failures => true) shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}") end @@ -469,6 +500,7 @@ ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU= } EOS + shell("apt-key del #{PUPPETLABS_GPG_KEY_ID}", :acceptable_exit_codes => [0,1,2]) apply_manifest(pp, :expect_failures => true) do |r| expect(r.stderr).to match(/--keyserver-options this is totally/) end diff --git a/spec/acceptance/apt_key_spec.rb b/spec/acceptance/apt_key_spec.rb deleted file mode 100644 index 9f2ba39..0000000 --- a/spec/acceptance/apt_key_spec.rb +++ /dev/null @@ -1,200 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'apt::key', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do - context 'apt::key' do - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::key { 'puppetlabs': - key => '4BD6EC30', - key_server => 'pgp.mit.edu', - } - - apt::key { 'jenkins': - key => 'D50582E6', - key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key', - } - EOS - - shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2]) - shell('apt-key del D50582E6', :acceptable_exit_codes => [0,1,2]) - apply_manifest(pp, :catch_failures => true) - end - - describe 'keys should exist' do - it 'finds puppetlabs key' do - shell('apt-key list | grep 4BD6EC30') - end - it 'finds jenkins key' do - shell('apt-key list | grep D50582E6') - end - end - end - context 'ensure' do - context 'absent' do - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::key { 'puppetlabs': - ensure => absent, - key => '4BD6EC30', - key_server => 'pgp.mit.edu', - } - - apt::key { 'jenkins': - ensure => absent, - key => 'D50582E6', - key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe 'keys shouldnt exist' do - it 'fails' do - shell('apt-key list | grep 4BD6EC30', :acceptable_exit_codes => [1]) - end - it 'fails' do - shell('apt-key list | grep D50582E6', :acceptable_exit_codes => [1]) - end - end - end - end - - context 'reset' do - it 'clean up keys' do - shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2]) - shell('apt-key del D50582E6', :acceptable_exit_codes => [0,1,2]) - end - end - - context 'key options' do - context 'key_content' do - - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::key { 'puppetlabs': - key => '4BD6EC30', - key_content => '-----BEGIN PGP PUBLIC KEY BLOCK----- - Version: GnuPG v1.4.12 (GNU/Linux) - Comment: GPGTools - http://gpgtools.org - - mQINBEw3u0ABEAC1+aJQpU59fwZ4mxFjqNCgfZgDhONDSYQFMRnYC1dzBpJHzI6b - fUBQeaZ8rh6N4kZ+wq1eL86YDXkCt4sCvNTP0eF2XaOLbmxtV9bdpTIBep9bQiKg - 5iZaz+brUZlFk/MyJ0Yz//VQ68N1uvXccmD6uxQsVO+gx7rnarg/BGuCNaVtGwy+ - S98g8Begwxs9JmGa8pMCcSxtC7fAfAEZ02cYyrw5KfBvFI3cHDdBqrEJQKwKeLKY - GHK3+H1TM4ZMxPsLuR/XKCbvTyl+OCPxU2OxPjufAxLlr8BWUzgJv6ztPe9imqpH - Ppp3KuLFNorjPqWY5jSgKl94W/CO2x591e++a1PhwUn7iVUwVVe+mOEWnK5+Fd0v - VMQebYCXS+3dNf6gxSvhz8etpw20T9Ytg4EdhLvCJRV/pYlqhcq+E9le1jFOHOc0 - Nc5FQweUtHGaNVyn8S1hvnvWJBMxpXq+Bezfk3X8PhPT/l9O2lLFOOO08jo0OYiI - wrjhMQQOOSZOb3vBRvBZNnnxPrcdjUUm/9cVB8VcgI5KFhG7hmMCwH70tpUWcZCN - NlI1wj/PJ7Tlxjy44f1o4CQ5FxuozkiITJvh9CTg+k3wEmiaGz65w9jRl9ny2gEl - f4CR5+ba+w2dpuDeMwiHJIs5JsGyJjmA5/0xytB7QvgMs2q25vWhygsmUQARAQAB - tEdQdXBwZXQgTGFicyBSZWxlYXNlIEtleSAoUHVwcGV0IExhYnMgUmVsZWFzZSBL - ZXkpIDxpbmZvQHB1cHBldGxhYnMuY29tPokCPgQTAQIAKAUCTDe7QAIbAwUJA8Jn - AAYLCQgHAwIGFQgCCQoLBBYCAwECHgECF4AACgkQEFS3okvW7DAZaw//aLmE/eob - pXpIUVyCUWQxEvPtM/h/SAJsG3KoHN9u216ews+UHsL/7F91ceVXQQdD2e8CtYWF - eLNM0RSM9i/KM60g4CvIQlmNqdqhi1HsgGqInZ72/XLAXun0gabfC36rLww2kel+ - aMpRf58SrSuskY321NnMEJl4OsHV2hfNtAIgw2e/zm9RhoMpGKxoHZCvFhnP7u2M - 2wMq7iNDDWb6dVsLpzdlVf242zCbubPCxxQXOpA56rzkUPuJ85mdVw4i19oPIFIZ - VL5owit1SxCOxBg4b8oaMS36hEl3qtZG834rtLfcqAmqjhx6aJuJLOAYN84QjDEU - 3NI5IfNRMvluIeTcD4Dt5FCYahN045tW1Rc6s5GAR8RW45GYwQDzG+kkkeeGxwEh - qCW7nOHuwZIoVJufNhd28UFn83KGJHCQt4NBBr3K5TcY6bDQEIrpSplWSDBbd3p1 - IaoZY1WSDdP9OTVOSbsz0JiglWmUWGWCdd/CMSW/D7/3VUOJOYRDwptvtSYcjJc8 - 1UV+1zB+rt5La/OWe4UOORD+jU1ATijQEaFYxBbqBBkFboAEXq9btRQyegqk+eVp - HhzacP5NYFTMThvHuTapNytcCso5au/cMywqCgY1DfcMJyjocu4bCtrAd6w4kGKN - MUdwNDYQulHZDI+UjJInhramyngdzZLjdeGJARwEEAECAAYFAkw3wEYACgkQIVr+ - UOQUcDKvEwgAoBuOPnPioBwYp8oHVPTo/69cJn1225kfraUYGebCcrRwuoKd8Iyh - R165nXYJmD8yrAFBk8ScUVKsQ/pSnqNrBCrlzQD6NQvuIWVFegIdjdasrWX6Szj+ - N1OllbzIJbkE5eo0WjCMEKJVI/GTY2AnTWUAm36PLQC5HnSATykqwxeZDsJ/s8Rc - kd7+QN5sBVytG3qb45Q7jLJpLcJO6KYH4rz9ZgN7LzyyGbu9DypPrulADG9OrL7e - lUnsGDG4E1M8Pkgk9Xv9MRKao1KjYLD5zxOoVtdeoKEQdnM+lWMJin1XvoqJY7FT - DJk6o+cVqqHkdKL+sgsscFVQljgCEd0EgIkCHAQQAQgABgUCTPlA6QAKCRBcE9bb - kwUuAxdYD/40FxAeNCYByxkr/XRT0gFT+NCjPuqPWCM5tf2NIhSapXtb2+32WbAf - DzVfqWjC0G0RnQBve+vcjpY4/rJu4VKIDGIT8CtnKOIyEcXTNFOehi65xO4ypaei - BPSb3ip3P0of1iZZDQrNHMW5VcyL1c+PWT/6exXSGsePtO/89tc6mupqZtC05f5Z - XG4jswMF0U6Q5s3S0tG7Y+oQhKNFJS4sH4rHe1o5CxKwNRSzqccA0hptKy3MHUZ2 - +zeHzuRdRWGjb2rUiVxnIvPPBGxF2JHhB4ERhGgbTxRZ6wZbdW06BOE8r7pGrUpU - fCw/WRT3gGXJHpGPOzFAvr3Xl7VcDUKTVmIajnpd3SoyD1t2XsvJlSQBOWbViucH - dvE4SIKQ77vBLRlZIoXXVb6Wu7Vq+eQs1ybjwGOhnnKjz8llXcMnLzzN86STpjN4 - qGTXQy/E9+dyUP1sXn3RRwb+ZkdI77m1YY95QRNgG/hqh77IuWWg1MtTSgQnP+F2 - 7mfo0/522hObhdAe73VO3ttEPiriWy7tw3bS9daP2TAVbYyFqkvptkBb1OXRUSzq - UuWjBmZ35UlXjKQsGeUHlOiEh84aondF90A7gx0X/ktNIPRrfCGkHJcDu+HVnR7x - Kk+F0qb9+/pGLiT3rqeQTr8fYsb4xLHT7uEg1gVFB1g0kd+RQHzV74kCPgQTAQIA - KAIbAwYLCQgHAwIGFQgCCQoLBBYCAwECHgECF4AFAk/x5PoFCQtIMjoACgkQEFS3 - okvW7DAIKQ/9HvZyf+LHVSkCk92Kb6gckniin3+5ooz67hSr8miGBfK4eocqQ0H7 - bdtWjAILzR/IBY0xj6OHKhYP2k8TLc7QhQjt0dRpNkX+Iton2AZryV7vUADreYz4 - 4B0bPmhiE+LL46ET5IThLKu/KfihzkEEBa9/t178+dO9zCM2xsXaiDhMOxVE32gX - vSZKP3hmvnK/FdylUY3nWtPedr+lHpBLoHGaPH7cjI+MEEugU3oAJ0jpq3V8n4w0 - jIq2V77wfmbD9byIV7dXcxApzciK+ekwpQNQMSaceuxLlTZKcdSqo0/qmS2A863Y - ZQ0ZBe+Xyf5OI33+y+Mry+vl6Lre2VfPm3udgR10E4tWXJ9Q2CmG+zNPWt73U1FD - 7xBI7PPvOlyzCX4QJhy2Fn/fvzaNjHp4/FSiCw0HvX01epcersyun3xxPkRIjwwR - M9m5MJ0o4hhPfa97zibXSh8XXBnosBQxeg6nEnb26eorVQbqGx0ruu/W2m5/JpUf - REsFmNOBUbi8xlKNS5CZypH3Zh88EZiTFolOMEh+hT6s0l6znBAGGZ4m/Unacm5y - DHmg7unCk4JyVopQ2KHMoqG886elu+rm0ASkhyqBAk9sWKptMl3NHiYTRE/m9VAk - ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU= - =a34C - -----END PGP PUBLIC KEY BLOCK----- - ', - } - EOS - - shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2]) - apply_manifest(pp, :catch_failures => true) - end - end - describe 'keys should exist' do - it 'finds puppetlabs key' do - shell('apt-key list | grep 4BD6EC30') - end - end - - context 'key_source' do - - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::key { 'puppetlabs': - key => '4BD6EC30', - key_source => 'http://apt.puppetlabs.com/pubkey.gpg', - } - EOS - - shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2]) - apply_manifest(pp, :catch_failures => true) - end - - describe 'keys should exist' do - it 'finds puppetlabs key' do - shell('apt-key list | grep 4BD6EC30') - end - end - end - - context 'key_options' do - - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::key { 'puppetlabs': - key => '4BD6EC30', - key_source => 'http://apt.puppetlabs.com/pubkey.gpg', - key_options => 'debug' - } - EOS - - shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2]) - apply_manifest(pp, :catch_failures => true) - end - - describe 'keys should exist' do - it 'finds puppetlabs key' do - shell('apt-key list | grep 4BD6EC30') - end - end - end - end - -end diff --git a/spec/acceptance/apt_ppa_spec.rb b/spec/acceptance/apt_ppa_spec.rb deleted file mode 100644 index b665c5c..0000000 --- a/spec/acceptance/apt_ppa_spec.rb +++ /dev/null @@ -1,138 +0,0 @@ -require 'spec_helper_acceptance' - -if fact('operatingsystem') == 'Ubuntu' - describe 'apt::ppa', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do - - context 'reset' do - it 'removes ppa' do - shell('rm /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0,1,2]) - shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*', :acceptable_exit_codes => [0,1,2]) - end - end - - context 'adding a ppa that doesnt exist' do - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::ppa { 'ppa:canonical-kernel-team/ppa': } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe 'contains the source file' do - it 'contains a kernel ppa source' do - shell('ls /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0]) - end - end - end - - context 'reading a removed ppa.' do - it 'setup' do - # This leaves a blank file - shell('echo > /etc/apt/sources.list.d/raravena80-collectd5-$(lsb_release -c -s).list') - end - - it 'should read it successfully' do - pp = <<-EOS - include '::apt' - apt::ppa { 'ppa:raravena80/collectd5': } - EOS - - apply_manifest(pp, :catch_failures => true) - end - end - - context 'reset' do - it 'removes added ppas' do - shell('rm /etc/apt/sources.list.d/canonical-kernel-team-ppa-*') - shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*') - end - end - - context 'ensure' do - context 'present' do - it 'works without failure' do - pp = <<-EOS - include '::apt' - apt::ppa { 'ppa:canonical-kernel-team/ppa': ensure => present } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe 'contains the source file' do - it 'contains a kernel ppa source' do - shell('ls /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0]) - end - end - end - end - - context 'ensure' do - context 'absent' do - it 'works without failure' do - pp = <<-EOS - include '::apt' - apt::ppa { 'ppa:canonical-kernel-team/ppa': ensure => absent } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe 'doesnt contain the source file' do - it 'fails' do - shell('ls /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [2]) - end - end - end - end - - context 'release' do - context 'precise' do - it 'works without failure' do - pp = <<-EOS - include '::apt' - apt::ppa { 'ppa:canonical-kernel-team/ppa': - ensure => present, - release => precise, - } - EOS - - shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2]) - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/sources.list.d/canonical-kernel-team-ppa-precise.list') do - it { should be_file } - end - end - end - - context 'options' do - context '-y', :unless => default[:platform].match(/10\.04/) do - it 'works without failure' do - pp = <<-EOS - include '::apt' - apt::ppa { 'ppa:canonical-kernel-team/ppa': - ensure => present, - release => precise, - options => '-y', - } - EOS - - shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2]) - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/sources.list.d/canonical-kernel-team-ppa-precise.list') do - it { should be_file } - end - end - end - - context 'reset' do - it { shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2]) } - end - end -end diff --git a/spec/acceptance/apt_source_spec.rb b/spec/acceptance/apt_source_spec.rb deleted file mode 100644 index c2d076c..0000000 --- a/spec/acceptance/apt_source_spec.rb +++ /dev/null @@ -1,326 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'apt::source', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do - - context 'apt::source' do - context 'ensure => present' do - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::source { 'puppetlabs': - ensure => present, - location => 'http://apt.puppetlabs.com', - repos => 'main', - key => '4BD6EC30', - key_server => 'pgp.mit.edu', - } - EOS - - shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2]) - shell('rm /etc/apt/sources.list.d/puppetlabs.list', :acceptable_exit_codes => [0,1,2]) - apply_manifest(pp, :catch_failures => true) - end - - describe 'key should exist' do - it 'finds puppetlabs key' do - shell('apt-key list | grep 4BD6EC30', :acceptable_exit_codes => [0]) - end - end - - describe file('/etc/apt/sources.list.d/puppetlabs.list') do - it { should be_file } - end - end - - context 'ensure => absent' do - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::source { 'puppetlabs': - ensure => absent, - location => 'http://apt.puppetlabs.com', - repos => 'main', - key => '4BD6EC30', - key_server => 'pgp.mit.edu', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - # The key should remain -we don't delete those when deleting a source. - describe 'key should exist' do - it 'finds puppetlabs key' do - shell('apt-key list | grep 4BD6EC30', :acceptable_exit_codes => [0]) - end - end - describe file('/etc/apt/sources.list.d/puppetlabs.list') do - it { should_not be_file } - end - end - - end - - context 'release' do - context 'test' do - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::source { 'puppetlabs': - ensure => present, - location => 'http://apt.puppetlabs.com', - repos => 'main', - key => '4BD6EC30', - key_server => 'pgp.mit.edu', - release => 'precise', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/sources.list.d/puppetlabs.list') do - it { should be_file } - it { should contain 'deb http://apt.puppetlabs.com precise main' } - end - end - end - - context 'include_src' do - context 'true' do - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::source { 'puppetlabs': - ensure => present, - location => 'http://apt.puppetlabs.com', - repos => 'main', - key => '4BD6EC30', - key_server => 'pgp.mit.edu', - include_src => true, - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/sources.list.d/puppetlabs.list') do - it { should be_file } - it { should contain 'deb-src http://apt.puppetlabs.com' } - end - end - - context 'false' do - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::source { 'puppetlabs': - ensure => present, - location => 'http://apt.puppetlabs.com', - repos => 'main', - key => '4BD6EC30', - key_server => 'pgp.mit.edu', - include_src => false, - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/sources.list.d/puppetlabs.list') do - it { should be_file } - it { should_not contain 'deb-src http://apt.puppetlabs.com' } - end - end - end - - context 'required_packages' do - context 'vim' do - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::source { 'puppetlabs': - ensure => present, - location => 'http://apt.puppetlabs.com', - repos => 'main', - key => '4BD6EC30', - key_server => 'pgp.mit.edu', - required_packages => 'vim', - } - EOS - - shell('apt-get -y remove vim') - apply_manifest(pp, :catch_failures => true) - end - - describe package('vim') do - it { should be_installed } - end - end - end - - context 'key content' do - context 'giant key' do - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::source { 'puppetlabs': - ensure => present, - location => 'http://apt.puppetlabs.com', - repos => 'main', - key => '4BD6EC30', - key_content => '-----BEGIN PGP PUBLIC KEY BLOCK----- - Version: GnuPG v1.4.12 (GNU/Linux) - Comment: GPGTools - http://gpgtools.org - - mQINBEw3u0ABEAC1+aJQpU59fwZ4mxFjqNCgfZgDhONDSYQFMRnYC1dzBpJHzI6b - fUBQeaZ8rh6N4kZ+wq1eL86YDXkCt4sCvNTP0eF2XaOLbmxtV9bdpTIBep9bQiKg - 5iZaz+brUZlFk/MyJ0Yz//VQ68N1uvXccmD6uxQsVO+gx7rnarg/BGuCNaVtGwy+ - S98g8Begwxs9JmGa8pMCcSxtC7fAfAEZ02cYyrw5KfBvFI3cHDdBqrEJQKwKeLKY - GHK3+H1TM4ZMxPsLuR/XKCbvTyl+OCPxU2OxPjufAxLlr8BWUzgJv6ztPe9imqpH - Ppp3KuLFNorjPqWY5jSgKl94W/CO2x591e++a1PhwUn7iVUwVVe+mOEWnK5+Fd0v - VMQebYCXS+3dNf6gxSvhz8etpw20T9Ytg4EdhLvCJRV/pYlqhcq+E9le1jFOHOc0 - Nc5FQweUtHGaNVyn8S1hvnvWJBMxpXq+Bezfk3X8PhPT/l9O2lLFOOO08jo0OYiI - wrjhMQQOOSZOb3vBRvBZNnnxPrcdjUUm/9cVB8VcgI5KFhG7hmMCwH70tpUWcZCN - NlI1wj/PJ7Tlxjy44f1o4CQ5FxuozkiITJvh9CTg+k3wEmiaGz65w9jRl9ny2gEl - f4CR5+ba+w2dpuDeMwiHJIs5JsGyJjmA5/0xytB7QvgMs2q25vWhygsmUQARAQAB - tEdQdXBwZXQgTGFicyBSZWxlYXNlIEtleSAoUHVwcGV0IExhYnMgUmVsZWFzZSBL - ZXkpIDxpbmZvQHB1cHBldGxhYnMuY29tPokCPgQTAQIAKAUCTDe7QAIbAwUJA8Jn - AAYLCQgHAwIGFQgCCQoLBBYCAwECHgECF4AACgkQEFS3okvW7DAZaw//aLmE/eob - pXpIUVyCUWQxEvPtM/h/SAJsG3KoHN9u216ews+UHsL/7F91ceVXQQdD2e8CtYWF - eLNM0RSM9i/KM60g4CvIQlmNqdqhi1HsgGqInZ72/XLAXun0gabfC36rLww2kel+ - aMpRf58SrSuskY321NnMEJl4OsHV2hfNtAIgw2e/zm9RhoMpGKxoHZCvFhnP7u2M - 2wMq7iNDDWb6dVsLpzdlVf242zCbubPCxxQXOpA56rzkUPuJ85mdVw4i19oPIFIZ - VL5owit1SxCOxBg4b8oaMS36hEl3qtZG834rtLfcqAmqjhx6aJuJLOAYN84QjDEU - 3NI5IfNRMvluIeTcD4Dt5FCYahN045tW1Rc6s5GAR8RW45GYwQDzG+kkkeeGxwEh - qCW7nOHuwZIoVJufNhd28UFn83KGJHCQt4NBBr3K5TcY6bDQEIrpSplWSDBbd3p1 - IaoZY1WSDdP9OTVOSbsz0JiglWmUWGWCdd/CMSW/D7/3VUOJOYRDwptvtSYcjJc8 - 1UV+1zB+rt5La/OWe4UOORD+jU1ATijQEaFYxBbqBBkFboAEXq9btRQyegqk+eVp - HhzacP5NYFTMThvHuTapNytcCso5au/cMywqCgY1DfcMJyjocu4bCtrAd6w4kGKN - MUdwNDYQulHZDI+UjJInhramyngdzZLjdeGJARwEEAECAAYFAkw3wEYACgkQIVr+ - UOQUcDKvEwgAoBuOPnPioBwYp8oHVPTo/69cJn1225kfraUYGebCcrRwuoKd8Iyh - R165nXYJmD8yrAFBk8ScUVKsQ/pSnqNrBCrlzQD6NQvuIWVFegIdjdasrWX6Szj+ - N1OllbzIJbkE5eo0WjCMEKJVI/GTY2AnTWUAm36PLQC5HnSATykqwxeZDsJ/s8Rc - kd7+QN5sBVytG3qb45Q7jLJpLcJO6KYH4rz9ZgN7LzyyGbu9DypPrulADG9OrL7e - lUnsGDG4E1M8Pkgk9Xv9MRKao1KjYLD5zxOoVtdeoKEQdnM+lWMJin1XvoqJY7FT - DJk6o+cVqqHkdKL+sgsscFVQljgCEd0EgIkCHAQQAQgABgUCTPlA6QAKCRBcE9bb - kwUuAxdYD/40FxAeNCYByxkr/XRT0gFT+NCjPuqPWCM5tf2NIhSapXtb2+32WbAf - DzVfqWjC0G0RnQBve+vcjpY4/rJu4VKIDGIT8CtnKOIyEcXTNFOehi65xO4ypaei - BPSb3ip3P0of1iZZDQrNHMW5VcyL1c+PWT/6exXSGsePtO/89tc6mupqZtC05f5Z - XG4jswMF0U6Q5s3S0tG7Y+oQhKNFJS4sH4rHe1o5CxKwNRSzqccA0hptKy3MHUZ2 - +zeHzuRdRWGjb2rUiVxnIvPPBGxF2JHhB4ERhGgbTxRZ6wZbdW06BOE8r7pGrUpU - fCw/WRT3gGXJHpGPOzFAvr3Xl7VcDUKTVmIajnpd3SoyD1t2XsvJlSQBOWbViucH - dvE4SIKQ77vBLRlZIoXXVb6Wu7Vq+eQs1ybjwGOhnnKjz8llXcMnLzzN86STpjN4 - qGTXQy/E9+dyUP1sXn3RRwb+ZkdI77m1YY95QRNgG/hqh77IuWWg1MtTSgQnP+F2 - 7mfo0/522hObhdAe73VO3ttEPiriWy7tw3bS9daP2TAVbYyFqkvptkBb1OXRUSzq - UuWjBmZ35UlXjKQsGeUHlOiEh84aondF90A7gx0X/ktNIPRrfCGkHJcDu+HVnR7x - Kk+F0qb9+/pGLiT3rqeQTr8fYsb4xLHT7uEg1gVFB1g0kd+RQHzV74kCPgQTAQIA - KAIbAwYLCQgHAwIGFQgCCQoLBBYCAwECHgECF4AFAk/x5PoFCQtIMjoACgkQEFS3 - okvW7DAIKQ/9HvZyf+LHVSkCk92Kb6gckniin3+5ooz67hSr8miGBfK4eocqQ0H7 - bdtWjAILzR/IBY0xj6OHKhYP2k8TLc7QhQjt0dRpNkX+Iton2AZryV7vUADreYz4 - 4B0bPmhiE+LL46ET5IThLKu/KfihzkEEBa9/t178+dO9zCM2xsXaiDhMOxVE32gX - vSZKP3hmvnK/FdylUY3nWtPedr+lHpBLoHGaPH7cjI+MEEugU3oAJ0jpq3V8n4w0 - jIq2V77wfmbD9byIV7dXcxApzciK+ekwpQNQMSaceuxLlTZKcdSqo0/qmS2A863Y - ZQ0ZBe+Xyf5OI33+y+Mry+vl6Lre2VfPm3udgR10E4tWXJ9Q2CmG+zNPWt73U1FD - 7xBI7PPvOlyzCX4QJhy2Fn/fvzaNjHp4/FSiCw0HvX01epcersyun3xxPkRIjwwR - M9m5MJ0o4hhPfa97zibXSh8XXBnosBQxeg6nEnb26eorVQbqGx0ruu/W2m5/JpUf - REsFmNOBUbi8xlKNS5CZypH3Zh88EZiTFolOMEh+hT6s0l6znBAGGZ4m/Unacm5y - DHmg7unCk4JyVopQ2KHMoqG886elu+rm0ASkhyqBAk9sWKptMl3NHiYTRE/m9VAk - ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU= - =a34C - -----END PGP PUBLIC KEY BLOCK-----', - } - EOS - - shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2]) - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/sources.list.d/puppetlabs.list') do - it { should be_file } - end - describe 'keys should exist' do - it 'finds puppetlabs key' do - shell('apt-key list | grep 4BD6EC30') - end - end - end - end - - context 'key_source' do - context 'http://apt.puppetlabs.com/pubkey.gpg' do - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::source { 'puppetlabs': - ensure => present, - location => 'http://apt.puppetlabs.com', - release => 'precise', - repos => 'main', - key => '4BD6EC30', - key_source => 'http://apt.puppetlabs.com/pubkey.gpg', - } - EOS - - shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2]) - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/sources.list.d/puppetlabs.list') do - it { should be_file } - it { should contain 'deb http://apt.puppetlabs.com precise main' } - end - describe 'keys should exist' do - it 'finds puppetlabs key' do - shell('apt-key list | grep 4BD6EC30') - end - end - end - end - - context 'pin' do - context 'false' do - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::source { 'puppetlabs': - ensure => present, - location => 'http://apt.puppetlabs.com', - repos => 'main', - key => '4BD6EC30', - key_server => 'pgp.mit.edu', - pin => false, - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/puppetlabs.pref') do - it { should_not be_file } - end - end - context 'true' do - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::source { 'puppetlabs': - ensure => present, - location => 'http://apt.puppetlabs.com', - repos => 'main', - key => '4BD6EC30', - key_server => 'pgp.mit.edu', - pin => true, - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/puppetlabs.pref') do - it { should be_file } - end - end - end - -end diff --git a/spec/acceptance/apt_spec.rb b/spec/acceptance/apt_spec.rb index 60def0e..3011f9d 100644 --- a/spec/acceptance/apt_spec.rb +++ b/spec/acceptance/apt_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'apt class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do +describe 'apt class' do context 'reset' do it 'fixes the sources.list' do @@ -8,294 +8,37 @@ describe 'apt class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily') end end - context 'always_apt_update => true' do + context 'all the things' do it 'should work with no errors' do - pp = <<-EOS - class { 'apt': always_apt_update => true } - EOS - - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/apt_update/) - end - end - end - context 'always_apt_update => false' do - it 'should work with no errors' do - pp = <<-EOS - class { 'apt': always_apt_update => false } - EOS - - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to_not match(/apt_update/) - end - end - end - - # disable_keys drops in a 99unauth file to ignore keys in - # other files. - context 'disable_keys => true' do - it 'should work with no errors' do - pp = <<-EOS - class { 'apt': disable_keys => true } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/99unauth') do - it { should be_file } - it { should contain 'APT::Get::AllowUnauthenticated 1;' } - end - end - context 'disable_keys => false' do - it 'should work with no errors' do - pp = <<-EOS - class { 'apt': disable_keys => false } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/99unauth') do - it { should_not be_file } - end - end - - # proxy_host sets the proxy to use for transfers. - # proxy_port sets the proxy port to use. - context 'proxy settings' do - it 'should work with no errors' do - pp = <<-EOS - class { 'apt': - proxy_host => 'localhost', - proxy_port => '7042', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/01proxy') do - it { should be_file } - it { should contain 'Acquire::http::Proxy "http://localhost:7042\";' } - end - describe file('/etc/apt/apt.conf.d/proxy') do - it { should_not be_file } - end - end - - context 'purge_sources' do - it 'creates a fake apt file' do - shell('touch /etc/apt/sources.list.d/fake.list') - shell('echo "deb fake" >> /etc/apt/sources.list') - end - it 'purge_sources_list and purge_sources_list_d => true' do pp = <<-EOS class { 'apt': + always_apt_update => true, + disable_keys => true, purge_sources_list => true, purge_sources_list_d => true, + purge_preferences => true, + purge_preferences_d => true, + update_timeout => '400', + update_tries => '3', + sources => { + 'puppetlabs' => { + 'ensure' => present, + 'location' => 'http://apt.puppetlabs.com', + 'repos' => 'main', + 'key' => '4BD6EC30', + 'key_server' => 'pgp.mit.edu', + } + }, + fancy_progress => true, } EOS apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/sources.list') do - it { should_not contain 'deb fake' } - end - - describe file('/etc/apt/sources.list.d/fake.list') do - it { should_not be_file } - end - end - context 'proxy settings' do - it 'should work with no errors' do - pp = <<-EOS - class { 'apt': - proxy_host => 'localhost', - proxy_port => '7042', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/01proxy') do - it { should be_file } - it { should contain 'Acquire::http::Proxy "http://localhost:7042\";' } - end - describe file('/etc/apt/apt.conf.d/proxy') do - it { should_not be_file } - end - end - - context 'purge_sources' do - context 'false' do - it 'creates a fake apt file' do - shell('touch /etc/apt/sources.list.d/fake.list') - shell('echo "deb fake" >> /etc/apt/sources.list') - end - it 'purge_sources_list and purge_sources_list_d => false' do - pp = <<-EOS - class { 'apt': - purge_sources_list => false, - purge_sources_list_d => false, - } - EOS - - apply_manifest(pp, :catch_failures => false) - end - - describe file('/etc/apt/sources.list') do - it { should contain 'deb fake' } - end - - describe file('/etc/apt/sources.list.d/fake.list') do - it { should be_file } - end - end - - context 'true' do - it 'creates a fake apt file' do - shell('touch /etc/apt/sources.list.d/fake.list') - shell('echo "deb fake" >> /etc/apt/sources.list') - end - it 'purge_sources_list and purge_sources_list_d => true' do - pp = <<-EOS - class { 'apt': - purge_sources_list => true, - purge_sources_list_d => true, - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/sources.list') do - it { should_not contain 'deb fake' } - end - - describe file('/etc/apt/sources.list.d/fake.list') do - it { should_not be_file } - end - end - end - - context 'purge_preferences' do - context 'false' do - it 'creates a preferences file' do - shell("echo 'original' > /etc/apt/preferences") - end - - it 'should work with no errors' do - pp = <<-EOS - class { 'apt': purge_preferences => false } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences') do - it { should be_file } - it 'is not managed by Puppet' do - shell("grep 'original' /etc/apt/preferences", {:acceptable_exit_codes => 0}) - end - end - end - - context 'true' do - it 'creates a preferences file' do - shell('touch /etc/apt/preferences') - end - - it 'should work with no errors' do - pp = <<-EOS - class { 'apt': purge_preferences => true } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences') do - it { should_not be_file } - end - end - end - - context 'purge_preferences_d' do - context 'false' do - it 'creates a preferences file' do - shell('touch /etc/apt/preferences.d/test') - end - - it 'should work with no errors' do - pp = <<-EOS - class { 'apt': purge_preferences_d => false } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/test') do - it { should be_file } - end - end - context 'true' do - it 'creates a preferences file' do - shell('touch /etc/apt/preferences.d/test') - end - - it 'should work with no errors' do - pp = <<-EOS - class { 'apt': purge_preferences_d => true } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/test') do - it { should_not be_file } - end - end - end - - context 'update_timeout' do - context '5000' do - it 'should work with no errors' do - pp = <<-EOS - class { 'apt': update_timeout => '5000' } - EOS - - apply_manifest(pp, :catch_failures => true) - end - end - end - - context 'fancy_progress => true' do - it 'should work with no errors' do - pp = <<-EOS - class { 'apt': fancy_progress => true } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/99progressbar') do - it { should be_file } - it { should contain 'Dpkg::Progress-Fancy "1";' } - end - end - context 'fancy_progress => false' do - it 'should work with no errors' do - pp = <<-EOS - class { 'apt': fancy_progress => false } - EOS - apply_manifest(pp, :catch_failures => true) end - - describe file('/etc/apt/apt.conf.d/99progressbar') do - it { should_not be_file } + it 'should still work' do + shell('apt-get update') + shell('apt-get -y --force-yes upgrade') end end diff --git a/spec/acceptance/backports_spec.rb b/spec/acceptance/backports_spec.rb deleted file mode 100644 index 78f21fd..0000000 --- a/spec/acceptance/backports_spec.rb +++ /dev/null @@ -1,73 +0,0 @@ -require 'spec_helper_acceptance' - -codename = fact('lsbdistcodename') -case fact('operatingsystem') -when 'Ubuntu' - repos = 'main universe multiverse restricted' -when 'Debian' - repos = 'main contrib non-free' -end - -describe 'apt::backports class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do - context 'defaults' do - it 'should work with no errors' do - pp = <<-EOS - class { 'apt::backports': } - EOS - - apply_manifest(pp, :catch_failures => true) - end - end - - context 'release' do - it 'should work with no errors' do - pp = <<-EOS - class { 'apt::backports': release => '#{codename}' } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/sources.list.d/backports.list') do - it { should be_file } - it { should contain "#{codename}-backports #{repos}" } - end - end - - context 'location' do - it 'should work with no errors' do - pp = <<-EOS - class { 'apt::backports': release => 'precise', location => 'http://localhost/ubuntu' } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/sources.list.d/backports.list') do - it { should be_file } - it { should contain "deb http://localhost/ubuntu precise-backports #{repos}" } - end - end - - context 'pin_priority' do - it 'should work with no errors' do - pp = <<-EOS - class { 'apt::backports': pin_priority => 500, } - EOS - - apply_manifest(pp, :catch_failures => true) - end - describe file('/etc/apt/preferences.d/backports.pref') do - it { should be_file } - it { should contain "Pin-Priority: 500" } - end - end - - context 'reset' do - it 'deletes backport files' do - shell('rm -rf /etc/apt/sources.list.d/backports.list') - shell('rm -rf /etc/apt/preferences.d/backports.pref') - end - end - -end diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index e599449..f228e4c 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'apt class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do +describe 'apt class' do context 'default parameters' do # Using puppet_apply as a helper diff --git a/spec/acceptance/conf_spec.rb b/spec/acceptance/conf_spec.rb deleted file mode 100644 index 8a8ed63..0000000 --- a/spec/acceptance/conf_spec.rb +++ /dev/null @@ -1,66 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'apt::conf define', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do - context 'defaults' do - it 'should work with no errors' do - pp = <<-EOS - apt::conf { 'test': - content => 'test', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50test') do - it { should be_file } - it { should contain 'test' } - end - end - - context 'ensure' do - context 'absent' do - it 'should work with no errors' do - pp = <<-EOS - apt::conf { 'test': - ensure => absent, - content => 'test', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50test') do - it { should_not be_file } - end - end - end - - context 'priority' do - context '99' do - it 'should work with no errors' do - pp = <<-EOS - apt::conf { 'test': - ensure => present, - content => 'test', - priority => '99', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/99test') do - it { should be_file } - it { should contain 'test' } - end - end - end - - context 'cleanup' do - it 'deletes 99test' do - shell ('rm -rf /etc/apt/apt.conf.d/99test') - end - end -end diff --git a/spec/acceptance/force_spec.rb b/spec/acceptance/force_spec.rb deleted file mode 100644 index 5f4dec3..0000000 --- a/spec/acceptance/force_spec.rb +++ /dev/null @@ -1,76 +0,0 @@ -require 'spec_helper_acceptance' - -codename = fact('lsbdistcodename') - -describe 'apt::force define', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do - context 'defaults' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::force { 'vim': } - EOS - - shell('apt-get remove -y vim') - apply_manifest(pp, :catch_failures => true) - end - - describe package('vim') do - it { should be_installed } - end - end - - context 'release' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::force { 'vim': release => '#{codename}' } - EOS - - shell('apt-get remove -y vim') - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/apt-get -y -t #{codename} install vim/) - end - end - - describe package('vim') do - it { should be_installed } - end - end - - context 'version' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::force { 'vim': version => '1.1.1' } - EOS - - shell('apt-get remove -y vim') - apply_manifest(pp, :catch_failures => false) do |r| - expect(r.stdout).to match(/apt-get -y install vim=1.1.1/) - end - end - - describe package('vim') do - it { should_not be_installed } - end - end - - context 'timeout' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::force { 'ocaml': timeout => '1' } - EOS - - shell('apt-get clean') - apply_manifest(pp, :expect_failures => true) do |r| - expect(r.stderr).to match(/Error: Command exceeded timeout/) - end - end - - describe package('ocaml') do - it { should_not be_installed } - end - end - -end diff --git a/spec/acceptance/pin_spec.rb b/spec/acceptance/pin_spec.rb deleted file mode 100644 index 07fc607..0000000 --- a/spec/acceptance/pin_spec.rb +++ /dev/null @@ -1,286 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'apt::pin define', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do - context 'defaults' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::pin { 'vim-puppet': } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/vim-puppet.pref') do - it { should be_file } - it { should contain 'Pin: release a=vim-puppet' } - end - end - - context 'ensure' do - context 'present' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::pin { 'vim-puppet': ensure => present } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/vim-puppet.pref') do - it { should be_file } - it { should contain 'Pin: release a=vim-puppet' } - end - end - - context 'absent' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::pin { 'vim-puppet': ensure => absent } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/vim-puppet.pref') do - it { should_not be_file } - end - end - end - - context 'order' do - context '99' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::pin { 'vim-puppet': - ensure => present, - order => '99', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/99-vim-puppet.pref') do - it { should be_file } - it { should contain 'Pin: release a=vim-puppet' } - end - end - end - - context 'packages' do - context 'test' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::pin { 'vim-puppet': - ensure => present, - packages => 'test', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/vim-puppet.pref') do - it { should be_file } - it { should contain 'Package: test' } - it { should contain 'Pin: release a=vim-puppet' } - end - end - - context 'array' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::pin { 'array': - ensure => present, - packages => ['apache', 'ntop'], - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/array.pref') do - it { should be_file } - it { should contain 'Package: apache ntop' } - it { should contain 'Pin: release a=array' } - end - end - end - - context 'release' do - context 'testrelease' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::pin { 'vim-puppet': - ensure => present, - release => 'testrelease', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/vim-puppet.pref') do - it { should be_file } - it { should contain 'Pin: release a=testrelease' } - end - end - end - - context 'origin' do - context 'testrelease' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::pin { 'vim-puppet': - ensure => present, - origin => 'testrelease', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/vim-puppet.pref') do - it { should be_file } - it { should contain 'Pin: origin testrelease' } - end - end - end - - context 'version' do - context '1.0.0' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::pin { 'vim-puppet': - ensure => present, - packages => 'test', - version => '1.0.0', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/vim-puppet.pref') do - it { should be_file } - it { should contain 'Package: test' } - it { should contain 'Pin: version 1.0.0' } - end - end - end - - context 'codename' do - context 'testname' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::pin { 'vim-puppet': - ensure => present, - codename => 'testname', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/vim-puppet.pref') do - it { should be_file } - it { should contain 'Pin: release n=testname' } - end - end - end - - context 'release_version' do - context '1.1.1' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::pin { 'vim-puppet': - ensure => present, - release_version => '1.1.1', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/vim-puppet.pref') do - it { should be_file } - it { should contain 'Pin: release v=1.1.1' } - end - end - end - - context 'component' do - context 'testcomponent' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::pin { 'vim-puppet': - ensure => present, - component => 'testcomponent', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/vim-puppet.pref') do - it { should be_file } - it { should contain 'Pin: release c=testcomponent' } - end - end - end - - context 'originator' do - context 'testorigin' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::pin { 'vim-puppet': - ensure => present, - originator => 'testorigin', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/vim-puppet.pref') do - it { should be_file } - it { should contain 'Pin: release o=testorigin' } - end - end - end - - context 'label' do - context 'testlabel' do - it 'should work with no errors' do - pp = <<-EOS - include apt - apt::pin { 'vim-puppet': - ensure => present, - label => 'testlabel', - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/preferences.d/vim-puppet.pref') do - it { should be_file } - it { should contain 'Pin: release l=testlabel' } - end - end - end - -end diff --git a/spec/acceptance/release_spec.rb b/spec/acceptance/release_spec.rb deleted file mode 100644 index e7467bf..0000000 --- a/spec/acceptance/release_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'apt::release class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do - context 'release_id' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::release': release_id => 'precise', } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/01release') do - it { should be_file } - it { should contain 'APT::Default-Release "precise";' } - end - end - - context 'reset' do - it 'cleans up' do - shell('rm -rf /etc/apt/apt.conf.d/01release') - end - end - -end diff --git a/spec/acceptance/unattended_upgrade_spec.rb b/spec/acceptance/unattended_upgrade_spec.rb deleted file mode 100644 index 6a19f4e..0000000 --- a/spec/acceptance/unattended_upgrade_spec.rb +++ /dev/null @@ -1,562 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'apt::unattended_upgrades class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do - context 'defaults' do - it 'should work with no errors' do - pp = <<-EOS - include apt - include apt::unattended_upgrades - EOS - - # Attempted workaround for problems seen on debian with - # something holding the package database open. - #shell('killall -9 apt-get') - #shell('killall -9 dpkg') - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/10periodic') do - it { should be_file } - end - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - end - end - - context 'origins' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - origins => ['${distro_id}:${distro_codename}-test'], - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - it { should contain '${distro_id}:${distro_codename}-test' } - end - end - - context 'blacklist' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - blacklist => ['puppet'] - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - it { should contain 'puppet' } - end - end - - context 'update' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - update => '99' - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/10periodic') do - it { should be_file } - it { should contain 'APT::Periodic::Update-Package-Lists "99";' } - end - end - - context 'download' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - download => '99' - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/10periodic') do - it { should be_file } - it { should contain 'APT::Periodic::Download-Upgradeable-Packages "99";' } - end - end - - context 'upgrade' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - upgrade => '99' - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/10periodic') do - it { should be_file } - it { should contain 'APT::Periodic::Unattended-Upgrade "99";' } - end - end - - context 'autoclean' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - autoclean => '99' - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/10periodic') do - it { should be_file } - it { should contain 'APT::Periodic::AutocleanInterval "99";' } - end - end - - context 'auto_fix' do - context 'true' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - auto_fix => true - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - it { should contain 'Unattended-Upgrade::AutoFixInterruptedDpkg "true";' } - end - end - - context 'false' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - auto_fix => false - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - it { should contain 'Unattended-Upgrade::AutoFixInterruptedDpkg "false";' } - end - end - end - - context 'minimal_steps' do - context 'true' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - minimal_steps => true - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - it { should contain 'Unattended-Upgrade::MinimalSteps "true";' } - end - end - - context 'false' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - minimal_steps => false - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - it { should contain 'Unattended-Upgrade::MinimalSteps "false";' } - end - end - end - - context 'install_on_shutdown' do - context 'true' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - install_on_shutdown => true - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - it { should contain 'Unattended-Upgrade::InstallOnShutdown "true";' } - end - end - - context 'false' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - install_on_shutdown => false - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - it { should contain 'Unattended-Upgrade::InstallOnShutdown "false";' } - end - end - end - - context 'mail_to' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - mail_to => 'test@example.com' - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - it { should contain 'Unattended-Upgrade::Mail "test@example.com";' } - end - end - - context 'mail_only_on_error' do - context 'true' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - mail_to => 'test@example.com', - mail_only_on_error => true - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - it { should contain 'Unattended-Upgrade::MailOnlyOnError "true";' } - end - end - - context 'false' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - mail_to => 'test@example.com', - mail_only_on_error => false, - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - it { should contain 'Unattended-Upgrade::MailOnlyOnError "false";' } - end - end - - context 'mail_to missing' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - mail_only_on_error => true, - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - it { should_not contain 'Unattended-Upgrade::MailOnlyOnError "true";' } - end - end - end - - context 'remove_unused' do - context 'true' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - remove_unused => true - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - it { should contain 'Unattended-Upgrade::Remove-Unused-Dependencies "true";' } - end - end - - context 'false' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - remove_unused => false, - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - it { should contain 'Unattended-Upgrade::Remove-Unused-Dependencies "false";' } - end - end - end - - context 'auto_reboot' do - context 'true' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - auto_reboot => true - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - it { should contain 'Unattended-Upgrade::Automatic-Reboot "true";' } - end - end - - context 'false' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - auto_reboot => false, - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - it { should contain 'Unattended-Upgrade::Automatic-Reboot "false";' } - end - end - end - - context 'dl_limit' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - dl_limit => '99' - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do - it { should be_file } - it { should contain 'Acquire::http::Dl-Limit "99"' } - end - end - - context 'enable' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - enable => '2' - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/10periodic') do - it { should be_file } - it { should contain 'APT::Periodic::Enable "2"' } - end - end - - context 'backup_interval' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - backup_interval => '2' - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/10periodic') do - it { should be_file } - it { should contain 'APT::Periodic::BackUpArchiveInterval "2";' } - end - end - - context 'backup_level' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - backup_level => '2' - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/10periodic') do - it { should be_file } - it { should contain 'APT::Periodic::BackUpLevel "2";' } - end - end - - context 'max_age' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - max_age => '2' - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/10periodic') do - it { should be_file } - it { should contain 'APT::Periodic::MaxAge "2";' } - end - end - - context 'min_age' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - min_age => '2' - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/10periodic') do - it { should be_file } - it { should contain 'APT::Periodic::MinAge "2";' } - end - end - - context 'max_size' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - max_size => '2' - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/10periodic') do - it { should be_file } - it { should contain 'APT::Periodic::MaxSize "2";' } - end - end - - context 'download_delta' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - download_delta => '2' - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/10periodic') do - it { should be_file } - it { should contain 'APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";' } - end - end - - context 'verbose' do - it 'should work with no errors' do - pp = <<-EOS - include apt - class { 'apt::unattended_upgrades': - verbose => '2' - } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe file('/etc/apt/apt.conf.d/10periodic') do - it { should be_file } - it { should contain 'APT::Periodic::Verbose "2";' } - end - end - -end diff --git a/spec/acceptance/unsupported_spec.rb b/spec/acceptance/unsupported_spec.rb deleted file mode 100644 index 3f74685..0000000 --- a/spec/acceptance/unsupported_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'unsupported distributions and OSes', :if => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do - it 'class apt fails' do - pp = <<-EOS - class { 'apt': } - EOS - expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/This module only works on Debian or derivatives like Ubuntu/i) - end -end diff --git a/spec/classes/apt_spec.rb b/spec/classes/apt_spec.rb index a21e044..0a1c0a1 100644 --- a/spec/classes/apt_spec.rb +++ b/spec/classes/apt_spec.rb @@ -1,170 +1,265 @@ require 'spec_helper' describe 'apt', :type => :class do let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } - let :default_params do - { - :disable_keys => :undef, - :always_apt_update => false, - :purge_sources_list => false, - :purge_sources_list_d => false, - } + + context 'defaults' do + it { should contain_file('sources.list').that_notifies('Exec[apt_update]').only_with({ + 'ensure' => 'present', + 'path' => '/etc/apt/sources.list', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'notify' => 'Exec[apt_update]', + })} + + it { should contain_file('sources.list.d').that_notifies('Exec[apt_update]').only_with({ + 'ensure' => 'directory', + 'path' => '/etc/apt/sources.list.d', + 'owner' => 'root', + 'group' => 'root', + 'purge' => false, + 'recurse' => false, + 'notify' => 'Exec[apt_update]', + })} + + it { should contain_file('preferences.d').only_with({ + 'ensure' => 'directory', + 'path' => '/etc/apt/preferences.d', + 'owner' => 'root', + 'group' => 'root', + 'purge' => false, + 'recurse' => false, + })} + + it { should contain_file('01proxy').that_notifies('Exec[apt_update]').only_with({ + 'ensure' => 'absent', + 'path' => '/etc/apt/apt.conf.d/01proxy', + 'notify' => 'Exec[apt_update]', + })} + + it 'should lay down /etc/apt/apt.conf.d/15update-stamp' do + should contain_file('/etc/apt/apt.conf.d/15update-stamp').with({ + 'group' => 'root', + 'mode' => '0644', + 'owner' => 'root', + }).with_content('APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};') + end + + it { should contain_file('old-proxy-file').that_notifies('Exec[apt_update]').only_with({ + 'ensure' => 'absent', + 'path' => '/etc/apt/apt.conf.d/proxy', + 'notify' => 'Exec[apt_update]', + })} + + it { should contain_exec('apt_update').with({ + 'refreshonly' => 'true', + })} end - [{}, - { - :disable_keys => true, - :always_apt_update => true, - :proxy_host => true, - :proxy_port => '3128', - :purge_sources_list => true, - :purge_sources_list_d => true, - }, - { - :purge_preferences => true, - :purge_preferences_d => true, - }, - { - :disable_keys => false - } - ].each do |param_set| - describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do - let :param_hash do - default_params.merge(param_set) - end + context 'lots of non-defaults' do + let :params do + { + :always_apt_update => true, + :disable_keys => true, + :proxy_host => 'foo', + :proxy_port => '9876', + :purge_sources_list => true, + :purge_sources_list_d => true, + :purge_preferences => true, + :purge_preferences_d => true, + :update_timeout => '1', + :update_tries => '3', + :fancy_progress => true, + } + end - let :params do - param_set - end + it { should contain_file('sources.list').with({ + 'content' => "# Repos managed by puppet.\n" + })} - let :refresh_only_apt_update do - if param_hash[:always_apt_update] - false - else - true - end - end + it { should contain_file('sources.list.d').with({ + 'purge' => 'true', + 'recurse' => 'true', + })} - it { should contain_class("apt::params") } - - it { - if param_hash[:purge_sources_list] - should contain_file("sources.list").with({ - 'path' => "/etc/apt/sources.list", - 'ensure' => "present", - 'owner' => "root", - 'group' => "root", - 'mode' => "0644", - "content" => "# Repos managed by puppet.\n" - }) - else - should contain_file("sources.list").with({ - 'path' => "/etc/apt/sources.list", - 'ensure' => "present", - 'owner' => "root", - 'group' => "root", - 'mode' => "0644", - 'content' => nil - }) - end + it { should contain_file('apt-preferences').only_with({ + 'ensure' => 'absent', + 'path' => '/etc/apt/preferences', + })} + + it { should contain_file('preferences.d').with({ + 'purge' => 'true', + 'recurse' => 'true', + })} + + it { should contain_file('99progressbar').only_with({ + 'ensure' => 'present', + 'content' => 'Dpkg::Progress-Fancy "1";', + 'path' => '/etc/apt/apt.conf.d/99progressbar', + })} + + it { should contain_file('99unauth').only_with({ + 'ensure' => 'present', + 'content' => "APT::Get::AllowUnauthenticated 1;\n", + 'path' => '/etc/apt/apt.conf.d/99unauth', + })} + + it { should contain_file('01proxy').that_notifies('Exec[apt_update]').only_with({ + 'ensure' => 'present', + 'path' => '/etc/apt/apt.conf.d/01proxy', + 'content' => "Acquire::http::Proxy \"http://foo:9876\";\n", + 'notify' => 'Exec[apt_update]', + 'mode' => '0644', + 'owner' => 'root', + 'group' => 'root' + })} + + it { should contain_exec('apt_update').with({ + 'refreshonly' => 'false', + 'timeout' => '1', + 'tries' => '3', + })} + + end + + context 'more non-default' do + let :params do + { + :fancy_progress => false, + :disable_keys => false, } - it { - if param_hash[:purge_sources_list_d] - should create_file("sources.list.d").with({ - 'path' => "/etc/apt/sources.list.d", - 'ensure' => "directory", - 'owner' => "root", - 'group' => "root", - 'purge' => true, - 'recurse' => true, - 'notify' => 'Exec[apt_update]' - }) - else - should create_file("sources.list.d").with({ - 'path' => "/etc/apt/sources.list.d", - 'ensure' => "directory", - 'owner' => "root", - 'group' => "root", - 'purge' => false, - 'recurse' => false, - 'notify' => 'Exec[apt_update]' - }) - end + end + + it { should contain_file('99progressbar').only_with({ + 'ensure' => 'absent', + 'path' => '/etc/apt/apt.conf.d/99progressbar', + })} + + it { should contain_file('99unauth').only_with({ + 'ensure' => 'absent', + 'path' => '/etc/apt/apt.conf.d/99unauth', + })} + + end + + context 'with sources defined on valid osfamily' do + let :facts do + { :osfamily => 'Debian', + :lsbdistcodename => 'precise', + :lsbdistid => 'Debian', } - it { - if param_hash[:purge_preferences] - should create_file('apt-preferences').with({ - :ensure => 'absent', - :path => '/etc/apt/preferences', - }) - else - should_not contain_file('apt-preferences') - end + end + let(:params) { { :sources => { + 'debian_unstable' => { + 'location' => 'http://debian.mirror.iweb.ca/debian/', + 'release' => 'unstable', + 'repos' => 'main contrib non-free', + 'required_packages' => 'debian-keyring debian-archive-keyring', + 'key' => '55BE302B', + 'key_server' => 'subkeys.pgp.net', + 'pin' => '-10', + 'include_src' => true + }, + 'puppetlabs' => { + 'location' => 'http://apt.puppetlabs.com', + 'repos' => 'main', + 'key' => '4BD6EC30', + 'key_server' => 'pgp.mit.edu', } + } } } - it { - if param_hash[:purge_preferences_d] - should create_file("preferences.d").with({ - 'path' => "/etc/apt/preferences.d", - 'ensure' => "directory", - 'owner' => "root", - 'group' => "root", - 'purge' => true, - 'recurse' => true, - }) - else - should create_file("preferences.d").with({ - 'path' => "/etc/apt/preferences.d", - 'ensure' => "directory", - 'owner' => "root", - 'group' => "root", - 'purge' => false, - 'recurse' => false, - }) - end - } + it { + should contain_file('debian_unstable.list').with({ + 'ensure' => 'present', + 'path' => '/etc/apt/sources.list.d/debian_unstable.list', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'notify' => 'Exec[apt_update]', + }) + } - it { - should contain_exec("apt_update").with({ - 'command' => "/usr/bin/apt-get update", - 'refreshonly' => refresh_only_apt_update - }) - } + it { should contain_file('debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) } + it { should contain_file('debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) } - it { - if param_hash[:disable_keys] == true - should create_file("99unauth").with({ - 'content' => "APT::Get::AllowUnauthenticated 1;\n", - 'ensure' => "present", - 'path' => "/etc/apt/apt.conf.d/99unauth" - }) - elsif param_hash[:disable_keys] == false - should create_file("99unauth").with({ - 'ensure' => "absent", - 'path' => "/etc/apt/apt.conf.d/99unauth" - }) - elsif param_hash[:disable_keys] != :undef - should_not create_file("99unauth").with({ - 'path' => "/etc/apt/apt.conf.d/99unauth" - }) - end - } - describe 'when setting a proxy' do - it { - if param_hash[:proxy_host] - should contain_file('01proxy').with( - 'path' => '/etc/apt/apt.conf.d/01proxy', - 'content' => "Acquire::http::Proxy \"http://#{param_hash[:proxy_host]}:#{param_hash[:proxy_port]}\";\n", - 'notify' => "Exec[apt_update]" - ) - else - should contain_file('01proxy').with( - 'path' => '/etc/apt/apt.conf.d/01proxy', - 'notify' => 'Exec[apt_update]', - 'ensure' => 'absent' - ) - end + it { + should contain_file('puppetlabs.list').with({ + 'ensure' => 'present', + 'path' => '/etc/apt/sources.list.d/puppetlabs.list', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'notify' => 'Exec[apt_update]', + }) + } + + it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) } + it { should contain_file('puppetlabs.list').with_content(/^deb-src http:\/\/apt.puppetlabs.com precise main$/) } + end + + describe 'failing tests' do + context 'bad purge_sources_list' do + let :params do + { + 'purge_sources_list' => 'foo' + } + end + it do + expect { + should compile + }.to raise_error(Puppet::Error) + end + end + + context 'bad purge_sources_list_d' do + let :params do + { + 'purge_sources_list_d' => 'foo' + } + end + it do + expect { + should compile + }.to raise_error(Puppet::Error) + end + end + + context 'bad purge_preferences' do + let :params do + { + 'purge_preferences' => 'foo' + } + end + it do + expect { + should compile + }.to raise_error(Puppet::Error) + end + end + + context 'bad purge_preferences_d' do + let :params do + { + 'purge_preferences_d' => 'foo' } end + it do + expect { + should compile + }.to raise_error(Puppet::Error) + end + end + + context 'with unsupported osfamily' do + let :facts do + { :osfamily => 'Darwin', } + end + + it do + expect { + should compile + }.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/) + end end end end diff --git a/spec/classes/apt_update_spec.rb b/spec/classes/apt_update_spec.rb new file mode 100644 index 0000000..d70efd3 --- /dev/null +++ b/spec/classes/apt_update_spec.rb @@ -0,0 +1,109 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe 'apt::update', :type => :class do + context 'when apt::always_apt_update is true' do + #This should completely disable all of this logic. These tests are to guarantee that we don't somehow magically change the behavior. + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } + let (:pre_condition) { "class{'::apt': always_apt_update => true}" } + it 'should trigger an apt-get update run' do + #set the apt_update exec's refreshonly attribute to false + should contain_exec('apt_update').with({'refreshonly' => false }) + end + ['always','daily','weekly','reluctantly'].each do |update_frequency| + context "when apt::apt_update_frequency has the value of #{update_frequency}" do + { 'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval| + context "and $::apt_update_last_success indicates #{desc}" do + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval } } + let (:pre_condition) { "class{'::apt': always_apt_update => true, apt_update_frequency => '#{update_frequency}' }" } + it 'should trigger an apt-get update run' do + # set the apt_update exec's refreshonly attribute to false + should contain_exec('apt_update').with({'refreshonly' => false}) + end + end + context 'when $::apt_update_last_success is nil' do + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } + let (:pre_condition) { "class{'::apt': always_apt_update => true, apt_update_frequency => '#{update_frequency}' }" } + it 'should trigger an apt-get update run' do + #set the apt_update exec\'s refreshonly attribute to false + should contain_exec('apt_update').with({'refreshonly' => false}) + end + end + end + end + end + end + + context 'when apt::always_apt_update is false' do + context "and apt::apt_update_frequency has the value of always" do + { 'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval| + context "and $::apt_update_last_success indicates #{desc}" do + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval } } + let (:pre_condition) { "class{'::apt': always_apt_update => false, apt_update_frequency => 'always' }" } + it 'should trigger an apt-get update run' do + #set the apt_update exec's refreshonly attribute to false + should contain_exec('apt_update').with({'refreshonly' => false}) + end + end + end + context 'when $::apt_update_last_success is nil' do + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } + let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => 'always' }" } + it 'should trigger an apt-get update run' do + #set the apt_update exec\'s refreshonly attribute to false + should contain_exec('apt_update').with({'refreshonly' => false}) + end + end + end + context "and apt::apt_update_frequency has the value of reluctantly" do + {'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval| + context "and $::apt_update_last_success indicates #{desc}" do + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval} } + let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => 'reluctantly' }" } + it 'should not trigger an apt-get update run' do + #don't change the apt_update exec's refreshonly attribute. (it should be true) + should contain_exec('apt_update').with({'refreshonly' => true}) + end + end + end + context 'when $::apt_update_last_success is nil' do + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } + let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => 'reluctantly' }" } + it 'should not trigger an apt-get update run' do + #don't change the apt_update exec's refreshonly attribute. (it should be true) + should contain_exec('apt_update').with({'refreshonly' => true}) + end + end + end + ['daily','weekly'].each do |update_frequency| + context "and apt::apt_update_frequency has the value of #{update_frequency}" do + { 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval| + context "and $::apt_update_last_success indicates #{desc}" do + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval } } + let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => '#{update_frequency}' }" } + it 'should trigger an apt-get update run' do + #set the apt_update exec\'s refreshonly attribute to false + should contain_exec('apt_update').with({'refreshonly' => false}) + end + end + end + context 'when the $::apt_update_last_success fact has a recent value' do + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => Time.now.to_i } } + let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => '#{update_frequency}' }" } + it 'should not trigger an apt-get update run' do + #don't change the apt_update exec\'s refreshonly attribute. (it should be true) + should contain_exec('apt_update').with({'refreshonly' => true}) + end + end + context 'when $::apt_update_last_success is nil' do + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } + let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => '#{update_frequency}' }" } + it 'should trigger an apt-get update run' do + #set the apt_update exec\'s refreshonly attribute to false + should contain_exec('apt_update').with({'refreshonly' => false}) + end + end + end + end + end +end diff --git a/spec/classes/backports_spec.rb b/spec/classes/backports_spec.rb index 2f67aa4..18f6337 100644 --- a/spec/classes/backports_spec.rb +++ b/spec/classes/backports_spec.rb @@ -5,7 +5,8 @@ describe 'apt::backports', :type => :class do let :facts do { 'lsbdistcodename' => 'Karmic', - 'lsbdistid' => 'Ubuntu' + 'lsbdistid' => 'Ubuntu', + 'osfamily' => 'Debian' } end @@ -36,7 +37,8 @@ describe 'apt::backports', :type => :class do let :facts do { 'lsbdistcodename' => 'Karmic', - 'lsbdistid' => 'Ubuntu' + 'lsbdistid' => 'Ubuntu', + 'osfamily' => 'Debian' } end @@ -57,6 +59,7 @@ describe 'apt::backports', :type => :class do { 'lsbdistcodename' => 'Squeeze', 'lsbdistid' => 'Debian', + 'osfamily' => 'Debian' } end @@ -71,12 +74,55 @@ describe 'apt::backports', :type => :class do } end + describe "when turning on backports for linux mint debian edition" do + + let :facts do + { + 'lsbdistcodename' => 'debian', + 'lsbdistid' => 'LinuxMint', + 'osfamily' => 'Debian' + } + end + + it { should contain_apt__source('backports').with({ + 'location' => 'http://ftp.debian.org/debian/', + 'release' => 'wheezy-backports', + 'repos' => 'main contrib non-free', + 'key' => '46925553', + 'key_server' => 'pgp.mit.edu', + 'pin' => 200, + }) + } + end + + describe "when turning on backports for linux mint 17 (ubuntu-based)" do + + let :facts do + { + 'lsbdistcodename' => 'qiana', + 'lsbdistid' => 'LinuxMint', + 'osfamily' => 'Debian' + } + end + + it { should contain_apt__source('backports').with({ + 'location' => 'http://us.archive.ubuntu.com/ubuntu', + 'release' => 'trusty-backports', + 'repos' => 'main universe multiverse restricted', + 'key' => '437D05B5', + 'key_server' => 'pgp.mit.edu', + 'pin' => 200, + }) + } + end + describe "when turning on backports for debian squeeze but using your own mirror" do let :facts do { 'lsbdistcodename' => 'Squeeze', - 'lsbdistid' => 'Debian' + 'lsbdistid' => 'Debian', + 'osfamily' => 'Debian' } end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb deleted file mode 100644 index c5e938a..0000000 --- a/spec/classes/init_spec.rb +++ /dev/null @@ -1,69 +0,0 @@ -require 'spec_helper' -describe 'apt' do - context 'with sources defined on valid osfamily' do - let :facts do - { :osfamily => 'Debian', - :lsbdistcodename => 'precise', - :lsbdistid => 'Debian', - } - end - let(:params) { { :sources => { - 'debian_unstable' => { - 'location' => 'http://debian.mirror.iweb.ca/debian/', - 'release' => 'unstable', - 'repos' => 'main contrib non-free', - 'required_packages' => 'debian-keyring debian-archive-keyring', - 'key' => '55BE302B', - 'key_server' => 'subkeys.pgp.net', - 'pin' => '-10', - 'include_src' => true - }, - 'puppetlabs' => { - 'location' => 'http://apt.puppetlabs.com', - 'repos' => 'main', - 'key' => '4BD6EC30', - 'key_server' => 'pgp.mit.edu', - } - } } } - - it { - should contain_file('debian_unstable.list').with({ - 'ensure' => 'present', - 'path' => '/etc/apt/sources.list.d/debian_unstable.list', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - 'notify' => 'Exec[apt_update]', - }) - } - - it { should contain_file('debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) } - it { should contain_file('debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) } - - it { - should contain_file('puppetlabs.list').with({ - 'ensure' => 'present', - 'path' => '/etc/apt/sources.list.d/puppetlabs.list', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - 'notify' => 'Exec[apt_update]', - }) - } - - it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) } - it { should contain_file('puppetlabs.list').with_content(/^deb-src http:\/\/apt.puppetlabs.com precise main$/) } - end - - context 'with unsupported osfamily' do - let :facts do - { :osfamily => 'Darwin', } - end - - it do - expect { - should compile - }.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/) - end - end -end diff --git a/spec/classes/params_spec.rb b/spec/classes/params_spec.rb index aa330bb..d85e849 100644 --- a/spec/classes/params_spec.rb +++ b/spec/classes/params_spec.rb @@ -24,4 +24,16 @@ describe 'apt::params', :type => :class do end end + + describe "With lsb-release not installed" do + let(:facts) { { :lsbdistid => '' } } + let (:title) { 'my_package' } + + it do + expect { + should compile + }.to raise_error(Puppet::Error, /Unable to determine lsbdistid, is lsb-release installed/) + end + end + end diff --git a/spec/classes/unattended_upgrades_spec.rb b/spec/classes/unattended_upgrades_spec.rb index 8494f04..57df21c 100644 --- a/spec/classes/unattended_upgrades_spec.rb +++ b/spec/classes/unattended_upgrades_spec.rb @@ -24,270 +24,176 @@ describe 'apt::unattended_upgrades', :type => :class do }) } - describe "origins" do - describe 'on Debian' do - default_facts = { :lsbdistid => 'Debian' } - context 'defaults' do - let :facts do default_facts end - it { - should contain_file(file_unattended).with_content( - /^Unattended-Upgrade::Origins-Pattern/ - ).with_content( - /"origin=Debian,archive=stable,label=Debian-Security";/ - ) - } - end - context 'defaults with custom origin' do - let :facts do default_facts end - let :params do { :origins => ['bananana']} end - it { - should contain_file(file_unattended).with_content( - /^Unattended-Upgrade::Origins-Pattern/ - ).with_content( - /"bananana";/ - ) - } - end - context 'defaults with invalid origin' do - let :facts do default_facts end - let :params do { :origins => 'bananana'} end - it { - expect {subject}.to raise_error(/is not an Array/) - } - end - context 'squeeze' do - let :facts do default_facts.merge({:lsbdistcodename => 'squeeze'}) end - it { - should contain_file(file_unattended).with_content( - /^Unattended-Upgrade::Allowed-Origins/ - ).with_content( - /"\${distro_id} \${distro_codename}-lts";/ - ).with_content( - /"\${distro_id} \${distro_codename}-security";/ - ).with_content( - /"\${distro_id} oldstable";/ - ) - } - end - context 'wheezy' do - let :facts do default_facts.merge({:lsbdistcodename => 'wheezy'}) end - it { - should contain_file(file_unattended).with_content( - /^Unattended-Upgrade::Origins-Pattern/ - ).with_content( - /"origin=Debian,archive=stable,label=Debian-Security";/ - ) + describe 'failing' do + let :facts do + { + 'lsbdistid' => 'debian', + 'lsbdistcodename' => 'squeeze', + } + end + context 'bad auto_fix' do + let :params do + { + 'auto_fix' => 'foo', } end + it { expect { should raise_error(Puppet::Error) } } end - describe 'on Ubuntu' do - default_facts = { :lsbdistid => 'Ubuntu' } - context 'default' do - let :facts do default_facts end - it { - should contain_file(file_unattended).with_content( - /^Unattended-Upgrade::Allowed-Origins/ - ).with_content( - /"\${distro_id}\:\${distro_codename}-security";/ - ) - } - end - context 'lucid' do - let :facts do default_facts.merge({:lsbdistcodename => 'lucid'}) end - it { - should contain_file(file_unattended).with_content( - /^Unattended-Upgrade::Allowed-Origins/ - ).with_content( - /"\${distro_id} \${distro_codename}-security";/ - ) - } - end - context 'precise' do - let :facts do default_facts.merge({:lsbdistcodename => 'precise'}) end - it { - should contain_file(file_unattended).with_content( - /^Unattended-Upgrade::Allowed-Origins/ - ).with_content( - /"\${distro_id}\:\${distro_codename}-security";/ - ) - } - end - context 'trusty' do - let :facts do default_facts.merge({:lsbdistcodename => 'trusty'}) end - it { - should contain_file(file_unattended).with_content( - /^Unattended-Upgrade::Allowed-Origins/ - ).with_content( - /"\${distro_id}\:\${distro_codename}-security";/ - ) + context 'bad minimal_steps' do + let :params do + { + 'minimal_steps' => 'foo', } end - end - end - - describe "blacklist" do - describe "with param defaults" do - let(:params) {{ }} - it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\};$/) } + it { expect { should raise_error(Puppet::Error) } } end - describe "with blacklist => []" do + context 'bad install_on_shutdown' do let :params do - { :blacklist => ['libc6', 'libc6-dev'] } + { + 'install_on_shutdown' => 'foo', + } end - it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\t"libc6";\n\t"libc6-dev";\n\};$/) } - end - end - - describe "with update => 2" do - let :params do - { :update => "2" } - end - it { should contain_file(file_periodic).with_content(/^APT::Periodic::Update-Package-Lists "2";$/) } - end - - describe "with download => 2" do - let :params do - { :download => "2" } - end - it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages "2";$/) } - end - - describe "with upgrade => 2" do - let :params do - { :upgrade => "2" } - end - it { should contain_file(file_periodic).with_content(/^APT::Periodic::Unattended-Upgrade "2";$/) } - end - - describe "with autoclean => 2" do - let :params do - { :autoclean => "2" } - end - it { should contain_file(file_periodic).with_content(/^APT::Periodic::AutocleanInterval "2";$/) } - end - - describe "with auto_fix => false" do - let :params do - { :auto_fix => false } - end - it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::AutoFixInterruptedDpkg "false";$/) } - end - - describe "with minimal_steps => true" do - let :params do - { :minimal_steps => true } - end - it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MinimalSteps "true";$/) } - end - - describe "with install_on_shutdown => true" do - let :params do - { :install_on_shutdown => true } - end - it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::InstallOnShutdown "true";$/) } - end - - describe "mail_to" do - describe "param defaults" do - let(:params) {{ }} - it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail /) } - it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError /) } + it { expect { should raise_error(Puppet::Error) } } end - describe "with mail_to => user@website, mail_only_on_error => true" do + context 'bad mail_only_on_error' do let :params do - { :mail_to => "user@website", - :mail_only_on_error => true } + { + 'mail_only_on_error' => 'foo', + } end - it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail "user@website";$/) } - it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError "true";$/) } - end - end - - describe "with remove_unused => false" do - let :params do - { :remove_unused => false } - end - it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Remove-Unused-Dependencies "false";$/) } - end - - describe "with auto_reboot => true" do - let :params do - { :auto_reboot => true } - end - it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Automatic-Reboot "true";$/) } - end - - describe "dl_limit" do - describe "param defaults" do - let(:params) {{ }} - it { should_not contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit /) } + it { expect { should raise_error(Puppet::Error) } } end - describe "with dl_limit => 70" do + context 'bad remove_unused' do let :params do - { :dl_limit => "70" } + { + 'remove_unused' => 'foo', + } end - it { should contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit "70";$/) } - end - end - - describe "with enable => 0" do - let :params do - { :enable => "0" } - end - it { should contain_file(file_periodic).with_content(/^APT::Periodic::Enable "0";$/) } - end - - describe "with backup_interval => 1" do - let :params do - { :backup_interval => "1" } - end - it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpArchiveInterval "1";$/) } - end - - describe "with backup_level => 0" do - let :params do - { :backup_level => "0" } + it { expect { should raise_error(Puppet::Error) } } end - it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpLevel "0";$/) } - end - describe "with max_age => 1" do - let :params do - { :max_age => "1" } - end - it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxAge "1";$/) } - end - - describe "with min_age => 1" do - let :params do - { :min_age => "1" } + context 'bad auto_reboot' do + let :params do + { + 'auto_reboot' => 'foo', + } + end + it { expect { should raise_error(Puppet::Error) } } end - it { should contain_file(file_periodic).with_content(/^APT::Periodic::MinAge "1";$/) } - end - describe "with max_size => 1" do - let :params do - { :max_size => "1" } + context 'bad origins' do + let :params do + { + 'origins' => 'foo' + } + end + it { expect { should raise_error(Puppet::Error) } } end - it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxSize "1";$/) } - end - describe "with download_delta => 2" do - let :params do - { :download_delta => "2" } - end - it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";$/) } - end + context 'bad randomsleep' do + let :params do + { + 'randomsleep' => '4ever' + } + end + it { expect { should raise_error(Puppet::Error) } } + end + end + + context 'defaults' do + let :facts do + { + 'lsbdistid' => 'debian', + 'lsbdistcodename' => 'squeeze', + } + end + + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Allowed-Origins \{\n\t"\${distro_id} oldstable";\n\t"\${distro_id} \${distro_codename}-security";\n\t"\${distro_id} \${distro_codename}-lts";\n\};} } + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::AutoFixInterruptedDpkg "true";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::MinimalSteps "false";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::InstallOnShutdown "false";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Remove-Unused-Dependencies "true";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Automatic-Reboot "false";}} + + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Enable "1";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpArchiveInterval "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpLevel "3";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxAge "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MinAge "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxSize "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Update-Package-Lists "1";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages "1";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages-Debdelta "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Unattended-Upgrade "1";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::AutocleanInterval "7";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Verbose "0";}} + it { is_expected.to_not contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::RandomSleep}} + end + + context 'anything but defaults' do + let :facts do + { + 'lsbdistid' => 'debian', + 'lsbdistcodename' => 'wheezy', + } + end + + let :params do + { + 'enable' => '0', + 'backup_interval' => '3', + 'backup_level' => '1', + 'max_age' => '7', + 'min_age' => '1', + 'max_size' => '100', + 'update' => '0', + 'download' => '0', + 'download_delta' => '1', + 'upgrade' => '0', + 'autoclean' => '0', + 'verbose' => '1', + 'origins' => ['bananas'], + 'blacklist' => ['foo', 'bar'], + 'auto_fix' => false, + 'minimal_steps' => true, + 'install_on_shutdown' => true, + 'mail_to' => 'root@localhost', + 'mail_only_on_error' => true, + 'remove_unused' => false, + 'auto_reboot' => true, + 'dl_limit' => '70', + 'randomsleep' => '1799', + } + end + + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Origins-Pattern \{\n\t"bananas";\n\};} } + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Package-Blacklist \{\n\t"foo";\n\t"bar";\n\};} } + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::AutoFixInterruptedDpkg "false";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::MinimalSteps "true";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::InstallOnShutdown "true";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Mail "root@localhost";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::MailOnlyOnError "true";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Remove-Unused-Dependencies "false";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Automatic-Reboot "true";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Acquire::http::Dl-Limit "70";}} + + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Enable "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpArchiveInterval "3";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpLevel "1";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxAge "7";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MinAge "1";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxSize "100";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Update-Package-Lists "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages-Debdelta "1";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Unattended-Upgrade "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::AutocleanInterval "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Verbose "1";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::RandomSleep "1799";}} - describe "with verbose => 2" do - let :params do - { :verbose => "2" } - end - it { should contain_file(file_periodic).with_content(/^APT::Periodic::Verbose "2";$/) } end - end diff --git a/spec/defines/builddep_spec.rb b/spec/defines/builddep_spec.rb index a0cbaa4..41152d5 100644 --- a/spec/defines/builddep_spec.rb +++ b/spec/defines/builddep_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' describe 'apt::builddep', :type => :define do - let(:facts) { { :lsbdistid => 'Debian' } } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } let(:title) { 'my_package' } - describe "should require apt-get update" do - it { should contain_exec("apt_update").with({ - 'command' => "/usr/bin/apt-get update", - 'refreshonly' => true + describe "defaults" do + it { should contain_exec("apt-builddep-my_package").that_requires('Exec[apt_update]').with({ + 'command' => "/usr/bin/apt-get -y --force-yes build-dep my_package", + 'logoutput' => 'on_failure' }) } it { should contain_anchor("apt::builddep::my_package").with({ diff --git a/spec/defines/conf_spec.rb b/spec/defines/conf_spec.rb index cda5900..ec4e229 100644 --- a/spec/defines/conf_spec.rb +++ b/spec/defines/conf_spec.rb @@ -17,12 +17,6 @@ describe 'apt::conf', :type => :define do "/etc/apt/apt.conf.d/00norecommends" end - it { should contain_apt__conf('norecommends').with({ - 'priority' => '00', - 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n" - }) - } - it { should contain_file(filename).with({ 'ensure' => 'present', 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n", diff --git a/spec/defines/force_spec.rb b/spec/defines/force_spec.rb index 0d3d6e5..c32c438 100644 --- a/spec/defines/force_spec.rb +++ b/spec/defines/force_spec.rb @@ -11,18 +11,18 @@ describe 'apt::force', :type => :define do 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 - let :params do - default_params - end - it { should contain_exec("/usr/bin/apt-get -y install #{title}").with( - :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'", - :timeout => '300' + 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' ) } end @@ -30,7 +30,7 @@ describe 'apt::force', :type => :define do 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 @@ -39,11 +39,41 @@ describe 'apt::force', :type => :define do 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( @@ -51,8 +81,22 @@ describe 'apt::force', :type => :define do :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 diff --git a/spec/defines/hold_spec.rb b/spec/defines/hold_spec.rb index 731e218..60b991f 100644 --- a/spec/defines/hold_spec.rb +++ b/spec/defines/hold_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' describe 'apt::hold' do let :facts do { - :osfamily => 'Debian', - :lsbdistid => 'Debian', - :lsbrelease => 'wheezy', + :osfamily => 'Debian', + :lsbdistid => 'Debian', + :lsbrelease => 'wheezy', } end let :title do @@ -18,14 +18,7 @@ describe 'apt::hold' do let :params do default_params end it 'creates an apt preferences file' do - should contain_apt__hold(title).with({ - :ensure => 'present', - :package => title, - :version => params[:version], - :priority => 1001, - }) - - should contain_apt__pin("hold #{title} at #{params[:version]}").with({ + should contain_apt__pin("hold_#{title}").with({ :ensure => 'present', :packages => title, :version => params[:version], @@ -38,11 +31,8 @@ describe 'apt::hold' do let :params do default_params.merge({:ensure => 'absent',}) end it 'creates an apt preferences file' do - should contain_apt__hold(title).with({ - :ensure => params[:ensure], - }) - should contain_apt__pin("hold #{title} at #{params[:version]}").with({ + should contain_apt__pin("hold_#{title}").with({ :ensure => params[:ensure], }) end @@ -52,22 +42,29 @@ describe 'apt::hold' do let :params do default_params.merge({:priority => 990,}) end it 'creates an apt preferences file' do - should contain_apt__hold(title).with({ + should contain_apt__pin("hold_#{title}").with({ :ensure => 'present', - :package => title, + :packages => title, :version => params[:version], :priority => params[:priority], }) + end + end - should contain_apt__pin("hold #{title} at #{params[:version]}").with({ + describe 'package => foo' do + let :params do default_params.merge({:package => 'foo'}) end + + it 'creates an apt preferences file' do + should contain_apt__pin("hold_foo").with({ :ensure => 'present', - :packages => title, + :packages => 'foo', :version => params[:version], - :priority => params[:priority], + :priority => 1001, }) end end + describe 'validation' do context 'version => {}' do let :params do { :version => {}, } end diff --git a/spec/defines/key_spec.rb b/spec/defines/key_spec.rb index 005c95e..dbb67c4 100644 --- a/spec/defines/key_spec.rb +++ b/spec/defines/key_spec.rb @@ -10,12 +10,6 @@ describe 'apt::key', :type => :define do describe 'normal operation' do describe 'default options' do - it 'contains the apt::key' do - should contain_apt__key(title).with({ - :key => title, - :ensure => 'present', - }) - end it 'contains the apt_key' do should contain_apt_key(title).with({ :id => title, @@ -40,12 +34,6 @@ describe 'apt::key', :type => :define do :key => GPG_KEY_ID, } end - it 'contains the apt::key' do - should contain_apt__key(title).with({ - :key => GPG_KEY_ID, - :ensure => 'present', - }) - end it 'contains the apt_key' do should contain_apt_key(title).with({ :id => GPG_KEY_ID, @@ -66,12 +54,6 @@ describe 'apt::key', :type => :define do :ensure => 'absent', } end - it 'contains the apt::key' do - should contain_apt__key(title).with({ - :key => title, - :ensure => 'absent', - }) - end it 'contains the apt_key' do should contain_apt_key(title).with({ :id => title, @@ -87,26 +69,22 @@ describe 'apt::key', :type => :define do end end - describe 'key_content =>' do + describe 'set a bunch of things!' do let :params do { :key_content => 'GPG key content', + :key_source => 'http://apt.puppetlabs.com/pubkey.gpg', + :key_server => 'pgp.mit.edu', + :key_options => 'debug', } end - it 'contains the apt::key' do - should contain_apt__key(title).with({ - :key => title, - :ensure => 'present', - :key_content => params[:key_content], - }) - end it 'contains the apt_key' do should contain_apt_key(title).with({ :id => title, :ensure => 'present', - :source => nil, - :server => nil, + :source => 'http://apt.puppetlabs.com/pubkey.gpg', + :server => 'pgp.mit.edu', :content => params[:key_content], - :keyserver_options => nil, + :keyserver_options => 'debug', }) end it 'contains the apt_key present anchor' do @@ -114,217 +92,131 @@ describe 'apt::key', :type => :define do end end - describe 'key_source =>' do - let :params do { - :key_source => 'http://apt.puppetlabs.com/pubkey.gpg', + context "domain with dash" do + let(:params) do{ + :key_server => 'p-gp.m-it.edu', } end - - it 'contains the apt::key' do - should contain_apt__key(title).with({ - :key => title, - :ensure => 'present', - :key_source => params[:key_source], + it 'contains the apt_key' do + should contain_apt_key(title).with({ + :id => title, + :server => 'p-gp.m-it.edu', }) end + end + + context "url" do + let :params do + { + :key_server => 'hkp://pgp.mit.edu', + } + end it 'contains the apt_key' do should contain_apt_key(title).with({ - :id => title, - :ensure => 'present', - :source => params[:key_source], - :server => nil, - :content => nil, - :keyserver_options => nil, + :id => title, + :server => 'hkp://pgp.mit.edu', }) end - it 'contains the apt_key present anchor' do - should contain_anchor("apt_key #{title} present") - end end - - describe 'key_server =>' do - context 'domain name' do - let :params do { - :key_server => 'pgp.mit.edu', - } end - - it 'contains the apt::key' do - should contain_apt__key(title).with({ - :key => title, - :ensure => 'present', - :key_server => 'pgp.mit.edu', - }) - end - it 'contains the apt_key' do - should contain_apt_key(title).with({ - :id => title, - :ensure => 'present', - :source => nil, - :server => params[:key_server], - :content => nil, - :keyserver_options => nil, - }) - end - it 'contains the apt_key present anchor' do - should contain_anchor("apt_key #{title} present") - end - end - - context "domain with dash" do - let(:params) do{ - :key_server => 'p-gp.m-it.edu', - } end - it "should contain apt::key" do - should contain_apt__key(title).with({ - :key => title, - :ensure => 'present', - :key_server => 'p-gp.m-it.edu', - }) - end + context "url with port number" do + let :params do + { + :key_server => 'hkp://pgp.mit.edu:80', + } end - - context "domain begin with dash" do - let(:params) do{ - :key_server => '-pgp.mit.edu', - } end - it 'fails' do - expect { subject } .to raise_error(/does not match/) - end + it 'contains the apt_key' do + should contain_apt_key(title).with({ + :id => title, + :server => 'hkp://pgp.mit.edu:80', + }) end + end + end - context "domain begin with dot" do - let(:params) do{ - :key_server => '.pgp.mit.edu', - } end - it 'fails' do - expect { subject } .to raise_error(/does not match/) - end + describe 'validation' do + context "domain begin with dash" do + let(:params) do{ + :key_server => '-pgp.mit.edu', + } end + it 'fails' do + expect { subject } .to raise_error(/does not match/) end + end - context "domain end with dot" do - let(:params) do{ - :key_server => "pgp.mit.edu.", - } end - it 'fails' do - expect { subject } .to raise_error(/does not match/) - end + context "domain begin with dot" do + let(:params) do{ + :key_server => '.pgp.mit.edu', + } end + it 'fails' do + expect { subject } .to raise_error(/does not match/) end + end - context "url" do - let (:params) do{ - :key_server => 'hkp://pgp.mit.edu', - } end - it "should contain apt::key" do - should contain_apt__key(title).with({ - :key => title, - :ensure => 'present', - :key_server => 'hkp://pgp.mit.edu', - }) - end + context "domain end with dot" do + let(:params) do{ + :key_server => "pgp.mit.edu.", + } end + it 'fails' do + expect { subject } .to raise_error(/does not match/) end - context "url with port number" do - let (:params) do{ - :key_server => 'hkp://pgp.mit.edu:80', - } end - it "should contain apt::key" do - should contain_apt__key(title).with({ - :key => title, - :ensure => 'present', - :key_server => 'hkp://pgp.mit.edu:80', - }) - end + end + context "exceed character url" do + let :params do + { + :key_server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu' + } end - - context "incorrect port number url" do - let (:params) do{ + it 'fails' do + expect { subject }.to raise_error(/does not match/) + end + end + context "incorrect port number url" do + let :params do + { :key_server => 'hkp://pgp.mit.edu:8008080' - } end - it 'fails' do - expect { subject }.to raise_error(/does not match/) - end + } + end + it 'fails' do + expect { subject }.to raise_error(/does not match/) end - context "incorrect protocol for url" do - let (:params) do{ + end + context "incorrect protocol for url" do + let :params do + { :key_server => 'abc://pgp.mit.edu:80' - } end - it 'fails' do - expect { subject }.to raise_error(/does not match/) - end + } end - context "missing port number url" do - let (:params) do{ - :key_server => 'hkp://pgp.mit.edu:' - } end - it 'fails' do - expect { subject }.to raise_error(/does not match/) - end + it 'fails' do + expect { subject }.to raise_error(/does not match/) end - context "url ending with a dot" do - let (:params) do{ - :key_server => 'hkp://pgp.mit.edu.' - } end - it 'fails' do - expect { subject }.to raise_error(/does not match/) - end + end + context "missing port number url" do + let :params do + { + :key_server => 'hkp://pgp.mit.edu:' + } end - context "url begin with a dash" do - let(:params) do{ - :key_server => "hkp://-pgp.mit.edu", - } end - it 'fails' do - expect { subject }.to raise_error(/does not match/) - end + it 'fails' do + expect { subject }.to raise_error(/does not match/) end - context "url with dash" do - let(:params) do{ - :key_server => 'hkp://p-gp.m-it.edu', - } end - it "should contain apt::key" do - should contain_apt__key(title).with({ - :key => title, - :ensure => 'present', - :key_server => 'hkp://p-gp.m-it.edu', - }) - end + end + context "url ending with a dot" do + let :params do + { + :key_server => 'hkp://pgp.mit.edu.' + } end - context "exceed characher url" do - let (:params) do{ - :key_server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu' - } end - it 'fails' do - expect { subject }.to raise_error(/does not match/) - end + it 'fails' do + expect { subject }.to raise_error(/does not match/) end - end - - describe 'key_options =>' do - let :params do { - :key_options => 'debug', + end + context "url begin with a dash" do + let(:params) do{ + :key_server => "hkp://-pgp.mit.edu", } end - - it 'contains the apt::key' do - should contain_apt__key(title).with({ - :key => title, - :ensure => 'present', - :key_options => 'debug', - }) - end - it 'contains the apt_key' do - should contain_apt_key(title).with({ - :id => title, - :ensure => 'present', - :source => nil, - :server => nil, - :content => nil, - :keyserver_options => params[:key_options], - }) - end - it 'contains the apt_key present anchor' do - should contain_anchor("apt_key #{title} present") + it 'fails' do + expect { subject }.to raise_error(/does not match/) end end - end - - describe 'validation' do context 'invalid key' do let :title do 'Out of rum. Why? Why are we out of rum?' @@ -369,44 +261,55 @@ describe 'apt::key', :type => :define do expect { subject }.to raise_error(/is not a string/) end end - end - describe 'duplication' do - context 'two apt::key resources for same key, different titles' do - let :pre_condition do - "apt::key { 'duplicate': key => #{title}, }" + context 'invalid ensure' do + let :params do + { + :ensure => 'foo', + } end - - it 'contains two apt::key resources' do - should contain_apt__key('duplicate').with({ - :key => title, - :ensure => 'present', - }) - should contain_apt__key(title).with({ - :key => title, - :ensure => 'present', - }) - end - - it 'contains only a single apt_key' do - should contain_apt_key('duplicate').with({ - :id => title, - :ensure => 'present', - :source => nil, - :server => nil, - :content => nil, - :keyserver_options => nil, - }) - should_not contain_apt_key(title) + it 'fails' do + expect { subject }.to raise_error(/does not match/) end end - context 'two apt::key resources, different ensure' do - let :pre_condition do - "apt::key { 'duplicate': key => #{title}, ensure => 'absent', }" + describe 'duplication' do + context 'two apt::key resources for same key, different titles' do + let :pre_condition do + "apt::key { 'duplicate': key => #{title}, }" + end + + it 'contains two apt::key resources' do + should contain_apt__key('duplicate').with({ + :key => title, + :ensure => 'present', + }) + should contain_apt__key(title).with({ + :key => title, + :ensure => 'present', + }) + end + + it 'contains only a single apt_key' do + should contain_apt_key('duplicate').with({ + :id => title, + :ensure => 'present', + :source => nil, + :server => nil, + :content => nil, + :keyserver_options => nil, + }) + should_not contain_apt_key(title) + end end - it 'informs the user of the impossibility' do - expect { subject }.to raise_error(/already ensured as absent/) + + context 'two apt::key resources, different ensure' do + let :pre_condition do + "apt::key { 'duplicate': key => #{title}, ensure => 'absent', }" + end + it 'informs the user of the impossibility' do + expect { subject }.to raise_error(/already ensured as absent/) + end end end end diff --git a/spec/defines/pin_spec.rb b/spec/defines/pin_spec.rb index d79462c..23ebd59 100644 --- a/spec/defines/pin_spec.rb +++ b/spec/defines/pin_spec.rb @@ -3,118 +3,165 @@ describe 'apt::pin', :type => :define do let(:facts) { { :lsbdistid => 'Debian' } } let(:title) { 'my_pin' } - let :default_params do - { - :ensure => 'present', - :order => '', - :packages => '*', - :priority => '0', - :release => nil + context 'defaults' do + it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: \*\nPin: release a=my_pin\nPin-Priority: 0\n/)} + it { is_expected.to contain_file("my_pin.pref").with({ + 'ensure' => 'present', + 'path' => '/etc/apt/preferences.d/my_pin.pref', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + }) } end - [ - { :params => {}, - :content => "Explanation: : my_pin\nPackage: *\nPin: release a=my_pin\nPin-Priority: 0\n" - }, - { - :params => { - :packages => 'apache', - :priority => '1' - }, - :content => "Explanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n" - }, - { - :params => { - :order => 50, - :packages => 'apache', - :priority => '1' - }, - :content => "Explanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n" - }, - { - :params => { - :ensure => 'absent', - :packages => 'apache', - :priority => '1' - }, - :content => "Explanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n" - }, - { - :params => { - :packages => 'apache', - :priority => '1', - :release => 'my_newpin' - }, - :content => "Explanation: : my_pin\nPackage: apache\nPin: release a=my_newpin\nPin-Priority: 1\n" - }, - { - :params => { - :packages => 'apache', - :priority => '1', - :version => '2.2.16*' - }, - :content => "Explanation: : my_pin\nPackage: apache\nPin: version 2.2.16*\nPin-Priority: 1\n" - }, - { - :params => { - :priority => '1', - :origin => 'ftp.de.debian.org' - }, - :content => "Explanation: : my_pin\nPackage: *\nPin: origin ftp.de.debian.org\nPin-Priority: 1\n" - }, - { - :params => { - :packages => 'apache', - :priority => '1', - :release => 'stable', - :codename => 'wheezy', - :release_version => '3.0', - :component => 'main', - :originator => 'Debian', - :label => 'Debian' - }, - :content => "Explanation: : my_pin\nPackage: apache\nPin: release a=stable, n=wheezy, v=3.0, c=main, o=Debian, l=Debian\nPin-Priority: 1\n" - }, - { - :params => { - :packages => ['apache', 'ntop'], - }, - :content => "Explanation: : my_pin\nPackage: apache ntop\nPin: release a=my_pin\nPin-Priority: 0\n" - }, - ].each do |param_set| - describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do - let :param_hash do - default_params.merge(param_set[:params]) - end + context 'set version' do + let :params do + { + 'packages' => 'vim', + 'version' => '1', + } + end + it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n/)} + it { is_expected.to contain_file("my_pin.pref").with({ + 'ensure' => 'present', + 'path' => '/etc/apt/preferences.d/my_pin.pref', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + }) + } + end - let :params do - param_set[:params] - end + context 'set origin' do + let :params do + { + 'packages' => 'vim', + 'origin' => 'test', + } + end + it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n/)} + it { is_expected.to contain_file("my_pin.pref").with({ + 'ensure' => 'present', + 'path' => '/etc/apt/preferences.d/my_pin.pref', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + }) + } + end - it { should contain_class("apt::params") } + context 'not defaults' do + let :params do + { + 'explanation' => 'foo', + 'order' => 99, + 'release' => '1', + 'codename' => 'bar', + 'release_version' => '2', + 'component' => 'baz', + 'originator' => 'foobar', + 'label' => 'foobaz', + 'priority' => 10, + } + end + it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: foo\nPackage: \*\nPin: release a=1, n=bar, v=2, c=baz, o=foobar, l=foobaz\nPin-Priority: 10\n/) } + it { is_expected.to contain_file("my_pin.pref").with({ + 'ensure' => 'present', + 'path' => '/etc/apt/preferences.d/99-my_pin.pref', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + }) + } + end - it { should contain_file("#{title}.pref").with({ - 'ensure' => param_hash[:ensure], - 'path' => "/etc/apt/preferences.d/#{param_hash[:order] == '' ? "" : "#{param_hash[:order]}-"}#{title}.pref", - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - 'content' => param_set[:content], - }) + context 'ensure absent' do + let :params do + { + 'ensure' => 'absent' } end + it { is_expected.to contain_file("my_pin.pref").with({ + 'ensure' => 'absent', + }) + } + end + + context 'bad characters' do + let(:title) { 'such bad && wow!' } + it { is_expected.to contain_file("such__bad____wow_.pref") } end - describe 'resource title with invalid chars' do - context 'spaces' do - let(:title) { 'oh my god this is not valid' } - it { should contain_file('oh_my_god_this_is_not_valid.pref') } + describe 'validation' do + context 'invalid order' do + let :params do + { + 'order' => 'foo', + } + end + it do + expect { + should compile + }.to raise_error(Puppet::Error, /Only integers are allowed/) + end + end + + context 'packages == * and version' do + let :params do + { + 'version' => '1', + } + end + it do + expect { + should compile + }.to raise_error(Puppet::Error, /parameter version cannot be used in general form/) + end end - context '#$&*$' do - let(:title) { 'so && many $* invalid @! things' } - it { should contain_file('so____many____invalid____things.pref') } + context 'packages == * and release and origin' do + let :params do + { + 'origin' => 'test', + 'release' => 'foo', + } + end + it do + expect { + should compile + }.to raise_error(Puppet::Error, /parameters release and origin are mutually exclusive/) + end + end + + context 'specific form with release and origin' do + let :params do + { + 'release' => 'foo', + 'origin' => 'test', + 'packages' => 'vim', + } + end + it do + expect { + should compile + }.to raise_error(Puppet::Error, /parameters release, origin, and version are mutually exclusive/) + end + end + + context 'specific form with version and origin' do + let :params do + { + 'version' => '1', + 'origin' => 'test', + 'packages' => 'vim', + } + end + it do + expect { + should compile + }.to raise_error(Puppet::Error, /parameters release, origin, and version are mutually exclusive/) + end end end end diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb index 6944f9b..3a4c381 100644 --- a/spec/defines/ppa_spec.rb +++ b/spec/defines/ppa_spec.rb @@ -1,158 +1,163 @@ require 'spec_helper' describe 'apt::ppa', :type => :define do - [ - { - :lsbdistrelease => '11.04', - :lsbdistcodename => 'natty', - :operatingsystem => 'Ubuntu', - :lsbdistid => 'Ubuntu', - :package => 'python-software-properties' - }, - { - :lsbdistrelease => '12.10', - :lsbdistcodename => 'quantal', - :operatingsystem => 'Ubuntu', - :lsbdistid => 'Ubuntu', - :package => 'software-properties-common' - }, - ].each do |platform| - context "on #{platform[:lsbdistcodename]}" do - let :facts do - { - :lsbdistrelease => platform[:lsbdistrelease], - :lsbdistcodename => platform[:lsbdistcodename], - :operatingsystem => platform[:operatingsystem], - :lsbdistid => platform[:lsbdistid], - :osfamily => 'Debian', - } - end - let :release do - "#{platform[:lsbdistcodename]}" - end - let :package do - "#{platform[:package]}" - end - let :options do - "-y" - end - ['ppa:dans_ppa', 'dans_ppa','ppa:dans-daily/ubuntu'].each do |t| - describe "with title #{t}" do - let :pre_condition do - 'class { "apt": }' - end - let :title do - t - end - let :filename do - t.sub(/^ppa:/,'').gsub('/','-') << "-" << "#{release}.list" - end - - it { should contain_package("#{package}") } - it { should contain_exec("apt_update").with( - 'command' => '/usr/bin/apt-get update', - 'refreshonly' => true - ) - } + describe 'defaults' do + let :pre_condition do + 'class { "apt": }' + end + let :facts do + { + :lsbdistrelease => '11.04', + :lsbdistcodename => 'natty', + :operatingsystem => 'Ubuntu', + :osfamily => 'Debian', + :lsbdistid => 'Ubuntu', + } + end - it { should contain_exec("add-apt-repository-#{t}").with( - 'command' => "/usr/bin/add-apt-repository #{options} #{t}", - 'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}", - 'require' => ["File[sources.list.d]", "Package[#{package}]"], - 'notify' => "Exec[apt_update]" - ) - } + let(:title) { 'ppa:needs/such.substitution/wow' } + it { is_expected.to contain_package('python-software-properties') } + it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Exec[apt_update]').with({ + 'environment' => [], + 'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow', + 'unless' => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list', + 'user' => 'root', + 'logoutput' => 'on_failure', + }) + } - it { should create_file("/etc/apt/sources.list.d/#{filename}").with( - 'ensure' => 'file', - 'require' => "Exec[add-apt-repository-#{t}]" - ) - } - end - end - describe 'without a proxy defined' do - let :title do - 'rspec_ppa' - end - let :pre_condition do - 'class { "apt": - proxy_host => false - }' - end - let :filename do - "#{title}-#{release}.list" - end + it { is_expected.to contain_file('/etc/apt/sources.list.d/needs-such_substitution-wow-natty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with({ + 'ensure' => 'file', + }) + } + end - it { should contain_exec("add-apt-repository-#{title}").with( - 'environment' => [], - 'command' => "/usr/bin/add-apt-repository #{options} #{title}", - 'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}", - 'require' => ["File[sources.list.d]", "Package[#{package}]"], - 'notify' => "Exec[apt_update]" - ) - } - end + describe 'apt included, no proxy' do + let :pre_condition do + 'class { "apt": }' + end + let :facts do + { + :lsbdistrelease => '14.04', + :lsbdistcodename => 'trusty', + :operatingsystem => 'Ubuntu', + :lsbdistid => 'Ubuntu', + :osfamily => 'Debian', + } + end + let :params do + { + 'options' => '', + } + end + let(:title) { 'ppa:foo' } + it { is_expected.to contain_package('software-properties-common') } + it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({ + 'environment' => [], + 'command' => '/usr/bin/add-apt-repository ppa:foo', + 'unless' => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list', + 'user' => 'root', + 'logoutput' => 'on_failure', + }) + } - describe 'behind a proxy' do - let :title do - 'rspec_ppa' - end - let :pre_condition do - 'class { "apt": - proxy_host => "user:pass@proxy", - }' - end - let :filename do - "#{title}-#{release}.list" - end + it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_requires('Exec[add-apt-repository-ppa:foo]').with({ + 'ensure' => 'file', + }) + } + end - it { should contain_exec("add-apt-repository-#{title}").with( - 'environment' => [ - "http_proxy=http://user:pass@proxy:8080", - "https_proxy=http://user:pass@proxy:8080", - ], - 'command' => "/usr/bin/add-apt-repository #{options} #{title}", - 'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}", - 'require' => ["File[sources.list.d]", "Package[#{package}]"], - 'notify' => "Exec[apt_update]" - ) - } - end + describe 'apt included, proxy' do + let :pre_condition do + 'class { "apt": proxy_host => "example.com" }' end + let :facts do + { + :lsbdistrelease => '14.04', + :lsbdistcodename => 'trusty', + :operatingsystem => 'Ubuntu', + :lsbdistid => 'Ubuntu', + :osfamily => 'Debian', + } + end + let :params do + { + 'release' => 'lucid', + } + end + let(:title) { 'ppa:foo' } + it { is_expected.to contain_package('software-properties-common') } + it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({ + 'environment' => ['http_proxy=http://example.com:8080', 'https_proxy=http://example.com:8080'], + 'command' => '/usr/bin/add-apt-repository -y ppa:foo', + 'unless' => '/usr/bin/test -s /etc/apt/sources.list.d/foo-lucid.list', + 'user' => 'root', + 'logoutput' => 'on_failure', + }) + } + + it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-lucid.list').that_requires('Exec[add-apt-repository-ppa:foo]').with({ + 'ensure' => 'file', + }) + } end - [ { :lsbdistcodename => 'natty', - :package => 'python-software-properties' }, - { :lsbdistcodename => 'quantal', - :package => 'software-properties-common'}, - ].each do |platform| - context "on #{platform[:lsbdistcodename]}" do - describe "it should not error if package['#{platform[:package]}'] is already defined" do - let :pre_condition do - 'class {"apt": }' + - 'package { "#{platform[:package]}": }->Apt::Ppa["ppa"]' - end - let :facts do - {:lsbdistcodename => '#{platform[:lsbdistcodename]}', - :operatingsystem => 'Ubuntu', - :lsbdistid => 'Ubuntu', - :osfamily => 'Debian'} - end - let(:title) { "ppa" } - let(:release) { "#{platform[:lsbdistcodename]}" } - it { should contain_package('#{platform[:package]}') } - end + describe 'ensure absent' do + let :facts do + { + :lsbdistrelease => '14.04', + :lsbdistcodename => 'trusty', + :operatingsystem => 'Ubuntu', + :lsbdistid => 'Ubuntu', + :osfamily => 'Debian', + } + end + let(:title) { 'ppa:foo' } + let :params do + { + 'ensure' => 'absent' + } end + it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_notifies('Exec[apt_update]').with({ + 'ensure' => 'absent', + }) + } end - describe "without Class[apt] should raise a Puppet::Error" do - let(:release) { "natty" } - let(:title) { "ppa" } - it { expect { should contain_apt__ppa(title) }.to raise_error(Puppet::Error) } - end + context 'validation' do + describe 'no release' do + let :facts do + { + :lsbdistrelease => '14.04', + :operatingsystem => 'Ubuntu', + :lsbdistid => 'Ubuntu', + :osfamily => 'Debian', + } + end + let(:title) { 'ppa:foo' } + it do + expect { + should compile + }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/) + end + end - describe "without release should raise a Puppet::Error" do - let(:title) { "ppa:" } - it { expect { should contain_apt__ppa(:release) }.to raise_error(Puppet::Error) } + describe 'not ubuntu' do + let :facts do + { + :lsbdistrelease => '14.04', + :lsbdistcodename => 'trusty', + :operatingsystem => 'Debian', + :lsbdistid => 'Ubuntu', + :osfamily => 'Debian', + } + end + let(:title) { 'ppa:foo' } + it do + expect { + should compile + }.to raise_error(Puppet::Error, /apt::ppa is currently supported on Ubuntu only./) + end + end end end diff --git a/spec/defines/source_spec.rb b/spec/defines/source_spec.rb index 7c7ae39..8327ed2 100644 --- a/spec/defines/source_spec.rb +++ b/spec/defines/source_spec.rb @@ -1,177 +1,131 @@ require 'spec_helper' describe 'apt::source', :type => :define do - let(:facts) { { :lsbdistid => 'Debian' } } GPG_KEY_ID = '4BD6EC30' let :title do 'my_source' end - let :default_params do - { - :ensure => 'present', - :location => '', - :release => 'karmic', - :repos => 'main', - :include_src => true, - :required_packages => false, - :key => false, - :key_server => false, - :key_content => false, - :key_source => false, - :pin => false - } - end + context 'mostly defaults' do + let :facts do + { + :lsbdistid => 'Debian', + :lsbdistcodename => 'wheezy', + :osfamily => 'Debian' + } + end - [{}, - { - :location => 'http://example.com', - :release => 'precise', - :repos => 'security', - :include_src => false, - :required_packages => 'apache', - :key => GPG_KEY_ID, - :key_server => 'keyserver.debian.com', - :pin => '600', - :key_content => 'ABCD1234' - }, - { - :key => GPG_KEY_ID, - :key_server => 'keyserver.debian.com', - }, - { - :ensure => 'absent', - :location => 'http://example.com', - :release => 'precise', - :repos => 'security', - }, - { - :release => '', - }, - { - :release => 'custom', - }, - { - :architecture => 'amd64', - } - ].each do |param_set| - describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do - let :param_hash do - default_params.merge(param_set) - end + let :params do + { + 'include_deb' => false, + } + end - let :facts do - {:lsbdistcodename => 'karmic', :lsbdistid => 'Ubuntu'} - end + it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({ + 'ensure' => 'present', + 'path' => '/etc/apt/sources.list.d/my_source.list', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + }).with_content(/#file generated by puppet\n# my_source\ndeb-src wheezy main\n/) + } + end - let :params do - param_set - end + context 'no defaults' do + let :facts do + { + :lsbdistid => 'Debian', + :lsbdistcodename => 'wheezy', + :osfamily => 'Debian' + } + end + let :params do + { + 'comment' => 'foo', + 'location' => 'http://debian.mirror.iweb.ca/debian/', + 'release' => 'sid', + 'repos' => 'testing', + 'include_src' => false, + 'required_packages' => 'vim', + 'key' => GPG_KEY_ID, + 'key_server' => 'pgp.mit.edu', + 'key_content' => 'GPG key content', + 'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg', + 'pin' => '10', + 'architecture' => 'x86_64', + } + end - let :filename do - "/etc/apt/sources.list.d/#{title}.list" - end + it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({ + 'ensure' => 'present', + 'path' => '/etc/apt/sources.list.d/my_source.list', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + }).with_content(/#file generated by puppet\n# foo\ndeb \[arch=x86_64\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/) + } - let :content do - content = "#file generated by puppet\n" - if param_hash[:comment] - content << "# #{comment}" - else - content << "# #{title}" - end - if param_hash[:architecture] - arch = "[arch=#{param_hash[:architecture]}] " - end - content << "\ndeb #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n" + it { is_expected.to contain_apt__pin('my_source').that_comes_before('File[my_source.list]').with({ + 'ensure' => 'present', + 'priority' => '10', + 'origin' => 'debian.mirror.iweb.ca', + }) + } - if param_hash[:include_src] - content << "deb-src #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n" - end - content - end + it { is_expected.to contain_exec("Required packages: 'vim' for my_source").that_comes_before('Exec[apt_update]').that_subscribes_to('File[my_source.list]').with({ + 'command' => '/usr/bin/apt-get -y install vim', + 'logoutput' => 'on_failure', + 'refreshonly' => true, + 'tries' => '3', + 'try_sleep' => '1', + }) + } - it { should contain_apt__params } + it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('File[my_source.list]').with({ + 'ensure' => 'present', + 'key' => GPG_KEY_ID, + 'key_server' => 'pgp.mit.edu', + 'key_content' => 'GPG key content', + 'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg', + }) + } + end - it { should contain_file("#{title}.list").with({ - 'ensure' => param_hash[:ensure], - 'path' => filename, - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - 'content' => content, - }) + context 'ensure => absent' do + let :facts do + { + :lsbdistid => 'Debian', + :lsbdistcodename => 'wheezy', + :osfamily => 'Debian' } - - it { - if param_hash[:pin] - should contain_apt__pin(title).with({ - "priority" => param_hash[:pin], - "before" => "File[#{title}.list]" - }) - else - should_not contain_apt__pin(title).with({ - "priority" => param_hash[:pin], - "before" => "File[#{title}.list]" - }) - end + end + let :params do + { + 'ensure' => 'absent', } + end - it { - should contain_exec("apt_update").with({ - "command" => "/usr/bin/apt-get update", - "refreshonly" => true - }) - } + it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({ + 'ensure' => 'absent' + }) + } + end - it { - if param_hash[:required_packages] - should contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({ - "command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}", - "subscribe" => "File[#{title}.list]", - "refreshonly" => true, - "before" => 'Exec[apt_update]', - }) - else - should_not contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({ - "command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}", - "subscribe" => "File[#{title}.list]", - "refreshonly" => true - }) - end - } + describe 'validation' do + context 'no release' do + let :facts do + { + :lsbdistid => 'Debian', + :osfamily => 'Debian' + } + end - it { - key_server = param_hash[:key_server] || nil - key_content = param_hash[:key_content] || nil - key_source = param_hash[:key_source] || nil - if param_hash[:key] - should contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({ - "key" => param_hash[:key], - "ensure" => :present, - "key_server" => key_server, - "key_content" => key_content, - "key_source" => key_source, - "before" => "File[#{title}.list]" - }) - else - should_not contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({ - "key" => param_hash[:key], - "ensure" => :present, - "key_server" => param_hash[:key_server], - "key_content" => param_hash[:key_content], - "key_source" => param_hash[:key_source], - "before" => "File[#{title}.list]" - }) - end - } + it do + expect { + should compile + }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/) + end end end - describe "without release should raise a Puppet::Error" do - let(:default_params) { Hash.new } - let(:facts) { Hash.new } - it { expect { should raise_error(Puppet::Error) } } - let(:facts) { { :lsbdistcodename => 'lucid', :lsbdistid => 'Ubuntu' } } - it { should contain_apt__source(title) } - end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 3352564..fd1f2c5 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -2,13 +2,14 @@ require 'beaker-rspec' # Install Puppet unless ENV['RS_PROVISION'] == 'no' + # This will install the latest available package on el and deb based + # systems fail on windows and osx, and install via gem on other *nixes + foss_opts = { :default_action => 'gem_install' } + + if default.is_pe?; then install_pe; else install_puppet( foss_opts ); end + hosts.each do |host| - if host.is_pe? - install_pe - else - install_puppet - on host, "mkdir -p #{host['distmoduledir']}" - end + on host, "mkdir -p #{host['distmoduledir']}" end end @@ -26,7 +27,7 @@ RSpec.configure do |c| # Install module and dependencies puppet_module_install(:source => proj_root, :module_name => 'apt') hosts.each do |host| - shell('/bin/touch /etc/puppet/hiera.yaml') + shell("/bin/touch #{default['puppetpath']}/hiera.yaml") shell('puppet module install puppetlabs-stdlib --version 2.2.1', { :acceptable_exit_codes => [0,1] }) end end diff --git a/spec/unit/facter/apt_update_last_success_spec.rb b/spec/unit/facter/apt_update_last_success_spec.rb new file mode 100644 index 0000000..08774cd --- /dev/null +++ b/spec/unit/facter/apt_update_last_success_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe 'apt_update_last_success fact' do + subject { Facter.fact(:apt_update_last_success).value } + after(:each) { Facter.clear } + + describe 'on Debian based distro which has not yet created the update-success-stamp file' do + before { + Facter.fact(:osfamily).stubs(:value).returns 'Debian' + File.stubs(:exists?).returns false + } + it 'should have a value of -1' do + should == -1 + end + end + + describe 'on Debian based distro which has created the update-success-stamp' do + before { + Facter.fact(:osfamily).stubs(:value).returns 'Debian' + File.stubs(:exists?).returns true + File.stubs(:mtime).returns 1407660561 + } + it 'should have the value of the mtime of the file' do + should == 1407660561 + end + end + +end diff --git a/spec/unit/puppet/type/apt_key_spec.rb b/spec/unit/puppet/type/apt_key_spec.rb index c29f82b..e661ba1 100644 --- a/spec/unit/puppet/type/apt_key_spec.rb +++ b/spec/unit/puppet/type/apt_key_spec.rb @@ -41,7 +41,7 @@ describe Puppet::Type::type(:apt_key) do :id => 'FFFFFFFF4BD6EC30' )} it 'id is set' do - resource[:id].should eq '4BD6EC30' + resource[:id].should eq 'FFFFFFFF4BD6EC30' end end @@ -68,7 +68,7 @@ describe Puppet::Type::type(:apt_key) do :id => '0xFFFFFFFF4BD6EC30' )} it 'id is set' do - resource[:id].should eq '4BD6EC30' + resource[:id].should eq 'FFFFFFFF4BD6EC30' end end diff --git a/templates/10periodic.erb b/templates/10periodic.erb index 5737c9a..43caed9 100644 --- a/templates/10periodic.erb +++ b/templates/10periodic.erb @@ -10,3 +10,6 @@ APT::Periodic::Download-Upgradeable-Packages-Debdelta "<%= @download_delta %>"; APT::Periodic::Unattended-Upgrade "<%= @upgrade %>"; APT::Periodic::AutocleanInterval "<%= @autoclean %>"; APT::Periodic::Verbose "<%= @verbose %>"; +<%- unless @randomsleep.nil? -%> +APT::Periodic::RandomSleep "<%= @randomsleep %>"; +<%- end -%> diff --git a/templates/source.list.erb b/templates/source.list.erb index a57244f..01b2176 100644 --- a/templates/source.list.erb +++ b/templates/source.list.erb @@ -1,6 +1,8 @@ #file generated by puppet # <%= @comment %> +<%- if @include_deb then -%> deb <% if @architecture %>[arch=<%= @architecture %>] <% end %><%= @location %> <%= @release_real %> <%= @repos %> +<%- end -%> <%- if @include_src then -%> deb-src <% if @architecture %>[arch=<%= @architecture %>] <% end %><%= @location %> <%= @release_real %> <%= @repos %> <%- end -%>