diff --git a/.fixtures.yml b/.fixtures.yml index 2bb941de23..578437cb9f 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -2,6 +2,6 @@ fixtures: repositories: "stdlib": "repo": "git://github.com/puppetlabs/puppetlabs-stdlib.git" - "ref": "v2.2.1" + "ref": "4.5.0" symlinks: "apt": "#{source_dir}" diff --git a/.travis.yml b/.travis.yml index ec6f08dc6d..8b374e9bb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ --- language: ruby +sudo: false bundler_args: --without system_tests script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'" matrix: diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b2a45a5ca..06eb422d01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,84 @@ +##2015-04-07 - Supported Release 2.0.0 +###Summary + +This is a major rewrite of the apt module. Many classes and defines were removed, but all existing functionality should still work. Please carefully review documentation before upgrading. + +####Backwards-incompatible changes + +As this is a major rewrite of the module there are a great number of backwards incompatible changes. Please review this and the updated README carefully before upgrading. + +#####`apt_key` +- `keyserver_options` parameter renamed to `options` + +#####`apt::backports` +- This no longer works out of the box on Linux Mint. If using this on mint, you must specify the `location`, `release`, `repos`, and `key` parameters. [Example](examples/backports.pp) + +#####`apt::builddep` +- This define was removed. Functionality can be matched passing 'build-dep' to `install_options` in the package resource. [Example](examples/builddep.pp) + +#####`apt::debian::testing` +- This class was removed. Manually add an `apt::source` instead. [Example](examples/debian_testing.pp) + +#####`apt::debian::unstable` +- This class was removed. Manually add an `apt::source` instead. [Example](examples/debian_unstable.pp) + +#####`apt::force` +- This define was removed. Functionallity can be matched by setting `install_options` in the package resource. See [here](examples/force.pp) for how to set the options. + +#####`apt::hold` +- This define was removed. Simply use an `apt::pin` with `priority => 1001` for the same functionality. + +#####`apt` +- `always_apt_update` - This parameter was removed. Use `update => { 'frequency' => 'always' }` instead. +- `apt_update_frequency` - This parameter was removed. Use `update => { 'frequency' => }` instead. +- `disable_keys` - This parameter was removed. See this [example](examples/disable_keys.pp) if you need this functionality. +- `proxy_host` - This parameter was removed. Use `proxy => { 'host' => }` instead. +- `proxy_port` - This parameter was removed. Use `proxy => { 'port' => }` instead. +- `purge_sources_list` - This parameter was removed. Use `purge => { 'sources.list' => }` instead. +- `purge_sources_list_d` - This parameter was removed. Use `purge => { 'sources.list.d' => }` instead. +- `purge_preferences` - This parameter was removed. Use `purge => { 'preferences' => }` instead. +- `purge_preferences_d` - This parameter was removed. Use `purge => { 'preferences.d' => }` instead. +- `update_timeout` - This parameter was removed. Use `update => { 'timeout' => }` instead. +- `update_tries` - This parameter was removed. Use `update => { 'tries' => }` instead. + +#####`apt::key` +- `key` - This parameter was renamed to `id`. +- `key_content` - This parameter was renamed to `content`. +- `key_source` - This parameter was renamed to `source`. +- `key_server` - This parameter was renamed to `server`. +- `key_options` - This parameter was renamed to `options`. + +#####`apt::release` +- This class was removed. See this [example](examples/release.pp) for how to achieve this functionality. + +#####`apt::source` +- `include_src` - This parameter was removed. Use `include => { 'src' => }` instead. ***NOTE*** This now defaults to false. +- `include_deb` - This parameter was removed. Use `include => { 'deb' => }` instead. +- `required_packages` - This parameter was removed. Use package resources for these packages if needed. +- `key` - This can either be a key id or a hash including key options. If using a hash, `key => { 'id' => }` must be specified. +- `key_server` - This parameter was removed. Use `key => { 'server' => }` instead. +- `key_content` - This parameter was removed. Use `key => { 'content' => }` instead. +- `key_source` - This parameter was removed. Use `key => { 'source' => }` instead. +- `trusted_source` - This parameter was renamed to `allow_unsigned`. + +#####`apt::unattended_upgrades` +- This class was removed and is being republished under the puppet-community namespace. The git repository is available [here](https://github.com/puppet-community/puppet-unattended_upgrades) and it will be published to the forge [here](https://forge.puppetlabs.com/puppet/unattended_upgrades). + +####Changes to default behavior +- By default purge unmanaged files in 'sources.list', 'sources.list.d', 'preferences', and 'preferences.d'. +- Changed default for `package_manage` in `apt::ppa` to `false`. Set to `true` in a single PPA if you need the package to be managed. +- `apt::source` will no longer include the `src` entries by default. +- `pin` in `apt::source` now defaults to `undef` instead of `false` + +####Features +- Added the ability to pass hashes of `apt::key`s, `apt::ppa`s, and `apt::setting`s to `apt`. +- Added 'https' key to `proxy` hash to allow disabling `https_proxy` for the `apt::ppa` environment. +- Added `apt::setting` define to abstract away configuration. +- Added the ability to pass hashes to `pin` and `key` in `apt::backports` and `apt::source`. + +####Bugfixes +- Fixes for strict variables. + ##2015-03-17 - Supported Release 1.8.0 ###Summary diff --git a/README.md b/README.md index 3fd74b3d2c..9ae90e1d7d 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,6 @@ The apt module automates obtaining and installing software packages on \*nix sys * System repositories * Authentication keys -**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'. - ### Beginning with apt To begin using the apt module with default parameters, declare the class with `include apt`. @@ -31,58 +29,25 @@ Any Puppet code that uses anything from the apt module requires that the core ap 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. -``` -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 +class { 'apt': } ``` ## Reference ### Classes -* `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. - - 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`: Main class, provides common resources and options. Allows Puppet to manage your system's sources.list file and sources.list.d directory. By default, it will not purge 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. + * `apt::backports`: This class adds the necessary components to get backports for Ubuntu and Debian. The release name defaults to "$lsbdistcodename-backports". Setting this manually can cause undefined and potentially serious behavior. - 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. + 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. - 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. + If you raise the priority through the `pin` 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::params`: Sets defaults for the apt module parameters. -* `apt::release`: Sets the default Apt release. This class is particularly useful when using repositories that are unstable in Ubuntu, such as Debian. - - ``` - class { 'apt::release': - release_id => 'precise', - } - ``` - -* `apt::unattended_upgrades`: 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. - - ``` - class { 'apt::unattended_upgrades': - 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. +* `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 `update['frequency']` to `'always'`, the update runs on every Puppet run. ### Types @@ -90,7 +55,7 @@ class { 'apt': A native Puppet type and provider for managing GPG keys for Apt is provided by this module. - ``` + ```puppet apt_key { 'puppetlabs': ensure => 'present', id => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30', @@ -102,74 +67,29 @@ class { 'apt': * `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 apt_key is a native type, you can use it and query for it with MCollective. + * `options`: Additional options to pass to `apt-key`'s `--keyserver-options`. ### Defined Types -* `apt::builddep`: Installs the build dependencies of a specified package. - - `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. -* `apt::hold`: Holds a specific version of a package. You can hold a package to a full version or a partial version. - - To set a package's ensure attribute to 'latest' but get the version specified by `apt::hold`: - - ``` - 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'], - } - ``` - - 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 compatibility; 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`: 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. - - ``` + ```puppet apt::key { 'puppetlabs': - key => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30', - key_server => 'pgp.mit.edu', + id => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30', + server => 'pgp.mit.edu', } apt::key { 'jenkins': - key => '150FDE3F7787E7D11EF4E12A9B7D32F2D50582E6', - key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key', + id => '150FDE3F7787E7D11EF4E12A9B7D32F2D50582E6', + source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key', } ``` * `apt::pin`: Defined type that adds an Apt pin for a certain release. - ``` + ```puppet apt::pin { 'karmic': priority => 700 } apt::pin { 'karmic-updates': priority => 700 } apt::pin { 'karmic-security': priority => 700 } @@ -177,7 +97,7 @@ class { 'apt': Note that you can also specify more complex pins using distribution properties. - ``` + ```puppet apt::pin { 'stable': priority => -10, originator => 'Debian', @@ -191,147 +111,136 @@ class { 'apt': * `apt::ppa`: Adds a PPA repository using `add-apt-repository`. For example, `apt::ppa { 'ppa:drizzle-developers/ppa': }`. +* `apt::setting`: Defined type to abstract the creation of Apt configuration files. + * `apt::source`: Adds an Apt source to `/etc/apt/sources.list.d/`. For example: - ``` + ```puppet 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 => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', - key_server => 'subkeys.pgp.net', - pin => '-10', - include_src => true, - include_deb => true + comment => 'This is the iWeb Debian unstable mirror', + location => 'http://debian.mirror.iweb.ca/debian/', + release => 'unstable', + repos => 'main contrib non-free', + pin => '-10', + key => { + 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', + 'server' => 'subkeys.pgp.net', + }, + include => { + 'src' => true, + 'deb' => true, + }, } ``` For example, to configure your system so the source is the Puppet Labs Apt repository: - ``` + ```puppet apt::source { 'puppetlabs': - location => 'http://apt.puppetlabs.com', - repos => 'main dependencies', - key => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30', - key_server => 'pgp.mit.edu', - } + location => 'http://apt.puppetlabs.com', + repos => 'main', + key => { + 'id' => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30', + 'server' => 'pgp.mit.edu', + }, ``` ### Facts 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. 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 -``` -
+```yaml
 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'
+    key:
+      id: '9AA38DCD55BE302B'
+      server: 'subkeys.pgp.net'
     pin: '-10'
-    include_src: true
-    include_deb: true
+    include:
+      src: true
+      deb: true
 
   'puppetlabs':
     location: 'http://apt.puppetlabs.com'
-    repos: 'main dependencies'
-    key: '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'
-    key_server: 'pgp.mit.edu'
-
+ repos: 'main' + key: + id: '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30' + 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 - -* `legacy_origin`: If set to true, use the old `Unattended-Upgrade::Allowed-Origins` variable. If false, use `Unattended-Upgrade::Origins-Pattern`. OS-dependent defaults are defined in `apt::params`. -* `origins`: The repositories from which to automatically upgrade included packages. OS-dependent defaults are defined in `apt::params`. (Usually only security updates are enabled by default) -* `blacklist`: A list of packages to **not** automatically upgrade. This list is empty by default. -* `update`: How often, in days, to run `apt-get update`. Defaults to '1'. -* `download`: How often, in days, to run `apt-get upgrade --download-only`. Defaults to '1'. -* `upgrade`: How often, in days, to upgrade packages included in the origins list. Defaults to '1'. -* `autoclean`: How often, in days, to run `apt-get autoclean`. Defaults to '7'. -* `auto_fix`: Tries to automatically fix interrupted package installations. Defaults to 'true'. -* `minimal_steps`: Split the upgrade process into sections to allow shutdown during upgrade. Defaults to 'false'. -* `install_on_shutdown`: Install updates on shutdown instead of in the background. Defaults to 'false'. -* `mail_to`: Send e-mail to this address about packages upgrades or errors. This is not set by default. -* `mail_only_on_error`: Send e-mail only in case of error, not on successful upgrade. Defaults to 'false'. -* `remove_unused`: Removes unused dependencies. Defaults to 'true'. -* `auto_reboot`: Reboot the system **without confirmation** if an update requires rebooting. Defaults to 'false'. -* `dl_limit`: Use a bandwidth limit for downloading, specified in kb/sec. This is not set by default. -* `randomsleep`: How long, in seconds, to randomly wait before applying upgrades. This is not set by default. - -####apt::source - -* `comment`: Add a comment to the apt source file. -* `ensure`: Allows you to remove the apt source file. Can be 'present' or 'absent'. -* `location`: The URL of the apt repository. -* `release`: The distribution of the apt repository. Defaults to fact 'lsbdistcodename'. -* `repos`: The component of the apt repository. This defaults to 'main'. -* `include_deb`: References a Debian distribution's binary package. -* `include_src`: Enable the deb-src type, references a Debian distribution's source code in the same form as the include_deb type. A deb-src line is required to fetch source indexes. -* `required_packages`: install required packages via an exec. defaults to 'false'. -* `key`: See apt::key -* `key_server`: See apt::key -* `key_content`: See apt::key -* `key_source`: See apt::key -* `pin`: See apt::pin -* `architecture`: can be used to specify for which architectures information should be downloaded. If this option is not set all architectures defined by the APT::Architectures option will be downloaded. Defaults to 'undef' which means all. Example values can be 'i386' or 'i386,alpha,powerpc'. -* `trusted_source` can be set to indicate that packages from this source are always authenticated even if the Release file is not signed or the signature can't be checked. Defaults to false. Can be 'true' or 'false'. +####apt + +* `update`: Hash to configure various update settings. Valid keys are: + * 'frequency': 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. + * 'timeout': Overrides the exec timeout in seconds for `apt-get update`. Defaults to exec default (300). + * '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. +* `purge`: Hash to configure various purge settings. Valid keys are: + * 'sources.list': If set to 'true', Puppet purges all unmanaged entries from sources.list. Accepts `true` or `false`. Defaults to `false`. + * 'sources.list.d': If set to 'true', Puppet purges all unmanaged entries from sources.list.d. Accepts `true` or `false`. Defaults to `false`. + * 'preferences.list': If set to 'true', Puppet purges all unmanaged entries from preferences.list. Accepts `true` or `false`. Defaults to `false`. + * 'preferences.list.d': If set to 'true', Puppet purges all unmanaged entries from preferences.list.d. Accepts `true` or `false`. Defaults to `false`. +* `proxy`: Hash to configure various proxy settings. Valid keys are: + * 'host': Configures a proxy host and stores the configuration in /etc/apt/apt.conf.d/01proxy. + * 'port': Configures a proxy port and stores the configuration in /etc/apt/apt.conf.d/01proxy. + * 'https': Boolean to configure whether or not to enable https proxies. Defaults to false. +* `keys`: Passes a hash to `create\_resource` to make new `apt::key` resources. +* `ppas`: Passes a hash to `create\_resource` to make new `apt::ppa` resources. +* `settings`: Passes a hash to `create\_resource` to make new `apt::setting` resources. +* `sources`: Passes a hash to `create\_resource` to make new `apt::source` resources. + +####apt::backports + +* `location`: The URL of the apt repository. OS-dependent defaults are specifed in `apt::params` for Ubuntu and Debian. Required parameter for other OSes. +* `release`: The distribution of the apt repository. Defaults to "${lsbdistcodename}-backports" for Ubuntu and Debian. Required parameter for other OSes. +* `repos`: The component of the apt repository. OS-dependent defaults are speicifed in `apt::params` for Ubuntu and Debian. Required parameter for other OSes. +* `key`: The key for the backports repository. Can either be a string or a hash. See apt::setting for details on passing key as a hash. OS-dependent defaults are specified in `apt::params` for Ubuntu and Debian. Required parameter for other OSes. +* `pin`: The pin priority for backports repository. Can either be a number, a string, or a hash that will be passed as parameters to `apt::pin`. Defaults to `200`. + +####apt::conf + +* `content`: The content of the configuration file. +* `ensure`: Whether the configuration file should be 'present' or 'absent'. Defaults to 'present'. +* `priority`: Numeric priority for the configuration file. Defaults to '50'. ####apt::key * `ensure`: The state we want this key in. Can be 'present' or 'absent'. -* `key`: Is a GPG key ID or full key fingerprint. This value is validated with a regex enforcing it to only contain valid hexadecimal characters, be precisely 8 or 16 hexadecimal characters long and optionally prefixed with 0x for key IDs, or 40 hexadecimal characters long for key fingerprints. -* `key_content`: This parameter can be used to pass in a GPG key as a string in case it cannot be fetched from a remote location and using a file resource is for other reasons inconvenient. -* `key_source`: This parameter can be used to pass in the location of a GPG key. This URI can take the form of a `URL` (ftp, http or https) and a `path` (absolute path to a file on the target system). -* `key_server`: The keyserver from where to fetch our GPG key. It can either be a domain name or URL. It defaults to undef which results in apt_key's default keyserver being used, currently `keyserver.ubuntu.com`. -* `key_options`: Additional options to pass on to `apt-key adv --keyserver-options`. +* `id`: Is a GPG key ID or full key fingerprint. This value is validated with a regex enforcing it to only contain valid hexadecimal characters, be precisely 8 or 16 hexadecimal characters long and optionally prefixed with 0x for key IDs, or 40 hexadecimal characters long for key fingerprints. +* `content`: This parameter can be used to pass in a GPG key as a string in case it cannot be fetched from a remote location and using a file resource is for other reasons inconvenient. +* `source`: This parameter can be used to pass in the location of a GPG key. This URI can take the form of a `URL` (ftp, http or https) and a `path` (absolute path to a file on the target system). +* `server`: The keyserver from where to fetch our GPG key. It can either be a domain name or URL. It defaults to 'keyserver.ubuntu.com'. +* `options`: Additional options to pass on to `apt-key adv --keyserver-options`. ####apt::pin * `ensure`: The state we want this pin in. Can be 'present' or 'absent'. -* `explanation`: Add a comment. Defaults to `${caller_module_name}: ${name}`. -* `order`: The order of the file name. Defaults to '', otherwise must be an integer. +* `explanation`: Add a comment. Defaults to `${caller\_module\_name}: ${name}`. +* `order`: The order of the file name. Defaults to undef, otherwise must be an integer. * `packages`: The list of packages to pin. Defaults to '\*'. Can be an array or string. * `priority`: Several versions of a package may be available for installation when the sources.list(5) file contains references to more than one distribution (for example, stable and testing). APT assigns a priority to each version that is available. Subject to dependency constraints, apt-get selects the version with the highest priority for installation. * `release`: The Debian release. Defaults to ''. Typical values can be 'stable', 'testing' and 'unstable'. * `origin`: Can be used to match a hostname. The following record will assign a high priority to all versions available from the server identified by the hostname. Defaults to ''. * `version`: The specific form assigns a priority (a "Pin-Priority") to one or more specified packages with a specified version or version range. * `codename`: The distribution (lsbdistcodename) of the apt repository. Defaults to ''. -* `release_version`: Names the release version. For example, the packages in the tree might belong to Debian release version 7. Defaults to ''. +* `release\_version`: Names the release version. For example, the packages in the tree might belong to Debian release version 7. Defaults to ''. * `component`: Names the licensing component associated with the packages in the directory tree of the Release file. defaults to ''. Typical values can be 'main', 'dependencies' and 'restricted' * `originator`: Names the originator of the packages in the directory tree of the Release file. Defaults to ''. Most commonly, this is Debian. * `label`: Names the label of the packages in the directory tree of the Release file. Defaults to ''. Most commonly, this is Debian. @@ -345,44 +254,36 @@ It is recommended to read the manpage 'apt_preferences(5)' * `ensure`: Whether we are adding or removing the PPA. Can be 'present' or 'absent'. Defaults to 'present'. * `release`: The codename for the operating system you're running. Defaults to `$lsbdistcodename`. Required if lsb-release is not installed. * `options`: Options to be passed to the `apt-add-repository` command. OS-dependent defaults are set in `apt::params`. -* `package_name`: The package that provides the `apt-add-repository` command. OS-dependent defaults are set in `apt::params`. -* `package_manage`: Whether or not to manage the package providing `apt-add-repository`. Defaults to true. +* `package\_name`: The package that provides the `apt-add-repository` command. OS-dependent defaults are set in `apt::params`. +* `package\_manage`: Whether or not to manage the package providing `apt-add-repository`. Defaults to true. -### Testing +####apt::setting -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. +* `priority`: Integer or zero-padded integer setting the file priority. Defaults to 50. +* `ensure`: Whether to add or remove the file. Valid values are 'present', 'absent', and 'file'. Defaults to `file`. +* `source`: The source for the file. Exactly one of `content` and `source` must be specified. +* `content`: The content for the file. Exactly one of `content` and `source` must be specified. +* `notify\_update`: Boolean for whether or not this `apt::setting` should trigger an `apt-get update`. Defaults to `true`. -#### Example Test - -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: - -``` -class { 'apt': } - -apt::source { 'puppetlabs': - location => 'http://apt.puppetlabs.com', - repos => 'main dependencies', - key => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30', - 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. - -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: - -``` -$ 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 -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. +* `comment`: Add a comment to the apt source file. +* `ensure`: Allows you to remove the apt source file. Can be 'present' or 'absent'. +* `location`: The URL of the apt repository. Defaults to undef. Required unless `ensure => 'absent'`. +* `release`: The distribution of the apt repository. Defaults to fact 'lsbdistcodename'. +* `repos`: The component of the apt repository. This defaults to 'main'. +* `include`: Hash to configure include options. Valid keys are: + * 'deb': References a Debian distribution's binary package. Defaults to `true`. + * 'src': Enable the deb-src type, references a Debian distribution's source code in the same form as the `include['deb']` type. A deb-src line is required to fetch source indexes. Defaults to `false`. +* `key`: Add key from source. Takes either a string or a hash. If a string, the value will be passed to `id` in the `apt::key`. If a hash, valid keys are: + * 'id': See `id` in `apt::key`. Required if a hash is specified. + * 'server': See `server` in `apt::key` + * 'content': See `content` in `apt::key` + * 'source': See `source` in `apt::key` + * 'options': See `options` in `apt::key` +* `pin`: See apt::pin. Defaults to undef. Can be a string, number, or a hash to be passed as parameters to `apt::pin`. +* `architecture`: can be used to specify for which architectures information should be downloaded. If this option is not set all architectures defined by the APT::Architectures option will be downloaded. Defaults to `undef` which means all. Example values can be 'i386' or 'i386,alpha,powerpc'. +* `allow\_unsigned`: can be set to indicate that packages from this source are always authenticated even if the Release file is not signed or the signature can't be checked. Defaults to `false`. Can be `true` or `false`. Limitations ----------- diff --git a/examples/backports.pp b/examples/backports.pp new file mode 100644 index 0000000000..0dfe084850 --- /dev/null +++ b/examples/backports.pp @@ -0,0 +1,11 @@ +# Set up a backport for linuxmint qiana +class { 'apt': } +apt::backports { 'qiana': + location => 'http://us.archive.ubuntu.com/ubuntu', + release => 'trusty-backports', + repos => 'main universe multiverse restricted', + key => { + id => '630239CC130E1A7FD81A27B140976EAF437D05B5', + server => 'pgp.mit.edu', + }, +} diff --git a/examples/builddep.pp b/examples/builddep.pp new file mode 100644 index 0000000000..deaaef8c8f --- /dev/null +++ b/examples/builddep.pp @@ -0,0 +1,3 @@ +package{ 'glusterfs-server': + install_options => 'build-dep', +} diff --git a/examples/debian_testing.pp b/examples/debian_testing.pp new file mode 100644 index 0000000000..3ed98f21f1 --- /dev/null +++ b/examples/debian_testing.pp @@ -0,0 +1,18 @@ +package { 'debian-keyring': + ensure => present +} + +package { 'debian-archive-keyring': + ensure => present +} + +apt::source { 'debian_testing': + location => 'http://debian.mirror.iweb.ca/debian/', + release => 'testing', + repos => 'main contrib non-free', + pin => '-10', + key => { + id => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', + server => 'subkeys.pgp.net', + }, +} diff --git a/examples/debian_unstable.pp b/examples/debian_unstable.pp new file mode 100644 index 0000000000..b1492cd538 --- /dev/null +++ b/examples/debian_unstable.pp @@ -0,0 +1,18 @@ +package { 'debian-keyring': + ensure => present +} + +package { 'debian-archive-keyring': + ensure => present +} + +apt::source { 'debian_unstable': + location => 'http://debian.mirror.iweb.ca/debian/', + release => 'unstable', + repos => 'main contrib non-free', + pin => '-10', + key => { + id => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', + server => 'subkeys.pgp.net', + }, +} diff --git a/examples/disable_keys.pp b/examples/disable_keys.pp new file mode 100644 index 0000000000..50d0ea8022 --- /dev/null +++ b/examples/disable_keys.pp @@ -0,0 +1,5 @@ +#Note: This is generally a bad idea. You should not disable verifying repository signatures. +apt::conf { 'unauth': + priority => 99, + content => 'APT::Get::AllowUnauthenticated 1;' +} diff --git a/examples/fancy_progress.pp b/examples/fancy_progress.pp new file mode 100644 index 0000000000..db78441b6b --- /dev/null +++ b/examples/fancy_progress.pp @@ -0,0 +1,4 @@ +apt::conf { 'progressbar': + priority => 99, + content => 'Dpkg::Progress-Fancy "1";', +} diff --git a/examples/force.pp b/examples/force.pp new file mode 100644 index 0000000000..4cfaa96fd9 --- /dev/null +++ b/examples/force.pp @@ -0,0 +1,28 @@ +#if you need to specify a release +$rel_string = '-t ' +#else +$rel_string = '' + +#if you need to specify a version +$ensure = '' +#else +$ensure = installed + +#if overwrite existing cfg files +$config_files = '-o Dpkg::Options::="--force-confnew"' +#elsif force use of old files +$config_files = '-o Dpkg::Options::="--force-confold"' +#elsif update only unchanged files +$config_files = '-o Dpkg::Options::="--force-confdef"' +#else +$config_files = '' + +#if install missing configuration files for the package +$config_missing = '-o Dpkg::Options::="--force-confmiss"' +#else +$config_missing = '' + +package { '': + ensure => $ensure, + install_options => "${config_files} ${config_missing} ${rel_string}", +} diff --git a/examples/hold.pp b/examples/hold.pp new file mode 100644 index 0000000000..00f760c4e0 --- /dev/null +++ b/examples/hold.pp @@ -0,0 +1,5 @@ +apt::pin { 'hold-vim': + packages => 'vim', + version => '2:7.4.488-5', + priority => 1001, +} diff --git a/examples/key.pp b/examples/key.pp new file mode 100644 index 0000000000..cc8681fbf8 --- /dev/null +++ b/examples/key.pp @@ -0,0 +1,6 @@ +# Declare Apt key for apt.puppetlabs.com source +apt::key { 'puppetlabs': + id => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30', + server => 'pgp.mit.edu', + options => 'http-proxy="http://proxyuser:proxypass@example.org:3128"', +} diff --git a/tests/pin.pp b/examples/pin.pp similarity index 100% rename from tests/pin.pp rename to examples/pin.pp diff --git a/tests/ppa.pp b/examples/ppa.pp similarity index 100% rename from tests/ppa.pp rename to examples/ppa.pp diff --git a/examples/release.pp b/examples/release.pp new file mode 100644 index 0000000000..46d6893b0d --- /dev/null +++ b/examples/release.pp @@ -0,0 +1,4 @@ +apt::conf { 'release': + content => 'APT::Default-Release "karmic";', + priority => '01', +} diff --git a/examples/source.pp b/examples/source.pp new file mode 100644 index 0000000000..33dc2a1938 --- /dev/null +++ b/examples/source.pp @@ -0,0 +1,35 @@ +# Declare the apt class to manage /etc/apt/sources.list and /etc/sources.list.d +class { 'apt': } + +# Install the puppetlabs apt source +# Release is automatically obtained from lsbdistcodename fact if available. +apt::source { 'puppetlabs': + location => 'http://apt.puppetlabs.com', + repos => 'main', + key => { + id => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30', + server => 'pgp.mit.edu', + }, +} + +# test two sources with the same key +apt::source { 'debian_testing': + location => 'http://debian.mirror.iweb.ca/debian/', + release => 'testing', + repos => 'main contrib non-free', + key => { + id => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', + server => 'subkeys.pgp.net', + }, + pin => '-10', +} +apt::source { 'debian_unstable': + location => 'http://debian.mirror.iweb.ca/debian/', + release => 'unstable', + repos => 'main contrib non-free', + key => { + id => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', + server => 'subkeys.pgp.net', + }, + pin => '-10', +} diff --git a/examples/unattended_upgrades.pp b/examples/unattended_upgrades.pp new file mode 100644 index 0000000000..464090415c --- /dev/null +++ b/examples/unattended_upgrades.pp @@ -0,0 +1 @@ +# TODO diff --git a/lib/puppet/provider/apt_key/apt_key.rb b/lib/puppet/provider/apt_key/apt_key.rb index cd68d37063..f8c7d1976a 100644 --- a/lib/puppet/provider/apt_key/apt_key.rb +++ b/lib/puppet/provider/apt_key/apt_key.rb @@ -141,7 +141,14 @@ def tempfile(content) if File.executable? command(:gpg) extracted_key = execute(["#{command(:gpg)} --with-fingerprint --with-colons #{file.path} | awk -F: '/^fpr:/ { print $10 }'"], :failonfail => false) extracted_key = extracted_key.chomp - if extracted_key != name + + found_match = false + extracted_key.each_line do |line| + if line.chomp == name + found_match = true + end + end + if not found_match fail("The id in your manifest #{resource[:name]} and the fingerprint from content/source do not match. Please check there is not an error in the id or check the content/source is legitimate.") end else @@ -161,8 +168,8 @@ def create # Breaking up the command like this is needed because it blows up # if --recv-keys isn't the last argument. command.push('adv', '--keyserver', resource[:server]) - unless resource[:keyserver_options].nil? - command.push('--keyserver-options', resource[:keyserver_options]) + unless resource[:options].nil? + command.push('--keyserver-options', resource[:options]) end command.push('--recv-keys', resource[:id]) elsif resource[:content] diff --git a/lib/puppet/type/apt_key.rb b/lib/puppet/type/apt_key.rb index 7130496ea9..81b66a2638 100644 --- a/lib/puppet/type/apt_key.rb +++ b/lib/puppet/type/apt_key.rb @@ -61,11 +61,11 @@ newparam(:server) do desc 'The key server to fetch the key from based on the ID. It can either be a domain name or url.' defaultto :'keyserver.ubuntu.com' - + newvalues(/\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$/) end - newparam(:keyserver_options) do + newparam(:options) do desc 'Additional options to pass to apt-key\'s --keyserver-options.' end diff --git a/manifests/backports.pp b/manifests/backports.pp index ff8cb44b97..3cac0b5b5b 100644 --- a/manifests/backports.pp +++ b/manifests/backports.pp @@ -1,82 +1,59 @@ -# This adds the necessary components to get backports for ubuntu and debian -# -# == Parameters -# -# [*release*] -# The ubuntu/debian release name. Defaults to $lsbdistcodename. Setting this -# manually can cause undefined behavior. (Read: universe exploding) -# -# [*pin_priority*] -# _default_: 200 -# -# The priority that should be awarded by default to all packages coming from -# the Debian Backports project. -# -# == Examples -# -# include apt::backports -# -# class { 'apt::backports': -# release => 'natty', -# } -# -# == Authors -# -# Ben Hughes, I think. At least blame him if this goes wrong. -# I just added puppet doc. -# -# == Copyright -# -# Copyright 2011 Puppet Labs Inc, unless otherwise noted. -class apt::backports( - $release = $::lsbdistcodename, - $location = $::apt::params::backports_location, - $pin_priority = 200, -) inherits apt::params { - - if ! is_integer($pin_priority) { - fail('$pin_priority must be an integer') +class apt::backports ( + $location = undef, + $release = undef, + $repos = undef, + $key = undef, + $pin = 200, +){ + if $location { + validate_string($location) + $_location = $location } - - 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) + if $release { + validate_string($release) + $_release = $release } - - $key = $distid ? { - 'debian' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', - 'ubuntu' => '630239CC130E1A7FD81A27B140976EAF437D05B5', + if $repos { + validate_string($repos) + $_repos = $repos + } + if $key { + unless is_hash($key) { + validate_string($key) + } + $_key = $key } - $repos = $distid ? { - 'debian' => 'main contrib non-free', - 'ubuntu' => 'main universe multiverse restricted', + unless is_hash($pin) { + unless (is_numeric($pin) or is_string($pin)) { + fail('pin must be either a string, number or hash') + } } - apt::pin { 'backports': - before => Apt::Source['backports'], - release => "${release_real}-backports", - priority => $pin_priority, + if ($::apt::xfacts['lsbdistid'] == 'debian' or $::apt::xfacts['lsbdistid'] == 'ubuntu') { + unless $location { + $_location = $::apt::backports['location'] + } + unless $release { + $_release = "${::apt::xfacts['lsbdistcodename']}-backports" + } + unless $repos { + $_repos = $::apt::backports['repos'] + } + unless $key { + $_key = $::apt::backports['key'] + } + } else { + unless $location and $release and $repos and $key { + fail('If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key') + } } apt::source { 'backports': - location => $location, - release => "${release_real}-backports", - repos => $repos, - key => $key, - key_server => 'pgp.mit.edu', + location => $_location, + release => $_release, + repos => $_repos, + key => $_key, + pin => $pin, } + } diff --git a/manifests/builddep.pp b/manifests/builddep.pp deleted file mode 100644 index 3a059c273d..0000000000 --- a/manifests/builddep.pp +++ /dev/null @@ -1,16 +0,0 @@ -# builddep.pp - -define apt::builddep() { - include apt::update - - exec { "apt-builddep-${name}": - command => "/usr/bin/apt-get -y --force-yes build-dep ${name}", - logoutput => 'on_failure', - require => Exec['apt_update'], - } - - # Need anchor to provide containment for dependencies. - anchor { "apt::builddep::${name}": - require => Class['apt::update'], - } -} diff --git a/manifests/conf.pp b/manifests/conf.pp index 318422e293..da6d64e738 100644 --- a/manifests/conf.pp +++ b/manifests/conf.pp @@ -1,18 +1,18 @@ define apt::conf ( - $content, + $content = undef, $ensure = present, - $priority = '50' + $priority = '50', ) { - include apt::params - - $apt_conf_d = $apt::params::apt_conf_d + unless $ensure == 'absent' { + unless $content { + fail('Need to pass in content parameter') + } + } - file { "${apt_conf_d}/${priority}${name}": - ensure => $ensure, - content => template('apt/_header.erb', 'apt/conf.erb'), - owner => root, - group => root, - mode => '0644', + apt::setting { "conf-${name}": + ensure => $ensure, + priority => $priority, + content => template('apt/_header.erb', 'apt/conf.erb'), } } diff --git a/manifests/debian/testing.pp b/manifests/debian/testing.pp deleted file mode 100644 index 7af48d2458..0000000000 --- a/manifests/debian/testing.pp +++ /dev/null @@ -1,21 +0,0 @@ -# testing.pp - -class apt::debian::testing { - include apt - - # deb http://debian.mirror.iweb.ca/debian/ testing main contrib non-free - # deb-src http://debian.mirror.iweb.ca/debian/ testing main contrib non-free - # Key: 46925553 Server: subkeys.pgp.net - # debian-keyring - # debian-archive-keyring - - apt::source { 'debian_testing': - location => 'http://debian.mirror.iweb.ca/debian/', - release => 'testing', - repos => 'main contrib non-free', - required_packages => 'debian-keyring debian-archive-keyring', - key => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', - key_server => 'subkeys.pgp.net', - pin => '-10', - } -} diff --git a/manifests/debian/unstable.pp b/manifests/debian/unstable.pp deleted file mode 100644 index 23ce9b49bc..0000000000 --- a/manifests/debian/unstable.pp +++ /dev/null @@ -1,21 +0,0 @@ -# unstable.pp - -class apt::debian::unstable { - include apt - - # deb http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free - # deb-src http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free - # Key: 46925553 Server: subkeys.pgp.net - # debian-keyring - # debian-archive-keyring - - apt::source { 'debian_unstable': - location => 'http://debian.mirror.iweb.ca/debian/', - release => 'unstable', - repos => 'main contrib non-free', - required_packages => 'debian-keyring debian-archive-keyring', - key => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', - key_server => 'subkeys.pgp.net', - pin => '-10', - } -} diff --git a/manifests/force.pp b/manifests/force.pp deleted file mode 100644 index 8ceeb17060..0000000000 --- a/manifests/force.pp +++ /dev/null @@ -1,60 +0,0 @@ -# force.pp -# force a package from a specific release - -define apt::force( - $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 ? { - false => undef, - default => "=${version}", - } - - $release_string = $release ? { - false => undef, - 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', default: { $config_files = '' } - } - - case $cfg_missing { - true: { $config_missing = '-o Dpkg::Options::="--force-confmiss"' } - false, default: { $config_missing = '' } - } - - if $version == false { - if $release == false { - $install_check = "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'" - } else { - # If installed version and candidate version differ, this check returns 1 (false). - $install_check = "/usr/bin/test \$(/usr/bin/apt-cache policy -t ${release} ${name} | /bin/grep -E 'Installed|Candidate' | /usr/bin/uniq -s 14 | /usr/bin/wc -l) -eq 1" - } - } else { - if $release == false { - $install_check = "/usr/bin/dpkg -s ${name} | grep -q 'Version: ${version}'" - } else { - $install_check = "/usr/bin/apt-cache policy -t ${release} ${name} | /bin/grep -q 'Installed: ${version}'" - } - } - - exec { "${provider} -y ${config_files} ${config_missing} ${release_string} install ${name}${version_string}": - unless => $install_check, - environment => ['LC_ALL=C', 'LANG=C'], - logoutput => 'on_failure', - timeout => $timeout, - } -} diff --git a/manifests/hold.pp b/manifests/hold.pp deleted file mode 100644 index 61e8afcb3b..0000000000 --- a/manifests/hold.pp +++ /dev/null @@ -1,54 +0,0 @@ -# == Define apt::hold -# -# This defined type allows you to hold a package based on the version you -# require. It's implemented by dropping an apt preferences file pinning the -# package to the version you require. -# -# === Parameters -# -# [*version*] -# The version at which you wish to pin a package. -# -# This can either be the full version, such as 4:2.11.8.1-5, or -# a partial version, such as 4:2.11.* -# -# [*package*] -# _default_: +$title+, the title/name of the resource. -# -# Name of the package that apt is to hold. -# -# [*priority*] -# _default_: +1001+ -# -# The default priority of 1001 causes this preference to always win. By -# setting the priority to a number greater than 1000 apt will always install -# this version even if it means downgrading the currently installed version. -define apt::hold( - $version, - $ensure = 'present', - $package = $title, - $priority = 1001, -){ - - validate_string($title) - validate_re($ensure, ['^present|absent',]) - validate_string($package) - validate_string($version) - - if ! is_integer($priority) { - fail('$priority must be an integer') - } - - if $ensure == 'present' { - ::apt::pin { "hold_${package}": - packages => $package, - version => $version, - priority => $priority, - } - } else { - ::apt::pin { "hold_${package}": - ensure => 'absent', - } - } - -} diff --git a/manifests/init.pp b/manifests/init.pp index 5f33fdba70..140e171c50 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,112 +1,100 @@ -# == Class: apt -# -# This module manages the initial configuration of apt. -# -# The parameters listed here are not required in general and were -# added for use cases related to development environments. -# -# === Parameters -# -# [*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. -# -# === Examples -# -# class { 'apt': } -# -# === Requires -# -# puppetlabs/stdlib >= 2.2.1 # class apt( - $always_apt_update = false, - $apt_update_frequency = 'reluctantly', - $disable_keys = undef, - $proxy_host = undef, - $proxy_port = '8080', - $purge_sources_list = false, - $purge_sources_list_d = false, - $purge_preferences = false, - $purge_preferences_d = false, - $update_timeout = undef, - $update_tries = undef, - $sources = undef, - $fancy_progress = undef -) { - - if $::osfamily != 'Debian' { - fail('This module only works on Debian or derivatives like Ubuntu') - } + $update = {}, + $purge = {}, + $proxy = {}, + $sources = {}, + $keys = {}, + $ppas = {}, + $settings = {}, +) inherits ::apt::params { $frequency_options = ['always','daily','weekly','reluctantly'] - validate_re($apt_update_frequency, $frequency_options) - include apt::params + validate_hash($update) + if $update['frequency'] { + validate_re($update['frequency'], $frequency_options) + } + if $update['timeout'] { + unless is_integer($update['timeout']) { + fail('timeout value for update must be an integer') + } + } + if $update['tries'] { + unless is_integer($update['tries']) { + fail('tries value for update must be an integer') + } + } + + $_update = merge($::apt::update_defaults, $update) include apt::update - validate_bool($purge_sources_list, $purge_sources_list_d, - $purge_preferences, $purge_preferences_d) + validate_hash($purge) + if $purge['sources.list'] { + validate_bool($purge['sources.list']) + } + if $purge['sources.list.d'] { + validate_bool($purge['sources.list.d']) + } + if $purge['preferences'] { + validate_bool($purge['preferences']) + } + if $purge['preferences.d'] { + validate_bool($purge['preferences.d']) + } + + $_purge = merge($::apt::purge_defaults, $purge) + + validate_hash($proxy) + if $proxy['host'] { + validate_string($proxy['host']) + } + if $proxy['port'] { + unless is_integer($proxy['port']) { + fail('$proxy port must be an integer') + } + } + if $proxy['https'] { + validate_bool($proxy['https']) + } + + $_proxy = merge($apt::proxy_defaults, $proxy) + + validate_hash($sources) + validate_hash($keys) + validate_hash($settings) + validate_hash($ppas) + + if $proxy['host'] { + apt::setting { 'conf-proxy': + priority => '01', + content => template('apt/_header.erb', 'apt/proxy.erb'), + } + } - $sources_list_content = $purge_sources_list ? { + $sources_list_content = $_purge['sources.list'] ? { false => undef, true => "# Repos managed by puppet.\n", } - if $always_apt_update == true { + $preferences_ensure = $_purge['preferences'] ? { + false => file, + true => absent, + } + + if $_update['frequency'] == 'always' { Exec <| title=='apt_update' |> { refreshonly => false, } } - file { '/etc/apt/apt.conf.d/15update-stamp': - ensure => 'file', - content => template('apt/_header.erb', 'apt/15update-stamp.erb'), - group => 'root', - mode => '0644', - owner => 'root', + apt::setting { 'conf-update-stamp': + priority => 15, + content => template('apt/_header.erb', 'apt/15update-stamp.erb'), } - $root = $apt::params::root - $apt_conf_d = $apt::params::apt_conf_d - $sources_list_d = $apt::params::sources_list_d - $preferences_d = $apt::params::preferences_d - $provider = $apt::params::provider - file { 'sources.list': - ensure => present, - path => "${root}/sources.list", + ensure => file, + path => $::apt::sources_list, owner => root, group => root, mode => '0644', @@ -116,101 +104,51 @@ file { 'sources.list.d': ensure => directory, - path => $sources_list_d, + path => $::apt::sources_list_d, owner => root, group => root, - purge => $purge_sources_list_d, - recurse => $purge_sources_list_d, + mode => '0644', + purge => $_purge['sources.list.d'], + recurse => $_purge['sources.list.d'], notify => Exec['apt_update'], } - if $purge_preferences { - file { 'apt-preferences': - ensure => absent, - path => "${root}/preferences", - } + file { 'preferences': + ensure => $preferences_ensure, + path => $::apt::preferences, + owner => root, + group => root, + mode => '0644', + notify => Exec['apt_update'], } file { 'preferences.d': ensure => directory, - path => $preferences_d, + path => $::apt::preferences_d, owner => root, group => root, - purge => $purge_preferences_d, - recurse => $purge_preferences_d, - } - - case $fancy_progress { - true: { - file { '99progressbar': - ensure => present, - content => template('apt/_header.erb', 'apt/progressbar.erb'), - path => "${apt_conf_d}/99progressbar", - } - } - false: { - file { '99progressbar': - ensure => absent, - path => "${apt_conf_d}/99progressbar", - } - } - undef: {} # do nothing - default: { fail('Valid values for fancy_progress are true or false') } + mode => '0644', + purge => $_purge['preferences.d'], + recurse => $_purge['preferences.d'], + notify => Exec['apt_update'], } - case $disable_keys { - true: { - file { '99unauth': - ensure => present, - content => template('apt/_header.erb', 'apt/unauth.erb'), - path => "${apt_conf_d}/99unauth", - } - } - false: { - file { '99unauth': - ensure => absent, - path => "${apt_conf_d}/99unauth", - } - } - undef: { } # do nothing - default: { fail('Valid values for disable_keys are true or false') } - } + contain 'apt::update' - 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 => template('apt/_header.erb', 'apt/proxy.erb'), - notify => Exec['apt_update'], - mode => '0644', - owner => root, - group => root, - } - } + # manage sources if present + if $sources { + create_resources('apt::source', $sources) } - - file { 'old-proxy-file': - ensure => absent, - path => "${apt_conf_d}/proxy", - notify => Exec['apt_update'], + # manage keys if present + if $keys { + create_resources('apt::key', $keys) } - - # Need anchor to provide containment for dependencies. - anchor { 'apt::update': - require => Class['apt::update'], + # manage ppas if present + if $ppas { + create_resources('apt::ppa', $ppas) } - - # manage sources if present - if $sources != undef { - validate_hash($sources) - create_resources('apt::source', $sources) + # manage settings if present + if $settings { + create_resources('apt::setting', $settings) } } diff --git a/manifests/key.pp b/manifests/key.pp index ce5fc2514c..6761e6912d 100644 --- a/manifests/key.pp +++ b/manifests/key.pp @@ -7,7 +7,7 @@ # # === Parameters # -# [*key*] +# [*id*] # _default_: +$title+, the title/name of the resource # # Is a GPG key ID or full key fingerprint. This value is validated with @@ -23,14 +23,14 @@ # * +present+ # * +absent+ # -# [*key_content*] +# [*content*] # _default_: +undef+ # # This parameter can be used to pass in a GPG key as a # string in case it cannot be fetched from a remote location # and using a file resource is for other reasons inconvenient. # -# [*key_source*] +# [*source*] # _default_: +undef+ # # This parameter can be used to pass in the location of a GPG @@ -38,80 +38,78 @@ # * +URL+: ftp, http or https # * +path+: absolute path to a file on the target system. # -# [*key_server*] +# [*server*] # _default_: +undef+ # # The keyserver from where to fetch our GPG key. It can either be a domain -# name or url. It defaults to -# undef which results in apt_key's default keyserver being used, -# currently +keyserver.ubuntu.com+. +# name or url. It defaults to +keyserver.ubuntu.com+. # -# [*key_options*] +# [*options*] # _default_: +undef+ # # Additional options to pass on to `apt-key adv --keyserver-options`. define apt::key ( - $key = $title, - $ensure = present, - $key_content = undef, - $key_source = undef, - $key_server = undef, - $key_options = undef, + $id = $title, + $ensure = present, + $content = undef, + $source = undef, + $server = $::apt::keyserver, + $options = undef, ) { - validate_re($key, ['\A(0x)?[0-9a-fA-F]{8}\Z', '\A(0x)?[0-9a-fA-F]{16}\Z', '\A(0x)?[0-9a-fA-F]{40}\Z']) + validate_re($id, ['\A(0x)?[0-9a-fA-F]{8}\Z', '\A(0x)?[0-9a-fA-F]{16}\Z', '\A(0x)?[0-9a-fA-F]{40}\Z']) validate_re($ensure, ['\Aabsent|present\Z',]) - if $key_content { - validate_string($key_content) + if $content { + validate_string($content) } - if $key_source { - validate_re($key_source, ['\Ahttps?:\/\/', '\Aftp:\/\/', '\A\/\w+']) + if $source { + validate_re($source, ['\Ahttps?:\/\/', '\Aftp:\/\/', '\A\/\w+']) } - if $key_server { - validate_re($key_server,['\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$']) + if $server { + validate_re($server,['\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$']) } - if $key_options { - validate_string($key_options) + if $options { + validate_string($options) } case $ensure { present: { - if defined(Anchor["apt_key ${key} absent"]){ - fail("key with id ${key} already ensured as absent") + if defined(Anchor["apt_key ${id} absent"]){ + fail("key with id ${id} already ensured as absent") } - if !defined(Anchor["apt_key ${key} present"]) { + if !defined(Anchor["apt_key ${id} present"]) { apt_key { $title: - ensure => $ensure, - id => $key, - source => $key_source, - content => $key_content, - server => $key_server, - keyserver_options => $key_options, + ensure => $ensure, + id => $id, + source => $source, + content => $content, + server => $server, + options => $options, } -> - anchor { "apt_key ${key} present": } + anchor { "apt_key ${id} present": } } } absent: { - if defined(Anchor["apt_key ${key} present"]){ - fail("key with id ${key} already ensured as present") + if defined(Anchor["apt_key ${id} present"]){ + fail("key with id ${id} already ensured as present") } - if !defined(Anchor["apt_key ${key} absent"]){ + if !defined(Anchor["apt_key ${id} absent"]){ apt_key { $title: - ensure => $ensure, - id => $key, - source => $key_source, - content => $key_content, - server => $key_server, - keyserver_options => $key_options, + ensure => $ensure, + id => $id, + source => $source, + content => $content, + server => $server, + options => $options, } -> - anchor { "apt_key ${key} absent": } + anchor { "apt_key ${id} absent": } } } diff --git a/manifests/params.pp b/manifests/params.pp index 4efe872e5b..5a0c170d91 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,95 +1,144 @@ class apt::params { + + if $::osfamily != 'Debian' { + fail('This module only works on Debian or derivatives like Ubuntu') + } + + # Strict variables facts lookup compatibility + $xfacts = { + 'lsbdistcodename' => defined('$lsbdistcodename') ? { + true => $::lsbdistcodename, + default => undef, + }, + 'lsbdistrelease' => defined('$lsbdistrelease') ? { + true => $::lsbdistrelease, + default => undef, + }, + 'lsbmajdistrelease' => defined('$lsbmajdistrelease') ? { + true => $::lsbmajdistrelease, + default => undef, + }, + 'lsbdistdescription' => defined('$lsbdistdescription') ? { + true => $::lsbdistdescription, + default => undef, + }, + 'lsbminordistrelease' => defined('$lsbminordistrelease') ? { + true => $::lsbminordistrelease, + default => undef, + }, + 'lsbdistid' => defined('$lsbdistid') ? { + true => $::lsbdistid, + default => undef, + }, + } + $root = '/etc/apt' $provider = '/usr/bin/apt-get' + $sources_list = "${root}/sources.list" $sources_list_d = "${root}/sources.list.d" - $apt_conf_d = "${root}/apt.conf.d" + $conf_d = "${root}/apt.conf.d" + $preferences = "${root}/preferences" $preferences_d = "${root}/preferences.d" + $keyserver = 'keyserver.ubuntu.com' - 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', - } - } - } - 'Cumulus Networks': { - $distid = 'debian' - $distcodename = $::lsbdistcodename - } - '': { - fail('Unable to determine lsbdistid, is lsb-release installed?') - } - default: { - fail("Unsupported lsbdistid (${::lsbdistid})") + $config_files = { + 'conf' => { + 'path' => $conf_d, + 'ext' => '', + }, + 'pref' => { + 'path' => $preferences_d, + 'ext' => '', + }, + 'list' => { + 'path' => $sources_list_d, + 'ext' => '.list', } } - case $distid { + + $update_defaults = { + 'frequency' => 'reluctantly', + 'timeout' => undef, + 'tries' => undef, + } + + $proxy_defaults = { + 'host' => undef, + 'port' => 8080, + 'https' => false, + } + + $purge_defaults = { + 'sources.list' => false, + 'sources.list.d' => false, + 'preferences' => false, + 'preferences.d' => false, + } + + $source_key_defaults = { + 'server' => $keyserver, + 'options' => undef, + 'content' => undef, + 'source' => undef, + } + + $include_defaults = { + 'deb' => true, + 'src' => false, + } + + case $xfacts['lsbdistid'] { 'debian': { - case $distcodename { + case $xfacts['lsbdistcodename'] { 'squeeze': { - $backports_location = 'http://backports.debian.org/debian-backports' - $legacy_origin = true - $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/' - $legacy_origin = false - $origins = ['origin=Debian,archive=stable,label=Debian-Security', - 'origin=Debian,archive=oldstable,label=Debian-Security'] + $backports = { + 'location' => 'http://backports.debian.org/debian-backports', + 'key' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', + 'repos' => 'main contrib non-free', + } } default: { - $backports_location = 'http://http.debian.net/debian/' - $legacy_origin = false - $origins = ['origin=Debian,archive=stable,label=Debian-Security'] + $backports = { + 'location' => 'http://ftp.debian.org/debian/', + 'key' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', + 'repos' => 'main contrib non-free', + } } } } 'ubuntu': { - case $distcodename { + $backports = { + 'location' => 'http://archive.ubuntu.com/ubuntu', + 'key' => '630239CC130E1A7FD81A27B140976EAF437D05B5', + 'repos' => 'main universe multiverse restricted', + } + + case $xfacts['lsbdistcodename'] { 'lucid': { - $backports_location = 'http://us.archive.ubuntu.com/ubuntu' $ppa_options = undef $ppa_package = 'python-software-properties' - $legacy_origin = true - $origins = ['${distro_id} ${distro_codename}-security'] #lint:ignore:single_quote_string_with_variables } 'precise': { - $backports_location = 'http://us.archive.ubuntu.com/ubuntu' $ppa_options = '-y' $ppa_package = 'python-software-properties' - $legacy_origin = true - $origins = ['${distro_id}:${distro_codename}-security'] #lint:ignore:single_quote_string_with_variables } 'trusty', 'utopic', 'vivid': { - $backports_location = 'http://us.archive.ubuntu.com/ubuntu' $ppa_options = '-y' $ppa_package = 'software-properties-common' - $legacy_origin = true - $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' $ppa_package = 'python-software-properties' - $legacy_origin = true - $origins = ['${distro_id}:${distro_codename}-security'] #lint:ignore:single_quote_string_with_variables } } } + undef: { + fail('Unable to determine lsbdistid, is lsb-release installed?') + } + default: { + $ppa_options = undef + $ppa_package = undef + $backports = undef + } } } diff --git a/manifests/pin.pp b/manifests/pin.pp index 935dc226e5..bcccf28b7c 100644 --- a/manifests/pin.pp +++ b/manifests/pin.pp @@ -3,8 +3,8 @@ define apt::pin( $ensure = present, - $explanation = "${caller_module_name}: ${name}", - $order = '', + $explanation = undef, + $order = undef, $packages = '*', $priority = 0, $release = '', # a= @@ -16,14 +16,20 @@ $originator = '', # o= $label = '' # l= ) { - include apt::params - - $preferences_d = $apt::params::preferences_d - - if $order != '' and !is_integer($order) { + if $order and !is_integer($order) { fail('Only integers are allowed in the apt::pin order param') } + if $explanation { + $_explanation = $explanation + } else { + if defined('$caller_module_name') { # strict vars check + $_explanation = "${caller_module_name}: ${name}" + } else { + $_explanation = ": ${name}" + } + } + $pin_release_array = [ $release, $codename, @@ -56,7 +62,6 @@ } } - # According to man 5 apt_preferences: # The files have either no or "pref" as filename extension # and only contain alphanumeric, hyphen (-), underscore (_) and period @@ -66,16 +71,9 @@ # be silently ignored. $file_name = regsubst($title, '[^0-9a-z\-_\.]', '_', 'IG') - $path = $order ? { - '' => "${preferences_d}/${file_name}.pref", - default => "${preferences_d}/${order}-${file_name}.pref", - } - file { "${file_name}.pref": - ensure => $ensure, - path => $path, - owner => root, - group => root, - mode => '0644', - content => template('apt/_header.erb', 'apt/pin.pref.erb'), + apt::setting { "pref-${file_name}": + ensure => $ensure, + priority => $order, + content => template('apt/_header.erb', 'apt/pin.pref.erb'), } } diff --git a/manifests/ppa.pp b/manifests/ppa.pp index e86a19fd9d..808c9751a0 100644 --- a/manifests/ppa.pp +++ b/manifests/ppa.pp @@ -1,23 +1,17 @@ # ppa.pp - define apt::ppa( $ensure = 'present', - $release = $::lsbdistcodename, - $options = $::apt::params::ppa_options, - $package_name = $::apt::params::ppa_package, - $package_manage = true, + $options = $::apt::ppa_options, + $release = $::apt::xfacts['lsbdistcodename'], + $package_name = $::apt::ppa_package, + $package_manage = false, ) { - include apt::params - include apt::update - - $sources_list_d = $apt::params::sources_list_d - - if ! $release { + unless $release { fail('lsbdistcodename fact not available: release parameter required') } - if $::operatingsystem != 'Ubuntu' { - fail('apt::ppa is currently supported on Ubuntu only.') + if $::apt::xfacts['lsbdistid'] == 'Debian' { + fail('apt::ppa is not currently supported on Debian.') } $filename_without_slashes = regsubst($name, '/', '-', 'G') @@ -27,52 +21,43 @@ if $ensure == 'present' { if $package_manage { - if ! defined(Package[$package_name]) { - package { $package_name: } - } + package { $package_name: } $_require = [File['sources.list.d'], Package[$package_name]] } else { $_require = File['sources.list.d'] } - if defined(Class['apt']) { - case $::apt::proxy_host { - false, '', undef: { - $proxy_env = [] - } - default: { - $proxy_env = ["http_proxy=http://${::apt::proxy_host}:${::apt::proxy_port}", "https_proxy=http://${::apt::proxy_host}:${::apt::proxy_port}"] - } + $_proxy = $::apt::_proxy + if $_proxy['host'] { + if $_proxy['https'] { + $_proxy_env = ["http_proxy=http://${_proxy['host']}:${_proxy['port']}", "https_proxy=https://${_proxy['host']}:${_proxy['port']}"] + } else { + $_proxy_env = ["http_proxy=http://${_proxy['host']}:${_proxy['port']}"] } } else { - $proxy_env = [] + $_proxy_env = [] } exec { "add-apt-repository-${name}": - environment => $proxy_env, + environment => $_proxy_env, command => "/usr/bin/add-apt-repository ${options} ${name}", - unless => "/usr/bin/test -s ${sources_list_d}/${sources_list_d_filename}", + unless => "/usr/bin/test -s ${::apt::sources_list_d}/${sources_list_d_filename}", user => 'root', logoutput => 'on_failure', notify => Exec['apt_update'], require => $_require, } - file { "${sources_list_d}/${sources_list_d_filename}": + file { "${::apt::sources_list_d}/${sources_list_d_filename}": ensure => file, require => Exec["add-apt-repository-${name}"], } } else { - file { "${sources_list_d}/${sources_list_d_filename}": + file { "${::apt::sources_list_d}/${sources_list_d_filename}": ensure => 'absent', notify => Exec['apt_update'], } } - - # Need anchor to provide containment for dependencies. - anchor { "apt::ppa::${name}": - require => Class['apt::update'], - } } diff --git a/manifests/release.pp b/manifests/release.pp deleted file mode 100644 index ae12dd4fb2..0000000000 --- a/manifests/release.pp +++ /dev/null @@ -1,17 +0,0 @@ -# release.pp - -class apt::release ( - $release_id -) { - - include apt::params - - $root = $apt::params::root - - file { "${root}/apt.conf.d/01release": - owner => root, - group => root, - mode => '0644', - content => template('apt/_header.erb', 'apt/release.erb'), - } -} diff --git a/manifests/setting.pp b/manifests/setting.pp new file mode 100644 index 0000000000..ab84460232 --- /dev/null +++ b/manifests/setting.pp @@ -0,0 +1,63 @@ +define apt::setting ( + $priority = 50, + $ensure = file, + $source = undef, + $content = undef, + $notify_update = true, +) { + + if $content and $source { + fail('apt::setting cannot have both content and source') + } + + if !$content and !$source { + fail('apt::setting needs either of content or source') + } + + validate_re($ensure, ['file', 'present', 'absent']) + validate_bool($notify_update) + + $title_array = split($title, '-') + $setting_type = $title_array[0] + $base_name = join(delete_at($title_array, 0), '-') + + validate_re($setting_type, ['\Aconf\z', '\Apref\z', '\Alist\z'], "apt::setting resource name/title must start with either 'conf-', 'pref-' or 'list-'") + + unless is_integer($priority) { + # need this to allow zero-padded priority. + validate_re($priority, '^\d+$', 'apt::setting priority must be an integer or a zero-padded integer') + } + + if $source { + validate_string($source) + } + + if $content { + validate_string($content) + } + + if $setting_type == 'list' { + $_priority = '' + } else { + $_priority = $priority + } + + $_path = $::apt::config_files[$setting_type]['path'] + $_ext = $::apt::config_files[$setting_type]['ext'] + + if $notify_update { + $_notify = Exec['apt_update'] + } else { + $_notify = undef + } + + file { "${_path}/${_priority}${base_name}${_ext}": + ensure => $ensure, + owner => 'root', + group => 'root', + mode => '0644', + content => $content, + source => $source, + notify => $_notify, + } +} diff --git a/manifests/source.pp b/manifests/source.pp index f6647dfe76..40fc015bb6 100644 --- a/manifests/source.pp +++ b/manifests/source.pp @@ -1,93 +1,85 @@ # source.pp # add an apt source - define apt::source( - $comment = $name, - $ensure = present, - $location = '', - $release = 'UNDEF', - $repos = 'main', - $include_src = true, - $include_deb = true, - $required_packages = false, - $key = undef, - $key_server = 'keyserver.ubuntu.com', - $key_content = undef, - $key_source = undef, - $pin = false, - $architecture = undef, - $trusted_source = false, + $location = undef, + $comment = $name, + $ensure = present, + $release = $::apt::xfacts['lsbdistcodename'], + $repos = 'main', + $include = {}, + $key = undef, + $pin = undef, + $architecture = undef, + $allow_unsigned = false, ) { + validate_string($architecture, $comment, $location, $repos) + validate_bool($allow_unsigned) + validate_hash($include) - include apt::params - include apt::update + unless $release { + fail('lsbdistcodename fact not available: release parameter required') + } - validate_string($architecture) - validate_bool($trusted_source) + if $ensure == 'present' and ! $location { + fail('cannot create a source entry without specifying a location') + } - $sources_list_d = $apt::params::sources_list_d - $provider = $apt::params::provider + $_before = Apt::Setting["list-${title}"] + $_include = merge($::apt::include_defaults, $include) - if $release == 'UNDEF' { - if $::lsbdistcodename == undef { - fail('lsbdistcodename fact not available: release parameter required') + if $key { + if is_hash($key) { + unless $key['id'] { + fail('key hash must contain at least an id entry') + } + $_key = merge($::apt::source_key_defaults, $key) } else { - $release_real = $::lsbdistcodename + validate_string($key) + $_key = $key } - } else { - $release_real = $release } - file { "${name}.list": + apt::setting { "list-${name}": ensure => $ensure, - path => "${sources_list_d}/${name}.list", - owner => root, - group => root, - mode => '0644', content => template('apt/_header.erb', 'apt/source.list.erb'), - notify => Exec['apt_update'], - } - - - if ($pin != false) { - # Get the host portion out of the url so we can pin to origin - $url_split = split($location, '/') - $host = $url_split[2] - - apt::pin { $name: - ensure => $ensure, - priority => $pin, - before => File["${name}.list"], - origin => $host, - } } - if ($required_packages != false) and ($ensure == 'present') { - exec { "Required packages: '${required_packages}' for ${name}": - command => "${provider} -y install ${required_packages}", - logoutput => 'on_failure', - refreshonly => true, - tries => 3, - try_sleep => 1, - subscribe => File["${name}.list"], - before => Exec['apt_update'], + if $pin { + if is_hash($pin) { + $_pin = merge($pin, { 'ensure' => $ensure, 'before' => $_before }) + } elsif (is_numeric($pin) or is_string($pin)) { + $url_split = split($location, '/') + $host = $url_split[2] + $_pin = { + 'ensure' => $ensure, + 'priority' => $pin, + 'before' => $_before, + 'origin' => $host, + } + } else { + fail('Received invalid value for pin parameter') } + create_resources('apt::pin', { "${name}" => $_pin }) } # We do not want to remove keys when the source is absent. if $key and ($ensure == 'present') { - apt::key { "Add key: ${key} from Apt::Source ${title}": - ensure => present, - key => $key, - key_server => $key_server, - key_content => $key_content, - key_source => $key_source, - before => File["${name}.list"], + if is_hash($_key) { + apt::key { "Add key: ${_key['id']} from Apt::Source ${title}": + ensure => present, + id => $_key['id'], + server => $_key['server'], + content => $_key['content'], + source => $_key['source'], + options => $_key['options'], + before => $_before, + } + } else { + apt::key { "Add key: ${_key} from Apt::Source ${title}": + ensure => present, + id => $_key, + before => $_before, + } } } - - # Need anchor to provide containment for dependencies. - anchor { "apt::source::${name}": - require => Class['apt::update'], - } } diff --git a/manifests/unattended_upgrades.pp b/manifests/unattended_upgrades.pp deleted file mode 100644 index 028ffc647c..0000000000 --- a/manifests/unattended_upgrades.pp +++ /dev/null @@ -1,81 +0,0 @@ -# Class: apt::unattended_upgrades -# -# This class manages the unattended-upgrades package and related configuration -# files for ubuntu -# -# origins are the repositories to automatically upgrade included packages -# blacklist is a list of packages to not automatically upgrade -# update is how often to run "apt-get update" in days -# download is how often to run "apt-get upgrade --download-only" in days -# upgrade is how often to upgrade packages included in the origins list in days -# autoclean is how often to run "apt-get autoclean" in days -# -# information on the other options can be found in the 50unattended-upgrades -# file and in /etc/cron.daily/apt -# -class apt::unattended_upgrades ( - $legacy_origin = $::apt::params::legacy_origin, - $origins = $::apt::params::origins, - $blacklist = [], - $update = '1', - $download = '1', - $upgrade = '1', - $autoclean = '7', - $auto_fix = true, - $minimal_steps = false, - $install_on_shutdown = false, - $mail_to = 'NONE', - $mail_only_on_error = false, - $remove_unused = true, - $auto_reboot = false, - $dl_limit = 'NONE', - $randomsleep = undef, - $enable = '1', - $backup_interval = '0', - $backup_level = '3', - $max_age = '0', - $min_age = '0', - $max_size = '0', - $download_delta = '0', - $verbose = '0', -) inherits ::apt::params { - - validate_bool( - $legacy_origin, - $auto_fix, - $minimal_steps, - $install_on_shutdown, - $mail_only_on_error, - $remove_unused, - $auto_reboot - ) - validate_array($origins) - - if $randomsleep { - unless is_numeric($randomsleep) { - fail('randomsleep must be numeric') - } - } - - package { 'unattended-upgrades': - ensure => present, - } - - file { '/etc/apt/apt.conf.d/50unattended-upgrades': - ensure => file, - owner => 'root', - group => 'root', - mode => '0644', - content => template('apt/_header.erb', 'apt/50unattended-upgrades.erb'), - require => Package['unattended-upgrades'], - } - - file { '/etc/apt/apt.conf.d/10periodic': - ensure => file, - owner => 'root', - group => 'root', - mode => '0644', - content => template('apt/_header.erb', 'apt/10periodic.erb'), - require => Package['unattended-upgrades'], - } -} diff --git a/manifests/update.pp b/manifests/update.pp index d9b338d952..86f068200c 100644 --- a/manifests/update.pp +++ b/manifests/update.pp @@ -1,55 +1,48 @@ 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 + case $::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 + } + '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 } - } - default: { - #catches 'recluctantly', and any other value (which should not occur). - #do nothing. - $_kick_apt = false + } else { + #if apt-get update has not successfully run, we should kick apt_update + $_kick_apt = true } } - } else { - $_kick_apt = false + default: { + #catches 'recluctantly', and any other value (which should not occur). + #do nothing. + $_kick_apt = false + } } if $_kick_apt { @@ -58,11 +51,11 @@ $_refresh = true } exec { 'apt_update': - command => "${apt::params::provider} update", + command => "${::apt::provider} update", logoutput => 'on_failure', refreshonly => $_refresh, - timeout => $apt::update_timeout, - tries => $apt::update_tries, + timeout => $::apt::_update['timeout'], + tries => $::apt::_update['tries'], try_sleep => 1 } } diff --git a/metadata.json b/metadata.json index 5b14ae45cc..10e859ef1c 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-apt", - "version": "1.8.0", + "version": "2.0.0", "author": "Puppet Labs", "summary": "Provides an interface for managing Apt source, key, and definitions with Puppet", "license": "Apache-2.0", @@ -31,10 +31,10 @@ }, { "name": "puppet", - "version_requirement": "3.x" + "version_requirement": ">= 3.4.0" } ], "dependencies": [ - {"name":"puppetlabs/stdlib","version_requirement":">= 2.2.1"} + {"name":"puppetlabs/stdlib","version_requirement":">= 4.5.0"} ] } diff --git a/spec/acceptance/apt_key_provider_spec.rb b/spec/acceptance/apt_key_provider_spec.rb index 1f703c9ce6..f1f232e7a9 100644 --- a/spec/acceptance/apt_key_provider_spec.rb +++ b/spec/acceptance/apt_key_provider_spec.rb @@ -202,6 +202,187 @@ end end + context 'multiple keys' do + it 'runs without errors' do + pp = <<-EOS + apt_key { 'puppetlabs': + id => '#{PUPPETLABS_GPG_KEY_FINGERPRINT}', + ensure => 'present', + content => "-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v1.4.12 (GNU/Linux) +Comment: GPGTools - http://gpgtools.org + +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 +=Gl+v +-----END PGP PUBLIC KEY BLOCK-----", + } + EOS + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_failures => true) + shell(PUPPETLABS_KEY_CHECK_COMMAND) + end + end + context 'bogus key' do it 'fails' do pp = <<-EOS @@ -488,14 +669,14 @@ end end - describe 'keyserver_options =>' do + describe 'options =>' do context 'debug' do it 'works' do pp = <<-EOS apt_key { 'puppetlabs': - id => '#{PUPPETLABS_GPG_KEY_LONG_ID}', - ensure => 'present', - keyserver_options => 'debug', + id => '#{PUPPETLABS_GPG_KEY_LONG_ID}', + ensure => 'present', + options => 'debug', } EOS @@ -507,9 +688,9 @@ it 'fails on invalid options' do pp = <<-EOS apt_key { 'puppetlabs': - id => '#{PUPPETLABS_GPG_KEY_LONG_ID}', - ensure => 'present', - keyserver_options => 'this is totally bonkers', + id => '#{PUPPETLABS_GPG_KEY_LONG_ID}', + ensure => 'present', + options => 'this is totally bonkers', } EOS diff --git a/spec/acceptance/apt_spec.rb b/spec/acceptance/apt_spec.rb index 9ace221809..c948df2ac2 100644 --- a/spec/acceptance/apt_spec.rb +++ b/spec/acceptance/apt_spec.rb @@ -12,24 +12,28 @@ it 'should work with no errors' 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 => { + update => { + 'frequency' => 'always', + 'timeout' => '400', + 'tries' => '3', + }, + purge => { + 'sources.list' => true, + 'sources.list.d' => true, + 'preferences' => true, + 'preferences.d' => true, + }, + sources => { 'puppetlabs' => { - 'ensure' => present, - 'location' => 'http://apt.puppetlabs.com', - 'repos' => 'main', - 'key' => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30', - 'key_server' => 'pgp.mit.edu', - } + 'ensure' => present, + 'location' => 'http://apt.puppetlabs.com', + 'repos' => 'main', + 'key' => { + 'id' => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30', + 'server' => 'pgp.mit.edu', + }, + }, }, - fancy_progress => true, } EOS diff --git a/spec/classes/apt_backports_spec.rb b/spec/classes/apt_backports_spec.rb new file mode 100644 index 0000000000..b9077a6bcd --- /dev/null +++ b/spec/classes/apt_backports_spec.rb @@ -0,0 +1,261 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe 'apt::backports', :type => :class do + let (:pre_condition) { "class{ '::apt': }" } + describe 'debian/ubuntu tests' do + context 'defaults on deb' do + let(:facts) do + { + :lsbdistid => 'Debian', + :osfamily => 'Debian', + :lsbdistcodename => 'wheezy', + } + end + it { is_expected.to contain_apt__source('backports').with({ + :location => 'http://ftp.debian.org/debian/', + :key => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', + :repos => 'main contrib non-free', + :release => 'wheezy-backports', + :pin => 200, + }) + } + end + context 'defaults on squeeze' do + let(:facts) do + { + :lsbdistid => 'Debian', + :osfamily => 'Debian', + :lsbdistcodename => 'squeeze', + } + end + it { is_expected.to contain_apt__source('backports').with({ + :location => 'http://backports.debian.org/debian-backports', + :key => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', + :repos => 'main contrib non-free', + :release => 'squeeze-backports', + :pin => 200, + }) + } + end + context 'defaults on ubuntu' do + let(:facts) do + { + :lsbdistid => 'Ubuntu', + :osfamily => 'Debian', + :lsbdistcodename => 'trusty', + } + end + it { is_expected.to contain_apt__source('backports').with({ + :location => 'http://archive.ubuntu.com/ubuntu', + :key => '630239CC130E1A7FD81A27B140976EAF437D05B5', + :repos => 'main universe multiverse restricted', + :release => 'trusty-backports', + :pin => 200, + }) + } + end + context 'set everything' do + let(:facts) do + { + :lsbdistid => 'Ubuntu', + :osfamily => 'Debian', + :lsbdistcodename => 'trusty', + } + end + let(:params) do + { + :location => 'http://archive.ubuntu.com/ubuntu-test', + :release => 'vivid', + :repos => 'main', + :key => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', + :pin => '90', + } + end + it { is_expected.to contain_apt__source('backports').with({ + :location => 'http://archive.ubuntu.com/ubuntu-test', + :key => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', + :repos => 'main', + :release => 'vivid', + :pin => 90, + }) + } + end + context 'set things with hashes' do + let(:facts) do + { + :lsbdistid => 'Ubuntu', + :osfamily => 'Debian', + :lsbdistcodename => 'trusty', + } + end + let(:params) do + { + :key => { + 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', + }, + :pin => { + 'priority' => '90', + }, + } + end + it { is_expected.to contain_apt__source('backports').with({ + :key => { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' }, + :pin => { 'priority' => '90' }, + }) + } + end + end + describe 'mint tests' do + let(:facts) do + { + :lsbdistid => 'linuxmint', + :osfamily => 'Debian', + :lsbdistcodename => 'qiana', + } + end + context 'sets all the needed things' do + let(:params) do + { + :location => 'http://archive.ubuntu.com/ubuntu', + :release => 'trusty-backports', + :repos => 'main universe multiverse restricted', + :key => '630239CC130E1A7FD81A27B140976EAF437D05B5', + } + end + it { is_expected.to contain_apt__source('backports').with({ + :location => 'http://archive.ubuntu.com/ubuntu', + :key => '630239CC130E1A7FD81A27B140976EAF437D05B5', + :repos => 'main universe multiverse restricted', + :release => 'trusty-backports', + :pin => 200, + }) + } + end + context 'missing location' do + let(:params) do + { + :release => 'trusty-backports', + :repos => 'main universe multiverse restricted', + :key => '630239CC130E1A7FD81A27B140976EAF437D05B5', + } + end + it do + expect { + is_expected.to compile + }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/) + end + end + context 'missing release' do + let(:params) do + { + :location => 'http://archive.ubuntu.com/ubuntu', + :repos => 'main universe multiverse restricted', + :key => '630239CC130E1A7FD81A27B140976EAF437D05B5', + } + end + it do + expect { + is_expected.to compile + }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/) + end + end + context 'missing repos' do + let(:params) do + { + :location => 'http://archive.ubuntu.com/ubuntu', + :release => 'trusty-backports', + :key => '630239CC130E1A7FD81A27B140976EAF437D05B5', + } + end + it do + expect { + is_expected.to compile + }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/) + end + end + context 'missing key' do + let(:params) do + { + :location => 'http://archive.ubuntu.com/ubuntu', + :release => 'trusty-backports', + :repos => 'main universe multiverse restricted', + } + end + it do + expect { + is_expected.to compile + }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/) + end + end + end + describe 'validation' do + let(:facts) do + { + :lsbdistid => 'Ubuntu', + :osfamily => 'Debian', + :lsbdistcodename => 'trusty', + } + end + context 'invalid location' do + let(:params) do + { + :location => true + } + end + it do + expect { + is_expected.to compile + }.to raise_error(Puppet::Error, /is not a string/) + end + end + context 'invalid release' do + let(:params) do + { + :release => true + } + end + it do + expect { + is_expected.to compile + }.to raise_error(Puppet::Error, /is not a string/) + end + end + context 'invalid repos' do + let(:params) do + { + :repos => true + } + end + it do + expect { + is_expected.to compile + }.to raise_error(Puppet::Error, /is not a string/) + end + end + context 'invalid key' do + let(:params) do + { + :key => true + } + end + it do + expect { + is_expected.to compile + }.to raise_error(Puppet::Error, /is not a string/) + end + end + context 'invalid pin' do + let(:params) do + { + :pin => true + } + end + it do + expect { + is_expected.to compile + }.to raise_error(Puppet::Error, /pin must be either a string, number or hash/) + end + end + end +end diff --git a/spec/classes/apt_spec.rb b/spec/classes/apt_spec.rb index d3ef34dfa3..ee7cd33a24 100644 --- a/spec/classes/apt_spec.rb +++ b/spec/classes/apt_spec.rb @@ -1,143 +1,128 @@ require 'spec_helper' -describe 'apt', :type => :class do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } +describe 'apt' do + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy'} } 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 { is_expected.to contain_file('sources.list').that_notifies('Exec[apt_update]').only_with({ + :ensure => 'file', + :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 { is_expected.to contain_file('sources.list.d').that_notifies('Exec[apt_update]').only_with({ + :ensure => 'directory', + :path => '/etc/apt/sources.list.d', + :owner => 'root', + :group => 'root', + :mode => '0644', + :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 { is_expected.to contain_file('preferences').that_notifies('Exec[apt_update]').only_with({ + :ensure => 'file', + :path => '/etc/apt/preferences', + :owner => 'root', + :group => 'root', + :mode => '0644', + :notify => 'Exec[apt_update]', })} - 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 { is_expected.to contain_file('preferences.d').that_notifies('Exec[apt_update]').only_with({ + :ensure => 'directory', + :path => '/etc/apt/preferences.d', + :owner => 'root', + :group => 'root', + :mode => '0644', + :purge => false, + :recurse => false, + :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', + is_expected.to 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 { is_expected.to contain_exec('apt_update').with({ + :refreshonly => 'true', })} - it { should contain_exec('apt_update').with({ - 'refreshonly' => 'true', - })} + it { is_expected.not_to contain_apt__setting('conf-proxy') } end + describe 'proxy=' do + context 'host=localhost' do + let(:params) { { :proxy => { 'host' => 'localhost'} } } + it { is_expected.to contain_apt__setting('conf-proxy').with({ + :priority => '01', + }).with_content( + /Acquire::http::proxy "http:\/\/localhost:8080\/";/ + ).without_content( + /Acquire::https::proxy/ + )} + end + + context 'host=localhost and port=8180' do + let(:params) { { :proxy => { 'host' => 'localhost', 'port' => 8180} } } + it { is_expected.to contain_apt__setting('conf-proxy').with({ + :priority => '01', + }).with_content( + /Acquire::http::proxy "http:\/\/localhost:8180\/";/ + ).without_content( + /Acquire::https::proxy/ + )} + end + + context 'host=localhost and https=true' do + let(:params) { { :proxy => { 'host' => 'localhost', 'https' => true} } } + it { is_expected.to contain_apt__setting('conf-proxy').with({ + :priority => '01', + }).with_content( + /Acquire::http::proxy "http:\/\/localhost:8080\/";/ + ).with_content( + /Acquire::https::proxy "https:\/\/localhost:8080\/";/ + )} + end + 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, + :update => { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 }, + :purge => { 'sources.list' => false, 'sources.list.d' => false, + 'preferences' => false, 'preferences.d' => false, }, } end - it { should contain_file('sources.list').with({ - 'content' => "# Repos managed by puppet.\n" - })} - - it { should contain_file('sources.list.d').with({ - 'purge' => 'true', - 'recurse' => 'true', - })} - - 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 { is_expected.to contain_file('sources.list').without({ + :content => "# Repos managed by puppet.\n", })} - it { should contain_file('99progressbar').only_with({ - 'ensure' => 'present', - 'content' => /Dpkg::Progress-Fancy "1";/, - 'path' => '/etc/apt/apt.conf.d/99progressbar', + it { is_expected.to contain_file('sources.list.d').with({ + :purge => false, + :recurse => false, })} - it { should contain_file('99unauth').only_with({ - 'ensure' => 'present', - 'content' => /APT::Get::AllowUnauthenticated 1;/, - 'path' => '/etc/apt/apt.conf.d/99unauth', + it { is_expected.to contain_file('preferences').with({ + :ensure => 'file', })} - 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";/, - 'notify' => 'Exec[apt_update]', - 'mode' => '0644', - 'owner' => 'root', - 'group' => 'root' + it { is_expected.to contain_file('preferences.d').with({ + :purge => false, + :recurse => false, })} - 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, - } - 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', + it { is_expected.to contain_exec('apt_update').with({ + :refreshonly => false, + :timeout => 1, + :tries => 3, })} end @@ -154,98 +139,125 @@ 'location' => 'http://debian.mirror.iweb.ca/debian/', 'release' => 'unstable', 'repos' => 'main contrib non-free', - 'required_packages' => 'debian-keyring debian-archive-keyring', - 'key' => '150C8614919D8446E01E83AF9AA38DCD55BE302B', - 'key_server' => 'subkeys.pgp.net', + 'key' => { 'id' => '150C8614919D8446E01E83AF9AA38DCD55BE302B', 'server' => 'subkeys.pgp.net' }, 'pin' => '-10', - 'include_src' => true + 'include' => {'src' => true,}, }, 'puppetlabs' => { 'location' => 'http://apt.puppetlabs.com', 'repos' => 'main', - 'key' => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30', - 'key_server' => 'pgp.mit.edu', + 'key' => { 'id' => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30', '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]', + is_expected.to contain_apt__setting('list-debian_unstable').with({ + :ensure => 'present', }) } - 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 { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) } + it { is_expected.to contain_file('/etc/apt/sources.list.d/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]', + is_expected.to contain_apt__setting('list-puppetlabs').with({ + :ensure => 'present', }) } - 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$/) } + it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) } + end + + context 'with keys defined on valid osfamily' do + let :facts do + { :osfamily => 'Debian', + :lsbdistcodename => 'precise', + :lsbdistid => 'Debian', + } + end + let(:params) { { :keys => { + '55BE302B' => { + 'server' => 'subkeys.pgp.net', + }, + '4BD6EC30' => { + 'server' => 'pgp.mit.edu', + } + } } } + + it { is_expected.to contain_apt__key('55BE302B').with({ + :server => 'subkeys.pgp.net', + })} + + it { is_expected.to contain_apt__key('4BD6EC30').with({ + :server => 'pgp.mit.edu', + })} + end + + context 'with ppas defined on valid osfamily' do + let :facts do + { :osfamily => 'Debian', + :lsbdistcodename => 'precise', + :lsbdistid => 'ubuntu', + } + end + let(:params) { { :ppas => { + 'ppa:drizzle-developers/ppa' => {}, + 'ppa:nginx/stable' => {}, + } } } + + it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa')} + it { is_expected.to contain_apt__ppa('ppa:nginx/stable')} + end + + context 'with settings defined on valid osfamily' do + let :facts do + { :osfamily => 'Debian', + :lsbdistcodename => 'precise', + :lsbdistid => 'Debian', + } + end + let(:params) { { :settings => { + 'conf-banana' => { 'content' => 'banana' }, + 'pref-banana' => { 'content' => 'banana' }, + } } } + + it { is_expected.to contain_apt__setting('conf-banana')} + it { is_expected.to contain_apt__setting('pref-banana')} end describe 'failing tests' do - context 'bad purge_sources_list' do - let :params do - { - 'purge_sources_list' => 'foo' - } - end + context "purge['sources.list']=>'banana'" do + let(:params) { { :purge => { 'sources.list' => 'banana' }, } } it do expect { - should compile + is_expected.to compile }.to raise_error(Puppet::Error) end end - context 'bad purge_sources_list_d' do - let :params do - { - 'purge_sources_list_d' => 'foo' - } - end + context "purge['sources.list.d']=>'banana'" do + let(:params) { { :purge => { 'sources.list.d' => 'banana' }, } } it do expect { - should compile + is_expected.to compile }.to raise_error(Puppet::Error) end end - context 'bad purge_preferences' do - let :params do - { - 'purge_preferences' => 'foo' - } - end + context "purge['preferences']=>'banana'" do + let(:params) { { :purge => { 'preferences' => 'banana' }, } } it do expect { - should compile + is_expected.to compile }.to raise_error(Puppet::Error) end end - context 'bad purge_preferences_d' do - let :params do - { - 'purge_preferences_d' => 'foo' - } - end + context "purge['preferences.d']=>'banana'" do + let(:params) { { :purge => { 'preferences.d' => 'banana' }, } } it do expect { - should compile + is_expected.to compile }.to raise_error(Puppet::Error) end end @@ -257,7 +269,7 @@ it do expect { - should compile + is_expected.to compile }.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/) end end diff --git a/spec/classes/apt_update_spec.rb b/spec/classes/apt_update_spec.rb index d70efd37d1..8fba4a0c98 100644 --- a/spec/classes/apt_update_spec.rb +++ b/spec/classes/apt_update_spec.rb @@ -2,106 +2,72 @@ 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 + context "and apt::update['frequency']='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, :lsbdistcodename => 'wheezy' } } + let (:pre_condition) { "class{'::apt': update => {'frequency' => 'always' },}" } + it 'should trigger an apt-get update run' do + #set the apt_update exec's refreshonly attribute to false + is_expected.to 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', :lsbdistcodename => 'wheezy' } } + let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'always' },}" } + it 'should trigger an apt-get update run' do + #set the apt_update exec\'s refreshonly attribute to false + is_expected.to contain_exec('apt_update').with({'refreshonly' => false}) + 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 + context "and apt::update['frequency']='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, :lsbdistcodename => 'wheezy'} } + let (:pre_condition) { "class{ '::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) + is_expected.to 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 => '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 + context 'when $::apt_update_last_success is nil' do + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } } + let (:pre_condition) { "class{ '::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) + is_expected.to contain_exec('apt_update').with({'refreshonly' => true}) 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| + end + ['daily','weekly'].each do |update_frequency| + context "and 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 => '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}) + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy' } } + let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" } + it 'should trigger an apt-get update run' do + #set the apt_update exec\'s refreshonly attribute to false + is_expected.to 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 => 'reluctantly' }" } + context 'when the $::apt_update_last_success fact has a recent value' do + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => Time.now.to_i } } + let (:pre_condition) { "class{ '::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}) + #don't change the apt_update exec\'s refreshonly attribute. (it should be true) + is_expected.to 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 + context 'when $::apt_update_last_success is nil' do + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => nil } } + let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" } + it 'should trigger an apt-get update run' do + #set the apt_update exec\'s refreshonly attribute to false + is_expected.to contain_exec('apt_update').with({'refreshonly' => false}) end end end diff --git a/spec/classes/backports_spec.rb b/spec/classes/backports_spec.rb deleted file mode 100644 index 721a4a613c..0000000000 --- a/spec/classes/backports_spec.rb +++ /dev/null @@ -1,177 +0,0 @@ -require 'spec_helper' -describe 'apt::backports', :type => :class do - - describe 'when asigning a custom priority to backports' do - let :facts do - { - 'lsbdistcodename' => 'Karmic', - 'lsbdistid' => 'Ubuntu', - 'osfamily' => 'Debian' - } - end - - context 'integer priority' do - let :params do { :pin_priority => 500 } end - - it { should contain_apt__source('backports').with({ - 'location' => 'http://old-releases.ubuntu.com/ubuntu', - 'release' => 'karmic-backports', - 'repos' => 'main universe multiverse restricted', - 'key' => '630239CC130E1A7FD81A27B140976EAF437D05B5', - 'key_server' => 'pgp.mit.edu', - }) - } - - it { should contain_apt__pin('backports').with({ - 'release' => 'karmic-backports', - 'priority' => 500, - }) - } - end - - context 'invalid priority' do - let :params do { :pin_priority => 'banana' } end - it 'should fail' do - expect { subject }.to raise_error(/must be an integer/) - end - end - end - - describe 'when turning on backports for ubuntu karmic' do - - let :facts do - { - 'lsbdistcodename' => 'Karmic', - 'lsbdistid' => 'Ubuntu', - 'osfamily' => 'Debian' - } - end - - it { should contain_apt__source('backports').with({ - 'location' => 'http://old-releases.ubuntu.com/ubuntu', - 'release' => 'karmic-backports', - 'repos' => 'main universe multiverse restricted', - 'key' => '630239CC130E1A7FD81A27B140976EAF437D05B5', - 'key_server' => 'pgp.mit.edu', - }) - } - - it { should contain_apt__pin('backports').with({ - 'release' => 'karmic-backports', - 'priority' => 200, - }) - } - end - - describe "when turning on backports for debian squeeze" do - - let :facts do - { - 'lsbdistcodename' => 'Squeeze', - 'lsbdistid' => 'Debian', - 'osfamily' => 'Debian' - } - end - - it { should contain_apt__source('backports').with({ - 'location' => 'http://backports.debian.org/debian-backports', - 'release' => 'squeeze-backports', - 'repos' => 'main contrib non-free', - 'key' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', - 'key_server' => 'pgp.mit.edu', - }) - } - - it { should contain_apt__pin('backports').with({ - 'release' => 'squeeze-backports', - 'priority' => 200, - }) - } - 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' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', - 'key_server' => 'pgp.mit.edu', - }) - } - - it { should contain_apt__pin('backports').with({ - 'release' => 'wheezy-backports', - 'priority' => 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' => '630239CC130E1A7FD81A27B140976EAF437D05B5', - 'key_server' => 'pgp.mit.edu', - }) - } - - it { should contain_apt__pin('backports').with({ - 'release' => 'trusty-backports', - 'priority' => 200, - }) - } - end - - describe "when turning on backports for debian squeeze but using your own mirror" do - - let :facts do - { - 'lsbdistcodename' => 'Squeeze', - 'lsbdistid' => 'Debian', - 'osfamily' => 'Debian' - } - end - - let :location do - 'http://mirrors.example.com/debian-backports' - end - - let :params do - { 'location' => location } - end - - it { should contain_apt__source('backports').with({ - 'location' => location, - 'release' => 'squeeze-backports', - 'repos' => 'main contrib non-free', - 'key' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', - 'key_server' => 'pgp.mit.edu', - }) - } - - it { should contain_apt__pin('backports').with({ - 'release' => 'squeeze-backports', - 'priority' => 200, - }) - } - end -end diff --git a/spec/classes/debian_testing_spec.rb b/spec/classes/debian_testing_spec.rb deleted file mode 100644 index a2e35f5479..0000000000 --- a/spec/classes/debian_testing_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' -describe 'apt::debian::testing', :type => :class do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } - it { - should contain_apt__source("debian_testing").with({ - "location" => "http://debian.mirror.iweb.ca/debian/", - "release" => "testing", - "repos" => "main contrib non-free", - "required_packages" => "debian-keyring debian-archive-keyring", - "key" => "A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553", - "key_server" => "subkeys.pgp.net", - "pin" => "-10" - }) - } -end diff --git a/spec/classes/debian_unstable_spec.rb b/spec/classes/debian_unstable_spec.rb deleted file mode 100644 index 14d8650ffe..0000000000 --- a/spec/classes/debian_unstable_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' -describe 'apt::debian::unstable', :type => :class do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } - it { - should contain_apt__source("debian_unstable").with({ - "location" => "http://debian.mirror.iweb.ca/debian/", - "release" => "unstable", - "repos" => "main contrib non-free", - "required_packages" => "debian-keyring debian-archive-keyring", - "key" => "A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553", - "key_server" => "subkeys.pgp.net", - "pin" => "-10" - }) - } -end diff --git a/spec/classes/params_spec.rb b/spec/classes/params_spec.rb index d85e849d5a..f8599b3699 100644 --- a/spec/classes/params_spec.rb +++ b/spec/classes/params_spec.rb @@ -1,37 +1,24 @@ require 'spec_helper' describe 'apt::params', :type => :class do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } } let (:title) { 'my_package' } - it { should contain_apt__params } + it { is_expected.to contain_apt__params } # There are 4 resources in this class currently # there should not be any more resources because it is a params class # The resources are class[apt::params], class[main], class[settings], stage[main] it "Should not contain any resources" do - subject.resources.size.should == 4 - end - - describe "With unknown lsbdistid" do - - let(:facts) { { :lsbdistid => 'CentOS' } } - let (:title) { 'my_package' } - - it do - expect { - should compile - }.to raise_error(Puppet::Error, /Unsupported lsbdistid/) - end - + expect(subject.resources.size).to eq(4) end describe "With lsb-release not installed" do - let(:facts) { { :lsbdistid => '' } } + let(:facts) { { :lsbdistid => '', :osfamily => 'Debian' } } let (:title) { 'my_package' } it do expect { - should compile + is_expected.to compile }.to raise_error(Puppet::Error, /Unable to determine lsbdistid, is lsb-release installed/) end end diff --git a/spec/classes/release_spec.rb b/spec/classes/release_spec.rb deleted file mode 100644 index f8c6512840..0000000000 --- a/spec/classes/release_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'spec_helper' -describe 'apt::release', :type => :class do - let(:facts) { { :lsbdistid => 'Debian' } } - let (:title) { 'my_package' } - - let :param_set do - { :release_id => 'precise' } - end - - let (:params) { param_set } - - it { should contain_class("apt::params") } - - it { - should contain_file("/etc/apt/apt.conf.d/01release").with({ - "mode" => "0644", - "owner" => "root", - "group" => "root", - "content" => /APT::Default-Release "#{param_set[:release_id]}";/ - }) - } -end - diff --git a/spec/classes/unattended_upgrades_spec.rb b/spec/classes/unattended_upgrades_spec.rb deleted file mode 100644 index 0a02755536..0000000000 --- a/spec/classes/unattended_upgrades_spec.rb +++ /dev/null @@ -1,211 +0,0 @@ -require 'spec_helper' -describe 'apt::unattended_upgrades', :type => :class do - let(:file_unattended) { '/etc/apt/apt.conf.d/50unattended-upgrades' } - let(:file_periodic) { '/etc/apt/apt.conf.d/10periodic' } - let(:facts) { { :lsbdistid => 'Debian' } } - - it { should contain_package("unattended-upgrades") } - - it { - should create_file("/etc/apt/apt.conf.d/50unattended-upgrades").with({ - "owner" => "root", - "group" => "root", - "mode" => "0644", - "require" => "Package[unattended-upgrades]", - }) - } - - it { - should create_file("/etc/apt/apt.conf.d/10periodic").with({ - "owner" => "root", - "group" => "root", - "mode" => "0644", - "require" => "Package[unattended-upgrades]", - }) - } - - 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 - - context 'bad minimal_steps' do - let :params do - { - 'minimal_steps' => 'foo', - } - end - it { expect { should raise_error(Puppet::Error) } } - end - - context 'bad install_on_shutdown' do - let :params do - { - 'install_on_shutdown' => 'foo', - } - end - it { expect { should raise_error(Puppet::Error) } } - end - - context 'bad mail_only_on_error' do - let :params do - { - 'mail_only_on_error' => 'foo', - } - end - it { expect { should raise_error(Puppet::Error) } } - end - - context 'bad remove_unused' do - let :params do - { - 'remove_unused' => 'foo', - } - end - it { expect { should raise_error(Puppet::Error) } } - end - - context 'bad auto_reboot' do - let :params do - { - 'auto_reboot' => 'foo', - } - end - it { expect { should raise_error(Puppet::Error) } } - end - - context 'bad origins' do - let :params do - { - 'origins' => 'foo' - } - end - 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 - 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 'wheezy' do - let :facts do - { - 'lsbdistid' => 'debian', - 'lsbdistcodename' => 'wheezy', - } - end - - it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Origins-Pattern \{\n\t"origin=Debian,archive=stable,label=Debian-Security";\n\t"origin=Debian,archive=oldstable,label=Debian-Security";\n\};} } - end - - context 'anything but defaults' do - let :facts do - { - 'lsbdistid' => 'debian', - 'lsbdistcodename' => 'wheezy', - } - end - - let :params do - { - 'legacy_origin' => true, - '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::Allowed-Origins \{\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";}} - - end -end diff --git a/spec/defines/builddep_spec.rb b/spec/defines/builddep_spec.rb deleted file mode 100644 index 41152d5c9b..0000000000 --- a/spec/defines/builddep_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'spec_helper' -describe 'apt::builddep', :type => :define do - - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } - let(:title) { 'my_package' } - - 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({ - 'require' => 'Class[Apt::Update]', - }) - } - end - -end diff --git a/spec/defines/conf_spec.rb b/spec/defines/conf_spec.rb index 2c1752f074..e96f8bcd82 100644 --- a/spec/defines/conf_spec.rb +++ b/spec/defines/conf_spec.rb @@ -1,6 +1,9 @@ require 'spec_helper' describe 'apt::conf', :type => :define do - let(:facts) { { :lsbdistid => 'Debian' } } + let :pre_condition do + 'class { "apt": }' + end + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } } let :title do 'norecommends' end @@ -17,7 +20,7 @@ "/etc/apt/apt.conf.d/00norecommends" end - it { should contain_file(filename).with({ + it { is_expected.to contain_file(filename).with({ 'ensure' => 'present', 'content' => /Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;/, 'owner' => 'root', @@ -27,12 +30,23 @@ } end + describe "when creating a preference without content" do + let :params do + { + :priority => '00', + } + end + + it 'fails' do + expect { subject } .to raise_error(/pass in content/) + end + end + describe "when removing an apt preference" do let :params do { :ensure => 'absent', :priority => '00', - :content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n" } end @@ -40,9 +54,8 @@ "/etc/apt/apt.conf.d/00norecommends" end - it { should contain_file(filename).with({ + it { is_expected.to contain_file(filename).with({ 'ensure' => 'absent', - 'content' => /Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;/, 'owner' => 'root', 'group' => 'root', 'mode' => '0644', diff --git a/spec/defines/force_spec.rb b/spec/defines/force_spec.rb deleted file mode 100644 index c32c438c59..0000000000 --- a/spec/defines/force_spec.rb +++ /dev/null @@ -1,102 +0,0 @@ -require 'spec_helper' -describe 'apt::force', :type => :define do - let(:facts) { { :lsbdistid => 'Debian' } } - let :pre_condition do - 'include apt::params' - end - - let :title do - 'my_package' - end - - let :default_params do - { - :release => false, - :version => false, - :cfg_files => 'none', - :cfg_missing => false, - } - end - - describe "when using default parameters" do - it { should contain_exec("/usr/bin/apt-get -y install #{title}").with( - :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'", - :logoutput => 'on_failure', - :timeout => '300' - ) } - end - - describe "when specifying release parameter" 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( - :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 - - describe "when specifying version parameter" do - let :params do - default_params.merge(:version => '1') - end - it { should contain_exec("/usr/bin/apt-get -y install #{title}=#{params[:version]}").with( - :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Version: #{params[:version]}'" - ) } - end - - describe "when specifying cfg_files parameter" do - let :params do - default_params.merge(:cfg_files => 'unchanged') - end - it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confdef" install my_package').with( - :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'" - ) } - end - - describe "when specifying cfg_missing parameter" do - let :params do - default_params.merge(:cfg_missing => true) - end - it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confmiss" install my_package').with( - :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'" - ) } - end - - describe "when specifying cfg_files and cfg_missing parameter" do - let :params do - default_params.merge( - :cfg_files => 'unchanged', - :cfg_missing => true - ) - end - it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confmiss" install my_package').with( - :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'" - ) } - end - - describe "when specifying release and version parameters" do - let :params do - default_params.merge( - :release => 'testing', - :version => '1' - ) - end - it { should contain_exec("/usr/bin/apt-get -y -t #{params[:release]} install #{title}=1").with( - :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 deleted file mode 100644 index 60b991f194..0000000000 --- a/spec/defines/hold_spec.rb +++ /dev/null @@ -1,97 +0,0 @@ -require 'spec_helper' -describe 'apt::hold' do - let :facts do { - :osfamily => 'Debian', - :lsbdistid => 'Debian', - :lsbrelease => 'wheezy', - } end - - let :title do - 'vim' - end - - let :default_params do { - :version => '1.1.1', - } end - - describe 'default params' do - let :params do default_params end - - it 'creates an apt preferences file' do - should contain_apt__pin("hold_#{title}").with({ - :ensure => 'present', - :packages => title, - :version => params[:version], - :priority => 1001, - }) - end - end - - describe 'ensure => absent' do - let :params do default_params.merge({:ensure => 'absent',}) end - - it 'creates an apt preferences file' do - - should contain_apt__pin("hold_#{title}").with({ - :ensure => params[:ensure], - }) - end - end - - describe 'priority => 990' do - let :params do default_params.merge({:priority => 990,}) end - - it 'creates an apt preferences file' do - should contain_apt__pin("hold_#{title}").with({ - :ensure => 'present', - :packages => title, - :version => params[:version], - :priority => params[:priority], - }) - end - end - - 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 => 'foo', - :version => params[:version], - :priority => 1001, - }) - end - end - - - describe 'validation' do - context 'version => {}' do - let :params do { :version => {}, } end - it 'should fail' do - expect { subject }.to raise_error(/is not a string/) - end - end - - context 'ensure => bananana' do - let :params do default_params.merge({:ensure => 'bananana',}) end - it 'should fail' do - expect { subject }.to raise_error(/does not match/) - end - end - - context 'package => []' do - let :params do default_params.merge({:package => [],}) end - it 'should fail' do - expect { subject }.to raise_error(/is not a string/) - end - end - - context 'priority => bananana' do - let :params do default_params.merge({:priority => 'bananana',}) end - it 'should fail' do - expect { subject }.to raise_error(/must be an integer/) - end - end - end -end diff --git a/spec/defines/key_spec.rb b/spec/defines/key_spec.rb index 7ac1d28130..b9bcea845a 100644 --- a/spec/defines/key_spec.rb +++ b/spec/defines/key_spec.rb @@ -1,7 +1,12 @@ require 'spec_helper' -describe 'apt::key', :type => :define do - let(:facts) { { :lsbdistid => 'Debian' } } +describe 'apt::key' do + let :pre_condition do + 'class { "apt": }' + end + + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } } + GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30' let :title do @@ -11,17 +16,17 @@ describe 'normal operation' do describe 'default options' do it 'contains the apt_key' do - should contain_apt_key(title).with({ - :id => title, - :ensure => 'present', - :source => nil, - :server => nil, - :content => nil, - :keyserver_options => nil, + is_expected.to contain_apt_key(title).with({ + :id => title, + :ensure => 'present', + :source => nil, + :server => 'keyserver.ubuntu.com', + :content => nil, + :options => nil, }) end it 'contains the apt_key present anchor' do - should contain_anchor("apt_key #{title} present") + is_expected.to contain_anchor("apt_key #{title} present") end end @@ -31,21 +36,21 @@ end let :params do { - :key => GPG_KEY_ID, + :id => GPG_KEY_ID, } end it 'contains the apt_key' do - should contain_apt_key(title).with({ - :id => GPG_KEY_ID, - :ensure => 'present', - :source => nil, - :server => nil, - :content => nil, - :keyserver_options => nil, + is_expected.to contain_apt_key(title).with({ + :id => GPG_KEY_ID, + :ensure => 'present', + :source => nil, + :server => 'keyserver.ubuntu.com', + :content => nil, + :options => nil, }) end it 'contains the apt_key present anchor' do - should contain_anchor("apt_key #{GPG_KEY_ID} present") + is_expected.to contain_anchor("apt_key #{GPG_KEY_ID} present") end end @@ -55,49 +60,49 @@ } end it 'contains the apt_key' do - should contain_apt_key(title).with({ - :id => title, - :ensure => 'absent', - :source => nil, - :server => nil, - :content => nil, - :keyserver_options => nil, + is_expected.to contain_apt_key(title).with({ + :id => title, + :ensure => 'absent', + :source => nil, + :server => 'keyserver.ubuntu.com', + :content => nil, + :keyserver => nil, }) end it 'contains the apt_key absent anchor' do - should contain_anchor("apt_key #{title} absent") + is_expected.to contain_anchor("apt_key #{title} absent") end end 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', + :content => 'GPG key content', + :source => 'http://apt.puppetlabs.com/pubkey.gpg', + :server => 'pgp.mit.edu', + :options => 'debug', } end it 'contains the apt_key' do - should contain_apt_key(title).with({ - :id => title, - :ensure => 'present', - :source => 'http://apt.puppetlabs.com/pubkey.gpg', - :server => 'pgp.mit.edu', - :content => params[:key_content], - :keyserver_options => 'debug', + is_expected.to contain_apt_key(title).with({ + :id => title, + :ensure => 'present', + :source => 'http://apt.puppetlabs.com/pubkey.gpg', + :server => 'pgp.mit.edu', + :content => params[:content], + :options => 'debug', }) end it 'contains the apt_key present anchor' do - should contain_anchor("apt_key #{title} present") + is_expected.to contain_anchor("apt_key #{title} present") end end context "domain with dash" do let(:params) do{ - :key_server => 'p-gp.m-it.edu', + :server => 'p-gp.m-it.edu', } end it 'contains the apt_key' do - should contain_apt_key(title).with({ + is_expected.to contain_apt_key(title).with({ :id => title, :server => 'p-gp.m-it.edu', }) @@ -107,11 +112,11 @@ context "url" do let :params do { - :key_server => 'hkp://pgp.mit.edu', + :server => 'hkp://pgp.mit.edu', } end it 'contains the apt_key' do - should contain_apt_key(title).with({ + is_expected.to contain_apt_key(title).with({ :id => title, :server => 'hkp://pgp.mit.edu', }) @@ -120,11 +125,11 @@ context "url with port number" do let :params do { - :key_server => 'hkp://pgp.mit.edu:80', + :server => 'hkp://pgp.mit.edu:80', } end it 'contains the apt_key' do - should contain_apt_key(title).with({ + is_expected.to contain_apt_key(title).with({ :id => title, :server => 'hkp://pgp.mit.edu:80', }) @@ -135,7 +140,7 @@ describe 'validation' do context "domain begin with dash" do let(:params) do{ - :key_server => '-pgp.mit.edu', + :server => '-pgp.mit.edu', } end it 'fails' do expect { subject } .to raise_error(/does not match/) @@ -144,7 +149,7 @@ context "domain begin with dot" do let(:params) do{ - :key_server => '.pgp.mit.edu', + :server => '.pgp.mit.edu', } end it 'fails' do expect { subject } .to raise_error(/does not match/) @@ -153,7 +158,7 @@ context "domain end with dot" do let(:params) do{ - :key_server => "pgp.mit.edu.", + :server => "pgp.mit.edu.", } end it 'fails' do expect { subject } .to raise_error(/does not match/) @@ -162,7 +167,7 @@ context "exceed character url" do let :params do { - :key_server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu' + :server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu' } end it 'fails' do @@ -172,7 +177,7 @@ context "incorrect port number url" do let :params do { - :key_server => 'hkp://pgp.mit.edu:8008080' + :server => 'hkp://pgp.mit.edu:8008080' } end it 'fails' do @@ -182,7 +187,7 @@ context "incorrect protocol for url" do let :params do { - :key_server => 'abc://pgp.mit.edu:80' + :server => 'abc://pgp.mit.edu:80' } end it 'fails' do @@ -192,7 +197,7 @@ context "missing port number url" do let :params do { - :key_server => 'hkp://pgp.mit.edu:' + :server => 'hkp://pgp.mit.edu:' } end it 'fails' do @@ -202,7 +207,7 @@ context "url ending with a dot" do let :params do { - :key_server => 'hkp://pgp.mit.edu.' + :server => 'hkp://pgp.mit.edu.' } end it 'fails' do @@ -211,7 +216,7 @@ end context "url begin with a dash" do let(:params) do{ - :key_server => "hkp://-pgp.mit.edu", + :server => "hkp://-pgp.mit.edu", } end it 'fails' do expect { subject }.to raise_error(/does not match/) @@ -228,7 +233,7 @@ context 'invalid source' do let :params do { - :key_source => 'afp://puppetlabs.com/key.gpg', + :source => 'afp://puppetlabs.com/key.gpg', } end it 'fails' do expect { subject }.to raise_error(/does not match/) @@ -237,7 +242,7 @@ context 'invalid content' do let :params do { - :key_content => [], + :content => [], } end it 'fails' do expect { subject }.to raise_error(/is not a string/) @@ -246,16 +251,16 @@ context 'invalid server' do let :params do { - :key_server => 'two bottles of rum', + :server => 'two bottles of rum', } end it 'fails' do expect { subject }.to raise_error(/does not match/) end end - context 'invalid keyserver_options' do + context 'invalid options' do let :params do { - :key_options => {}, + :options => {}, } end it 'fails' do expect { subject }.to raise_error(/is not a string/) @@ -276,36 +281,38 @@ describe 'duplication' do context 'two apt::key resources for same key, different titles' do let :pre_condition do - "apt::key { 'duplicate': key => '#{title}', }" + "class { 'apt': } + apt::key { 'duplicate': id => '#{title}', }" end it 'contains two apt::key resources' do - should contain_apt__key('duplicate').with({ - :key => title, + is_expected.to contain_apt__key('duplicate').with({ + :id => title, :ensure => 'present', }) - should contain_apt__key(title).with({ - :key => title, + is_expected.to contain_apt__key(title).with({ + :id => 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, + is_expected.to contain_apt_key('duplicate').with({ + :id => title, + :ensure => 'present', + :source => nil, + :server => 'keyserver.ubuntu.com', + :content => nil, + :options => nil, }) - should_not contain_apt_key(title) + is_expected.not_to contain_apt_key(title) end end context 'two apt::key resources, different ensure' do let :pre_condition do - "apt::key { 'duplicate': key => '#{title}', ensure => 'absent', }" + "class { 'apt': } + apt::key { 'duplicate': id => '#{title}', ensure => 'absent', }" end it 'informs the user of the impossibility' do expect { subject }.to raise_error(/already ensured as absent/) diff --git a/spec/defines/pin_spec.rb b/spec/defines/pin_spec.rb index 23ebd59b32..a11c3b5c25 100644 --- a/spec/defines/pin_spec.rb +++ b/spec/defines/pin_spec.rb @@ -1,18 +1,14 @@ require 'spec_helper' describe 'apt::pin', :type => :define do - let(:facts) { { :lsbdistid => 'Debian' } } + let :pre_condition do + 'class { "apt": }' + end + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } } let(:title) { 'my_pin' } 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', - }) - } + it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: \*\nPin: release a=my_pin\nPin-Priority: 0\n/)} + it { is_expected.to contain_apt__setting("pref-my_pin") } end context 'set version' do @@ -22,15 +18,8 @@ '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', - }) - } + it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n/)} + it { is_expected.to contain_apt__setting("pref-my_pin") } end context 'set origin' do @@ -40,15 +29,8 @@ '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', - }) - } + it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n/)} + it { is_expected.to contain_apt__setting("pref-my_pin") } end context 'not defaults' do @@ -65,13 +47,9 @@ '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', + it { is_expected.to contain_apt__setting("pref-my_pin").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_apt__setting("pref-my_pin").with({ + 'priority' => 99, }) } end @@ -82,7 +60,7 @@ 'ensure' => 'absent' } end - it { is_expected.to contain_file("my_pin.pref").with({ + it { is_expected.to contain_apt__setting("pref-my_pin").with({ 'ensure' => 'absent', }) } @@ -90,7 +68,7 @@ context 'bad characters' do let(:title) { 'such bad && wow!' } - it { is_expected.to contain_file("such__bad____wow_.pref") } + it { is_expected.to contain_apt__setting("pref-such__bad____wow_") } end describe 'validation' do @@ -102,7 +80,7 @@ end it do expect { - should compile + is_expected.to compile }.to raise_error(Puppet::Error, /Only integers are allowed/) end end @@ -115,7 +93,7 @@ end it do expect { - should compile + is_expected.to compile }.to raise_error(Puppet::Error, /parameter version cannot be used in general form/) end end @@ -129,7 +107,7 @@ end it do expect { - should compile + is_expected.to compile }.to raise_error(Puppet::Error, /parameters release and origin are mutually exclusive/) end end @@ -144,7 +122,7 @@ end it do expect { - should compile + is_expected.to compile }.to raise_error(Puppet::Error, /parameters release, origin, and version are mutually exclusive/) end end @@ -159,7 +137,7 @@ end it do expect { - should compile + is_expected.to compile }.to raise_error(Puppet::Error, /parameters release, origin, and version are mutually exclusive/) end end diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb index 866d323004..521b42ba2b 100644 --- a/spec/defines/ppa_spec.rb +++ b/spec/defines/ppa_spec.rb @@ -1,10 +1,10 @@ require 'spec_helper' -describe 'apt::ppa', :type => :define do +describe 'apt::ppa' do + let :pre_condition do + 'class { "apt": }' + end describe 'defaults' do - let :pre_condition do - 'class { "apt": }' - end let :facts do { :lsbdistrelease => '11.04', @@ -16,20 +16,21 @@ end let(:title) { 'ppa:needs/such.substitution/wow' } - it { is_expected.to contain_package('python-software-properties') } + it { is_expected.to_not 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', + :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', }) } + 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', - }) - } + describe 'ppa depending on ppa, MODULES-1156' do + let :pre_condition do + 'class { "apt": }' + end end describe 'package_name => software-properties-common' do @@ -38,7 +39,8 @@ end let :params do { - :package_name => 'software-properties-common' + :package_name => 'software-properties-common', + :package_manage => true, } end let :facts do @@ -106,7 +108,9 @@ describe 'apt included, no proxy' do let :pre_condition do - 'class { "apt": }' + 'class { "apt": } + apt::ppa { "ppa:foo2": } + ' end let :facts do { @@ -119,29 +123,62 @@ end let :params do { - 'options' => '', + :options => '', + :package_manage => true, + :require => 'Apt::Ppa[ppa:foo2]', } end let(:title) { 'ppa:foo' } + it { is_expected.to compile.with_all_deps } 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', + :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', }) } + 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', + describe 'apt included, proxy host' do + let :pre_condition do + 'class { "apt": + proxy => { "host" => "localhost" }, + }' + end + let :facts do + { + :lsbdistrelease => '14.04', + :lsbdistcodename => 'trusty', + :operatingsystem => 'Ubuntu', + :lsbdistid => 'Ubuntu', + :osfamily => 'Debian', + } + end + let :params do + { + 'options' => '', + 'package_manage' => true, + } + 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://localhost:8080'], + :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', }) } end - describe 'apt included, proxy' do + describe 'apt included, proxy host and port' do let :pre_condition do - 'class { "apt": proxy_host => "example.com" }' + 'class { "apt": + proxy => { "host" => "localhost", "port" => 8180 }, + }' end let :facts do { @@ -154,27 +191,59 @@ end let :params do { - 'release' => 'lucid', + :options => '', + :package_manage => true, } 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', + :environment => ['http_proxy=http://localhost:8180'], + :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', }) } + end - 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', + describe 'apt included, proxy host and port and https' do + let :pre_condition do + 'class { "apt": + proxy => { "host" => "localhost", "port" => 8180, "https" => true }, + }' + end + let :facts do + { + :lsbdistrelease => '14.04', + :lsbdistcodename => 'trusty', + :operatingsystem => 'Ubuntu', + :lsbdistid => 'Ubuntu', + :osfamily => 'Debian', + } + end + let :params do + { + :options => '', + :package_manage => true, + } + 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://localhost:8180', 'https_proxy=https://localhost:8180'], + :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', }) } end describe 'ensure absent' do + let :pre_condition do + 'class { "apt": }' + end let :facts do { :lsbdistrelease => '14.04', @@ -187,11 +256,11 @@ let(:title) { 'ppa:foo' } let :params do { - 'ensure' => 'absent' + :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', + :ensure => 'absent', }) } end @@ -204,12 +273,13 @@ :operatingsystem => 'Ubuntu', :lsbdistid => 'Ubuntu', :osfamily => 'Debian', + :lsbdistcodeanme => nil, } end let(:title) { 'ppa:foo' } it do expect { - should compile + is_expected.to compile }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/) end end @@ -217,18 +287,18 @@ describe 'not ubuntu' do let :facts do { - :lsbdistrelease => '14.04', - :lsbdistcodename => 'trusty', + :lsbdistrelease => '6.0.7', + :lsbdistcodename => 'wheezy', :operatingsystem => 'Debian', - :lsbdistid => 'Ubuntu', + :lsbdistid => 'debian', :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./) + is_expected.to compile + }.to raise_error(Puppet::Error, /not currently supported on Debian/) end end end diff --git a/spec/defines/setting_spec.rb b/spec/defines/setting_spec.rb new file mode 100644 index 0000000000..6f09f9ccf0 --- /dev/null +++ b/spec/defines/setting_spec.rb @@ -0,0 +1,115 @@ +require 'spec_helper' + +describe 'apt::setting' do + let(:pre_condition) { 'class { "apt": }' } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } } + let(:title) { 'conf-teddybear' } + + let(:default_params) { { :content => 'di' } } + + describe 'when using the defaults' do + context 'without source or content' do + it do + expect { is_expected.to compile }.to raise_error(Puppet::Error, /needs either of /) + end + end + + context 'with title=conf-teddybear ' do + let(:params) { default_params } + it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Exec[apt_update]') } + end + + context 'with title=pref-teddybear' do + let(:title) { 'pref-teddybear' } + let(:params) { default_params } + it { is_expected.to contain_file('/etc/apt/preferences.d/50teddybear').that_notifies('Exec[apt_update]') } + end + + context 'with title=list-teddybear' do + let(:title) { 'list-teddybear' } + let(:params) { default_params } + it { is_expected.to contain_file('/etc/apt/sources.list.d/teddybear.list').that_notifies('Exec[apt_update]') } + end + + context 'with source' do + let(:params) { { :source => 'puppet:///la/die/dah' } } + it { + is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Exec[apt_update]').with({ + :ensure => 'file', + :owner => 'root', + :group => 'root', + :mode => '0644', + :source => "#{params[:source]}", + })} + end + + context 'with content' do + let(:params) { default_params } + it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Exec[apt_update]').with({ + :ensure => 'file', + :owner => 'root', + :group => 'root', + :mode => '0644', + :content => "#{params[:content]}", + })} + end + end + + describe 'settings requiring settings, MODULES-769' do + let(:pre_condition) do + 'class { "apt": } + apt::setting { "list-teddybear": content => "foo" } + ' + end + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } } + let(:title) { 'conf-teddybear' } + let(:default_params) { { :content => 'di' } } + + let(:params) { default_params.merge({ :require => 'Apt::Setting[list-teddybear]' }) } + + it { is_expected.to compile.with_all_deps } + end + + describe 'when trying to pull one over' do + context 'with source and content' do + let(:params) { default_params.merge({ :source => 'la' }) } + it do + expect { is_expected.to compile }.to raise_error(Puppet::Error, /cannot have both /) + end + end + + context 'with title=ext-teddybear' do + let(:title) { 'ext-teddybear' } + let(:params) { default_params } + it do + expect { is_expected.to compile }.to raise_error(Puppet::Error, /must start with /) + end + end + + context 'with ensure=banana' do + let(:params) { default_params.merge({ :ensure => 'banana' }) } + it do + expect { is_expected.to compile }.to raise_error(Puppet::Error, /"banana" does not /) + end + end + + context 'with priority=1.2' do + let(:params) { default_params.merge({ :priority => 1.2 }) } + it do + expect { is_expected.to compile }.to raise_error(Puppet::Error, /be an integer /) + end + end + end + + describe 'with priority=100' do + let(:params) { default_params.merge({ :priority => 100 }) } + it { is_expected.to contain_file('/etc/apt/apt.conf.d/100teddybear').that_notifies('Exec[apt_update]') } + end + + describe 'with ensure=absent' do + let(:params) { default_params.merge({ :ensure => 'absent' }) } + it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Exec[apt_update]').with({ + :ensure => 'absent', + })} + end +end diff --git a/spec/defines/source_spec.rb b/spec/defines/source_spec.rb index 8ca7f8e203..3900158a16 100644 --- a/spec/defines/source_spec.rb +++ b/spec/defines/source_spec.rb @@ -1,14 +1,49 @@ require 'spec_helper' -describe 'apt::source', :type => :define do +describe 'apt::source' do GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30' + let :pre_condition do + 'class { "apt": }' + end let :title do 'my_source' end - context 'mostly defaults' do + context 'defaults' do + context 'without location' do + let :facts do + { + :lsbdistid => 'Debian', + :lsbdistcodename => 'wheezy', + :osfamily => 'Debian' + } + end + it do + expect { + is_expected.to compile + }.to raise_error(Puppet::Error, /source entry without specifying a location/) + end + end + context 'with location' do + let :facts do + { + :lsbdistid => 'Debian', + :lsbdistcodename => 'wheezy', + :osfamily => 'Debian' + } + end + let(:params) { { :location => 'hello.there', } } + + it { is_expected.to contain_apt__setting('list-my_source').with({ + :ensure => 'present', + }).without_content(/# my_source\ndeb-src hello.there wheezy main\n/) + } + end + end + + describe 'no defaults' do let :facts do { :lsbdistid => 'Debian', @@ -17,84 +52,136 @@ } end - let :params do - { - 'include_deb' => false, + context 'with complex pin' do + let :params do + { + :location => 'hello.there', + :pin => { 'release' => 'wishwash', + 'explanation' => 'wishwash', + 'priority' => 1001, }, + } + end + + it { is_expected.to contain_apt__setting('list-my_source').with({ + :ensure => 'present', + }).with_content(/hello.there wheezy main\n/) + } + + it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({ + :ensure => 'present', + :priority => 1001, + :explanation => 'wishwash', + :release => 'wishwash', + }) } 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(/# my_source\ndeb-src wheezy main\n/) - } - end + context 'with simple key' do + let :params do + { + :comment => 'foo', + :location => 'http://debian.mirror.iweb.ca/debian/', + :release => 'sid', + :repos => 'testing', + :key => GPG_KEY_ID, + :pin => '10', + :architecture => 'x86_64', + :allow_unsigned => true, + } + end - context 'no defaults' do - let :facts do - { - :lsbdistid => 'Debian', - :lsbdistcodename => 'wheezy', - :osfamily => 'Debian' + it { is_expected.to contain_apt__setting('list-my_source').with({ + :ensure => 'present', + }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/) + } + + it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({ + :ensure => 'present', + :priority => '10', + :origin => 'debian.mirror.iweb.ca', + }) + } + + it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({ + :ensure => 'present', + :id => GPG_KEY_ID, + }) } 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', - 'trusted_source' => true, + + context 'with complex key' do + let :params do + { + :comment => 'foo', + :location => 'http://debian.mirror.iweb.ca/debian/', + :release => 'sid', + :repos => 'testing', + :key => { 'id' => GPG_KEY_ID, 'server' => 'pgp.mit.edu', + 'content' => 'GPG key content', + 'source' => 'http://apt.puppetlabs.com/pubkey.gpg',}, + :pin => '10', + :architecture => 'x86_64', + :allow_unsigned => true, + } + end + + it { is_expected.to contain_apt__setting('list-my_source').with({ + :ensure => 'present', + }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/) + } + + it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({ + :ensure => 'present', + :priority => '10', + :origin => 'debian.mirror.iweb.ca', + }) + } + + it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({ + :ensure => 'present', + :id => GPG_KEY_ID, + :server => 'pgp.mit.edu', + :content => 'GPG key content', + :source => 'http://apt.puppetlabs.com/pubkey.gpg', + }) } 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(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/) - } + context 'with simple key' do + let :params do + { + :comment => 'foo', + :location => 'http://debian.mirror.iweb.ca/debian/', + :release => 'sid', + :repos => 'testing', + :key => GPG_KEY_ID, + :pin => '10', + :architecture => 'x86_64', + :allow_unsigned => true, + } + end - 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', - }) - } + it { is_expected.to contain_apt__setting('list-my_source').with({ + :ensure => 'present', + }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/) + } - 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 { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({ + :ensure => 'present', + :priority => '10', + :origin => 'debian.mirror.iweb.ca', + }) + } - 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', - }) - } + it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({ + :ensure => 'present', + :id => GPG_KEY_ID, + }) + } + end end - context 'trusted_source true' do + context 'allow_unsigned true' do let :facts do { :lsbdistid => 'Debian', @@ -104,18 +191,14 @@ end let :params do { - 'include_src' => false, - 'trusted_source' => true, + :location => 'hello.there', + :allow_unsigned => true, } 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(/# my_source\ndeb \[trusted=yes\] wheezy main\n/) + it { is_expected.to contain_apt__setting('list-my_source').with({ + :ensure => 'present', + }).with_content(/# my_source\ndeb \[trusted=yes\] hello.there wheezy main\n/) } end @@ -129,21 +212,18 @@ end let :params do { - 'include_deb' => false, - 'architecture' => 'x86_64', + :location => 'hello.there', + :include => {'deb' => false, 'src' => true,}, + :architecture => 'x86_64', } 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(/# my_source\ndeb-src \[arch=x86_64 \] wheezy main\n/) + it { is_expected.to contain_apt__setting('list-my_source').with({ + :ensure => 'present', + }).with_content(/# my_source\ndeb-src \[arch=x86_64 \] hello.there wheezy main\n/) } end - + context 'ensure => absent' do let :facts do { @@ -154,12 +234,12 @@ end let :params do { - 'ensure' => 'absent', + :ensure => 'absent', } end - it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({ - 'ensure' => 'absent' + it { is_expected.to contain_apt__setting('list-my_source').with({ + :ensure => 'absent' }) } end @@ -172,12 +252,36 @@ :osfamily => 'Debian' } end + let(:params) { { :location => 'hello.there', } } it do expect { - should compile + is_expected.to compile }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/) end end + + context 'invalid pin' do + let :facts do + { + :lsbdistid => 'Debian', + :lsbdistcodename => 'wheezy', + :osfamily => 'Debian' + } + end + let :params do + { + :location => 'hello.there', + :pin => true, + } + end + + it do + expect { + is_expected.to compile + }.to raise_error(Puppet::Error, /invalid value for pin/) + end + end + end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 6b2aa5d845..56b8dadc62 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -28,7 +28,7 @@ hosts.each do |host| copy_module_to(host, :source => proj_root, :module_name => 'apt') shell("/bin/touch #{default['puppetpath']}/hiera.yaml") - on host, puppet('module install puppetlabs-stdlib --version 2.2.1'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module install puppetlabs-stdlib --version 4.5.0'), { :acceptable_exit_codes => [0,1] } end end end diff --git a/spec/unit/facter/apt_has_updates_spec.rb b/spec/unit/facter/apt_has_updates_spec.rb index f8a3f20a13..b6eee265f7 100644 --- a/spec/unit/facter/apt_has_updates_spec.rb +++ b/spec/unit/facter/apt_has_updates_spec.rb @@ -8,7 +8,7 @@ before { Facter.fact(:osfamily).expects(:value).at_least(1).returns 'RedHat' } - it { should be_nil } + it { is_expected.to be_nil } end describe 'on Debian based distro missing update-notifier-common' do @@ -17,7 +17,7 @@ File.stubs(:executable?) # Stub all other calls File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns false } - it { should be_nil } + it { is_expected.to be_nil } end describe 'on Debian based distro with broken packages' do @@ -28,7 +28,7 @@ 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>&1').returns "E: Error: BrokenCount > 0" } - it { should be_nil } + it { is_expected.to be_nil } end describe 'on Debian based distro with unknown error with semicolons' do @@ -39,7 +39,7 @@ 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>&1').returns "E: Unknown Error: 'This error contains something that could be parsed like 4;3' (10)" } - it { should be_nil } + it { is_expected.to be_nil } end describe 'on Debian based distro' do @@ -50,7 +50,7 @@ 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>&1').returns "4;3" } - it { should be true } + it { is_expected.to be true } end end diff --git a/spec/unit/facter/apt_package_updates_spec.rb b/spec/unit/facter/apt_package_updates_spec.rb index 5c7a624f4d..08bfb42a34 100644 --- a/spec/unit/facter/apt_package_updates_spec.rb +++ b/spec/unit/facter/apt_package_updates_spec.rb @@ -8,7 +8,7 @@ before { Facter.fact(:apt_has_updates).stubs(:value).returns false } - it { should be nil } + it { is_expected.to be nil } end describe 'when apt has updates' do @@ -22,9 +22,9 @@ } it { if Facter.version < '2.0.0' - should == 'puppet-common,linux-generic,linux-image-generic' + is_expected.to eq('puppet-common,linux-generic,linux-image-generic') else - should == ['puppet-common', 'linux-generic', 'linux-image-generic'] + is_expected.to eq(['puppet-common', 'linux-generic', 'linux-image-generic']) end } end diff --git a/spec/unit/facter/apt_security_updates_spec.rb b/spec/unit/facter/apt_security_updates_spec.rb index 4bc760f789..83aa6ff620 100644 --- a/spec/unit/facter/apt_security_updates_spec.rb +++ b/spec/unit/facter/apt_security_updates_spec.rb @@ -8,7 +8,7 @@ before { Facter.fact(:apt_has_updates).stubs(:value).returns false } - it { should be nil } + it { is_expected.to be nil } end describe 'when apt has security updates' do @@ -19,7 +19,7 @@ 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>&1').returns "14;7" } - it { should == 7 } + it { is_expected.to eq(7) } end end diff --git a/spec/unit/facter/apt_update_last_success_spec.rb b/spec/unit/facter/apt_update_last_success_spec.rb index 08774cd012..cb32a5ef02 100644 --- a/spec/unit/facter/apt_update_last_success_spec.rb +++ b/spec/unit/facter/apt_update_last_success_spec.rb @@ -10,7 +10,7 @@ File.stubs(:exists?).returns false } it 'should have a value of -1' do - should == -1 + is_expected.to eq(-1) end end @@ -21,7 +21,7 @@ File.stubs(:mtime).returns 1407660561 } it 'should have the value of the mtime of the file' do - should == 1407660561 + is_expected.to eq(1407660561) end end diff --git a/spec/unit/facter/apt_updates_spec.rb b/spec/unit/facter/apt_updates_spec.rb index 7e9b77f84f..781ffd6972 100644 --- a/spec/unit/facter/apt_updates_spec.rb +++ b/spec/unit/facter/apt_updates_spec.rb @@ -8,7 +8,7 @@ before { Facter.fact(:apt_has_updates).stubs(:value).returns false } - it { should be nil } + it { is_expected.to be nil } end describe 'when apt has updates' do @@ -19,7 +19,7 @@ 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>&1').returns "14;7" } - it { should == 14 } + it { is_expected.to eq(14) } end end diff --git a/spec/unit/puppet/type/apt_key_spec.rb b/spec/unit/puppet/type/apt_key_spec.rb index e8a5462c6f..e412b50664 100644 --- a/spec/unit/puppet/type/apt_key_spec.rb +++ b/spec/unit/puppet/type/apt_key_spec.rb @@ -7,23 +7,23 @@ :id => '4BD6EC30' )} it 'id is set' do - resource[:id].should eq '4BD6EC30' + expect(resource[:id]).to eq '4BD6EC30' end it 'name is set to id' do - resource[:name].should eq '4BD6EC30' + expect(resource[:name]).to eq '4BD6EC30' end it 'keyserver is default' do - resource[:server].should eq :'keyserver.ubuntu.com' + expect(resource[:server]).to eq :'keyserver.ubuntu.com' end it 'source is not set' do - resource[:source].should eq nil + expect(resource[:source]).to eq nil end it 'content is not set' do - resource[:content].should eq nil + expect(resource[:content]).to eq nil end end @@ -32,7 +32,7 @@ :id => '4bd6ec30' )} it 'id is set' do - resource[:id].should eq '4BD6EC30' + expect(resource[:id]).to eq '4BD6EC30' end end @@ -41,7 +41,7 @@ :id => 'FFFFFFFF4BD6EC30' )} it 'id is set' do - resource[:id].should eq 'FFFFFFFF4BD6EC30' + expect(resource[:id]).to eq 'FFFFFFFF4BD6EC30' end end @@ -50,7 +50,7 @@ :id => '0x4BD6EC30' )} it 'id is set' do - resource[:id].should eq '4BD6EC30' + expect(resource[:id]).to eq '4BD6EC30' end end @@ -59,7 +59,7 @@ :id => '0x4bd6ec30' )} it 'id is set' do - resource[:id].should eq '4BD6EC30' + expect(resource[:id]).to eq '4BD6EC30' end end @@ -68,7 +68,7 @@ :id => '0xFFFFFFFF4BD6EC30' )} it 'id is set' do - resource[:id].should eq 'FFFFFFFF4BD6EC30' + expect(resource[:id]).to eq 'FFFFFFFF4BD6EC30' end end @@ -79,7 +79,7 @@ )} it 'source is set to the URL' do - resource[:source].should eq 'http://apt.puppetlabs.com/pubkey.gpg' + expect(resource[:source]).to eq 'http://apt.puppetlabs.com/pubkey.gpg' end end @@ -90,7 +90,7 @@ )} it 'content is set to the string' do - resource[:content].should eq 'http://apt.puppetlabs.com/pubkey.gpg' + expect(resource[:content]).to eq 'http://apt.puppetlabs.com/pubkey.gpg' end end @@ -101,7 +101,7 @@ )} it 'keyserver is set to Debian' do - resource[:server].should eq 'http://keyring.debian.org' + expect(resource[:server]).to eq 'http://keyring.debian.org' end end diff --git a/templates/10periodic.erb b/templates/10periodic.erb deleted file mode 100644 index 43caed9ea1..0000000000 --- a/templates/10periodic.erb +++ /dev/null @@ -1,15 +0,0 @@ -APT::Periodic::Enable "<%= @enable %>"; -APT::Periodic::BackUpArchiveInterval "<%= @backup_interval %>"; -APT::Periodic::BackUpLevel "<%= @backup_level %>"; -APT::Periodic::MaxAge "<%= @max_age %>"; -APT::Periodic::MinAge "<%= @min_age %>"; -APT::Periodic::MaxSize "<%= @max_size %>"; -APT::Periodic::Update-Package-Lists "<%= @update %>"; -APT::Periodic::Download-Upgradeable-Packages "<%= @download %>"; -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/50unattended-upgrades.erb b/templates/50unattended-upgrades.erb deleted file mode 100644 index 47ecb3479a..0000000000 --- a/templates/50unattended-upgrades.erb +++ /dev/null @@ -1,62 +0,0 @@ -// Automatically upgrade packages from these (origin:archive) pairs -<%- if @legacy_origin -%> -Unattended-Upgrade::Allowed-Origins { -<%- else -%> -Unattended-Upgrade::Origins-Pattern { -<%- end -%> -<% @origins.each do |origin| -%> - "<%= origin %>"; -<% end -%> -}; - -// List of packages to not update -Unattended-Upgrade::Package-Blacklist { -<% @blacklist.each do |package| -%> - "<%= package %>"; -<% end -%> -}; - -// This option allows you to control if on a unclean dpkg exit -// unattended-upgrades will automatically run -// dpkg --force-confold --configure -a -// The default is true, to ensure updates keep getting installed -Unattended-Upgrade::AutoFixInterruptedDpkg "<%= @auto_fix %>"; - -// Split the upgrade into the smallest possible chunks so that -// they can be interrupted with SIGUSR1. This makes the upgrade -// a bit slower but it has the benefit that shutdown while a upgrade -// is running is possible (with a small delay) -Unattended-Upgrade::MinimalSteps "<%= @minimal_steps %>"; - -// Install all unattended-upgrades when the machine is shuting down -// instead of doing it in the background while the machine is running -// This will (obviously) make shutdown slower -Unattended-Upgrade::InstallOnShutdown "<%= @install_on_shutdown %>"; - -<% if @mail_to != "NONE" %> -// Send email to this address for problems or packages upgrades -// If empty or unset then no email is sent, make sure that you -// have a working mail setup on your system. A package that provides -// 'mailx' must be installed. -Unattended-Upgrade::Mail "<%= @mail_to %>"; -<% end %> - -<% if @mail_to != "NONE" %> -// Set this value to "true" to get emails only on errors. Default -// is to always send a mail if Unattended-Upgrade::Mail is set -Unattended-Upgrade::MailOnlyOnError "<%= @mail_only_on_error %>"; -<% end %> - -// Do automatic removal of new unused dependencies after the upgrade -// (equivalent to apt-get autoremove) -Unattended-Upgrade::Remove-Unused-Dependencies "<%= @remove_unused %>"; - -// Automatically reboot *WITHOUT CONFIRMATION* if a -// the file /var/run/reboot-required is found after the upgrade -Unattended-Upgrade::Automatic-Reboot "<%= @auto_reboot %>"; - -<% if @dl_limit != "NONE" %> -// Use apt bandwidth limit feature, this example limits the download -// speed to 70kb/sec -Acquire::http::Dl-Limit "<%= @dl_limit %>"; -<% end %> diff --git a/templates/pin.pref.erb b/templates/pin.pref.erb index 26b2516c47..76936d7ca4 100644 --- a/templates/pin.pref.erb +++ b/templates/pin.pref.erb @@ -15,7 +15,7 @@ elsif @origin.length > 0 @pin = "origin #{@origin}" end -%> -Explanation: <%= @explanation %> +Explanation: <%= @_explanation %> Package: <%= @packages_string %> Pin: <%= @pin %> Pin-Priority: <%= @priority %> diff --git a/templates/progressbar.erb b/templates/progressbar.erb deleted file mode 100644 index d3d9278c0d..0000000000 --- a/templates/progressbar.erb +++ /dev/null @@ -1 +0,0 @@ -Dpkg::Progress-Fancy "1"; diff --git a/templates/proxy.erb b/templates/proxy.erb index accb0ccee8..670e3a7e87 100644 --- a/templates/proxy.erb +++ b/templates/proxy.erb @@ -1 +1,4 @@ -Acquire::http::Proxy "http://<%= @proxy_host %>:<%= @proxy_port %>"; +Acquire::http::proxy "http://<%= @_proxy['host'] %>:<%= @_proxy['port'] %>/"; +<%- if @_proxy['https'] %> +Acquire::https::proxy "https://<%= @_proxy['host'] %>:<%= @_proxy['port'] %>/"; +<%- end -%> diff --git a/templates/release.erb b/templates/release.erb deleted file mode 100644 index 08760af70a..0000000000 --- a/templates/release.erb +++ /dev/null @@ -1 +0,0 @@ -APT::Default-Release "<%= @release_id %>"; diff --git a/templates/source.list.erb b/templates/source.list.erb index b50be8d1fd..26838db51b 100644 --- a/templates/source.list.erb +++ b/templates/source.list.erb @@ -1,11 +1,11 @@ # <%= @comment %> -<%- if @include_deb then -%> -deb <%- if @architecture or @trusted_source -%> -[<%- if @architecture %>arch=<%= @architecture %> <% end %><% if @trusted_source %>trusted=yes<% end -%> -] <%- end %><%= @location %> <%= @release_real %> <%= @repos %> +<%- if @_include['deb'] then -%> +deb <%- if @architecture or @allow_unsigned -%> +[<%- if @architecture %>arch=<%= @architecture %> <% end %><% if @allow_unsigned %>trusted=yes<% end -%> +] <%- end %><%= @location %> <%= @release %> <%= @repos %> <%- end -%> -<%- if @include_src then -%> -deb-src <%- if @architecture or @trusted_source -%> -[<%- if @architecture %>arch=<%= @architecture %> <% end %><% if @trusted_source %>trusted=yes<% end -%> -] <%- end %><%= @location %> <%= @release_real %> <%= @repos %> +<%- if @_include['src'] then -%> +deb-src <%- if @architecture or @allow_unsigned -%> +[<%- if @architecture %>arch=<%= @architecture %> <% end %><% if @allow_unsigned %>trusted=yes<% end -%> +] <%- end %><%= @location %> <%= @release %> <%= @repos %> <%- end -%> diff --git a/templates/unauth.erb b/templates/unauth.erb deleted file mode 100644 index 77edd289f6..0000000000 --- a/templates/unauth.erb +++ /dev/null @@ -1 +0,0 @@ -APT::Get::AllowUnauthenticated 1; diff --git a/tests/builddep.pp b/tests/builddep.pp deleted file mode 100644 index 8b4f796408..0000000000 --- a/tests/builddep.pp +++ /dev/null @@ -1,2 +0,0 @@ -class { 'apt': } -apt::builddep{ 'glusterfs-server': } diff --git a/tests/debian/testing.pp b/tests/debian/testing.pp deleted file mode 100644 index 8245b3a337..0000000000 --- a/tests/debian/testing.pp +++ /dev/null @@ -1,2 +0,0 @@ -class { 'apt': } -class { 'apt::debian::testing': } diff --git a/tests/debian/unstable.pp b/tests/debian/unstable.pp deleted file mode 100644 index 8605179295..0000000000 --- a/tests/debian/unstable.pp +++ /dev/null @@ -1,2 +0,0 @@ -class { 'apt': } -class { 'apt::debian::unstable': } diff --git a/tests/force.pp b/tests/force.pp deleted file mode 100644 index 59ad8f1b57..0000000000 --- a/tests/force.pp +++ /dev/null @@ -1,17 +0,0 @@ -# force.pp - -# force a package from a specific release -apt::force { 'package1': - release => 'backports', -} - -# force a package to be a specific version -apt::force { 'package2': - version => '1.0.0-1', -} - -# force a package from a specific release to be a specific version -apt::force { 'package3': - release => 'sid', - version => '2.0.0-1', -} diff --git a/tests/init.pp b/tests/init.pp deleted file mode 100644 index abc75afa25..0000000000 --- a/tests/init.pp +++ /dev/null @@ -1 +0,0 @@ -class { 'apt': } diff --git a/tests/key.pp b/tests/key.pp deleted file mode 100644 index 79e0e1b749..0000000000 --- a/tests/key.pp +++ /dev/null @@ -1,6 +0,0 @@ -# Declare Apt key for apt.puppetlabs.com source -apt::key { 'puppetlabs': - key => '4BD6EC30', - key_server => 'pgp.mit.edu', - key_options => 'http-proxy="http://proxyuser:proxypass@example.org:3128"', -} diff --git a/tests/params.pp b/tests/params.pp deleted file mode 100644 index 5ddf3c6551..0000000000 --- a/tests/params.pp +++ /dev/null @@ -1 +0,0 @@ -include apt::params diff --git a/tests/release.pp b/tests/release.pp deleted file mode 100644 index 823f5861fa..0000000000 --- a/tests/release.pp +++ /dev/null @@ -1,4 +0,0 @@ -class { 'apt': } -class { 'apt::release': - release_id => 'karmic' -} diff --git a/tests/source.pp b/tests/source.pp deleted file mode 100644 index 823b37b736..0000000000 --- a/tests/source.pp +++ /dev/null @@ -1,29 +0,0 @@ -# Declare the apt class to manage /etc/apt/sources.list and /etc/sources.list.d -class { 'apt': } - -# Install the puppetlabs apt source -# Release is automatically obtained from lsbdistcodename fact if available. -apt::source { 'puppetlabs': - location => 'http://apt.puppetlabs.com', - repos => 'main', - key => '4BD6EC30', - key_server => 'pgp.mit.edu', -} - -# test two sources with the same key -apt::source { 'debian_testing': - location => 'http://debian.mirror.iweb.ca/debian/', - release => 'testing', - repos => 'main contrib non-free', - key => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', - key_server => 'subkeys.pgp.net', - pin => '-10', -} -apt::source { 'debian_unstable': - location => 'http://debian.mirror.iweb.ca/debian/', - release => 'unstable', - repos => 'main contrib non-free', - key => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', - key_server => 'subkeys.pgp.net', - pin => '-10', -} diff --git a/tests/unattended_upgrades.pp b/tests/unattended_upgrades.pp deleted file mode 100644 index 3b9b49eb72..0000000000 --- a/tests/unattended_upgrades.pp +++ /dev/null @@ -1 +0,0 @@ -include apt::unattended_upgrades