Merge pull request #377 from mhaskel/1.7.x-merge
authorColleen Murphy <cmurphy@users.noreply.github.com>
Mon, 27 Oct 2014 15:54:24 +0000 (08:54 -0700)
committerColleen Murphy <cmurphy@users.noreply.github.com>
Mon, 27 Oct 2014 15:54:24 +0000 (08:54 -0700)
Merge master back into 1.7.x

19 files changed:
README.md
lib/facter/apt_package_updates.rb [deleted file]
lib/facter/apt_security_updates.rb [deleted file]
lib/facter/apt_updates.rb
lib/puppet/provider/apt_key/apt_key.rb
lib/puppet/type/apt_key.rb
manifests/unattended_upgrades.pp
manifests/update.pp
metadata.json
spec/acceptance/apt_key_provider_spec.rb
spec/acceptance/apt_spec.rb
spec/classes/unattended_upgrades_spec.rb
spec/spec_helper_acceptance.rb
spec/unit/facter/apt_has_updates_spec.rb [new file with mode: 0644]
spec/unit/facter/apt_package_updates_spec.rb
spec/unit/facter/apt_security_updates_spec.rb
spec/unit/facter/apt_updates_spec.rb
spec/unit/puppet/type/apt_key_spec.rb
templates/10periodic.erb

index b0574a7aa0a138adbb9b536c79a0ef13f828fd37..991e961dcf2bb7ba17c5f17918b9937418ee81db 100644 (file)
--- a/README.md
+++ b/README.md
-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
 
 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 by opening 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
-
-To begin using the apt module with default parameters, declare the class.
-
-    include apt
-
-Puppet code that uses anything from the apt module requires that the core apt class be declared.
-
-Usage
------
-
-Using the apt module consists predominantly of declaring classes that provide the desired functionality and features.
-
-### apt
-
-`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.
-
-The parameters for `apt` are not generally required and are predominantly for development environment use cases.
-
-    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
-    }
-
-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.
-The cfg_files parameter controls wether newer or older configuration files should be used or only unchanged configuration files should be updated. Cfg_missing forces the provider to install all missing configuration files. Both are optional.
-
-    apt::force { 'glusterfs-server':
-      release     => 'unstable',
-      version     => '3.0.3',
-      cfg_files   => 'unchanged',
-      cfg_missing => true,
-      require     => Apt::Source['debian_unstable'],
-    }
-
-You can additionally set the following attributes:
-
- * `cfg_files`: "new", "old", "unchanged" or "none" (default). "new" will overwrite all existing configuration files with newer ones, "old" will force usage of all old files and "unchanged" only updates unchanged config files whereas setting "none" will don't do anything but providing backward-compatability with existing puppet manifests.
- * `cfg_missing`: "true" or "false". Setting cfg_missing to false will provide backward compatability whereas setting true will add an aptitude/apt-get parameter which checks and installs missing configuration files for the selected package.
-
-### apt_key
+**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'.
 
-A native Puppet type and provider for managing GPG keys for APT is provided by this module.
+### Beginning with apt
 
-    apt_key { 'puppetlabs':
-      ensure => 'present',
-      id     => '1054B7A24BD6EC30',
-    }
+To begin using the apt module with default parameters, declare the class with `include apt`.
 
-You can additionally set the following attributes:
+Any Puppet code that uses anything from the apt module requires that the core apt class be declared.
 
- * `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`.
+## Usage
 
-Because apt_key is a native type, it can be used in and queried for with MCollective.
+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::key
+```
+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
+}
+```
 
-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.
+## Reference
 
-    apt::key { 'puppetlabs':
-      key        => '1054B7A24BD6EC30',
-      key_server => 'pgp.mit.edu',
-    }
+### Classes
 
-    apt::key { 'jenkins':
-      key        => '9B7D32F2D50582E6',
-      key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key',
-    }
+* `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
+  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.
 
-Adds an apt pin for a certain release.
+  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 { 'karmic': priority => 700 }
-    apt::pin { 'karmic-updates': priority => 700 }
-    apt::pin { 'karmic-security': priority => 700 }
+  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.
 
-Note you can also specifying more complex pins using distribution properties.
+* `apt::params`: Sets defaults for the apt module parameters.
 
