diff --git a/puppet/apt b/puppet/apt
deleted file mode 120000
index ffa752fffe..0000000000
--- a/puppet/apt
+++ /dev/null
@@ -1 +0,0 @@
-puppet-apt/
\ No newline at end of file
diff --git a/puppet/apt/.bundle/config b/puppet/apt/.bundle/config
new file mode 100644
index 0000000000..2ddd802885
--- /dev/null
+++ b/puppet/apt/.bundle/config
@@ -0,0 +1,2 @@
+---
+BUNDLE_WITHOUT: development
diff --git a/puppet/apt/.fixtures.yml b/puppet/apt/.fixtures.yml
new file mode 100644
index 0000000000..dbd5621dea
--- /dev/null
+++ b/puppet/apt/.fixtures.yml
@@ -0,0 +1,5 @@
+fixtures:
+ repositories:
+ "stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
+ symlinks:
+ "apt": "#{source_dir}"
diff --git a/puppet/apt/.forge-release/pom.xml b/puppet/apt/.forge-release/pom.xml
new file mode 100644
index 0000000000..b788e86563
--- /dev/null
+++ b/puppet/apt/.forge-release/pom.xml
@@ -0,0 +1,29 @@
+
+ 4.0.0
+ puppetlabs
+ ghpublisher
+ 1.0.0
+ puppet-module
+ ghpublisher
+
+
+ ${env.PUBLISHER_LOGIN}
+ ${env.PUBLISHER_PASSWORD}
+
+
+
+
+
+ org.cloudsmith.geppetto
+ forge-maven-plugin
+ 3.2.0
+ true
+
+ false
+ ${project.build.directory}/forgeCache
+
+
+
+
+
diff --git a/puppet/apt/.forge-release/publish b/puppet/apt/.forge-release/publish
new file mode 100644
index 0000000000..7d8665f6a9
--- /dev/null
+++ b/puppet/apt/.forge-release/publish
@@ -0,0 +1,18 @@
+#!/bin/sh
+#
+# Perform GitHub publish
+if [ -z "$PUBLISHER_LOGIN" ]
+then
+ echo "Environment variable PUBLISHER_LOGIN must be set"
+ exit 1
+fi
+
+if [ -z "$PUBLISHER_PASSWORD" ]
+then
+ echo "Environment variable PUBLISHER_PASSWORD must be set"
+ exit 1
+fi
+
+MODULES_ROOT=`pwd`
+cd $(dirname $0)
+mvn -q -s settings.xml -Dforge.modules.root="$MODULES_ROOT" deploy
\ No newline at end of file
diff --git a/puppet/apt/.forge-release/settings.xml b/puppet/apt/.forge-release/settings.xml
new file mode 100644
index 0000000000..3ec7de2ea1
--- /dev/null
+++ b/puppet/apt/.forge-release/settings.xml
@@ -0,0 +1,34 @@
+
+
+
+ cloudsmith
+
+
+ cloudsmith
+ https://am0.cloudsmith.com/nexus/content/repositories/releases/
+
+ true
+
+
+ false
+
+
+
+
+
+ cloudsmith
+ https://am0.cloudsmith.com/nexus/content/repositories/releases/
+
+ true
+
+
+ false
+
+
+
+
+
+
+ cloudsmith
+
+
diff --git a/puppet/apt/.forge-release/validate b/puppet/apt/.forge-release/validate
new file mode 100644
index 0000000000..190ed338ed
--- /dev/null
+++ b/puppet/apt/.forge-release/validate
@@ -0,0 +1,6 @@
+#!/bin/sh
+#
+# Perform GitHub publish
+MODULES_ROOT=`pwd`
+cd $(dirname $0)
+mvn -q -s settings.xml -Dforge.modules.root="$MODULES_ROOT" compile
\ No newline at end of file
diff --git a/puppet/apt/.nodeset.yml b/puppet/apt/.nodeset.yml
new file mode 100644
index 0000000000..ad056fe655
--- /dev/null
+++ b/puppet/apt/.nodeset.yml
@@ -0,0 +1,19 @@
+---
+default_set: 'ubuntu-server-12042-x64'
+sets:
+ 'debian-607-x64':
+ nodes:
+ "main.foo.vm":
+ prefab: 'debian-607-x64'
+ 'debian-70rc1-x64':
+ nodes:
+ "main.foo.vm":
+ prefab: 'debian-70rc1-x64'
+ 'ubuntu-server-10044-x64':
+ nodes:
+ "main.foo.vm":
+ prefab: 'ubuntu-server-10044-x64'
+ 'ubuntu-server-12042-x64':
+ nodes:
+ "main.foo.vm":
+ prefab: 'ubuntu-server-12042-x64'
diff --git a/puppet/apt/.travis.yml b/puppet/apt/.travis.yml
new file mode 100644
index 0000000000..00924bac0a
--- /dev/null
+++ b/puppet/apt/.travis.yml
@@ -0,0 +1,40 @@
+---
+branches:
+ only:
+ - master
+language: ruby
+bundler_args: --without development
+script: bundle exec rake spec SPEC_OPTS='--format documentation'
+after_success:
+ - git clone -q git://github.com/puppetlabs/ghpublisher.git .forge-release
+ - .forge-release/publish
+rvm:
+ - 1.8.7
+ - 1.9.3
+ - 2.0.0
+env:
+ matrix:
+ - PUPPET_GEM_VERSION="~> 2.7.0"
+ - PUPPET_GEM_VERSION="~> 3.0.0"
+ - PUPPET_GEM_VERSION="~> 3.1.0"
+ - PUPPET_GEM_VERSION="~> 3.2.0"
+ global:
+ - PUBLISHER_LOGIN=puppetlabs
+ - secure: |-
+ ipB/CV1rVSTXU9ZDuzrFOlzJrRmJob36tKns2xszuH4r9s5P9qivNAngRGdV
+ msb69xvOlzQykM0WRF+4kJ6TZ7AbMiDI+VZ8GDtsRaU5/q3BpsvFe8aato+6
+ QeyFtBG62OsosTEhGws4mqiFsPDu3dHlakuJc9zevlTuhNwbKSs=
+matrix:
+ exclude:
+ - rvm: 1.9.3
+ env: PUPPET_GEM_VERSION="~> 2.7.0"
+ - rvm: 2.0.0
+ env: PUPPET_GEM_VERSION="~> 2.7.0"
+ - rvm: 2.0.0
+ env: PUPPET_GEM_VERSION="~> 3.0.0"
+ - rvm: 2.0.0
+ env: PUPPET_GEM_VERSION="~> 3.1.0"
+ - rvm: 1.8.7
+ env: PUPPET_GEM_VERSION="~> 3.2.0"
+notifications:
+ email: false
diff --git a/puppet/apt/CHANGELOG b/puppet/apt/CHANGELOG
new file mode 100644
index 0000000000..0d321bc299
--- /dev/null
+++ b/puppet/apt/CHANGELOG
@@ -0,0 +1,183 @@
+2013-10-08 1.4.0
+
+Summary:
+
+Minor bugfix and allow the timeout to be adjusted.
+
+Features:
+- Add an `updates_timeout` to apt::params
+
+Fixes:
+- Ensure apt::ppa can readd a ppa removed by hand.
+
+Summary
+
+1.3.0
+=====
+
+Summary:
+
+This major feature in this release is the new apt::unattended_upgrades class,
+allowing you to handle Ubuntu's unattended feature. This allows you to select
+specific packages to automatically upgrade without any further user
+involvement.
+
+In addition we extend our Wheezy support, add proxy support to apt:ppa and do
+various cleanups and tweaks.
+
+Features:
+- Add apt::unattended_upgrades support for Ubuntu.
+- Add wheezy backports support.
+- Use the geoDNS http.debian.net instead of the main debian ftp server.
+- Add `options` parameter to apt::ppa in order to pass options to apt-add-repository command.
+- Add proxy support for apt::ppa (uses proxy_host and proxy_port from apt).
+
+Bugfixes:
+- Fix regsubst() calls to quote single letters (for future parser).
+- Fix lint warnings and other misc cleanup.
+
+1.2.0
+=====
+
+Features:
+- Add geppetto `.project` natures
+- Add GH auto-release
+- Add `apt::key::key_options` parameter
+- Add complex pin support using distribution properties for `apt::pin` via new properties:
+ - `apt::pin::codename`
+ - `apt::pin::release_version`
+ - `apt::pin::component`
+ - `apt::pin::originator`
+ - `apt::pin::label`
+- Add source architecture support to `apt::source::architecture`
+
+Bugfixes:
+- Use apt-get instead of aptitude in apt::force
+- Update default backports location
+- Add dependency for required packages before apt-get update
+
+
+1.1.1
+=====
+
+This is a bug fix release that resolves a number of issues:
+
+* By changing template variable usage, we remove the deprecation warnings
+ for Puppet 3.2.x
+* Fixed proxy file removal, when proxy absent
+
+Some documentation, style and whitespaces changes were also merged. This
+release also introduced proper rspec-puppet unit testing on Travis-CI to help
+reduce regression.
+
+Thanks to all the community contributors below that made this patch possible.
+
+#### Detail Changes
+
+* fix minor comment type (Chris Rutter)
+* whitespace fixes (Michael Moll)
+* Update travis config file (William Van Hevelingen)
+* Build all branches on travis (William Van Hevelingen)
+* Standardize travis.yml on pattern introduced in stdlib (William Van Hevelingen)
+* Updated content to conform to README best practices template (Lauren Rother)
+* Fix apt::release example in readme (Brian Galey)
+* add @ to variables in template (Peter Hoeg)
+* Remove deprecation warnings for pin.pref.erb as well (Ken Barber)
+* Update travis.yml to latest versions of puppet (Ken Barber)
+* Fix proxy file removal (Scott Barber)
+* Add spec test for removing proxy configuration (Dean Reilly)
+* Fix apt::key listing longer than 8 chars (Benjamin Knofe)
+
+
+---------------------------------------
+
+1.1.0
+=====
+
+This release includes Ubuntu 12.10 (Quantal) support for PPAs.
+
+---------------------------------------
+
+2012-05-25 Puppet Labs - 0.0.4
+ * Fix ppa list filename when there is a period in the PPA name
+ * Add .pref extension to apt preferences files
+ * Allow preferences to be purged
+ * Extend pin support
+
+2012-05-04 Puppet Labs - 0.0.3
+ * only invoke apt-get update once
+ * only install python-software-properties if a ppa is added
+ * support 'ensure => absent' for all defined types
+ * add apt::conf
+ * add apt::backports
+ * fixed Modulefile for module tool dependency resolution
+ * configure proxy before doing apt-get update
+ * use apt-get update instead of aptitude for apt::ppa
+ * add support to pin release
+
+
+2012-03-26 Puppet Labs - 0.0.2
+41cedbb (#13261) Add real examples to smoke tests.
+d159a78 (#13261) Add key.pp smoke test
+7116c7a (#13261) Replace foo source with puppetlabs source
+1ead0bf Ignore pkg directory.
+9c13872 (#13289) Fix some more style violations
+0ea4ffa (#13289) Change test scaffolding to use a module & manifest dir fixture path
+a758247 (#13289) Clean up style violations and fix corresponding tests
+99c3fd3 (#13289) Add puppet lint tests to Rakefile
+5148cbf (#13125) Apt keys should be case insensitive
+b9607a4 Convert apt::key to use anchors
+
+2012-03-07 Puppet Labs - 0.0.1
+d4fec56 Modify apt::source release parameter test
+1132a07 (#12917) Add contributors to README
+8cdaf85 (#12823) Add apt::key defined type and modify apt::source to use it
+7c0d10b (#12809) $release should use $lsbdistcodename and fall back to manual input
+be2cc3e (#12522) Adjust spec test for splitting purge
+7dc60ae (#12522) Split purge option to spare sources.list
+9059c4e Fix source specs to test all key permutations
+8acb202 Add test for python-software-properties package
+a4af11f Check if python-software-properties is defined before attempting to define it.
+1dcbf3d Add tests for required_packages change
+f3735d2 Allow duplicate $required_packages
+74c8371 (#12430) Add tests for changes to apt module
+97ebb2d Test two sources with the same key
+1160bcd (#12526) Add ability to reverse apt { disable_keys => true }
+2842d73 Add Modulefile to puppet-apt
+c657742 Allow the use of the same key in multiple sources
+8c27963 (#12522) Adding purge option to apt class
+997c9fd (#12529) Add unit test for apt proxy settings
+50f3cca (#12529) Add parameter to support setting a proxy for apt
+d522877 (#12094) Replace chained .with_* with a hash
+8cf1bd0 (#12094) Remove deprecated spec.opts file
+2d688f4 (#12094) Add rspec-puppet tests for apt
+0fb5f78 (#12094) Replace name with path in file resources
+f759bc0 (#11953) Apt::force passes $version to aptitude
+f71db53 (#11413) Add spec test for apt::force to verify changes to unless
+2f5d317 (#11413) Update dpkg query used by apt::force
+cf6caa1 (#10451) Add test coverage to apt::ppa
+0dd697d include_src parameter in example; Whitespace cleanup
+b662eb8 fix typos in "repositories"
+1be7457 Fix (#10451) - apt::ppa fails to "apt-get update" when new PPA source is added
+864302a Set the pin priority before adding the source (Fix #10449)
+1de4e0a Refactored as per mlitteken
+1af9a13 Added some crazy bash madness to check if the ppa is installed already. Otherwise the manifest tries to add it on every run!
+52ca73e (#8720) Replace Apt::Ppa with Apt::Builddep
+5c05fa0 added builddep command.
+a11af50 added the ability to specify the content of a key
+c42db0f Fixes ppa test.
+77d2b0d reformatted whitespace to match recommended style of 2 space indentation.
+27ebdfc ignore swap files.
+377d58a added smoke tests for module.
+18f614b reformatted apt::ppa according to recommended style.
+d8a1e4e Created a params class to hold global data.
+636ae85 Added two params for apt class
+148fc73 Update LICENSE.
+ed2d19e Support ability to add more than one PPA
+420d537 Add call to apt-update after add-apt-repository in apt::ppa
+945be77 Add package definition for python-software-properties
+71fc425 Abs paths for all commands
+9d51cd1 Adding LICENSE
+71796e3 Heading fix in README
+87777d8 Typo in README
+f848bac First commit
diff --git a/puppet/apt/Gemfile b/puppet/apt/Gemfile
new file mode 100644
index 0000000000..15bd29daf0
--- /dev/null
+++ b/puppet/apt/Gemfile
@@ -0,0 +1,16 @@
+source 'https://rubygems.org'
+
+group :development, :test do
+ gem 'rake', :require => false
+ gem 'rspec-puppet', :require => false
+ gem 'puppetlabs_spec_helper', :require => false
+ gem 'rspec-system', :require => false
+ gem 'rspec-system-puppet', :require => false
+ gem 'rspec-system-serverspec', :require => false
+end
+
+if puppetversion = ENV['PUPPET_GEM_VERSION']
+ gem 'puppet', puppetversion, :require => false
+else
+ gem 'puppet', :require => false
+end
diff --git a/puppet/apt/Gemfile.lock b/puppet/apt/Gemfile.lock
new file mode 100644
index 0000000000..9932e1699c
--- /dev/null
+++ b/puppet/apt/Gemfile.lock
@@ -0,0 +1,70 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ builder (3.2.2)
+ diff-lcs (1.2.4)
+ facter (1.6.18)
+ hiera (1.0.0)
+ highline (1.6.19)
+ kwalify (0.7.2)
+ metaclass (0.0.1)
+ mocha (0.14.0)
+ metaclass (~> 0.0.1)
+ net-scp (1.1.2)
+ net-ssh (>= 2.6.5)
+ net-ssh (2.7.0)
+ nokogiri (1.5.10)
+ puppet (3.0.2)
+ facter (~> 1.6.11)
+ hiera (~> 1.0.0)
+ puppetlabs_spec_helper (0.4.1)
+ mocha (>= 0.10.5)
+ rake
+ rspec (>= 2.9.0)
+ rspec-puppet (>= 0.1.1)
+ rake (10.1.0)
+ rbvmomi (1.6.0)
+ builder
+ nokogiri (>= 1.4.1)
+ trollop
+ rspec (2.14.1)
+ rspec-core (~> 2.14.0)
+ rspec-expectations (~> 2.14.0)
+ rspec-mocks (~> 2.14.0)
+ rspec-core (2.14.5)
+ rspec-expectations (2.14.3)
+ diff-lcs (>= 1.1.3, < 2.0)
+ rspec-mocks (2.14.3)
+ rspec-puppet (0.1.6)
+ rspec
+ rspec-system (2.3.0)
+ kwalify (~> 0.7.2)
+ net-scp (~> 1.1)
+ net-ssh (~> 2.6)
+ nokogiri (~> 1.5.9)
+ rbvmomi (~> 1.6)
+ rspec (~> 2.13)
+ systemu (~> 2.5)
+ rspec-system-puppet (2.2.0)
+ rspec-system (~> 2.0)
+ rspec-system-serverspec (1.0.1)
+ rspec-system (~> 2.0)
+ serverspec (~> 0.0)
+ serverspec (0.10.5)
+ highline
+ net-ssh
+ rspec (>= 2.13.0)
+ systemu (2.5.2)
+ trollop (2.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ puppet (~> 3.0.0)
+ puppetlabs_spec_helper
+ rake
+ rspec-puppet
+ rspec-system
+ rspec-system-puppet
+ rspec-system-serverspec
diff --git a/puppet/apt/LICENSE b/puppet/apt/LICENSE
new file mode 100644
index 0000000000..638c347b17
--- /dev/null
+++ b/puppet/apt/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2011 Evolving Web Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/puppet/apt/Modulefile b/puppet/apt/Modulefile
new file mode 100644
index 0000000000..72aa142e5f
--- /dev/null
+++ b/puppet/apt/Modulefile
@@ -0,0 +1,14 @@
+name 'puppetlabs-apt'
+version '1.4.0'
+source 'https://github.com/puppetlabs/puppetlabs-apt'
+author 'Evolving Web / Puppet Labs'
+license 'Apache License 2.0'
+summary 'Puppet Labs Apt Module'
+description 'APT Module for Puppet'
+project_page 'https://github.com/puppetlabs/puppetlabs-apt'
+
+## Add dependencies, if any:
+#dependency 'puppetlabs/stdlib', '2.x'
+# The dependency should be written as above but librarian-puppet
+# does not support the expression as the PMT does.
+dependency 'puppetlabs/stdlib', '>= 2.2.1'
diff --git a/puppet/apt/README.md b/puppet/apt/README.md
new file mode 100644
index 0000000000..2ce5340ab6
--- /dev/null
+++ b/puppet/apt/README.md
@@ -0,0 +1,226 @@
+apt
+===
+
+[![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-apt.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-apt)
+
+## Description
+Provides helpful definitions for dealing with Apt.
+=======
+Overview
+--------
+
+The APT module provides a simple interface for managing APT source, key, and definitions with Puppet.
+
+Module Description
+------------------
+
+APT automates obtaining and installing software packages on *nix systems.
+
+Setup
+-----
+
+**What APT affects:**
+
+* package/service/configuration files for APT
+* your system's `sources.list` file and `sources.list.d` directory
+ * NOTE: Setting the `purge_sources_list` and `purge_sources_list_d` parameters to 'true' will destroy any existing content that was not declared with Puppet. The default for these parameters is 'false'.
+* system repositories
+* authentication keys
+* wget (optional)
+
+###Beginning with APT
+
+To begin using the APT module with default parameters, declare the class
+
+ class { 'apt': }
+
+Puppet code that uses anything from the APT module requires that the core apt class be declared.
+
+Usage
+-----
+
+Using the APT module consists predominantly in declaring classes that provide desired functionality and features.
+
+###apt
+
+`apt` provides a number of common resources and options that are shared by the various defined types in this module, so you MUST always include this class in your manifests.
+
+The parameters for `apt` are not required in general and are predominantly for development environment use-cases.
+
+ class { 'apt':
+ always_apt_update => false,
+ disable_keys => undef,
+ proxy_host => false,
+ proxy_port => '8080',
+ purge_sources_list => false,
+ purge_sources_list_d => false,
+ purge_preferences_d => false,
+ update_timeout => undef
+ }
+
+Puppet will manage your system's `sources.list` file and `sources.list.d` directory but will do its best to respect existing content.
+
+If you declare your apt class with `purge_sources_list` and `purge_sources_list_d` set to 'true', Puppet will unapologetically purge any existing content it finds that wasn't declared with Puppet.
+
+###apt::builddep
+
+Installs the build depends of a specified package.
+
+ apt::builddep { 'glusterfs-server': }
+
+###apt::force
+
+Forces a package to be installed from a specific release. This class is particularly useful when using repositories, like Debian, that are unstable in Ubuntu.
+
+ apt::force { 'glusterfs-server':
+ release => 'unstable',
+ version => '3.0.3',
+ require => Apt::Source['debian_unstable'],
+ }
+
+###apt::key
+
+Adds a key to the list of keys used by APT to authenticate packages.
+
+ apt::key { 'puppetlabs':
+ key => '4BD6EC30',
+ key_server => 'pgp.mit.edu',
+ }
+
+ apt::key { 'jenkins':
+ key => 'D50582E6',
+ key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key',
+ }
+
+Note that use of `key_source` requires wget to be installed and working.
+
+###apt::pin
+
+Adds an apt pin for a certain release.
+
+ apt::pin { 'karmic': priority => 700 }
+ apt::pin { 'karmic-updates': priority => 700 }
+ apt::pin { 'karmic-security': priority => 700 }
+
+Note you can also specifying more complex pins using distribution properties.
+
+ apt::pin { 'stable':
+ priority => -10,
+ originator => 'Debian',
+ release_version => '3.0',
+ component => 'main',
+ label => 'Debian'
+ }
+
+###apt::ppa
+
+Adds a ppa repository using `add-apt-repository`.
+
+ apt::ppa { 'ppa:drizzle-developers/ppa': }
+
+###apt::release
+
+Sets the default apt release. This class is particularly useful when using repositories, like Debian, that are unstable in Ubuntu.
+
+ class { 'apt::release':
+ release_id => 'precise',
+ }
+
+###apt::source
+
+Adds an apt source to `/etc/apt/sources.list.d/`.
+
+ 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 => '55BE302B',
+ key_server => 'subkeys.pgp.net',
+ pin => '-10',
+ include_src => true
+ }
+
+If you would like to configure your system so the source is the Puppet Labs APT repository
+
+ apt::source { 'puppetlabs':
+ location => 'http://apt.puppetlabs.com',
+ repos => 'main',
+ key => '4BD6EC30',
+ key_server => 'pgp.mit.edu',
+ }
+
+###Testing
+
+The APT module is mostly a collection of defined resource types, which provide reusable logic that can be leveraged to manage APT. It does provide smoke tests for testing functionality on a target system, as well as spec tests for checking a compiled catalog against an expected set of resources.
+
+####Example Test
+
+This test will set up a Puppet Labs apt repository. Start by creating a new smoke test in the apt module's test folder. Call it puppetlabs-apt.pp. Inside, declare a single resource representing the Puppet Labs APT source and gpg key
+
+ apt::source { 'puppetlabs':
+ location => 'http://apt.puppetlabs.com',
+ repos => 'main',
+ key => '4BD6EC30',
+ key_server => 'pgp.mit.edu',
+ }
+
+This resource creates an apt source named puppetlabs and gives Puppet information about the repository's location and key used to sign its packages. Puppet leverages Facter to determine the appropriate release, but you can set it directly by adding the release type.
+
+Check your smoke test for syntax errors
+
+ $ puppet parser validate tests/puppetlabs-apt.pp
+
+If you receive no output from that command, it means nothing is wrong. Then apply the code
+
+ $ puppet apply --verbose tests/puppetlabs-apt.pp
+ notice: /Stage[main]//Apt::Source[puppetlabs]/File[puppetlabs.list]/ensure: defined content as '{md5}3be1da4923fb910f1102a233b77e982e'
+ info: /Stage[main]//Apt::Source[puppetlabs]/File[puppetlabs.list]: Scheduling refresh of Exec[puppetlabs apt update]
+ notice: /Stage[main]//Apt::Source[puppetlabs]/Exec[puppetlabs apt update]: Triggered 'refresh' from 1 events>
+
+The above example used a smoke test to easily lay out a resource declaration and apply it on your system. In production, you may want to declare your APT sources inside the classes where they’re needed.
+
+Implementation
+--------------
+
+###apt::backports
+
+Adds the necessary components to get backports for Ubuntu and Debian. The release name defaults to `$lsbdistcodename`. Setting this manually can cause undefined behavior (read: universe exploding).
+
+Limitations
+-----------
+
+This module should work across all versions of Debian/Ubuntu and support all major APT repository management features.
+
+Development
+------------
+
+Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can’t access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve.
+
+We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.
+
+You can read the complete module contribution guide [on the Puppet Labs wiki.](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing)
+
+Contributors
+------------
+
+A lot of great people have contributed to this module. A somewhat current list follows:
+
+* Ben Godfrey
+* Branan Purvine-Riley
+* Christian G. Warden
+* Dan Bode
+* Garrett Honeycutt
+* Jeff Wallace
+* Ken Barber
+* Matthaus Litteken
+* Matthias Pigulla
+* Monty Taylor
+* Peter Drake
+* Reid Vandewiele
+* Robert Navarro
+* Ryan Coleman
+* Scott McLeod
+* Spencer Krum
+* William Van Hevelingen
+* Zach Leslie
diff --git a/puppet/apt/Rakefile b/puppet/apt/Rakefile
new file mode 100644
index 0000000000..bb60173e57
--- /dev/null
+++ b/puppet/apt/Rakefile
@@ -0,0 +1,2 @@
+require 'puppetlabs_spec_helper/rake_tasks'
+require 'rspec-system/rake_task'
diff --git a/puppet/apt/manifests/backports.pp b/puppet/apt/manifests/backports.pp
new file mode 100644
index 0000000000..e9180c48c2
--- /dev/null
+++ b/puppet/apt/manifests/backports.pp
@@ -0,0 +1,48 @@
+# 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)
+#
+# == 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
+) inherits apt::params {
+
+ $release_real = downcase($release)
+ $key = $::lsbdistid ? {
+ 'debian' => '55BE302B',
+ 'ubuntu' => '437D05B5',
+ }
+ $repos = $::lsbdistid ? {
+ 'debian' => 'main contrib non-free',
+ 'ubuntu' => 'main universe multiverse restricted',
+ }
+
+ apt::source { 'backports':
+ location => $location,
+ release => "${release_real}-backports",
+ repos => $repos,
+ key => $key,
+ key_server => 'pgp.mit.edu',
+ pin => '200',
+ }
+}
diff --git a/puppet/apt/manifests/builddep.pp b/puppet/apt/manifests/builddep.pp
new file mode 100644
index 0000000000..3294f71339
--- /dev/null
+++ b/puppet/apt/manifests/builddep.pp
@@ -0,0 +1,16 @@
+# 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',
+ notify => Exec['apt_update'],
+ }
+
+ # Need anchor to provide containment for dependencies.
+ anchor { "apt::builddep::${name}":
+ require => Class['apt::update'],
+ }
+}
diff --git a/puppet/apt/manifests/conf.pp b/puppet/apt/manifests/conf.pp
new file mode 100644
index 0000000000..3c4cb1975c
--- /dev/null
+++ b/puppet/apt/manifests/conf.pp
@@ -0,0 +1,18 @@
+define apt::conf (
+ $content,
+ $ensure = present,
+ $priority = '50'
+) {
+
+ include apt::params
+
+ $apt_conf_d = $apt::params::apt_conf_d
+
+ file { "${apt_conf_d}/${priority}${name}":
+ ensure => $ensure,
+ content => $content,
+ owner => root,
+ group => root,
+ mode => '0644',
+ }
+}
diff --git a/puppet/apt/manifests/debian/testing.pp b/puppet/apt/manifests/debian/testing.pp
new file mode 100644
index 0000000000..45133470fa
--- /dev/null
+++ b/puppet/apt/manifests/debian/testing.pp
@@ -0,0 +1,21 @@
+# 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: 55BE302B 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 => '55BE302B',
+ key_server => 'subkeys.pgp.net',
+ pin => '-10',
+ }
+}
diff --git a/puppet/apt/manifests/debian/unstable.pp b/puppet/apt/manifests/debian/unstable.pp
new file mode 100644
index 0000000000..401c9c5cda
--- /dev/null
+++ b/puppet/apt/manifests/debian/unstable.pp
@@ -0,0 +1,21 @@
+# 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: 55BE302B 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 => '55BE302B',
+ key_server => 'subkeys.pgp.net',
+ pin => '-10',
+ }
+}
diff --git a/puppet/apt/manifests/force.pp b/puppet/apt/manifests/force.pp
new file mode 100644
index 0000000000..2d33e942dc
--- /dev/null
+++ b/puppet/apt/manifests/force.pp
@@ -0,0 +1,24 @@
+# force.pp
+# force a package from a specific release
+
+define apt::force(
+ $release = 'testing',
+ $version = false,
+ $timeout = 300
+) {
+
+ $version_string = $version ? {
+ false => undef,
+ default => "=${version}",
+ }
+
+ $install_check = $version ? {
+ false => "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'",
+ default => "/usr/bin/dpkg -s ${name} | grep -q 'Version: ${version}'",
+ }
+ exec { "/usr/bin/apt-get -y -t ${release} install ${name}${version_string}":
+ unless => $install_check,
+ logoutput => 'on_failure',
+ timeout => $timeout,
+ }
+}
diff --git a/puppet/apt/manifests/init.pp b/puppet/apt/manifests/init.pp
new file mode 100644
index 0000000000..b106ad4909
--- /dev/null
+++ b/puppet/apt/manifests/init.pp
@@ -0,0 +1,121 @@
+# Class: apt
+#
+# This module manages the initial configuration of apt.
+#
+# Parameters:
+# The parameters listed here are not required in general and were
+# added for use cases related to development environments.
+# disable_keys - disables the requirement for all packages to be signed
+# always_apt_update - rather apt should be updated on every run (intended
+# for development environments where package updates are frequent)
+# 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)
+#
+# Actions:
+#
+# Requires:
+# puppetlabs/stdlib
+# Sample Usage:
+# class { 'apt': }
+
+class apt(
+ $always_apt_update = false,
+ $disable_keys = undef,
+ $proxy_host = false,
+ $proxy_port = '8080',
+ $purge_sources_list = false,
+ $purge_sources_list_d = false,
+ $purge_preferences_d = false,
+ $update_timeout = undef
+) {
+
+ include apt::params
+ include apt::update
+
+ validate_bool($purge_sources_list, $purge_sources_list_d, $purge_preferences_d)
+
+ $sources_list_content = $purge_sources_list ? {
+ false => undef,
+ true => "# Repos managed by puppet.\n",
+ }
+
+ if $always_apt_update == true {
+ Exec <| title=='apt_update' |> {
+ refreshonly => false,
+ }
+ }
+
+ $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",
+ owner => root,
+ group => root,
+ mode => '0644',
+ content => $sources_list_content,
+ notify => Exec['apt_update'],
+ }
+
+ file { 'sources.list.d':
+ ensure => directory,
+ path => $sources_list_d,
+ owner => root,
+ group => root,
+ purge => $purge_sources_list_d,
+ recurse => $purge_sources_list_d,
+ notify => Exec['apt_update'],
+ }
+
+ file { 'preferences.d':
+ ensure => directory,
+ path => $preferences_d,
+ owner => root,
+ group => root,
+ purge => $purge_preferences_d,
+ recurse => $purge_preferences_d,
+ }
+
+ case $disable_keys {
+ true: {
+ file { '99unauth':
+ ensure => present,
+ content => "APT::Get::AllowUnauthenticated 1;\n",
+ 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') }
+ }
+
+ $proxy_set = $proxy_host ? {
+ false => absent,
+ default => present
+ }
+
+ file { 'configure-apt-proxy':
+ ensure => $proxy_set,
+ path => "${apt_conf_d}/proxy",
+ content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";",
+ notify => Exec['apt_update'],
+ }
+
+ # Need anchor to provide containment for dependencies.
+ anchor { 'apt::update':
+ require => Class['apt::update'],
+ }
+}
diff --git a/puppet/apt/manifests/key.pp b/puppet/apt/manifests/key.pp
new file mode 100644
index 0000000000..c78bf658ce
--- /dev/null
+++ b/puppet/apt/manifests/key.pp
@@ -0,0 +1,90 @@
+define apt::key (
+ $key = $title,
+ $ensure = present,
+ $key_content = false,
+ $key_source = false,
+ $key_server = 'keyserver.ubuntu.com',
+ $key_options = false
+) {
+
+ include apt::params
+
+ $upkey = upcase($key)
+ # trim the key to the last 8 chars so we can match longer keys with apt-key list too
+ $trimmedkey = regsubst($upkey, '^.*(.{8})$', '\1')
+
+ if $key_content {
+ $method = 'content'
+ } elsif $key_source {
+ $method = 'source'
+ } elsif $key_server {
+ $method = 'server'
+ }
+
+ # This is a hash of the parts of the key definition that we care about.
+ # It is used as a unique identifier for this instance of apt::key. It gets
+ # hashed to ensure that the resource name doesn't end up being pages and
+ # pages (e.g. in the situation where key_content is specified).
+ $digest = sha1("${upkey}/${key_content}/${key_source}/${key_server}/")
+
+ # Allow multiple ensure => present for the same key to account for many
+ # apt::source resources that all reference the same key.
+ case $ensure {
+ present: {
+
+ anchor { "apt::key/${title}": }
+
+ if defined(Exec["apt::key ${upkey} absent"]) {
+ fail("Cannot ensure Apt::Key[${upkey}] present; ${upkey} already ensured absent")
+ }
+
+ if !defined(Anchor["apt::key ${upkey} present"]) {
+ anchor { "apt::key ${upkey} present": }
+ }
+
+ if $key_options{
+ $options_string = "--keyserver-options ${key_options}"
+ }
+ else{
+ $options_string = ''
+ }
+
+ if !defined(Exec[$digest]) {
+ $digest_command = $method ? {
+ 'content' => "echo '${key_content}' | /usr/bin/apt-key add -",
+ 'source' => "wget -q '${key_source}' -O- | apt-key add -",
+ 'server' => "apt-key adv --keyserver '${key_server}' ${options_string} --recv-keys '${upkey}'",
+ }
+ exec { $digest:
+ command => $digest_command,
+ path => '/bin:/usr/bin',
+ unless => "/usr/bin/apt-key list | /bin/grep '${trimmedkey}'",
+ logoutput => 'on_failure',
+ before => Anchor["apt::key ${upkey} present"],
+ }
+ }
+
+ Anchor["apt::key ${upkey} present"] -> Anchor["apt::key/${title}"]
+
+ }
+ absent: {
+
+ if defined(Anchor["apt::key ${upkey} present"]) {
+ fail("Cannot ensure Apt::Key[${upkey}] absent; ${upkey} already ensured present")
+ }
+
+ exec { "apt::key ${upkey} absent":
+ command => "apt-key del '${upkey}'",
+ path => '/bin:/usr/bin',
+ onlyif => "apt-key list | grep '${trimmedkey}'",
+ user => 'root',
+ group => 'root',
+ logoutput => 'on_failure',
+ }
+ }
+
+ default: {
+ fail "Invalid 'ensure' value '${ensure}' for aptkey"
+ }
+ }
+}
diff --git a/puppet/apt/manifests/params.pp b/puppet/apt/manifests/params.pp
new file mode 100644
index 0000000000..955954fe89
--- /dev/null
+++ b/puppet/apt/manifests/params.pp
@@ -0,0 +1,33 @@
+class apt::params {
+ $root = '/etc/apt'
+ $provider = '/usr/bin/apt-get'
+ $sources_list_d = "${root}/sources.list.d"
+ $apt_conf_d = "${root}/apt.conf.d"
+ $preferences_d = "${root}/preferences.d"
+
+ case $::lsbdistid {
+ 'debian': {
+ case $::lsbdistcodename {
+ 'squeeze': {
+ $backports_location = 'http://backports.debian.org/debian-backports'
+ }
+ 'wheezy': {
+ $backports_location = 'http://ftp.debian.org/debian/'
+ }
+ default: {
+ $backports_location = 'http://http.debian.net/debian/'
+ }
+ }
+ }
+ 'ubuntu': {
+ case $::lsbdistcodename {
+ 'hardy','lucid','maverick','natty','oneiric','precise': {
+ $backports_location = 'http://us.archive.ubuntu.com/ubuntu'
+ }
+ default: {
+ $backports_location = 'http://old-releases.ubuntu.com/ubuntu'
+ }
+ }
+ }
+ }
+}
diff --git a/puppet/apt/manifests/pin.pp b/puppet/apt/manifests/pin.pp
new file mode 100644
index 0000000000..402e79ede7
--- /dev/null
+++ b/puppet/apt/manifests/pin.pp
@@ -0,0 +1,73 @@
+# pin.pp
+# pin a release in apt, useful for unstable repositories
+
+define apt::pin(
+ $ensure = present,
+ $explanation = "${::caller_module_name}: ${name}",
+ $order = '',
+ $packages = '*',
+ $priority = 0,
+ $release = '', # a=
+ $origin = '',
+ $version = '',
+ $codename = '', # n=
+ $release_version = '', # v=
+ $component = '', # c=
+ $originator = '', # o=
+ $label = '' # l=
+) {
+
+ include apt::params
+
+ $preferences_d = $apt::params::preferences_d
+
+ if $order != '' and !is_integer($order) {
+ fail('Only integers are allowed in the apt::pin order param')
+ }
+
+ $pin_release_array = [
+ $release,
+ $codename,
+ $release_version,
+ $component,
+ $originator,
+ $label]
+ $pin_release = join($pin_release_array, '')
+
+ # Read the manpage 'apt_preferences(5)', especially the chapter
+ # 'Thea Effect of APT Preferences' to understand the following logic
+ # and the difference between specific and general form
+ if $packages != '*' { # specific form
+
+ if ( $pin_release != '' and ( $origin != '' or $version != '' )) or
+ ( $origin != '' and ( $pin_release != '' or $version != '' )) or
+ ( $version != '' and ( $pin_release != '' or $origin != '' )) {
+ fail('parameters release, origin, and version are mutually exclusive')
+ }
+
+ } else { # general form
+
+ if $version != '' {
+ fail('parameter version cannot be used in general form')
+ }
+
+ if ( $pin_release != '' and $origin != '' ) or
+ ( $origin != '' and $pin_release != '' ) {
+ fail('parmeters release and origin are mutually exclusive')
+ }
+
+ }
+
+ $path = $order ? {
+ '' => "${preferences_d}/${name}.pref",
+ default => "${preferences_d}/${order}-${name}.pref",
+ }
+ file { "${name}.pref":
+ ensure => $ensure,
+ path => $path,
+ owner => root,
+ group => root,
+ mode => '0644',
+ content => template('apt/pin.pref.erb'),
+ }
+}
diff --git a/puppet/apt/manifests/ppa.pp b/puppet/apt/manifests/ppa.pp
new file mode 100644
index 0000000000..7cb88c8cd5
--- /dev/null
+++ b/puppet/apt/manifests/ppa.pp
@@ -0,0 +1,63 @@
+# ppa.pp
+
+define apt::ppa(
+ $release = $::lsbdistcodename,
+ $options = '-y'
+) {
+ include apt::params
+ include apt::update
+
+ $sources_list_d = $apt::params::sources_list_d
+
+ if ! $release {
+ fail('lsbdistcodename fact not available: release parameter required')
+ }
+
+ $filename_without_slashes = regsubst($name, '/', '-', 'G')
+ $filename_without_dots = regsubst($filename_without_slashes, '\.', '_', 'G')
+ $filename_without_ppa = regsubst($filename_without_dots, '^ppa:', '', 'G')
+ $sources_list_d_filename = "${filename_without_ppa}-${release}.list"
+
+ $package = $::lsbdistrelease ? {
+ /^[1-9]\..*|1[01]\..*|12.04$/ => 'python-software-properties',
+ default => 'software-properties-common',
+ }
+
+ if ! defined(Package[$package]) {
+ package { $package: }
+ }
+
+ if defined(Class[apt]) {
+ $proxy_host = getparam(Class[apt], 'proxy_host')
+ $proxy_port = getparam(Class[apt], 'proxy_port')
+ case $proxy_host {
+ false, '': {
+ $proxy_env = []
+ }
+ default: {$proxy_env = ["http_proxy=http://${proxy_host}:${proxy_port}", "https_proxy=http://${proxy_host}:${proxy_port}"]}
+ }
+ } else {
+ $proxy_env = []
+ }
+ exec { "add-apt-repository-${name}":
+ environment => $proxy_env,
+ command => "/usr/bin/add-apt-repository ${options} ${name}",
+ unless => "/usr/bin/test -s ${sources_list_d}/${sources_list_d_filename}",
+ logoutput => 'on_failure',
+ notify => Exec['apt_update'],
+ require => [
+ File[$sources_list_d],
+ Package[$package],
+ ],
+ }
+
+ file { "${sources_list_d}/${sources_list_d_filename}":
+ ensure => file,
+ require => Exec["add-apt-repository-${name}"],
+ }
+
+ # Need anchor to provide containment for dependencies.
+ anchor { "apt::ppa::${name}":
+ require => Class['apt::update'],
+ }
+}
diff --git a/puppet/apt/manifests/release.pp b/puppet/apt/manifests/release.pp
new file mode 100644
index 0000000000..6e0a38f73f
--- /dev/null
+++ b/puppet/apt/manifests/release.pp
@@ -0,0 +1,17 @@
+# 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 => "APT::Default-Release \"${release_id}\";"
+ }
+}
diff --git a/puppet/apt/manifests/source.pp b/puppet/apt/manifests/source.pp
new file mode 100644
index 0000000000..713c7e933a
--- /dev/null
+++ b/puppet/apt/manifests/source.pp
@@ -0,0 +1,85 @@
+# source.pp
+# add an apt source
+
+define apt::source(
+ $ensure = present,
+ $location = '',
+ $release = 'UNDEF',
+ $repos = 'main',
+ $include_src = true,
+ $required_packages = false,
+ $key = false,
+ $key_server = 'keyserver.ubuntu.com',
+ $key_content = false,
+ $key_source = false,
+ $pin = false,
+ $architecture = undef
+) {
+
+ include apt::params
+ include apt::update
+
+ $sources_list_d = $apt::params::sources_list_d
+ $provider = $apt::params::provider
+
+ if $release == 'UNDEF' {
+ if $::lsbdistcodename == undef {
+ fail('lsbdistcodename fact not available: release parameter required')
+ } else {
+ $release_real = $::lsbdistcodename
+ }
+ } else {
+ $release_real = $release
+ }
+
+ file { "${name}.list":
+ ensure => $ensure,
+ path => "${sources_list_d}/${name}.list",
+ owner => root,
+ group => root,
+ mode => '0644',
+ content => template("${module_name}/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,
+ subscribe => File["${name}.list"],
+ before => Exec['apt_update'],
+ }
+ }
+
+ # We do not want to remove keys when the source is absent.
+ if ($key != false) 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"],
+ }
+ }
+
+ # Need anchor to provide containment for dependencies.
+ anchor { "apt::source::${name}":
+ require => Class['apt::update'],
+ }
+}
diff --git a/puppet/apt/manifests/unattended_upgrades.pp b/puppet/apt/manifests/unattended_upgrades.pp
new file mode 100644
index 0000000000..f006bd5289
--- /dev/null
+++ b/puppet/apt/manifests/unattended_upgrades.pp
@@ -0,0 +1,68 @@
+# 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 (
+ $origins = ['${distro_id}:${distro_codename}-security'],
+ $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",
+ $enable = "1",
+ $backup_interval = "0",
+ $backup_level = "3",
+ $max_age = "0",
+ $min_age = "0",
+ $max_size = "0",
+ $download_delta = "0",
+ $verbose = "0",
+) {
+
+ validate_bool(
+ $auto_fix,
+ $minimal_steps,
+ $install_on_shutdown,
+ $mail_only_on_error,
+ $remove_unused,
+ $auto_reboot
+ )
+
+ package { 'unattended-upgrades':
+ ensure => present,
+ }
+
+ File {
+ ensure => file,
+ owner => 'root',
+ group => 'root',
+ mode => '0644',
+ require => Package['unattended-upgrades'],
+ }
+
+ file {
+ '/etc/apt/apt.conf.d/50unattended-upgrades':
+ content => template('apt/50unattended-upgrades.erb');
+ '/etc/apt/apt.conf.d/10periodic':
+ content => template('apt/10periodic.erb');
+ }
+}
diff --git a/puppet/apt/manifests/update.pp b/puppet/apt/manifests/update.pp
new file mode 100644
index 0000000000..ce0b78fbdd
--- /dev/null
+++ b/puppet/apt/manifests/update.pp
@@ -0,0 +1,10 @@
+class apt::update {
+ include apt::params
+
+ exec { 'apt_update':
+ command => "${apt::params::provider} update",
+ logoutput => 'on_failure',
+ refreshonly => true,
+ timeout => $apt::update_timeout,
+ }
+}
diff --git a/puppet/apt/metadata.json b/puppet/apt/metadata.json
new file mode 100644
index 0000000000..3e4c9921c1
--- /dev/null
+++ b/puppet/apt/metadata.json
@@ -0,0 +1,87 @@
+{
+ "name": "puppetlabs-apt",
+ "version": "1.4.0",
+ "summary": "Puppet Labs Apt Module",
+ "author": "Evolving Web / Puppet Labs",
+ "description": "APT Module for Puppet",
+ "dependencies": [
+ {
+ "name": "puppetlabs/stdlib",
+ "version_requirement": "\u003e\u003d 2.2.1"
+ }
+ ],
+ "types": [],
+ "checksums": {
+ ".bundle/config": "7f1c988748783d2a8d455376eed1470c",
+ ".fixtures.yml": "0c43f56b0bb8e8d04e8051a0e7aa37a5",
+ ".forge-release/pom.xml": "c650a84961ad88de03192e23b63b3549",
+ ".forge-release/publish": "1c1d6dd64ef52246db485eb5459aa941",
+ ".forge-release/settings.xml": "06d768a57d582fe1ee078b563427e750",
+ ".forge-release/validate": "7fffde8112f42a1ec986d49ba80ac219",
+ ".nodeset.yml": "78d78c172336a387a1067464434ffbcb",
+ ".travis.yml": "782420dcc9d6412c79c30f03b1f3613c",
+ "CHANGELOG": "f5488e1e891a8f8c47143dac790ddab3",
+ "Gemfile": "1bfa7eb6e30346c9ddb4a8b144b0d255",
+ "Gemfile.lock": "8ff8bc3d32bb7412bd97e48190a93b2f",
+ "LICENSE": "20bcc606fc61ffba2b8cea840e8dce4d",
+ "Modulefile": "b34e93626fbc137cbb651952e7509839",
+ "README.md": "65176b395f7202fe5d222ae7b0de4e05",
+ "Rakefile": "0428ea3759a4692c91604396c406a9c1",
+ "manifests/backports.pp": "09f1d86603d0f44a2169acb3eeea2a70",
+ "manifests/builddep.pp": "4f313b5140c84aa7d5793b5a073c30dd",
+ "manifests/conf.pp": "5ddf258195d414d93284dfd281a8d6e3",
+ "manifests/debian/testing.pp": "aeb625bacb6a8df46c864ee9ee1cb5a5",
+ "manifests/debian/unstable.pp": "108038596b05dc1d28975884693f73f5",
+ "manifests/force.pp": "cf871e869f4114f32ab164de2a67e7e2",
+ "manifests/init.pp": "5ec106a7a03313c544159a9a1f6b78e6",
+ "manifests/key.pp": "3cf082ed91a3933ab7218d1be3464f4f",
+ "manifests/params.pp": "ca4ce3730a65c43f884ab3e6445f1661",
+ "manifests/pin.pp": "dea8cbaabc37010ce25838080608802b",
+ "manifests/ppa.pp": "754a83944ae79b5001fc0c0a8c775985",
+ "manifests/release.pp": "427f3ee70a6a1e55fa291e58655bd5d9",
+ "manifests/source.pp": "6eab8d33c173a066f5dec8474efdedb6",
+ "manifests/unattended_upgrades.pp": "e97f908b42010ff9a85be4afd2c721ab",
+ "manifests/update.pp": "436c79f160f2cb603710795a9ec71ac7",
+ "spec/classes/apt_spec.rb": "54841b04b42026770ed6d744a82c55df",
+ "spec/classes/backports_spec.rb": "7d2454a881cc26edd3dcd3acb7ffd20f",
+ "spec/classes/debian_testing_spec.rb": "fad1384cb9d3c99b2663d7df4762dc0e",
+ "spec/classes/debian_unstable_spec.rb": "11131efffd18db3c96e2bbe3d98a2fb7",
+ "spec/classes/params_spec.rb": "a25396d3f0bbac784a7951f03ad7e8f4",
+ "spec/classes/release_spec.rb": "d8f01a3cf0c2f6f6952b835196163ce4",
+ "spec/classes/unattended_upgrades_spec.rb": "a2e206bda79d24cdb43312d035eff66f",
+ "spec/defines/builddep_spec.rb": "e1300bb4f3abbd34029b11d8b733a6e5",
+ "spec/defines/conf_spec.rb": "b7fc9fb6cb270c276aacbfa4a43f228c",
+ "spec/defines/force_spec.rb": "97098c5b123be49e321e71cda288fe53",
+ "spec/defines/key_spec.rb": "7800c30647b1ddf799b991110109cba0",
+ "spec/defines/pin_spec.rb": "c912e59e9e3d1145280d659cccabe72b",
+ "spec/defines/ppa_spec.rb": "72ce037a1d6ea0a33f369b1f3d98b3d6",
+ "spec/defines/source_spec.rb": "e553bb9598dbe2becba6ae7f91d4deb0",
+ "spec/spec_helper.rb": "0db89c9a486df193c0e40095422e19dc",
+ "spec/spec_helper_system.rb": "e67d2574baae312f1095f90d78fdf5e9",
+ "spec/system/apt_builddep_spec.rb": "97be5a48d2d16d96cb7c35ccdbcdcb69",
+ "spec/system/apt_key_spec.rb": "098835d0c53c69390d4c3b6ea8ef3815",
+ "spec/system/apt_ppa_spec.rb": "c96f6d0bbdafac39beaf0d5e6eba9010",
+ "spec/system/apt_source_spec.rb": "df5aa98b03688884903c564bb507469f",
+ "spec/system/basic_spec.rb": "0a5b33d18254bedcb7886e34846ebff6",
+ "spec/system/class_spec.rb": "2ba4265236f00685c23cb00f908defc1",
+ "templates/10periodic.erb": "2aeea866a39f19a62254abbb4f1bc59d",
+ "templates/50unattended-upgrades.erb": "ae995ade214fdaefab51d335c85819ae",
+ "templates/pin.pref.erb": "623249839cee7788fa0805a3474396db",
+ "templates/source.list.erb": "65a016e60daf065c481f3d5f2c883324",
+ "tests/builddep.pp": "4773f57072111e58f2ed833fa4489a88",
+ "tests/debian/testing.pp": "1cbee56baddd6a91d981db8fddec70fb",
+ "tests/debian/unstable.pp": "4b2a090afeb315752262386f4dbcd8ca",
+ "tests/force.pp": "2bb6cf0b3d655cb51f95aeb79035e600",
+ "tests/init.pp": "551138eb704e71ab3687932dda429a81",
+ "tests/key.pp": "371a695e1332d51a38e283a87be52798",
+ "tests/params.pp": "900db40f3fc84b0be173278df2ebff35",
+ "tests/pin.pp": "4b4c3612d75a19dba8eb7227070fa4ab",
+ "tests/ppa.pp": "b902cce8159128b5e8b21bed540743ff",
+ "tests/release.pp": "53ce5debe6fa5bee42821767599cc768",
+ "tests/source.pp": "9cecd9aa0dcde250fe49be9e26971a98",
+ "tests/unattended-upgrades.pp": "cdc853f1b58e5206c5a538621ddca161"
+ },
+ "source": "https://github.com/puppetlabs/puppetlabs-apt",
+ "project_page": "https://github.com/puppetlabs/puppetlabs-apt",
+ "license": "Apache License 2.0"
+}
\ No newline at end of file
diff --git a/puppet/apt/spec/classes/apt_spec.rb b/puppet/apt/spec/classes/apt_spec.rb
new file mode 100644
index 0000000000..a66feac788
--- /dev/null
+++ b/puppet/apt/spec/classes/apt_spec.rb
@@ -0,0 +1,133 @@
+require 'spec_helper'
+describe 'apt', :type => :class do
+ let :default_params do
+ {
+ :disable_keys => :undef,
+ :always_apt_update => false,
+ :purge_sources_list => false,
+ :purge_sources_list_d => false,
+ }
+ end
+
+ [{},
+ {
+ :disable_keys => true,
+ :always_apt_update => true,
+ :proxy_host => true,
+ :proxy_port => '3128',
+ :purge_sources_list => true,
+ :purge_sources_list_d => true,
+ },
+ {
+ :disable_keys => false
+ }
+ ].each do |param_set|
+ describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
+ let :param_hash do
+ default_params.merge(param_set)
+ end
+
+ let :params do
+ param_set
+ end
+
+ let :refresh_only_apt_update do
+ if param_hash[:always_apt_update]
+ false
+ else
+ true
+ end
+ end
+
+ it { should include_class("apt::params") }
+
+ it {
+ if param_hash[:purge_sources_list]
+ should contain_file("sources.list").with({
+ 'path' => "/etc/apt/sources.list",
+ 'ensure' => "present",
+ 'owner' => "root",
+ 'group' => "root",
+ 'mode' => "0644",
+ "content" => "# Repos managed by puppet.\n"
+ })
+ else
+ should contain_file("sources.list").with({
+ 'path' => "/etc/apt/sources.list",
+ 'ensure' => "present",
+ 'owner' => "root",
+ 'group' => "root",
+ 'mode' => "0644",
+ 'content' => nil
+ })
+ end
+ }
+ it {
+ if param_hash[:purge_sources_list_d]
+ should create_file("sources.list.d").with({
+ 'path' => "/etc/apt/sources.list.d",
+ 'ensure' => "directory",
+ 'owner' => "root",
+ 'group' => "root",
+ 'purge' => true,
+ 'recurse' => true,
+ 'notify' => 'Exec[apt_update]'
+ })
+ else
+ should create_file("sources.list.d").with({
+ 'path' => "/etc/apt/sources.list.d",
+ 'ensure' => "directory",
+ 'owner' => "root",
+ 'group' => "root",
+ 'purge' => false,
+ 'recurse' => false,
+ 'notify' => 'Exec[apt_update]'
+ })
+ end
+ }
+
+ it {
+ should contain_exec("apt_update").with({
+ 'command' => "/usr/bin/apt-get update",
+ 'refreshonly' => refresh_only_apt_update
+ })
+ }
+
+ it {
+ if param_hash[:disable_keys] == true
+ should create_file("99unauth").with({
+ 'content' => "APT::Get::AllowUnauthenticated 1;\n",
+ 'ensure' => "present",
+ 'path' => "/etc/apt/apt.conf.d/99unauth"
+ })
+ elsif param_hash[:disable_keys] == false
+ should create_file("99unauth").with({
+ 'ensure' => "absent",
+ 'path' => "/etc/apt/apt.conf.d/99unauth"
+ })
+ elsif param_hash[:disable_keys] != :undef
+ should_not create_file("99unauth").with({
+ 'path' => "/etc/apt/apt.conf.d/99unauth"
+ })
+ end
+ }
+ describe 'when setting a proxy' do
+ it {
+ if param_hash[:proxy_host]
+ should contain_file('configure-apt-proxy').with(
+ 'path' => '/etc/apt/apt.conf.d/proxy',
+ 'content' => "Acquire::http::Proxy \"http://#{param_hash[:proxy_host]}:#{param_hash[:proxy_port]}\";",
+ 'notify' => "Exec[apt_update]"
+ )
+ else
+ should contain_file('configure-apt-proxy').with(
+ 'path' => '/etc/apt/apt.conf.d/proxy',
+ 'notify' => 'Exec[apt_update]',
+ 'ensure' => 'absent'
+ )
+ end
+ }
+ end
+ end
+ end
+end
diff --git a/puppet/apt/spec/classes/backports_spec.rb b/puppet/apt/spec/classes/backports_spec.rb
new file mode 100644
index 0000000000..27c6708f25
--- /dev/null
+++ b/puppet/apt/spec/classes/backports_spec.rb
@@ -0,0 +1,71 @@
+require 'spec_helper'
+describe 'apt::backports', :type => :class do
+
+ describe 'when turning on backports for ubuntu karmic' do
+
+ let :facts do
+ {
+ 'lsbdistcodename' => 'Karmic',
+ 'lsbdistid' => 'Ubuntu'
+ }
+ end
+
+ it { should contain_apt__source('backports').with({
+ 'location' => 'http://old-releases.ubuntu.com/ubuntu',
+ 'release' => 'karmic-backports',
+ 'repos' => 'main universe multiverse restricted',
+ 'key' => '437D05B5',
+ 'key_server' => 'pgp.mit.edu',
+ 'pin' => '200',
+ })
+ }
+ end
+
+ describe "when turning on backports for debian squeeze" do
+
+ let :facts do
+ {
+ 'lsbdistcodename' => 'Squeeze',
+ 'lsbdistid' => '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' => '55BE302B',
+ 'key_server' => 'pgp.mit.edu',
+ 'pin' => '200',
+ })
+ }
+ end
+
+ describe "when turning on backports for debian squeeze but using your own mirror" do
+
+ let :facts do
+ {
+ 'lsbdistcodename' => 'Squeeze',
+ 'lsbdistid' => 'Debian'
+ }
+ 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' => '55BE302B',
+ 'key_server' => 'pgp.mit.edu',
+ 'pin' => '200',
+ })
+ }
+ end
+end
diff --git a/puppet/apt/spec/classes/debian_testing_spec.rb b/puppet/apt/spec/classes/debian_testing_spec.rb
new file mode 100644
index 0000000000..6006afb418
--- /dev/null
+++ b/puppet/apt/spec/classes/debian_testing_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+describe 'apt::debian::testing', :type => :class do
+ 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" => "55BE302B",
+ "key_server" => "subkeys.pgp.net",
+ "pin" => "-10"
+ })
+ }
+end
diff --git a/puppet/apt/spec/classes/debian_unstable_spec.rb b/puppet/apt/spec/classes/debian_unstable_spec.rb
new file mode 100644
index 0000000000..411182df11
--- /dev/null
+++ b/puppet/apt/spec/classes/debian_unstable_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+describe 'apt::debian::unstable', :type => :class do
+ 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" => "55BE302B",
+ "key_server" => "subkeys.pgp.net",
+ "pin" => "-10"
+ })
+ }
+end
diff --git a/puppet/apt/spec/classes/params_spec.rb b/puppet/apt/spec/classes/params_spec.rb
new file mode 100644
index 0000000000..f2790b0adb
--- /dev/null
+++ b/puppet/apt/spec/classes/params_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper'
+describe 'apt::params', :type => :class do
+ let (:title) { 'my_package' }
+
+ it { should 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
+end
diff --git a/puppet/apt/spec/classes/release_spec.rb b/puppet/apt/spec/classes/release_spec.rb
new file mode 100644
index 0000000000..d131b22810
--- /dev/null
+++ b/puppet/apt/spec/classes/release_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+describe 'apt::release', :type => :class do
+ let (:title) { 'my_package' }
+
+ let :param_set do
+ { :release_id => 'precise' }
+ end
+
+ let (:params) { param_set }
+
+ it { should include_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/puppet/apt/spec/classes/unattended_upgrades_spec.rb b/puppet/apt/spec/classes/unattended_upgrades_spec.rb
new file mode 100644
index 0000000000..8abc603251
--- /dev/null
+++ b/puppet/apt/spec/classes/unattended_upgrades_spec.rb
@@ -0,0 +1,204 @@
+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' }
+
+ 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 "origins" do
+ describe "with param defaults" do
+ let(:params) {{ }}
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Allowed-Origins \{\n\t"\${distro_id}:\${distro_codename}-security";\n\};$/) }
+ end
+
+ describe "with origins => ['ubuntu:precise-security']" do
+ let :params do
+ { :origins => ['ubuntu:precise-security'] }
+ end
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Allowed-Origins \{\n\t"ubuntu:precise-security";\n\};$/) }
+ end
+ end
+
+ describe "blacklist" do
+ describe "with param defaults" do
+ let(:params) {{ }}
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\};$/) }
+ end
+
+ describe "with blacklist => []" do
+ let :params do
+ { :blacklist => ['libc6', 'libc6-dev'] }
+ end
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\t"libc6";\n\t"libc6-dev";\n\};$/) }
+ end
+ end
+
+ describe "with update => 2" do
+ let :params do
+ { :update => "2" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::Update-Package-Lists "2";$/) }
+ end
+
+ describe "with download => 2" do
+ let :params do
+ { :download => "2" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages "2";$/) }
+ end
+
+ describe "with upgrade => 2" do
+ let :params do
+ { :upgrade => "2" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::Unattended-Upgrade "2";$/) }
+ end
+
+ describe "with autoclean => 2" do
+ let :params do
+ { :autoclean => "2" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::AutocleanInterval "2";$/) }
+ end
+
+ describe "with auto_fix => false" do
+ let :params do
+ { :auto_fix => false }
+ end
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::AutoFixInterruptedDpkg "false";$/) }
+ end
+
+ describe "with minimal_steps => true" do
+ let :params do
+ { :minimal_steps => true }
+ end
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MinimalSteps "true";$/) }
+ end
+
+ describe "with install_on_shutdown => true" do
+ let :params do
+ { :install_on_shutdown => true }
+ end
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::InstallOnShutdown "true";$/) }
+ end
+
+ describe "mail_to" do
+ describe "param defaults" do
+ let(:params) {{ }}
+ it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail /) }
+ it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError /) }
+ end
+
+ describe "with mail_to => user@website, mail_only_on_error => true" do
+ let :params do
+ { :mail_to => "user@website",
+ :mail_only_on_error => true }
+ end
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail "user@website";$/) }
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError "true";$/) }
+ end
+ end
+
+ describe "with remove_unused => false" do
+ let :params do
+ { :remove_unused => false }
+ end
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Remove-Unused-Dependencies "false";$/) }
+ end
+
+ describe "with auto_reboot => true" do
+ let :params do
+ { :auto_reboot => true }
+ end
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Automatic-Reboot "true";$/) }
+ end
+
+ describe "dl_limit" do
+ describe "param defaults" do
+ let(:params) {{ }}
+ it { should_not contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit /) }
+ end
+
+ describe "with dl_limit => 70" do
+ let :params do
+ { :dl_limit => "70" }
+ end
+ it { should contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit "70";$/) }
+ end
+ end
+
+ describe "with enable => 0" do
+ let :params do
+ { :enable => "0" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::Enable "0";$/) }
+ end
+
+ describe "with backup_interval => 1" do
+ let :params do
+ { :backup_interval => "1" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpArchiveInterval "1";$/) }
+ end
+
+ describe "with backup_level => 0" do
+ let :params do
+ { :backup_level => "0" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpLevel "0";$/) }
+ end
+
+ describe "with max_age => 1" do
+ let :params do
+ { :max_age => "1" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxAge "1";$/) }
+ end
+
+ describe "with min_age => 1" do
+ let :params do
+ { :min_age => "1" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::MinAge "1";$/) }
+ end
+
+ describe "with max_size => 1" do
+ let :params do
+ { :max_size => "1" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxSize "1";$/) }
+ end
+
+ describe "with download_delta => 2" do
+ let :params do
+ { :download_delta => "2" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";$/) }
+ end
+
+ describe "with verbose => 2" do
+ let :params do
+ { :verbose => "2" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::Verbose "2";$/) }
+ end
+
+end
diff --git a/puppet/apt/spec/defines/builddep_spec.rb b/puppet/apt/spec/defines/builddep_spec.rb
new file mode 100644
index 0000000000..4e2b698d93
--- /dev/null
+++ b/puppet/apt/spec/defines/builddep_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+describe 'apt::builddep', :type => :define do
+
+ let(:title) { 'my_package' }
+
+ describe "should require apt-get update" do
+ it { should contain_exec("apt_update").with({
+ 'command' => "/usr/bin/apt-get update",
+ 'refreshonly' => true
+ })
+ }
+ it { should contain_anchor("apt::builddep::my_package").with({
+ 'require' => 'Class[Apt::Update]',
+ })
+ }
+ end
+
+end
diff --git a/puppet/apt/spec/defines/conf_spec.rb b/puppet/apt/spec/defines/conf_spec.rb
new file mode 100644
index 0000000000..5a81b5148c
--- /dev/null
+++ b/puppet/apt/spec/defines/conf_spec.rb
@@ -0,0 +1,57 @@
+require 'spec_helper'
+describe 'apt::conf', :type => :define do
+ let :title do
+ 'norecommends'
+ end
+
+ describe "when creating an apt preference" do
+ let :params do
+ {
+ :priority => '00',
+ :content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
+ }
+ end
+
+ let :filename do
+ "/etc/apt/apt.conf.d/00norecommends"
+ end
+
+ it { should contain_apt__conf('norecommends').with({
+ 'priority' => '00',
+ 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
+ })
+ }
+
+ it { should contain_file(filename).with({
+ 'ensure' => 'present',
+ 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
+ 'owner' => 'root',
+ 'group' => 'root',
+ 'mode' => '0644',
+ })
+ }
+ 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
+
+ let :filename do
+ "/etc/apt/apt.conf.d/00norecommends"
+ end
+
+ it { should contain_file(filename).with({
+ 'ensure' => 'absent',
+ 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
+ 'owner' => 'root',
+ 'group' => 'root',
+ 'mode' => '0644',
+ })
+ }
+ end
+end
diff --git a/puppet/apt/spec/defines/force_spec.rb b/puppet/apt/spec/defines/force_spec.rb
new file mode 100644
index 0000000000..f5d6ac22a9
--- /dev/null
+++ b/puppet/apt/spec/defines/force_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper'
+describe 'apt::force', :type => :define do
+ let :title do
+ 'my_package'
+ end
+
+ let :default_params do
+ {
+ :release => 'testing',
+ :version => false
+ }
+ end
+
+ [{},
+ {
+ :release => 'stable',
+ :version => '1'
+ }
+ ].each do |param_set|
+ describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
+ let :param_hash do
+ default_params.merge(param_set)
+ end
+
+ let :params do
+ param_set
+ end
+
+ let :unless_query do
+ base_command = "/usr/bin/dpkg -s #{title} | grep -q "
+ base_command + (params[:version] ? "'Version: #{params[:version]}'" : "'Status: install'")
+ end
+
+ let :exec_title do
+ base_exec = "/usr/bin/apt-get -y -t #{param_hash[:release]} install #{title}"
+ base_exec + (params[:version] ? "=#{params[:version]}" : "")
+ end
+ it { should contain_exec(exec_title).with_unless(unless_query) }
+ end
+ end
+end
diff --git a/puppet/apt/spec/defines/key_spec.rb b/puppet/apt/spec/defines/key_spec.rb
new file mode 100644
index 0000000000..aea197a7b2
--- /dev/null
+++ b/puppet/apt/spec/defines/key_spec.rb
@@ -0,0 +1,123 @@
+require 'spec_helper'
+describe 'apt::key', :type => :define do
+ let :title do
+ '8347A27F'
+ end
+
+ let :default_params do
+ {
+ :key => title,
+ :ensure => 'present',
+ :key_server => "keyserver.ubuntu.com",
+ :key_source => false,
+ :key_content => false
+ }
+ end
+
+ [{},
+ {
+ :ensure => 'absent'
+ },
+ {
+ :ensure => 'random'
+ },
+ {
+ :key_source => 'ftp://ftp.example.org/key',
+ },
+ {
+ :key_content => 'deadbeef',
+ }
+ ].each do |param_set|
+
+ let :param_hash do
+ param_hash = default_params.merge(param_set)
+ param_hash[:key].upcase! if param_hash[:key]
+ param_hash
+ end
+
+ let :params do
+ param_set
+ end
+
+ let :digest do
+ str = String.new
+ str << param_hash[:key].to_s << '/'
+ str << param_hash[:key_content].to_s << '/'
+ str << param_hash[:key_source].to_s << '/'
+ str << param_hash[:key_server].to_s << '/'
+ Digest::SHA1.hexdigest(str)
+ end
+
+ describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
+
+ it {
+ if [:present, 'present', :absent, 'absent'].include? param_hash[:ensure]
+ should contain_apt__params
+ end
+ }
+
+ it {
+ if [:present, 'present'].include? param_hash[:ensure]
+ should_not contain_exec("apt::key #{param_hash[:key]} absent")
+ should contain_anchor("apt::key #{param_hash[:key]} present")
+ should contain_exec(digest).with({
+ "path" => "/bin:/usr/bin",
+ "unless" => "/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'"
+ })
+ elsif [:absent, 'absent'].include? param_hash[:ensure]
+ should_not contain_anchor("apt::key #{param_hash[:key]} present")
+ should contain_exec("apt::key #{param_hash[:key]} absent").with({
+ "path" => "/bin:/usr/bin",
+ "onlyif" => "apt-key list | grep '#{param_hash[:key]}'",
+ "command" => "apt-key del '#{param_hash[:key]}'"
+ })
+ else
+ expect { should raise_error(Puppet::Error) }
+ end
+ }
+
+ it {
+ if [:present, 'present'].include? param_hash[:ensure]
+ if param_hash[:key_content]
+ should contain_exec(digest).with({
+ "command" => "echo '#{param_hash[:key_content]}' | /usr/bin/apt-key add -"
+ })
+ elsif param_hash[:key_source]
+ should contain_exec(digest).with({
+ "command" => "wget -q '#{param_hash[:key_source]}' -O- | apt-key add -"
+ })
+ elsif param_hash[:key_server]
+ should contain_exec(digest).with({
+ "command" => "apt-key adv --keyserver '#{param_hash[:key_server]}' --recv-keys '#{param_hash[:key]}'"
+ })
+ end
+ end
+ }
+
+ end
+ end
+
+ [{ :ensure => 'present' }, { :ensure => 'absent' }].each do |param_set|
+ describe "should correctly handle duplicate definitions" do
+
+ let :pre_condition do
+ "apt::key { 'duplicate': key => '#{title}'; }"
+ end
+
+ let(:params) { param_set }
+
+ it {
+ if param_set[:ensure] == 'present'
+ should contain_anchor("apt::key #{title} present")
+ should contain_apt__key(title)
+ should contain_apt__key("duplicate")
+ elsif param_set[:ensure] == 'absent'
+ expect { should raise_error(Puppet::Error) }
+ end
+ }
+
+ end
+ end
+
+end
+
diff --git a/puppet/apt/spec/defines/pin_spec.rb b/puppet/apt/spec/defines/pin_spec.rb
new file mode 100644
index 0000000000..a4cb1e26e3
--- /dev/null
+++ b/puppet/apt/spec/defines/pin_spec.rb
@@ -0,0 +1,101 @@
+require 'spec_helper'
+describe 'apt::pin', :type => :define do
+ let(:title) { 'my_pin' }
+
+ let :default_params do
+ {
+ :ensure => 'present',
+ :order => '',
+ :packages => '*',
+ :priority => '0',
+ :release => nil
+ }
+ end
+
+ [
+ { :params => {},
+ :content => "# my_pin\nExplanation: : my_pin\nPackage: *\nPin: release a=my_pin\nPin-Priority: 0\n"
+ },
+ {
+ :params => {
+ :packages => 'apache',
+ :priority => '1'
+ },
+ :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
+ },
+ {
+ :params => {
+ :order => 50,
+ :packages => 'apache',
+ :priority => '1'
+ },
+ :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
+ },
+ {
+ :params => {
+ :ensure => 'absent',
+ :packages => 'apache',
+ :priority => '1'
+ },
+ :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
+ },
+ {
+ :params => {
+ :packages => 'apache',
+ :priority => '1',
+ :release => 'my_newpin'
+ },
+ :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_newpin\nPin-Priority: 1\n"
+ },
+ {
+ :params => {
+ :packages => 'apache',
+ :priority => '1',
+ :version => '2.2.16*'
+ },
+ :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: version 2.2.16*\nPin-Priority: 1\n"
+ },
+ {
+ :params => {
+ :priority => '1',
+ :origin => 'ftp.de.debian.org'
+ },
+ :content => "# my_pin\nExplanation: : my_pin\nPackage: *\nPin: origin \"ftp.de.debian.org\"\nPin-Priority: 1\n"
+ },
+ {
+ :params => {
+ :packages => 'apache',
+ :priority => '1',
+ :release => 'stable',
+ :codename => 'wheezy',
+ :release_version => '3.0',
+ :component => 'main',
+ :originator => 'Debian',
+ :label => 'Debian'
+ },
+ :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=stable, n=wheezy, v=3.0, c=main, o=Debian, l=Debian\nPin-Priority: 1\n"
+ },
+ ].each do |param_set|
+ describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
+ let :param_hash do
+ default_params.merge(param_set[:params])
+ end
+
+ let :params do
+ param_set[:params]
+ end
+
+ it { should include_class("apt::params") }
+
+ it { should contain_file("#{title}.pref").with({
+ 'ensure' => param_hash[:ensure],
+ 'path' => "/etc/apt/preferences.d/#{param_hash[:order] == '' ? "" : "#{param_hash[:order]}-"}#{title}.pref",
+ 'owner' => 'root',
+ 'group' => 'root',
+ 'mode' => '0644',
+ 'content' => param_set[:content],
+ })
+ }
+ end
+ end
+end
diff --git a/puppet/apt/spec/defines/ppa_spec.rb b/puppet/apt/spec/defines/ppa_spec.rb
new file mode 100644
index 0000000000..5b59f57776
--- /dev/null
+++ b/puppet/apt/spec/defines/ppa_spec.rb
@@ -0,0 +1,143 @@
+require 'spec_helper'
+describe 'apt::ppa', :type => :define do
+ [ { :lsbdistrelease => '11.04',
+ :lsbdistcodename => 'natty',
+ :package => 'python-software-properties'},
+ { :lsbdistrelease => '12.10',
+ :lsbdistcodename => 'quantal',
+ :package => 'software-properties-common'},
+ ].each do |platform|
+ context "on #{platform[:lsbdistcodename]}" do
+ let :facts do
+ {
+ :lsbdistrelease => platform[:lsbdistrelease],
+ :lsbdistcodename => platform[:lsbdistcodename],
+ }
+ end
+ let :release do
+ "#{platform[:lsbdistcodename]}"
+ end
+ let :package do
+ "#{platform[:package]}"
+ end
+ let :options do
+ "-y"
+ end
+ ['ppa:dans_ppa', 'dans_ppa','ppa:dans-daily/ubuntu'].each do |t|
+ describe "with title #{t}" do
+ let :pre_condition do
+ 'class { "apt": }'
+ end
+ let :title do
+ t
+ end
+ let :filename do
+ t.sub(/^ppa:/,'').gsub('/','-') << "-" << "#{release}.list"
+ end
+
+ it { should contain_package("#{package}") }
+
+ it { should contain_exec("apt_update").with(
+ 'command' => '/usr/bin/apt-get update',
+ 'refreshonly' => true
+ )
+ }
+
+ it { should contain_exec("add-apt-repository-#{t}").with(
+ 'command' => "/usr/bin/add-apt-repository #{options} #{t}",
+ 'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
+ 'require' => ["File[/etc/apt/sources.list.d]", "Package[#{package}]"],
+ 'notify' => "Exec[apt_update]"
+ )
+ }
+
+ it { should create_file("/etc/apt/sources.list.d/#{filename}").with(
+ 'ensure' => 'file',
+ 'require' => "Exec[add-apt-repository-#{t}]"
+ )
+ }
+ end
+ end
+ describe 'without a proxy defined' do
+ let :title do
+ 'rspec_ppa'
+ end
+ let :pre_condition do
+ 'class { "apt":
+ proxy_host => false
+ }'
+ end
+ let :filename do
+ "#{title}-#{release}.list"
+ end
+
+ it { should contain_exec("add-apt-repository-#{title}").with(
+ 'environment' => [],
+ 'command' => "/usr/bin/add-apt-repository #{options} #{title}",
+ 'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
+ 'require' => ["File[/etc/apt/sources.list.d]", "Package[#{package}]"],
+ 'notify' => "Exec[apt_update]"
+ )
+ }
+ end
+
+ describe 'behind a proxy' do
+ let :title do
+ 'rspec_ppa'
+ end
+ let :pre_condition do
+ 'class { "apt":
+ proxy_host => "user:pass@proxy",
+ }'
+ end
+ let :filename do
+ "#{title}-#{release}.list"
+ end
+
+ it { should contain_exec("add-apt-repository-#{title}").with(
+ 'environment' => [
+ "http_proxy=http://user:pass@proxy:8080",
+ "https_proxy=http://user:pass@proxy:8080",
+ ],
+ 'command' => "/usr/bin/add-apt-repository #{options} #{title}",
+ 'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
+ 'require' => ["File[/etc/apt/sources.list.d]", "Package[#{package}]"],
+ 'notify' => "Exec[apt_update]"
+ )
+ }
+ end
+ end
+ end
+
+ [ { :lsbdistcodename => 'natty',
+ :package => 'python-software-properties' },
+ { :lsbdistcodename => 'quantal',
+ :package => 'software-properties-common'},
+ ].each do |platform|
+ context "on #{platform[:lsbdistcodename]}" do
+ describe "it should not error if package['#{platform[:package]}'] is already defined" do
+ let :pre_condition do
+ 'class {"apt": }' +
+ 'package { "#{platform[:package]}": }->Apt::Ppa["ppa"]'
+ end
+ let :facts do
+ {:lsbdistcodename => '#{platform[:lsbdistcodename]}'}
+ end
+ let(:title) { "ppa" }
+ let(:release) { "#{platform[:lsbdistcodename]}" }
+ it { should contain_package('#{platform[:package]}') }
+ end
+ end
+ end
+
+ describe "without Class[apt] should raise a Puppet::Error" do
+ let(:release) { "natty" }
+ let(:title) { "ppa" }
+ it { expect { should contain_apt__ppa(title) }.to raise_error(Puppet::Error) }
+ end
+
+ describe "without release should raise a Puppet::Error" do
+ let(:title) { "ppa:" }
+ it { expect { should contain_apt__ppa(:release) }.to raise_error(Puppet::Error) }
+ end
+end
diff --git a/puppet/apt/spec/defines/source_spec.rb b/puppet/apt/spec/defines/source_spec.rb
new file mode 100644
index 0000000000..9ad4d463e4
--- /dev/null
+++ b/puppet/apt/spec/defines/source_spec.rb
@@ -0,0 +1,166 @@
+require 'spec_helper'
+describe 'apt::source', :type => :define do
+ let :title do
+ 'my_source'
+ end
+
+ let :default_params do
+ {
+ :ensure => 'present',
+ :location => '',
+ :release => 'karmic',
+ :repos => 'main',
+ :include_src => true,
+ :required_packages => false,
+ :key => false,
+ :key_server => 'keyserver.ubuntu.com',
+ :key_content => false,
+ :key_source => false,
+ :pin => false
+ }
+ end
+
+ [{},
+ {
+ :location => 'http://example.com',
+ :release => 'precise',
+ :repos => 'security',
+ :include_src => false,
+ :required_packages => 'apache',
+ :key => 'key_name',
+ :key_server => 'keyserver.debian.com',
+ :pin => '600',
+ :key_content => 'ABCD1234'
+ },
+ {
+ :key => 'key_name',
+ :key_server => 'keyserver.debian.com',
+ :key_content => false,
+ },
+ {
+ :ensure => 'absent',
+ :location => 'http://example.com',
+ :release => 'precise',
+ :repos => 'security',
+ },
+ {
+ :release => '',
+ },
+ {
+ :release => 'custom',
+ },
+ {
+ :architecture => 'amd64',
+ }
+ ].each do |param_set|
+ describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
+ let :param_hash do
+ default_params.merge(param_set)
+ end
+
+ let :facts do
+ {:lsbdistcodename => 'karmic'}
+ end
+
+ let :params do
+ param_set
+ end
+
+ let :filename do
+ "/etc/apt/sources.list.d/#{title}.list"
+ end
+
+ let :content do
+ content = "# #{title}"
+ if param_hash[:architecture]
+ arch = "[arch=#{param_hash[:architecture]}]"
+ end
+ content << "\ndeb #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
+
+ if param_hash[:include_src]
+ content << "deb-src #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
+ end
+ content
+ end
+
+ it { should contain_apt__params }
+
+ it { should contain_file("#{title}.list").with({
+ 'ensure' => param_hash[:ensure],
+ 'path' => filename,
+ 'owner' => 'root',
+ 'group' => 'root',
+ 'mode' => '0644',
+ 'content' => content,
+ })
+ }
+
+ it {
+ if param_hash[:pin]
+ should contain_apt__pin(title).with({
+ "priority" => param_hash[:pin],
+ "before" => "File[#{title}.list]"
+ })
+ else
+ should_not contain_apt__pin(title).with({
+ "priority" => param_hash[:pin],
+ "before" => "File[#{title}.list]"
+ })
+ end
+ }
+
+ it {
+ should contain_exec("apt_update").with({
+ "command" => "/usr/bin/apt-get update",
+ "refreshonly" => true
+ })
+ }
+
+ it {
+ if param_hash[:required_packages]
+ should contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
+ "command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
+ "subscribe" => "File[#{title}.list]",
+ "refreshonly" => true,
+ "before" => 'Exec[apt_update]',
+ })
+ else
+ should_not contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
+ "command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
+ "subscribe" => "File[#{title}.list]",
+ "refreshonly" => true
+ })
+ end
+ }
+
+ it {
+ if param_hash[:key]
+ should contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
+ "key" => param_hash[:key],
+ "ensure" => :present,
+ "key_server" => param_hash[:key_server],
+ "key_content" => param_hash[:key_content],
+ "key_source" => param_hash[:key_source],
+ "before" => "File[#{title}.list]"
+ })
+ else
+ should_not contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
+ "key" => param_hash[:key],
+ "ensure" => :present,
+ "key_server" => param_hash[:key_server],
+ "key_content" => param_hash[:key_content],
+ "key_source" => param_hash[:key_source],
+ "before" => "File[#{title}.list]"
+ })
+ end
+ }
+ end
+ end
+ describe "without release should raise a Puppet::Error" do
+ let(:default_params) { Hash.new }
+ let(:facts) { Hash.new }
+ it { expect { should raise_error(Puppet::Error) } }
+ let(:facts) { { :lsbdistcodename => 'lucid' } }
+ it { should contain_apt__source(title) }
+ end
+end
diff --git a/puppet/apt/spec/spec_helper.rb b/puppet/apt/spec/spec_helper.rb
new file mode 100644
index 0000000000..2c6f56649a
--- /dev/null
+++ b/puppet/apt/spec/spec_helper.rb
@@ -0,0 +1 @@
+require 'puppetlabs_spec_helper/module_spec_helper'
diff --git a/puppet/apt/spec/spec_helper_system.rb b/puppet/apt/spec/spec_helper_system.rb
new file mode 100644
index 0000000000..490a6017eb
--- /dev/null
+++ b/puppet/apt/spec/spec_helper_system.rb
@@ -0,0 +1,30 @@
+require 'rspec-system/spec_helper'
+require 'rspec-system-puppet/helpers'
+require 'rspec-system-serverspec/helpers'
+
+include RSpecSystemPuppet::Helpers
+
+include Serverspec::Helper::RSpecSystem
+include Serverspec::Helper::DetectOS
+
+RSpec.configure do |c|
+ # Project root
+ proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+ # Enable colour
+ c.tty = true
+
+ c.include RSpecSystemPuppet::Helpers
+
+ # This is where we 'setup' the nodes before running our tests
+ c.before :suite do
+ # May as well update here as this can only run on apt-get machines.
+ shell('apt-get update')
+ # Install puppet
+ puppet_install
+
+ # Install modules and dependencies
+ puppet_module_install(:source => proj_root, :module_name => 'apt')
+ shell('puppet module install puppetlabs-stdlib')
+ end
+end
diff --git a/puppet/apt/spec/system/apt_builddep_spec.rb b/puppet/apt/spec/system/apt_builddep_spec.rb
new file mode 100644
index 0000000000..fa16ab42f5
--- /dev/null
+++ b/puppet/apt/spec/system/apt_builddep_spec.rb
@@ -0,0 +1,38 @@
+require 'spec_helper_system'
+
+describe 'apt::builddep' do
+
+ context 'reset' do
+ it 'removes packages' do
+ shell('apt-get -y remove glusterfs-server')
+ shell('apt-get -y remove g++')
+ end
+ end
+
+ context 'apt::builddep' do
+ it 'should work with no errors' do
+ pp = <<-EOS
+ include '::apt'
+ apt::builddep { 'glusterfs-server': }
+ EOS
+
+ puppet_apply(pp) do |r|
+ r.exit_code.should_not == 1
+ end
+ end
+
+ describe 'should install g++ as a dependency' do
+ describe package('g++') do
+ it { should be_installed }
+ end
+ end
+ end
+
+ context 'reset' do
+ it 'removes packages' do
+ shell('apt-get -y remove glusterfs-server')
+ shell('apt-get -y remove g++')
+ end
+ end
+
+end
diff --git a/puppet/apt/spec/system/apt_key_spec.rb b/puppet/apt/spec/system/apt_key_spec.rb
new file mode 100644
index 0000000000..4842cb5972
--- /dev/null
+++ b/puppet/apt/spec/system/apt_key_spec.rb
@@ -0,0 +1,53 @@
+require 'spec_helper_system'
+
+describe 'apt::key' do
+
+ context 'reset' do
+ it 'clean up keys' do
+ shell('apt-key del 4BD6EC30')
+ shell('apt-key del D50582E6')
+ end
+ end
+
+ context 'apt::key' do
+ it 'should work with no errors' do
+ pp = <<-EOS
+ include '::apt'
+ apt::key { 'puppetlabs':
+ key => '4BD6EC30',
+ key_server => 'pgp.mit.edu',
+ }
+
+ apt::key { 'jenkins':
+ key => 'D50582E6',
+ key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key',
+ }
+ EOS
+
+ puppet_apply(pp) do |r|
+ r.exit_code.should_not == 1
+ end
+ end
+
+ describe 'keys should exist' do
+ it 'finds puppetlabs key' do
+ shell('apt-key list | grep 4BD6EC30') do |r|
+ r.exit_code.should be_zero
+ end
+ end
+ it 'finds jenkins key' do
+ shell('apt-key list | grep D50582E6') do |r|
+ r.exit_code.should be_zero
+ end
+ end
+ end
+ end
+
+ context 'reset' do
+ it 'clean up keys' do
+ shell('apt-key del 4BD6EC30')
+ shell('apt-key del D50582E6')
+ end
+ end
+
+end
diff --git a/puppet/apt/spec/system/apt_ppa_spec.rb b/puppet/apt/spec/system/apt_ppa_spec.rb
new file mode 100644
index 0000000000..2e2baf5d2b
--- /dev/null
+++ b/puppet/apt/spec/system/apt_ppa_spec.rb
@@ -0,0 +1,59 @@
+require 'spec_helper_system'
+
+describe 'apt::ppa' do
+
+ context 'reset' do
+ it 'removes ppa' do
+ shell('rm /etc/apt/sources.list.d/drizzle-developers-ppa*')
+ shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*')
+ end
+ end
+
+ context 'adding a ppa that doesnt exist' do
+ it 'should work with no errors' do
+ pp = <<-EOS
+ include '::apt'
+ apt::ppa { 'ppa:drizzle-developers/ppa': }
+ EOS
+
+ puppet_apply(pp) do |r|
+ r.exit_code.should_not == 1
+ end
+ end
+
+ describe 'contains the source file' do
+ it 'contains a drizzle ppa source' do
+ shell('ls /etc/apt/sources.list.d/drizzle-developers-ppa-*.list') do |r|
+ r.exit_code.should be_zero
+ end
+ end
+ end
+ end
+
+ context 'readding a removed ppa.' do
+ it 'setup' do
+ shell('add-apt-repository -y ppa:raravena80/collectd5')
+ # This leaves a blank file
+ shell('add-apt-repository --remove ppa:raravena80/collectd5')
+ end
+
+ it 'should readd it successfully' do
+ pp = <<-EOS
+ include '::apt'
+ apt::ppa { 'ppa:raravena80/collectd5': }
+ EOS
+
+ puppet_apply(pp) do |r|
+ r.exit_code.should_not == 1
+ end
+ end
+ end
+
+ context 'reset' do
+ it 'removes added ppas' do
+ shell('rm /etc/apt/sources.list.d/drizzle-developers-ppa*')
+ shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*')
+ end
+ end
+
+end
diff --git a/puppet/apt/spec/system/apt_source_spec.rb b/puppet/apt/spec/system/apt_source_spec.rb
new file mode 100644
index 0000000000..6a445e13ef
--- /dev/null
+++ b/puppet/apt/spec/system/apt_source_spec.rb
@@ -0,0 +1,51 @@
+require 'spec_helper_system'
+
+describe 'apt::source' do
+
+ context 'reset' do
+ it 'clean up puppetlabs repo' do
+ shell('apt-key del 4BD6EC30')
+ shell('rm /etc/apt/sources.list.d/puppetlabs.list')
+ end
+ end
+
+ context 'apt::source' do
+ it 'should work with no errors' do
+ pp = <<-EOS
+ include '::apt'
+ apt::source { 'puppetlabs':
+ location => 'http://apt.puppetlabs.com',
+ repos => 'main',
+ key => '4BD6EC30',
+ key_server => 'pgp.mit.edu',
+ }
+ EOS
+
+ puppet_apply(pp) do |r|
+ r.exit_code.should_not == 1
+ end
+ end
+
+ describe 'key should exist' do
+ it 'finds puppetlabs key' do
+ shell('apt-key list | grep 4BD6EC30') do |r|
+ r.exit_code.should be_zero
+ end
+ end
+ end
+
+ describe 'source should exist' do
+ describe file('/etc/apt/sources.list.d/puppetlabs.list') do
+ it { should be_file }
+ end
+ end
+ end
+
+ context 'reset' do
+ it 'clean up puppetlabs repo' do
+ shell('apt-key del 4BD6EC30')
+ shell('rm /etc/apt/sources.list.d/puppetlabs.list')
+ end
+ end
+
+end
diff --git a/puppet/apt/spec/system/basic_spec.rb b/puppet/apt/spec/system/basic_spec.rb
new file mode 100644
index 0000000000..3008356356
--- /dev/null
+++ b/puppet/apt/spec/system/basic_spec.rb
@@ -0,0 +1,10 @@
+require 'spec_helper_system'
+
+describe 'basic tests:' do
+ # Using puppet_apply as a subject
+ context puppet_apply 'notice("foo")' do
+ its(:stdout) { should =~ /foo/ }
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should be_zero }
+ end
+end
diff --git a/puppet/apt/spec/system/class_spec.rb b/puppet/apt/spec/system/class_spec.rb
new file mode 100644
index 0000000000..7bb6b8d64e
--- /dev/null
+++ b/puppet/apt/spec/system/class_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper_system'
+
+describe 'apt class' do
+
+ context 'default parameters' do
+ # Using puppet_apply as a helper
+ it 'should work with no errors' do
+ pp = <<-EOS
+ class { 'apt': }
+ EOS
+
+ # Run it twice and test for idempotency
+ puppet_apply(pp) do |r|
+ r.exit_code.should_not == 1
+ r.refresh
+ r.exit_code.should be_zero
+ end
+ end
+ end
+end
diff --git a/puppet/apt/templates/10periodic.erb b/puppet/apt/templates/10periodic.erb
new file mode 100644
index 0000000000..5737c9ac29
--- /dev/null
+++ b/puppet/apt/templates/10periodic.erb
@@ -0,0 +1,12 @@
+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 %>";
diff --git a/puppet/apt/templates/50unattended-upgrades.erb b/puppet/apt/templates/50unattended-upgrades.erb
new file mode 100644
index 0000000000..4df0f74401
--- /dev/null
+++ b/puppet/apt/templates/50unattended-upgrades.erb
@@ -0,0 +1,53 @@
+// Automatically upgrade packages from these (origin:archive) pairs
+Unattended-Upgrade::Allowed-Origins {
+<% @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 %>";
+
+// 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.
+<% if @mail_to != "NONE" %>Unattended-Upgrade::Mail "<%= @mail_to %>";<% end %>
+
+// Set this value to "true" to get emails only on errors. Default
+// is to always send a mail if Unattended-Upgrade::Mail is set
+<% if @mail_to != "NONE" %>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 %>";
+
+
+// Use apt bandwidth limit feature, this example limits the download
+// speed to 70kb/sec
+<% if @dl_limit != "NONE" %>Acquire::http::Dl-Limit "<%= @dl_limit %>";<% end %>
diff --git a/puppet/apt/templates/pin.pref.erb b/puppet/apt/templates/pin.pref.erb
new file mode 100644
index 0000000000..62c44c7241
--- /dev/null
+++ b/puppet/apt/templates/pin.pref.erb
@@ -0,0 +1,22 @@
+<%-
+@pin = "release a=#{@name}" # default value
+if @pin_release.length > 0
+ options = []
+ options.push("a=#{@release}") if @release.length > 0
+ options.push("n=#{@codename}") if @codename.length > 0
+ options.push("v=#{@release_version}") if @release_version.length > 0
+ options.push("c=#{@component}") if @component.length > 0
+ options.push("o=#{@originator}") if @originator.length > 0
+ options.push("l=#{@label}") if @label.length > 0
+ @pin = "release #{options.join(', ')}"
+elsif @version.length > 0
+ @pin = "version #{@version}"
+elsif @origin.length > 0
+ @pin = "origin \"#{@origin}\""
+end
+-%>
+# <%= @name %>
+Explanation: <%= @explanation %>
+Package: <%= @packages %>
+Pin: <%= @pin %>
+Pin-Priority: <%= @priority %>
diff --git a/puppet/apt/templates/source.list.erb b/puppet/apt/templates/source.list.erb
new file mode 100644
index 0000000000..e8b6865940
--- /dev/null
+++ b/puppet/apt/templates/source.list.erb
@@ -0,0 +1,5 @@
+# <%= @name %>
+deb <% if @architecture %>[arch=<%= @architecture %>]<% end %><%= @location %> <%= @release_real %> <%= @repos %>
+<%- if @include_src then -%>
+deb-src <% if @architecture %>[arch=<%= @architecture %>]<% end %><%= @location %> <%= @release_real %> <%= @repos %>
+<%- end -%>
diff --git a/puppet/apt/tests/builddep.pp b/puppet/apt/tests/builddep.pp
new file mode 100644
index 0000000000..8b4f796408
--- /dev/null
+++ b/puppet/apt/tests/builddep.pp
@@ -0,0 +1,2 @@
+class { 'apt': }
+apt::builddep{ 'glusterfs-server': }
diff --git a/puppet/apt/tests/debian/testing.pp b/puppet/apt/tests/debian/testing.pp
new file mode 100644
index 0000000000..8245b3a337
--- /dev/null
+++ b/puppet/apt/tests/debian/testing.pp
@@ -0,0 +1,2 @@
+class { 'apt': }
+class { 'apt::debian::testing': }
diff --git a/puppet/apt/tests/debian/unstable.pp b/puppet/apt/tests/debian/unstable.pp
new file mode 100644
index 0000000000..8605179295
--- /dev/null
+++ b/puppet/apt/tests/debian/unstable.pp
@@ -0,0 +1,2 @@
+class { 'apt': }
+class { 'apt::debian::unstable': }
diff --git a/puppet/apt/tests/force.pp b/puppet/apt/tests/force.pp
new file mode 100644
index 0000000000..f3313633d0
--- /dev/null
+++ b/puppet/apt/tests/force.pp
@@ -0,0 +1,7 @@
+# force.pp
+# force a package from a specific release
+
+apt::force { 'package':
+ release => 'testing',
+ version => false
+}
diff --git a/puppet/apt/tests/init.pp b/puppet/apt/tests/init.pp
new file mode 100644
index 0000000000..abc75afa25
--- /dev/null
+++ b/puppet/apt/tests/init.pp
@@ -0,0 +1 @@
+class { 'apt': }
diff --git a/puppet/apt/tests/key.pp b/puppet/apt/tests/key.pp
new file mode 100644
index 0000000000..79e0e1b749
--- /dev/null
+++ b/puppet/apt/tests/key.pp
@@ -0,0 +1,6 @@
+# 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/puppet/apt/tests/params.pp b/puppet/apt/tests/params.pp
new file mode 100644
index 0000000000..5ddf3c6551
--- /dev/null
+++ b/puppet/apt/tests/params.pp
@@ -0,0 +1 @@
+include apt::params
diff --git a/puppet/apt/tests/pin.pp b/puppet/apt/tests/pin.pp
new file mode 100644
index 0000000000..6a9024c234
--- /dev/null
+++ b/puppet/apt/tests/pin.pp
@@ -0,0 +1,5 @@
+# pin a release in apt, useful for unstable repositories
+apt::pin { 'foo':
+ packages => '*',
+ priority => 0,
+}
diff --git a/puppet/apt/tests/ppa.pp b/puppet/apt/tests/ppa.pp
new file mode 100644
index 0000000000..e728f6f10f
--- /dev/null
+++ b/puppet/apt/tests/ppa.pp
@@ -0,0 +1,4 @@
+class { 'apt': }
+
+# Example declaration of an Apt PPA
+apt::ppa{ 'ppa:openstack-ppa/bleeding-edge': }
diff --git a/puppet/apt/tests/release.pp b/puppet/apt/tests/release.pp
new file mode 100644
index 0000000000..823f5861fa
--- /dev/null
+++ b/puppet/apt/tests/release.pp
@@ -0,0 +1,4 @@
+class { 'apt': }
+class { 'apt::release':
+ release_id => 'karmic'
+}
diff --git a/puppet/apt/tests/source.pp b/puppet/apt/tests/source.pp
new file mode 100644
index 0000000000..d83cb9787a
--- /dev/null
+++ b/puppet/apt/tests/source.pp
@@ -0,0 +1,29 @@
+# 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 => '55BE302B',
+ 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 => '55BE302B',
+ key_server => 'subkeys.pgp.net',
+ pin => '-10',
+}
diff --git a/puppet/apt/tests/unattended-upgrades.pp b/puppet/apt/tests/unattended-upgrades.pp
new file mode 100644
index 0000000000..7f65ab4f57
--- /dev/null
+++ b/puppet/apt/tests/unattended-upgrades.pp
@@ -0,0 +1 @@
+include apt::unattended-upgrades
diff --git a/puppet/puppet-apt/LICENSE b/puppet/puppet-apt/LICENSE
deleted file mode 100644
index 94a9ed024d..0000000000
--- a/puppet/puppet-apt/LICENSE
+++ /dev/null
@@ -1,674 +0,0 @@
- GNU GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc.
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The GNU General Public License is a free, copyleft license for
-software and other kinds of works.
-
- The licenses for most software and other practical works are designed
-to take away your freedom to share and change the works. By contrast,
-the GNU General Public License is intended to guarantee your freedom to
-share and change all versions of a program--to make sure it remains free
-software for all its users. We, the Free Software Foundation, use the
-GNU General Public License for most of our software; it applies also to
-any other work released this way by its authors. You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-them if you wish), that you receive source code or can get it if you
-want it, that you can change the software or use pieces of it in new
-free programs, and that you know you can do these things.
-
- To protect your rights, we need to prevent others from denying you
-these rights or asking you to surrender the rights. Therefore, you have
-certain responsibilities if you distribute copies of the software, or if
-you modify it: responsibilities to respect the freedom of others.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must pass on to the recipients the same
-freedoms that you received. You must make sure that they, too, receive
-or can get the source code. And you must show them these terms so they
-know their rights.
-
- Developers that use the GNU GPL protect your rights with two steps:
-(1) assert copyright on the software, and (2) offer you this License
-giving you legal permission to copy, distribute and/or modify it.
-
- For the developers' and authors' protection, the GPL clearly explains
-that there is no warranty for this free software. For both users' and
-authors' sake, the GPL requires that modified versions be marked as
-changed, so that their problems will not be attributed erroneously to
-authors of previous versions.
-
- Some devices are designed to deny users access to install or run
-modified versions of the software inside them, although the manufacturer
-can do so. This is fundamentally incompatible with the aim of
-protecting users' freedom to change the software. The systematic
-pattern of such abuse occurs in the area of products for individuals to
-use, which is precisely where it is most unacceptable. Therefore, we
-have designed this version of the GPL to prohibit the practice for those
-products. If such problems arise substantially in other domains, we
-stand ready to extend this provision to those domains in future versions
-of the GPL, as needed to protect the freedom of users.
-
- Finally, every program is threatened constantly by software patents.
-States should not allow patents to restrict development and use of
-software on general-purpose computers, but in those that do, we wish to
-avoid the special danger that patents applied to a free program could
-make it effectively proprietary. To prevent this, the GPL assures that
-patents cannot be used to render the program non-free.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- TERMS AND CONDITIONS
-
- 0. Definitions.
-
- "This License" refers to version 3 of the GNU General Public License.
-
- "Copyright" also means copyright-like laws that apply to other kinds of
-works, such as semiconductor masks.
-
- "The Program" refers to any copyrightable work licensed under this
-License. Each licensee is addressed as "you". "Licensees" and
-"recipients" may be individuals or organizations.
-
- To "modify" a work means to copy from or adapt all or part of the work
-in a fashion requiring copyright permission, other than the making of an
-exact copy. The resulting work is called a "modified version" of the
-earlier work or a work "based on" the earlier work.
-
- A "covered work" means either the unmodified Program or a work based
-on the Program.
-
- To "propagate" a work means to do anything with it that, without
-permission, would make you directly or secondarily liable for
-infringement under applicable copyright law, except executing it on a
-computer or modifying a private copy. Propagation includes copying,
-distribution (with or without modification), making available to the
-public, and in some countries other activities as well.
-
- To "convey" a work means any kind of propagation that enables other
-parties to make or receive copies. Mere interaction with a user through
-a computer network, with no transfer of a copy, is not conveying.
-
- An interactive user interface displays "Appropriate Legal Notices"
-to the extent that it includes a convenient and prominently visible
-feature that (1) displays an appropriate copyright notice, and (2)
-tells the user that there is no warranty for the work (except to the
-extent that warranties are provided), that licensees may convey the
-work under this License, and how to view a copy of this License. If
-the interface presents a list of user commands or options, such as a
-menu, a prominent item in the list meets this criterion.
-
- 1. Source Code.
-
- The "source code" for a work means the preferred form of the work
-for making modifications to it. "Object code" means any non-source
-form of a work.
-
- A "Standard Interface" means an interface that either is an official
-standard defined by a recognized standards body, or, in the case of
-interfaces specified for a particular programming language, one that
-is widely used among developers working in that language.
-
- The "System Libraries" of an executable work include anything, other
-than the work as a whole, that (a) is included in the normal form of
-packaging a Major Component, but which is not part of that Major
-Component, and (b) serves only to enable use of the work with that
-Major Component, or to implement a Standard Interface for which an
-implementation is available to the public in source code form. A
-"Major Component", in this context, means a major essential component
-(kernel, window system, and so on) of the specific operating system
-(if any) on which the executable work runs, or a compiler used to
-produce the work, or an object code interpreter used to run it.
-
- The "Corresponding Source" for a work in object code form means all
-the source code needed to generate, install, and (for an executable
-work) run the object code and to modify the work, including scripts to
-control those activities. However, it does not include the work's
-System Libraries, or general-purpose tools or generally available free
-programs which are used unmodified in performing those activities but
-which are not part of the work. For example, Corresponding Source
-includes interface definition files associated with source files for
-the work, and the source code for shared libraries and dynamically
-linked subprograms that the work is specifically designed to require,
-such as by intimate data communication or control flow between those
-subprograms and other parts of the work.
-
- The Corresponding Source need not include anything that users
-can regenerate automatically from other parts of the Corresponding
-Source.
-
- The Corresponding Source for a work in source code form is that
-same work.
-
- 2. Basic Permissions.
-
- All rights granted under this License are granted for the term of
-copyright on the Program, and are irrevocable provided the stated
-conditions are met. This License explicitly affirms your unlimited
-permission to run the unmodified Program. The output from running a
-covered work is covered by this License only if the output, given its
-content, constitutes a covered work. This License acknowledges your
-rights of fair use or other equivalent, as provided by copyright law.
-
- You may make, run and propagate covered works that you do not
-convey, without conditions so long as your license otherwise remains
-in force. You may convey covered works to others for the sole purpose
-of having them make modifications exclusively for you, or provide you
-with facilities for running those works, provided that you comply with
-the terms of this License in conveying all material for which you do
-not control copyright. Those thus making or running the covered works
-for you must do so exclusively on your behalf, under your direction
-and control, on terms that prohibit them from making any copies of
-your copyrighted material outside their relationship with you.
-
- Conveying under any other circumstances is permitted solely under
-the conditions stated below. Sublicensing is not allowed; section 10
-makes it unnecessary.
-
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
-
- No covered work shall be deemed part of an effective technological
-measure under any applicable law fulfilling obligations under article
-11 of the WIPO copyright treaty adopted on 20 December 1996, or
-similar laws prohibiting or restricting circumvention of such
-measures.
-
- When you convey a covered work, you waive any legal power to forbid
-circumvention of technological measures to the extent such circumvention
-is effected by exercising rights under this License with respect to
-the covered work, and you disclaim any intention to limit operation or
-modification of the work as a means of enforcing, against the work's
-users, your or third parties' legal rights to forbid circumvention of
-technological measures.
-
- 4. Conveying Verbatim Copies.
-
- You may convey verbatim copies of the Program's source code as you
-receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy an appropriate copyright notice;
-keep intact all notices stating that this License and any
-non-permissive terms added in accord with section 7 apply to the code;
-keep intact all notices of the absence of any warranty; and give all
-recipients a copy of this License along with the Program.
-
- You may charge any price or no price for each copy that you convey,
-and you may offer support or warranty protection for a fee.
-
- 5. Conveying Modified Source Versions.
-
- You may convey a work based on the Program, or the modifications to
-produce it from the Program, in the form of source code under the
-terms of section 4, provided that you also meet all of these conditions:
-
- a) The work must carry prominent notices stating that you modified
- it, and giving a relevant date.
-
- b) The work must carry prominent notices stating that it is
- released under this License and any conditions added under section
- 7. This requirement modifies the requirement in section 4 to
- "keep intact all notices".
-
- c) You must license the entire work, as a whole, under this
- License to anyone who comes into possession of a copy. This
- License will therefore apply, along with any applicable section 7
- additional terms, to the whole of the work, and all its parts,
- regardless of how they are packaged. This License gives no
- permission to license the work in any other way, but it does not
- invalidate such permission if you have separately received it.
-
- d) If the work has interactive user interfaces, each must display
- Appropriate Legal Notices; however, if the Program has interactive
- interfaces that do not display Appropriate Legal Notices, your
- work need not make them do so.
-
- A compilation of a covered work with other separate and independent
-works, which are not by their nature extensions of the covered work,
-and which are not combined with it such as to form a larger program,
-in or on a volume of a storage or distribution medium, is called an
-"aggregate" if the compilation and its resulting copyright are not
-used to limit the access or legal rights of the compilation's users
-beyond what the individual works permit. Inclusion of a covered work
-in an aggregate does not cause this License to apply to the other
-parts of the aggregate.
-
- 6. Conveying Non-Source Forms.
-
- You may convey a covered work in object code form under the terms
-of sections 4 and 5, provided that you also convey the
-machine-readable Corresponding Source under the terms of this License,
-in one of these ways:
-
- a) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by the
- Corresponding Source fixed on a durable physical medium
- customarily used for software interchange.
-
- b) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by a
- written offer, valid for at least three years and valid for as
- long as you offer spare parts or customer support for that product
- model, to give anyone who possesses the object code either (1) a
- copy of the Corresponding Source for all the software in the
- product that is covered by this License, on a durable physical
- medium customarily used for software interchange, for a price no
- more than your reasonable cost of physically performing this
- conveying of source, or (2) access to copy the
- Corresponding Source from a network server at no charge.
-
- c) Convey individual copies of the object code with a copy of the
- written offer to provide the Corresponding Source. This
- alternative is allowed only occasionally and noncommercially, and
- only if you received the object code with such an offer, in accord
- with subsection 6b.
-
- d) Convey the object code by offering access from a designated
- place (gratis or for a charge), and offer equivalent access to the
- Corresponding Source in the same way through the same place at no
- further charge. You need not require recipients to copy the
- Corresponding Source along with the object code. If the place to
- copy the object code is a network server, the Corresponding Source
- may be on a different server (operated by you or a third party)
- that supports equivalent copying facilities, provided you maintain
- clear directions next to the object code saying where to find the
- Corresponding Source. Regardless of what server hosts the
- Corresponding Source, you remain obligated to ensure that it is
- available for as long as needed to satisfy these requirements.
-
- e) Convey the object code using peer-to-peer transmission, provided
- you inform other peers where the object code and Corresponding
- Source of the work are being offered to the general public at no
- charge under subsection 6d.
-
- A separable portion of the object code, whose source code is excluded
-from the Corresponding Source as a System Library, need not be
-included in conveying the object code work.
-
- A "User Product" is either (1) a "consumer product", which means any
-tangible personal property which is normally used for personal, family,
-or household purposes, or (2) anything designed or sold for incorporation
-into a dwelling. In determining whether a product is a consumer product,
-doubtful cases shall be resolved in favor of coverage. For a particular
-product received by a particular user, "normally used" refers to a
-typical or common use of that class of product, regardless of the status
-of the particular user or of the way in which the particular user
-actually uses, or expects or is expected to use, the product. A product
-is a consumer product regardless of whether the product has substantial
-commercial, industrial or non-consumer uses, unless such uses represent
-the only significant mode of use of the product.
-
- "Installation Information" for a User Product means any methods,
-procedures, authorization keys, or other information required to install
-and execute modified versions of a covered work in that User Product from
-a modified version of its Corresponding Source. The information must
-suffice to ensure that the continued functioning of the modified object
-code is in no case prevented or interfered with solely because
-modification has been made.
-
- If you convey an object code work under this section in, or with, or
-specifically for use in, a User Product, and the conveying occurs as
-part of a transaction in which the right of possession and use of the
-User Product is transferred to the recipient in perpetuity or for a
-fixed term (regardless of how the transaction is characterized), the
-Corresponding Source conveyed under this section must be accompanied
-by the Installation Information. But this requirement does not apply
-if neither you nor any third party retains the ability to install
-modified object code on the User Product (for example, the work has
-been installed in ROM).
-
- The requirement to provide Installation Information does not include a
-requirement to continue to provide support service, warranty, or updates
-for a work that has been modified or installed by the recipient, or for
-the User Product in which it has been modified or installed. Access to a
-network may be denied when the modification itself materially and
-adversely affects the operation of the network or violates the rules and
-protocols for communication across the network.
-
- Corresponding Source conveyed, and Installation Information provided,
-in accord with this section must be in a format that is publicly
-documented (and with an implementation available to the public in
-source code form), and must require no special password or key for
-unpacking, reading or copying.
-
- 7. Additional Terms.
-
- "Additional permissions" are terms that supplement the terms of this
-License by making exceptions from one or more of its conditions.
-Additional permissions that are applicable to the entire Program shall
-be treated as though they were included in this License, to the extent
-that they are valid under applicable law. If additional permissions
-apply only to part of the Program, that part may be used separately
-under those permissions, but the entire Program remains governed by
-this License without regard to the additional permissions.
-
- When you convey a copy of a covered work, you may at your option
-remove any additional permissions from that copy, or from any part of
-it. (Additional permissions may be written to require their own
-removal in certain cases when you modify the work.) You may place
-additional permissions on material, added by you to a covered work,
-for which you have or can give appropriate copyright permission.
-
- Notwithstanding any other provision of this License, for material you
-add to a covered work, you may (if authorized by the copyright holders of
-that material) supplement the terms of this License with terms:
-
- a) Disclaiming warranty or limiting liability differently from the
- terms of sections 15 and 16 of this License; or
-
- b) Requiring preservation of specified reasonable legal notices or
- author attributions in that material or in the Appropriate Legal
- Notices displayed by works containing it; or
-
- c) Prohibiting misrepresentation of the origin of that material, or
- requiring that modified versions of such material be marked in
- reasonable ways as different from the original version; or
-
- d) Limiting the use for publicity purposes of names of licensors or
- authors of the material; or
-
- e) Declining to grant rights under trademark law for use of some
- trade names, trademarks, or service marks; or
-
- f) Requiring indemnification of licensors and authors of that
- material by anyone who conveys the material (or modified versions of
- it) with contractual assumptions of liability to the recipient, for
- any liability that these contractual assumptions directly impose on
- those licensors and authors.
-
- All other non-permissive additional terms are considered "further
-restrictions" within the meaning of section 10. If the Program as you
-received it, or any part of it, contains a notice stating that it is
-governed by this License along with a term that is a further
-restriction, you may remove that term. If a license document contains
-a further restriction but permits relicensing or conveying under this
-License, you may add to a covered work material governed by the terms
-of that license document, provided that the further restriction does
-not survive such relicensing or conveying.
-
- If you add terms to a covered work in accord with this section, you
-must place, in the relevant source files, a statement of the
-additional terms that apply to those files, or a notice indicating
-where to find the applicable terms.
-
- Additional terms, permissive or non-permissive, may be stated in the
-form of a separately written license, or stated as exceptions;
-the above requirements apply either way.
-
- 8. Termination.
-
- You may not propagate or modify a covered work except as expressly
-provided under this License. Any attempt otherwise to propagate or
-modify it is void, and will automatically terminate your rights under
-this License (including any patent licenses granted under the third
-paragraph of section 11).
-
- However, if you cease all violation of this License, then your
-license from a particular copyright holder is reinstated (a)
-provisionally, unless and until the copyright holder explicitly and
-finally terminates your license, and (b) permanently, if the copyright
-holder fails to notify you of the violation by some reasonable means
-prior to 60 days after the cessation.
-
- Moreover, your license from a particular copyright holder is
-reinstated permanently if the copyright holder notifies you of the
-violation by some reasonable means, this is the first time you have
-received notice of violation of this License (for any work) from that
-copyright holder, and you cure the violation prior to 30 days after
-your receipt of the notice.
-
- Termination of your rights under this section does not terminate the
-licenses of parties who have received copies or rights from you under
-this License. If your rights have been terminated and not permanently
-reinstated, you do not qualify to receive new licenses for the same
-material under section 10.
-
- 9. Acceptance Not Required for Having Copies.
-
- You are not required to accept this License in order to receive or
-run a copy of the Program. Ancillary propagation of a covered work
-occurring solely as a consequence of using peer-to-peer transmission
-to receive a copy likewise does not require acceptance. However,
-nothing other than this License grants you permission to propagate or
-modify any covered work. These actions infringe copyright if you do
-not accept this License. Therefore, by modifying or propagating a
-covered work, you indicate your acceptance of this License to do so.
-
- 10. Automatic Licensing of Downstream Recipients.
-
- Each time you convey a covered work, the recipient automatically
-receives a license from the original licensors, to run, modify and
-propagate that work, subject to this License. You are not responsible
-for enforcing compliance by third parties with this License.
-
- An "entity transaction" is a transaction transferring control of an
-organization, or substantially all assets of one, or subdividing an
-organization, or merging organizations. If propagation of a covered
-work results from an entity transaction, each party to that
-transaction who receives a copy of the work also receives whatever
-licenses to the work the party's predecessor in interest had or could
-give under the previous paragraph, plus a right to possession of the
-Corresponding Source of the work from the predecessor in interest, if
-the predecessor has it or can get it with reasonable efforts.
-
- You may not impose any further restrictions on the exercise of the
-rights granted or affirmed under this License. For example, you may
-not impose a license fee, royalty, or other charge for exercise of
-rights granted under this License, and you may not initiate litigation
-(including a cross-claim or counterclaim in a lawsuit) alleging that
-any patent claim is infringed by making, using, selling, offering for
-sale, or importing the Program or any portion of it.
-
- 11. Patents.
-
- A "contributor" is a copyright holder who authorizes use under this
-License of the Program or a work on which the Program is based. The
-work thus licensed is called the contributor's "contributor version".
-
- A contributor's "essential patent claims" are all patent claims
-owned or controlled by the contributor, whether already acquired or
-hereafter acquired, that would be infringed by some manner, permitted
-by this License, of making, using, or selling its contributor version,
-but do not include claims that would be infringed only as a
-consequence of further modification of the contributor version. For
-purposes of this definition, "control" includes the right to grant
-patent sublicenses in a manner consistent with the requirements of
-this License.
-
- Each contributor grants you a non-exclusive, worldwide, royalty-free
-patent license under the contributor's essential patent claims, to
-make, use, sell, offer for sale, import and otherwise run, modify and
-propagate the contents of its contributor version.
-
- In the following three paragraphs, a "patent license" is any express
-agreement or commitment, however denominated, not to enforce a patent
-(such as an express permission to practice a patent or covenant not to
-sue for patent infringement). To "grant" such a patent license to a
-party means to make such an agreement or commitment not to enforce a
-patent against the party.
-
- If you convey a covered work, knowingly relying on a patent license,
-and the Corresponding Source of the work is not available for anyone
-to copy, free of charge and under the terms of this License, through a
-publicly available network server or other readily accessible means,
-then you must either (1) cause the Corresponding Source to be so
-available, or (2) arrange to deprive yourself of the benefit of the
-patent license for this particular work, or (3) arrange, in a manner
-consistent with the requirements of this License, to extend the patent
-license to downstream recipients. "Knowingly relying" means you have
-actual knowledge that, but for the patent license, your conveying the
-covered work in a country, or your recipient's use of the covered work
-in a country, would infringe one or more identifiable patents in that
-country that you have reason to believe are valid.
-
- If, pursuant to or in connection with a single transaction or
-arrangement, you convey, or propagate by procuring conveyance of, a
-covered work, and grant a patent license to some of the parties
-receiving the covered work authorizing them to use, propagate, modify
-or convey a specific copy of the covered work, then the patent license
-you grant is automatically extended to all recipients of the covered
-work and works based on it.
-
- A patent license is "discriminatory" if it does not include within
-the scope of its coverage, prohibits the exercise of, or is
-conditioned on the non-exercise of one or more of the rights that are
-specifically granted under this License. You may not convey a covered
-work if you are a party to an arrangement with a third party that is
-in the business of distributing software, under which you make payment
-to the third party based on the extent of your activity of conveying
-the work, and under which the third party grants, to any of the
-parties who would receive the covered work from you, a discriminatory
-patent license (a) in connection with copies of the covered work
-conveyed by you (or copies made from those copies), or (b) primarily
-for and in connection with specific products or compilations that
-contain the covered work, unless you entered into that arrangement,
-or that patent license was granted, prior to 28 March 2007.
-
- Nothing in this License shall be construed as excluding or limiting
-any implied license or other defenses to infringement that may
-otherwise be available to you under applicable patent law.
-
- 12. No Surrender of Others' Freedom.
-
- If conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot convey a
-covered work so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you may
-not convey it at all. For example, if you agree to terms that obligate you
-to collect a royalty for further conveying from those to whom you convey
-the Program, the only way you could satisfy both those terms and this
-License would be to refrain entirely from conveying the Program.
-
- 13. Use with the GNU Affero General Public License.
-
- Notwithstanding any other provision of this License, you have
-permission to link or combine any covered work with a work licensed
-under version 3 of the GNU Affero General Public License into a single
-combined work, and to convey the resulting work. The terms of this
-License will continue to apply to the part which is the covered work,
-but the special requirements of the GNU Affero General Public License,
-section 13, concerning interaction through a network will apply to the
-combination as such.
-
- 14. Revised Versions of this License.
-
- The Free Software Foundation may publish revised and/or new versions of
-the GNU General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
- Each version is given a distinguishing version number. If the
-Program specifies that a certain numbered version of the GNU General
-Public License "or any later version" applies to it, you have the
-option of following the terms and conditions either of that numbered
-version or of any later version published by the Free Software
-Foundation. If the Program does not specify a version number of the
-GNU General Public License, you may choose any version ever published
-by the Free Software Foundation.
-
- If the Program specifies that a proxy can decide which future
-versions of the GNU General Public License can be used, that proxy's
-public statement of acceptance of a version permanently authorizes you
-to choose that version for the Program.
-
- Later license versions may give you additional or different
-permissions. However, no additional obligations are imposed on any
-author or copyright holder as a result of your choosing to follow a
-later version.
-
- 15. Disclaimer of Warranty.
-
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
-APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
-HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
-OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
-IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
-ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. Limitation of Liability.
-
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
-THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
-GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
-USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
-DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
-PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
-EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGES.
-
- 17. Interpretation of Sections 15 and 16.
-
- If the disclaimer of warranty and limitation of liability provided
-above cannot be given local legal effect according to their terms,
-reviewing courts shall apply local law that most closely approximates
-an absolute waiver of all civil liability in connection with the
-Program, unless a warranty or assumption of liability accompanies a
-copy of the Program in return for a fee.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-state the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-
- Copyright (C)
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-
-Also add information on how to contact you by electronic and paper mail.
-
- If the program does terminal interaction, make it output a short
-notice like this when it starts in an interactive mode:
-
- Copyright (C)
- This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, your program's commands
-might be different; for a GUI interface, you would use an "about box".
-
- You should also get your employer (if you work as a programmer) or school,
-if any, to sign a "copyright disclaimer" for the program, if necessary.
-For more information on this, and how to apply and follow the GNU GPL, see
-.
-
- The GNU General Public License does not permit incorporating your program
-into proprietary programs. If your program is a subroutine library, you
-may consider it more useful to permit linking proprietary applications with
-the library. If this is what you want to do, use the GNU Lesser General
-Public License instead of this License. But first, please read
-.
diff --git a/puppet/puppet-apt/Modulefile b/puppet/puppet-apt/Modulefile
deleted file mode 100644
index ccd8369a37..0000000000
--- a/puppet/puppet-apt/Modulefile
+++ /dev/null
@@ -1,8 +0,0 @@
-name 'camptocamp-apt'
-version '0.0.2'
-source 'https://github.com/camptocamp/puppet-apt'
-author 'DevOps Team / Camptocamp'
-license 'GNU GPLv3'
-summary 'Camptocamp Apt Module'
-description 'APT Module for Puppet'
-project_page 'https://github.com/camptocamp/puppet-apt'
diff --git a/puppet/puppet-apt/README.md b/puppet/puppet-apt/README.md
deleted file mode 100644
index 2766b190d2..0000000000
--- a/puppet/puppet-apt/README.md
+++ /dev/null
@@ -1,98 +0,0 @@
-# Apt module for Puppet
-
-**Manages apt configuration under Debian or Ubuntu.**
-
-This module is provided by [Camptocamp](http://www.camptocamp.com/)
-
-## Classes
-
- * apt
- * apt::backports
- * apt::clean
- * apt::params
- * apt::unattended-upgrade
- * apt::unattended-upgrade::automatic
-
-### apt::clean
-
-Variables
-
- * **$apt\_clean\_minutes**: cronjob minutes - default uses fqdn\_rand()
- * **$apt\_clean\_hours** : cronjob hours - default to 0
- * **$apt\_clean\_mday** : cronjob monthday - default uses fqdn\_rand()
-
-## Definitions
-
- * apt::conf
- * apt::key
- * apt::ppa
- * apt::preferences
- * apt::sources\_list
-
-### apt::conf
-
- apt::conf{'99unattended-upgrade':
- ensure => present,
- content => "APT::Periodic::Unattended-Upgrade \"1\";\n",
- }
-
-### apt::key
-
- apt::key {"A37E4CF5":
- source => "http://dev.camptocamp.com/packages/debian/pub.key",
- }
-
- apt::key {"997D3880":
- keyserver => "keyserver.ubuntu.com",
- }
-
-### apt::ppa
-
- apt::ppa {'chris-lea':
- ensure => present,
- key => 'C7917B12',
- ppa => 'node.js'
- }
-
-### apt::preferences
-
- apt::preferences {"${lsbdistcodename}-backports":
- ensure => present,
- package => '*',
- pin => "release a=${lsbdistcodename}-backports",
- priority => 400,
- }
-
-### apt::sources\_list
-
- apt::sources_list {"camptocamp":
- ensure => present,
- content => 'deb http://dev.camptocamp.com/packages/ etch puppet',
- }
-
-## Contributing
-
-Please report bugs and feature request using [GitHub issue
-tracker](https://github.com/camptocamp/puppet-apt/issues).
-
-For pull requests, it is very much appreciated to check your Puppet manifest
-with [puppet-lint](https://github.com/camptocamp/puppet-apt/issues) to follow the recommended Puppet style guidelines from the
-[Puppet Labs style guide](http://docs.puppetlabs.com/guides/style_guide.html).
-
-## License
-
-Copyright (c) 2012 All rights reserved.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-
diff --git a/puppet/puppet-apt/files/10periodic b/puppet/puppet-apt/files/10periodic
deleted file mode 100644
index 20214b77e3..0000000000
--- a/puppet/puppet-apt/files/10periodic
+++ /dev/null
@@ -1,4 +0,0 @@
-// Unattended-Upgrade::Mail "root";
-APT::Periodic::Update-Package-Lists "1";
-APT::Periodic::Download-Upgradeable-Packages "0";
-APT::Periodic::AutocleanInterval "1";
diff --git a/puppet/puppet-apt/lib/facter/apt_version.rb b/puppet/puppet-apt/lib/facter/apt_version.rb
deleted file mode 100644
index 1348f012c0..0000000000
--- a/puppet/puppet-apt/lib/facter/apt_version.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-output = %x{apt-get -v 2>&1}
-
-if $?.exitstatus and output.match(/apt (\d+\.\d+\.\d+).*/)
-
- Facter.add("apt_version") do
- setcode do
- $1
- end
- end
-end
diff --git a/puppet/puppet-apt/manifests/backports.pp b/puppet/puppet-apt/manifests/backports.pp
deleted file mode 100644
index 98f0ab08fa..0000000000
--- a/puppet/puppet-apt/manifests/backports.pp
+++ /dev/null
@@ -1,23 +0,0 @@
-class apt::backports ($priority = 400) {
-
- $debian_mirror = 'http://backports.debian.org/debian-backports'
- $ubuntu_mirror = 'http://archive.ubuntu.com/ubuntu'
-
- $uri = $::operatingsystem ? {
- Debian => "deb ${debian_mirror} ${::lsbdistcodename}-backports main contrib non-free\n",
- Ubuntu => "deb ${ubuntu_mirror} ${::lsbdistcodename}-backports main universe multiverse restricted\n",
- }
-
- apt::sources_list{'backports':
- ensure => present,
- content => $uri,
- }
-
- apt::preferences {"${::lsbdistcodename}-backports":
- ensure => present,
- package => '*',
- pin => "release a=${::lsbdistcodename}-backports",
- priority => $priority,
- }
-
-}
diff --git a/puppet/puppet-apt/manifests/clean.pp b/puppet/puppet-apt/manifests/clean.pp
deleted file mode 100644
index b228faa64e..0000000000
--- a/puppet/puppet-apt/manifests/clean.pp
+++ /dev/null
@@ -1,23 +0,0 @@
-# == Class: apt::clean
-#
-# Create a cronjob which will run "apt-get clean" once a month.
-#
-# === Variables
-#
-# *$apt_clean_minutes*: cronjob minutes - default uses fqdn_rand()
-# *$apt_clean_hours*: cronjob hours - default to 0
-# *$apt_clean_mday*: cronjob monthday - default uses fqdn_rand()
-#
-class apt::clean {
- $minutes = $apt_clean_minutes? {'' => fqdn_rand(60), default => $apt_clean_minutes }
- $hours = $apt_clean_hours? {'' => '0' , default => $apt_clean_hours }
- $monthday = $apt_clean_mday? {'' => fqdn_rand(29), default => $apt_clean_mday }
-
- cron {'cleanup APT cache - prevents diskfull':
- ensure => present,
- command => 'apt-get clean',
- hour => $hours,
- minute => $minutes,
- monthday => $monthday,
- }
-}
diff --git a/puppet/puppet-apt/manifests/conf.pp b/puppet/puppet-apt/manifests/conf.pp
deleted file mode 100644
index 27c416410f..0000000000
--- a/puppet/puppet-apt/manifests/conf.pp
+++ /dev/null
@@ -1,23 +0,0 @@
-define apt::conf($ensure, $content = false, $source = false) {
- if $content {
- file {"/etc/apt/apt.conf.d/${name}":
- ensure => $ensure,
- content => $content,
- owner => "root",
- group => "root",
- before => Exec['apt-get_update'],
- notify => Exec['apt-get_update'],
- }
- }
-
- if $source {
- file {"/etc/apt/apt.conf.d/${name}":
- ensure => $ensure,
- source => $source,
- owner => "root",
- group => "root",
- before => Exec['apt-get_update'],
- notify => Exec['apt-get_update'],
- }
- }
-}
diff --git a/puppet/puppet-apt/manifests/init.pp b/puppet/puppet-apt/manifests/init.pp
deleted file mode 100644
index 6560b1bbf5..0000000000
--- a/puppet/puppet-apt/manifests/init.pp
+++ /dev/null
@@ -1,50 +0,0 @@
-class apt {
-
- include apt::params
-
- Package {
- require => Exec['apt-get_update']
- }
-
- # apt support preferences.d since version >= 0.7.22
- if versioncmp($::apt_version, '0.7.22') >= 0 {
- file {'/etc/apt/preferences':
- ensure => absent,
- }
-
- file {'/etc/apt/preferences.d':
- ensure => directory,
- owner => root,
- group => root,
- mode => '0755',
- recurse => $apt::params::manage_preferences,
- purge => $apt::params::manage_preferences,
- force => $apt::params::manage_preferences,
- }
- }
-
- package {$apt::params::keyring_package:
- ensure => present,
- }
-
- # ensure only files managed by puppet be present in this directory.
- file {'/etc/apt/sources.list.d':
- ensure => directory,
- source => 'puppet:///modules/apt/empty/',
- recurse => $apt::params::manage_sourceslist,
- purge => $apt::params::manage_sourceslist,
- force => $apt::params::manage_sourceslist,
- ignore => $apt::params::ignore_sourceslist,
- }
-
- apt::conf {'10periodic':
- ensure => present,
- source => 'puppet:///modules/apt/10periodic',
- }
-
- exec {'apt-get_update':
- command => 'apt-get update',
- refreshonly => true,
- }
-
-}
diff --git a/puppet/puppet-apt/manifests/key.pp b/puppet/puppet-apt/manifests/key.pp
deleted file mode 100644
index eccdc2fad2..0000000000
--- a/puppet/puppet-apt/manifests/key.pp
+++ /dev/null
@@ -1,43 +0,0 @@
-define apt::key (
- $keyserver = 'pgp.mit.edu',
- $ensure = present,
- $source = '',
- $content = ''
-) {
-
- case $ensure {
-
- present: {
- if $content == '' {
- if $source == '' {
- $thekey = "gpg --keyserver ${keyserver} --recv-key '${name}' && gpg --export --armor '${name}'"
- }
- else {
- $thekey = "wget -O - '${source}'"
- }
- }
- else {
- $thekey = "echo '${content}'"
- }
-
-
- exec { "import gpg key ${name}":
- command => "${thekey} | apt-key add -",
- unless => "apt-key list | grep -Fqe '${name}'",
- before => Exec['apt-get_update'],
- notify => Exec['apt-get_update'],
- }
- }
-
- absent: {
- exec {"apt-key del ${name}":
- onlyif => "apt-key list | grep -Fqe '${name}'",
- }
- }
-
- default: {
- fail "Invalid 'ensure' value '${ensure}' for apt::key"
- }
-
- }
-}
diff --git a/puppet/puppet-apt/manifests/params.pp b/puppet/puppet-apt/manifests/params.pp
deleted file mode 100644
index 8846b71576..0000000000
--- a/puppet/puppet-apt/manifests/params.pp
+++ /dev/null
@@ -1,23 +0,0 @@
-class apt::params {
-
- $manage_preferences = $apt_manage_preferences ? {
- '' => true,
- default => $apt_manage_preferences,
- }
-
- $manage_sourceslist = $apt_manage_sourceslist ? {
- '' => true,
- default => $apt_manage_sourceslist,
- }
-
- $ignore_sourceslist = $apt_ignore_sourceslist ? {
- '' => '.placeholder',
- default => $apt_ignore_sourceslist,
- }
-
- $keyring_package = $::lsbdistid ? {
- Debian => ['debian-keyring', 'debian-archive-keyring'],
- Ubuntu => 'ubuntu-keyring',
- }
-
-}
diff --git a/puppet/puppet-apt/manifests/ppa.pp b/puppet/puppet-apt/manifests/ppa.pp
deleted file mode 100644
index b974cdd88b..0000000000
--- a/puppet/puppet-apt/manifests/ppa.pp
+++ /dev/null
@@ -1,23 +0,0 @@
-define apt::ppa (
- $key,
- $ensure = present,
- $ppa ='ppa'
-) {
-
- apt::key {$key:
- ensure => $ensure,
- }
-
- $ppa_name = inline_template("<%=
- if ppa.is_a?(Array)
- ppa.join('-')
- else
- ppa
- end %>")
-
- apt::sources_list {"${name}-${ppa_name}-${lsbdistcodename}":
- ensure => $ensure,
- content => template('apt/ppa-list.erb'),
- }
-
-}
diff --git a/puppet/puppet-apt/manifests/preferences.pp b/puppet/puppet-apt/manifests/preferences.pp
deleted file mode 100644
index 4fa06731c9..0000000000
--- a/puppet/puppet-apt/manifests/preferences.pp
+++ /dev/null
@@ -1,23 +0,0 @@
-define apt::preferences($ensure="present", $package="", $pin, $priority) {
-
- $pkg = $package ? {
- "" => $name,
- default => $package,
- }
-
- $fname = regsubst($name, '\.', '-', 'G')
-
- # apt support preferences.d since version >= 0.7.22
- if versioncmp($::apt_version, '0.7.22') >= 0 {
- file {"/etc/apt/preferences.d/$fname":
- ensure => $ensure,
- owner => root,
- group => root,
- mode => 644,
- content => template("apt/preferences.erb"),
- before => Exec["apt-get_update"],
- notify => Exec["apt-get_update"],
- }
- }
-
-}
diff --git a/puppet/puppet-apt/manifests/sources_list.pp b/puppet/puppet-apt/manifests/sources_list.pp
deleted file mode 100644
index 0c413dd04d..0000000000
--- a/puppet/puppet-apt/manifests/sources_list.pp
+++ /dev/null
@@ -1,27 +0,0 @@
-define apt::sources_list (
- $ensure = present,
- $source = false,
- $content = false
-) {
-
- if $source {
- file {"/etc/apt/sources.list.d/${name}.list":
- ensure => $ensure,
- source => $source,
- owner => "root",
- group => "root",
- before => Exec['apt-get_update'],
- notify => Exec['apt-get_update'],
- }
- } else {
- file {"/etc/apt/sources.list.d/${name}.list":
- ensure => $ensure,
- content => $content,
- owner => "root",
- group => "root",
- before => Exec['apt-get_update'],
- notify => Exec['apt-get_update'],
- }
- }
-
-}
diff --git a/puppet/puppet-apt/manifests/unattended-upgrade.pp b/puppet/puppet-apt/manifests/unattended-upgrade.pp
deleted file mode 100644
index 99dbf3d62a..0000000000
--- a/puppet/puppet-apt/manifests/unattended-upgrade.pp
+++ /dev/null
@@ -1,5 +0,0 @@
-class apt::unattended-upgrade {
- package {'unattended-upgrades':
- ensure => present,
- }
-}
diff --git a/puppet/puppet-apt/manifests/unattended-upgrade/automatic.pp b/puppet/puppet-apt/manifests/unattended-upgrade/automatic.pp
deleted file mode 100644
index cb642605b0..0000000000
--- a/puppet/puppet-apt/manifests/unattended-upgrade/automatic.pp
+++ /dev/null
@@ -1,18 +0,0 @@
-class apt::unattended-upgrade::automatic inherits apt::unattended-upgrade {
-
- apt::conf{'99unattended-upgrade':
- ensure => present,
- content => "APT::Periodic::Unattended-Upgrade \"1\";\n",
- }
-
- $dist = $::lsbdistid? {
- Debian => $::lsbdistcodename,
- default => $::lsbdistid,
- }
-
- apt::conf{'50unattended-upgrades':
- ensure => present,
- content => template("apt/unattended-upgrades.${dist}.erb"),
- }
-
-}
diff --git a/puppet/puppet-apt/templates/ppa-list.erb b/puppet/puppet-apt/templates/ppa-list.erb
deleted file mode 100644
index a55d1ae3cb..0000000000
--- a/puppet/puppet-apt/templates/ppa-list.erb
+++ /dev/null
@@ -1,4 +0,0 @@
-<% ppa.each do |one_ppa| %>
-deb http://ppa.launchpad.net/<%= name %>/<%= one_ppa %>/ubuntu <%= lsbdistcodename %> main
-deb-src http://ppa.launchpad.net/<%= name %>/<%= one_ppa %>/ubuntu <%= lsbdistcodename %> main
-<% end %>
diff --git a/puppet/puppet-apt/templates/preferences.erb b/puppet/puppet-apt/templates/preferences.erb
deleted file mode 100644
index 920cb50b04..0000000000
--- a/puppet/puppet-apt/templates/preferences.erb
+++ /dev/null
@@ -1,5 +0,0 @@
-# file managed by puppet
-Package: <%= pkg %>
-Pin: <%= pin %>
-Pin-Priority: <%= priority %>
-
diff --git a/puppet/puppet-apt/templates/unattended-upgrades.Ubuntu.erb b/puppet/puppet-apt/templates/unattended-upgrades.Ubuntu.erb
deleted file mode 100644
index 5686d07fed..0000000000
--- a/puppet/puppet-apt/templates/unattended-upgrades.Ubuntu.erb
+++ /dev/null
@@ -1,8 +0,0 @@
-Unattended-Upgrade::Allowed-Origins {
- "Ubuntu <%= lsbdistcodename %>-security";
- "Ubuntu <%= lsbdistcodename %>-updates";
- "Ubuntu <%= lsbdistcodename %>";
- "Canonical <%= lsbdistcodename %>";
-};
-
-Dpkg::Options { "--force-confold"; }
diff --git a/puppet/puppet-apt/templates/unattended-upgrades.lenny.erb b/puppet/puppet-apt/templates/unattended-upgrades.lenny.erb
deleted file mode 100644
index e401917f2a..0000000000
--- a/puppet/puppet-apt/templates/unattended-upgrades.lenny.erb
+++ /dev/null
@@ -1,6 +0,0 @@
-// file managed by puppet
-Unattended-Upgrade::Allowed-Origins {
- "Debian oldstable";
-};
-
-Dpkg::Options { "--force-confold"; }
diff --git a/puppet/puppet-apt/templates/unattended-upgrades.squeeze.erb b/puppet/puppet-apt/templates/unattended-upgrades.squeeze.erb
deleted file mode 100644
index c52144b56b..0000000000
--- a/puppet/puppet-apt/templates/unattended-upgrades.squeeze.erb
+++ /dev/null
@@ -1,7 +0,0 @@
-// file managed by puppet
-Unattended-Upgrade::Allowed-Origins {
- "Debian stable";
- "Debian squeeze-security";
-};
-
-Dpkg::Options { "--force-confold"; }
diff --git a/puppet/stdlib/CHANGELOG b/puppet/stdlib/CHANGELOG
new file mode 100644
index 0000000000..e1a095f630
--- /dev/null
+++ b/puppet/stdlib/CHANGELOG
@@ -0,0 +1,278 @@
+2013-05-06 - Jeff McCune - 4.1.0
+ * (#20582) Restore facter_dot_d to stdlib for PE users (3b887c8)
+ * (maint) Update Gemfile with GEM_FACTER_VERSION (f44d535)
+
+2013-05-06 - Alex Cline - 4.1.0
+ * Terser method of string to array conversion courtesy of ethooz. (d38bce0)
+
+2013-05-06 - Alex Cline 4.1.0
+ * Refactor ensure_resource expectations (b33cc24)
+
+2013-05-06 - Alex Cline 4.1.0
+ * Changed str-to-array conversion and removed abbreviation. (de253db)
+
+2013-05-03 - Alex Cline 4.1.0
+ * (#20548) Allow an array of resource titles to be passed into the ensure_resource function (e08734a)
+
+2013-05-02 - Raphaël Pinson - 4.1.0
+ * Add a dirname function (2ba9e47)
+
+2013-04-29 - Mark Smith-Guerrero - 4.1.0
+ * (maint) Fix a small typo in hash() description (928036a)
+
+2013-04-12 - Jeff McCune - 4.0.2
+ * Update user information in gemspec to make the intent of the Gem clear.
+
+2013-04-11 - Jeff McCune - 4.0.1
+ * Fix README function documentation (ab3e30c)
+
+2013-04-11 - Jeff McCune - 4.0.0
+ * stdlib 4.0 drops support with Puppet 2.7
+ * stdlib 4.0 preserves support with Puppet 3
+
+2013-04-11 - Jeff McCune - 4.0.0
+ * Add ability to use puppet from git via bundler (9c5805f)
+
+2013-04-10 - Jeff McCune - 4.0.0
+ * (maint) Make stdlib usable as a Ruby GEM (e81a45e)
+
+2013-04-10 - Erik Dalén - 4.0.0
+ * Add a count function (f28550e)
+
+2013-03-31 - Amos Shapira - 4.0.0
+ * (#19998) Implement any2array (7a2fb80)
+
+2013-03-29 - Steve Huff - 4.0.0
+ * (19864) num2bool match fix (8d217f0)
+
+2013-03-20 - Erik Dalén - 4.0.0
+ * Allow comparisons of Numeric and number as String (ff5dd5d)
+
+2013-03-26 - Richard Soderberg - 4.0.0
+ * add suffix function to accompany the prefix function (88a93ac)
+
+2013-03-19 - Kristof Willaert - 4.0.0
+ * Add floor function implementation and unit tests (0527341)
+
+2012-04-03 - Eric Shamow - 4.0.0
+ * (#13610) Add is_function_available to stdlib (961dcab)
+
+2012-12-17 - Justin Lambert - 4.0.0
+ * str2bool should return a boolean if called with a boolean (5d5a4d4)
+
+2012-10-23 - Uwe Stuehler - 4.0.0
+ * Fix number of arguments check in flatten() (e80207b)
+
+2013-03-11 - Jeff McCune - 4.0.0
+ * Add contributing document (96e19d0)
+
+2013-03-04 - Raphaël Pinson - 4.0.0
+ * Add missing documentation for validate_augeas and validate_cmd to README.markdown (a1510a1)
+
+2013-02-14 - Joshua Hoblitt - 4.0.0
+ * (#19272) Add has_element() function (95cf3fe)
+
+2013-02-07 - Raphaël Pinson - 4.0.0
+ * validate_cmd(): Use Puppet::Util::Execution.execute when available (69248df)
+
+2012-12-06 - Raphaël Pinson - 4.0.0
+ * Add validate_augeas function (3a97c23)
+
+2012-12-06 - Raphaël Pinson - 4.0.0
+ * Add validate_cmd function (6902cc5)
+
+2013-01-14 - David Schmitt - 4.0.0
+ * Add geppetto project definition (b3fc0a3)
+
+2013-01-02 - Jaka Hudoklin - 4.0.0
+ * Add getparam function to get defined resource parameters (20e0e07)
+
+2013-01-05 - Jeff McCune - 4.0.0
+ * (maint) Add Travis CI Support (d082046)
+
+2012-12-04 - Jeff McCune - 4.0.0
+ * Clarify that stdlib 3 supports Puppet 3 (3a6085f)
+
+2012-11-30 - Erik Dalén - 4.0.0
+ * maint: style guideline fixes (7742e5f)
+
+2012-11-09 - James Fryman - 4.0.0
+ * puppet-lint cleanup (88acc52)
+
+2012-11-06 - Joe Julian - 4.0.0
+ * Add function, uriescape, to URI.escape strings. Redmine #17459 (fd52b8d)
+
+2012-09-18 - Chad Metcalf - 3.2.0
+ * Add an ensure_packages function. (8a8c09e)
+
+2012-11-23 - Erik Dalén - 3.2.0
+ * (#17797) min() and max() functions (9954133)
+
+2012-05-23 - Peter Meier - 3.2.0
+ * (#14670) autorequire a file_line resource's path (dfcee63)
+
+2012-11-19 - Joshua Harlan Lifton - 3.2.0
+ * Add join_keys_to_values function (ee0f2b3)
+
+2012-11-17 - Joshua Harlan Lifton - 3.2.0
+ * Extend delete function for strings and hashes (7322e4d)
+
+2012-08-03 - Gary Larizza - 3.2.0
+ * Add the pick() function (ba6dd13)
+
+2012-03-20 - Wil Cooley - 3.2.0
+ * (#13974) Add predicate functions for interface facts (f819417)
+
+2012-11-06 - Joe Julian - 3.2.0
+ * Add function, uriescape, to URI.escape strings. Redmine #17459 (70f4a0e)
+
+2012-10-25 - Jeff McCune - 3.1.1
+ * (maint) Fix spec failures resulting from Facter API changes (97f836f)
+
+2012-10-23 - Matthaus Owens - 3.1.0
+ * Add PE facts to stdlib (cdf3b05)
+
+2012-08-16 - Jeff McCune - 3.0.1
+ * Fix accidental removal of facts_dot_d.rb in 3.0.0 release
+
+2012-08-16 - Jeff McCune - 3.0.0
+ * stdlib 3.0 drops support with Puppet 2.6
+ * stdlib 3.0 preserves support with Puppet 2.7
+
+2012-08-07 - Dan Bode - 3.0.0
+ * Add function ensure_resource and defined_with_params (ba789de)
+
+2012-07-10 - Hailee Kenney - 3.0.0
+ * (#2157) Remove facter_dot_d for compatibility with external facts (f92574f)
+
+2012-04-10 - Chris Price - 3.0.0
+ * (#13693) moving logic from local spec_helper to puppetlabs_spec_helper (85f96df)
+
+2012-10-25 - Jeff McCune - 2.5.1
+ * (maint) Fix spec failures resulting from Facter API changes (97f836f)
+
+2012-10-23 - Matthaus Owens - 2.5.0
+ * Add PE facts to stdlib (cdf3b05)
+
+2012-08-15 - Dan Bode - 2.5.0
+ * Explicitly load functions used by ensure_resource (9fc3063)
+
+2012-08-13 - Dan Bode - 2.5.0
+ * Add better docs about duplicate resource failures (97d327a)
+
+2012-08-13 - Dan Bode - 2.5.0
+ * Handle undef for parameter argument (4f8b133)
+
+2012-08-07 - Dan Bode - 2.5.0
+ * Add function ensure_resource and defined_with_params (a0cb8cd)
+
+2012-08-20 - Jeff McCune - 2.5.0
+ * Disable tests that fail on 2.6.x due to #15912 (c81496e)
+
+2012-08-20 - Jeff McCune - 2.5.0
+ * (Maint) Fix mis-use of rvalue functions as statements (4492913)
+
+2012-08-20 - Jeff McCune - 2.5.0
+ * Add .rspec file to repo root (88789e8)
+
+2012-06-07 - Chris Price - 2.4.0
+ * Add support for a 'match' parameter to file_line (a06c0d8)
+
+2012-08-07 - Erik Dalén - 2.4.0
+ * (#15872) Add to_bytes function (247b69c)
+
+2012-07-19 - Jeff McCune - 2.4.0
+ * (Maint) use PuppetlabsSpec::PuppetInternals.scope (master) (deafe88)
+
+2012-07-10 - Hailee Kenney - 2.4.0
+ * (#2157) Make facts_dot_d compatible with external facts (5fb0ddc)
+
+2012-03-16 - Steve Traylen - 2.4.0
+ * (#13205) Rotate array/string randomley based on fqdn, fqdn_rotate() (fef247b)
+
+2012-05-22 - Peter Meier - 2.3.3
+ * fix regression in #11017 properly (f0a62c7)
+
+2012-05-10 - Jeff McCune - 2.3.3
+ * Fix spec tests using the new spec_helper (7d34333)
+
+2012-05-10 - Puppet Labs - 2.3.2
+ * Make file_line default to ensure => present (1373e70)
+ * Memoize file_line spec instance variables (20aacc5)
+ * Fix spec tests using the new spec_helper (1ebfa5d)
+ * (#13595) initialize_everything_for_tests couples modules Puppet ver (3222f35)
+ * (#13439) Fix MRI 1.9 issue with spec_helper (15c5fd1)
+ * (#13439) Fix test failures with Puppet 2.6.x (665610b)
+ * (#13439) refactor spec helper for compatibility with both puppet 2.7 and master (82194ca)
+ * (#13494) Specify the behavior of zero padded strings (61891bb)
+
+2012-03-29 Puppet Labs - 2.1.3
+* (#11607) Add Rakefile to enable spec testing
+* (#12377) Avoid infinite loop when retrying require json
+
+2012-03-13 Puppet Labs - 2.3.1
+* (#13091) Fix LoadError bug with puppet apply and puppet_vardir fact
+
+2012-03-12 Puppet Labs - 2.3.0
+* Add a large number of new Puppet functions
+* Backwards compatibility preserved with 2.2.x
+
+2011-12-30 Puppet Labs - 2.2.1
+* Documentation only release for the Forge
+
+2011-12-30 Puppet Labs - 2.1.2
+* Documentation only release for PE 2.0.x
+
+2011-11-08 Puppet Labs - 2.2.0
+* #10285 - Refactor json to use pson instead.
+* Maint - Add watchr autotest script
+* Maint - Make rspec tests work with Puppet 2.6.4
+* #9859 - Add root_home fact and tests
+
+2011-08-18 Puppet Labs - 2.1.1
+* Change facts.d paths to match Facter 2.0 paths.
+* /etc/facter/facts.d
+* /etc/puppetlabs/facter/facts.d
+
+2011-08-17 Puppet Labs - 2.1.0
+* Add R.I. Pienaar's facts.d custom facter fact
+* facts defined in /etc/facts.d and /etc/puppetlabs/facts.d are
+ automatically loaded now.
+
+2011-08-04 Puppet Labs - 2.0.0
+* Rename whole_line to file_line
+* This is an API change and as such motivating a 2.0.0 release according to semver.org.
+
+2011-08-04 Puppet Labs - 1.1.0
+* Rename append_line to whole_line
+* This is an API change and as such motivating a 1.1.0 release.
+
+2011-08-04 Puppet Labs - 1.0.0
+* Initial stable release
+* Add validate_array and validate_string functions
+* Make merge() function work with Ruby 1.8.5
+* Add hash merging function
+* Add has_key function
+* Add loadyaml() function
+* Add append_line native
+
+2011-06-21 Jeff McCune - 0.1.7
+* Add validate_hash() and getvar() functions
+
+2011-06-15 Jeff McCune - 0.1.6
+* Add anchor resource type to provide containment for composite classes
+
+2011-06-03 Jeff McCune - 0.1.5
+* Add validate_bool() function to stdlib
+
+0.1.4 2011-05-26 Jeff McCune
+* Move most stages after main
+
+0.1.3 2011-05-25 Jeff McCune
+* Add validate_re() function
+
+0.1.2 2011-05-24 Jeff McCune
+* Update to add annotated tag
+
+0.1.1 2011-05-24 Jeff McCune
+* Add stdlib::stages class with a standard set of stages
diff --git a/puppet/stdlib/CONTRIBUTING.md b/puppet/stdlib/CONTRIBUTING.md
new file mode 100644
index 0000000000..bd11f636e6
--- /dev/null
+++ b/puppet/stdlib/CONTRIBUTING.md
@@ -0,0 +1,65 @@
+# How to contribute
+
+Third-party patches are essential for keeping stdlib great. We simply can't
+access the huge number of platforms and myriad configurations for running
+stdlib. We want to keep it as easy as possible to contribute changes that
+get things working in your environment. There are a few guidelines that we
+need contributors to follow so that we can have a chance of keeping on
+top of things.
+
+## Getting Started
+
+* Make sure you have a [Redmine account](http://projects.puppetlabs.com)
+* Make sure you have a [GitHub account](https://github.com/signup/free)
+* Submit a ticket for your issue, assuming one does not already exist.
+ * Clearly describe the issue including steps to reproduce when it is a bug.
+ * Make sure you fill in the earliest version that you know has the issue.
+* Fork the repository on GitHub
+
+## Making Changes
+
+* Create a topic branch from where you want to base your work.
+ * This is usually the master branch.
+ * Only target release branches if you are certain your fix must be on that
+ branch.
+ * To quickly create a topic branch based on master; `git branch
+ fix/master/my_contribution master` then checkout the new branch with `git
+ checkout fix/master/my_contribution`. Please avoid working directly on the
+ `master` branch.
+* Make commits of logical units.
+* Check for unnecessary whitespace with `git diff --check` before committing.
+* Make sure your commit messages are in the proper format.
+
+````
+ (#99999) Make the example in CONTRIBUTING imperative and concrete
+
+ Without this patch applied the example commit message in the CONTRIBUTING
+ document is not a concrete example. This is a problem because the
+ contributor is left to imagine what the commit message should look like
+ based on a description rather than an example. This patch fixes the
+ problem by making the example concrete and imperative.
+
+ The first line is a real life imperative statement with a ticket number
+ from our issue tracker. The body describes the behavior without the patch,
+ why this is a problem, and how the patch fixes the problem when applied.
+````
+
+* Make sure you have added the necessary tests for your changes.
+* Run _all_ the tests to assure nothing else was accidentally broken.
+
+## Submitting Changes
+
+* Sign the [Contributor License Agreement](http://links.puppetlabs.com/cla).
+* Push your changes to a topic branch in your fork of the repository.
+* Submit a pull request to the repository in the puppetlabs organization.
+* Update your Redmine ticket to mark that you have submitted code and are ready for it to be reviewed.
+ * Include a link to the pull request in the ticket
+
+# Additional Resources
+
+* [More information on contributing](http://links.puppetlabs.com/contribute-to-puppet)
+* [Bug tracker (Redmine)](http://projects.puppetlabs.com)
+* [Contributor License Agreement](http://links.puppetlabs.com/cla)
+* [General GitHub documentation](http://help.github.com/)
+* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
+* #puppet-dev IRC channel on freenode.org
diff --git a/puppet/stdlib/Gemfile b/puppet/stdlib/Gemfile
new file mode 100644
index 0000000000..197cc6b015
--- /dev/null
+++ b/puppet/stdlib/Gemfile
@@ -0,0 +1,42 @@
+source "https://rubygems.org"
+
+def location_for(place, fake_version = nil)
+ mdata = /^(git:[^#]*)#(.*)/.match(place)
+ if mdata
+ [fake_version, { :git => mdata[1], :branch => mdata[2], :require => false }].compact
+ elsif place =~ /^file:\/\/(.*)/
+ ['>= 0', { :path => File.expand_path(mdata[1]), :require => false }]
+ else
+ [place, { :require => false }]
+ end
+end
+
+group :development do
+ gem 'watchr'
+end
+
+group :development, :test do
+ gem 'rake'
+ gem 'puppetmodule-stdlib', ">= 1.0.0", :path => File.expand_path("..", __FILE__)
+ gem 'rspec', "~> 2.11.0", :require => false
+ gem 'mocha', "~> 0.10.5", :require => false
+ gem 'puppetlabs_spec_helper', :require => false
+ gem 'rspec-puppet', :require => false
+end
+
+facterversion = ENV['GEM_FACTER_VERSION']
+if facterversion
+ gem 'facter', *location_for(facterversion)
+else
+ gem 'facter', :require => false
+end
+
+ENV['GEM_PUPPET_VERSION'] ||= ENV['PUPPET_GEM_VERSION']
+puppetversion = ENV['GEM_PUPPET_VERSION']
+if puppetversion
+ gem 'puppet', *location_for(puppetversion)
+else
+ gem 'puppet', :require => false
+end
+
+# vim:ft=ruby
diff --git a/puppet/stdlib/LICENSE b/puppet/stdlib/LICENSE
new file mode 100644
index 0000000000..ec0587c0d9
--- /dev/null
+++ b/puppet/stdlib/LICENSE
@@ -0,0 +1,19 @@
+Copyright (C) 2011 Puppet Labs Inc
+
+and some parts:
+
+Copyright (C) 2011 Krzysztof Wilczynski
+
+Puppet Labs can be contacted at: info@puppetlabs.com
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
diff --git a/puppet/stdlib/Modulefile b/puppet/stdlib/Modulefile
new file mode 100644
index 0000000000..9d2e8c220c
--- /dev/null
+++ b/puppet/stdlib/Modulefile
@@ -0,0 +1,11 @@
+name 'puppetlabs-stdlib'
+version '4.1.0'
+source 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
+author 'puppetlabs'
+license 'Apache 2.0'
+summary 'Puppet Module Standard Library'
+description 'Standard Library for Puppet Modules'
+project_page 'https://github.com/puppetlabs/puppetlabs-stdlib'
+
+## Add dependencies, if any:
+# dependency 'username/name', '>= 1.2.0'
diff --git a/puppet/stdlib/README.markdown b/puppet/stdlib/README.markdown
new file mode 100644
index 0000000000..7b45b17006
--- /dev/null
+++ b/puppet/stdlib/README.markdown
@@ -0,0 +1,1194 @@
+# Puppet Labs Standard Library #
+
+[![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-stdlib.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-stdlib)
+
+This module provides a "standard library" of resources for developing Puppet
+Modules. This modules will include the following additions to Puppet
+
+ * Stages
+ * Facts
+ * Functions
+ * Defined resource types
+ * Types
+ * Providers
+
+This module is officially curated and provided by Puppet Labs. The modules
+Puppet Labs writes and distributes will make heavy use of this standard
+library.
+
+To report or research a bug with any part of this module, please go to
+[http://projects.puppetlabs.com/projects/stdlib](http://projects.puppetlabs.com/projects/stdlib)
+
+# Versions #
+
+This module follows semver.org (v1.0.0) versioning guidelines. The standard
+library module is released as part of [Puppet
+Enterprise](http://puppetlabs.com/puppet/puppet-enterprise/) and as a result
+older versions of Puppet Enterprise that Puppet Labs still supports will have
+bugfix maintenance branches periodically "merged up" into master. The current
+list of integration branches are:
+
+ * v2.1.x (v2.1.1 released in PE 1)
+ * v2.2.x (Never released as part of PE, only to the Forge)
+ * v2.3.x (Released in PE 2)
+ * v3.0.x (Never released as part of PE, only to the Forge)
+ * v4.0.x (Drops support for Puppet 2.7)
+ * master (mainline development branch)
+
+The first Puppet Enterprise version including the stdlib module is Puppet
+Enterprise 1.2.
+
+# Compatibility #
+
+Puppet Versions | < 2.6 | 2.6 | 2.7 | 3.x |
+:---------------|:-----:|:---:|:---:|:----:
+**stdlib 2.x** | no | **yes** | **yes** | no
+**stdlib 3.x** | no | no | **yes** | **yes**
+**stdlib 4.x** | no | no | no | **yes**
+
+The stdlib module does not work with Puppet versions released prior to Puppet
+2.6.0.
+
+## stdlib 2.x ##
+
+All stdlib releases in the 2.0 major version support Puppet 2.6 and Puppet 2.7.
+
+## stdlib 3.x ##
+
+The 3.0 major release of stdlib drops support for Puppet 2.6. Stdlib 3.x
+supports Puppet 2 and Puppet 3.
+
+## stdlib 4.x ##
+
+The 4.0 major release of stdlib drops support for Puppet 2.7. Stdlib 4.x
+supports Puppet 3. Notably, ruby 1.8.5 is no longer supported though ruby
+1.8.7, 1.9.3, and 2.0.0 are fully supported.
+
+# Functions #
+
+abs
+---
+Returns the absolute value of a number, for example -34.56 becomes
+34.56. Takes a single integer and float value as an argument.
+
+
+- *Type*: rvalue
+
+any2array
+---------
+This converts any object to an array containing that object. Empty argument
+lists are converted to an empty array. Arrays are left untouched. Hashes are
+converted to arrays of alternating keys and values.
+
+
+- *Type*: rvalue
+
+bool2num
+--------
+Converts a boolean to a number. Converts the values:
+false, f, 0, n, and no to 0
+true, t, 1, y, and yes to 1
+ Requires a single boolean or string as an input.
+
+
+- *Type*: rvalue
+
+capitalize
+----------
+Capitalizes the first letter of a string or array of strings.
+Requires either a single string or an array as an input.
+
+
+- *Type*: rvalue
+
+chomp
+-----
+Removes the record separator from the end of a string or an array of
+strings, for example `hello\n` becomes `hello`.
+Requires a single string or array as an input.
+
+
+- *Type*: rvalue
+
+chop
+----
+Returns a new string with the last character removed. If the string ends
+with `\r\n`, both characters are removed. Applying chop to an empty
+string returns an empty string. If you wish to merely remove record
+separators then you should use the `chomp` function.
+Requires a string or array of strings as input.
+
+
+- *Type*: rvalue
+
+concat
+------
+Appends the contents of array 2 onto array 1.
+
+*Example:*
+
+ concat(['1','2','3'],['4','5','6'])
+
+Would result in:
+
+ ['1','2','3','4','5','6']
+
+
+- *Type*: rvalue
+
+count
+-----
+Takes an array as first argument and an optional second argument.
+Count the number of elements in array that matches second argument.
+If called with only an array it counts the number of elements that are not nil/undef.
+
+
+- *Type*: rvalue
+
+defined_with_params
+-------------------
+Takes a resource reference and an optional hash of attributes.
+
+Returns true if a resource with the specified attributes has already been added
+to the catalog, and false otherwise.
+
+ user { 'dan':
+ ensure => present,
+ }
+
+ if ! defined_with_params(User[dan], {'ensure' => 'present' }) {
+ user { 'dan': ensure => present, }
+ }
+
+
+- *Type*: rvalue
+
+delete
+------
+Deletes all instances of a given element from an array, substring from a
+string, or key from a hash.
+
+*Examples:*
+
+ delete(['a','b','c','b'], 'b')
+ Would return: ['a','c']
+
+ delete({'a'=>1,'b'=>2,'c'=>3}, 'b')
+ Would return: {'a'=>1,'c'=>3}
+
+ delete('abracadabra', 'bra')
+ Would return: 'acada'
+
+
+- *Type*: rvalue
+
+delete_at
+---------
+Deletes a determined indexed value from an array.
+
+*Examples:*
+
+ delete_at(['a','b','c'], 1)
+
+Would return: ['a','c']
+
+
+- *Type*: rvalue
+
+dirname
+-------
+Returns the `dirname` of a path.
+
+*Examples:*
+
+ dirname('/path/to/a/file.ext')
+
+Would return: '/path/to/a'
+
+downcase
+--------
+Converts the case of a string or all strings in an array to lower case.
+
+
+- *Type*: rvalue
+
+empty
+-----
+Returns true if the variable is empty.
+
+
+- *Type*: rvalue
+
+ensure_packages
+---------------
+Takes a list of packages and only installs them if they don't already exist.
+
+
+- *Type*: statement
+
+ensure_resource
+---------------
+Takes a resource type, title, and a list of attributes that describe a
+resource.
+
+ user { 'dan':
+ ensure => present,
+ }
+
+This example only creates the resource if it does not already exist:
+
+ ensure_resource('user, 'dan', {'ensure' => 'present' })
+
+If the resource already exists but does not match the specified parameters,
+this function will attempt to recreate the resource leading to a duplicate
+resource definition error.
+
+An array of resources can also be passed in and each will be created with
+the type and parameters specified if it doesn't already exist.
+
+ ensure_resource('user', ['dan','alex'], {'ensure' => 'present'})
+
+
+
+- *Type*: statement
+
+flatten
+-------
+This function flattens any deeply nested arrays and returns a single flat array
+as a result.
+
+*Examples:*
+
+ flatten(['a', ['b', ['c']]])
+
+Would return: ['a','b','c']
+
+
+- *Type*: rvalue
+
+floor
+-----
+Returns the largest integer less or equal to the argument.
+Takes a single numeric value as an argument.
+
+
+- *Type*: rvalue
+
+fqdn_rotate
+-----------
+Rotates an array a random number of times based on a nodes fqdn.
+
+
+- *Type*: rvalue
+
+get_module_path
+---------------
+Returns the absolute path of the specified module for the current
+environment.
+
+Example:
+ $module_path = get_module_path('stdlib')
+
+
+- *Type*: rvalue
+
+getparam
+--------
+Takes a resource reference and name of the parameter and
+returns value of resource's parameter.
+
+*Examples:*
+
+ define example_resource($param) {
+ }
+
+ example_resource { "example_resource_instance":
+ param => "param_value"
+ }
+
+ getparam(Example_resource["example_resource_instance"], "param")
+
+Would return: param_value
+
+
+- *Type*: rvalue
+
+getvar
+------
+Lookup a variable in a remote namespace.
+
+For example:
+
+ $foo = getvar('site::data::foo')
+ # Equivalent to $foo = $site::data::foo
+
+This is useful if the namespace itself is stored in a string:
+
+ $datalocation = 'site::data'
+ $bar = getvar("${datalocation}::bar")
+ # Equivalent to $bar = $site::data::bar
+
+
+- *Type*: rvalue
+
+grep
+----
+This function searches through an array and returns any elements that match
+the provided regular expression.
+
+*Examples:*
+
+ grep(['aaa','bbb','ccc','aaaddd'], 'aaa')
+
+Would return:
+
+ ['aaa','aaaddd']
+
+
+- *Type*: rvalue
+
+has_interface_with
+------------------
+Returns boolean based on kind and value:
+* macaddress
+* netmask
+* ipaddress
+* network
+
+has_interface_with("macaddress", "x:x:x:x:x:x")
+has_interface_with("ipaddress", "127.0.0.1") => true
+etc.
+
+If no "kind" is given, then the presence of the interface is checked:
+has_interface_with("lo") => true
+
+
+- *Type*: rvalue
+
+has_ip_address
+--------------
+Returns true if the client has the requested IP address on some interface.
+
+This function iterates through the 'interfaces' fact and checks the
+'ipaddress_IFACE' facts, performing a simple string comparison.
+
+
+- *Type*: rvalue
+
+has_ip_network
+--------------
+Returns true if the client has an IP address within the requested network.
+
+This function iterates through the 'interfaces' fact and checks the
+'network_IFACE' facts, performing a simple string comparision.
+
+
+- *Type*: rvalue
+
+has_key
+-------
+Determine if a hash has a certain key value.
+
+Example:
+
+ $my_hash = {'key_one' => 'value_one'}
+ if has_key($my_hash, 'key_two') {
+ notice('we will not reach here')
+ }
+ if has_key($my_hash, 'key_one') {
+ notice('this will be printed')
+ }
+
+
+
+- *Type*: rvalue
+
+hash
+----
+This function converts an array into a hash.
+
+*Examples:*
+
+ hash(['a',1,'b',2,'c',3])
+
+Would return: {'a'=>1,'b'=>2,'c'=>3}
+
+
+- *Type*: rvalue
+
+is_array
+--------
+Returns true if the variable passed to this function is an array.
+
+- *Type*: rvalue
+
+is_domain_name
+--------------
+Returns true if the string passed to this function is a syntactically correct domain name.
+
+- *Type*: rvalue
+
+is_float
+--------
+Returns true if the variable passed to this function is a float.
+
+- *Type*: rvalue
+
+is_function_available
+---------------------
+This function accepts a string as an argument, determines whether the
+Puppet runtime has access to a function by that name. It returns a
+true if the function exists, false if not.
+
+- *Type*: rvalue
+
+is_hash
+-------
+Returns true if the variable passed to this function is a hash.
+
+- *Type*: rvalue
+
+is_integer
+----------
+Returns true if the variable returned to this string is an integer.
+
+- *Type*: rvalue
+
+is_ip_address
+-------------
+Returns true if the string passed to this function is a valid IP address.
+
+- *Type*: rvalue
+
+is_mac_address
+--------------
+Returns true if the string passed to this function is a valid mac address.
+
+- *Type*: rvalue
+
+is_numeric
+----------
+Returns true if the variable passed to this function is a number.
+
+- *Type*: rvalue
+
+is_string
+---------
+Returns true if the variable passed to this function is a string.
+
+- *Type*: rvalue
+
+join
+----
+This function joins an array into a string using a seperator.
+
+*Examples:*
+
+ join(['a','b','c'], ",")
+
+Would result in: "a,b,c"
+
+- *Type*: rvalue
+
+join_keys_to_values
+-------------------
+This function joins each key of a hash to that key's corresponding value with a
+separator. Keys and values are cast to strings. The return value is an array in
+which each element is one joined key/value pair.
+
+*Examples:*
+
+ join_keys_to_values({'a'=>1,'b'=>2}, " is ")
+
+Would result in: ["a is 1","b is 2"]
+
+- *Type*: rvalue
+
+keys
+----
+Returns the keys of a hash as an array.
+
+- *Type*: rvalue
+
+loadyaml
+--------
+Load a YAML file containing an array, string, or hash, and return the data
+in the corresponding native data type.
+
+For example:
+
+ $myhash = loadyaml('/etc/puppet/data/myhash.yaml')
+
+
+- *Type*: rvalue
+
+lstrip
+------
+Strips leading spaces to the left of a string.
+
+- *Type*: rvalue
+
+max
+---
+Returns the highest value of all arguments.
+Requires at least one argument.
+
+- *Type*: rvalue
+
+member
+------
+This function determines if a variable is a member of an array.
+
+*Examples:*
+
+ member(['a','b'], 'b')
+
+Would return: true
+
+ member(['a','b'], 'c')
+
+Would return: false
+
+- *Type*: rvalue
+
+merge
+-----
+Merges two or more hashes together and returns the resulting hash.
+
+For example:
+
+ $hash1 = {'one' => 1, 'two', => 2}
+ $hash2 = {'two' => 'dos', 'three', => 'tres'}
+ $merged_hash = merge($hash1, $hash2)
+ # The resulting hash is equivalent to:
+ # $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'}
+
+When there is a duplicate key, the key in the rightmost hash will "win."
+
+- *Type*: rvalue
+
+min
+---
+Returns the lowest value of all arguments.
+Requires at least one argument.
+
+- *Type*: rvalue
+
+num2bool
+--------
+This function converts a number or a string representation of a number into a
+true boolean. Zero or anything non-numeric becomes false. Numbers higher then 0
+become true.
+
+- *Type*: rvalue
+
+parsejson
+---------
+This function accepts JSON as a string and converts into the correct Puppet
+structure.
+
+- *Type*: rvalue
+
+parseyaml
+---------
+This function accepts YAML as a string and converts it into the correct
+Puppet structure.
+
+- *Type*: rvalue
+
+pick
+----
+This function is similar to a coalesce function in SQL in that it will return
+the first value in a list of values that is not undefined or an empty string
+(two things in Puppet that will return a boolean false value). Typically,
+this function is used to check for a value in the Puppet Dashboard/Enterprise
+Console, and failover to a default value like the following:
+
+ $real_jenkins_version = pick($::jenkins_version, '1.449')
+
+The value of $real_jenkins_version will first look for a top-scope variable
+called 'jenkins_version' (note that parameters set in the Puppet Dashboard/
+Enterprise Console are brought into Puppet as top-scope variables), and,
+failing that, will use a default value of 1.449.
+
+- *Type*: rvalue
+
+prefix
+------
+This function applies a prefix to all elements in an array.
+
+*Examples:*
+
+ prefix(['a','b','c'], 'p')
+
+Will return: ['pa','pb','pc']
+
+- *Type*: rvalue
+
+range
+-----
+When given range in the form of (start, stop) it will extrapolate a range as
+an array.
+
+*Examples:*
+
+ range("0", "9")
+
+Will return: [0,1,2,3,4,5,6,7,8,9]
+
+ range("00", "09")
+
+Will return: [0,1,2,3,4,5,6,7,8,9] (Zero padded strings are converted to
+integers automatically)
+
+ range("a", "c")
+
+Will return: ["a","b","c"]
+
+ range("host01", "host10")
+
+Will return: ["host01", "host02", ..., "host09", "host10"]
+
+- *Type*: rvalue
+
+reject
+------
+This function searches through an array and rejects all elements that match
+the provided regular expression.
+
+*Examples:*
+
+ reject(['aaa','bbb','ccc','aaaddd'], 'aaa')
+
+Would return:
+
+ ['bbb','ccc']
+
+
+- *Type*: rvalue
+
+reverse
+-------
+Reverses the order of a string or array.
+
+- *Type*: rvalue
+
+rstrip
+------
+Strips leading spaces to the right of the string.
+
+- *Type*: rvalue
+
+shuffle
+-------
+Randomizes the order of a string or array elements.
+
+- *Type*: rvalue
+
+size
+----
+Returns the number of elements in a string or array.
+
+- *Type*: rvalue
+
+sort
+----
+Sorts strings and arrays lexically.
+
+- *Type*: rvalue
+
+squeeze
+-------
+Returns a new string where runs of the same character that occur in this set
+are replaced by a single character.
+
+- *Type*: rvalue
+
+str2bool
+--------
+This converts a string to a boolean. This attempt to convert strings that
+contain things like: y, 1, t, true to 'true' and strings that contain things
+like: 0, f, n, false, no to 'false'.
+
+
+- *Type*: rvalue
+
+str2saltedsha512
+----------------
+This converts a string to a salted-SHA512 password hash (which is used for
+OS X versions >= 10.7). Given any simple string, you will get a hex version
+of a salted-SHA512 password hash that can be inserted into your Puppet
+manifests as a valid password attribute.
+
+
+- *Type*: rvalue
+
+strftime
+--------
+This function returns formatted time.
+
+*Examples:*
+
+To return the time since epoch:
+
+ strftime("%s")
+
+To return the date:
+
+ strftime("%Y-%m-%d")
+
+*Format meaning:*
+
+ %a - The abbreviated weekday name (``Sun'')
+ %A - The full weekday name (``Sunday'')
+ %b - The abbreviated month name (``Jan'')
+ %B - The full month name (``January'')
+ %c - The preferred local date and time representation
+ %C - Century (20 in 2009)
+ %d - Day of the month (01..31)
+ %D - Date (%m/%d/%y)
+ %e - Day of the month, blank-padded ( 1..31)
+ %F - Equivalent to %Y-%m-%d (the ISO 8601 date format)
+ %h - Equivalent to %b
+ %H - Hour of the day, 24-hour clock (00..23)
+ %I - Hour of the day, 12-hour clock (01..12)
+ %j - Day of the year (001..366)
+ %k - hour, 24-hour clock, blank-padded ( 0..23)
+ %l - hour, 12-hour clock, blank-padded ( 0..12)
+ %L - Millisecond of the second (000..999)
+ %m - Month of the year (01..12)
+ %M - Minute of the hour (00..59)
+ %n - Newline (
+)
+ %N - Fractional seconds digits, default is 9 digits (nanosecond)
+ %3N millisecond (3 digits)
+ %6N microsecond (6 digits)
+ %9N nanosecond (9 digits)
+ %p - Meridian indicator (``AM'' or ``PM'')
+ %P - Meridian indicator (``am'' or ``pm'')
+ %r - time, 12-hour (same as %I:%M:%S %p)
+ %R - time, 24-hour (%H:%M)
+ %s - Number of seconds since 1970-01-01 00:00:00 UTC.
+ %S - Second of the minute (00..60)
+ %t - Tab character ( )
+ %T - time, 24-hour (%H:%M:%S)
+ %u - Day of the week as a decimal, Monday being 1. (1..7)
+ %U - Week number of the current year,
+ starting with the first Sunday as the first
+ day of the first week (00..53)
+ %v - VMS date (%e-%b-%Y)
+ %V - Week number of year according to ISO 8601 (01..53)
+ %W - Week number of the current year,
+ starting with the first Monday as the first
+ day of the first week (00..53)
+ %w - Day of the week (Sunday is 0, 0..6)
+ %x - Preferred representation for the date alone, no time
+ %X - Preferred representation for the time alone, no date
+ %y - Year without a century (00..99)
+ %Y - Year with century
+ %z - Time zone as hour offset from UTC (e.g. +0900)
+ %Z - Time zone name
+ %% - Literal ``%'' character
+
+
+- *Type*: rvalue
+
+strip
+-----
+This function removes leading and trailing whitespace from a string or from
+every string inside an array.
+
+*Examples:*
+
+ strip(" aaa ")
+
+Would result in: "aaa"
+
+
+- *Type*: rvalue
+
+suffix
+------
+This function applies a suffix to all elements in an array.
+
+*Examples:*
+
+ suffix(['a','b','c'], 'p')
+
+Will return: ['ap','bp','cp']
+
+
+- *Type*: rvalue
+
+swapcase
+--------
+This function will swap the existing case of a string.
+
+*Examples:*
+
+ swapcase("aBcD")
+
+Would result in: "AbCd"
+
+
+- *Type*: rvalue
+
+time
+----
+This function will return the current time since epoch as an integer.
+
+*Examples:*
+
+ time()
+
+Will return something like: 1311972653
+
+
+- *Type*: rvalue
+
+to_bytes
+--------
+Converts the argument into bytes, for example 4 kB becomes 4096.
+Takes a single string value as an argument.
+
+
+- *Type*: rvalue
+
+type
+----
+Returns the type when passed a variable. Type can be one of:
+
+* string
+* array
+* hash
+* float
+* integer
+* boolean
+
+
+- *Type*: rvalue
+
+unique
+------
+This function will remove duplicates from strings and arrays.
+
+*Examples:*
+
+ unique("aabbcc")
+
+Will return:
+
+ abc
+
+You can also use this with arrays:
+
+ unique(["a","a","b","b","c","c"])
+
+This returns:
+
+ ["a","b","c"]
+
+
+- *Type*: rvalue
+
+upcase
+------
+Converts a string or an array of strings to uppercase.
+
+*Examples:*
+
+ upcase("abcd")
+
+Will return:
+
+ ASDF
+
+
+- *Type*: rvalue
+
+uriescape
+---------
+Urlencodes a string or array of strings.
+Requires either a single string or an array as an input.
+
+
+- *Type*: rvalue
+
+validate_absolute_path
+----------------------
+Validate the string represents an absolute path in the filesystem. This function works
+for windows and unix style paths.
+
+The following values will pass:
+
+ $my_path = "C:/Program Files (x86)/Puppet Labs/Puppet"
+ validate_absolute_path($my_path)
+ $my_path2 = "/var/lib/puppet"
+ validate_absolute_path($my_path2)
+
+
+The following values will fail, causing compilation to abort:
+
+ validate_absolute_path(true)
+ validate_absolute_path([ 'var/lib/puppet', '/var/foo' ])
+ validate_absolute_path([ '/var/lib/puppet', 'var/foo' ])
+ $undefined = undef
+ validate_absolute_path($undefined)
+
+
+
+- *Type*: statement
+
+validate_array
+--------------
+Validate that all passed values are array data structures. Abort catalog
+compilation if any value fails this check.
+
+The following values will pass:
+
+ $my_array = [ 'one', 'two' ]
+ validate_array($my_array)
+
+The following values will fail, causing compilation to abort:
+
+ validate_array(true)
+ validate_array('some_string')
+ $undefined = undef
+ validate_array($undefined)
+
+
+
+- *Type*: statement
+
+validate_augeas
+---------------
+Perform validation of a string using an Augeas lens
+The first argument of this function should be a string to
+test, and the second argument should be the name of the Augeas lens to use.
+If Augeas fails to parse the string with the lens, the compilation will
+abort with a parse error.
+
+A third argument can be specified, listing paths which should
+not be found in the file. The `$file` variable points to the location
+of the temporary file being tested in the Augeas tree.
+
+For example, if you want to make sure your passwd content never contains
+a user `foo`, you could write:
+
+ validate_augeas($passwdcontent, 'Passwd.lns', ['$file/foo'])
+
+Or if you wanted to ensure that no users used the '/bin/barsh' shell,
+you could use:
+
+ validate_augeas($passwdcontent, 'Passwd.lns', ['$file/*[shell="/bin/barsh"]']
+
+If a fourth argument is specified, this will be the error message raised and
+seen by the user.
+
+A helpful error message can be returned like this:
+
+ validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers content with Augeas')
+
+
+
+- *Type*: statement
+
+validate_bool
+-------------
+Validate that all passed values are either true or false. Abort catalog
+compilation if any value fails this check.
+
+The following values will pass:
+
+ $iamtrue = true
+ validate_bool(true)
+ validate_bool(true, true, false, $iamtrue)
+
+The following values will fail, causing compilation to abort:
+
+ $some_array = [ true ]
+ validate_bool("false")
+ validate_bool("true")
+ validate_bool($some_array)
+
+
+
+- *Type*: statement
+
+validate_cmd
+------------
+Perform validation of a string with an external command.
+The first argument of this function should be a string to
+test, and the second argument should be a path to a test command
+taking a file as last argument. If the command, launched against
+a tempfile containing the passed string, returns a non-null value,
+compilation will abort with a parse error.
+
+If a third argument is specified, this will be the error message raised and
+seen by the user.
+
+A helpful error message can be returned like this:
+
+Example:
+
+ validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content')
+
+
+
+- *Type*: statement
+
+validate_hash
+-------------
+Validate that all passed values are hash data structures. Abort catalog
+compilation if any value fails this check.
+
+The following values will pass:
+
+ $my_hash = { 'one' => 'two' }
+ validate_hash($my_hash)
+
+The following values will fail, causing compilation to abort:
+
+ validate_hash(true)
+ validate_hash('some_string')
+ $undefined = undef
+ validate_hash($undefined)
+
+
+
+- *Type*: statement
+
+validate_re
+-----------
+Perform simple validation of a string against one or more regular
+expressions. The first argument of this function should be a string to
+test, and the second argument should be a stringified regular expression
+(without the // delimiters) or an array of regular expressions. If none
+of the regular expressions match the string passed in, compilation will
+abort with a parse error.
+
+If a third argument is specified, this will be the error message raised and
+seen by the user.
+
+The following strings will validate against the regular expressions:
+
+ validate_re('one', '^one$')
+ validate_re('one', [ '^one', '^two' ])
+
+The following strings will fail to validate, causing compilation to abort:
+
+ validate_re('one', [ '^two', '^three' ])
+
+A helpful error message can be returned like this:
+
+ validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7')
+
+
+
+- *Type*: statement
+
+validate_slength
+----------------
+Validate that the first argument is a string (or an array of strings), and
+less/equal to than the length of the second argument. It fails if the first
+argument is not a string or array of strings, and if arg 2 is not convertable
+to a number.
+
+The following values will pass:
+
+ validate_slength("discombobulate",17)
+ validate_slength(["discombobulate","moo"],17)
+
+The following valueis will not:
+
+ validate_slength("discombobulate",1)
+ validate_slength(["discombobulate","thermometer"],5)
+
+
+
+- *Type*: statement
+
+validate_string
+---------------
+Validate that all passed values are string data structures. Abort catalog
+compilation if any value fails this check.
+
+The following values will pass:
+
+ $my_string = "one two"
+ validate_string($my_string, 'three')
+
+The following values will fail, causing compilation to abort:
+
+ validate_string(true)
+ validate_string([ 'some', 'array' ])
+ $undefined = undef
+ validate_string($undefined)
+
+
+- *Type*: statement
+
+values
+------
+When given a hash this function will return the values of that hash.
+
+*Examples:*
+
+ $hash = {
+ 'a' => 1,
+ 'b' => 2,
+ 'c' => 3,
+ }
+ values($hash)
+
+This example would return:
+
+ [1,2,3]
+
+
+- *Type*: rvalue
+
+values_at
+---------
+Finds value inside an array based on location.
+
+The first argument is the array you want to analyze, and the second element can
+be a combination of:
+
+* A single numeric index
+* A range in the form of 'start-stop' (eg. 4-9)
+* An array combining the above
+
+*Examples*:
+
+ values_at(['a','b','c'], 2)
+
+Would return ['c'].
+
+ values_at(['a','b','c'], ["0-1"])
+
+Would return ['a','b'].
+
+ values_at(['a','b','c','d','e'], [0, "2-3"])
+
+Would return ['a','c','d'].
+
+
+- *Type*: rvalue
+
+zip
+---
+Takes one element from first array and merges corresponding elements from second array. This generates a sequence of n-element arrays, where n is one more than the count of arguments.
+
+*Example:*
+
+ zip(['1','2','3'],['4','5','6'])
+
+Would result in:
+
+ ["1", "4"], ["2", "5"], ["3", "6"]
+
+
+- *Type*: rvalue
+
+*This page autogenerated on 2013-04-11 13:54:25 -0700*
diff --git a/puppet/stdlib/README_DEVELOPER.markdown b/puppet/stdlib/README_DEVELOPER.markdown
new file mode 100644
index 0000000000..04349ed79b
--- /dev/null
+++ b/puppet/stdlib/README_DEVELOPER.markdown
@@ -0,0 +1,35 @@
+Puppet Specific Facts
+=====================
+
+Facter is meant to stand alone and apart from Puppet. However, Facter often
+runs inside Puppet and all custom facts included in the stdlib module will
+almost always be evaluated in the context of Puppet and Facter working
+together.
+
+Still, we don't want to write custom facts that blow up in the users face if
+Puppet is not loaded in memory. This is often the case if the user runs
+`facter` without also supplying the `--puppet` flag.
+
+Ah! But Jeff, the custom fact won't be in the `$LOAD_PATH` unless the user
+supplies `--facter`! You might say...
+
+Not (always) true I say! If the user happens to have a CWD of
+`/stdlib/lib` then the facts will automatically be evaluated and
+blow up.
+
+In any event, it's pretty easy to write a fact that has no value if Puppet is
+not loaded. Simply do it like this:
+
+ Facter.add(:node_vardir) do
+ setcode do
+ # This will be nil if Puppet is not available.
+ Facter::Util::PuppetSettings.with_puppet do
+ Puppet[:vardir]
+ end
+ end
+ end
+
+The `Facter::Util::PuppetSettings.with_puppet` method accepts a block and
+yields to it only if the Puppet library is loaded. If the Puppet library is
+not loaded, then the method silently returns `nil` which Facter interprets as
+an undefined fact value. The net effect is that the fact won't be set.
diff --git a/puppet/stdlib/README_SPECS.markdown b/puppet/stdlib/README_SPECS.markdown
new file mode 100644
index 0000000000..917b6310dd
--- /dev/null
+++ b/puppet/stdlib/README_SPECS.markdown
@@ -0,0 +1,7 @@
+NOTE
+====
+
+This project's specs depend on puppet core, and thus they require the
+`puppetlabs_spec_helper` project. For more information please see the README
+in that project, which can be found here: [puppetlabs spec
+helper](https://github.com/puppetlabs/puppetlabs_spec_helper)
diff --git a/puppet/stdlib/RELEASE_PROCESS.markdown b/puppet/stdlib/RELEASE_PROCESS.markdown
new file mode 100644
index 0000000000..0f9328ed0f
--- /dev/null
+++ b/puppet/stdlib/RELEASE_PROCESS.markdown
@@ -0,0 +1,24 @@
+# Contributing to this module #
+
+ * Work in a topic branch
+ * Submit a github pull request
+ * Address any comments / feeback
+ * Merge into master using --no-ff
+
+# Releasing this module #
+
+ * This module adheres to http://semver.org/
+ * Look for API breaking changes using git diff vX.Y.Z..master
+ * If no API breaking changes, the minor version may be bumped.
+ * If there are API breaking changes, the major version must be bumped.
+ * If there are only small minor changes, the patch version may be bumped.
+ * Update the CHANGELOG
+ * Update the Modulefile
+ * Commit these changes with a message along the lines of "Update CHANGELOG and
+ Modulefile for release"
+ * Create an annotated tag with git tag -a vX.Y.Z -m 'version X.Y.Z' (NOTE the
+ leading v as per semver.org)
+ * Push the tag with git push origin --tags
+ * Build a new package with puppet-module or the rake build task if it exists
+ * Publish the new package to the forge
+ * Bonus points for an announcement to puppet-users.
diff --git a/puppet/stdlib/Rakefile b/puppet/stdlib/Rakefile
new file mode 100644
index 0000000000..14f1c24622
--- /dev/null
+++ b/puppet/stdlib/Rakefile
@@ -0,0 +1,2 @@
+require 'rubygems'
+require 'puppetlabs_spec_helper/rake_tasks'
diff --git a/puppet/stdlib/lib/facter/facter_dot_d.rb b/puppet/stdlib/lib/facter/facter_dot_d.rb
new file mode 100644
index 0000000000..e414b2077d
--- /dev/null
+++ b/puppet/stdlib/lib/facter/facter_dot_d.rb
@@ -0,0 +1,202 @@
+# A Facter plugin that loads facts from /etc/facter/facts.d
+# and /etc/puppetlabs/facter/facts.d.
+#
+# Facts can be in the form of JSON, YAML or Text files
+# and any executable that returns key=value pairs.
+#
+# In the case of scripts you can also create a file that
+# contains a cache TTL. For foo.sh store the ttl as just
+# a number in foo.sh.ttl
+#
+# The cache is stored in /tmp/facts_cache.yaml as a mode
+# 600 file and will have the end result of not calling your
+# fact scripts more often than is needed
+
+class Facter::Util::DotD
+ require 'yaml'
+
+ def initialize(dir="/etc/facts.d", cache_file="/tmp/facts_cache.yml")
+ @dir = dir
+ @cache_file = cache_file
+ @cache = nil
+ @types = {".txt" => :txt, ".json" => :json, ".yaml" => :yaml}
+ end
+
+ def entries
+ Dir.entries(@dir).reject{|f| f =~ /^\.|\.ttl$/}.sort.map {|f| File.join(@dir, f) }
+ rescue
+ []
+ end
+
+ def fact_type(file)
+ extension = File.extname(file)
+
+ type = @types[extension] || :unknown
+
+ type = :script if type == :unknown && File.executable?(file)
+
+ return type
+ end
+
+ def txt_parser(file)
+ File.readlines(file).each do |line|
+ if line =~ /^(.+)=(.+)$/
+ var = $1; val = $2
+
+ Facter.add(var) do
+ setcode { val }
+ end
+ end
+ end
+ rescue Exception => e
+ Facter.warn("Failed to handle #{file} as text facts: #{e.class}: #{e}")
+ end
+
+ def json_parser(file)
+ begin
+ require 'json'
+ rescue LoadError
+ retry if require 'rubygems'
+ raise
+ end
+
+ JSON.load(File.read(file)).each_pair do |f, v|
+ Facter.add(f) do
+ setcode { v }
+ end
+ end
+ rescue Exception => e
+ Facter.warn("Failed to handle #{file} as json facts: #{e.class}: #{e}")
+ end
+
+ def yaml_parser(file)
+ require 'yaml'
+
+ YAML.load_file(file).each_pair do |f, v|
+ Facter.add(f) do
+ setcode { v }
+ end
+ end
+ rescue Exception => e
+ Facter.warn("Failed to handle #{file} as yaml facts: #{e.class}: #{e}")
+ end
+
+ def script_parser(file)
+ result = cache_lookup(file)
+ ttl = cache_time(file)
+
+ unless result
+ result = Facter::Util::Resolution.exec(file)
+
+ if ttl > 0
+ Facter.debug("Updating cache for #{file}")
+ cache_store(file, result)
+ cache_save!
+ end
+ else
+ Facter.debug("Using cached data for #{file}")
+ end
+
+ result.split("\n").each do |line|
+ if line =~ /^(.+)=(.+)$/
+ var = $1; val = $2
+
+ Facter.add(var) do
+ setcode { val }
+ end
+ end
+ end
+ rescue Exception => e
+ Facter.warn("Failed to handle #{file} as script facts: #{e.class}: #{e}")
+ Facter.debug(e.backtrace.join("\n\t"))
+ end
+
+ def cache_save!
+ cache = load_cache
+ File.open(@cache_file, "w", 0600) {|f| f.write(YAML.dump(cache)) }
+ rescue
+ end
+
+ def cache_store(file, data)
+ load_cache
+
+ @cache[file] = {:data => data, :stored => Time.now.to_i}
+ rescue
+ end
+
+ def cache_lookup(file)
+ cache = load_cache
+
+ return nil if cache.empty?
+
+ ttl = cache_time(file)
+
+ if cache[file]
+ now = Time.now.to_i
+
+ return cache[file][:data] if ttl == -1
+ return cache[file][:data] if (now - cache[file][:stored]) <= ttl
+ return nil
+ else
+ return nil
+ end
+ rescue
+ return nil
+ end
+
+ def cache_time(file)
+ meta = file + ".ttl"
+
+ return File.read(meta).chomp.to_i
+ rescue
+ return 0
+ end
+
+ def load_cache
+ unless @cache
+ if File.exist?(@cache_file)
+ @cache = YAML.load_file(@cache_file)
+ else
+ @cache = {}
+ end
+ end
+
+ return @cache
+ rescue
+ @cache = {}
+ return @cache
+ end
+
+ def create
+ entries.each do |fact|
+ type = fact_type(fact)
+ parser = "#{type}_parser"
+
+ if respond_to?("#{type}_parser")
+ Facter.debug("Parsing #{fact} using #{parser}")
+
+ send(parser, fact)
+ end
+ end
+ end
+end
+
+
+mdata = Facter.version.match(/(\d+)\.(\d+)\.(\d+)/)
+if mdata
+ (major, minor, patch) = mdata.captures.map { |v| v.to_i }
+ if major < 2
+ # Facter 1.7 introduced external facts support directly
+ unless major == 1 and minor > 6
+ Facter::Util::DotD.new("/etc/facter/facts.d").create
+ Facter::Util::DotD.new("/etc/puppetlabs/facter/facts.d").create
+
+ # Windows has a different configuration directory that defaults to a vendor
+ # specific sub directory of the %COMMON_APPDATA% directory.
+ if Dir.const_defined? 'COMMON_APPDATA' then
+ windows_facts_dot_d = File.join(Dir::COMMON_APPDATA, 'PuppetLabs', 'facter', 'facts.d')
+ Facter::Util::DotD.new(windows_facts_dot_d).create
+ end
+ end
+ end
+end
diff --git a/puppet/stdlib/lib/facter/pe_version.rb b/puppet/stdlib/lib/facter/pe_version.rb
new file mode 100644
index 0000000000..0cc0f64e95
--- /dev/null
+++ b/puppet/stdlib/lib/facter/pe_version.rb
@@ -0,0 +1,53 @@
+# Fact: is_pe, pe_version, pe_major_version, pe_minor_version, pe_patch_version
+#
+# Purpose: Return various facts about the PE state of the system
+#
+# Resolution: Uses a regex match against puppetversion to determine whether the
+# machine has Puppet Enterprise installed, and what version (overall, major,
+# minor, patch) is installed.
+#
+# Caveats:
+#
+Facter.add("pe_version") do
+ setcode do
+ pe_ver = Facter.value("puppetversion").match(/Puppet Enterprise (\d+\.\d+\.\d+)/)
+ pe_ver[1] if pe_ver
+ end
+end
+
+Facter.add("is_pe") do
+ setcode do
+ if Facter.value(:pe_version).to_s.empty? then
+ false
+ else
+ true
+ end
+ end
+end
+
+Facter.add("pe_major_version") do
+ confine :is_pe => true
+ setcode do
+ if pe_version = Facter.value(:pe_version)
+ pe_version.to_s.split('.')[0]
+ end
+ end
+end
+
+Facter.add("pe_minor_version") do
+ confine :is_pe => true
+ setcode do
+ if pe_version = Facter.value(:pe_version)
+ pe_version.to_s.split('.')[1]
+ end
+ end
+end
+
+Facter.add("pe_patch_version") do
+ confine :is_pe => true
+ setcode do
+ if pe_version = Facter.value(:pe_version)
+ pe_version.to_s.split('.')[2]
+ end
+ end
+end
diff --git a/puppet/stdlib/lib/facter/puppet_vardir.rb b/puppet/stdlib/lib/facter/puppet_vardir.rb
new file mode 100644
index 0000000000..0e6af40e49
--- /dev/null
+++ b/puppet/stdlib/lib/facter/puppet_vardir.rb
@@ -0,0 +1,26 @@
+# This facter fact returns the value of the Puppet vardir setting for the node
+# running puppet or puppet agent. The intent is to enable Puppet modules to
+# automatically have insight into a place where they can place variable data,
+# regardless of the node's platform.
+#
+# The value should be directly usable in a File resource path attribute.
+
+
+begin
+ require 'facter/util/puppet_settings'
+rescue LoadError => e
+ # puppet apply does not add module lib directories to the $LOAD_PATH (See
+ # #4248). It should (in the future) but for the time being we need to be
+ # defensive which is what this rescue block is doing.
+ rb_file = File.join(File.dirname(__FILE__), 'util', 'puppet_settings.rb')
+ load rb_file if File.exists?(rb_file) or raise e
+end
+
+Facter.add(:puppet_vardir) do
+ setcode do
+ # This will be nil if Puppet is not available.
+ Facter::Util::PuppetSettings.with_puppet do
+ Puppet[:vardir]
+ end
+ end
+end
diff --git a/puppet/stdlib/lib/facter/root_home.rb b/puppet/stdlib/lib/facter/root_home.rb
new file mode 100644
index 0000000000..8249f7d025
--- /dev/null
+++ b/puppet/stdlib/lib/facter/root_home.rb
@@ -0,0 +1,19 @@
+# A facter fact to determine the root home directory.
+# This varies on PE supported platforms and may be
+# reconfigured by the end user.
+
+module Facter::Util::RootHome
+ class << self
+ def get_root_home
+ root_ent = Facter::Util::Resolution.exec("getent passwd root")
+ # The home directory is the sixth element in the passwd entry
+ # If the platform doesn't have getent, root_ent will be nil and we should
+ # return it straight away.
+ root_ent && root_ent.split(":")[5]
+ end
+ end
+end
+
+Facter.add(:root_home) do
+ setcode { Facter::Util::RootHome.get_root_home }
+end
diff --git a/puppet/stdlib/lib/facter/util/puppet_settings.rb b/puppet/stdlib/lib/facter/util/puppet_settings.rb
new file mode 100644
index 0000000000..1ad945218a
--- /dev/null
+++ b/puppet/stdlib/lib/facter/util/puppet_settings.rb
@@ -0,0 +1,21 @@
+module Facter
+ module Util
+ module PuppetSettings
+ # This method is intended to provide a convenient way to evaluate a
+ # Facter code block only if Puppet is loaded. This is to account for the
+ # situation where the fact happens to be in the load path, but Puppet is
+ # not loaded for whatever reason. Perhaps the user is simply running
+ # facter without the --puppet flag and they happen to be working in a lib
+ # directory of a module.
+ def self.with_puppet
+ begin
+ Module.const_get("Puppet")
+ rescue NameError
+ nil
+ else
+ yield
+ end
+ end
+ end
+ end
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/abs.rb b/puppet/stdlib/lib/puppet/parser/functions/abs.rb
new file mode 100644
index 0000000000..11d2d7fead
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/abs.rb
@@ -0,0 +1,36 @@
+#
+# abs.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:abs, :type => :rvalue, :doc => <<-EOS
+ Returns the absolute value of a number, for example -34.56 becomes
+ 34.56. Takes a single integer and float value as an argument.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "abs(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ if value.is_a?(String)
+ if value.match(/^-?(?:\d+)(?:\.\d+){1}$/)
+ value = value.to_f
+ elsif value.match(/^-?\d+$/)
+ value = value.to_i
+ else
+ raise(Puppet::ParseError, 'abs(): Requires float or ' +
+ 'integer to work with')
+ end
+ end
+
+ # We have numeric value to handle ...
+ result = value.abs
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/any2array.rb b/puppet/stdlib/lib/puppet/parser/functions/any2array.rb
new file mode 100644
index 0000000000..e71407e89e
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/any2array.rb
@@ -0,0 +1,33 @@
+#
+# any2array.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:any2array, :type => :rvalue, :doc => <<-EOS
+This converts any object to an array containing that object. Empty argument
+lists are converted to an empty array. Arrays are left untouched. Hashes are
+converted to arrays of alternating keys and values.
+ EOS
+ ) do |arguments|
+
+ if arguments.empty?
+ return []
+ end
+
+ if arguments.length == 1
+ if arguments[0].kind_of?(Array)
+ return arguments[0]
+ elsif arguments[0].kind_of?(Hash)
+ result = []
+ arguments[0].each do |key, value|
+ result << key << value
+ end
+ return result
+ end
+ end
+
+ return arguments
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/bool2num.rb b/puppet/stdlib/lib/puppet/parser/functions/bool2num.rb
new file mode 100644
index 0000000000..9a07a8a119
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/bool2num.rb
@@ -0,0 +1,49 @@
+#
+# bool2num.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:bool2num, :type => :rvalue, :doc => <<-EOS
+ Converts a boolean to a number. Converts the values:
+ false, f, 0, n, and no to 0
+ true, t, 1, y, and yes to 1
+ Requires a single boolean or string as an input.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "bool2num(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ # We can have either true or false, or string which resembles boolean ...
+ unless [FalseClass, TrueClass, String].include?(klass)
+ raise(Puppet::ParseError, 'bool2num(): Requires either ' +
+ 'boolean or string to work with')
+ end
+
+ if value.is_a?(String)
+ # We consider all the yes, no, y, n and so on too ...
+ value = case value
+ #
+ # This is how undef looks like in Puppet ...
+ # We yield 0 (or false if you wish) in this case.
+ #
+ when /^$/, '' then false # Empty string will be false ...
+ when /^(1|t|y|true|yes)$/ then true
+ when /^(0|f|n|false|no)$/ then false
+ when /^(undef|undefined)$/ then false # This is not likely to happen ...
+ else
+ raise(Puppet::ParseError, 'bool2num(): Unknown type of boolean given')
+ end
+ end
+
+ # We have real boolean values as well ...
+ result = value ? 1 : 0
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/capitalize.rb b/puppet/stdlib/lib/puppet/parser/functions/capitalize.rb
new file mode 100644
index 0000000000..640d00b82f
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/capitalize.rb
@@ -0,0 +1,34 @@
+#
+# capitalize.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:capitalize, :type => :rvalue, :doc => <<-EOS
+ Capitalizes the first letter of a string or array of strings.
+ Requires either a single string or an array as an input.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "capitalize(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'capitalize(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ result = value.collect { |i| i.is_a?(String) ? i.capitalize : i }
+ else
+ result = value.capitalize
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/chomp.rb b/puppet/stdlib/lib/puppet/parser/functions/chomp.rb
new file mode 100644
index 0000000000..4564a000ab
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/chomp.rb
@@ -0,0 +1,35 @@
+#
+# chomp.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:chomp, :type => :rvalue, :doc => <<-'EOS'
+ Removes the record separator from the end of a string or an array of
+ strings, for example `hello\n` becomes `hello`.
+ Requires a single string or array as an input.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "chomp(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'chomp(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ result = value.collect { |i| i.is_a?(String) ? i.chomp : i }
+ else
+ result = value.chomp
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/chop.rb b/puppet/stdlib/lib/puppet/parser/functions/chop.rb
new file mode 100644
index 0000000000..f242af39ce
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/chop.rb
@@ -0,0 +1,37 @@
+#
+# chop.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:chop, :type => :rvalue, :doc => <<-'EOS'
+ Returns a new string with the last character removed. If the string ends
+ with `\r\n`, both characters are removed. Applying chop to an empty
+ string returns an empty string. If you wish to merely remove record
+ separators then you should use the `chomp` function.
+ Requires a string or array of strings as input.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "chop(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'chop(): Requires either an ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ result = value.collect { |i| i.is_a?(String) ? i.chop : i }
+ else
+ result = value.chop
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/concat.rb b/puppet/stdlib/lib/puppet/parser/functions/concat.rb
new file mode 100644
index 0000000000..c86aa0057c
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/concat.rb
@@ -0,0 +1,37 @@
+#
+# concat.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:concat, :type => :rvalue, :doc => <<-EOS
+Appends the contents of array 2 onto array 1.
+
+*Example:*
+
+ concat(['1','2','3'],['4','5','6'])
+
+Would result in:
+
+ ['1','2','3','4','5','6']
+ EOS
+ ) do |arguments|
+
+ # Check that 2 arguments have been given ...
+ raise(Puppet::ParseError, "concat(): Wrong number of arguments " +
+ "given (#{arguments.size} for 2)") if arguments.size != 2
+
+ a = arguments[0]
+ b = arguments[1]
+
+ # Check that both args are arrays.
+ unless a.is_a?(Array) and b.is_a?(Array)
+ raise(Puppet::ParseError, 'concat(): Requires array to work with')
+ end
+
+ result = a.concat(b)
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/count.rb b/puppet/stdlib/lib/puppet/parser/functions/count.rb
new file mode 100644
index 0000000000..52de1b8a5a
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/count.rb
@@ -0,0 +1,22 @@
+module Puppet::Parser::Functions
+ newfunction(:count, :type => :rvalue, :arity => -2, :doc => <<-EOS
+Takes an array as first argument and an optional second argument.
+Count the number of elements in array that matches second argument.
+If called with only an array it counts the number of elements that are not nil/undef.
+ EOS
+ ) do |args|
+
+ if (args.size > 2) then
+ raise(ArgumentError, "count(): Wrong number of arguments "+
+ "given #{args.size} for 1 or 2.")
+ end
+
+ collection, item = args
+
+ if item then
+ collection.count item
+ else
+ collection.count { |obj| obj != nil && obj != :undef && obj != '' }
+ end
+ end
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/defined_with_params.rb b/puppet/stdlib/lib/puppet/parser/functions/defined_with_params.rb
new file mode 100644
index 0000000000..d7df306c79
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/defined_with_params.rb
@@ -0,0 +1,35 @@
+# Test whether a given class or definition is defined
+require 'puppet/parser/functions'
+
+Puppet::Parser::Functions.newfunction(:defined_with_params,
+ :type => :rvalue,
+ :doc => <<-'ENDOFDOC'
+Takes a resource reference and an optional hash of attributes.
+
+Returns true if a resource with the specified attributes has already been added
+to the catalog, and false otherwise.
+
+ user { 'dan':
+ ensure => present,
+ }
+
+ if ! defined_with_params(User[dan], {'ensure' => 'present' }) {
+ user { 'dan': ensure => present, }
+ }
+ENDOFDOC
+) do |vals|
+ reference, params = vals
+ raise(ArgumentError, 'Must specify a reference') unless reference
+ if (! params) || params == ''
+ params = {}
+ end
+ ret = false
+ if resource = findresource(reference.to_s)
+ matches = params.collect do |key, value|
+ resource[key] == value
+ end
+ ret = params.empty? || !matches.include?(false)
+ end
+ Puppet.debug("Resource #{reference} was not determined to be defined")
+ ret
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/delete.rb b/puppet/stdlib/lib/puppet/parser/functions/delete.rb
new file mode 100644
index 0000000000..f81434409c
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/delete.rb
@@ -0,0 +1,46 @@
+#
+# delete.rb
+#
+
+# TODO(Krzysztof Wilczynski): We need to add support for regular expression ...
+
+module Puppet::Parser::Functions
+ newfunction(:delete, :type => :rvalue, :doc => <<-EOS
+Deletes all instances of a given element from an array, substring from a
+string, or key from a hash.
+
+*Examples:*
+
+ delete(['a','b','c','b'], 'b')
+ Would return: ['a','c']
+
+ delete({'a'=>1,'b'=>2,'c'=>3}, 'b')
+ Would return: {'a'=>1,'c'=>3}
+
+ delete('abracadabra', 'bra')
+ Would return: 'acada'
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 2) then
+ raise(Puppet::ParseError, "delete(): Wrong number of arguments "+
+ "given #{arguments.size} for 2.")
+ end
+
+ collection = arguments[0]
+ item = arguments[1]
+
+ case collection
+ when Array, Hash
+ collection.delete item
+ when String
+ collection.gsub! item, ''
+ else
+ raise(TypeError, "delete(): First argument must be an Array, " +
+ "String, or Hash. Given an argument of class #{collection.class}.")
+ end
+ collection
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/delete_at.rb b/puppet/stdlib/lib/puppet/parser/functions/delete_at.rb
new file mode 100644
index 0000000000..3eb4b53756
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/delete_at.rb
@@ -0,0 +1,49 @@
+#
+# delete_at.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:delete_at, :type => :rvalue, :doc => <<-EOS
+Deletes a determined indexed value from an array.
+
+*Examples:*
+
+ delete_at(['a','b','c'], 1)
+
+Would return: ['a','c']
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "delete_at(): Wrong number of arguments " +
+ "given (#{arguments.size} for 2)") if arguments.size < 2
+
+ array = arguments[0]
+
+ unless array.is_a?(Array)
+ raise(Puppet::ParseError, 'delete_at(): Requires array to work with')
+ end
+
+ index = arguments[1]
+
+ if index.is_a?(String) and not index.match(/^\d+$/)
+ raise(Puppet::ParseError, 'delete_at(): You must provide ' +
+ 'non-negative numeric index')
+ end
+
+ result = array.clone
+
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ index = index.to_i
+
+ if index > result.size - 1 # First element is at index 0 is it not?
+ raise(Puppet::ParseError, 'delete_at(): Given index ' +
+ 'exceeds size of array given')
+ end
+
+ result.delete_at(index) # We ignore the element that got deleted ...
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/dirname.rb b/puppet/stdlib/lib/puppet/parser/functions/dirname.rb
new file mode 100644
index 0000000000..ea8cc1e081
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/dirname.rb
@@ -0,0 +1,15 @@
+module Puppet::Parser::Functions
+ newfunction(:dirname, :type => :rvalue, :doc => <<-EOS
+ Returns the dirname of a path.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "dirname(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ path = arguments[0]
+ return File.dirname(path)
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/downcase.rb b/puppet/stdlib/lib/puppet/parser/functions/downcase.rb
new file mode 100644
index 0000000000..4066d210f7
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/downcase.rb
@@ -0,0 +1,33 @@
+#
+# downcase.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:downcase, :type => :rvalue, :doc => <<-EOS
+Converts the case of a string or all strings in an array to lower case.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "downcase(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'downcase(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ result = value.collect { |i| i.is_a?(String) ? i.downcase : i }
+ else
+ result = value.downcase
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/empty.rb b/puppet/stdlib/lib/puppet/parser/functions/empty.rb
new file mode 100644
index 0000000000..80ebb86b89
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/empty.rb
@@ -0,0 +1,28 @@
+#
+# empty.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:empty, :type => :rvalue, :doc => <<-EOS
+Returns true if the variable is empty.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "empty(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, Hash, String].include?(klass)
+ raise(Puppet::ParseError, 'empty(): Requires either ' +
+ 'array, hash or string to work with')
+ end
+
+ result = value.empty?
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/ensure_packages.rb b/puppet/stdlib/lib/puppet/parser/functions/ensure_packages.rb
new file mode 100644
index 0000000000..450ea026d1
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/ensure_packages.rb
@@ -0,0 +1,24 @@
+#
+# ensure_packages.rb
+#
+require 'puppet/parser/functions'
+
+module Puppet::Parser::Functions
+ newfunction(:ensure_packages, :type => :statement, :doc => <<-EOS
+Takes a list of packages and only installs them if they don't already exist.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size != 1
+ raise(Puppet::ParseError, "ensure_packages(): Requires array " +
+ "given (#{arguments[0].class})") if !arguments[0].kind_of?(Array)
+
+ Puppet::Parser::Functions.function(:ensure_resource)
+ arguments[0].each { |package_name|
+ function_ensure_resource(['package', package_name, {'ensure' => 'present' } ])
+ }
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/ensure_resource.rb b/puppet/stdlib/lib/puppet/parser/functions/ensure_resource.rb
new file mode 100644
index 0000000000..a9a17338e0
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/ensure_resource.rb
@@ -0,0 +1,45 @@
+# Test whether a given class or definition is defined
+require 'puppet/parser/functions'
+
+Puppet::Parser::Functions.newfunction(:ensure_resource,
+ :type => :statement,
+ :doc => <<-'ENDOFDOC'
+Takes a resource type, title, and a list of attributes that describe a
+resource.
+
+ user { 'dan':
+ ensure => present,
+ }
+
+This example only creates the resource if it does not already exist:
+
+ ensure_resource('user, 'dan', {'ensure' => 'present' })
+
+If the resource already exists but does not match the specified parameters,
+this function will attempt to recreate the resource leading to a duplicate
+resource definition error.
+
+An array of resources can also be passed in and each will be created with
+the type and parameters specified if it doesn't already exist.
+
+ ensure_resource('user', ['dan','alex'], {'ensure' => 'present'})
+
+ENDOFDOC
+) do |vals|
+ type, title, params = vals
+ raise(ArgumentError, 'Must specify a type') unless type
+ raise(ArgumentError, 'Must specify a title') unless title
+ params ||= {}
+
+ items = [title].flatten
+
+ items.each do |item|
+ Puppet::Parser::Functions.function(:defined_with_params)
+ if function_defined_with_params(["#{type}[#{item}]", params])
+ Puppet.debug("Resource #{type}[#{item}] not created because it already exists")
+ else
+ Puppet::Parser::Functions.function(:create_resources)
+ function_create_resources([type.capitalize, { item => params }])
+ end
+ end
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/flatten.rb b/puppet/stdlib/lib/puppet/parser/functions/flatten.rb
new file mode 100644
index 0000000000..a1ed183290
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/flatten.rb
@@ -0,0 +1,33 @@
+#
+# flatten.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:flatten, :type => :rvalue, :doc => <<-EOS
+This function flattens any deeply nested arrays and returns a single flat array
+as a result.
+
+*Examples:*
+
+ flatten(['a', ['b', ['c']]])
+
+Would return: ['a','b','c']
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "flatten(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size != 1
+
+ array = arguments[0]
+
+ unless array.is_a?(Array)
+ raise(Puppet::ParseError, 'flatten(): Requires array to work with')
+ end
+
+ result = array.flatten
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/floor.rb b/puppet/stdlib/lib/puppet/parser/functions/floor.rb
new file mode 100644
index 0000000000..a401923499
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/floor.rb
@@ -0,0 +1,20 @@
+module Puppet::Parser::Functions
+ newfunction(:floor, :type => :rvalue, :doc => <<-EOS
+ Returns the largest integer less or equal to the argument.
+ Takes a single numeric value as an argument.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "floor(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size != 1
+
+ arg = arguments[0]
+
+ raise(Puppet::ParseError, "floor(): Wrong argument type " +
+ "given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false
+
+ arg.floor
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb b/puppet/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb
new file mode 100644
index 0000000000..6558206055
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb
@@ -0,0 +1,46 @@
+#
+# fqdn_rotate.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:fqdn_rotate, :type => :rvalue, :doc => <<-EOS
+Rotates an array a random number of times based on a nodes fqdn.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "fqdn_rotate(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+ require 'digest/md5'
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'fqdn_rotate(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ result = value.clone
+
+ string = value.is_a?(String) ? true : false
+
+ # Check whether it makes sense to rotate ...
+ return result if result.size <= 1
+
+ # We turn any string value into an array to be able to rotate ...
+ result = string ? result.split('') : result
+
+ elements = result.size
+
+ srand(Digest::MD5.hexdigest([lookupvar('::fqdn'),arguments].join(':')).hex)
+ rand(elements).times {
+ result.push result.shift
+ }
+
+ result = string ? result.join : result
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/get_module_path.rb b/puppet/stdlib/lib/puppet/parser/functions/get_module_path.rb
new file mode 100644
index 0000000000..1421b91f52
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/get_module_path.rb
@@ -0,0 +1,17 @@
+module Puppet::Parser::Functions
+ newfunction(:get_module_path, :type =>:rvalue, :doc => <<-EOT
+ Returns the absolute path of the specified module for the current
+ environment.
+
+ Example:
+ $module_path = get_module_path('stdlib')
+ EOT
+ ) do |args|
+ raise(Puppet::ParseError, "get_module_path(): Wrong number of arguments, expects one") unless args.size == 1
+ if module_path = Puppet::Module.find(args[0], compiler.environment.to_s)
+ module_path.path
+ else
+ raise(Puppet::ParseError, "Could not find module #{args[0]} in environment #{compiler.environment}")
+ end
+ end
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/getparam.rb b/puppet/stdlib/lib/puppet/parser/functions/getparam.rb
new file mode 100644
index 0000000000..6d510069f9
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/getparam.rb
@@ -0,0 +1,35 @@
+# Test whether a given class or definition is defined
+require 'puppet/parser/functions'
+
+Puppet::Parser::Functions.newfunction(:getparam,
+ :type => :rvalue,
+ :doc => <<-'ENDOFDOC'
+Takes a resource reference and name of the parameter and
+returns value of resource's parameter.
+
+*Examples:*
+
+ define example_resource($param) {
+ }
+
+ example_resource { "example_resource_instance":
+ param => "param_value"
+ }
+
+ getparam(Example_resource["example_resource_instance"], "param")
+
+Would return: param_value
+ENDOFDOC
+) do |vals|
+ reference, param = vals
+ raise(ArgumentError, 'Must specify a reference') unless reference
+ raise(ArgumentError, 'Must specify name of a parameter') unless param and param.instance_of? String
+
+ return '' if param.empty?
+
+ if resource = findresource(reference.to_s)
+ return resource[param] if resource[param]
+ end
+
+ return ''
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/getvar.rb b/puppet/stdlib/lib/puppet/parser/functions/getvar.rb
new file mode 100644
index 0000000000..162114995b
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/getvar.rb
@@ -0,0 +1,26 @@
+module Puppet::Parser::Functions
+
+ newfunction(:getvar, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
+ Lookup a variable in a remote namespace.
+
+ For example:
+
+ $foo = getvar('site::data::foo')
+ # Equivalent to $foo = $site::data::foo
+
+ This is useful if the namespace itself is stored in a string:
+
+ $datalocation = 'site::data'
+ $bar = getvar("${datalocation}::bar")
+ # Equivalent to $bar = $site::data::bar
+ ENDHEREDOC
+
+ unless args.length == 1
+ raise Puppet::ParseError, ("getvar(): wrong number of arguments (#{args.length}; must be 1)")
+ end
+
+ self.lookupvar("#{args[0]}")
+
+ end
+
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/grep.rb b/puppet/stdlib/lib/puppet/parser/functions/grep.rb
new file mode 100644
index 0000000000..ceba9ecc8f
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/grep.rb
@@ -0,0 +1,33 @@
+#
+# grep.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:grep, :type => :rvalue, :doc => <<-EOS
+This function searches through an array and returns any elements that match
+the provided regular expression.
+
+*Examples:*
+
+ grep(['aaa','bbb','ccc','aaaddd'], 'aaa')
+
+Would return:
+
+ ['aaa','aaaddd']
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 2) then
+ raise(Puppet::ParseError, "grep(): Wrong number of arguments "+
+ "given #{arguments.size} for 2")
+ end
+
+ a = arguments[0]
+ pattern = Regexp.new(arguments[1])
+
+ a.grep(pattern)
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/has_interface_with.rb b/puppet/stdlib/lib/puppet/parser/functions/has_interface_with.rb
new file mode 100644
index 0000000000..7f150a7176
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/has_interface_with.rb
@@ -0,0 +1,52 @@
+#
+# has_interface_with
+#
+
+module Puppet::Parser::Functions
+ newfunction(:has_interface_with, :type => :rvalue, :doc => <<-EOS
+Returns boolean based on kind and value:
+ * macaddress
+ * netmask
+ * ipaddress
+ * network
+
+has_interface_with("macaddress", "x:x:x:x:x:x")
+has_interface_with("ipaddress", "127.0.0.1") => true
+etc.
+
+If no "kind" is given, then the presence of the interface is checked:
+has_interface_with("lo") => true
+ EOS
+ ) do |args|
+
+ raise(Puppet::ParseError, "has_interface_with(): Wrong number of arguments " +
+ "given (#{args.size} for 1 or 2)") if args.size < 1 or args.size > 2
+
+ interfaces = lookupvar('interfaces')
+
+ # If we do not have any interfaces, then there are no requested attributes
+ return false if (interfaces == :undefined)
+
+ interfaces = interfaces.split(',')
+
+ if args.size == 1
+ return interfaces.member?(args[0])
+ end
+
+ kind, value = args
+
+ if lookupvar(kind) == value
+ return true
+ end
+
+ result = false
+ interfaces.each do |iface|
+ if value == lookupvar("#{kind}_#{iface}")
+ result = true
+ break
+ end
+ end
+
+ result
+ end
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/has_ip_address.rb b/puppet/stdlib/lib/puppet/parser/functions/has_ip_address.rb
new file mode 100644
index 0000000000..842c8ec674
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/has_ip_address.rb
@@ -0,0 +1,25 @@
+#
+# has_ip_address
+#
+
+module Puppet::Parser::Functions
+ newfunction(:has_ip_address, :type => :rvalue, :doc => <<-EOS
+Returns true if the client has the requested IP address on some interface.
+
+This function iterates through the 'interfaces' fact and checks the
+'ipaddress_IFACE' facts, performing a simple string comparison.
+ EOS
+ ) do |args|
+
+ raise(Puppet::ParseError, "has_ip_address(): Wrong number of arguments " +
+ "given (#{args.size} for 1)") if args.size != 1
+
+ Puppet::Parser::Functions.autoloader.load(:has_interface_with) \
+ unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with)
+
+ function_has_interface_with(['ipaddress', args[0]])
+
+ end
+end
+
+# vim:sts=2 sw=2
diff --git a/puppet/stdlib/lib/puppet/parser/functions/has_ip_network.rb b/puppet/stdlib/lib/puppet/parser/functions/has_ip_network.rb
new file mode 100644
index 0000000000..9ccf9024f7
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/has_ip_network.rb
@@ -0,0 +1,25 @@
+#
+# has_ip_network
+#
+
+module Puppet::Parser::Functions
+ newfunction(:has_ip_network, :type => :rvalue, :doc => <<-EOS
+Returns true if the client has an IP address within the requested network.
+
+This function iterates through the 'interfaces' fact and checks the
+'network_IFACE' facts, performing a simple string comparision.
+ EOS
+ ) do |args|
+
+ raise(Puppet::ParseError, "has_ip_network(): Wrong number of arguments " +
+ "given (#{args.size} for 1)") if args.size != 1
+
+ Puppet::Parser::Functions.autoloader.load(:has_interface_with) \
+ unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with)
+
+ function_has_interface_with(['network', args[0]])
+
+ end
+end
+
+# vim:sts=2 sw=2
diff --git a/puppet/stdlib/lib/puppet/parser/functions/has_key.rb b/puppet/stdlib/lib/puppet/parser/functions/has_key.rb
new file mode 100644
index 0000000000..4657cc29cd
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/has_key.rb
@@ -0,0 +1,28 @@
+module Puppet::Parser::Functions
+
+ newfunction(:has_key, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
+ Determine if a hash has a certain key value.
+
+ Example:
+
+ $my_hash = {'key_one' => 'value_one'}
+ if has_key($my_hash, 'key_two') {
+ notice('we will not reach here')
+ }
+ if has_key($my_hash, 'key_one') {
+ notice('this will be printed')
+ }
+
+ ENDHEREDOC
+
+ unless args.length == 2
+ raise Puppet::ParseError, ("has_key(): wrong number of arguments (#{args.length}; must be 2)")
+ end
+ unless args[0].is_a?(Hash)
+ raise Puppet::ParseError, "has_key(): expects the first argument to be a hash, got #{args[0].inspect} which is of type #{args[0].class}"
+ end
+ args[0].has_key?(args[1])
+
+ end
+
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/hash.rb b/puppet/stdlib/lib/puppet/parser/functions/hash.rb
new file mode 100644
index 0000000000..8cc4823be5
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/hash.rb
@@ -0,0 +1,41 @@
+#
+# hash.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:hash, :type => :rvalue, :doc => <<-EOS
+This function converts an array into a hash.
+
+*Examples:*
+
+ hash(['a',1,'b',2,'c',3])
+
+Would return: {'a'=>1,'b'=>2,'c'=>3}
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "hash(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ array = arguments[0]
+
+ unless array.is_a?(Array)
+ raise(Puppet::ParseError, 'hash(): Requires array to work with')
+ end
+
+ result = {}
+
+ begin
+ # This is to make it compatible with older version of Ruby ...
+ array = array.flatten
+ result = Hash[*array]
+ rescue Exception
+ raise(Puppet::ParseError, 'hash(): Unable to compute ' +
+ 'hash from array given')
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/is_array.rb b/puppet/stdlib/lib/puppet/parser/functions/is_array.rb
new file mode 100644
index 0000000000..b39e184ae5
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/is_array.rb
@@ -0,0 +1,22 @@
+#
+# is_array.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_array, :type => :rvalue, :doc => <<-EOS
+Returns true if the variable passed to this function is an array.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "is_array(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ type = arguments[0]
+
+ result = type.is_a?(Array)
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/is_domain_name.rb b/puppet/stdlib/lib/puppet/parser/functions/is_domain_name.rb
new file mode 100644
index 0000000000..5826dc0d9a
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/is_domain_name.rb
@@ -0,0 +1,47 @@
+#
+# is_domain_name.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_domain_name, :type => :rvalue, :doc => <<-EOS
+Returns true if the string passed to this function is a syntactically correct domain name.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_domain_name(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ domain = arguments[0]
+
+ # Limits (rfc1035, 3.1)
+ domain_max_length=255
+ label_min_length=1
+ label_max_length=63
+
+ # Allow ".", it is the top level domain
+ return true if domain == '.'
+
+ # Remove the final dot, if present.
+ domain.chomp!('.')
+
+ # Check the whole domain
+ return false if domain.empty?
+ return false if domain.length > domain_max_length
+
+ # Check each label in the domain
+ labels = domain.split('.')
+ vlabels = labels.each do |label|
+ break if label.length < label_min_length
+ break if label.length > label_max_length
+ break if label[-1..-1] == '-'
+ break if label[0..0] == '-'
+ break unless /^[a-z\d-]+$/i.match(label)
+ end
+ return vlabels == labels
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/is_float.rb b/puppet/stdlib/lib/puppet/parser/functions/is_float.rb
new file mode 100644
index 0000000000..911f3c2dcd
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/is_float.rb
@@ -0,0 +1,27 @@
+#
+# is_float.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_float, :type => :rvalue, :doc => <<-EOS
+Returns true if the variable passed to this function is a float.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_float(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ value = arguments[0]
+
+ if value != value.to_f.to_s and !value.is_a? Float then
+ return false
+ else
+ return true
+ end
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/is_function_available.rb b/puppet/stdlib/lib/puppet/parser/functions/is_function_available.rb
new file mode 100644
index 0000000000..6cbd35c3db
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/is_function_available.rb
@@ -0,0 +1,23 @@
+#
+# is_function_available.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_function_available, :type => :rvalue, :doc => <<-EOS
+This function accepts a string as an argument, determines whether the
+Puppet runtime has access to a function by that name. It returns a
+true if the function exists, false if not.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_function_available?(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ function = Puppet::Parser::Functions.function(arguments[0].to_sym)
+ function.is_a?(String) and not function.empty?
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/is_hash.rb b/puppet/stdlib/lib/puppet/parser/functions/is_hash.rb
new file mode 100644
index 0000000000..ad907f086f
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/is_hash.rb
@@ -0,0 +1,22 @@
+#
+# is_hash.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_hash, :type => :rvalue, :doc => <<-EOS
+Returns true if the variable passed to this function is a hash.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "is_hash(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size != 1
+
+ type = arguments[0]
+
+ result = type.is_a?(Hash)
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/is_integer.rb b/puppet/stdlib/lib/puppet/parser/functions/is_integer.rb
new file mode 100644
index 0000000000..6b29e988e3
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/is_integer.rb
@@ -0,0 +1,27 @@
+#
+# is_integer.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_integer, :type => :rvalue, :doc => <<-EOS
+Returns true if the variable returned to this string is an integer.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_integer(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ value = arguments[0]
+
+ if value != value.to_i.to_s and !value.is_a? Fixnum then
+ return false
+ else
+ return true
+ end
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/is_ip_address.rb b/puppet/stdlib/lib/puppet/parser/functions/is_ip_address.rb
new file mode 100644
index 0000000000..a90adabe15
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/is_ip_address.rb
@@ -0,0 +1,32 @@
+#
+# is_ip_address.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_ip_address, :type => :rvalue, :doc => <<-EOS
+Returns true if the string passed to this function is a valid IP address.
+ EOS
+ ) do |arguments|
+
+ require 'ipaddr'
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ begin
+ ip = IPAddr.new(arguments[0])
+ rescue ArgumentError
+ return false
+ end
+
+ if ip.ipv4? or ip.ipv6? then
+ return true
+ else
+ return false
+ end
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/is_mac_address.rb b/puppet/stdlib/lib/puppet/parser/functions/is_mac_address.rb
new file mode 100644
index 0000000000..1b3088a26a
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/is_mac_address.rb
@@ -0,0 +1,27 @@
+#
+# is_mac_address.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_mac_address, :type => :rvalue, :doc => <<-EOS
+Returns true if the string passed to this function is a valid mac address.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_mac_address(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ mac = arguments[0]
+
+ if /^[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}$/.match(mac) then
+ return true
+ else
+ return false
+ end
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/is_numeric.rb b/puppet/stdlib/lib/puppet/parser/functions/is_numeric.rb
new file mode 100644
index 0000000000..abf03213c6
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/is_numeric.rb
@@ -0,0 +1,27 @@
+#
+# is_numeric.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_numeric, :type => :rvalue, :doc => <<-EOS
+Returns true if the variable passed to this function is a number.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_numeric(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ value = arguments[0]
+
+ if value == value.to_f.to_s or value == value.to_i.to_s or value.is_a? Numeric then
+ return true
+ else
+ return false
+ end
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/is_string.rb b/puppet/stdlib/lib/puppet/parser/functions/is_string.rb
new file mode 100644
index 0000000000..f5bef0457f
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/is_string.rb
@@ -0,0 +1,26 @@
+#
+# is_string.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_string, :type => :rvalue, :doc => <<-EOS
+Returns true if the variable passed to this function is a string.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "is_string(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ type = arguments[0]
+
+ result = type.is_a?(String)
+
+ if result and (type == type.to_f.to_s or type == type.to_i.to_s) then
+ return false
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/join.rb b/puppet/stdlib/lib/puppet/parser/functions/join.rb
new file mode 100644
index 0000000000..005a46ea51
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/join.rb
@@ -0,0 +1,41 @@
+#
+# join.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:join, :type => :rvalue, :doc => <<-EOS
+This function joins an array into a string using a seperator.
+
+*Examples:*
+
+ join(['a','b','c'], ",")
+
+Would result in: "a,b,c"
+ EOS
+ ) do |arguments|
+
+ # Technically we support two arguments but only first is mandatory ...
+ raise(Puppet::ParseError, "join(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ array = arguments[0]
+
+ unless array.is_a?(Array)
+ raise(Puppet::ParseError, 'join(): Requires array to work with')
+ end
+
+ suffix = arguments[1] if arguments[1]
+
+ if suffix
+ unless suffix.is_a?(String)
+ raise(Puppet::ParseError, 'join(): Requires string to work with')
+ end
+ end
+
+ result = suffix ? array.join(suffix) : array.join
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/join_keys_to_values.rb b/puppet/stdlib/lib/puppet/parser/functions/join_keys_to_values.rb
new file mode 100644
index 0000000000..e9924fe2e6
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/join_keys_to_values.rb
@@ -0,0 +1,47 @@
+#
+# join.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:join_keys_to_values, :type => :rvalue, :doc => <<-EOS
+This function joins each key of a hash to that key's corresponding value with a
+separator. Keys and values are cast to strings. The return value is an array in
+which each element is one joined key/value pair.
+
+*Examples:*
+
+ join_keys_to_values({'a'=>1,'b'=>2}, " is ")
+
+Would result in: ["a is 1","b is 2"]
+ EOS
+ ) do |arguments|
+
+ # Validate the number of arguments.
+ if arguments.size != 2
+ raise(Puppet::ParseError, "join_keys_to_values(): Takes exactly two " +
+ "arguments, but #{arguments.size} given.")
+ end
+
+ # Validate the first argument.
+ hash = arguments[0]
+ if not hash.is_a?(Hash)
+ raise(TypeError, "join_keys_to_values(): The first argument must be a " +
+ "hash, but a #{hash.class} was given.")
+ end
+
+ # Validate the second argument.
+ separator = arguments[1]
+ if not separator.is_a?(String)
+ raise(TypeError, "join_keys_to_values(): The second argument must be a " +
+ "string, but a #{separator.class} was given.")
+ end
+
+ # Join the keys to their values.
+ hash.map do |k,v|
+ String(k) + separator + String(v)
+ end
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/keys.rb b/puppet/stdlib/lib/puppet/parser/functions/keys.rb
new file mode 100644
index 0000000000..f0d13b6476
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/keys.rb
@@ -0,0 +1,26 @@
+#
+# keys.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:keys, :type => :rvalue, :doc => <<-EOS
+Returns the keys of a hash as an array.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "keys(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ hash = arguments[0]
+
+ unless hash.is_a?(Hash)
+ raise(Puppet::ParseError, 'keys(): Requires hash to work with')
+ end
+
+ result = hash.keys
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/loadyaml.rb b/puppet/stdlib/lib/puppet/parser/functions/loadyaml.rb
new file mode 100644
index 0000000000..10c400501b
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/loadyaml.rb
@@ -0,0 +1,20 @@
+module Puppet::Parser::Functions
+
+ newfunction(:loadyaml, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
+ Load a YAML file containing an array, string, or hash, and return the data
+ in the corresponding native data type.
+
+ For example:
+
+ $myhash = loadyaml('/etc/puppet/data/myhash.yaml')
+ ENDHEREDOC
+
+ unless args.length == 1
+ raise Puppet::ParseError, ("loadyaml(): wrong number of arguments (#{args.length}; must be 1)")
+ end
+
+ YAML.load_file(args[0])
+
+ end
+
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/lstrip.rb b/puppet/stdlib/lib/puppet/parser/functions/lstrip.rb
new file mode 100644
index 0000000000..3a64de3376
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/lstrip.rb
@@ -0,0 +1,33 @@
+#
+# lstrip.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:lstrip, :type => :rvalue, :doc => <<-EOS
+Strips leading spaces to the left of a string.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "lstrip(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'lstrip(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ result = value.collect { |i| i.is_a?(String) ? i.lstrip : i }
+ else
+ result = value.lstrip
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/max.rb b/puppet/stdlib/lib/puppet/parser/functions/max.rb
new file mode 100644
index 0000000000..60fb94ac04
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/max.rb
@@ -0,0 +1,21 @@
+module Puppet::Parser::Functions
+ newfunction(:max, :type => :rvalue, :doc => <<-EOS
+ Returns the highest value of all arguments.
+ Requires at least one argument.
+ EOS
+ ) do |args|
+
+ raise(Puppet::ParseError, "max(): Wrong number of arguments " +
+ "need at least one") if args.size == 0
+
+ # Sometimes we get numbers as numerics and sometimes as strings.
+ # We try to compare them as numbers when possible
+ return args.max do |a,b|
+ if a.to_s =~ /\A-?\d+(.\d+)?\z/ and b.to_s =~ /\A-?\d+(.\d+)?\z/ then
+ a.to_f <=> b.to_f
+ else
+ a.to_s <=> b.to_s
+ end
+ end
+ end
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/member.rb b/puppet/stdlib/lib/puppet/parser/functions/member.rb
new file mode 100644
index 0000000000..43d76affd9
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/member.rb
@@ -0,0 +1,44 @@
+#
+# member.rb
+#
+
+# TODO(Krzysztof Wilczynski): We need to add support for regular expression ...
+# TODO(Krzysztof Wilczynski): Support for strings and hashes too ...
+
+module Puppet::Parser::Functions
+ newfunction(:member, :type => :rvalue, :doc => <<-EOS
+This function determines if a variable is a member of an array.
+
+*Examples:*
+
+ member(['a','b'], 'b')
+
+Would return: true
+
+ member(['a','b'], 'c')
+
+Would return: false
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "member(): Wrong number of arguments " +
+ "given (#{arguments.size} for 2)") if arguments.size < 2
+
+ array = arguments[0]
+
+ unless array.is_a?(Array)
+ raise(Puppet::ParseError, 'member(): Requires array to work with')
+ end
+
+ item = arguments[1]
+
+ raise(Puppet::ParseError, 'member(): You must provide item ' +
+ 'to search for within array given') if item.empty?
+
+ result = array.include?(item)
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/merge.rb b/puppet/stdlib/lib/puppet/parser/functions/merge.rb
new file mode 100644
index 0000000000..6ec085eb10
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/merge.rb
@@ -0,0 +1,33 @@
+module Puppet::Parser::Functions
+ newfunction(:merge, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
+ Merges two or more hashes together and returns the resulting hash.
+
+ For example:
+
+ $hash1 = {'one' => 1, 'two', => 2}
+ $hash2 = {'two' => 'dos', 'three', => 'tres'}
+ $merged_hash = merge($hash1, $hash2)
+ # The resulting hash is equivalent to:
+ # $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'}
+
+ When there is a duplicate key, the key in the rightmost hash will "win."
+
+ ENDHEREDOC
+
+ if args.length < 2
+ raise Puppet::ParseError, ("merge(): wrong number of arguments (#{args.length}; must be at least 2)")
+ end
+
+ # The hash we accumulate into
+ accumulator = Hash.new
+ # Merge into the accumulator hash
+ args.each do |arg|
+ unless arg.is_a?(Hash)
+ raise Puppet::ParseError, "merge: unexpected argument type #{arg.class}, only expects hash arguments"
+ end
+ accumulator.merge!(arg)
+ end
+ # Return the fully merged hash
+ accumulator
+ end
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/min.rb b/puppet/stdlib/lib/puppet/parser/functions/min.rb
new file mode 100644
index 0000000000..6bd6ebf20c
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/min.rb
@@ -0,0 +1,21 @@
+module Puppet::Parser::Functions
+ newfunction(:min, :type => :rvalue, :doc => <<-EOS
+ Returns the lowest value of all arguments.
+ Requires at least one argument.
+ EOS
+ ) do |args|
+
+ raise(Puppet::ParseError, "min(): Wrong number of arguments " +
+ "need at least one") if args.size == 0
+
+ # Sometimes we get numbers as numerics and sometimes as strings.
+ # We try to compare them as numbers when possible
+ return args.min do |a,b|
+ if a.to_s =~ /\A^-?\d+(.\d+)?\z/ and b.to_s =~ /\A-?\d+(.\d+)?\z/ then
+ a.to_f <=> b.to_f
+ else
+ a.to_s <=> b.to_s
+ end
+ end
+ end
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/num2bool.rb b/puppet/stdlib/lib/puppet/parser/functions/num2bool.rb
new file mode 100644
index 0000000000..af0e6ed789
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/num2bool.rb
@@ -0,0 +1,43 @@
+#
+# num2bool.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:num2bool, :type => :rvalue, :doc => <<-EOS
+This function converts a number or a string representation of a number into a
+true boolean. Zero or anything non-numeric becomes false. Numbers higher then 0
+become true.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "num2bool(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size != 1
+
+ number = arguments[0]
+
+ case number
+ when Numeric
+ # Yay, it's a number
+ when String
+ begin
+ number = Float(number)
+ rescue ArgumentError => ex
+ raise(Puppet::ParseError, "num2bool(): '#{number}' does not look like a number: #{ex.message}")
+ end
+ else
+ begin
+ number = number.to_s
+ rescue NoMethodError => ex
+ raise(Puppet::ParseError, "num2bool(): Unable to parse argument: #{ex.message}")
+ end
+ end
+
+ # Truncate Floats
+ number = number.to_i
+
+ # Return true for any positive number and false otherwise
+ return number > 0
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/parsejson.rb b/puppet/stdlib/lib/puppet/parser/functions/parsejson.rb
new file mode 100644
index 0000000000..a9a16a4524
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/parsejson.rb
@@ -0,0 +1,24 @@
+#
+# parsejson.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:parsejson, :type => :rvalue, :doc => <<-EOS
+This function accepts JSON as a string and converts into the correct Puppet
+structure.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "parsejson(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ json = arguments[0]
+
+ # PSON is natively available in puppet
+ PSON.load(json)
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/parseyaml.rb b/puppet/stdlib/lib/puppet/parser/functions/parseyaml.rb
new file mode 100644
index 0000000000..53d54faff7
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/parseyaml.rb
@@ -0,0 +1,24 @@
+#
+# parseyaml.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:parseyaml, :type => :rvalue, :doc => <<-EOS
+This function accepts YAML as a string and converts it into the correct
+Puppet structure.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "parseyaml(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ require 'yaml'
+
+ YAML::load(arguments[0])
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/pick.rb b/puppet/stdlib/lib/puppet/parser/functions/pick.rb
new file mode 100644
index 0000000000..cbc030021a
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/pick.rb
@@ -0,0 +1,29 @@
+module Puppet::Parser::Functions
+ newfunction(:pick, :type => :rvalue, :doc => <<-EOS
+
+This function is similar to a coalesce function in SQL in that it will return
+the first value in a list of values that is not undefined or an empty string
+(two things in Puppet that will return a boolean false value). Typically,
+this function is used to check for a value in the Puppet Dashboard/Enterprise
+Console, and failover to a default value like the following:
+
+ $real_jenkins_version = pick($::jenkins_version, '1.449')
+
+The value of $real_jenkins_version will first look for a top-scope variable
+called 'jenkins_version' (note that parameters set in the Puppet Dashboard/
+Enterprise Console are brought into Puppet as top-scope variables), and,
+failing that, will use a default value of 1.449.
+
+EOS
+) do |args|
+ args = args.compact
+ args.delete(:undef)
+ args.delete(:undefined)
+ args.delete("")
+ if args[0].to_s.empty? then
+ fail "Must provide non empty value."
+ else
+ return args[0]
+ end
+ end
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/prefix.rb b/puppet/stdlib/lib/puppet/parser/functions/prefix.rb
new file mode 100644
index 0000000000..62211ae684
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/prefix.rb
@@ -0,0 +1,45 @@
+#
+# prefix.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:prefix, :type => :rvalue, :doc => <<-EOS
+This function applies a prefix to all elements in an array.
+
+*Examples:*
+
+ prefix(['a','b','c'], 'p')
+
+Will return: ['pa','pb','pc']
+ EOS
+ ) do |arguments|
+
+ # Technically we support two arguments but only first is mandatory ...
+ raise(Puppet::ParseError, "prefix(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ array = arguments[0]
+
+ unless array.is_a?(Array)
+ raise Puppet::ParseError, "prefix(): expected first argument to be an Array, got #{array.inspect}"
+ end
+
+ prefix = arguments[1] if arguments[1]
+
+ if prefix
+ unless prefix.is_a?(String)
+ raise Puppet::ParseError, "prefix(): expected second argument to be a String, got #{suffix.inspect}"
+ end
+ end
+
+ # Turn everything into string same as join would do ...
+ result = array.collect do |i|
+ i = i.to_s
+ prefix ? prefix + i : i
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/range.rb b/puppet/stdlib/lib/puppet/parser/functions/range.rb
new file mode 100644
index 0000000000..825617b383
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/range.rb
@@ -0,0 +1,80 @@
+#
+# range.rb
+#
+
+# TODO(Krzysztof Wilczynski): We probably need to approach numeric values differently ...
+
+module Puppet::Parser::Functions
+ newfunction(:range, :type => :rvalue, :doc => <<-EOS
+When given range in the form of (start, stop) it will extrapolate a range as
+an array.
+
+*Examples:*
+
+ range("0", "9")
+
+Will return: [0,1,2,3,4,5,6,7,8,9]
+
+ range("00", "09")
+
+Will return: [0,1,2,3,4,5,6,7,8,9] (Zero padded strings are converted to
+integers automatically)
+
+ range("a", "c")
+
+Will return: ["a","b","c"]
+
+ range("host01", "host10")
+
+Will return: ["host01", "host02", ..., "host09", "host10"]
+ EOS
+ ) do |arguments|
+
+ # We support more than one argument but at least one is mandatory ...
+ raise(Puppet::ParseError, "range(): Wrong number of " +
+ "arguments given (#{arguments.size} for 1)") if arguments.size < 1
+
+ if arguments.size > 1
+ start = arguments[0]
+ stop = arguments[1]
+
+ type = '..' # We select simplest type for Range available in Ruby ...
+
+ elsif arguments.size > 0
+ value = arguments[0]
+
+ if m = value.match(/^(\w+)(\.\.\.?|\-)(\w+)$/)
+ start = m[1]
+ stop = m[3]
+
+ type = m[2]
+
+ elsif value.match(/^.+$/)
+ raise(Puppet::ParseError, 'range(): Unable to compute range ' +
+ 'from the value given')
+ else
+ raise(Puppet::ParseError, 'range(): Unknown format of range given')
+ end
+ end
+
+ # Check whether we have integer value if so then make it so ...
+ if start.match(/^\d+$/)
+ start = start.to_i
+ stop = stop.to_i
+ else
+ start = start.to_s
+ stop = stop.to_s
+ end
+
+ range = case type
+ when /^(\.\.|\-)$/ then (start .. stop)
+ when /^(\.\.\.)$/ then (start ... stop) # Exclusive of last element ...
+ end
+
+ result = range.collect { |i| i } # Get them all ... Pokemon ...
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/reject.rb b/puppet/stdlib/lib/puppet/parser/functions/reject.rb
new file mode 100644
index 0000000000..1953ffcf11
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/reject.rb
@@ -0,0 +1,31 @@
+#
+# reject.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:reject, :type => :rvalue, :doc => <<-EOS) do |args|
+This function searches through an array and rejects all elements that match
+the provided regular expression.
+
+*Examples:*
+
+ reject(['aaa','bbb','ccc','aaaddd'], 'aaa')
+
+Would return:
+
+ ['bbb','ccc']
+EOS
+
+ if (args.size != 2)
+ raise Puppet::ParseError,
+ "reject(): Wrong number of arguments given #{args.size} for 2"
+ end
+
+ ary = args[0]
+ pattern = Regexp.new(args[1])
+
+ ary.reject { |e| e =~ pattern }
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/reverse.rb b/puppet/stdlib/lib/puppet/parser/functions/reverse.rb
new file mode 100644
index 0000000000..fe048690cd
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/reverse.rb
@@ -0,0 +1,28 @@
+#
+# reverse.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:reverse, :type => :rvalue, :doc => <<-EOS
+Reverses the order of a string or array.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "reverse(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'reverse(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ result = value.reverse
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/rstrip.rb b/puppet/stdlib/lib/puppet/parser/functions/rstrip.rb
new file mode 100644
index 0000000000..29b0998205
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/rstrip.rb
@@ -0,0 +1,32 @@
+#
+# rstrip.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:rstrip, :type => :rvalue, :doc => <<-EOS
+Strips leading spaces to the right of the string.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "rstrip(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'rstrip(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ result = value.collect { |i| i.is_a?(String) ? i.rstrip : i }
+ else
+ result = value.rstrip
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/shuffle.rb b/puppet/stdlib/lib/puppet/parser/functions/shuffle.rb
new file mode 100644
index 0000000000..18134ab633
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/shuffle.rb
@@ -0,0 +1,46 @@
+#
+# shuffle.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:shuffle, :type => :rvalue, :doc => <<-EOS
+Randomizes the order of a string or array elements.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "shuffle(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'shuffle(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ result = value.clone
+
+ string = value.is_a?(String) ? true : false
+
+ # Check whether it makes sense to shuffle ...
+ return result if result.size <= 1
+
+ # We turn any string value into an array to be able to shuffle ...
+ result = string ? result.split('') : result
+
+ elements = result.size
+
+ # Simple implementation of Fisher–Yates in-place shuffle ...
+ elements.times do |i|
+ j = rand(elements - i) + i
+ result[j], result[i] = result[i], result[j]
+ end
+
+ result = string ? result.join : result
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/size.rb b/puppet/stdlib/lib/puppet/parser/functions/size.rb
new file mode 100644
index 0000000000..cc207e3fad
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/size.rb
@@ -0,0 +1,48 @@
+#
+# size.rb
+#
+
+# TODO(Krzysztof Wilczynski): Support for hashes would be nice too ...
+
+module Puppet::Parser::Functions
+ newfunction(:size, :type => :rvalue, :doc => <<-EOS
+Returns the number of elements in a string or array.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "size(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ item = arguments[0]
+
+ if item.is_a?(String)
+
+ begin
+ #
+ # Check whether your item is a numeric value or not ...
+ # This will take care about positive and/or negative numbers
+ # for both integer and floating-point values ...
+ #
+ # Please note that Puppet has no notion of hexadecimal
+ # nor octal numbers for its DSL at this point in time ...
+ #
+ Float(item)
+
+ raise(Puppet::ParseError, 'size(): Requires either ' +
+ 'string or array to work with')
+
+ rescue ArgumentError
+ result = item.size
+ end
+
+ elsif item.is_a?(Array)
+ result = item.size
+ else
+ raise(Puppet::ParseError, 'size(): Unknown type given')
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/sort.rb b/puppet/stdlib/lib/puppet/parser/functions/sort.rb
new file mode 100644
index 0000000000..cefbe5463b
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/sort.rb
@@ -0,0 +1,27 @@
+#
+# sort.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:sort, :type => :rvalue, :doc => <<-EOS
+Sorts strings and arrays lexically.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "sort(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ value = arguments[0]
+
+ if value.is_a?(Array) then
+ value.sort
+ elsif value.is_a?(String) then
+ value.split("").sort.join("")
+ end
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/squeeze.rb b/puppet/stdlib/lib/puppet/parser/functions/squeeze.rb
new file mode 100644
index 0000000000..81fadfdb2f
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/squeeze.rb
@@ -0,0 +1,36 @@
+#
+# squeeze.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:squeeze, :type => :rvalue, :doc => <<-EOS
+Returns a new string where runs of the same character that occur in this set are replaced by a single character.
+ EOS
+ ) do |arguments|
+
+ if ((arguments.size != 2) and (arguments.size != 1)) then
+ raise(Puppet::ParseError, "squeeze(): Wrong number of arguments "+
+ "given #{arguments.size} for 2 or 1")
+ end
+
+ item = arguments[0]
+ squeezeval = arguments[1]
+
+ if item.is_a?(Array) then
+ if squeezeval then
+ item.collect { |i| i.squeeze(squeezeval) }
+ else
+ item.collect { |i| i.squeeze }
+ end
+ else
+ if squeezeval then
+ item.squeeze(squeezeval)
+ else
+ item.squeeze
+ end
+ end
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/str2bool.rb b/puppet/stdlib/lib/puppet/parser/functions/str2bool.rb
new file mode 100644
index 0000000000..fece7a6f27
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/str2bool.rb
@@ -0,0 +1,46 @@
+#
+# str2bool.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:str2bool, :type => :rvalue, :doc => <<-EOS
+This converts a string to a boolean. This attempt to convert strings that
+contain things like: y, 1, t, true to 'true' and strings that contain things
+like: 0, f, n, false, no to 'false'.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "str2bool(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ string = arguments[0]
+
+ # If string is already Boolean, return it
+ if !!string == string
+ return string
+ end
+
+ unless string.is_a?(String)
+ raise(Puppet::ParseError, 'str2bool(): Requires either ' +
+ 'string to work with')
+ end
+
+ # We consider all the yes, no, y, n and so on too ...
+ result = case string
+ #
+ # This is how undef looks like in Puppet ...
+ # We yield false in this case.
+ #
+ when /^$/, '' then false # Empty string will be false ...
+ when /^(1|t|y|true|yes)$/ then true
+ when /^(0|f|n|false|no)$/ then false
+ when /^(undef|undefined)$/ then false # This is not likely to happen ...
+ else
+ raise(Puppet::ParseError, 'str2bool(): Unknown type of boolean given')
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/str2saltedsha512.rb b/puppet/stdlib/lib/puppet/parser/functions/str2saltedsha512.rb
new file mode 100644
index 0000000000..7fe7b0128a
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/str2saltedsha512.rb
@@ -0,0 +1,32 @@
+#
+# str2saltedsha512.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:str2saltedsha512, :type => :rvalue, :doc => <<-EOS
+This converts a string to a salted-SHA512 password hash (which is used for
+OS X versions >= 10.7). Given any simple string, you will get a hex version
+of a salted-SHA512 password hash that can be inserted into your Puppet
+manifests as a valid password attribute.
+ EOS
+ ) do |arguments|
+ require 'digest/sha2'
+
+ raise(Puppet::ParseError, "str2saltedsha512(): Wrong number of arguments " +
+ "passed (#{arguments.size} but we require 1)") if arguments.size != 1
+
+ password = arguments[0]
+
+ unless password.is_a?(String)
+ raise(Puppet::ParseError, 'str2saltedsha512(): Requires a ' +
+ "String argument, you passed: #{password.class}")
+ end
+
+ seedint = rand(2**31 - 1)
+ seedstring = Array(seedint).pack("L")
+ saltedpass = Digest::SHA512.digest(seedstring + password)
+ (seedstring + saltedpass).unpack('H*')[0]
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/strftime.rb b/puppet/stdlib/lib/puppet/parser/functions/strftime.rb
new file mode 100644
index 0000000000..0b52adecdb
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/strftime.rb
@@ -0,0 +1,107 @@
+#
+# strftime.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:strftime, :type => :rvalue, :doc => <<-EOS
+This function returns formatted time.
+
+*Examples:*
+
+To return the time since epoch:
+
+ strftime("%s")
+
+To return the date:
+
+ strftime("%Y-%m-%d")
+
+*Format meaning:*
+
+ %a - The abbreviated weekday name (``Sun'')
+ %A - The full weekday name (``Sunday'')
+ %b - The abbreviated month name (``Jan'')
+ %B - The full month name (``January'')
+ %c - The preferred local date and time representation
+ %C - Century (20 in 2009)
+ %d - Day of the month (01..31)
+ %D - Date (%m/%d/%y)
+ %e - Day of the month, blank-padded ( 1..31)
+ %F - Equivalent to %Y-%m-%d (the ISO 8601 date format)
+ %h - Equivalent to %b
+ %H - Hour of the day, 24-hour clock (00..23)
+ %I - Hour of the day, 12-hour clock (01..12)
+ %j - Day of the year (001..366)
+ %k - hour, 24-hour clock, blank-padded ( 0..23)
+ %l - hour, 12-hour clock, blank-padded ( 0..12)
+ %L - Millisecond of the second (000..999)
+ %m - Month of the year (01..12)
+ %M - Minute of the hour (00..59)
+ %n - Newline (\n)
+ %N - Fractional seconds digits, default is 9 digits (nanosecond)
+ %3N millisecond (3 digits)
+ %6N microsecond (6 digits)
+ %9N nanosecond (9 digits)
+ %p - Meridian indicator (``AM'' or ``PM'')
+ %P - Meridian indicator (``am'' or ``pm'')
+ %r - time, 12-hour (same as %I:%M:%S %p)
+ %R - time, 24-hour (%H:%M)
+ %s - Number of seconds since 1970-01-01 00:00:00 UTC.
+ %S - Second of the minute (00..60)
+ %t - Tab character (\t)
+ %T - time, 24-hour (%H:%M:%S)
+ %u - Day of the week as a decimal, Monday being 1. (1..7)
+ %U - Week number of the current year,
+ starting with the first Sunday as the first
+ day of the first week (00..53)
+ %v - VMS date (%e-%b-%Y)
+ %V - Week number of year according to ISO 8601 (01..53)
+ %W - Week number of the current year,
+ starting with the first Monday as the first
+ day of the first week (00..53)
+ %w - Day of the week (Sunday is 0, 0..6)
+ %x - Preferred representation for the date alone, no time
+ %X - Preferred representation for the time alone, no date
+ %y - Year without a century (00..99)
+ %Y - Year with century
+ %z - Time zone as hour offset from UTC (e.g. +0900)
+ %Z - Time zone name
+ %% - Literal ``%'' character
+ EOS
+ ) do |arguments|
+
+ # Technically we support two arguments but only first is mandatory ...
+ raise(Puppet::ParseError, "strftime(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ format = arguments[0]
+
+ raise(Puppet::ParseError, 'strftime(): You must provide ' +
+ 'format for evaluation') if format.empty?
+
+ # The Time Zone argument is optional ...
+ time_zone = arguments[1] if arguments[1]
+
+ time = Time.new
+
+ # There is probably a better way to handle Time Zone ...
+ if time_zone and not time_zone.empty?
+ original_zone = ENV['TZ']
+
+ local_time = time.clone
+ local_time = local_time.utc
+
+ ENV['TZ'] = time_zone
+
+ time = local_time.localtime
+
+ ENV['TZ'] = original_zone
+ end
+
+ result = time.strftime(format)
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/strip.rb b/puppet/stdlib/lib/puppet/parser/functions/strip.rb
new file mode 100644
index 0000000000..5f4630d7de
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/strip.rb
@@ -0,0 +1,39 @@
+#
+# strip.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:strip, :type => :rvalue, :doc => <<-EOS
+This function removes leading and trailing whitespace from a string or from
+every string inside an array.
+
+*Examples:*
+
+ strip(" aaa ")
+
+Would result in: "aaa"
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "strip(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'strip(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ result = value.collect { |i| i.is_a?(String) ? i.strip : i }
+ else
+ result = value.strip
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/suffix.rb b/puppet/stdlib/lib/puppet/parser/functions/suffix.rb
new file mode 100644
index 0000000000..f7792d6f7a
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/suffix.rb
@@ -0,0 +1,45 @@
+#
+# suffix.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:suffix, :type => :rvalue, :doc => <<-EOS
+This function applies a suffix to all elements in an array.
+
+*Examples:*
+
+ suffix(['a','b','c'], 'p')
+
+Will return: ['ap','bp','cp']
+ EOS
+ ) do |arguments|
+
+ # Technically we support two arguments but only first is mandatory ...
+ raise(Puppet::ParseError, "suffix(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ array = arguments[0]
+
+ unless array.is_a?(Array)
+ raise Puppet::ParseError, "suffix(): expected first argument to be an Array, got #{array.inspect}"
+ end
+
+ suffix = arguments[1] if arguments[1]
+
+ if suffix
+ unless suffix.is_a? String
+ raise Puppet::ParseError, "suffix(): expected second argument to be a String, got #{suffix.inspect}"
+ end
+ end
+
+ # Turn everything into string same as join would do ...
+ result = array.collect do |i|
+ i = i.to_s
+ suffix ? i + suffix : i
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/swapcase.rb b/puppet/stdlib/lib/puppet/parser/functions/swapcase.rb
new file mode 100644
index 0000000000..b9e6632533
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/swapcase.rb
@@ -0,0 +1,39 @@
+#
+# swapcase.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:swapcase, :type => :rvalue, :doc => <<-EOS
+This function will swap the existing case of a string.
+
+*Examples:*
+
+ swapcase("aBcD")
+
+Would result in: "AbCd"
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "swapcase(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'swapcase(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ result = value.collect { |i| i.is_a?(String) ? i.swapcase : i }
+ else
+ result = value.swapcase
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/time.rb b/puppet/stdlib/lib/puppet/parser/functions/time.rb
new file mode 100644
index 0000000000..0cddaf86b9
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/time.rb
@@ -0,0 +1,49 @@
+#
+# time.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:time, :type => :rvalue, :doc => <<-EOS
+This function will return the current time since epoch as an integer.
+
+*Examples:*
+
+ time()
+
+Will return something like: 1311972653
+ EOS
+ ) do |arguments|
+
+ # The Time Zone argument is optional ...
+ time_zone = arguments[0] if arguments[0]
+
+ if (arguments.size != 0) and (arguments.size != 1) then
+ raise(Puppet::ParseError, "time(): Wrong number of arguments "+
+ "given #{arguments.size} for 0 or 1")
+ end
+
+ time = Time.new
+
+ # There is probably a better way to handle Time Zone ...
+ if time_zone and not time_zone.empty?
+ original_zone = ENV['TZ']
+
+ local_time = time.clone
+ local_time = local_time.utc
+
+ ENV['TZ'] = time_zone
+
+ time = local_time.localtime
+
+ ENV['TZ'] = original_zone
+ end
+
+ # Calling Time#to_i on a receiver changes it. Trust me I am the Doctor.
+ result = time.strftime('%s')
+ result = result.to_i
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/to_bytes.rb b/puppet/stdlib/lib/puppet/parser/functions/to_bytes.rb
new file mode 100644
index 0000000000..8ff73d10b4
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/to_bytes.rb
@@ -0,0 +1,28 @@
+module Puppet::Parser::Functions
+ newfunction(:to_bytes, :type => :rvalue, :doc => <<-EOS
+ Converts the argument into bytes, for example 4 kB becomes 4096.
+ Takes a single string value as an argument.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "to_bytes(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size != 1
+
+ arg = arguments[0]
+
+ return arg if arg.is_a? Numeric
+
+ value,prefix = */([0-9.e+-]*)\s*([^bB]?)/.match(arg)[1,2]
+
+ value = value.to_f
+ case prefix
+ when '' then return value.to_i
+ when 'k' then return (value*(1<<10)).to_i
+ when 'M' then return (value*(1<<20)).to_i
+ when 'G' then return (value*(1<<30)).to_i
+ when 'T' then return (value*(1<<40)).to_i
+ when 'E' then return (value*(1<<50)).to_i
+ else raise Puppet::ParseError, "to_bytes(): Unknown prefix #{prefix}"
+ end
+ end
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/type.rb b/puppet/stdlib/lib/puppet/parser/functions/type.rb
new file mode 100644
index 0000000000..8d85f11585
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/type.rb
@@ -0,0 +1,50 @@
+#
+# type.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:type, :type => :rvalue, :doc => <<-EOS
+Returns the type when passed a variable. Type can be one of:
+
+* string
+* array
+* hash
+* float
+* integer
+* boolean
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "type(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+
+ klass = value.class
+
+ if not [TrueClass, FalseClass, Array, Bignum, Fixnum, Float, Hash, String].include?(klass)
+ raise(Puppet::ParseError, 'type(): Unknown type')
+ end
+
+ klass = klass.to_s # Ugly ...
+
+ # We note that Integer is the parent to Bignum and Fixnum ...
+ result = case klass
+ when /^(?:Big|Fix)num$/ then 'integer'
+ when /^(?:True|False)Class$/ then 'boolean'
+ else klass
+ end
+
+ if result == "String" then
+ if value == value.to_i.to_s then
+ result = "Integer"
+ elsif value == value.to_f.to_s then
+ result = "Float"
+ end
+ end
+
+ return result.downcase
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/unique.rb b/puppet/stdlib/lib/puppet/parser/functions/unique.rb
new file mode 100644
index 0000000000..8844a74185
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/unique.rb
@@ -0,0 +1,51 @@
+#
+# unique.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:unique, :type => :rvalue, :doc => <<-EOS
+This function will remove duplicates from strings and arrays.
+
+*Examples:*
+
+ unique("aabbcc")
+
+Will return:
+
+ abc
+
+You can also use this with arrays:
+
+ unique(["a","a","b","b","c","c"])
+
+This returns:
+
+ ["a","b","c"]
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "unique(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'unique(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ result = value.clone
+
+ string = value.is_a?(String) ? true : false
+
+ # We turn any string value into an array to be able to shuffle ...
+ result = string ? result.split('') : result
+ result = result.uniq # Remove duplicates ...
+ result = string ? result.join : result
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/upcase.rb b/puppet/stdlib/lib/puppet/parser/functions/upcase.rb
new file mode 100644
index 0000000000..fe6cadc3cc
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/upcase.rb
@@ -0,0 +1,41 @@
+#
+# upcase.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:upcase, :type => :rvalue, :doc => <<-EOS
+Converts a string or an array of strings to uppercase.
+
+*Examples:*
+
+ upcase("abcd")
+
+Will return:
+
+ ASDF
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "upcase(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'upcase(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ result = value.collect { |i| i.is_a?(String) ? i.upcase : i }
+ else
+ result = value.upcase
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/uriescape.rb b/puppet/stdlib/lib/puppet/parser/functions/uriescape.rb
new file mode 100644
index 0000000000..67b93a64d7
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/uriescape.rb
@@ -0,0 +1,36 @@
+#
+# uriescape.rb
+#
+require 'uri'
+
+module Puppet::Parser::Functions
+ newfunction(:uriescape, :type => :rvalue, :doc => <<-EOS
+ Urlencodes a string or array of strings.
+ Requires either a single string or an array as an input.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "uriescape(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+ unsafe = ":/?#[]@!$&'()*+,;= "
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'uriescape(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ result = value.collect { |i| i.is_a?(String) ? URI.escape(i,unsafe) : i }
+ else
+ result = URI.escape(value,unsafe)
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/validate_absolute_path.rb b/puppet/stdlib/lib/puppet/parser/functions/validate_absolute_path.rb
new file mode 100644
index 0000000000..fe279744ec
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/validate_absolute_path.rb
@@ -0,0 +1,56 @@
+module Puppet::Parser::Functions
+ newfunction(:validate_absolute_path, :doc => <<-'ENDHEREDOC') do |args|
+ Validate the string represents an absolute path in the filesystem. This function works
+ for windows and unix style paths.
+
+ The following values will pass:
+
+ $my_path = "C:/Program Files (x86)/Puppet Labs/Puppet"
+ validate_absolute_path($my_path)
+ $my_path2 = "/var/lib/puppet"
+ validate_absolute_path($my_path2)
+
+
+ The following values will fail, causing compilation to abort:
+
+ validate_absolute_path(true)
+ validate_absolute_path([ 'var/lib/puppet', '/var/foo' ])
+ validate_absolute_path([ '/var/lib/puppet', 'var/foo' ])
+ $undefined = undef
+ validate_absolute_path($undefined)
+
+ ENDHEREDOC
+
+ require 'puppet/util'
+
+ unless args.length > 0 then
+ raise Puppet::ParseError, ("validate_absolute_path(): wrong number of arguments (#{args.length}; must be > 0)")
+ end
+
+ args.each do |arg|
+ # This logic was borrowed from
+ # [lib/puppet/file_serving/base.rb](https://github.com/puppetlabs/puppet/blob/master/lib/puppet/file_serving/base.rb)
+
+ # Puppet 2.7 and beyond will have Puppet::Util.absolute_path? Fall back to a back-ported implementation otherwise.
+ if Puppet::Util.respond_to?(:absolute_path?) then
+ unless Puppet::Util.absolute_path?(arg, :posix) or Puppet::Util.absolute_path?(arg, :windows)
+ raise Puppet::ParseError, ("#{arg.inspect} is not an absolute path.")
+ end
+ else
+ # This code back-ported from 2.7.x's lib/puppet/util.rb Puppet::Util.absolute_path?
+ # Determine in a platform-specific way whether a path is absolute. This
+ # defaults to the local platform if none is specified.
+ # Escape once for the string literal, and once for the regex.
+ slash = '[\\\\/]'
+ name = '[^\\\\/]+'
+ regexes = {
+ :windows => %r!^(([A-Z]:#{slash})|(#{slash}#{slash}#{name}#{slash}#{name})|(#{slash}#{slash}\?#{slash}#{name}))!i,
+ :posix => %r!^/!,
+ }
+
+ rval = (!!(arg =~ regexes[:posix])) || (!!(arg =~ regexes[:windows]))
+ rval or raise Puppet::ParseError, ("#{arg.inspect} is not an absolute path.")
+ end
+ end
+ end
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/validate_array.rb b/puppet/stdlib/lib/puppet/parser/functions/validate_array.rb
new file mode 100644
index 0000000000..34b511825c
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/validate_array.rb
@@ -0,0 +1,33 @@
+module Puppet::Parser::Functions
+
+ newfunction(:validate_array, :doc => <<-'ENDHEREDOC') do |args|
+ Validate that all passed values are array data structures. Abort catalog
+ compilation if any value fails this check.
+
+ The following values will pass:
+
+ $my_array = [ 'one', 'two' ]
+ validate_array($my_array)
+
+ The following values will fail, causing compilation to abort:
+
+ validate_array(true)
+ validate_array('some_string')
+ $undefined = undef
+ validate_array($undefined)
+
+ ENDHEREDOC
+
+ unless args.length > 0 then
+ raise Puppet::ParseError, ("validate_array(): wrong number of arguments (#{args.length}; must be > 0)")
+ end
+
+ args.each do |arg|
+ unless arg.is_a?(Array)
+ raise Puppet::ParseError, ("#{arg.inspect} is not an Array. It looks to be a #{arg.class}")
+ end
+ end
+
+ end
+
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/validate_augeas.rb b/puppet/stdlib/lib/puppet/parser/functions/validate_augeas.rb
new file mode 100644
index 0000000000..154d66091c
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/validate_augeas.rb
@@ -0,0 +1,81 @@
+module Puppet::Parser::Functions
+ newfunction(:validate_augeas, :doc => <<-'ENDHEREDOC') do |args|
+ Perform validation of a string using an Augeas lens
+ The first argument of this function should be a string to
+ test, and the second argument should be the name of the Augeas lens to use.
+ If Augeas fails to parse the string with the lens, the compilation will
+ abort with a parse error.
+
+ A third argument can be specified, listing paths which should
+ not be found in the file. The `$file` variable points to the location
+ of the temporary file being tested in the Augeas tree.
+
+ For example, if you want to make sure your passwd content never contains
+ a user `foo`, you could write:
+
+ validate_augeas($passwdcontent, 'Passwd.lns', ['$file/foo'])
+
+ Or if you wanted to ensure that no users used the '/bin/barsh' shell,
+ you could use:
+
+ validate_augeas($passwdcontent, 'Passwd.lns', ['$file/*[shell="/bin/barsh"]']
+
+ If a fourth argument is specified, this will be the error message raised and
+ seen by the user.
+
+ A helpful error message can be returned like this:
+
+ validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers content with Augeas')
+
+ ENDHEREDOC
+ unless Puppet.features.augeas?
+ raise Puppet::ParseError, ("validate_augeas(): this function requires the augeas feature. See http://projects.puppetlabs.com/projects/puppet/wiki/Puppet_Augeas#Pre-requisites for how to activate it.")
+ end
+
+ if (args.length < 2) or (args.length > 4) then
+ raise Puppet::ParseError, ("validate_augeas(): wrong number of arguments (#{args.length}; must be 2, 3, or 4)")
+ end
+
+ msg = args[3] || "validate_augeas(): Failed to validate content against #{args[1].inspect}"
+
+ require 'augeas'
+ aug = Augeas::open(nil, nil, Augeas::NO_MODL_AUTOLOAD)
+ begin
+ content = args[0]
+
+ # Test content in a temporary file
+ tmpfile = Tempfile.new("validate_augeas")
+ begin
+ tmpfile.write(content)
+ ensure
+ tmpfile.close
+ end
+
+ # Check for syntax
+ lens = args[1]
+ aug.transform(
+ :lens => lens,
+ :name => 'Validate_augeas',
+ :incl => tmpfile.path
+ )
+ aug.load!
+
+ unless aug.match("/augeas/files#{tmpfile.path}//error").empty?
+ error = aug.get("/augeas/files#{tmpfile.path}//error/message")
+ msg += " with error: #{error}"
+ raise Puppet::ParseError, (msg)
+ end
+
+ # Launch unit tests
+ tests = args[2] || []
+ aug.defvar('file', "/files#{tmpfile.path}")
+ tests.each do |t|
+ msg += " testing path #{t}"
+ raise Puppet::ParseError, (msg) unless aug.match(t).empty?
+ end
+ ensure
+ aug.close
+ tmpfile.unlink
+ end
+ end
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/validate_bool.rb b/puppet/stdlib/lib/puppet/parser/functions/validate_bool.rb
new file mode 100644
index 0000000000..62c1d88821
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/validate_bool.rb
@@ -0,0 +1,34 @@
+module Puppet::Parser::Functions
+
+ newfunction(:validate_bool, :doc => <<-'ENDHEREDOC') do |args|
+ Validate that all passed values are either true or false. Abort catalog
+ compilation if any value fails this check.
+
+ The following values will pass:
+
+ $iamtrue = true
+ validate_bool(true)
+ validate_bool(true, true, false, $iamtrue)
+
+ The following values will fail, causing compilation to abort:
+
+ $some_array = [ true ]
+ validate_bool("false")
+ validate_bool("true")
+ validate_bool($some_array)
+
+ ENDHEREDOC
+
+ unless args.length > 0 then
+ raise Puppet::ParseError, ("validate_bool(): wrong number of arguments (#{args.length}; must be > 0)")
+ end
+
+ args.each do |arg|
+ unless (arg.is_a?(TrueClass) || arg.is_a?(FalseClass))
+ raise Puppet::ParseError, ("#{arg.inspect} is not a boolean. It looks to be a #{arg.class}")
+ end
+ end
+
+ end
+
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/validate_cmd.rb b/puppet/stdlib/lib/puppet/parser/functions/validate_cmd.rb
new file mode 100644
index 0000000000..344a80cd36
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/validate_cmd.rb
@@ -0,0 +1,47 @@
+require 'puppet/util/execution'
+
+module Puppet::Parser::Functions
+ newfunction(:validate_cmd, :doc => <<-'ENDHEREDOC') do |args|
+ Perform validation of a string with an external command.
+ The first argument of this function should be a string to
+ test, and the second argument should be a path to a test command
+ taking a file as last argument. If the command, launched against
+ a tempfile containing the passed string, returns a non-null value,
+ compilation will abort with a parse error.
+
+ If a third argument is specified, this will be the error message raised and
+ seen by the user.
+
+ A helpful error message can be returned like this:
+
+ Example:
+
+ validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content')
+
+ ENDHEREDOC
+ if (args.length < 2) or (args.length > 3) then
+ raise Puppet::ParseError, ("validate_cmd(): wrong number of arguments (#{args.length}; must be 2 or 3)")
+ end
+
+ msg = args[2] || "validate_cmd(): failed to validate content with command #{args[1].inspect}"
+
+ content = args[0]
+ checkscript = args[1]
+
+ # Test content in a temporary file
+ tmpfile = Tempfile.new("validate_cmd")
+ begin
+ tmpfile.write(content)
+ if Puppet::Util::Execution.respond_to?('execute')
+ Puppet::Util::Execution.execute("#{checkscript} #{tmpfile.path}")
+ else
+ Puppet::Util.execute("#{checkscript} #{tmpfile.path}")
+ end
+ rescue Puppet::ExecutionFailure => detail
+ msg += "\n#{detail}"
+ raise Puppet::ParseError, msg
+ ensure
+ tmpfile.unlink
+ end
+ end
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/validate_hash.rb b/puppet/stdlib/lib/puppet/parser/functions/validate_hash.rb
new file mode 100644
index 0000000000..9bdd543283
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/validate_hash.rb
@@ -0,0 +1,33 @@
+module Puppet::Parser::Functions
+
+ newfunction(:validate_hash, :doc => <<-'ENDHEREDOC') do |args|
+ Validate that all passed values are hash data structures. Abort catalog
+ compilation if any value fails this check.
+
+ The following values will pass:
+
+ $my_hash = { 'one' => 'two' }
+ validate_hash($my_hash)
+
+ The following values will fail, causing compilation to abort:
+
+ validate_hash(true)
+ validate_hash('some_string')
+ $undefined = undef
+ validate_hash($undefined)
+
+ ENDHEREDOC
+
+ unless args.length > 0 then
+ raise Puppet::ParseError, ("validate_hash(): wrong number of arguments (#{args.length}; must be > 0)")
+ end
+
+ args.each do |arg|
+ unless arg.is_a?(Hash)
+ raise Puppet::ParseError, ("#{arg.inspect} is not a Hash. It looks to be a #{arg.class}")
+ end
+ end
+
+ end
+
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/validate_re.rb b/puppet/stdlib/lib/puppet/parser/functions/validate_re.rb
new file mode 100644
index 0000000000..ca25a702c5
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/validate_re.rb
@@ -0,0 +1,40 @@
+module Puppet::Parser::Functions
+ newfunction(:validate_re, :doc => <<-'ENDHEREDOC') do |args|
+ Perform simple validation of a string against one or more regular
+ expressions. The first argument of this function should be a string to
+ test, and the second argument should be a stringified regular expression
+ (without the // delimiters) or an array of regular expressions. If none
+ of the regular expressions match the string passed in, compilation will
+ abort with a parse error.
+
+ If a third argument is specified, this will be the error message raised and
+ seen by the user.
+
+ The following strings will validate against the regular expressions:
+
+ validate_re('one', '^one$')
+ validate_re('one', [ '^one', '^two' ])
+
+ The following strings will fail to validate, causing compilation to abort:
+
+ validate_re('one', [ '^two', '^three' ])
+
+ A helpful error message can be returned like this:
+
+ validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7')
+
+ ENDHEREDOC
+ if (args.length < 2) or (args.length > 3) then
+ raise Puppet::ParseError, ("validate_re(): wrong number of arguments (#{args.length}; must be 2 or 3)")
+ end
+
+ msg = args[2] || "validate_re(): #{args[0].inspect} does not match #{args[1].inspect}"
+
+ # We're using a flattened array here because we can't call String#any? in
+ # Ruby 1.9 like we can in Ruby 1.8
+ raise Puppet::ParseError, (msg) unless [args[1]].flatten.any? do |re_str|
+ args[0] =~ Regexp.compile(re_str)
+ end
+
+ end
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/validate_slength.rb b/puppet/stdlib/lib/puppet/parser/functions/validate_slength.rb
new file mode 100644
index 0000000000..fdcc0a2d1a
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/validate_slength.rb
@@ -0,0 +1,52 @@
+module Puppet::Parser::Functions
+
+ newfunction(:validate_slength, :doc => <<-'ENDHEREDOC') do |args|
+ Validate that the first argument is a string (or an array of strings), and
+ less/equal to than the length of the second argument. It fails if the first
+ argument is not a string or array of strings, and if arg 2 is not convertable
+ to a number.
+
+ The following values will pass:
+
+ validate_slength("discombobulate",17)
+ validate_slength(["discombobulate","moo"],17)
+
+ The following valueis will not:
+
+ validate_slength("discombobulate",1)
+ validate_slength(["discombobulate","thermometer"],5)
+
+ ENDHEREDOC
+
+ raise Puppet::ParseError, ("validate_slength(): Wrong number of arguments (#{args.length}; must be = 2)") unless args.length == 2
+
+ unless (args[0].is_a?(String) or args[0].is_a?(Array))
+ raise Puppet::ParseError, ("validate_slength(): please pass a string, or an array of strings - what you passed didn't work for me at all - #{args[0].class}")
+ end
+
+ begin
+ max_length = args[1].to_i
+ rescue NoMethodError => e
+ raise Puppet::ParseError, ("validate_slength(): Couldn't convert whatever you passed as the length parameter to an integer - sorry: " + e.message )
+ end
+
+ raise Puppet::ParseError, ("validate_slength(): please pass a positive number as max_length") unless max_length > 0
+
+ case args[0]
+ when String
+ raise Puppet::ParseError, ("validate_slength(): #{args[0].inspect} is #{args[0].length} characters. It should have been less than or equal to #{max_length} characters") unless args[0].length <= max_length
+ when Array
+ args[0].each do |arg|
+ if arg.is_a?(String)
+ unless ( arg.is_a?(String) and arg.length <= max_length )
+ raise Puppet::ParseError, ("validate_slength(): #{arg.inspect} is #{arg.length} characters. It should have been less than or equal to #{max_length} characters")
+ end
+ else
+ raise Puppet::ParseError, ("validate_slength(): #{arg.inspect} is not a string, it's a #{arg.class}")
+ end
+ end
+ else
+ raise Puppet::ParseError, ("validate_slength(): please pass a string, or an array of strings - what you passed didn't work for me at all - #{args[0].class}")
+ end
+ end
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/validate_string.rb b/puppet/stdlib/lib/puppet/parser/functions/validate_string.rb
new file mode 100644
index 0000000000..e667794a67
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/validate_string.rb
@@ -0,0 +1,33 @@
+module Puppet::Parser::Functions
+
+ newfunction(:validate_string, :doc => <<-'ENDHEREDOC') do |args|
+ Validate that all passed values are string data structures. Abort catalog
+ compilation if any value fails this check.
+
+ The following values will pass:
+
+ $my_string = "one two"
+ validate_string($my_string, 'three')
+
+ The following values will fail, causing compilation to abort:
+
+ validate_string(true)
+ validate_string([ 'some', 'array' ])
+ $undefined = undef
+ validate_string($undefined)
+
+ ENDHEREDOC
+
+ unless args.length > 0 then
+ raise Puppet::ParseError, ("validate_string(): wrong number of arguments (#{args.length}; must be > 0)")
+ end
+
+ args.each do |arg|
+ unless arg.is_a?(String)
+ raise Puppet::ParseError, ("#{arg.inspect} is not a string. It looks to be a #{arg.class}")
+ end
+ end
+
+ end
+
+end
diff --git a/puppet/stdlib/lib/puppet/parser/functions/values.rb b/puppet/stdlib/lib/puppet/parser/functions/values.rb
new file mode 100644
index 0000000000..16067561b4
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/values.rb
@@ -0,0 +1,39 @@
+#
+# values.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:values, :type => :rvalue, :doc => <<-EOS
+When given a hash this function will return the values of that hash.
+
+*Examples:*
+
+ $hash = {
+ 'a' => 1,
+ 'b' => 2,
+ 'c' => 3,
+ }
+ values($hash)
+
+This example would return:
+
+ [1,2,3]
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "values(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ hash = arguments[0]
+
+ unless hash.is_a?(Hash)
+ raise(Puppet::ParseError, 'values(): Requires hash to work with')
+ end
+
+ result = hash.values
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/values_at.rb b/puppet/stdlib/lib/puppet/parser/functions/values_at.rb
new file mode 100644
index 0000000000..d3e69d97fc
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/values_at.rb
@@ -0,0 +1,98 @@
+#
+# values_at.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:values_at, :type => :rvalue, :doc => <<-EOS
+Finds value inside an array based on location.
+
+The first argument is the array you want to analyze, and the second element can
+be a combination of:
+
+* A single numeric index
+* A range in the form of 'start-stop' (eg. 4-9)
+* An array combining the above
+
+*Examples*:
+
+ values_at(['a','b','c'], 2)
+
+Would return ['c'].
+
+ values_at(['a','b','c'], ["0-1"])
+
+Would return ['a','b'].
+
+ values_at(['a','b','c','d','e'], [0, "2-3"])
+
+Would return ['a','c','d'].
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "values_at(): Wrong number of " +
+ "arguments given (#{arguments.size} for 2)") if arguments.size < 2
+
+ array = arguments.shift
+
+ unless array.is_a?(Array)
+ raise(Puppet::ParseError, 'values_at(): Requires array to work with')
+ end
+
+ indices = [arguments.shift].flatten() # Get them all ... Pokemon ...
+
+ if not indices or indices.empty?
+ raise(Puppet::ParseError, 'values_at(): You must provide ' +
+ 'at least one positive index to collect')
+ end
+
+ result = []
+ indices_list = []
+
+ indices.each do |i|
+ if m = i.match(/^(\d+)(\.\.\.?|\-)(\d+)$/)
+ start = m[1].to_i
+ stop = m[3].to_i
+
+ type = m[2]
+
+ if start > stop
+ raise(Puppet::ParseError, 'values_at(): Stop index in ' +
+ 'given indices range is smaller than the start index')
+ elsif stop > array.size - 1 # First element is at index 0 is it not?
+ raise(Puppet::ParseError, 'values_at(): Stop index in ' +
+ 'given indices range exceeds array size')
+ end
+
+ range = case type
+ when /^(\.\.|\-)$/ then (start .. stop)
+ when /^(\.\.\.)$/ then (start ... stop) # Exclusive of last element ...
+ end
+
+ range.each { |i| indices_list << i.to_i }
+ else
+ # Only positive numbers allowed in this case ...
+ if not i.match(/^\d+$/)
+ raise(Puppet::ParseError, 'values_at(): Unknown format ' +
+ 'of given index')
+ end
+
+ # In Puppet numbers are often string-encoded ...
+ i = i.to_i
+
+ if i > array.size - 1 # Same story. First element is at index 0 ...
+ raise(Puppet::ParseError, 'values_at(): Given index ' +
+ 'exceeds array size')
+ end
+
+ indices_list << i
+ end
+ end
+
+ # We remove nil values as they make no sense in Puppet DSL ...
+ result = indices_list.collect { |i| array[i] }.compact
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/parser/functions/zip.rb b/puppet/stdlib/lib/puppet/parser/functions/zip.rb
new file mode 100644
index 0000000000..2b56e9ca07
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/parser/functions/zip.rb
@@ -0,0 +1,65 @@
+#
+# zip.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:zip, :type => :rvalue, :doc => <<-EOS
+Takes one element from first array and merges corresponding elements from second array. This generates a sequence of n-element arrays, where n is one more than the count of arguments.
+
+*Example:*
+
+ zip(['1','2','3'],['4','5','6'])
+
+Would result in:
+
+ ["1", "4"], ["2", "5"], ["3", "6"]
+ EOS
+ ) do |arguments|
+
+ # Technically we support three arguments but only first is mandatory ...
+ raise(Puppet::ParseError, "zip(): Wrong number of arguments " +
+ "given (#{arguments.size} for 2)") if arguments.size < 2
+
+ a = arguments[0]
+ b = arguments[1]
+
+ unless a.is_a?(Array) and b.is_a?(Array)
+ raise(Puppet::ParseError, 'zip(): Requires array to work with')
+ end
+
+ flatten = arguments[2] if arguments[2]
+
+ if flatten
+ klass = flatten.class
+
+ # We can have either true or false, or string which resembles boolean ...
+ unless [FalseClass, TrueClass, String].include?(klass)
+ raise(Puppet::ParseError, 'zip(): Requires either ' +
+ 'boolean or string to work with')
+ end
+
+ if flatten.is_a?(String)
+ # We consider all the yes, no, y, n and so on too ...
+ flatten = case flatten
+ #
+ # This is how undef looks like in Puppet ...
+ # We yield false in this case.
+ #
+ when /^$/, '' then false # Empty string will be false ...
+ when /^(1|t|y|true|yes)$/ then true
+ when /^(0|f|n|false|no)$/ then false
+ when /^(undef|undefined)$/ then false # This is not likely to happen ...
+ else
+ raise(Puppet::ParseError, 'zip(): Unknown type of boolean given')
+ end
+ end
+ end
+
+ result = a.zip(b)
+ result = flatten ? result.flatten : result
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/stdlib/lib/puppet/provider/file_line/ruby.rb b/puppet/stdlib/lib/puppet/provider/file_line/ruby.rb
new file mode 100644
index 0000000000..a3219d3d4d
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/provider/file_line/ruby.rb
@@ -0,0 +1,59 @@
+
+Puppet::Type.type(:file_line).provide(:ruby) do
+
+ def exists?
+ lines.find do |line|
+ line.chomp == resource[:line].chomp
+ end
+ end
+
+ def create
+ if resource[:match]
+ handle_create_with_match()
+ else
+ handle_create_without_match()
+ end
+ end
+
+ def destroy
+ local_lines = lines
+ File.open(resource[:path],'w') do |fh|
+ fh.write(local_lines.reject{|l| l.chomp == resource[:line] }.join(''))
+ end
+ end
+
+ private
+ def lines
+ # If this type is ever used with very large files, we should
+ # write this in a different way, using a temp
+ # file; for now assuming that this type is only used on
+ # small-ish config files that can fit into memory without
+ # too much trouble.
+ @lines ||= File.readlines(resource[:path])
+ end
+
+ def handle_create_with_match()
+ regex = resource[:match] ? Regexp.new(resource[:match]) : nil
+ match_count = lines.select { |l| regex.match(l) }.size
+ if match_count > 1
+ raise Puppet::Error, "More than one line in file '#{resource[:path]}' matches pattern '#{resource[:match]}'"
+ end
+ File.open(resource[:path], 'w') do |fh|
+ lines.each do |l|
+ fh.puts(regex.match(l) ? resource[:line] : l)
+ end
+
+ if (match_count == 0)
+ fh.puts(resource[:line])
+ end
+ end
+ end
+
+ def handle_create_without_match
+ File.open(resource[:path], 'a') do |fh|
+ fh.puts resource[:line]
+ end
+ end
+
+
+end
diff --git a/puppet/stdlib/lib/puppet/type/anchor.rb b/puppet/stdlib/lib/puppet/type/anchor.rb
new file mode 100644
index 0000000000..fe1e5aa195
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/type/anchor.rb
@@ -0,0 +1,46 @@
+Puppet::Type.newtype(:anchor) do
+ desc <<-'ENDOFDESC'
+ A simple resource type intended to be used as an anchor in a composite class.
+
+ In Puppet 2.6, when a class declares another class, the resources in the
+ interior class are not contained by the exterior class. This interacts badly
+ with the pattern of composing complex modules from smaller classes, as it
+ makes it impossible for end users to specify order relationships between the
+ exterior class and other modules.
+
+ The anchor type lets you work around this. By sandwiching any interior
+ classes between two no-op resources that _are_ contained by the exterior
+ class, you can ensure that all resources in the module are contained.
+
+ class ntp {
+ # These classes will have the correct order relationship with each
+ # other. However, without anchors, they won't have any order
+ # relationship to Class['ntp'].
+ class { 'ntp::package': }
+ -> class { 'ntp::config': }
+ -> class { 'ntp::service': }
+
+ # These two resources "anchor" the composed classes within the ntp
+ # class.
+ anchor { 'ntp::begin': } -> Class['ntp::package']
+ Class['ntp::service'] -> anchor { 'ntp::end': }
+ }
+
+ This allows the end user of the ntp module to establish require and before
+ relationships with Class['ntp']:
+
+ class { 'ntp': } -> class { 'mcollective': }
+ class { 'mcollective': } -> class { 'ntp': }
+
+ ENDOFDESC
+
+ newparam :name do
+ desc "The name of the anchor resource."
+ end
+
+ def refresh
+ # We don't do anything with them, but we need this to
+ # show that we are "refresh aware" and not break the
+ # chain of propagation.
+ end
+end
diff --git a/puppet/stdlib/lib/puppet/type/file_line.rb b/puppet/stdlib/lib/puppet/type/file_line.rb
new file mode 100644
index 0000000000..f71a4bc7b6
--- /dev/null
+++ b/puppet/stdlib/lib/puppet/type/file_line.rb
@@ -0,0 +1,70 @@
+Puppet::Type.newtype(:file_line) do
+
+ desc <<-EOT
+ Ensures that a given line is contained within a file. The implementation
+ matches the full line, including whitespace at the beginning and end. If
+ the line is not contained in the given file, Puppet will add the line to
+ ensure the desired state. Multiple resources may be declared to manage
+ multiple lines in the same file.
+
+ Example:
+
+ file_line { 'sudo_rule':
+ path => '/etc/sudoers',
+ line => '%sudo ALL=(ALL) ALL',
+ }
+ file_line { 'sudo_rule_nopw':
+ path => '/etc/sudoers',
+ line => '%sudonopw ALL=(ALL) NOPASSWD: ALL',
+ }
+
+ In this example, Puppet will ensure both of the specified lines are
+ contained in the file /etc/sudoers.
+
+ EOT
+
+ ensurable do
+ defaultvalues
+ defaultto :present
+ end
+
+ newparam(:name, :namevar => true) do
+ desc 'An arbitrary name used as the identity of the resource.'
+ end
+
+ newparam(:match) do
+ desc 'An optional regular expression to run against existing lines in the file;\n' +
+ 'if a match is found, we replace that line rather than adding a new line.'
+ end
+
+ newparam(:line) do
+ desc 'The line to be appended to the file located by the path parameter.'
+ end
+
+ newparam(:path) do
+ desc 'The file Puppet will ensure contains the line specified by the line parameter.'
+ validate do |value|
+ unless (Puppet.features.posix? and value =~ /^\//) or (Puppet.features.microsoft_windows? and (value =~ /^.:\// or value =~ /^\/\/[^\/]+\/[^\/]+/))
+ raise(Puppet::Error, "File paths must be fully qualified, not '#{value}'")
+ end
+ end
+ end
+
+ # Autorequire the file resource if it's being managed
+ autorequire(:file) do
+ self[:path]
+ end
+
+ validate do
+ unless self[:line] and self[:path]
+ raise(Puppet::Error, "Both line and path are required attributes")
+ end
+
+ if (self[:match])
+ unless Regexp.new(self[:match]).match(self[:line])
+ raise(Puppet::Error, "When providing a 'match' parameter, the value must be a regex that matches against the value of your 'line' parameter")
+ end
+ end
+
+ end
+end
diff --git a/puppet/stdlib/manifests/init.pp b/puppet/stdlib/manifests/init.pp
new file mode 100644
index 0000000000..500ad770d5
--- /dev/null
+++ b/puppet/stdlib/manifests/init.pp
@@ -0,0 +1,20 @@
+# Class: stdlib
+#
+# This module manages stdlib. Most of stdlib's features are automatically
+# loaded by Puppet, but this class should be declared in order to use the
+# standardized run stages.
+#
+# Parameters: none
+#
+# Actions:
+#
+# Declares all other classes in the stdlib module. Currently, this consists
+# of stdlib::stages.
+#
+# Requires: nothing
+#
+class stdlib {
+
+ class { 'stdlib::stages': }
+
+}
diff --git a/puppet/stdlib/manifests/stages.pp b/puppet/stdlib/manifests/stages.pp
new file mode 100644
index 0000000000..eb15fd650d
--- /dev/null
+++ b/puppet/stdlib/manifests/stages.pp
@@ -0,0 +1,43 @@
+# Class: stdlib::stages
+#
+# This class manages a standard set of run stages for Puppet. It is managed by
+# the stdlib class, and should not be declared independently.
+#
+# The high level stages are (in order):
+#
+# * setup
+# * main
+# * runtime
+# * setup_infra
+# * deploy_infra
+# * setup_app
+# * deploy_app
+# * deploy
+#
+# Parameters: none
+#
+# Actions:
+#
+# Declares various run-stages for deploying infrastructure,
+# language runtimes, and application layers.
+#
+# Requires: nothing
+#
+# Sample Usage:
+#
+# node default {
+# include stdlib
+# class { java: stage => 'runtime' }
+# }
+#
+class stdlib::stages {
+
+ stage { 'setup': before => Stage['main'] }
+ stage { 'runtime': require => Stage['main'] }
+ -> stage { 'setup_infra': }
+ -> stage { 'deploy_infra': }
+ -> stage { 'setup_app': }
+ -> stage { 'deploy_app': }
+ -> stage { 'deploy': }
+
+}
diff --git a/puppet/stdlib/metadata.json b/puppet/stdlib/metadata.json
new file mode 100644
index 0000000000..5d3308e210
--- /dev/null
+++ b/puppet/stdlib/metadata.json
@@ -0,0 +1,270 @@
+{
+ "types": [
+ {
+ "doc": " A simple resource type intended to be used as an anchor in a composite class.\n\n In Puppet 2.6, when a class declares another class, the resources in the\n interior class are not contained by the exterior class. This interacts badly\n with the pattern of composing complex modules from smaller classes, as it\n makes it impossible for end users to specify order relationships between the\n exterior class and other modules.\n\n The anchor type lets you work around this. By sandwiching any interior\n classes between two no-op resources that _are_ contained by the exterior\n class, you can ensure that all resources in the module are contained.\n\n class ntp {\n # These classes will have the correct order relationship with each\n # other. However, without anchors, they won't have any order\n # relationship to Class['ntp'].\n class { 'ntp::package': }\n -> class { 'ntp::config': }\n -> class { 'ntp::service': }\n\n # These two resources \"anchor\" the composed classes within the ntp\n # class.\n anchor { 'ntp::begin': } -> Class['ntp::package']\n Class['ntp::service'] -> anchor { 'ntp::end': }\n }\n\n This allows the end user of the ntp module to establish require and before\n relationships with Class['ntp']:\n\n class { 'ntp': } -> class { 'mcollective': }\n class { 'mcollective': } -> class { 'ntp': }\n\n",
+ "parameters": [
+ {
+ "doc": "The name of the anchor resource.",
+ "name": "name"
+ }
+ ],
+ "name": "anchor",
+ "properties": [
+
+ ]
+ },
+ {
+ "doc": " Ensures that a given line is contained within a file. The implementation\n matches the full line, including whitespace at the beginning and end. If\n the line is not contained in the given file, Puppet will add the line to\n ensure the desired state. Multiple resources may be declared to manage\n multiple lines in the same file.\n\n Example:\n\n file_line { 'sudo_rule':\n path => '/etc/sudoers',\n line => '%sudo ALL=(ALL) ALL',\n }\n file_line { 'sudo_rule_nopw':\n path => '/etc/sudoers',\n line => '%sudonopw ALL=(ALL) NOPASSWD: ALL',\n }\n\n In this example, Puppet will ensure both of the specified lines are\n contained in the file /etc/sudoers.\n\n",
+ "providers": [
+ {
+ "doc": "",
+ "name": "ruby"
+ }
+ ],
+ "parameters": [
+ {
+ "doc": "An arbitrary name used as the identity of the resource.",
+ "name": "name"
+ },
+ {
+ "doc": "An optional regular expression to run against existing lines in the file;\\nif a match is found, we replace that line rather than adding a new line.",
+ "name": "match"
+ },
+ {
+ "doc": "The line to be appended to the file located by the path parameter.",
+ "name": "line"
+ },
+ {
+ "doc": "The file Puppet will ensure contains the line specified by the line parameter.",
+ "name": "path"
+ }
+ ],
+ "name": "file_line",
+ "properties": [
+ {
+ "doc": "The basic property that the resource should be in. Valid values are `present`, `absent`.",
+ "name": "ensure"
+ }
+ ]
+ }
+ ],
+ "license": "Apache 2.0",
+ "checksums": {
+ "spec/unit/puppet/parser/functions/uriescape_spec.rb": "8d9e15156d93fe29bfe91a2e83352ff4",
+ "Gemfile": "a7144ac8fdb2255ed7badb6b54f6c342",
+ "spec/unit/facter/root_home_spec.rb": "4f4c4236ac2368d2e27fd2f3eb606a19",
+ "spec/unit/puppet/parser/functions/size_spec.rb": "d126b696b21a8cd754d58f78ddba6f06",
+ "spec/unit/puppet/parser/functions/shuffle_spec.rb": "2141a54d2fb3cf725b88184d639677f4",
+ "spec/unit/puppet/parser/functions/validate_re_spec.rb": "b21292ad2f30c0d43ab2f0c2df0ba7d5",
+ "lib/puppet/parser/functions/flatten.rb": "25777b76f9719162a8bab640e5595b7a",
+ "lib/puppet/parser/functions/ensure_packages.rb": "ca852b2441ca44b91a984094de4e3afc",
+ "lib/puppet/parser/functions/validate_augeas.rb": "d4acca7b8a9fdada9ae39e5101902cc1",
+ "spec/unit/puppet/parser/functions/unique_spec.rb": "2df8b3b2edb9503943cb4dcb4a371867",
+ "tests/has_ip_network.pp": "abc05686797a776ea8c054657e6f7456",
+ "spec/fixtures/manifests/site.pp": "d41d8cd98f00b204e9800998ecf8427e",
+ "lib/puppet/parser/functions/defined_with_params.rb": "ffab4433d03f32b551f2ea024a2948fc",
+ "lib/puppet/parser/functions/size.rb": "8972d48c0f9e487d659bd7326b40b642",
+ "lib/puppet/parser/functions/has_ip_address.rb": "ee207f47906455a5aa49c4fb219dd325",
+ "lib/facter/util/puppet_settings.rb": "9f1d2593d0ae56bfca89d4b9266aeee1",
+ "spec/unit/puppet/parser/functions/any2array_spec.rb": "167e114cfa222de971bf8be141766b6a",
+ "spec/unit/facter/pe_required_facts_spec.rb": "0ec83db2a004a0d7f6395b34939c53b9",
+ "spec/unit/puppet/parser/functions/bool2num_spec.rb": "67c3055d5d4e4c9fbcaca82038a09081",
+ "lib/facter/root_home.rb": "f559294cceafcf70799339627d94871d",
+ "lib/puppet/parser/functions/loadyaml.rb": "2b912f257aa078e376d3b3f6a86c2a00",
+ "spec/unit/puppet/parser/functions/is_float_spec.rb": "171fc0e382d9856c2d8db2b70c9ec9cd",
+ "lib/puppet/type/anchor.rb": "bbd36bb49c3b554f8602d8d3df366c0c",
+ "lib/puppet/parser/functions/getparam.rb": "4dd7a0e35f4a3780dcfc9b19b4e0006e",
+ "lib/facter/facter_dot_d.rb": "b35b8b59ec579901444f984127f0b833",
+ "lib/puppet/parser/functions/strftime.rb": "e02e01a598ca5d7d6eee0ba22440304a",
+ "lib/puppet/parser/functions/max.rb": "f652fd0b46ef7d2fbdb42b141f8fdd1d",
+ "spec/spec_helper.rb": "4449b0cafd8f7b2fb440c0cdb0a1f2b3",
+ "lib/puppet/parser/functions/merge.rb": "52281fe881b762e2adfef20f58dc4180",
+ "lib/puppet/parser/functions/validate_slength.rb": "0ca530d1d3b45c3fe2d604c69acfc22f",
+ "spec/unit/puppet/parser/functions/suffix_spec.rb": "c3eed8e40066f2ad56264405c4192f2e",
+ "spec/unit/puppet/parser/functions/validate_bool_spec.rb": "32a580f280ba62bf17ccd30460d357bd",
+ "spec/unit/puppet/parser/functions/str2bool_spec.rb": "60e3eaea48b0f6efccc97010df7d912c",
+ "lib/puppet/parser/functions/reject.rb": "689f6a7c961a55fe9dcd240921f4c7f9",
+ "lib/puppet/parser/functions/delete.rb": "9b17b9f7f820adf02360147c1a2f4279",
+ "lib/puppet/parser/functions/strip.rb": "273d547c7b05c0598556464dfd12f5fd",
+ "lib/puppet/parser/functions/values.rb": "066a6e4170e5034edb9a80463dff2bb5",
+ "LICENSE": "38a048b9d82e713d4e1b2573e370a756",
+ "lib/puppet/parser/functions/is_array.rb": "875ca4356cb0d7a10606fb146b4a3d11",
+ "spec/unit/puppet/parser/functions/strip_spec.rb": "a01796bebbdabd3fad12b0662ea5966e",
+ "lib/puppet/parser/functions/swapcase.rb": "4902f38f0b9292afec66d40fee4b02ec",
+ "lib/puppet/parser/functions/has_ip_network.rb": "b4d726c8b2a0afac81ced8a3a28aa731",
+ "spec/unit/puppet/parser/functions/validate_array_spec.rb": "bcd231229554785c4270ca92ef99cb60",
+ "lib/puppet/parser/functions/validate_re.rb": "c6664b3943bc820415a43f16372dc2a9",
+ "lib/puppet/parser/functions/time.rb": "08d88d52abd1e230e3a2f82107545d48",
+ "lib/puppet/parser/functions/is_numeric.rb": "0a9bcc49e8f57af81bdfbb7e7c3a575c",
+ "spec/unit/puppet/parser/functions/merge_spec.rb": "a63c0bc2f812e27fbef570d834ef61ce",
+ "lib/puppet/parser/functions/count.rb": "9eb74eccd93e2b3c87fd5ea14e329eba",
+ "spec/unit/puppet/parser/functions/values_at_spec.rb": "de45fd8abbc4c037c3c4fac2dcf186f9",
+ "spec/monkey_patches/publicize_methods.rb": "ce2c98f38b683138c5ac649344a39276",
+ "spec/unit/puppet/parser/functions/is_hash_spec.rb": "408e121a5e30c4c5c4a0a383beb6e209",
+ "lib/puppet/parser/functions/chop.rb": "4691a56e6064b792ed4575e4ad3f3d20",
+ "spec/unit/puppet/parser/functions/validate_cmd_spec.rb": "538db08292a0ecc4cd902a14aaa55d74",
+ "spec/unit/puppet/parser/functions/is_integer_spec.rb": "a302cf1de5ccb494ca9614d2fc2b53c5",
+ "spec/functions/ensure_resource_spec.rb": "3423a445e13efc7663a71c6641d49d07",
+ "spec/unit/puppet/parser/functions/keys_spec.rb": "35cc2ed490dc68da6464f245dfebd617",
+ "manifests/init.pp": "f2ba5f36e7227ed87bbb69034fc0de8b",
+ "lib/puppet/parser/functions/dirname.rb": "bef7214eb89db3eb8f7ee5fc9dca0233",
+ "lib/puppet/parser/functions/validate_hash.rb": "e9cfaca68751524efe16ecf2f958a9a0",
+ "lib/puppet/parser/functions/join_keys_to_values.rb": "f29da49531228f6ca5b3aa0df00a14c2",
+ "spec/unit/puppet/parser/functions/delete_spec.rb": "0d84186ea618523b4b2a4ca0b5a09c9e",
+ "lib/puppet/parser/functions/validate_string.rb": "6afcbc51f83f0714348b8d61e06ea7eb",
+ "spec/unit/puppet/parser/functions/rstrip_spec.rb": "a408e933753c9c323a05d7079d32cbb3",
+ "spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb": "c67b71737bee9936f5261d41a37bad46",
+ "spec/unit/puppet/parser/functions/concat_spec.rb": "c21aaa84609f92290d5ffb2ce8ea4bf5",
+ "lib/puppet/parser/functions/unique.rb": "217ccce6d23235af92923f50f8556963",
+ "CHANGELOG": "344383410cb78409f0c59ecf38e8c21a",
+ "lib/puppet/parser/functions/member.rb": "541e67d06bc4155e79b00843a125e9bc",
+ "spec/unit/puppet/parser/functions/validate_string_spec.rb": "64a4f681084cba55775a070f7fab5e0c",
+ "lib/facter/puppet_vardir.rb": "c7ddc97e8a84ded3dd93baa5b9b3283d",
+ "lib/puppet/parser/functions/pick.rb": "2bede116a0651405c47e650bbf942abe",
+ "spec/unit/puppet/parser/functions/parseyaml_spec.rb": "65dfed872930ffe0d21954c15daaf498",
+ "lib/puppet/parser/functions/delete_at.rb": "6bc24b79390d463d8be95396c963381a",
+ "lib/puppet/parser/functions/zip.rb": "a80782461ed9465f0cd0c010936f1855",
+ "tests/file_line.pp": "67727539aa7b7dd76f06626fe734f7f7",
+ "lib/puppet/parser/functions/ensure_resource.rb": "3f68b8e17a16bfd01455cd73f8e324ba",
+ "lib/puppet/parser/functions/num2bool.rb": "605c12fa518c87ed2c66ae153e0686ce",
+ "spec/unit/puppet/parser/functions/grep_spec.rb": "78179537496a7150469e591a95e255d8",
+ "lib/puppet/parser/functions/keys.rb": "eb6ac815ea14fbf423580ed903ef7bad",
+ "spec/unit/puppet/parser/functions/num2bool_spec.rb": "8cd5b46b7c8e612dfae3362e3a68a5f9",
+ "lib/puppet/parser/functions/parsejson.rb": "e7f968c34928107b84cd0860daf50ab1",
+ "lib/puppet/parser/functions/is_mac_address.rb": "288bd4b38d4df42a83681f13e7eaaee0",
+ "lib/puppet/parser/functions/join.rb": "b28087823456ca5cf943de4a233ac77f",
+ "spec/unit/puppet/parser/functions/type_spec.rb": "422f2c33458fe9b0cc9614d16f7573ba",
+ "lib/puppet/parser/functions/downcase.rb": "9204a04c2a168375a38d502db8811bbe",
+ "spec/unit/puppet/parser/functions/validate_augeas_spec.rb": "1d5bcfbf97dc56b45734248a14358d4f",
+ "spec/unit/puppet/parser/functions/has_ip_address_spec.rb": "f53c7baeaf024ff577447f6c28c0f3a7",
+ "lib/puppet/parser/functions/is_function_available.rb": "88c63869cb5df3402bc9756a8d40c16d",
+ "lib/puppet/parser/functions/prefix.rb": "21fd6a2c1ee8370964346b3bfe829d2b",
+ "spec/watchr.rb": "b588ddf9ef1c19ab97aa892cc776da73",
+ "spec/unit/puppet/parser/functions/has_key_spec.rb": "3e4e730d98bbdfb88438b6e08e45868e",
+ "lib/puppet/parser/functions/values_at.rb": "094ac110ce9f7a5b16d0c80a0cf2243c",
+ "lib/puppet/parser/functions/fqdn_rotate.rb": "20743a138c56fc806a35cb7b60137dbc",
+ "lib/puppet/parser/functions/rstrip.rb": "8a0d69876bdbc88a2054ba41c9c38961",
+ "spec/unit/puppet/parser/functions/validate_slength_spec.rb": "a1b4d805149dc0143e9a57e43e1f84bf",
+ "spec/functions/ensure_packages_spec.rb": "935b4aec5ab36bdd0458c1a9b2a93ad5",
+ "lib/puppet/parser/functions/suffix.rb": "109279db4180441e75545dbd5f273298",
+ "lib/puppet/parser/functions/str2saltedsha512.rb": "49afad7b386be38ce53deaefef326e85",
+ "spec/unit/puppet/parser/functions/count_spec.rb": "db98ef89752a7112425f0aade10108e0",
+ "lib/puppet/parser/functions/hash.rb": "9d072527dfc7354b69292e9302906530",
+ "manifests/stages.pp": "cc6ed1751d334b0ea278c0335c7f0b5a",
+ "spec/unit/puppet/parser/functions/is_ip_address_spec.rb": "6040a9bae4e5c853966148b634501157",
+ "spec/unit/facter/pe_version_spec.rb": "ef031cca838f36f99b1dab3259df96a5",
+ "spec/unit/puppet/parser/functions/get_module_path_spec.rb": "b7ea196f548b1a9a745ab6671295ab27",
+ "lib/puppet/parser/functions/is_integer.rb": "a50ebc15c30bffd759e4a6f8ec6a0cf3",
+ "lib/puppet/parser/functions/reverse.rb": "1386371c0f5301055fdf99079e862b3e",
+ "spec/unit/puppet/parser/functions/has_interface_with_spec.rb": "7c16d731c518b434c81b8cb2227cc916",
+ "README_SPECS.markdown": "82bb4c6abbb711f40778b162ec0070c1",
+ "spec/unit/puppet/parser/functions/is_domain_name_spec.rb": "8eed3a9eb9334bf6a473ad4e2cabc2ec",
+ "spec/unit/puppet/parser/functions/join_spec.rb": "c3b50c39390a86b493511be2c6722235",
+ "lib/puppet/parser/functions/chomp.rb": "719d46923d75251f7b6b68b6e015cccc",
+ "lib/puppet/parser/functions/is_string.rb": "2bd9a652bbb2668323eee6c57729ff64",
+ "spec/unit/puppet/parser/functions/is_array_spec.rb": "8c020af9c360abdbbf1ba887bb26babe",
+ "Modulefile": "351bba73290cd526ca7bacd4c7d250dc",
+ "spec/unit/puppet/parser/functions/reject_spec.rb": "8e16c9f064870e958b6278261e480954",
+ "spec/unit/puppet/type/file_line_spec.rb": "d9f4e08e8b98e565a07f1b995593fa89",
+ "spec/unit/puppet/parser/functions/lstrip_spec.rb": "1fc2c2d80b5f724a358c3cfeeaae6249",
+ "lib/puppet/parser/functions/type.rb": "62f914d6c90662aaae40c5539701be60",
+ "lib/puppet/parser/functions/shuffle.rb": "6445e6b4dc62c37b184a60eeaf34414b",
+ "lib/puppet/parser/functions/has_key.rb": "7cd9728c38f0b0065f832dabd62b0e7e",
+ "lib/puppet/parser/functions/concat.rb": "f28a09811ff4d19bb5e7a540e767d65c",
+ "spec/unit/puppet/parser/functions/capitalize_spec.rb": "82a4209a033fc88c624f708c12e64e2a",
+ "tests/init.pp": "1d98070412c76824e66db4b7eb74d433",
+ "lib/puppet/provider/file_line/ruby.rb": "a445a57f9b884037320ea37307dbc92b",
+ "tests/has_ip_address.pp": "93ce02915f67ddfb43a049b2b84ef391",
+ "spec/unit/puppet/parser/functions/min_spec.rb": "bf80bf58261117bb24392670b624a611",
+ "lib/puppet/parser/functions/to_bytes.rb": "83f23c33adbfa42b2a9d9fc2db3daeb4",
+ "lib/puppet/parser/functions/sort.rb": "504b033b438461ca4f9764feeb017833",
+ "lib/puppet/parser/functions/capitalize.rb": "14481fc8c7c83fe002066ebcf6722f17",
+ "lib/puppet/type/file_line.rb": "3e8222cb58f3503b3ea7de3647c602a0",
+ "lib/puppet/parser/functions/has_interface_with.rb": "8d3ebca805dc6edb88b6b7a13d404787",
+ "spec/functions/getparam_spec.rb": "122f37cf9ec7489f1dae10db39c871b5",
+ "Rakefile": "f37e6131fe7de9a49b09d31596f5fbf1",
+ "spec/unit/puppet/parser/functions/downcase_spec.rb": "b0197829512f2e92a2d2b06ce8e2226f",
+ "spec/unit/puppet/parser/functions/max_spec.rb": "5562bccc643443af7e4fa7c9d1e52b8b",
+ "lib/puppet/parser/functions/validate_absolute_path.rb": "385137ac24a2dec6cecc4e6ea75be442",
+ "spec/unit/puppet/parser/functions/getvar_spec.rb": "842bf88d47077a9ae64097b6e39c3364",
+ "spec/unit/puppet/parser/functions/sort_spec.rb": "7039cd230a94e95d9d1de2e1094acae2",
+ "spec/unit/puppet/parser/functions/strftime_spec.rb": "bf140883ecf3254277306fa5b25f0344",
+ "spec/unit/puppet/parser/functions/is_mac_address_spec.rb": "644cd498b426ff2f9ea9cbc5d8e141d7",
+ "spec/unit/puppet/parser/functions/empty_spec.rb": "028c30267d648a172d8a81a9262c3abe",
+ "lib/puppet/parser/functions/is_domain_name.rb": "fba9f855df3bbf90d72dfd5201f65d2b",
+ "lib/puppet/parser/functions/get_module_path.rb": "d4bf50da25c0b98d26b75354fa1bcc45",
+ "spec/unit/puppet/provider/file_line/ruby_spec.rb": "e8cd7432739cb212d40a9148523bd4d7",
+ "spec/unit/puppet/parser/functions/reverse_spec.rb": "48169990e59081ccbd112b6703418ce4",
+ "spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb": "1de174be8835ba6fef86b590887bb2cc",
+ "spec/unit/puppet/parser/functions/prefix_spec.rb": "16a95b321d76e773812693c80edfbe36",
+ "spec/spec.opts": "a600ded995d948e393fbe2320ba8e51c",
+ "spec/monkey_patches/alias_should_to_must.rb": "7cd4065c63f06f1ab3aaa1c5f92af947",
+ "lib/puppet/parser/functions/uriescape.rb": "9ebc34f1b2f319626512b8cd7cde604c",
+ "lib/puppet/parser/functions/floor.rb": "c5a960e9714810ebb99198ff81a11a3b",
+ "lib/puppet/parser/functions/empty.rb": "ae92905c9d94ddca30bf56b7b1dabedf",
+ "spec/unit/puppet/parser/functions/range_spec.rb": "91d69115dea43f62a2dca9a10467d836",
+ "tests/has_interface_with.pp": "59c98b4af0d39fc11d1ef4c7a6dc8f7a",
+ "spec/unit/puppet/parser/functions/is_function_available.rb": "069ef7490eba66424cab75444f36828a",
+ "README_DEVELOPER.markdown": "220a8b28521b5c5d2ea87c4ddb511165",
+ "spec/unit/puppet/parser/functions/flatten_spec.rb": "583c9a70f93e492cfb22ffa1811f6aa0",
+ "lib/puppet/parser/functions/upcase.rb": "a5744a74577cfa136fca2835e75888d3",
+ "lib/puppet/parser/functions/str2bool.rb": "c822a8944747f5624b13f2da0df8db21",
+ "lib/puppet/parser/functions/is_hash.rb": "8c7d9a05084dab0389d1b779c8a05b1a",
+ "lib/puppet/parser/functions/abs.rb": "32161bd0435fdfc2aec2fc559d2b454b",
+ "spec/unit/puppet/parser/functions/validate_hash_spec.rb": "8529c74051ceb71e6b1b97c9cecdf625",
+ "spec/unit/puppet/parser/functions/member_spec.rb": "067c60985efc57022ca1c5508d74d77f",
+ "README.markdown": "b63097a958f22abf7999d475a6a4d32a",
+ "spec/unit/puppet/parser/functions/values_spec.rb": "0ac9e141ed1f612d7cc224f747b2d1d9",
+ "lib/puppet/parser/functions/validate_cmd.rb": "0319a15d24fd077ebabc2f79969f6ab5",
+ "lib/puppet/parser/functions/is_float.rb": "f1b0d333061d31bf0c25bd4c33dc134b",
+ "lib/puppet/parser/functions/bool2num.rb": "8e627eee990e811e35e7e838c586bd77",
+ "lib/puppet/parser/functions/validate_bool.rb": "4ddffdf5954b15863d18f392950b88f4",
+ "lib/puppet/parser/functions/grep.rb": "5682995af458b05f3b53dd794c4bf896",
+ "spec/unit/puppet/parser/functions/upcase_spec.rb": "813668919bc62cdd1d349dafc19fbbb3",
+ "spec/unit/puppet/parser/functions/parsejson_spec.rb": "37ab84381e035c31d6a3dd9bf73a3d53",
+ "spec/unit/puppet/parser/functions/squeeze_spec.rb": "df5b349c208a9a2a4d4b8e6d9324756f",
+ "spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb": "07839082d24d5a7628fd5bce6c8b35c3",
+ "spec/unit/puppet/parser/functions/chop_spec.rb": "4e9534d25b952b261c9f46add677c390",
+ "lib/puppet/parser/functions/squeeze.rb": "541f85b4203b55c9931d3d6ecd5c75f8",
+ "lib/puppet/parser/functions/lstrip.rb": "210b103f78622e099f91cc2956b6f741",
+ "spec/unit/puppet/type/anchor_spec.rb": "a5478a72a7fab2d215f39982a9230c18",
+ "lib/facter/pe_version.rb": "4a9353952963b011759f3e6652a10da5",
+ "spec/unit/puppet/parser/functions/hash_spec.rb": "826337a92d8f7a189b7ac19615db0ed7",
+ "spec/unit/puppet/parser/functions/floor_spec.rb": "d01ef7dfe0245d7a0a73d7df13cb02e3",
+ "spec/unit/puppet/parser/functions/time_spec.rb": "b6d0279062779efe5153fe5cfafc5bbd",
+ "spec/unit/puppet/parser/functions/swapcase_spec.rb": "0660ce8807608cc8f98ad1edfa76a402",
+ "lib/puppet/parser/functions/validate_array.rb": "72b29289b8af1cfc3662ef9be78911b8",
+ "lib/puppet/parser/functions/is_ip_address.rb": "a714a736c1560e8739aaacd9030cca00",
+ "lib/puppet/parser/functions/getvar.rb": "10bf744212947bc6a7bfd2c9836dbd23",
+ "RELEASE_PROCESS.markdown": "94b92bc99ac4106ba1a74d5c04e520f9",
+ "spec/classes/anchor_spec.rb": "695d65275c3ac310d7fa23b91f8bbb4a",
+ "lib/puppet/parser/functions/any2array.rb": "a81e71d6b67a551d38770ba9a1948a75",
+ "spec/functions/defined_with_params_spec.rb": "3bdfac38e3d6f06140ff2e926f4ebed2",
+ "spec/unit/puppet/parser/functions/pick_spec.rb": "aba6247d3925e373272fca6768fd5403",
+ "spec/unit/puppet/parser/functions/to_bytes_spec.rb": "80aaf68cf7e938e46b5278c1907af6be",
+ "spec/unit/puppet/parser/functions/is_string_spec.rb": "5c015d8267de852da3a12b984e077092",
+ "spec/unit/puppet/parser/functions/abs_spec.rb": "0a5864a29a8e9e99acc483268bd5917c",
+ "spec/unit/facter/util/puppet_settings_spec.rb": "345bcbef720458e25be0190b7638e4d9",
+ "spec/unit/puppet/parser/functions/zip_spec.rb": "06a86e4e70d2aea63812582aae1d26c4",
+ "spec/unit/puppet/parser/functions/dirname_spec.rb": "1d7cf70468c2cfa6dacfc75935322395",
+ "spec/unit/puppet/parser/functions/delete_at_spec.rb": "5a4287356b5bd36a6e4c100421215b8e",
+ "spec/unit/puppet/parser/functions/chomp_spec.rb": "3cd8e2fe6b12efeffad94cce5b693b7c",
+ "spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb": "7c7937411b7fe4bb944c0c022d3a96b0",
+ "lib/puppet/parser/functions/range.rb": "033048bba333fe429e77e0f2e91db25f",
+ "lib/puppet/parser/functions/parseyaml.rb": "00f10ec1e2b050e23d80c256061ebdd7",
+ "spec/unit/puppet/parser/functions/is_numeric_spec.rb": "5f08148803b6088c27b211c446ad3658",
+ "spec/unit/puppet/parser/functions/has_ip_network_spec.rb": "885ea8a4c987b735d683b742bf846cb1",
+ "lib/puppet/parser/functions/min.rb": "0d2a1b7e735ab251c5469e735fa3f4c6",
+ "CONTRIBUTING.md": "fdddc4606dc3b6949e981e6bf50bc8e5"
+ },
+ "version": "4.1.0",
+ "description": "Standard Library for Puppet Modules",
+ "source": "git://github.com/puppetlabs/puppetlabs-stdlib.git",
+ "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
+ "summary": "Puppet Module Standard Library",
+ "dependencies": [
+
+ ],
+ "author": "puppetlabs",
+ "name": "puppetlabs-stdlib"
+}
\ No newline at end of file
diff --git a/puppet/stdlib/spec/classes/anchor_spec.rb b/puppet/stdlib/spec/classes/anchor_spec.rb
new file mode 100644
index 0000000000..2dd17de9ad
--- /dev/null
+++ b/puppet/stdlib/spec/classes/anchor_spec.rb
@@ -0,0 +1,32 @@
+require 'puppet'
+require 'rspec-puppet'
+
+describe "anchorrefresh" do
+ let(:node) { 'testhost.example.com' }
+ let :pre_condition do
+ <<-ANCHORCLASS
+class anchored {
+ anchor { 'anchored::begin': }
+ ~> anchor { 'anchored::end': }
+}
+
+class anchorrefresh {
+ notify { 'first': }
+ ~> class { 'anchored': }
+ ~> anchor { 'final': }
+}
+ ANCHORCLASS
+ end
+
+ def apply_catalog_and_return_exec_rsrc
+ catalog = subject.to_ral
+ transaction = catalog.apply
+ transaction.resource_status("Anchor[final]")
+ end
+
+ it 'propagates events through the anchored class' do
+ resource = apply_catalog_and_return_exec_rsrc
+
+ expect(resource.restarted).to eq(true)
+ end
+end
diff --git a/puppet/puppet-apt/files/empty/.placeholder b/puppet/stdlib/spec/fixtures/manifests/site.pp
similarity index 100%
rename from puppet/puppet-apt/files/empty/.placeholder
rename to puppet/stdlib/spec/fixtures/manifests/site.pp
diff --git a/puppet/stdlib/spec/functions/defined_with_params_spec.rb b/puppet/stdlib/spec/functions/defined_with_params_spec.rb
new file mode 100644
index 0000000000..28dbab3119
--- /dev/null
+++ b/puppet/stdlib/spec/functions/defined_with_params_spec.rb
@@ -0,0 +1,37 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+require 'rspec-puppet'
+describe 'defined_with_params' do
+ describe 'when a resource is not specified' do
+ it { should run.with_params().and_raise_error(ArgumentError) }
+ end
+ describe 'when compared against a resource with no attributes' do
+ let :pre_condition do
+ 'user { "dan": }'
+ end
+ it do
+ should run.with_params('User[dan]', {}).and_return(true)
+ should run.with_params('User[bob]', {}).and_return(false)
+ should run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false)
+ end
+ end
+
+ describe 'when compared against a resource with attributes' do
+ let :pre_condition do
+ 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}'
+ end
+ it do
+ should run.with_params('User[dan]', {}).and_return(true)
+ should run.with_params('User[dan]', '').and_return(true)
+ should run.with_params('User[dan]', {'ensure' => 'present'}
+ ).and_return(true)
+ should run.with_params('User[dan]',
+ {'ensure' => 'present', 'managehome' => false}
+ ).and_return(true)
+ should run.with_params('User[dan]',
+ {'ensure' => 'absent', 'managehome' => false}
+ ).and_return(false)
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/functions/ensure_packages_spec.rb b/puppet/stdlib/spec/functions/ensure_packages_spec.rb
new file mode 100644
index 0000000000..1c2a328e4e
--- /dev/null
+++ b/puppet/stdlib/spec/functions/ensure_packages_spec.rb
@@ -0,0 +1,42 @@
+#! /usr/bin/env ruby
+
+require 'spec_helper'
+require 'rspec-puppet'
+
+describe 'ensure_packages' do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ describe 'argument handling' do
+ it 'fails with no arguments' do
+ should run.with_params().and_raise_error(Puppet::ParseError)
+ end
+ it 'requires an array' do
+ lambda { scope.function_ensure_packages([['foo']]) }.should_not raise_error
+ end
+ it 'fails when given a string' do
+ should run.with_params('foo').and_raise_error(Puppet::ParseError)
+ end
+ end
+
+ context 'given a catalog containing Package[puppet]{ensure => absent}' do
+ let :pre_condition do
+ 'package { puppet: ensure => absent }'
+ end
+
+ # NOTE: should run.with_params has the side effect of making the compiler
+ # available to the test harness.
+ it 'has no effect on Package[puppet]' do
+ should run.with_params(['puppet'])
+ rsrc = compiler.catalog.resource('Package[puppet]')
+ rsrc.to_hash.should == {:ensure => "absent"}
+ end
+ end
+
+ context 'given a clean catalog' do
+ it 'declares package resources with ensure => present' do
+ should run.with_params(['facter'])
+ rsrc = compiler.catalog.resource('Package[facter]')
+ rsrc.to_hash.should == {:name => "facter", :ensure => "present"}
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/functions/ensure_resource_spec.rb b/puppet/stdlib/spec/functions/ensure_resource_spec.rb
new file mode 100644
index 0000000000..2e8aefc52d
--- /dev/null
+++ b/puppet/stdlib/spec/functions/ensure_resource_spec.rb
@@ -0,0 +1,64 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+require 'rspec-puppet'
+describe 'ensure_resource' do
+ describe 'when a type or title is not specified' do
+ it { should run.with_params().and_raise_error(ArgumentError) }
+ it { should run.with_params(['type']).and_raise_error(ArgumentError) }
+ end
+
+ describe 'when compared against a resource with no attributes' do
+ let :pre_condition do
+ 'user { "dan": }'
+ end
+ it "should contain the the ensured resources" do
+ subject.should run.with_params('user', 'dan', {})
+ compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]'
+ end
+ end
+
+ describe 'when compared against a resource with attributes' do
+ let :pre_condition do
+ 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}'
+ end
+ # these first three should not fail
+ it { should run.with_params('User', 'dan', {}) }
+ it { should run.with_params('User', 'dan', '') }
+ it { should run.with_params('User', 'dan', {'ensure' => 'present'}) }
+ it { should run.with_params('User', 'dan', {'ensure' => 'present', 'managehome' => false}) }
+ # test that this fails
+ it { should run.with_params('User', 'dan', {'ensure' => 'absent', 'managehome' => false}).and_raise_error(Puppet::Error) }
+ end
+
+ describe 'when an array of new resources are passed in' do
+ it "should contain the ensured resources" do
+ subject.should run.with_params('User', ['dan', 'alex'], {})
+ compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]'
+ compiler.catalog.resource('User[alex]').to_s.should == 'User[alex]'
+ end
+ end
+
+ describe 'when an array of existing resources is compared against existing resources' do
+ let :pre_condition do
+ 'user { "dan": ensure => present; "alex": ensure => present }'
+ end
+ it "should return the existing resources" do
+ subject.should run.with_params('User', ['dan', 'alex'], {})
+ compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]'
+ compiler.catalog.resource('User[alex]').to_s.should == 'User[alex]'
+ end
+ end
+
+ describe 'when compared against existing resources with attributes' do
+ let :pre_condition do
+ 'user { "dan": ensure => present; "alex": ensure => present }'
+ end
+ # These should not fail
+ it { should run.with_params('User', ['dan', 'alex'], {}) }
+ it { should run.with_params('User', ['dan', 'alex'], '') }
+ it { should run.with_params('User', ['dan', 'alex'], {'ensure' => 'present'}) }
+ # This should fail
+ it { should run.with_params('User', ['dan', 'alex'], {'ensure' => 'absent'}).and_raise_error(Puppet::Error) }
+ end
+end
diff --git a/puppet/stdlib/spec/functions/getparam_spec.rb b/puppet/stdlib/spec/functions/getparam_spec.rb
new file mode 100644
index 0000000000..d9c50a6c21
--- /dev/null
+++ b/puppet/stdlib/spec/functions/getparam_spec.rb
@@ -0,0 +1,34 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+require 'rspec-puppet'
+describe 'getparam' do
+ describe 'when a resource is not specified' do
+ it do
+ should run.with_params().and_raise_error(ArgumentError)
+ should run.with_params('User[dan]').and_raise_error(ArgumentError)
+ should run.with_params('User[dan]', {}).and_raise_error(ArgumentError)
+ should run.with_params('User[dan]', '').and_return('')
+ end
+ end
+ describe 'when compared against a resource with no params' do
+ let :pre_condition do
+ 'user { "dan": }'
+ end
+ it do
+ should run.with_params('User[dan]', 'shell').and_return('')
+ end
+ end
+
+ describe 'when compared against a resource with params' do
+ let :pre_condition do
+ 'user { "dan": ensure => present, shell => "/bin/sh", managehome => false}'
+ end
+ it do
+ should run.with_params('User[dan]', 'shell').and_return('/bin/sh')
+ should run.with_params('User[dan]', '').and_return('')
+ should run.with_params('User[dan]', 'ensure').and_return('present')
+ should run.with_params('User[dan]', 'managehome').and_return(false)
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/monkey_patches/alias_should_to_must.rb b/puppet/stdlib/spec/monkey_patches/alias_should_to_must.rb
new file mode 100755
index 0000000000..1a1111799f
--- /dev/null
+++ b/puppet/stdlib/spec/monkey_patches/alias_should_to_must.rb
@@ -0,0 +1,8 @@
+require 'rspec'
+
+class Object
+ # This is necessary because the RAL has a 'should'
+ # method.
+ alias :must :should
+ alias :must_not :should_not
+end
diff --git a/puppet/stdlib/spec/monkey_patches/publicize_methods.rb b/puppet/stdlib/spec/monkey_patches/publicize_methods.rb
new file mode 100755
index 0000000000..f3a1abf409
--- /dev/null
+++ b/puppet/stdlib/spec/monkey_patches/publicize_methods.rb
@@ -0,0 +1,10 @@
+# Some monkey-patching to allow us to test private methods.
+class Class
+ def publicize_methods(*methods)
+ saved_private_instance_methods = methods.empty? ? self.private_instance_methods : methods
+
+ self.class_eval { public(*saved_private_instance_methods) }
+ yield
+ self.class_eval { private(*saved_private_instance_methods) }
+ end
+end
diff --git a/puppet/stdlib/spec/spec.opts b/puppet/stdlib/spec/spec.opts
new file mode 100644
index 0000000000..91cd6427ed
--- /dev/null
+++ b/puppet/stdlib/spec/spec.opts
@@ -0,0 +1,6 @@
+--format
+s
+--colour
+--loadby
+mtime
+--backtrace
diff --git a/puppet/stdlib/spec/spec_helper.rb b/puppet/stdlib/spec/spec_helper.rb
new file mode 100644
index 0000000000..931d35c846
--- /dev/null
+++ b/puppet/stdlib/spec/spec_helper.rb
@@ -0,0 +1,28 @@
+dir = File.expand_path(File.dirname(__FILE__))
+$LOAD_PATH.unshift File.join(dir, 'lib')
+
+# Don't want puppet getting the command line arguments for rake or autotest
+ARGV.clear
+
+require 'puppet'
+require 'facter'
+require 'mocha'
+gem 'rspec', '>=2.0.0'
+require 'rspec/expectations'
+
+require 'puppetlabs_spec_helper/module_spec_helper'
+
+RSpec.configure do |config|
+ # FIXME REVISIT - We may want to delegate to Facter like we do in
+ # Puppet::PuppetSpecInitializer.initialize_via_testhelper(config) because
+ # this behavior is a duplication of the spec_helper in Facter.
+ config.before :each do
+ # Ensure that we don't accidentally cache facts and environment between
+ # test cases. This requires each example group to explicitly load the
+ # facts being exercised with something like
+ # Facter.collection.loader.load(:ipaddress)
+ Facter::Util::Loader.any_instance.stubs(:load_all)
+ Facter.clear
+ Facter.clear_messages
+ end
+end
diff --git a/puppet/stdlib/spec/unit/facter/pe_required_facts_spec.rb b/puppet/stdlib/spec/unit/facter/pe_required_facts_spec.rb
new file mode 100644
index 0000000000..f219b371f8
--- /dev/null
+++ b/puppet/stdlib/spec/unit/facter/pe_required_facts_spec.rb
@@ -0,0 +1,69 @@
+# Puppet Enterprise requires the following facts to be set in order to operate.
+# These facts are set using the file ???? and the two facts are
+# `fact_stomp_port`, and `fact_stomp_server`.
+#
+
+require 'spec_helper'
+
+describe "External facts in /etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt" do
+ context "With Facter 1.6.17 which does not have external facts support" do
+ before :each do
+ Facter.stubs(:version).returns("1.6.17")
+ # Stub out the filesystem for stdlib
+ Dir.stubs(:entries).with("/etc/puppetlabs/facter/facts.d").
+ returns(['puppet_enterprise_installer.txt'])
+ Dir.stubs(:entries).with("/etc/facter/facts.d").returns([])
+ File.stubs(:readlines).with('/etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt').
+ returns([
+ "fact_stomp_port=61613\n",
+ "fact_stomp_server=puppetmaster.acme.com\n",
+ "fact_is_puppetagent=true\n",
+ "fact_is_puppetmaster=false\n",
+ "fact_is_puppetca=false\n",
+ "fact_is_puppetconsole=false\n",
+ ])
+ if Facter.collection.respond_to? :load
+ Facter.collection.load(:facter_dot_d)
+ else
+ Facter.collection.loader.load(:facter_dot_d)
+ end
+ end
+
+ it 'defines fact_stomp_port' do
+ Facter.fact(:fact_stomp_port).value.should == '61613'
+ end
+ it 'defines fact_stomp_server' do
+ Facter.fact(:fact_stomp_server).value.should == 'puppetmaster.acme.com'
+ end
+ it 'defines fact_is_puppetagent' do
+ Facter.fact(:fact_is_puppetagent).value.should == 'true'
+ end
+ it 'defines fact_is_puppetmaster' do
+ Facter.fact(:fact_is_puppetmaster).value.should == 'false'
+ end
+ it 'defines fact_is_puppetca' do
+ Facter.fact(:fact_is_puppetca).value.should == 'false'
+ end
+ it 'defines fact_is_puppetconsole' do
+ Facter.fact(:fact_is_puppetconsole).value.should == 'false'
+ end
+ end
+
+ [ '1.7.1', '2.0.1' ].each do |v|
+ context "With Facter #{v} which has external facts support" do
+ before :each do
+ Facter.stubs(:version).returns(v)
+ end
+
+ it 'does not call Facter::Util::DotD.new' do
+ Facter::Util::DotD.expects(:new).never
+
+ if Facter.collection.respond_to? :load
+ Facter.collection.load(:facter_dot_d)
+ else
+ Facter.collection.loader.load(:facter_dot_d)
+ end
+ end
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/facter/pe_version_spec.rb b/puppet/stdlib/spec/unit/facter/pe_version_spec.rb
new file mode 100644
index 0000000000..931c6d4b0a
--- /dev/null
+++ b/puppet/stdlib/spec/unit/facter/pe_version_spec.rb
@@ -0,0 +1,76 @@
+#!/usr/bin/env rspec
+
+require 'spec_helper'
+
+describe "PE Version specs" do
+ before :each do
+ # Explicitly load the pe_version.rb file which contains generated facts
+ # that cannot be automatically loaded. Puppet 2.x implements
+ # Facter.collection.load while Facter 1.x markes Facter.collection.load as
+ # a private method.
+ if Facter.collection.respond_to? :load
+ Facter.collection.load(:pe_version)
+ else
+ Facter.collection.loader.load(:pe_version)
+ end
+ end
+
+ context "If PE is installed" do
+ %w{ 2.6.1 2.10.300 }.each do |version|
+ puppetversion = "2.7.19 (Puppet Enterprise #{version})"
+ context "puppetversion => #{puppetversion}" do
+ before :each do
+ Facter.fact(:puppetversion).stubs(:value).returns(puppetversion)
+ end
+
+ (major,minor,patch) = version.split(".")
+
+ it "Should return true" do
+ Facter.fact(:is_pe).value.should == true
+ end
+
+ it "Should have a version of #{version}" do
+ Facter.fact(:pe_version).value.should == version
+ end
+
+ it "Should have a major version of #{major}" do
+ Facter.fact(:pe_major_version).value.should == major
+ end
+
+ it "Should have a minor version of #{minor}" do
+ Facter.fact(:pe_minor_version).value.should == minor
+ end
+
+ it "Should have a patch version of #{patch}" do
+ Facter.fact(:pe_patch_version).value.should == patch
+ end
+ end
+ end
+ end
+
+ context "When PE is not installed" do
+ before :each do
+ Facter.fact(:puppetversion).stubs(:value).returns("2.7.19")
+ end
+
+ it "is_pe is false" do
+ Facter.fact(:is_pe).value.should == false
+ end
+
+ it "pe_version is nil" do
+ Facter.fact(:pe_version).value.should be_nil
+ end
+
+ it "pe_major_version is nil" do
+ Facter.fact(:pe_major_version).value.should be_nil
+ end
+
+ it "pe_minor_version is nil" do
+ Facter.fact(:pe_minor_version).value.should be_nil
+ end
+
+ it "Should have a patch version" do
+ Facter.fact(:pe_patch_version).value.should be_nil
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/facter/root_home_spec.rb b/puppet/stdlib/spec/unit/facter/root_home_spec.rb
new file mode 100644
index 0000000000..ce80684cae
--- /dev/null
+++ b/puppet/stdlib/spec/unit/facter/root_home_spec.rb
@@ -0,0 +1,40 @@
+require 'spec_helper'
+require 'facter/root_home'
+
+describe Facter::Util::RootHome do
+ context "solaris" do
+ let(:root_ent) { "root:x:0:0:Super-User:/:/sbin/sh" }
+ let(:expected_root_home) { "/" }
+
+ it "should return /" do
+ Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
+ Facter::Util::RootHome.get_root_home.should == expected_root_home
+ end
+ end
+ context "linux" do
+ let(:root_ent) { "root:x:0:0:root:/root:/bin/bash" }
+ let(:expected_root_home) { "/root" }
+
+ it "should return /root" do
+ Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
+ Facter::Util::RootHome.get_root_home.should == expected_root_home
+ end
+ end
+ context "macosx" do
+ let(:root_ent) { "root:*:0:0:System Administrator:/var/root:/bin/sh" }
+ let(:expected_root_home) { "/var/root" }
+
+ it "should return /var/root" do
+ Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
+ Facter::Util::RootHome.get_root_home.should == expected_root_home
+ end
+ end
+ context "windows" do
+ before :each do
+ Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(nil)
+ end
+ it "should be nil on windows" do
+ Facter::Util::RootHome.get_root_home.should be_nil
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/facter/util/puppet_settings_spec.rb b/puppet/stdlib/spec/unit/facter/util/puppet_settings_spec.rb
new file mode 100644
index 0000000000..c3ce6ea07e
--- /dev/null
+++ b/puppet/stdlib/spec/unit/facter/util/puppet_settings_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+require 'facter/util/puppet_settings'
+
+describe Facter::Util::PuppetSettings do
+
+ describe "#with_puppet" do
+ context "Without Puppet loaded" do
+ before(:each) do
+ Module.expects(:const_get).with("Puppet").raises(NameError)
+ end
+
+ it 'should be nil' do
+ subject.with_puppet { Puppet[:vardir] }.should be_nil
+ end
+ it 'should not yield to the block' do
+ Puppet.expects(:[]).never
+ subject.with_puppet { Puppet[:vardir] }.should be_nil
+ end
+ end
+ context "With Puppet loaded" do
+ module Puppet; end
+ let(:vardir) { "/var/lib/puppet" }
+
+ before :each do
+ Puppet.expects(:[]).with(:vardir).returns vardir
+ end
+ it 'should yield to the block' do
+ subject.with_puppet { Puppet[:vardir] }
+ end
+ it 'should return the nodes vardir' do
+ subject.with_puppet { Puppet[:vardir] }.should eq vardir
+ end
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/abs_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/abs_spec.rb
new file mode 100755
index 0000000000..c0b42970c5
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/abs_spec.rb
@@ -0,0 +1,25 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe "the abs function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("abs").should == "function_abs"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_abs([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should convert a negative number into a positive" do
+ result = scope.function_abs(["-34"])
+ result.should(eq(34))
+ end
+
+ it "should do nothing with a positive number" do
+ result = scope.function_abs(["5678"])
+ result.should(eq(5678))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/any2array_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/any2array_spec.rb
new file mode 100644
index 0000000000..b266e84f4f
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/any2array_spec.rb
@@ -0,0 +1,55 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the any2array function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("any2array").should == "function_any2array"
+ end
+
+ it "should return an empty array if there is less than 1 argument" do
+ result = scope.function_any2array([])
+ result.should(eq([]))
+ end
+
+ it "should convert boolean true to [ true ] " do
+ result = scope.function_any2array([true])
+ result.should(eq([true]))
+ end
+
+ it "should convert one object to [object]" do
+ result = scope.function_any2array(['one'])
+ result.should(eq(['one']))
+ end
+
+ it "should convert multiple objects to [objects]" do
+ result = scope.function_any2array(['one', 'two'])
+ result.should(eq(['one', 'two']))
+ end
+
+ it "should return empty array it was called with" do
+ result = scope.function_any2array([[]])
+ result.should(eq([]))
+ end
+
+ it "should return one-member array it was called with" do
+ result = scope.function_any2array([['string']])
+ result.should(eq(['string']))
+ end
+
+ it "should return multi-member array it was called with" do
+ result = scope.function_any2array([['one', 'two']])
+ result.should(eq(['one', 'two']))
+ end
+
+ it "should return members of a hash it was called with" do
+ result = scope.function_any2array([{ 'key' => 'value' }])
+ result.should(eq(['key', 'value']))
+ end
+
+ it "should return an empty array if it was called with an empty hash" do
+ result = scope.function_any2array([{ }])
+ result.should(eq([]))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/bool2num_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/bool2num_spec.rb
new file mode 100755
index 0000000000..518ac85ec5
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/bool2num_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the bool2num function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("bool2num").should == "function_bool2num"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_bool2num([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should convert true to 1" do
+ result = scope.function_bool2num([true])
+ result.should(eq(1))
+ end
+
+ it "should convert false to 0" do
+ result = scope.function_bool2num([false])
+ result.should(eq(0))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/capitalize_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/capitalize_spec.rb
new file mode 100755
index 0000000000..69c9758f25
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/capitalize_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the capitalize function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("capitalize").should == "function_capitalize"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_capitalize([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should capitalize the beginning of a string" do
+ result = scope.function_capitalize(["abc"])
+ result.should(eq("Abc"))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/chomp_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/chomp_spec.rb
new file mode 100755
index 0000000000..e425365fcb
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/chomp_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the chomp function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("chomp").should == "function_chomp"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_chomp([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should chomp the end of a string" do
+ result = scope.function_chomp(["abc\n"])
+ result.should(eq("abc"))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/chop_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/chop_spec.rb
new file mode 100755
index 0000000000..9e466de4b6
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/chop_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the chop function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("chop").should == "function_chop"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_chop([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should chop the end of a string" do
+ result = scope.function_chop(["asdf\n"])
+ result.should(eq("asdf"))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/concat_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/concat_spec.rb
new file mode 100644
index 0000000000..123188bd47
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/concat_spec.rb
@@ -0,0 +1,15 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the concat function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_concat([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should be able to concat an array" do
+ result = scope.function_concat([['1','2','3'],['4','5','6']])
+ result.should(eq(['1','2','3','4','5','6']))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/count_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/count_spec.rb
new file mode 100644
index 0000000000..2453815c26
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/count_spec.rb
@@ -0,0 +1,31 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe "the count function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("count").should == "function_count"
+ end
+
+ it "should raise a ArgumentError if there is more than 2 arguments" do
+ lambda { scope.function_count(['foo', 'bar', 'baz']) }.should( raise_error(ArgumentError))
+ end
+
+ it "should be able to count arrays" do
+ scope.function_count([["1","2","3"]]).should(eq(3))
+ end
+
+ it "should be able to count matching elements in arrays" do
+ scope.function_count([["1", "2", "2"], "2"]).should(eq(2))
+ end
+
+ it "should not count nil or empty strings" do
+ scope.function_count([["foo","bar",nil,""]]).should(eq(2))
+ end
+
+ it 'does not count an undefined hash key or an out of bound array index (which are both :undef)' do
+ expect(scope.function_count([["foo",:undef,:undef]])).to eq(1)
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/delete_at_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/delete_at_spec.rb
new file mode 100755
index 0000000000..d8d9618489
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/delete_at_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the delete_at function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("delete_at").should == "function_delete_at"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_delete_at([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should delete an item at specified location from an array" do
+ result = scope.function_delete_at([['a','b','c'],1])
+ result.should(eq(['a','c']))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/delete_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/delete_spec.rb
new file mode 100755
index 0000000000..2f29c93c0c
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/delete_spec.rb
@@ -0,0 +1,38 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the delete function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("delete").should == "function_delete"
+ end
+
+ it "should raise a ParseError if there are fewer than 2 arguments" do
+ lambda { scope.function_delete([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if there are greater than 2 arguments" do
+ lambda { scope.function_delete([[], 'foo', 'bar']) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a TypeError if a number is passed as the first argument" do
+ lambda { scope.function_delete([1, 'bar']) }.should( raise_error(TypeError))
+ end
+
+ it "should delete all instances of an element from an array" do
+ result = scope.function_delete([['a','b','c','b'],'b'])
+ result.should(eq(['a','c']))
+ end
+
+ it "should delete all instances of a substring from a string" do
+ result = scope.function_delete(['foobarbabarz','bar'])
+ result.should(eq('foobaz'))
+ end
+
+ it "should delete a key from a hash" do
+ result = scope.function_delete([{ 'a' => 1, 'b' => 2, 'c' => 3 },'b'])
+ result.should(eq({ 'a' => 1, 'c' => 3 }))
+ end
+
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/dirname_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/dirname_spec.rb
new file mode 100755
index 0000000000..fb3b4feca7
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/dirname_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the dirname function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("dirname").should == "function_dirname"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_dirname([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return dirname for an absolute path" do
+ result = scope.function_dirname(['/path/to/a/file.ext'])
+ result.should(eq('/path/to/a'))
+ end
+
+ it "should return dirname for a relative path" do
+ result = scope.function_dirname(['path/to/a/file.ext'])
+ result.should(eq('path/to/a'))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/downcase_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/downcase_spec.rb
new file mode 100755
index 0000000000..acef1f05d9
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/downcase_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the downcase function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("downcase").should == "function_downcase"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_downcase([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should downcase a string" do
+ result = scope.function_downcase(["ASFD"])
+ result.should(eq("asfd"))
+ end
+
+ it "should do nothing to a string that is already downcase" do
+ result = scope.function_downcase(["asdf asdf"])
+ result.should(eq("asdf asdf"))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/empty_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/empty_spec.rb
new file mode 100755
index 0000000000..7745875224
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/empty_spec.rb
@@ -0,0 +1,23 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the empty function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ it "should exist" do
+ Puppet::Parser::Functions.function("empty").should == "function_empty"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_empty([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return a true for an empty string" do
+ result = scope.function_empty([''])
+ result.should(eq(true))
+ end
+
+ it "should return a false for a non-empty string" do
+ result = scope.function_empty(['asdf'])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/flatten_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/flatten_spec.rb
new file mode 100755
index 0000000000..dba7a6bbdb
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/flatten_spec.rb
@@ -0,0 +1,27 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the flatten function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ it "should exist" do
+ Puppet::Parser::Functions.function("flatten").should == "function_flatten"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_flatten([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if there is more than 1 argument" do
+ lambda { scope.function_flatten([[], []]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should flatten a complex data structure" do
+ result = scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]])
+ result.should(eq(["a","b","c","d","e","f","g"]))
+ end
+
+ it "should do nothing to a structure that is already flat" do
+ result = scope.function_flatten([["a","b","c","d"]])
+ result.should(eq(["a","b","c","d"]))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/floor_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/floor_spec.rb
new file mode 100644
index 0000000000..dbc8c77358
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/floor_spec.rb
@@ -0,0 +1,39 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe "the floor function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("floor").should == "function_floor"
+ end
+
+ it "should raise a ParseError if there is less than 1 argument" do
+ lambda { scope.function_floor([]) }.should( raise_error(Puppet::ParseError, /Wrong number of arguments/))
+ end
+
+ it "should should raise a ParseError if input isn't numeric (eg. String)" do
+ lambda { scope.function_floor(["foo"]) }.should( raise_error(Puppet::ParseError, /Wrong argument type/))
+ end
+
+ it "should should raise a ParseError if input isn't numeric (eg. Boolean)" do
+ lambda { scope.function_floor([true]) }.should( raise_error(Puppet::ParseError, /Wrong argument type/))
+ end
+
+ it "should return an integer when a numeric type is passed" do
+ result = scope.function_floor([12.4])
+ result.is_a?(Integer).should(eq(true))
+ end
+
+ it "should return the input when an integer is passed" do
+ result = scope.function_floor([7])
+ result.should(eq(7))
+ end
+
+ it "should return the largest integer less than or equal to the input" do
+ result = scope.function_floor([3.8])
+ result.should(eq(3))
+ end
+end
+
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb
new file mode 100644
index 0000000000..2577723351
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb
@@ -0,0 +1,33 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the fqdn_rotate function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("fqdn_rotate").should == "function_fqdn_rotate"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_fqdn_rotate([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should rotate a string and the result should be the same size" do
+ scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
+ result = scope.function_fqdn_rotate(["asdf"])
+ result.size.should(eq(4))
+ end
+
+ it "should rotate a string to give the same results for one host" do
+ scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice
+ scope.function_fqdn_rotate(["abcdefg"]).should eql(scope.function_fqdn_rotate(["abcdefg"]))
+ end
+
+ it "should rotate a string to give different values on different hosts" do
+ scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
+ val1 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"])
+ scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.2")
+ val2 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"])
+ val1.should_not eql(val2)
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/get_module_path_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/get_module_path_spec.rb
new file mode 100644
index 0000000000..486bef6f20
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/get_module_path_spec.rb
@@ -0,0 +1,46 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:get_module_path) do
+ Internals = PuppetlabsSpec::PuppetInternals
+ class StubModule
+ attr_reader :path
+ def initialize(path)
+ @path = path
+ end
+ end
+
+ def scope(environment = "production")
+ Internals.scope(:compiler => Internals.compiler(:node => Internals.node(:environment => environment)))
+ end
+
+ it 'should only allow one argument' do
+ expect { scope.function_get_module_path([]) }.to raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/)
+ expect { scope.function_get_module_path(['1','2','3']) }.to raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/)
+ end
+ it 'should raise an exception when the module cannot be found' do
+ expect { scope.function_get_module_path(['foo']) }.to raise_error(Puppet::ParseError, /Could not find module/)
+ end
+ describe 'when locating a module' do
+ let(:modulepath) { "/tmp/does_not_exist" }
+ let(:path_of_module_foo) { StubModule.new("/tmp/does_not_exist/foo") }
+
+ before(:each) { Puppet[:modulepath] = modulepath }
+
+ it 'should be able to find module paths from the modulepath setting' do
+ Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo)
+ scope.function_get_module_path(['foo']).should == path_of_module_foo.path
+ end
+ it 'should be able to find module paths when the modulepath is a list' do
+ Puppet[:modulepath] = modulepath + ":/tmp"
+ Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo)
+ scope.function_get_module_path(['foo']).should == path_of_module_foo.path
+ end
+ it 'should respect the environment' do
+ pending("Disabled on Puppet 2.6.x") if Puppet.version =~ /^2\.6\b/
+ Puppet.settings[:environment] = 'danstestenv'
+ Puppet::Module.expects(:find).with('foo', 'danstestenv').returns(path_of_module_foo)
+ scope('danstestenv').function_get_module_path(['foo']).should == path_of_module_foo.path
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/getvar_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/getvar_spec.rb
new file mode 100644
index 0000000000..5ff834ee71
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/getvar_spec.rb
@@ -0,0 +1,37 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:getvar) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ describe 'when calling getvar from puppet' do
+
+ it "should not compile when no arguments are passed" do
+ pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = '$foo = getvar()'
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+
+ it "should not compile when too many arguments are passed" do
+ pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = '$foo = getvar("foo::bar", "baz")'
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+
+ it "should lookup variables in other namespaces" do
+ pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ class site::data { $foo = 'baz' }
+ include site::data
+ $foo = getvar("site::data::foo")
+ if $foo != 'baz' {
+ fail('getvar did not return what we expect')
+ }
+ ENDofPUPPETcode
+ scope.compiler.compile
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/grep_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/grep_spec.rb
new file mode 100755
index 0000000000..a93b842537
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/grep_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the grep function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("grep").should == "function_grep"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_grep([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should grep contents from an array" do
+ result = scope.function_grep([["aaabbb","bbbccc","dddeee"], "bbb"])
+ result.should(eq(["aaabbb","bbbccc"]))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/has_interface_with_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/has_interface_with_spec.rb
new file mode 100755
index 0000000000..c5264e4f30
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/has_interface_with_spec.rb
@@ -0,0 +1,64 @@
+#!/usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:has_interface_with) do
+
+ let(:scope) do
+ PuppetlabsSpec::PuppetInternals.scope
+ end
+
+ # The subject of these examples is the method itself.
+ subject do
+ function_name = Puppet::Parser::Functions.function(:has_interface_with)
+ scope.method(function_name)
+ end
+
+ # We need to mock out the Facts so we can specify how we expect this function
+ # to behave on different platforms.
+ context "On Mac OS X Systems" do
+ before :each do
+ scope.stubs(:lookupvar).with("interfaces").returns('lo0,gif0,stf0,en1,p2p0,fw0,en0,vmnet1,vmnet8,utun0')
+ end
+ it 'should have loopback (lo0)' do
+ subject.call(['lo0']).should be_true
+ end
+ it 'should not have loopback (lo)' do
+ subject.call(['lo']).should be_false
+ end
+ end
+ context "On Linux Systems" do
+ before :each do
+ scope.stubs(:lookupvar).with("interfaces").returns('eth0,lo')
+ scope.stubs(:lookupvar).with("ipaddress").returns('10.0.0.1')
+ scope.stubs(:lookupvar).with("ipaddress_lo").returns('127.0.0.1')
+ scope.stubs(:lookupvar).with("ipaddress_eth0").returns('10.0.0.1')
+ scope.stubs(:lookupvar).with('muppet').returns('kermit')
+ scope.stubs(:lookupvar).with('muppet_lo').returns('mspiggy')
+ scope.stubs(:lookupvar).with('muppet_eth0').returns('kermit')
+ end
+ it 'should have loopback (lo)' do
+ subject.call(['lo']).should be_true
+ end
+ it 'should not have loopback (lo0)' do
+ subject.call(['lo0']).should be_false
+ end
+ it 'should have ipaddress with 127.0.0.1' do
+ subject.call(['ipaddress', '127.0.0.1']).should be_true
+ end
+ it 'should have ipaddress with 10.0.0.1' do
+ subject.call(['ipaddress', '10.0.0.1']).should be_true
+ end
+ it 'should not have ipaddress with 10.0.0.2' do
+ subject.call(['ipaddress', '10.0.0.2']).should be_false
+ end
+ it 'should have muppet named kermit' do
+ subject.call(['muppet', 'kermit']).should be_true
+ end
+ it 'should have muppet named mspiggy' do
+ subject.call(['muppet', 'mspiggy']).should be_true
+ end
+ it 'should not have muppet named bigbird' do
+ subject.call(['muppet', 'bigbird']).should be_false
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/has_ip_address_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/has_ip_address_spec.rb
new file mode 100755
index 0000000000..5a68460820
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/has_ip_address_spec.rb
@@ -0,0 +1,39 @@
+#!/usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:has_ip_address) do
+
+ let(:scope) do
+ PuppetlabsSpec::PuppetInternals.scope
+ end
+
+ subject do
+ function_name = Puppet::Parser::Functions.function(:has_ip_address)
+ scope.method(function_name)
+ end
+
+ context "On Linux Systems" do
+ before :each do
+ scope.stubs(:lookupvar).with('interfaces').returns('eth0,lo')
+ scope.stubs(:lookupvar).with('ipaddress').returns('10.0.2.15')
+ scope.stubs(:lookupvar).with('ipaddress_eth0').returns('10.0.2.15')
+ scope.stubs(:lookupvar).with('ipaddress_lo').returns('127.0.0.1')
+ end
+
+ it 'should have primary address (10.0.2.15)' do
+ subject.call(['10.0.2.15']).should be_true
+ end
+
+ it 'should have lookupback address (127.0.0.1)' do
+ subject.call(['127.0.0.1']).should be_true
+ end
+
+ it 'should not have other address' do
+ subject.call(['192.1681.1.1']).should be_false
+ end
+
+ it 'should not have "mspiggy" on an interface' do
+ subject.call(['mspiggy']).should be_false
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/has_ip_network_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/has_ip_network_spec.rb
new file mode 100755
index 0000000000..c3a289e372
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/has_ip_network_spec.rb
@@ -0,0 +1,36 @@
+#!/usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:has_ip_network) do
+
+ let(:scope) do
+ PuppetlabsSpec::PuppetInternals.scope
+ end
+
+ subject do
+ function_name = Puppet::Parser::Functions.function(:has_ip_network)
+ scope.method(function_name)
+ end
+
+ context "On Linux Systems" do
+ before :each do
+ scope.stubs(:lookupvar).with('interfaces').returns('eth0,lo')
+ scope.stubs(:lookupvar).with('network').returns(:undefined)
+ scope.stubs(:lookupvar).with('network_eth0').returns('10.0.2.0')
+ scope.stubs(:lookupvar).with('network_lo').returns('127.0.0.1')
+ end
+
+ it 'should have primary network (10.0.2.0)' do
+ subject.call(['10.0.2.0']).should be_true
+ end
+
+ it 'should have loopback network (127.0.0.0)' do
+ subject.call(['127.0.0.1']).should be_true
+ end
+
+ it 'should not have other network' do
+ subject.call(['192.168.1.0']).should be_false
+ end
+ end
+end
+
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/has_key_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/has_key_spec.rb
new file mode 100644
index 0000000000..490daeae7c
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/has_key_spec.rb
@@ -0,0 +1,42 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:has_key) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ describe 'when calling has_key from puppet' do
+ it "should not compile when no arguments are passed" do
+ pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = '$x = has_key()'
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+
+ it "should not compile when 1 argument is passed" do
+ pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = "$x = has_key('foo')"
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+
+ it "should require the first value to be a Hash" do
+ pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = "$x = has_key('foo', 'bar')"
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /expects the first argument to be a hash/)
+ end
+ end
+
+ describe 'when calling the function has_key from a scope instance' do
+ it 'should detect existing keys' do
+ scope.function_has_key([{'one' => 1}, 'one']).should be_true
+ end
+
+ it 'should detect existing keys' do
+ scope.function_has_key([{'one' => 1}, 'two']).should be_false
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/hash_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/hash_spec.rb
new file mode 100644
index 0000000000..7c91be9077
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/hash_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the hash function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("hash").should == "function_hash"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_hash([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should convert an array to a hash" do
+ result = scope.function_hash([['a',1,'b',2,'c',3]])
+ result.should(eq({'a'=>1,'b'=>2,'c'=>3}))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/is_array_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/is_array_spec.rb
new file mode 100644
index 0000000000..e7f4bcd6df
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/is_array_spec.rb
@@ -0,0 +1,29 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_array function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_array").should == "function_is_array"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_is_array([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if passed an array" do
+ result = scope.function_is_array([[1,2,3]])
+ result.should(eq(true))
+ end
+
+ it "should return false if passed a hash" do
+ result = scope.function_is_array([{'a'=>1}])
+ result.should(eq(false))
+ end
+
+ it "should return false if passed a string" do
+ result = scope.function_is_array(["asdf"])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/is_domain_name_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/is_domain_name_spec.rb
new file mode 100644
index 0000000000..f2ea76dac7
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/is_domain_name_spec.rb
@@ -0,0 +1,64 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_domain_name function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_domain_name").should == "function_is_domain_name"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_is_domain_name([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if a valid short domain name" do
+ result = scope.function_is_domain_name(["x.com"])
+ result.should(be_true)
+ end
+
+ it "should return true if the domain is ." do
+ result = scope.function_is_domain_name(["."])
+ result.should(be_true)
+ end
+
+ it "should return true if the domain is x.com." do
+ result = scope.function_is_domain_name(["x.com."])
+ result.should(be_true)
+ end
+
+ it "should return true if a valid domain name" do
+ result = scope.function_is_domain_name(["foo.bar.com"])
+ result.should(be_true)
+ end
+
+ it "should allow domain parts to start with numbers" do
+ result = scope.function_is_domain_name(["3foo.2bar.com"])
+ result.should(be_true)
+ end
+
+ it "should allow domain to end with a dot" do
+ result = scope.function_is_domain_name(["3foo.2bar.com."])
+ result.should(be_true)
+ end
+
+ it "should allow a single part domain" do
+ result = scope.function_is_domain_name(["orange"])
+ result.should(be_true)
+ end
+
+ it "should return false if domain parts start with hyphens" do
+ result = scope.function_is_domain_name(["-3foo.2bar.com"])
+ result.should(be_false)
+ end
+
+ it "should return true if domain contains hyphens" do
+ result = scope.function_is_domain_name(["3foo-bar.2bar-fuzz.com"])
+ result.should(be_true)
+ end
+
+ it "should return false if domain name contains spaces" do
+ result = scope.function_is_domain_name(["not valid"])
+ result.should(be_false)
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/is_float_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/is_float_spec.rb
new file mode 100644
index 0000000000..b7d73b04a2
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/is_float_spec.rb
@@ -0,0 +1,33 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_float function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_float").should == "function_is_float"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_is_float([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if a float" do
+ result = scope.function_is_float(["0.12"])
+ result.should(eq(true))
+ end
+
+ it "should return false if a string" do
+ result = scope.function_is_float(["asdf"])
+ result.should(eq(false))
+ end
+
+ it "should return false if an integer" do
+ result = scope.function_is_float(["3"])
+ result.should(eq(false))
+ end
+ it "should return true if a float is created from an arithmetical operation" do
+ result = scope.function_is_float([3.2*2])
+ result.should(eq(true))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/is_function_available.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/is_function_available.rb
new file mode 100644
index 0000000000..bd40c51944
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/is_function_available.rb
@@ -0,0 +1,31 @@
+#!/usr/bin/env rspec
+require 'spec_helper'
+
+describe "the is_function_available function" do
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ end
+
+ before :each do
+ @scope = Puppet::Parser::Scope.new
+ end
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_function_available").should == "function_is_function_available"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { @scope.function_is_function_available([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return false if a nonexistent function is passed" do
+ result = @scope.function_is_function_available(['jeff_mccunes_left_sock'])
+ result.should(eq(false))
+ end
+
+ it "should return true if an available function is passed" do
+ result = @scope.function_is_function_available(['require'])
+ result.should(eq(true))
+ end
+
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/is_hash_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/is_hash_spec.rb
new file mode 100644
index 0000000000..bbebf39f9c
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/is_hash_spec.rb
@@ -0,0 +1,29 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_hash function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_hash").should == "function_is_hash"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_is_hash([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if passed a hash" do
+ result = scope.function_is_hash([{"a"=>1,"b"=>2}])
+ result.should(eq(true))
+ end
+
+ it "should return false if passed an array" do
+ result = scope.function_is_hash([["a","b"]])
+ result.should(eq(false))
+ end
+
+ it "should return false if passed a string" do
+ result = scope.function_is_hash(["asdf"])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/is_integer_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/is_integer_spec.rb
new file mode 100644
index 0000000000..4335795028
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/is_integer_spec.rb
@@ -0,0 +1,34 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_integer function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_integer").should == "function_is_integer"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_is_integer([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if an integer" do
+ result = scope.function_is_integer(["3"])
+ result.should(eq(true))
+ end
+
+ it "should return false if a float" do
+ result = scope.function_is_integer(["3.2"])
+ result.should(eq(false))
+ end
+
+ it "should return false if a string" do
+ result = scope.function_is_integer(["asdf"])
+ result.should(eq(false))
+ end
+
+ it "should return true if an integer is created from an arithmetical operation" do
+ result = scope.function_is_integer([3*2])
+ result.should(eq(true))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/is_ip_address_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/is_ip_address_spec.rb
new file mode 100644
index 0000000000..c0debb3d43
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/is_ip_address_spec.rb
@@ -0,0 +1,39 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_ip_address function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_ip_address").should == "function_is_ip_address"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_is_ip_address([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if an IPv4 address" do
+ result = scope.function_is_ip_address(["1.2.3.4"])
+ result.should(eq(true))
+ end
+
+ it "should return true if a full IPv6 address" do
+ result = scope.function_is_ip_address(["fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"])
+ result.should(eq(true))
+ end
+
+ it "should return true if a compressed IPv6 address" do
+ result = scope.function_is_ip_address(["fe00::1"])
+ result.should(eq(true))
+ end
+
+ it "should return false if not valid" do
+ result = scope.function_is_ip_address(["asdf"])
+ result.should(eq(false))
+ end
+
+ it "should return false if IP octets out of range" do
+ result = scope.function_is_ip_address(["1.1.1.300"])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/is_mac_address_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/is_mac_address_spec.rb
new file mode 100644
index 0000000000..ca9c590476
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/is_mac_address_spec.rb
@@ -0,0 +1,29 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_mac_address function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_mac_address").should == "function_is_mac_address"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_is_mac_address([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if a valid mac address" do
+ result = scope.function_is_mac_address(["00:a0:1f:12:7f:a0"])
+ result.should(eq(true))
+ end
+
+ it "should return false if octets are out of range" do
+ result = scope.function_is_mac_address(["00:a0:1f:12:7f:g0"])
+ result.should(eq(false))
+ end
+
+ it "should return false if not valid" do
+ result = scope.function_is_mac_address(["not valid"])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/is_numeric_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/is_numeric_spec.rb
new file mode 100644
index 0000000000..d7440fb0a9
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/is_numeric_spec.rb
@@ -0,0 +1,39 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_numeric function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_numeric").should == "function_is_numeric"
+ end
+
+ it "should raise a ParseError if there is less than 1 argument" do
+ lambda { scope.function_is_numeric([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if an integer" do
+ result = scope.function_is_numeric(["3"])
+ result.should(eq(true))
+ end
+
+ it "should return true if a float" do
+ result = scope.function_is_numeric(["3.2"])
+ result.should(eq(true))
+ end
+
+ it "should return true if an integer is created from an arithmetical operation" do
+ result = scope.function_is_numeric([3*2])
+ result.should(eq(true))
+ end
+
+ it "should return true if a float is created from an arithmetical operation" do
+ result = scope.function_is_numeric([3.2*2])
+ result.should(eq(true))
+ end
+
+ it "should return false if a string" do
+ result = scope.function_is_numeric(["asdf"])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/is_string_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/is_string_spec.rb
new file mode 100644
index 0000000000..3756bea8b5
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/is_string_spec.rb
@@ -0,0 +1,34 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_string function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_string").should == "function_is_string"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_is_string([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if a string" do
+ result = scope.function_is_string(["asdf"])
+ result.should(eq(true))
+ end
+
+ it "should return false if an integer" do
+ result = scope.function_is_string(["3"])
+ result.should(eq(false))
+ end
+
+ it "should return false if a float" do
+ result = scope.function_is_string(["3.23"])
+ result.should(eq(false))
+ end
+
+ it "should return false if an array" do
+ result = scope.function_is_string([["a","b","c"]])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb
new file mode 100644
index 0000000000..a52fb719f2
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb
@@ -0,0 +1,40 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the join_keys_to_values function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("join_keys_to_values").should == "function_join_keys_to_values"
+ end
+
+ it "should raise a ParseError if there are fewer than two arguments" do
+ lambda { scope.function_join_keys_to_values([{}]) }.should raise_error Puppet::ParseError
+ end
+
+ it "should raise a ParseError if there are greater than two arguments" do
+ lambda { scope.function_join_keys_to_values([{}, 'foo', 'bar']) }.should raise_error Puppet::ParseError
+ end
+
+ it "should raise a TypeError if the first argument is an array" do
+ lambda { scope.function_join_keys_to_values([[1,2], ',']) }.should raise_error TypeError
+ end
+
+ it "should raise a TypeError if the second argument is an array" do
+ lambda { scope.function_join_keys_to_values([{}, [1,2]]) }.should raise_error TypeError
+ end
+
+ it "should raise a TypeError if the second argument is a number" do
+ lambda { scope.function_join_keys_to_values([{}, 1]) }.should raise_error TypeError
+ end
+
+ it "should return an empty array given an empty hash" do
+ result = scope.function_join_keys_to_values([{}, ":"])
+ result.should == []
+ end
+
+ it "should join hash's keys to its values" do
+ result = scope.function_join_keys_to_values([{'a'=>1,2=>'foo',:b=>nil}, ":"])
+ result.should =~ ['a:1','2:foo','b:']
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/join_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/join_spec.rb
new file mode 100644
index 0000000000..aafa1a7f76
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/join_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the join function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("join").should == "function_join"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_join([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should join an array into a string" do
+ result = scope.function_join([["a","b","c"], ":"])
+ result.should(eq("a:b:c"))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/keys_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/keys_spec.rb
new file mode 100644
index 0000000000..fdd7a7073e
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/keys_spec.rb
@@ -0,0 +1,21 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the keys function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("keys").should == "function_keys"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_keys([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return an array of keys when given a hash" do
+ result = scope.function_keys([{'a'=>1, 'b'=>2}])
+ # =~ performs 'array with same elements' (set) matching
+ # For more info see RSpec::Matchers::MatchArray
+ result.should =~ ['a','b']
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/lstrip_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/lstrip_spec.rb
new file mode 100644
index 0000000000..b280ae7ac1
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/lstrip_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the lstrip function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("lstrip").should == "function_lstrip"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_lstrip([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should lstrip a string" do
+ result = scope.function_lstrip([" asdf"])
+ result.should(eq('asdf'))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/max_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/max_spec.rb
new file mode 100755
index 0000000000..ff6f2b361c
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/max_spec.rb
@@ -0,0 +1,27 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe "the max function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("max").should == "function_max"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_max([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should be able to compare strings" do
+ scope.function_max(["albatross","dog","horse"]).should(eq("horse"))
+ end
+
+ it "should be able to compare numbers" do
+ scope.function_max([6,8,4]).should(eq(8))
+ end
+
+ it "should be able to compare a number with a stringified number" do
+ scope.function_max([1,"2"]).should(eq("2"))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/member_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/member_spec.rb
new file mode 100644
index 0000000000..6e9a023fa4
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/member_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the member function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("member").should == "function_member"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_member([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if a member is in an array" do
+ result = scope.function_member([["a","b","c"], "a"])
+ result.should(eq(true))
+ end
+
+ it "should return false if a member is not in an array" do
+ result = scope.function_member([["a","b","c"], "d"])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/merge_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/merge_spec.rb
new file mode 100644
index 0000000000..04169e7e75
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/merge_spec.rb
@@ -0,0 +1,47 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:merge) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ describe 'when calling merge from puppet' do
+ it "should not compile when no arguments are passed" do
+ pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = '$x = merge()'
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+
+ it "should not compile when 1 argument is passed" do
+ pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = "$my_hash={'one' => 1}\n$x = merge($my_hash)"
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+ end
+
+ describe 'when calling merge on the scope instance' do
+ it 'should require all parameters are hashes' do
+ expect { new_hash = scope.function_merge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/)
+ end
+
+ it 'should be able to merge two hashes' do
+ new_hash = scope.function_merge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}])
+ new_hash['one'].should == '1'
+ new_hash['two'].should == '2'
+ new_hash['three'].should == '2'
+ end
+
+ it 'should merge multiple hashes' do
+ hash = scope.function_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}])
+ hash['one'].should == '3'
+ end
+
+ it 'should accept empty hashes' do
+ scope.function_merge([{},{},{}]).should == {}
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/min_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/min_spec.rb
new file mode 100755
index 0000000000..71d593ef09
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/min_spec.rb
@@ -0,0 +1,27 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe "the min function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("min").should == "function_min"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_min([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should be able to compare strings" do
+ scope.function_min(["albatross","dog","horse"]).should(eq("albatross"))
+ end
+
+ it "should be able to compare numbers" do
+ scope.function_min([6,8,4]).should(eq(4))
+ end
+
+ it "should be able to compare a number with a stringified number" do
+ scope.function_min([1,"2"]).should(eq(1))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/num2bool_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/num2bool_spec.rb
new file mode 100644
index 0000000000..b56196d3c6
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/num2bool_spec.rb
@@ -0,0 +1,67 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the num2bool function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("num2bool").should == "function_num2bool"
+ end
+
+ it "should raise a ParseError if there are no arguments" do
+ lambda { scope.function_num2bool([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if there are more than 1 arguments" do
+ lambda { scope.function_num2bool(["foo","bar"]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if passed something non-numeric" do
+ lambda { scope.function_num2bool(["xyzzy"]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if passed string 1" do
+ result = scope.function_num2bool(["1"])
+ result.should(be_true)
+ end
+
+ it "should return true if passed string 1.5" do
+ result = scope.function_num2bool(["1.5"])
+ result.should(be_true)
+ end
+
+ it "should return true if passed number 1" do
+ result = scope.function_num2bool([1])
+ result.should(be_true)
+ end
+
+ it "should return false if passed string 0" do
+ result = scope.function_num2bool(["0"])
+ result.should(be_false)
+ end
+
+ it "should return false if passed number 0" do
+ result = scope.function_num2bool([0])
+ result.should(be_false)
+ end
+
+ it "should return false if passed string -1" do
+ result = scope.function_num2bool(["-1"])
+ result.should(be_false)
+ end
+
+ it "should return false if passed string -1.5" do
+ result = scope.function_num2bool(["-1.5"])
+ result.should(be_false)
+ end
+
+ it "should return false if passed number -1" do
+ result = scope.function_num2bool([-1])
+ result.should(be_false)
+ end
+
+ it "should return false if passed float -1.5" do
+ result = scope.function_num2bool([-1.5])
+ result.should(be_false)
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/parsejson_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/parsejson_spec.rb
new file mode 100644
index 0000000000..f179ac111a
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/parsejson_spec.rb
@@ -0,0 +1,22 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the parsejson function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("parsejson").should == "function_parsejson"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_parsejson([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should convert JSON to a data structure" do
+ json = <<-EOS
+["aaa","bbb","ccc"]
+EOS
+ result = scope.function_parsejson([json])
+ result.should(eq(['aaa','bbb','ccc']))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/parseyaml_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/parseyaml_spec.rb
new file mode 100644
index 0000000000..0c7aea8a5a
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/parseyaml_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the parseyaml function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("parseyaml").should == "function_parseyaml"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_parseyaml([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should convert YAML to a data structure" do
+ yaml = <<-EOS
+- aaa
+- bbb
+- ccc
+EOS
+ result = scope.function_parseyaml([yaml])
+ result.should(eq(['aaa','bbb','ccc']))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/pick_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/pick_spec.rb
new file mode 100644
index 0000000000..761db6be21
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/pick_spec.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the pick function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("pick").should == "function_pick"
+ end
+
+ it 'should return the correct value' do
+ scope.function_pick(['first', 'second']).should == 'first'
+ end
+
+ it 'should return the correct value if the first value is empty' do
+ scope.function_pick(['', 'second']).should == 'second'
+ end
+
+ it 'should remove empty string values' do
+ scope.function_pick(['', 'first']).should == 'first'
+ end
+
+ it 'should remove :undef values' do
+ scope.function_pick([:undef, 'first']).should == 'first'
+ end
+
+ it 'should remove :undefined values' do
+ scope.function_pick([:undefined, 'first']).should == 'first'
+ end
+
+ it 'should error if no values are passed' do
+ expect { scope.function_pick([]) }.to raise_error(Puppet::Error, /Must provide non empty value./)
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/prefix_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/prefix_spec.rb
new file mode 100644
index 0000000000..5cf592bfba
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/prefix_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the prefix function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("prefix").should == "function_prefix"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_prefix([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return a prefixed array" do
+ result = scope.function_prefix([['a','b','c'], 'p'])
+ result.should(eq(['pa','pb','pc']))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/range_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/range_spec.rb
new file mode 100644
index 0000000000..42751f460b
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/range_spec.rb
@@ -0,0 +1,34 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the range function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("range").should == "function_range"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_range([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return a letter range" do
+ result = scope.function_range(["a","d"])
+ result.should(eq(['a','b','c','d']))
+ end
+
+ it "should return a number range" do
+ result = scope.function_range(["1","4"])
+ result.should(eq([1,2,3,4]))
+ end
+
+ it "should work with padded hostname like strings" do
+ expected = ("host01".."host10").to_a
+ scope.function_range(["host01","host10"]).should eq expected
+ end
+
+ it "should coerce zero padded digits to integers" do
+ expected = (0..10).to_a
+ scope.function_range(["00", "10"]).should eq expected
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/reject_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/reject_spec.rb
new file mode 100755
index 0000000000..f2cb741935
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/reject_spec.rb
@@ -0,0 +1,20 @@
+#!/usr/bin/env ruby
+
+require 'spec_helper'
+
+describe "the reject function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("reject").should == "function_reject"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_reject([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should reject contents from an array" do
+ result = scope.function_reject([["1111", "aaabbb","bbbccc","dddeee"], "bbb"])
+ result.should(eq(["1111", "dddeee"]))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/reverse_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/reverse_spec.rb
new file mode 100644
index 0000000000..1b59206547
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/reverse_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the reverse function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("reverse").should == "function_reverse"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_reverse([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should reverse a string" do
+ result = scope.function_reverse(["asdfghijkl"])
+ result.should(eq('lkjihgfdsa'))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/rstrip_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/rstrip_spec.rb
new file mode 100644
index 0000000000..d90de1d060
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/rstrip_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the rstrip function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("rstrip").should == "function_rstrip"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_rstrip([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should rstrip a string" do
+ result = scope.function_rstrip(["asdf "])
+ result.should(eq('asdf'))
+ end
+
+ it "should rstrip each element in an array" do
+ result = scope.function_rstrip([["a ","b ", "c "]])
+ result.should(eq(['a','b','c']))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/shuffle_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/shuffle_spec.rb
new file mode 100644
index 0000000000..93346d5370
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/shuffle_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the shuffle function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("shuffle").should == "function_shuffle"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_shuffle([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should shuffle a string and the result should be the same size" do
+ result = scope.function_shuffle(["asdf"])
+ result.size.should(eq(4))
+ end
+
+ it "should shuffle a string but the sorted contents should still be the same" do
+ result = scope.function_shuffle(["adfs"])
+ result.split("").sort.join("").should(eq("adfs"))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/size_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/size_spec.rb
new file mode 100644
index 0000000000..b1c435a302
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/size_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the size function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("size").should == "function_size"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_size([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return the size of a string" do
+ result = scope.function_size(["asdf"])
+ result.should(eq(4))
+ end
+
+ it "should return the size of an array" do
+ result = scope.function_size([["a","b","c"]])
+ result.should(eq(3))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/sort_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/sort_spec.rb
new file mode 100644
index 0000000000..3187a5aecb
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/sort_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the sort function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("sort").should == "function_sort"
+ end
+
+ it "should raise a ParseError if there is not 1 arguments" do
+ lambda { scope.function_sort(['','']) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should sort an array" do
+ result = scope.function_sort([["a","c","b"]])
+ result.should(eq(['a','b','c']))
+ end
+
+ it "should sort a string" do
+ result = scope.function_sort(["acb"])
+ result.should(eq('abc'))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/squeeze_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/squeeze_spec.rb
new file mode 100644
index 0000000000..60e5a3028d
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/squeeze_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the squeeze function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("squeeze").should == "function_squeeze"
+ end
+
+ it "should raise a ParseError if there is less than 2 arguments" do
+ lambda { scope.function_squeeze([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should squeeze a string" do
+ result = scope.function_squeeze(["aaabbbbcccc"])
+ result.should(eq('abc'))
+ end
+
+ it "should squeeze all elements in an array" do
+ result = scope.function_squeeze([["aaabbbbcccc","dddfff"]])
+ result.should(eq(['abc','df']))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/str2bool_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/str2bool_spec.rb
new file mode 100644
index 0000000000..ef6350f253
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/str2bool_spec.rb
@@ -0,0 +1,31 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the str2bool function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("str2bool").should == "function_str2bool"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_str2bool([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should convert string 'true' to true" do
+ result = scope.function_str2bool(["true"])
+ result.should(eq(true))
+ end
+
+ it "should convert string 'undef' to false" do
+ result = scope.function_str2bool(["undef"])
+ result.should(eq(false))
+ end
+
+ it "should return the boolean it was called with" do
+ result = scope.function_str2bool([true])
+ result.should(eq(true))
+ result = scope.function_str2bool([false])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb
new file mode 100644
index 0000000000..df8fb8e905
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb
@@ -0,0 +1,45 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the str2saltedsha512 function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("str2saltedsha512").should == "function_str2saltedsha512"
+ end
+
+ it "should raise a ParseError if there is less than 1 argument" do
+ expect { scope.function_str2saltedsha512([]) }.to( raise_error(Puppet::ParseError) )
+ end
+
+ it "should raise a ParseError if there is more than 1 argument" do
+ expect { scope.function_str2saltedsha512(['foo', 'bar', 'baz']) }.to( raise_error(Puppet::ParseError) )
+ end
+
+ it "should return a salted-sha512 password hash 136 characters in length" do
+ result = scope.function_str2saltedsha512(["password"])
+ result.length.should(eq(136))
+ end
+
+ it "should raise an error if you pass a non-string password" do
+ expect { scope.function_str2saltedsha512([1234]) }.to( raise_error(Puppet::ParseError) )
+ end
+
+ it "should generate a valid password" do
+ # Allow the function to generate a password based on the string 'password'
+ password_hash = scope.function_str2saltedsha512(["password"])
+
+ # Separate the Salt and Password from the Password Hash
+ salt = password_hash[0..7]
+ password = password_hash[8..-1]
+
+ # Convert the Salt and Password from Hex to Binary Data
+ str_salt = Array(salt.lines).pack('H*')
+ str_password = Array(password.lines).pack('H*')
+
+ # Combine the Binary Salt with 'password' and compare the end result
+ saltedpass = Digest::SHA512.digest(str_salt + 'password')
+ result = (str_salt + saltedpass).unpack('H*')[0]
+ result.should == password_hash
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/strftime_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/strftime_spec.rb
new file mode 100644
index 0000000000..df42b6f26b
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/strftime_spec.rb
@@ -0,0 +1,29 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the strftime function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("strftime").should == "function_strftime"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_strftime([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "using %s should be higher then when I wrote this test" do
+ result = scope.function_strftime(["%s"])
+ result.to_i.should(be > 1311953157)
+ end
+
+ it "using %s should be lower then 1.5 trillion" do
+ result = scope.function_strftime(["%s"])
+ result.to_i.should(be < 1500000000)
+ end
+
+ it "should return a date when given %Y-%m-%d" do
+ result = scope.function_strftime(["%Y-%m-%d"])
+ result.should =~ /^\d{4}-\d{2}-\d{2}$/
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/strip_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/strip_spec.rb
new file mode 100644
index 0000000000..fccdd26067
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/strip_spec.rb
@@ -0,0 +1,18 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the strip function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ it "should exist" do
+ Puppet::Parser::Functions.function("strip").should == "function_strip"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_strip([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should strip a string" do
+ result = scope.function_strip([" ab cd "])
+ result.should(eq('ab cd'))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/suffix_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/suffix_spec.rb
new file mode 100644
index 0000000000..c28f719c8e
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/suffix_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the suffix function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("suffix").should == "function_suffix"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_suffix([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return a suffixed array" do
+ result = scope.function_suffix([['a','b','c'], 'p'])
+ result.should(eq(['ap','bp','cp']))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/swapcase_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/swapcase_spec.rb
new file mode 100644
index 0000000000..808b415876
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/swapcase_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the swapcase function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("swapcase").should == "function_swapcase"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_swapcase([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should swapcase a string" do
+ result = scope.function_swapcase(["aaBBccDD"])
+ result.should(eq('AAbbCCdd'))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/time_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/time_spec.rb
new file mode 100644
index 0000000000..e9fb76e6ac
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/time_spec.rb
@@ -0,0 +1,29 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the time function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("time").should == "function_time"
+ end
+
+ it "should raise a ParseError if there is more than 2 arguments" do
+ lambda { scope.function_time(['','']) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return a number" do
+ result = scope.function_time([])
+ result.should be_an(Integer)
+ end
+
+ it "should be higher then when I wrote this test" do
+ result = scope.function_time([])
+ result.should(be > 1311953157)
+ end
+
+ it "should be lower then 1.5 trillion" do
+ result = scope.function_time([])
+ result.should(be < 1500000000)
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
new file mode 100755
index 0000000000..d1ea4c80cc
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
@@ -0,0 +1,58 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe "the to_bytes function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("to_bytes").should == "function_to_bytes"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_to_bytes([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should convert kB to B" do
+ result = scope.function_to_bytes(["4 kB"])
+ result.should(eq(4096))
+ end
+
+ it "should work without B in unit" do
+ result = scope.function_to_bytes(["4 k"])
+ result.should(eq(4096))
+ end
+
+ it "should work without a space before unit" do
+ result = scope.function_to_bytes(["4k"])
+ result.should(eq(4096))
+ end
+
+ it "should work without a unit" do
+ result = scope.function_to_bytes(["5678"])
+ result.should(eq(5678))
+ end
+
+ it "should convert fractions" do
+ result = scope.function_to_bytes(["1.5 kB"])
+ result.should(eq(1536))
+ end
+
+ it "should convert scientific notation" do
+ result = scope.function_to_bytes(["1.5e2 B"])
+ result.should(eq(150))
+ end
+
+ it "should do nothing with a positive number" do
+ result = scope.function_to_bytes([5678])
+ result.should(eq(5678))
+ end
+
+ it "should should raise a ParseError if input isn't a number" do
+ lambda { scope.function_to_bytes(["foo"]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should should raise a ParseError if prefix is unknown" do
+ lambda { scope.function_to_bytes(["5 uB"]) }.should( raise_error(Puppet::ParseError))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/type_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/type_spec.rb
new file mode 100644
index 0000000000..8fec88f266
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/type_spec.rb
@@ -0,0 +1,43 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the type function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ it "should exist" do
+ Puppet::Parser::Functions.function("type").should == "function_type"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_type([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return string when given a string" do
+ result = scope.function_type(["aaabbbbcccc"])
+ result.should(eq('string'))
+ end
+
+ it "should return array when given an array" do
+ result = scope.function_type([["aaabbbbcccc","asdf"]])
+ result.should(eq('array'))
+ end
+
+ it "should return hash when given a hash" do
+ result = scope.function_type([{"a"=>1,"b"=>2}])
+ result.should(eq('hash'))
+ end
+
+ it "should return integer when given an integer" do
+ result = scope.function_type(["1"])
+ result.should(eq('integer'))
+ end
+
+ it "should return float when given a float" do
+ result = scope.function_type(["1.34"])
+ result.should(eq('float'))
+ end
+
+ it "should return boolean when given a boolean" do
+ result = scope.function_type([true])
+ result.should(eq('boolean'))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/unique_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/unique_spec.rb
new file mode 100644
index 0000000000..5d48d49b72
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/unique_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the unique function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("unique").should == "function_unique"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_unique([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should remove duplicate elements in a string" do
+ result = scope.function_unique(["aabbc"])
+ result.should(eq('abc'))
+ end
+
+ it "should remove duplicate elements in an array" do
+ result = scope.function_unique([["a","a","b","b","c"]])
+ result.should(eq(['a','b','c']))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/upcase_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/upcase_spec.rb
new file mode 100644
index 0000000000..5db55138a6
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/upcase_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the upcase function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("upcase").should == "function_upcase"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_upcase([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should upcase a string" do
+ result = scope.function_upcase(["abc"])
+ result.should(eq('ABC'))
+ end
+
+ it "should do nothing if a string is already upcase" do
+ result = scope.function_upcase(["ABC"])
+ result.should(eq('ABC'))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/uriescape_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/uriescape_spec.rb
new file mode 100644
index 0000000000..371de46873
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/uriescape_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the uriescape function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("uriescape").should == "function_uriescape"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_uriescape([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should uriescape a string" do
+ result = scope.function_uriescape([":/?#[]@!$&'()*+,;= "])
+ result.should(eq('%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D%20'))
+ end
+
+ it "should do nothing if a string is already safe" do
+ result = scope.function_uriescape(["ABCdef"])
+ result.should(eq('ABCdef'))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb
new file mode 100644
index 0000000000..08aaf78992
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb
@@ -0,0 +1,83 @@
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:validate_absolute_path) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ # The subject of these examples is the method itself.
+ subject do
+ # This makes sure the function is loaded within each test
+ function_name = Puppet::Parser::Functions.function(:validate_absolute_path)
+ scope.method(function_name)
+ end
+
+ describe "Valid Paths" do
+ def self.valid_paths
+ %w{
+ C:/
+ C:\\
+ C:\\WINDOWS\\System32
+ C:/windows/system32
+ X:/foo/bar
+ X:\\foo\\bar
+ /var/tmp
+ /var/lib/puppet
+ /var/opt/../lib/puppet
+ }
+ end
+
+ context "Without Puppet::Util.absolute_path? (e.g. Puppet <= 2.6)" do
+ before :each do
+ # The intent here is to mock Puppet to behave like Puppet 2.6 does.
+ # Puppet 2.6 does not have the absolute_path? method. This is only a
+ # convenience test, stdlib should be run with the Puppet 2.6.x in the
+ # $LOAD_PATH in addition to 2.7.x and master.
+ Puppet::Util.expects(:respond_to?).with(:absolute_path?).returns(false)
+ end
+ valid_paths.each do |path|
+ it "validate_absolute_path(#{path.inspect}) should not fail" do
+ expect { subject.call [path] }.not_to raise_error Puppet::ParseError
+ end
+ end
+ end
+
+ context "Puppet without mocking" do
+ valid_paths.each do |path|
+ it "validate_absolute_path(#{path.inspect}) should not fail" do
+ expect { subject.call [path] }.not_to raise_error Puppet::ParseError
+ end
+ end
+ end
+ end
+
+ describe 'Invalid paths' do
+ context 'Garbage inputs' do
+ [
+ nil,
+ [ nil ],
+ { 'foo' => 'bar' },
+ { },
+ '',
+ ].each do |path|
+ it "validate_absolute_path(#{path.inspect}) should fail" do
+ expect { subject.call [path] }.to raise_error Puppet::ParseError
+ end
+ end
+ end
+
+ context 'Relative paths' do
+ %w{
+ relative1
+ .
+ ..
+ ./foo
+ ../foo
+ etc/puppetlabs/puppet
+ opt/puppet/bin
+ }.each do |path|
+ it "validate_absolute_path(#{path.inspect}) should fail" do
+ expect { subject.call [path] }.to raise_error Puppet::ParseError
+ end
+ end
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/validate_array_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_array_spec.rb
new file mode 100644
index 0000000000..4b31cfde42
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_array_spec.rb
@@ -0,0 +1,38 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:validate_array) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ describe 'when calling validate_array from puppet' do
+
+ %w{ true false }.each do |the_string|
+ it "should not compile when #{the_string} is a string" do
+ Puppet[:code] = "validate_array('#{the_string}')"
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/)
+ end
+
+ it "should not compile when #{the_string} is a bare word" do
+ Puppet[:code] = "validate_array(#{the_string})"
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/)
+ end
+ end
+
+ it "should compile when multiple array arguments are passed" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $foo = [ ]
+ $bar = [ 'one', 'two' ]
+ validate_array($foo, $bar)
+ ENDofPUPPETcode
+ scope.compiler.compile
+ end
+
+ it "should not compile when an undef variable is passed" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $foo = undef
+ validate_array($foo)
+ ENDofPUPPETcode
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/)
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/validate_augeas_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_augeas_spec.rb
new file mode 100644
index 0000000000..ab5c140d1e
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_augeas_spec.rb
@@ -0,0 +1,102 @@
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:validate_augeas), :if => Puppet.features.augeas? do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ # The subject of these examplres is the method itself.
+ subject do
+ # This makes sure the function is loaded within each test
+ function_name = Puppet::Parser::Functions.function(:validate_augeas)
+ scope.method(function_name)
+ end
+
+ context 'Using Puppet::Parser::Scope.new' do
+
+ describe 'Garbage inputs' do
+ inputs = [
+ [ nil ],
+ [ [ nil ] ],
+ [ { 'foo' => 'bar' } ],
+ [ { } ],
+ [ '' ],
+ [ "one", "one", "MSG to User", "4th arg" ],
+ ]
+
+ inputs.each do |input|
+ it "validate_augeas(#{input.inspect}) should fail" do
+ expect { subject.call [input] }.to raise_error Puppet::ParseError
+ end
+ end
+ end
+
+ describe 'Valid inputs' do
+ inputs = [
+ [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns' ],
+ [ "proc /proc proc nodev,noexec,nosuid 0 0\n", 'Fstab.lns'],
+ ]
+
+ inputs.each do |input|
+ it "validate_augeas(#{input.inspect}) should not fail" do
+ expect { subject.call input }.not_to raise_error
+ end
+ end
+ end
+
+ describe "Valid inputs which should raise an exception without a message" do
+ # The intent here is to make sure valid inputs raise exceptions when they
+ # don't specify an error message to display. This is the behvior in
+ # 2.2.x and prior.
+ inputs = [
+ [ "root:x:0:0:root\n", 'Passwd.lns' ],
+ [ "127.0.1.1\n", 'Hosts.lns' ],
+ ]
+
+ inputs.each do |input|
+ it "validate_augeas(#{input.inspect}) should fail" do
+ expect { subject.call input }.to raise_error /validate_augeas.*?matched less than it should/
+ end
+ end
+ end
+
+ describe "Nicer Error Messages" do
+ # The intent here is to make sure the function returns the 3rd argument
+ # in the exception thrown
+ inputs = [
+ [ "root:x:0:0:root\n", 'Passwd.lns', [], 'Failed to validate passwd content' ],
+ [ "127.0.1.1\n", 'Hosts.lns', [], 'Wrong hosts content' ],
+ ]
+
+ inputs.each do |input|
+ it "validate_augeas(#{input.inspect}) should fail" do
+ expect { subject.call input }.to raise_error /#{input[2]}/
+ end
+ end
+ end
+
+ describe "Passing simple unit tests" do
+ inputs = [
+ [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
+ [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
+ ]
+
+ inputs.each do |input|
+ it "validate_augeas(#{input.inspect}) should fail" do
+ expect { subject.call input }.not_to raise_error
+ end
+ end
+ end
+
+ describe "Failing simple unit tests" do
+ inputs = [
+ [ "foobar:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
+ [ "root:x:0:0:root:/root:/bin/sh\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
+ ]
+
+ inputs.each do |input|
+ it "validate_augeas(#{input.inspect}) should fail" do
+ expect { subject.call input }.to raise_error /testing path/
+ end
+ end
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/validate_bool_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_bool_spec.rb
new file mode 100644
index 0000000000..261fb2352d
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_bool_spec.rb
@@ -0,0 +1,51 @@
+#! /usr/bin/env/ruby -S rspec
+
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:validate_bool) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ describe 'when calling validate_bool from puppet' do
+
+ %w{ true false }.each do |the_string|
+
+ it "should not compile when #{the_string} is a string" do
+ Puppet[:code] = "validate_bool('#{the_string}')"
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/)
+ end
+
+ it "should compile when #{the_string} is a bare word" do
+ Puppet[:code] = "validate_bool(#{the_string})"
+ scope.compiler.compile
+ end
+
+ end
+
+ it "should not compile when an arbitrary string is passed" do
+ Puppet[:code] = 'validate_bool("jeff and dan are awesome")'
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/)
+ end
+
+ it "should not compile when no arguments are passed" do
+ Puppet[:code] = 'validate_bool()'
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+
+ it "should compile when multiple boolean arguments are passed" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $foo = true
+ $bar = false
+ validate_bool($foo, $bar, true, false)
+ ENDofPUPPETcode
+ scope.compiler.compile
+ end
+
+ it "should compile when multiple boolean arguments are passed" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $foo = true
+ $bar = false
+ validate_bool($foo, $bar, true, false, 'jeff')
+ ENDofPUPPETcode
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/)
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/validate_cmd_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_cmd_spec.rb
new file mode 100644
index 0000000000..69ea7f4960
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_cmd_spec.rb
@@ -0,0 +1,81 @@
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:validate_cmd) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ # The subject of these examplres is the method itself.
+ subject do
+ # This makes sure the function is loaded within each test
+ function_name = Puppet::Parser::Functions.function(:validate_cmd)
+ scope.method(function_name)
+ end
+
+ context 'Using Puppet::Parser::Scope.new' do
+
+ describe 'Garbage inputs' do
+ inputs = [
+ [ nil ],
+ [ [ nil ] ],
+ [ { 'foo' => 'bar' } ],
+ [ { } ],
+ [ '' ],
+ [ "one", "one", "MSG to User", "4th arg" ],
+ ]
+
+ inputs.each do |input|
+ it "validate_cmd(#{input.inspect}) should fail" do
+ expect { subject.call [input] }.to raise_error Puppet::ParseError
+ end
+ end
+ end
+
+ describe 'Valid inputs' do
+ inputs = [
+ [ '/full/path/to/something', '/bin/echo' ],
+ [ '/full/path/to/something', '/bin/cat' ],
+ ]
+
+ inputs.each do |input|
+ it "validate_cmd(#{input.inspect}) should not fail" do
+ expect { subject.call input }.not_to raise_error
+ end
+ end
+ end
+
+ describe "Valid inputs which should raise an exception without a message" do
+ # The intent here is to make sure valid inputs raise exceptions when they
+ # don't specify an error message to display. This is the behvior in
+ # 2.2.x and prior.
+ inputs = [
+ [ "hello", "/bin/false" ],
+ ]
+
+ inputs.each do |input|
+ it "validate_cmd(#{input.inspect}) should fail" do
+ expect { subject.call input }.to raise_error /validate_cmd.*?failed to validate content with command/
+ end
+ end
+ end
+
+ describe "Nicer Error Messages" do
+ # The intent here is to make sure the function returns the 3rd argument
+ # in the exception thrown
+ inputs = [
+ [ "hello", [ "bye", "later", "adios" ], "MSG to User" ],
+ [ "greetings", "salutations", "Error, greetings does not match salutations" ],
+ ]
+
+ inputs.each do |input|
+ it "validate_cmd(#{input.inspect}) should fail" do
+ expect { subject.call input }.to raise_error /#{input[2]}/
+ end
+ end
+ end
+
+ describe "Test output message" do
+ it "validate_cmd('whatever', 'kthnksbye') should fail" do
+ expect { subject.call ['whatever', 'kthnksbye'] }.to raise_error /kthnksbye.* returned 1/
+ end
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/validate_hash_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_hash_spec.rb
new file mode 100644
index 0000000000..a0c35c2304
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_hash_spec.rb
@@ -0,0 +1,43 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:validate_hash) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ describe 'when calling validate_hash from puppet' do
+
+ %w{ true false }.each do |the_string|
+
+ it "should not compile when #{the_string} is a string" do
+ Puppet[:code] = "validate_hash('#{the_string}')"
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/)
+ end
+
+ it "should not compile when #{the_string} is a bare word" do
+ Puppet[:code] = "validate_hash(#{the_string})"
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/)
+ end
+
+ end
+
+ it "should compile when multiple hash arguments are passed" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $foo = {}
+ $bar = { 'one' => 'two' }
+ validate_hash($foo, $bar)
+ ENDofPUPPETcode
+ scope.compiler.compile
+ end
+
+ it "should not compile when an undef variable is passed" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $foo = undef
+ validate_hash($foo)
+ ENDofPUPPETcode
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/)
+ end
+
+ end
+
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/validate_re_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_re_spec.rb
new file mode 100644
index 0000000000..d189efb667
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_re_spec.rb
@@ -0,0 +1,76 @@
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:validate_re) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ # The subject of these examplres is the method itself.
+ subject do
+ # This makes sure the function is loaded within each test
+ function_name = Puppet::Parser::Functions.function(:validate_re)
+ scope.method(function_name)
+ end
+
+ context 'Using Puppet::Parser::Scope.new' do
+
+ describe 'Garbage inputs' do
+ inputs = [
+ [ nil ],
+ [ [ nil ] ],
+ [ { 'foo' => 'bar' } ],
+ [ { } ],
+ [ '' ],
+ [ "one", "one", "MSG to User", "4th arg" ],
+ ]
+
+ inputs.each do |input|
+ it "validate_re(#{input.inspect}) should fail" do
+ expect { subject.call [input] }.to raise_error Puppet::ParseError
+ end
+ end
+ end
+
+ describe 'Valid inputs' do
+ inputs = [
+ [ '/full/path/to/something', '^/full' ],
+ [ '/full/path/to/something', 'full' ],
+ [ '/full/path/to/something', ['full', 'absent'] ],
+ [ '/full/path/to/something', ['full', 'absent'], 'Message to the user' ],
+ ]
+
+ inputs.each do |input|
+ it "validate_re(#{input.inspect}) should not fail" do
+ expect { subject.call input }.not_to raise_error
+ end
+ end
+ end
+ describe "Valid inputs which should raise an exception without a message" do
+ # The intent here is to make sure valid inputs raise exceptions when they
+ # don't specify an error message to display. This is the behvior in
+ # 2.2.x and prior.
+ inputs = [
+ [ "hello", [ "bye", "later", "adios" ] ],
+ [ "greetings", "salutations" ],
+ ]
+
+ inputs.each do |input|
+ it "validate_re(#{input.inspect}) should fail" do
+ expect { subject.call input }.to raise_error /validate_re.*?does not match/
+ end
+ end
+ end
+ describe "Nicer Error Messages" do
+ # The intent here is to make sure the function returns the 3rd argument
+ # in the exception thrown
+ inputs = [
+ [ "hello", [ "bye", "later", "adios" ], "MSG to User" ],
+ [ "greetings", "salutations", "Error, greetings does not match salutations" ],
+ ]
+
+ inputs.each do |input|
+ it "validate_re(#{input.inspect}) should fail" do
+ expect { subject.call input }.to raise_error /#{input[2]}/
+ end
+ end
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/validate_slength_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_slength_spec.rb
new file mode 100755
index 0000000000..eccf908de0
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_slength_spec.rb
@@ -0,0 +1,48 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe "the validate_slength function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("validate_slength").should == "function_validate_slength"
+ end
+
+ it "should raise a ParseError if there is less than 2 arguments" do
+ expect { scope.function_validate_slength([]) }.to(raise_error(Puppet::ParseError))
+ expect { scope.function_validate_slength(["asdf"]) }.to(raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if argument 2 doesn't convert to a fixnum" do
+ expect { scope.function_validate_slength(["moo",["2"]]) }.to(raise_error(Puppet::ParseError, /Couldn't convert whatever you passed/))
+ end
+
+ it "should raise a ParseError if argument 2 converted, but to 0, e.g. a string" do
+ expect { scope.function_validate_slength(["moo","monkey"]) }.to(raise_error(Puppet::ParseError, /please pass a positive number as max_length/))
+ end
+
+ it "should raise a ParseError if argument 2 converted, but to 0" do
+ expect { scope.function_validate_slength(["moo","0"]) }.to(raise_error(Puppet::ParseError, /please pass a positive number as max_length/))
+ end
+
+ it "should fail if string greater then size" do
+ expect { scope.function_validate_slength(["test", 2]) }.to(raise_error(Puppet::ParseError, /It should have been less than or equal to/))
+ end
+
+ it "should fail if you pass an array of something other than strings" do
+ expect { scope.function_validate_slength([["moo",["moo"],Hash.new["moo" => 7]], 7]) }.to(raise_error(Puppet::ParseError, /is not a string, it's a/))
+ end
+
+ it "should fail if you pass something other than a string or array" do
+ expect { scope.function_validate_slength([Hash.new["moo" => "7"],6]) }.to(raise_error(Puppet::ParseError), /please pass a string, or an array of strings/)
+ end
+
+ it "should not fail if string is smaller or equal to size" do
+ expect { scope.function_validate_slength(["test", 5]) }.to_not(raise_error(Puppet::ParseError))
+ end
+
+ it "should not fail if array of string is are all smaller or equal to size" do
+ expect { scope.function_validate_slength([["moo","foo","bar"], 5]) }.to_not(raise_error(Puppet::ParseError))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/validate_string_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_string_spec.rb
new file mode 100644
index 0000000000..3b4fb3e1da
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/validate_string_spec.rb
@@ -0,0 +1,60 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:validate_string) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ describe 'when calling validate_string from puppet' do
+
+ %w{ foo bar baz }.each do |the_string|
+
+ it "should compile when #{the_string} is a string" do
+ Puppet[:code] = "validate_string('#{the_string}')"
+ scope.compiler.compile
+ end
+
+ it "should compile when #{the_string} is a bare word" do
+ Puppet[:code] = "validate_string(#{the_string})"
+ scope.compiler.compile
+ end
+
+ end
+
+ %w{ true false }.each do |the_string|
+ it "should compile when #{the_string} is a string" do
+ Puppet[:code] = "validate_string('#{the_string}')"
+ scope.compiler.compile
+ end
+
+ it "should not compile when #{the_string} is a bare word" do
+ Puppet[:code] = "validate_string(#{the_string})"
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a string/)
+ end
+ end
+
+ it "should compile when multiple string arguments are passed" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $foo = ''
+ $bar = 'two'
+ validate_string($foo, $bar)
+ ENDofPUPPETcode
+ scope.compiler.compile
+ end
+
+ it "should compile when an explicitly undef variable is passed (NOTE THIS MAY NOT BE DESIRABLE)" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $foo = undef
+ validate_string($foo)
+ ENDofPUPPETcode
+ scope.compiler.compile
+ end
+
+ it "should compile when an undefined variable is passed (NOTE THIS MAY NOT BE DESIRABLE)" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ validate_string($foobarbazishouldnotexist)
+ ENDofPUPPETcode
+ scope.compiler.compile
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/values_at_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/values_at_spec.rb
new file mode 100644
index 0000000000..08e95a567b
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/values_at_spec.rb
@@ -0,0 +1,38 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the values_at function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("values_at").should == "function_values_at"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_values_at([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if you try to use a range where stop is greater then start" do
+ lambda { scope.function_values_at([['a','b'],["3-1"]]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return a value at from an array" do
+ result = scope.function_values_at([['a','b','c'],"1"])
+ result.should(eq(['b']))
+ end
+
+ it "should return a value at from an array when passed a range" do
+ result = scope.function_values_at([['a','b','c'],"0-1"])
+ result.should(eq(['a','b']))
+ end
+
+ it "should return chosen values from an array when passed number of indexes" do
+ result = scope.function_values_at([['a','b','c'],["0","2"]])
+ result.should(eq(['a','c']))
+ end
+
+ it "should return chosen values from an array when passed ranges and multiple indexes" do
+ result = scope.function_values_at([['a','b','c','d','e','f','g'],["0","2","4-5"]])
+ result.should(eq(['a','c','e','f']))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/values_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/values_spec.rb
new file mode 100644
index 0000000000..14ae417638
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/values_spec.rb
@@ -0,0 +1,31 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the values function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("values").should == "function_values"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_values([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return values from a hash" do
+ result = scope.function_values([{'a'=>'1','b'=>'2','c'=>'3'}])
+ # =~ is the RSpec::Matchers::MatchArray matcher.
+ # A.K.A. "array with same elements" (multiset) matching
+ result.should =~ %w{ 1 2 3 }
+ end
+
+ it "should return a multiset" do
+ result = scope.function_values([{'a'=>'1','b'=>'3','c'=>'3'}])
+ result.should =~ %w{ 1 3 3 }
+ result.should_not =~ %w{ 1 3 }
+ end
+
+ it "should raise a ParseError unless a Hash is provided" do
+ lambda { scope.function_values([['a','b','c']]) }.should( raise_error(Puppet::ParseError))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/parser/functions/zip_spec.rb b/puppet/stdlib/spec/unit/puppet/parser/functions/zip_spec.rb
new file mode 100644
index 0000000000..f45ab17308
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/parser/functions/zip_spec.rb
@@ -0,0 +1,15 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the zip function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_zip([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should be able to zip an array" do
+ result = scope.function_zip([['1','2','3'],['4','5','6']])
+ result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]]))
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/provider/file_line/ruby_spec.rb b/puppet/stdlib/spec/unit/puppet/provider/file_line/ruby_spec.rb
new file mode 100644
index 0000000000..7857d399fc
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/provider/file_line/ruby_spec.rb
@@ -0,0 +1,127 @@
+require 'puppet'
+require 'tempfile'
+provider_class = Puppet::Type.type(:file_line).provider(:ruby)
+describe provider_class do
+ context "when adding" do
+ before :each do
+ # TODO: these should be ported over to use the PuppetLabs spec_helper
+ # file fixtures once the following pull request has been merged:
+ # https://github.com/puppetlabs/puppetlabs-stdlib/pull/73/files
+ tmp = Tempfile.new('tmp')
+ @tmpfile = tmp.path
+ tmp.close!
+ @resource = Puppet::Type::File_line.new(
+ {:name => 'foo', :path => @tmpfile, :line => 'foo'}
+ )
+ @provider = provider_class.new(@resource)
+ end
+ it 'should detect if the line exists in the file' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write('foo')
+ end
+ @provider.exists?.should be_true
+ end
+ it 'should detect if the line does not exist in the file' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write('foo1')
+ end
+ @provider.exists?.should be_nil
+ end
+ it 'should append to an existing file when creating' do
+ @provider.create
+ File.read(@tmpfile).chomp.should == 'foo'
+ end
+ end
+
+ context "when matching" do
+ before :each do
+ # TODO: these should be ported over to use the PuppetLabs spec_helper
+ # file fixtures once the following pull request has been merged:
+ # https://github.com/puppetlabs/puppetlabs-stdlib/pull/73/files
+ tmp = Tempfile.new('tmp')
+ @tmpfile = tmp.path
+ tmp.close!
+ @resource = Puppet::Type::File_line.new(
+ {
+ :name => 'foo',
+ :path => @tmpfile,
+ :line => 'foo = bar',
+ :match => '^foo\s*=.*$',
+ }
+ )
+ @provider = provider_class.new(@resource)
+ end
+
+ it 'should raise an error if more than one line matches, and should not have modified the file' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz")
+ end
+ @provider.exists?.should be_nil
+ expect { @provider.create }.to raise_error(Puppet::Error, /More than one line.*matches/)
+ File.read(@tmpfile).should eql("foo1\nfoo=blah\nfoo2\nfoo=baz")
+ end
+
+ it 'should replace a line that matches' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo=blah\nfoo2")
+ end
+ @provider.exists?.should be_nil
+ @provider.create
+ File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2")
+ end
+ it 'should add a new line if no lines match' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo2")
+ end
+ @provider.exists?.should be_nil
+ @provider.create
+ File.read(@tmpfile).should eql("foo1\nfoo2\nfoo = bar\n")
+ end
+ it 'should do nothing if the exact line already exists' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo = bar\nfoo2")
+ end
+ @provider.exists?.should be_true
+ @provider.create
+ File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2")
+ end
+ end
+
+ context "when removing" do
+ before :each do
+ # TODO: these should be ported over to use the PuppetLabs spec_helper
+ # file fixtures once the following pull request has been merged:
+ # https://github.com/puppetlabs/puppetlabs-stdlib/pull/73/files
+ tmp = Tempfile.new('tmp')
+ @tmpfile = tmp.path
+ tmp.close!
+ @resource = Puppet::Type::File_line.new(
+ {:name => 'foo', :path => @tmpfile, :line => 'foo', :ensure => 'absent' }
+ )
+ @provider = provider_class.new(@resource)
+ end
+ it 'should remove the line if it exists' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo\nfoo2")
+ end
+ @provider.destroy
+ File.read(@tmpfile).should eql("foo1\nfoo2")
+ end
+
+ it 'should remove the line without touching the last new line' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo\nfoo2\n")
+ end
+ @provider.destroy
+ File.read(@tmpfile).should eql("foo1\nfoo2\n")
+ end
+
+ it 'should remove any occurence of the line' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo\nfoo2\nfoo\nfoo")
+ end
+ @provider.destroy
+ File.read(@tmpfile).should eql("foo1\nfoo2\n")
+ end
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/type/anchor_spec.rb b/puppet/stdlib/spec/unit/puppet/type/anchor_spec.rb
new file mode 100644
index 0000000000..2030b83f2e
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/type/anchor_spec.rb
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby
+
+require 'puppet'
+
+anchor = Puppet::Type.type(:anchor).new(:name => "ntp::begin")
+
+describe anchor do
+ it "should stringify normally" do
+ anchor.to_s.should == "Anchor[ntp::begin]"
+ end
+end
diff --git a/puppet/stdlib/spec/unit/puppet/type/file_line_spec.rb b/puppet/stdlib/spec/unit/puppet/type/file_line_spec.rb
new file mode 100644
index 0000000000..edc64bd1e5
--- /dev/null
+++ b/puppet/stdlib/spec/unit/puppet/type/file_line_spec.rb
@@ -0,0 +1,69 @@
+require 'puppet'
+require 'tempfile'
+describe Puppet::Type.type(:file_line) do
+ let :file_line do
+ Puppet::Type.type(:file_line).new(:name => 'foo', :line => 'line', :path => '/tmp/path')
+ end
+ it 'should accept a line and path' do
+ file_line[:line] = 'my_line'
+ file_line[:line].should == 'my_line'
+ file_line[:path] = '/my/path'
+ file_line[:path].should == '/my/path'
+ end
+ it 'should accept a match regex' do
+ file_line[:match] = '^foo.*$'
+ file_line[:match].should == '^foo.*$'
+ end
+ it 'should not accept a match regex that does not match the specified line' do
+ expect {
+ Puppet::Type.type(:file_line).new(
+ :name => 'foo',
+ :path => '/my/path',
+ :line => 'foo=bar',
+ :match => '^bar=blah$'
+ )}.to raise_error(Puppet::Error, /the value must be a regex that matches/)
+ end
+ it 'should accept a match regex that does match the specified line' do
+ expect {
+ Puppet::Type.type(:file_line).new(
+ :name => 'foo',
+ :path => '/my/path',
+ :line => 'foo=bar',
+ :match => '^\s*foo=.*$'
+ )}.not_to raise_error
+ end
+ it 'should accept posix filenames' do
+ file_line[:path] = '/tmp/path'
+ file_line[:path].should == '/tmp/path'
+ end
+ it 'should not accept unqualified path' do
+ expect { file_line[:path] = 'file' }.to raise_error(Puppet::Error, /File paths must be fully qualified/)
+ end
+ it 'should require that a line is specified' do
+ expect { Puppet::Type.type(:file_line).new(:name => 'foo', :path => '/tmp/file') }.to raise_error(Puppet::Error, /Both line and path are required attributes/)
+ end
+ it 'should require that a file is specified' do
+ expect { Puppet::Type.type(:file_line).new(:name => 'foo', :line => 'path') }.to raise_error(Puppet::Error, /Both line and path are required attributes/)
+ end
+ it 'should default to ensure => present' do
+ file_line[:ensure].should eq :present
+ end
+
+ it "should autorequire the file it manages" do
+ catalog = Puppet::Resource::Catalog.new
+ file = Puppet::Type.type(:file).new(:name => "/tmp/path")
+ catalog.add_resource file
+ catalog.add_resource file_line
+
+ relationship = file_line.autorequire.find do |rel|
+ (rel.source.to_s == "File[/tmp/path]") and (rel.target.to_s == file_line.to_s)
+ end
+ relationship.should be_a Puppet::Relationship
+ end
+
+ it "should not autorequire the file it manages if it is not managed" do
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource file_line
+ file_line.autorequire.should be_empty
+ end
+end
diff --git a/puppet/stdlib/spec/watchr.rb b/puppet/stdlib/spec/watchr.rb
new file mode 100644
index 0000000000..885ef1d5f1
--- /dev/null
+++ b/puppet/stdlib/spec/watchr.rb
@@ -0,0 +1,86 @@
+ENV['FOG_MOCK'] ||= 'true'
+ENV['AUTOTEST'] = 'true'
+ENV['WATCHR'] = '1'
+
+system 'clear'
+
+def growl(message)
+ growlnotify = `which growlnotify`.chomp
+ title = "Watchr Test Results"
+ image = case message
+ when /(\d+)\s+?(failure|error)/i
+ ($1.to_i == 0) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
+ else
+ '~/.watchr_images/unknown.png'
+ end
+ options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
+ system %(#{growlnotify} #{options} &)
+end
+
+def run(cmd)
+ puts(cmd)
+ `#{cmd}`
+end
+
+def run_spec_test(file)
+ if File.exist? file
+ result = run "rspec --format p --color #{file}"
+ growl result.split("\n").last
+ puts result
+ else
+ puts "FIXME: No test #{file} [#{Time.now}]"
+ end
+end
+
+def filter_rspec(data)
+ data.split("\n").find_all do |l|
+ l =~ /^(\d+)\s+exampl\w+.*?(\d+).*?failur\w+.*?(\d+).*?pending/
+ end.join("\n")
+end
+
+def run_all_tests
+ system('clear')
+ files = Dir.glob("spec/**/*_spec.rb").join(" ")
+ result = run "rspec #{files}"
+ growl_results = filter_rspec result
+ growl growl_results
+ puts result
+ puts "GROWL: #{growl_results}"
+end
+
+# Ctrl-\
+Signal.trap 'QUIT' do
+ puts " --- Running all tests ---\n\n"
+ run_all_tests
+end
+
+@interrupted = false
+
+# Ctrl-C
+Signal.trap 'INT' do
+ if @interrupted then
+ @wants_to_quit = true
+ abort("\n")
+ else
+ puts "Interrupt a second time to quit"
+ @interrupted = true
+ Kernel.sleep 1.5
+ # raise Interrupt, nil # let the run loop catch it
+ run_suite
+ end
+end
+
+def file2spec(file)
+ result = file.sub('lib/puppet/', 'spec/unit/puppet/').gsub(/\.rb$/, '_spec.rb')
+ result = file.sub('lib/facter/', 'spec/unit/facter/').gsub(/\.rb$/, '_spec.rb')
+end
+
+
+watch( 'spec/.*_spec\.rb' ) do |md|
+ #run_spec_test(md[0])
+ run_all_tests
+end
+watch( 'lib/.*\.rb' ) do |md|
+ # run_spec_test(file2spec(md[0]))
+ run_all_tests
+end
diff --git a/puppet/stdlib/tests/file_line.pp b/puppet/stdlib/tests/file_line.pp
new file mode 100644
index 0000000000..eea693e15e
--- /dev/null
+++ b/puppet/stdlib/tests/file_line.pp
@@ -0,0 +1,9 @@
+# This is a simple smoke test
+# of the file_line resource type.
+file { '/tmp/dansfile':
+ ensure => present
+}->
+file_line { 'dans_line':
+ line => 'dan is awesome',
+ path => '/tmp/dansfile',
+}
diff --git a/puppet/stdlib/tests/has_interface_with.pp b/puppet/stdlib/tests/has_interface_with.pp
new file mode 100644
index 0000000000..e1f1353cdd
--- /dev/null
+++ b/puppet/stdlib/tests/has_interface_with.pp
@@ -0,0 +1,10 @@
+include stdlib
+info('has_interface_with(\'lo\'):', has_interface_with('lo'))
+info('has_interface_with(\'loX\'):', has_interface_with('loX'))
+info('has_interface_with(\'ipaddress\', \'127.0.0.1\'):', has_interface_with('ipaddress', '127.0.0.1'))
+info('has_interface_with(\'ipaddress\', \'127.0.0.100\'):', has_interface_with('ipaddress', '127.0.0.100'))
+info('has_interface_with(\'network\', \'127.0.0.0\'):', has_interface_with('network', '127.0.0.0'))
+info('has_interface_with(\'network\', \'128.0.0.0\'):', has_interface_with('network', '128.0.0.0'))
+info('has_interface_with(\'netmask\', \'255.0.0.0\'):', has_interface_with('netmask', '255.0.0.0'))
+info('has_interface_with(\'netmask\', \'256.0.0.0\'):', has_interface_with('netmask', '256.0.0.0'))
+
diff --git a/puppet/stdlib/tests/has_ip_address.pp b/puppet/stdlib/tests/has_ip_address.pp
new file mode 100644
index 0000000000..8429a88553
--- /dev/null
+++ b/puppet/stdlib/tests/has_ip_address.pp
@@ -0,0 +1,3 @@
+include stdlib
+info('has_ip_address(\'192.168.1.256\'):', has_ip_address('192.168.1.256'))
+info('has_ip_address(\'127.0.0.1\'):', has_ip_address('127.0.0.1'))
diff --git a/puppet/stdlib/tests/has_ip_network.pp b/puppet/stdlib/tests/has_ip_network.pp
new file mode 100644
index 0000000000..a15d8c011b
--- /dev/null
+++ b/puppet/stdlib/tests/has_ip_network.pp
@@ -0,0 +1,4 @@
+include stdlib
+info('has_ip_network(\'127.0.0.0\'):', has_ip_network('127.0.0.0'))
+info('has_ip_network(\'128.0.0.0\'):', has_ip_network('128.0.0.0'))
+
diff --git a/puppet/stdlib/tests/init.pp b/puppet/stdlib/tests/init.pp
new file mode 100644
index 0000000000..9675d8374b
--- /dev/null
+++ b/puppet/stdlib/tests/init.pp
@@ -0,0 +1 @@
+include stdlib
diff --git a/puppet/zulip/manifests/base.pp b/puppet/zulip/manifests/base.pp
index a1db8f07ad..bbf5275c68 100644
--- a/puppet/zulip/manifests/base.pp
+++ b/puppet/zulip/manifests/base.pp
@@ -1,4 +1,5 @@
class zulip::base {
+ include apt
$base_packages = [ # Basic requirements for effective operation of a server
"ntp",
# This is just good practice
diff --git a/puppet/zulip/manifests/enterprise.pp b/puppet/zulip/manifests/enterprise.pp
index 5f7d4214c7..1ce996e7fb 100644
--- a/puppet/zulip/manifests/enterprise.pp
+++ b/puppet/zulip/manifests/enterprise.pp
@@ -3,13 +3,14 @@ class zulip::enterprise {
include zulip::app_frontend
include zulip::postgres_appdb
- apt::key {"E5FB045CA79AA8FC25FDE9F3B4F81D07A529EF65":
- source => "https://zulip.com/dist/keys/enterprise.asc",
- }
-
- apt::sources_list {"zulip":
- ensure => present,
- content => 'deb http://apt.zulip.com/enterprise precise v1',
+ apt::source {'zulip':
+ location => 'http://apt.zulip.com/enterprise',
+ release => 'precise',
+ repos => 'v1',
+ key => 'E5FB045CA79AA8FC25FDE9F3B4F81D07A529EF65',
+ key_source => 'https://zulip.com/dist/keys/enterprise.asc',
+ pin => '995',
+ include_src => true,
}
file { "/etc/nginx/sites-available/zulip-enterprise":
diff --git a/puppet/zulip_internal/manifests/base.pp b/puppet/zulip_internal/manifests/base.pp
index 0cf8fef152..17e297b17c 100644
--- a/puppet/zulip_internal/manifests/base.pp
+++ b/puppet/zulip_internal/manifests/base.pp
@@ -17,13 +17,14 @@ class zulip_internal::base {
]
package { $org_base_packages: ensure => "installed" }
- apt::key {"E5FB045CA79AA8FC25FDE9F3B4F81D07A529EF65":
- source => "https://zulip.com/dist/keys/ops.asc",
- }
-
- apt::sources_list {"zulip":
- ensure => present,
- content => 'deb http://apt.zulip.com/ops wheezy main',
+ apt::source {'zulip':
+ location => 'http://apt.zulip.com/ops',
+ release => 'wheezy',
+ repos => 'main',
+ key => 'E5FB045CA79AA8FC25FDE9F3B4F81D07A529EF65',
+ key_source => 'https://zulip.com/dist/keys/ops.asc',
+ pin => '995',
+ include_src => true,
}
file { '/etc/apt/apt.conf.d/02periodic':