-    apt::pin { 'stable':
-      priority        => -10,
-      originator      => 'Debian',
-      release_version => '3.0',
-      component       => 'main',
-      label           => 'Debian'
-    }
+* `apt::release`: Sets the default Apt release. This class is particularly useful when using repositories that are unstable in Ubuntu, such as 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.
+  ```
+  class { 'apt::release':
+    release_id => 'precise',
+  }
+  ```  
 
-### apt::hold
+* `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.
 
-When you wish to hold a package in Puppet, it 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::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.
 
-Moreover, when Puppet is told to hold a package, it holds it at the current version installed; there is no way to tell it to both install a specific version **and** hold that version, unless you use an exec resource that wraps `dpkg --set-selections` or `apt-mark`.
+### Types
 
-At first glance, it seems this issue could also be solved by passing the version required to the ensure attribute---but that only means that Puppet will install that
-version after it processes the package. It does not inform apt that we want
-this package to be held; that is, should another package want to upgrade this one (because of a version requirement in a dependency, for example), we want apt to refuse.
+* `apt_key`
 
-To solve this issue, use apt::hold. Implement this by creating a preferences file with a priority of 1001. Under normal circumstances, this preference will always win. Because the priority is > 1000, apt will maintain the required version, downgrading the current package if necessary.
+  A native Puppet type and provider for managing GPG keys for Apt is provided by this module.
 
-With this, you can now set a package's ensure attribute to 'latest' but get the version specified by apt::hold:
+  ```
+  apt_key { 'puppetlabs':
+    ensure => 'present',
+    id     => '1054B7A24BD6EC30',
+  }
+  ```
 
-    apt::hold { 'vim':
-      version => '2:7.3.547-7',
-    }
+  You can additionally set the following attributes:
 
-Alternatively, if you want to hold Vim at version 7.3.*, you can pass in a version with a glob:
+   * `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::hold { 'vim':
-      version => '2:7.3.*',
-    }
-
-### apt::ppa
+  Because apt_key is a native type, you can use it and query for it with MCollective. 
 
-Adds a ppa repository using `add-apt-repository`.
+### Defined Types
 
-    apt::ppa { 'ppa:drizzle-developers/ppa': }
+* `apt::builddep`: Installs the build dependencies of a specified package.
 
-### apt::release
+  `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.
 
-Sets the default apt release. This class is particularly useful when using repositories, like Debian, that are unstable in Ubuntu.
+* `apt::hold`: Holds a specific version of a package. You can hold a package to a full version or a partial version.
 
-    class { 'apt::release':
-      release_id => 'precise',
-    }
-
-### apt::source
-
-Adds an apt source to `/etc/apt/sources.list.d/`.
-
-    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
-    }
+  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        => '1054B7A24BD6EC30',
-      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',
     }
-
-### 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---this should happen when config files get updated or other relevant changes occur. If you set the `always_apt_update` parameter, the update will run on every Puppet run.
+  ```
 
 ### Facts
 
-There are a few facts included in 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 that `apt-get update` last ran successfully. This is determined by reading the mtime of the file `/var/lib/apt/periodic/update-success-stamp`. That file is generated by the `/etc/apt/apt.conf.d/15update-stamp` file.
+* `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.
+
+**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
+
+```
 <pre>
 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: '9AA38DCD55BE302B'
-      key_server: 'subkeys.pgp.net'
-      pin: '-10'
-      include_src: 'true'
-      include_deb: '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: '1054B7A24BD6EC30'
-      key_server: 'pgp.mit.edu'
+    location: 'http://apt.puppetlabs.com'
+    repos: 'main'
+    key: '1054B7A24BD6EC30'
+    key_server: 'pgp.mit.edu'
 </pre>
+```
+
+### 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 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.
+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, 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:
+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:
 
-    apt::source { 'puppetlabs':
-      location   => 'http://apt.puppetlabs.com',
-      repos      => 'main',
-      key        => '1054B7A24BD6EC30',
-      key_server => 'pgp.mit.edu',
-    }
+```
+apt::source { 'puppetlabs':
+  location   => 'http://apt.puppetlabs.com',
+  repos      => 'main',
+  key        => '1054B7A24BD6EC30',
+  key_server => 'pgp.mit.edu',
+}
+```    
 
-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.
+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.
 
 Check your smoke test for syntax errors:
 
-    $ puppet parser validate tests/puppetlabs-apt.pp
+`$ puppet parser validate tests/puppetlabs-apt.pp`
 
 If you receive no output from that command, it means nothing is wrong. Then, apply the code:
 
-    $ 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>
-
-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.
-
-Implementation
---------------
-
-### apt::backports
-
-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).
-
-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.
+```
+$ 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
 ------------
diff --git a/lib/facter/apt_package_updates.rb b/lib/facter/apt_package_updates.rb
deleted file mode 100644 (file)
index 97c75c6..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-Facter.add("apt_package_updates") do
-  confine :osfamily => 'Debian'
-  setcode do
-    if File.executable?("/usr/lib/update-notifier/apt-check")
-      packages = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check -p 2>&1')
-      packages = packages.split("\n")
-      if Facter.version < '2.0.0'
-        packages = packages.join(',')
-      end
-      packages
-    end
-  end
-end
diff --git a/lib/facter/apt_security_updates.rb b/lib/facter/apt_security_updates.rb
deleted file mode 100644 (file)
index 19bae75..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-Facter.add("apt_security_updates") do
-  confine :osfamily => 'Debian'
-  setcode do
-    if File.executable?("/usr/lib/update-notifier/apt-check")
-      updates = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check 2>&1')
-      Integer(updates.strip.split(';')[1])
-    end
-  end
-end
index ee177380c231939a12f0d22fd33dbacd4acd3f0c..77e667e6d76c18f8f2eed5adc3b2dad187035c32 100644 (file)
@@ -1,9 +1,37 @@
-Facter.add("apt_updates") do
+apt_package_updates = nil
+Facter.add("apt_has_updates") do
   confine :osfamily => 'Debian'
+  if File.executable?("/usr/lib/update-notifier/apt-check")
+    apt_package_updates = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check 2>/dev/null').split(';')
+  end
+
+  setcode do
+    apt_package_updates != ['0', '0'] unless apt_package_updates.nil?
+  end
+end
+
+Facter.add("apt_package_updates") do
+  confine :apt_has_updates => true
   setcode do
-    if File.executable?("/usr/lib/update-notifier/apt-check")
-      updates = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check 2>&1')
-      Integer(updates.strip.split(';')[0])
+    packages = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check -p 2>/dev/null').split("\n")
+    if Facter.version < '2.0.0'
+      packages.join(',')
+    else
+      packages
     end
   end
 end
+
+Facter.add("apt_updates") do
+  confine :apt_has_updates => true
+  setcode do
+    Integer(apt_package_updates[0])
+  end
+end
+
+Facter.add("apt_security_updates") do
+  confine :apt_has_updates => true
+  setcode do
+    Integer(apt_package_updates[1])
+  end
+end
index e5020fe27dd0647702dba262c62b2df3eaa28033..3ef94315089634cb75eb5f8cefa8886be20e09cc 100644 (file)
@@ -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
index e2cb8d9cf92695dded9d331b627dc7759abc9092..f55247314cc6f650bab39dd13735bcdda3b9dc3e 100644 (file)
@@ -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
 
index 2f75d5dd19aef4eba17a96bfbf80cd6ba3b163a1..069c3593dd627ebd6207f595e5633540b248f021 100644 (file)
@@ -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,6 +49,12 @@ class apt::unattended_upgrades (
   )
   validate_array($origins)
 
+  if $randomsleep {
+    unless is_numeric($randomsleep) {
+      fail('randomsleep must be numeric')
+    }
+  }
+
   package { 'unattended-upgrades':
     ensure => present,
   }
index 9112c9b62668963187a8de7e619d62525199d9d7..d9b338d952a23bfef373dd987d151ef8a2467fab 100644 (file)
@@ -19,6 +19,8 @@ class apt::update {
         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
@@ -32,6 +34,8 @@ class apt::update {
         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
@@ -41,9 +45,13 @@ class apt::update {
       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 {
index f6ea55e160ae8d25ee515973185888eb5105addd..1403e1406dfc63e77cf1cb120b49d19a89f726ab 100644 (file)
@@ -27,7 +27,7 @@
   "requirements": [
     {
       "name": "pe",
-      "version_requirement": ">= 3.2.0 < 3.4.0"
+      "version_requirement": "3.x"
     },
     {
       "name": "puppet",
index 0f20174d062cde85336e4c5229f0708f56e5d672..3f2536c7f09819760b723da13535ab5abf4d6ff1 100644 (file)
@@ -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'
+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' do
           EOS
 
           apply_manifest(pp, :catch_failures => true)
-          apply_manifest(pp, :catch_failures => true)
+          apply_manifest(pp, :catch_changes => true)
           shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}")
         end
       end
@@ -59,6 +64,32 @@ describe 'apt_key' do
 
   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,7 +100,7 @@ describe 'apt_key' do
 
         # 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
index 3c97421ab0c1eded83c1f161544924d0cb552ed3..3011f9dfdec6a56aecd5837f738046ee68461f1d 100644 (file)
@@ -38,7 +38,7 @@ describe 'apt class' do
     end
     it 'should still work' do
       shell('apt-get update')
-      shell('apt-get -y upgrade')
+      shell('apt-get -y --force-yes upgrade')
     end
   end
 
index 291719b0098b66e986bfeb4cfee5b61cc6ff47bd..57df21cbdfa3a2750ab38d167cf20393fd919d08 100644 (file)
@@ -94,6 +94,14 @@ describe 'apt::unattended_upgrades', :type => :class do
       it { expect { should raise_error(Puppet::Error) } }
     end
 
+    context 'bad randomsleep' do
+      let :params do
+        {
+          'randomsleep' => '4ever'
+        }
+      end
+      it { expect { should raise_error(Puppet::Error) } }
+    end
   end
 
   context 'defaults' do
@@ -123,6 +131,7 @@ describe 'apt::unattended_upgrades', :type => :class do
     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
@@ -157,6 +166,7 @@ describe 'apt::unattended_upgrades', :type => :class do
         'remove_unused'       => false,
         'auto_reboot'         => true,
         'dl_limit'            => '70',
+        'randomsleep'         => '1799',
       }
     end
 
@@ -183,6 +193,7 @@ describe 'apt::unattended_upgrades', :type => :class do
     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";}}
 
   end
 end
index fd1f2c56b9c0167498523d675a46a1ec433dcdd4..a523bb8321eb13f2db3e8b792f879ea48b76ac9f 100644 (file)
@@ -25,8 +25,8 @@ RSpec.configure do |c|
   # Configure all nodes in nodeset
   c.before :suite do
     # Install module and dependencies
-    puppet_module_install(:source => proj_root, :module_name => 'apt')
     hosts.each do |host|
+      copy_module_to(host, :source => proj_root, :module_name => 'apt')
       shell("/bin/touch #{default['puppetpath']}/hiera.yaml")
       shell('puppet module install puppetlabs-stdlib --version 2.2.1', { :acceptable_exit_codes => [0,1] })
     end
diff --git a/spec/unit/facter/apt_has_updates_spec.rb b/spec/unit/facter/apt_has_updates_spec.rb
new file mode 100644 (file)
index 0000000..691fb32
--- /dev/null
@@ -0,0 +1,34 @@
+require 'spec_helper'
+
+describe 'apt_has_updates fact' do
+  subject { Facter.fact(:apt_has_updates).value }
+  after(:each) { Facter.clear }
+
+  describe 'on non-Debian distro' do
+    before {
+      Facter.fact(:osfamily).expects(:value).returns 'RedHat'
+    }
+    it { should be_nil }
+  end
+
+  describe 'on Debian based distro missing update-notifier-common' do
+    before {
+      Facter.fact(:osfamily).expects(:value).returns 'Debian'
+      File.stubs(:executable?) # Stub all other calls
+      File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns false
+    }
+    it { should be_nil }
+  end
+
+  describe 'on Debian based distro' do
+    before {
+      Facter.fact(:osfamily).expects(:value).returns 'Debian'
+      File.stubs(:executable?) # Stub all other calls
+      Facter::Util::Resolution.stubs(:exec) # Catch all other calls
+      File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true
+      Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>/dev/null').returns "4;3"
+    }
+    it { should be true }
+  end
+end
+
index dfa09270eb59d050a08812d4984846c040494efd..c0f54f23af80260a752240f598bfc069ce188377 100644 (file)
@@ -4,26 +4,28 @@ describe 'apt_package_updates fact' do
   subject { Facter.fact(:apt_package_updates).value }
   after(:each) { Facter.clear }
 
-  describe 'on Debian based distro missing update-notifier-common' do
+  describe 'when apt has no updates' do
     before { 
-    Facter.fact(:osfamily).stubs(:value).returns 'Debian'
-    File.stubs(:executable?).returns false
-  }
-  it { should == nil }
+      Facter.fact(:apt_has_updates).stubs(:value).returns false
+    }
+    it { should be nil }
   end
 
-  describe 'on Debian based distro' do
+  describe 'when apt has updates' do
     before { 
-    Facter.fact(:osfamily).stubs(:value).returns 'Debian'
-    File.stubs(:executable?).returns true
-    Facter::Util::Resolution.stubs(:exec).returns "puppet-common\nlinux-generic\nlinux-image-generic"
-  }
-  it {
-    if Facter.version < '2.0.0'
-      should == 'puppet-common,linux-generic,linux-image-generic'
-    else
-      should == ['puppet-common', 'linux-generic', 'linux-image-generic']
-    end
-  }
+      Facter.fact(:osfamily).stubs(:value).returns 'Debian'
+      File.stubs(:executable?) # Stub all other calls
+      Facter::Util::Resolution.stubs(:exec) # Catch all other calls
+      File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true
+      Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>/dev/null').returns "1;2"
+      Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check -p 2>/dev/null').returns "puppet-common\nlinux-generic\nlinux-image-generic"
+    }
+    it {
+      if Facter.version < '2.0.0'
+        should == 'puppet-common,linux-generic,linux-image-generic'
+      else
+        should == ['puppet-common', 'linux-generic', 'linux-image-generic']
+      end
+    }
   end
 end
index 999603b6124d410d76882b4f2771523752e1411e..a5d26c76cf7408dd1c2b24a827f566cb49aabdb0 100644 (file)
@@ -4,21 +4,22 @@ describe 'apt_security_updates fact' do
   subject { Facter.fact(:apt_security_updates).value }
   after(:each) { Facter.clear }
 
-  describe 'on Debian based distro missing update-notifier-common' do
+  describe 'when apt has no updates' do
     before { 
-    Facter.fact(:osfamily).stubs(:value).returns 'Debian'
-    File.stubs(:executable?).returns false
-  }
-  it { should == nil }
+      Facter.fact(:apt_has_updates).stubs(:value).returns false
+    }
+    it { should be nil }
   end
 
-  describe 'on Debian based distro' do
+  describe 'when apt has security updates' do
     before { 
-    Facter.fact(:osfamily).stubs(:value).returns 'Debian'
-    File.stubs(:executable?).returns true
-    Facter::Util::Resolution.stubs(:exec).returns '14;7'
-  }
-  it { should == 7 }
+      Facter.fact(:osfamily).stubs(:value).returns 'Debian'
+      File.stubs(:executable?) # Stub all other calls
+      Facter::Util::Resolution.stubs(:exec) # Catch all other calls
+      File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true
+      Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>/dev/null').returns "14;7"
+    }
+    it { should == 7 }
   end
 
 end
index 2f343bd8a10dc1bca214fc1acd6a9e30da913ce2..538466f999e628572501b285016f4ab0f2a1604f 100644 (file)
@@ -4,21 +4,22 @@ describe 'apt_updates fact' do
   subject { Facter.fact(:apt_updates).value }
   after(:each) { Facter.clear }
 
-  describe 'on Debian based distro missing update-notifier-common' do
+  describe 'when apt has no updates' do
     before { 
-    Facter.fact(:osfamily).stubs(:value).returns 'Debian'
-    File.stubs(:executable?).returns false
-  }
-  it { should == nil }
+      Facter.fact(:apt_has_updates).stubs(:value).returns false
+    }
+    it { should be nil }
   end
 
-  describe 'on Debian based distro' do
+  describe 'when apt has updates' do
     before { 
-    Facter.fact(:osfamily).stubs(:value).returns 'Debian'
-    File.stubs(:executable?).returns true
-    Facter::Util::Resolution.stubs(:exec).returns '14;7'
-  }
-  it { should == 14 }
+      Facter.fact(:osfamily).stubs(:value).returns 'Debian'
+      File.stubs(:executable?) # Stub all other calls
+      Facter::Util::Resolution.stubs(:exec) # Catch all other calls
+      File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true
+      Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>/dev/null').returns "14;7"
+    }
+    it { should == 14 }
   end
 
 end
index c29f82b08862529c3e328cde6734bca4cff3c927..e661ba1bdbb5ea8ee1a809a36ac70dbac48846e7 100644 (file)
@@ -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
 
index 5737c9ac29fc8b25405a7e618ce150532e8d453e..43caed9ea149841dbdbe8fd1cee051b770966dab 100644 (file)
@@ -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 -%>