diff --git a/puppet/modules/scripts/files/scripts/updater/login.sh b/puppet/modules/scripts/files/scripts/updater/login.sh
new file mode 100755
index 0000000..2c5a25a
--- /dev/null
+++ b/puppet/modules/scripts/files/scripts/updater/login.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+nohup /usr/bin/php5 /home/vagrant/scripts/updater/updater.php >/dev/null 2>&1 &
+
+if [ -f /home/vagrant/scripts/updater/UPDATE_AVAILABLE ]; then
+ VERSION=`cat /home/vagrant/scripts/updater/UPDATE_AVAILABLE`
+ echo ""
+ echo "New release $VERSION available for joomla-console."
+
+ read -r -p "${1:-Do you want to update now? [y/N]} " response
+ case $response in
+ [yY][eE][sS]|[yY])
+ sudo composer self-update
+ composer global require joomlatools/joomla-console:$VERSION
+ rm -f /home/vagrant/scripts/updater/UPDATE_AVAILABLE
+ ;;
+ *)
+ exit
+ ;;
+ esac
+fi
+
diff --git a/puppet/modules/scripts/files/scripts/updater/updater.php b/puppet/modules/scripts/files/scripts/updater/updater.php
new file mode 100644
index 0000000..845611d
--- /dev/null
+++ b/puppet/modules/scripts/files/scripts/updater/updater.php
@@ -0,0 +1,76 @@
+#!/usr/bin/php5
+&1", $result, $code);
+
+if ($code === 1) {
+ exit(1); // Failed to fetch info from packagist
+}
+
+$versions = array();
+foreach ($result as $line => $content)
+{
+ $content = trim($content);
+
+ if (strpos($content, 'versions') === 0)
+ {
+ $parts = explode(':', $content);
+
+ if (count($parts) > 1)
+ {
+ $versions = explode(', ', $parts[1]);
+ break;
+ }
+ }
+}
+
+$versions = array_map('trim', $versions);
+array_filter($versions);
+
+if (!count($versions)) {
+ exit(1); // No available versions found!
+}
+
+$manifest = json_decode(file_get_contents('/home/vagrant/.composer/composer.lock'));
+if (!$manifest) {
+ exit(1); // No composer.lock file?
+}
+
+$currentVersion = false;
+foreach ($manifest->packages as $package)
+{
+ if ($package->name == 'joomlatools/joomla-console')
+ {
+ if (substr($package->version, 0, 1) != 'v') {
+ return; // Only update stable releases
+ }
+
+ $currentVersion = substr($package->version, 1);
+
+ break;
+ }
+}
+
+if (!$currentVersion) {
+ exit(1); // Could not find current version
+}
+
+$latest = '0.1';
+foreach ($versions as $version)
+{
+ if (preg_match('/^v[0-9]+\.[0-9]+\.[0-9]+$/', $version))
+ {
+ $version = substr($version, 1);
+
+ if (version_compare($version, $currentVersion, '>') && version_compare($version, $latest, '>')) {
+ $latest = $version;
+ }
+ }
+}
+
+if ($latest != '0.1') {
+ file_put_contents('/home/vagrant/scripts/updater/UPDATE_AVAILABLE', $latest);
+}
diff --git a/puppet/modules/scripts/manifests/init.pp b/puppet/modules/scripts/manifests/init.pp
index feef9e4..828226b 100644
--- a/puppet/modules/scripts/manifests/init.pp
+++ b/puppet/modules/scripts/manifests/init.pp
@@ -8,22 +8,46 @@
}
exec { 'make-scripts-executable':
- command => 'chmod +x /home/vagrant/scripts/remove_dotunderscore',
+ command => 'chmod +x /home/vagrant/scripts/remove_dotunderscore /home/vagrant/scripts/updater/login.sh',
require => File['/home/vagrant/scripts']
}
exec { 'add-scripts-to-path':
- command => 'echo "export PATH=\$PATH:/home/vagrant/.composer/vendor/bin" >> /home/vagrant/.profile',
- unless => 'grep ":/home/vagrant/.composer/vendor/bin" /home/vagrant/.profile',
+ command => 'echo "export PATH=\$PATH:/home/vagrant/.composer/vendor/bin" >> /home/vagrant/.bash_profile',
+ unless => 'grep ":/home/vagrant/.composer/vendor/bin" /home/vagrant/.bash_profile',
require => Exec['make-scripts-executable']
}
exec { 'add-console':
- command => 'composer global require joomlatools/joomla-console:1.* --no-interaction',
+ command => 'composer global require joomlatools/joomla-console:* --no-interaction',
unless => '[ -d /home/vagrant/.composer/vendor/joomlatools/joomla-console ]',
require => [File['/home/vagrant/scripts'], Class['Composer']],
user => vagrant,
environment => 'COMPOSER_HOME=/home/vagrant/.composer'
}
+ file {'/home/vagrant/.bash_profile':
+ ensure => file,
+ owner => vagrant,
+ group => vagrant,
+ notify => [File_line['joomla-console-updater'], File_line['cd-to-www-dir']]
+ }
+
+ file_line { 'joomla-console-updater':
+ path => '/home/vagrant/.bash_profile',
+ line => '/home/vagrant/scripts/updater/login.sh',
+ require => Exec['make-scripts-executable']
+ }
+
+ file_line { 'load-bashrc':
+ path => '/home/vagrant/.bash_profile',
+ line => '[ -f ~/.bashrc ] && . ~/.bashrc',
+ require => File['/home/vagrant/.bash_profile']
+ }
+
+ file_line { 'cd-to-www-dir':
+ path => '/home/vagrant/.bash_profile',
+ line => '[ -d /var/www ] && cd /var/www',
+ require => File_Line['load-bashrc']
+ }
}
\ No newline at end of file
diff --git a/puppet/modules/stdlib/.gemspec b/puppet/modules/stdlib/.gemspec
new file mode 100755
index 0000000..e274950
--- /dev/null
+++ b/puppet/modules/stdlib/.gemspec
@@ -0,0 +1,40 @@
+#
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = "puppetmodule-stdlib"
+
+ s.version = "4.0.2"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Puppet Labs"]
+ s.date = "2013-04-12"
+ s.description = [ 'This Gem format of the stdlib module is intended to make',
+ 'it easier for _module authors_ to resolve dependencies',
+ 'using a Gemfile when running automated testing jobs like',
+ 'Travis or Jenkins. The recommended best practice for',
+ 'installation by end users is to use the `puppet module',
+ 'install` command to install stdlib from the [Puppet',
+ 'Forge](http://forge.puppetlabs.com/puppetlabs/stdlib).' ].join(' ')
+ s.email = "puppet-dev@puppetlabs.com"
+ s.executables = []
+ s.files = [ 'CHANGELOG', 'CONTRIBUTING.md', 'Gemfile', 'LICENSE', 'Modulefile',
+ 'README.markdown', 'README_DEVELOPER.markdown', 'RELEASE_PROCESS.markdown',
+ 'Rakefile', 'spec/spec.opts' ]
+ s.files += Dir['lib/**/*.rb'] + Dir['manifests/**/*.pp'] + Dir['tests/**/*.pp'] + Dir['spec/**/*.rb']
+ s.homepage = "http://forge.puppetlabs.com/puppetlabs/stdlib"
+ s.rdoc_options = ["--title", "Puppet Standard Library Development Gem", "--main", "README.markdown", "--line-numbers"]
+ s.require_paths = ["lib"]
+ s.rubyforge_project = "puppetmodule-stdlib"
+ s.rubygems_version = "1.8.24"
+ s.summary = "This gem provides a way to make the standard library available for other module spec testing tasks."
+
+ if s.respond_to? :specification_version then
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ else
+ end
+ else
+ end
+end
diff --git a/puppet/modules/stdlib/.gitignore b/puppet/modules/stdlib/.gitignore
new file mode 100755
index 0000000..2e3ca63
--- /dev/null
+++ b/puppet/modules/stdlib/.gitignore
@@ -0,0 +1,8 @@
+pkg/
+.DS_Store
+metadata.json
+coverage/
+spec/fixtures/
+Gemfile.lock
+.bundle/
+vendor/bundle/
diff --git a/puppet/modules/stdlib/.rspec b/puppet/modules/stdlib/.rspec
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/.travis.yml b/puppet/modules/stdlib/.travis.yml
new file mode 100755
index 0000000..1bb1889
--- /dev/null
+++ b/puppet/modules/stdlib/.travis.yml
@@ -0,0 +1,25 @@
+language: ruby
+bundler_args: --without development
+script: "bundle exec rake spec SPEC_OPTS='--color --format documentation'"
+rvm:
+ - 1.8.7
+ - 1.9.3
+ - 2.0.0
+ - ruby-head
+env:
+ - PUPPET_GEM_VERSION=">= 3.0.0"
+matrix:
+ allow_failures:
+ - rvm: 2.0.0
+ - rvm: ruby-head
+ include:
+ - rvm: 1.8.7
+ env: PUPPET_GEM_VERSION="~> 2.7"
+notifications:
+ email: false
+ webhooks:
+ urls:
+ - https://puppet-dev-community.herokuapp.com/event/travis-ci/
+ on_success: always
+ on_failure: always
+ on_start: yes
diff --git a/puppet/modules/stdlib/CHANGELOG b/puppet/modules/stdlib/CHANGELOG
old mode 100644
new mode 100755
index b7c3ced..e1a095f
--- a/puppet/modules/stdlib/CHANGELOG
+++ b/puppet/modules/stdlib/CHANGELOG
@@ -1,30 +1,153 @@
-2012-11-28 - Peter Meier
- 2.6.0
- * Add reject() function (a79b2cd)
+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)
-2012-09-18 - Chad Metcalf - 2.6.0
+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 - 2.6.0
+2012-11-23 - Erik Dalén - 3.2.0
* (#17797) min() and max() functions (9954133)
-2012-05-23 - Peter Meier - 2.6.0
+2012-05-23 - Peter Meier - 3.2.0
* (#14670) autorequire a file_line resource's path (dfcee63)
-2012-11-19 - Joshua Harlan Lifton - 2.6.0
+2012-11-19 - Joshua Harlan Lifton - 3.2.0
* Add join_keys_to_values function (ee0f2b3)
-2012-11-17 - Joshua Harlan Lifton - 2.6.0
+2012-11-17 - Joshua Harlan Lifton - 3.2.0
* Extend delete function for strings and hashes (7322e4d)
-2012-08-03 - Gary Larizza - 2.6.0
+2012-08-03 - Gary Larizza - 3.2.0
* Add the pick() function (ba6dd13)
-2012-03-20 - Wil Cooley - 2.6.0
+2012-03-20 - Wil Cooley - 3.2.0
* (#13974) Add predicate functions for interface facts (f819417)
-2012-11-06 - Joe Julian - 2.6.0
+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)
diff --git a/puppet/modules/stdlib/CONTRIBUTING.md b/puppet/modules/stdlib/CONTRIBUTING.md
new file mode 100755
index 0000000..bd11f63
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/Gemfile b/puppet/modules/stdlib/Gemfile
new file mode 100755
index 0000000..197cc6b
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/LICENSE b/puppet/modules/stdlib/LICENSE
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/Modulefile b/puppet/modules/stdlib/Modulefile
old mode 100644
new mode 100755
index c3568e0..9d2e8c2
--- a/puppet/modules/stdlib/Modulefile
+++ b/puppet/modules/stdlib/Modulefile
@@ -1,6 +1,6 @@
name 'puppetlabs-stdlib'
-version '2.6.0'
-source 'git://github.com/puppetlabs/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'
diff --git a/puppet/modules/stdlib/README.markdown b/puppet/modules/stdlib/README.markdown
old mode 100644
new mode 100755
index 9fa4c38..7b45b17
--- a/puppet/modules/stdlib/README.markdown
+++ b/puppet/modules/stdlib/README.markdown
@@ -1,5 +1,7 @@
# Puppet Labs Standard Library #
+[](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
@@ -14,6 +16,9 @@ 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
@@ -23,9 +28,11 @@ 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.2, 1.2.1, 1.2.3, 1.2.4)
+ * 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 (Scheduled for next PE feature release)
+ * 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
@@ -33,50 +40,1155 @@ Enterprise 1.2.
# Compatibility #
-## stdlib v2.1.x, v2.2.x ##
+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 ##
-v2.1.x and v2.2.x of this module are designed to work with Puppet versions
-2.6.x and 2.7.x. There are currently no plans for a Puppet 0.25 standard
-library module.
+All stdlib releases in the 2.0 major version support Puppet 2.6 and Puppet 2.7.
-## stdlib v2.3.x ##
+## stdlib 3.x ##
-While not yet released, the standard library may only work with Puppet 2.7.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 #
- Please see `puppet doc -r function` for documentation on each function. The
- current list of functions is:
+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'].
+
- * getvar
- * has\_key
- * loadyaml
- * merge.rb
- * validate\_array
- * validate\_bool
- * validate\_hash
- * validate\_re
- * validate\_string
+- *Type*: rvalue
-## validate\_hash ##
+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.
- $somehash = { 'one' => 'two' }
- validate\_hash($somehash)
+*Example:*
-## getvar() ##
+ zip(['1','2','3'],['4','5','6'])
-This function aims to look up variables in user-defined namespaces within
-puppet. Note, if the namespace is a class, it should already be evaluated
-before the function is used.
+Would result in:
- $namespace = 'site::data'
- include "${namespace}"
- $myvar = getvar("${namespace}::myvar")
+ ["1", "4"], ["2", "5"], ["3", "6"]
-## Facts ##
-Facts in `/etc/facter/facts.d` and `/etc/puppetlabs/facter/facts.d` are now loaded
-automatically. This is a direct copy of R.I. Pienaar's custom facter fact
-located at:
-[https://github.com/ripienaar/facter-facts/tree/master/facts-dot-d](https://github.com/ripienaar/facter-facts/tree/master/facts-dot-d)
+- *Type*: rvalue
+*This page autogenerated on 2013-04-11 13:54:25 -0700*
diff --git a/puppet/modules/stdlib/README_DEVELOPER.markdown b/puppet/modules/stdlib/README_DEVELOPER.markdown
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/README_SPECS.markdown b/puppet/modules/stdlib/README_SPECS.markdown
new file mode 100755
index 0000000..917b631
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/RELEASE_PROCESS.markdown b/puppet/modules/stdlib/RELEASE_PROCESS.markdown
old mode 100644
new mode 100755
index 3982c84..0f9328e
--- a/puppet/modules/stdlib/RELEASE_PROCESS.markdown
+++ b/puppet/modules/stdlib/RELEASE_PROCESS.markdown
@@ -22,4 +22,3 @@
* 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/modules/stdlib/Rakefile b/puppet/modules/stdlib/Rakefile
old mode 100644
new mode 100755
index 01b2a31..14f1c24
--- a/puppet/modules/stdlib/Rakefile
+++ b/puppet/modules/stdlib/Rakefile
@@ -1,16 +1,2 @@
-require 'rake'
-require 'rspec/core/rake_task'
-
-task :default => [:test]
-
-desc 'Run RSpec'
-RSpec::Core::RakeTask.new(:test) do |t|
- t.pattern = 'spec/{unit}/**/*.rb'
- t.rspec_opts = ['--color']
-end
-
-desc 'Generate code coverage'
-RSpec::Core::RakeTask.new(:coverage) do |t|
- t.rcov = true
- t.rcov_opts = ['--exclude', 'spec']
-end
+require 'rubygems'
+require 'puppetlabs_spec_helper/rake_tasks'
diff --git a/puppet/modules/stdlib/lib/facter/facter_dot_d.rb b/puppet/modules/stdlib/lib/facter/facter_dot_d.rb
old mode 100644
new mode 100755
index c43801c..e414b20
--- a/puppet/modules/stdlib/lib/facter/facter_dot_d.rb
+++ b/puppet/modules/stdlib/lib/facter/facter_dot_d.rb
@@ -13,181 +13,190 @@
# fact scripts more often than is needed
class Facter::Util::DotD
- require 'yaml'
+ 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 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 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)
+ def fact_type(file)
+ extension = File.extname(file)
- type = @types[extension] || :unknown
+ type = @types[extension] || :unknown
- type = :script if type == :unknown && File.executable?(file)
+ type = :script if type == :unknown && File.executable?(file)
- return type
- end
+ return type
+ end
- def txt_parser(file)
- File.readlines(file).each do |line|
- if line =~ /^(.+)=(.+)$/
- var = $1; val = $2
+ def txt_parser(file)
+ File.readlines(file).each do |line|
+ if line =~ /^(.+)=(.+)$/
+ var = $1; val = $2
- Facter.add(var) do
- setcode { val }
- end
- end
+ Facter.add(var) do
+ setcode { val }
end
- rescue Exception => e
- Facter.warn("Failed to handle #{file} as text facts: #{e.class}: #{e}")
+ end
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}")
+ 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
- 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}")
+ 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 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
- Puppet.deprecation_warning("TTL for external facts is being removed. See http://links.puppetlabs.com/factercaching for more information.")
- Facter.debug("Using cached data for #{file}")
- end
-
- result.split("\n").each do |line|
- if line =~ /^(.+)=(.+)$/
- var = $1; val = $2
+ def yaml_parser(file)
+ require 'yaml'
- 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"))
+ YAML.load_file(file).each_pair do |f, v|
+ Facter.add(f) do
+ setcode { v }
+ end
end
-
- def cache_save!
- cache = load_cache
- File.open(@cache_file, "w", 0600) {|f| f.write(YAML.dump(cache)) }
- rescue
+ 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
- def cache_store(file, data)
- load_cache
+ result.split("\n").each do |line|
+ if line =~ /^(.+)=(.+)$/
+ var = $1; val = $2
- @cache[file] = {:data => data, :stored => Time.now.to_i}
- rescue
+ 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_lookup(file)
- cache = load_cache
+ def cache_save!
+ cache = load_cache
+ File.open(@cache_file, "w", 0600) {|f| f.write(YAML.dump(cache)) }
+ rescue
+ end
- return nil if cache.empty?
+ def cache_store(file, data)
+ load_cache
- ttl = cache_time(file)
+ @cache[file] = {:data => data, :stored => Time.now.to_i}
+ rescue
+ end
- 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_lookup(file)
+ cache = load_cache
- def cache_time(file)
- meta = file + ".ttl"
+ return nil if cache.empty?
- return File.read(meta).chomp.to_i
- rescue
- return 0
- end
+ ttl = cache_time(file)
- def load_cache
- unless @cache
- if File.exist?(@cache_file)
- @cache = YAML.load_file(@cache_file)
- else
- @cache = {}
- end
- end
+ if cache[file]
+ now = Time.now.to_i
- return @cache
- rescue
+ 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 = {}
- return @cache
+ end
end
- def create
- entries.each do |fact|
- type = fact_type(fact)
- parser = "#{type}_parser"
+ return @cache
+ rescue
+ @cache = {}
+ return @cache
+ end
- if respond_to?("#{type}_parser")
- Facter.debug("Parsing #{fact} using #{parser}")
+ def create
+ entries.each do |fact|
+ type = fact_type(fact)
+ parser = "#{type}_parser"
- send(parser, fact)
- end
- end
+ if respond_to?("#{type}_parser")
+ Facter.debug("Parsing #{fact} using #{parser}")
+
+ send(parser, fact)
+ end
end
+ end
end
-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
+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/modules/stdlib/lib/facter/pe_version.rb b/puppet/modules/stdlib/lib/facter/pe_version.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/facter/puppet_vardir.rb b/puppet/modules/stdlib/lib/facter/puppet_vardir.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/facter/root_home.rb b/puppet/modules/stdlib/lib/facter/root_home.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/facter/util/puppet_settings.rb b/puppet/modules/stdlib/lib/facter/util/puppet_settings.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/abs.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/abs.rb
old mode 100644
new mode 100755
index ade5462..11d2d7f
--- a/puppet/modules/stdlib/lib/puppet/parser/functions/abs.rb
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/abs.rb
@@ -4,7 +4,7 @@
module Puppet::Parser::Functions
newfunction(:abs, :type => :rvalue, :doc => <<-EOS
- Returns the absolute value of a number, for example -34.56 becomes
+ 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|
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/any2array.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/any2array.rb
new file mode 100755
index 0000000..e71407e
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/lib/puppet/parser/functions/bool2num.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/bool2num.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/capitalize.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/capitalize.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/chomp.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/chomp.rb
old mode 100644
new mode 100755
index c99d139..4564a00
--- a/puppet/modules/stdlib/lib/puppet/parser/functions/chomp.rb
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/chomp.rb
@@ -4,7 +4,7 @@
module Puppet::Parser::Functions
newfunction(:chomp, :type => :rvalue, :doc => <<-'EOS'
- Removes the record separator from the end of a string or an array of
+ 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
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/chop.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/chop.rb
old mode 100644
new mode 100755
index 636b990..f242af3
--- a/puppet/modules/stdlib/lib/puppet/parser/functions/chop.rb
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/chop.rb
@@ -4,9 +4,9 @@
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
+ 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
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/concat.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/concat.rb
new file mode 100755
index 0000000..c86aa00
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/lib/puppet/parser/functions/count.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/count.rb
new file mode 100755
index 0000000..52de1b8
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/delete.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/delete.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/delete_at.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/delete_at.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/dirname.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/dirname.rb
new file mode 100755
index 0000000..ea8cc1e
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/lib/puppet/parser/functions/downcase.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/downcase.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/empty.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/empty.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/ensure_packages.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/ensure_packages.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/ensure_resource.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/ensure_resource.rb
old mode 100644
new mode 100755
index fba2035..a9a1733
--- a/puppet/modules/stdlib/lib/puppet/parser/functions/ensure_resource.rb
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/ensure_resource.rb
@@ -19,17 +19,27 @@
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 ||= {}
- Puppet::Parser::Functions.function(:defined_with_params)
- if function_defined_with_params(["#{type}[#{title}]", params])
- Puppet.debug("Resource #{type}[#{title}] not created b/c it already exists")
- else
- Puppet::Parser::Functions.function(:create_resources)
- function_create_resources([type.capitalize, { 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/modules/stdlib/lib/puppet/parser/functions/flatten.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/flatten.rb
old mode 100644
new mode 100755
index 781da78..a1ed183
--- a/puppet/modules/stdlib/lib/puppet/parser/functions/flatten.rb
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/flatten.rb
@@ -16,7 +16,7 @@ module Puppet::Parser::Functions
) do |arguments|
raise(Puppet::ParseError, "flatten(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ "given (#{arguments.size} for 1)") if arguments.size != 1
array = arguments[0]
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/floor.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/floor.rb
new file mode 100755
index 0000000..a401923
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/get_module_path.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/get_module_path.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/getparam.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/getparam.rb
new file mode 100755
index 0000000..6d51006
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/lib/puppet/parser/functions/getvar.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/getvar.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/grep.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/grep.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/has_interface_with.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/has_interface_with.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/has_ip_address.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/has_ip_address.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/has_ip_network.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/has_ip_network.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/has_key.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/has_key.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/hash.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/hash.rb
old mode 100644
new mode 100755
index 453ba1e..8cc4823
--- a/puppet/modules/stdlib/lib/puppet/parser/functions/hash.rb
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/hash.rb
@@ -4,7 +4,7 @@
module Puppet::Parser::Functions
newfunction(:hash, :type => :rvalue, :doc => <<-EOS
-This function converts and array into a hash.
+This function converts an array into a hash.
*Examples:*
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_array.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_array.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_domain_name.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_domain_name.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_float.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_float.rb
old mode 100644
new mode 100755
index 2fc05ba..911f3c2
--- a/puppet/modules/stdlib/lib/puppet/parser/functions/is_float.rb
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/is_float.rb
@@ -15,7 +15,7 @@ module Puppet::Parser::Functions
value = arguments[0]
- if value != value.to_f.to_s then
+ if value != value.to_f.to_s and !value.is_a? Float then
return false
else
return true
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_function_available.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_function_available.rb
new file mode 100755
index 0000000..6cbd35c
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/lib/puppet/parser/functions/is_hash.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_hash.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_integer.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_integer.rb
old mode 100644
new mode 100755
index 8ee34f6..6b29e98
--- a/puppet/modules/stdlib/lib/puppet/parser/functions/is_integer.rb
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/is_integer.rb
@@ -15,7 +15,7 @@ module Puppet::Parser::Functions
value = arguments[0]
- if value != value.to_i.to_s then
+ if value != value.to_i.to_s and !value.is_a? Fixnum then
return false
else
return true
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_ip_address.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_ip_address.rb
old mode 100644
new mode 100755
index b4a9a15..a90adab
--- a/puppet/modules/stdlib/lib/puppet/parser/functions/is_ip_address.rb
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/is_ip_address.rb
@@ -15,7 +15,7 @@ module Puppet::Parser::Functions
"given #{arguments.size} for 1")
end
- begin
+ begin
ip = IPAddr.new(arguments[0])
rescue ArgumentError
return false
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_mac_address.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_mac_address.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_numeric.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_numeric.rb
old mode 100644
new mode 100755
index ce13ece..abf0321
--- a/puppet/modules/stdlib/lib/puppet/parser/functions/is_numeric.rb
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/is_numeric.rb
@@ -15,7 +15,7 @@ module Puppet::Parser::Functions
value = arguments[0]
- if value == value.to_f.to_s or value == value.to_i.to_s then
+ 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
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_string.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_string.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/join.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/join.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/join_keys_to_values.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/join_keys_to_values.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/keys.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/keys.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/loadyaml.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/loadyaml.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/lstrip.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/lstrip.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/max.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/max.rb
old mode 100644
new mode 100755
index 10b6f74..60fb94a
--- a/puppet/modules/stdlib/lib/puppet/parser/functions/max.rb
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/max.rb
@@ -8,6 +8,14 @@ module Puppet::Parser::Functions
raise(Puppet::ParseError, "max(): Wrong number of arguments " +
"need at least one") if args.size == 0
- return args.max
+ # 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/modules/stdlib/lib/puppet/parser/functions/member.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/member.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/merge.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/merge.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/min.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/min.rb
old mode 100644
new mode 100755
index abf1b62..6bd6ebf
--- a/puppet/modules/stdlib/lib/puppet/parser/functions/min.rb
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/min.rb
@@ -8,6 +8,14 @@ module Puppet::Parser::Functions
raise(Puppet::ParseError, "min(): Wrong number of arguments " +
"need at least one") if args.size == 0
- return args.min
+ # 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/modules/stdlib/lib/puppet/parser/functions/num2bool.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/num2bool.rb
old mode 100644
new mode 100755
index 874db22..af0e6ed
--- a/puppet/modules/stdlib/lib/puppet/parser/functions/num2bool.rb
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/num2bool.rb
@@ -2,38 +2,41 @@
# num2bool.rb
#
-# TODO(Krzysztof Wilczynski): We probably need to approach numeric values differently ...
-
module Puppet::Parser::Functions
newfunction(:num2bool, :type => :rvalue, :doc => <<-EOS
-This function converts a number into a true boolean. Zero becomes false. Numbers
-higher then 0 become true.
+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
+ "given (#{arguments.size} for 1)") if arguments.size != 1
number = arguments[0]
- # Only numbers allowed ...
- unless number.match(/^\-?\d+$/)
- raise(Puppet::ParseError, 'num2bool(): Requires integer to work with')
+ 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
- result = case number
- when /^0$/
- false
- when /^\-?\d+$/
- # Numbers in Puppet are often string-encoded which is troublesome ...
- number = number.to_i
- # We yield true for any positive number and false otherwise ...
- number > 0 ? true : false
- else
- raise(Puppet::ParseError, 'num2bool(): Unknown numeric format given')
- end
+ # Truncate Floats
+ number = number.to_i
- return result
+ # Return true for any positive number and false otherwise
+ return number > 0
end
end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/parsejson.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/parsejson.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/parseyaml.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/parseyaml.rb
old mode 100644
new mode 100755
index e8ac8a4..53d54fa
--- a/puppet/modules/stdlib/lib/puppet/parser/functions/parseyaml.rb
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/parseyaml.rb
@@ -4,7 +4,7 @@
module Puppet::Parser::Functions
newfunction(:parseyaml, :type => :rvalue, :doc => <<-EOS
-This function accepts YAML as a string and converts it into the correct
+This function accepts YAML as a string and converts it into the correct
Puppet structure.
EOS
) do |arguments|
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/pick.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/pick.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/prefix.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/prefix.rb
old mode 100644
new mode 100755
index 4593976..62211ae
--- a/puppet/modules/stdlib/lib/puppet/parser/functions/prefix.rb
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/prefix.rb
@@ -6,7 +6,7 @@ module Puppet::Parser::Functions
newfunction(:prefix, :type => :rvalue, :doc => <<-EOS
This function applies a prefix to all elements in an array.
-*Examles:*
+*Examples:*
prefix(['a','b','c'], 'p')
@@ -21,14 +21,14 @@ module Puppet::Parser::Functions
array = arguments[0]
unless array.is_a?(Array)
- raise(Puppet::ParseError, 'prefix(): Requires array to work with')
+ 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(): Requires string to work with')
+ raise Puppet::ParseError, "prefix(): expected second argument to be a String, got #{suffix.inspect}"
end
end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/range.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/range.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/reject.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/reject.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/reverse.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/reverse.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/rstrip.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/rstrip.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/shuffle.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/shuffle.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/size.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/size.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/sort.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/sort.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/squeeze.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/squeeze.rb
old mode 100644
new mode 100755
index 65c174a..81fadfd
--- a/puppet/modules/stdlib/lib/puppet/parser/functions/squeeze.rb
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/squeeze.rb
@@ -14,9 +14,9 @@ module Puppet::Parser::Functions
end
item = arguments[0]
- squeezeval = arguments[1]
+ squeezeval = arguments[1]
- if item.is_a?(Array) then
+ if item.is_a?(Array) then
if squeezeval then
item.collect { |i| i.squeeze(squeezeval) }
else
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/str2bool.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/str2bool.rb
old mode 100644
new mode 100755
index c320da6..fece7a6
--- a/puppet/modules/stdlib/lib/puppet/parser/functions/str2bool.rb
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/str2bool.rb
@@ -4,7 +4,7 @@
module Puppet::Parser::Functions
newfunction(:str2bool, :type => :rvalue, :doc => <<-EOS
-This converts a string to a boolean. This attempt to convert strings that
+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
@@ -14,6 +14,11 @@ module Puppet::Parser::Functions
"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 ' +
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/str2saltedsha512.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/str2saltedsha512.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/strftime.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/strftime.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/strip.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/strip.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/suffix.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/suffix.rb
new file mode 100755
index 0000000..f7792d6
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/lib/puppet/parser/functions/swapcase.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/swapcase.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/time.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/time.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/to_bytes.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/to_bytes.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/type.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/type.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/unique.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/unique.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/upcase.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/upcase.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/uriescape.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/uriescape.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/validate_absolute_path.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_absolute_path.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/validate_array.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_array.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/validate_augeas.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_augeas.rb
new file mode 100755
index 0000000..154d660
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/lib/puppet/parser/functions/validate_bool.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_bool.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/validate_cmd.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_cmd.rb
new file mode 100755
index 0000000..344a80c
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/lib/puppet/parser/functions/validate_hash.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_hash.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/validate_re.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_re.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/validate_slength.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_slength.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/validate_string.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_string.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/values.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/values.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/values_at.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/values_at.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/zip.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/zip.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/lib/puppet/provider/file_line/ruby.rb b/puppet/modules/stdlib/lib/puppet/provider/file_line/ruby.rb
old mode 100644
new mode 100755
index e21eaa8..a3219d3
--- a/puppet/modules/stdlib/lib/puppet/provider/file_line/ruby.rb
+++ b/puppet/modules/stdlib/lib/puppet/provider/file_line/ruby.rb
@@ -34,7 +34,7 @@ def lines
def handle_create_with_match()
regex = resource[:match] ? Regexp.new(resource[:match]) : nil
- match_count = lines.select { |l| regex.match(l) }.count
+ 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
diff --git a/puppet/modules/stdlib/lib/puppet/type/anchor.rb b/puppet/modules/stdlib/lib/puppet/type/anchor.rb
old mode 100644
new mode 100755
index 6b81732..fe1e5aa
--- a/puppet/modules/stdlib/lib/puppet/type/anchor.rb
+++ b/puppet/modules/stdlib/lib/puppet/type/anchor.rb
@@ -38,4 +38,9 @@ class { 'mcollective': } -> class { 'ntp': }
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/modules/stdlib/lib/puppet/type/file_line.rb b/puppet/modules/stdlib/lib/puppet/type/file_line.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/manifests/init.pp b/puppet/modules/stdlib/manifests/init.pp
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/manifests/stages.pp b/puppet/modules/stdlib/manifests/stages.pp
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/classes/anchor_spec.rb b/puppet/modules/stdlib/spec/classes/anchor_spec.rb
new file mode 100755
index 0000000..2dd17de
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/spec/functions/defined_with_params_spec.rb b/puppet/modules/stdlib/spec/functions/defined_with_params_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/functions/ensure_packages_spec.rb b/puppet/modules/stdlib/spec/functions/ensure_packages_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/functions/ensure_resource_spec.rb b/puppet/modules/stdlib/spec/functions/ensure_resource_spec.rb
old mode 100644
new mode 100755
index 611666e..2e8aefc
--- a/puppet/modules/stdlib/spec/functions/ensure_resource_spec.rb
+++ b/puppet/modules/stdlib/spec/functions/ensure_resource_spec.rb
@@ -4,17 +4,16 @@
require 'rspec-puppet'
describe 'ensure_resource' do
describe 'when a type or title is not specified' do
- it do
- should run.with_params().and_raise_error(ArgumentError)
- should run.with_params(['type']).and_raise_error(ArgumentError)
- end
+ 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 do
- should run.with_params('user', 'dan', {})
+ 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
@@ -23,18 +22,43 @@
let :pre_condition do
'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}'
end
- it do
- # these first three should not fail
- should run.with_params('User', 'dan', {})
- should run.with_params('User', 'dan', '')
- should run.with_params('User', 'dan', {'ensure' => 'present'})
- should run.with_params('User', 'dan',
- {'ensure' => 'present', 'managehome' => false}
- )
- # test that this fails
- should run.with_params('User', 'dan',
- {'ensure' => 'absent', 'managehome' => false}
- ).and_raise_error(Puppet::Error)
+ # 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/modules/stdlib/spec/functions/getparam_spec.rb b/puppet/modules/stdlib/spec/functions/getparam_spec.rb
new file mode 100755
index 0000000..d9c50a6
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/spec/lib/puppet_spec/files.rb b/puppet/modules/stdlib/spec/lib/puppet_spec/files.rb
deleted file mode 100755
index 30fb4fc..0000000
--- a/puppet/modules/stdlib/spec/lib/puppet_spec/files.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-require 'fileutils'
-require 'tempfile'
-
-# A support module for testing files.
-module PuppetSpec::Files
- # This code exists only to support tests that run as root, pretty much.
- # Once they have finally been eliminated this can all go... --daniel 2011-04-08
- if Puppet.features.posix? then
- def self.in_tmp(path)
- path =~ /^\/tmp/ or path =~ /^\/var\/folders/
- end
- elsif Puppet.features.microsoft_windows?
- def self.in_tmp(path)
- tempdir = File.expand_path(File.join(Dir::LOCAL_APPDATA, "Temp"))
- path =~ /^#{tempdir}/
- end
- else
- fail "Help! Can't find in_tmp for this platform"
- end
-
- def self.cleanup
- $global_tempfiles ||= []
- while path = $global_tempfiles.pop do
- fail "Not deleting tmpfile #{path} outside regular tmpdir" unless in_tmp(path)
-
- begin
- FileUtils.rm_r path, :secure => true
- rescue Errno::ENOENT
- # nothing to do
- end
- end
- end
-
- def tmpfile(name)
- # Generate a temporary file, just for the name...
- source = Tempfile.new(name)
- path = source.path
- source.close!
-
- # ...record it for cleanup,
- $global_tempfiles ||= []
- $global_tempfiles << File.expand_path(path)
-
- # ...and bam.
- path
- end
-
- def tmpdir(name)
- path = tmpfile(name)
- FileUtils.mkdir_p(path)
- path
- end
-end
diff --git a/puppet/modules/stdlib/spec/lib/puppet_spec/fixtures.rb b/puppet/modules/stdlib/spec/lib/puppet_spec/fixtures.rb
deleted file mode 100755
index 7f6bc2a..0000000
--- a/puppet/modules/stdlib/spec/lib/puppet_spec/fixtures.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-module PuppetSpec::Fixtures
- def fixtures(*rest)
- File.join(PuppetSpec::FIXTURE_DIR, *rest)
- end
- def my_fixture_dir
- callers = caller
- while line = callers.shift do
- next unless found = line.match(%r{/spec/(.*)_spec\.rb:})
- return fixtures(found[1])
- end
- fail "sorry, I couldn't work out your path from the caller stack!"
- end
- def my_fixture(name)
- file = File.join(my_fixture_dir, name)
- unless File.readable? file then
- fail Puppet::DevError, "fixture '#{name}' for #{my_fixture_dir} is not readable"
- end
- return file
- end
- def my_fixtures(glob = '*', flags = 0)
- files = Dir.glob(File.join(my_fixture_dir, glob), flags)
- unless files.length > 0 then
- fail Puppet::DevError, "fixture '#{glob}' for #{my_fixture_dir} had no files!"
- end
- block_given? and files.each do |file| yield file end
- files
- end
-end
diff --git a/puppet/modules/stdlib/spec/lib/puppet_spec/matchers.rb b/puppet/modules/stdlib/spec/lib/puppet_spec/matchers.rb
deleted file mode 100644
index 77f5803..0000000
--- a/puppet/modules/stdlib/spec/lib/puppet_spec/matchers.rb
+++ /dev/null
@@ -1,87 +0,0 @@
-require 'stringio'
-
-########################################################################
-# Backward compatibility for Jenkins outdated environment.
-module RSpec
- module Matchers
- module BlockAliases
- alias_method :to, :should unless method_defined? :to
- alias_method :to_not, :should_not unless method_defined? :to_not
- alias_method :not_to, :should_not unless method_defined? :not_to
- end
- end
-end
-
-
-########################################################################
-# Custom matchers...
-RSpec::Matchers.define :have_matching_element do |expected|
- match do |actual|
- actual.any? { |item| item =~ expected }
- end
-end
-
-
-RSpec::Matchers.define :exit_with do |expected|
- actual = nil
- match do |block|
- begin
- block.call
- rescue SystemExit => e
- actual = e.status
- end
- actual and actual == expected
- end
- failure_message_for_should do |block|
- "expected exit with code #{expected} but " +
- (actual.nil? ? " exit was not called" : "we exited with #{actual} instead")
- end
- failure_message_for_should_not do |block|
- "expected that exit would not be called with #{expected}"
- end
- description do
- "expect exit with #{expected}"
- end
-end
-
-
-RSpec::Matchers.define :have_printed do |expected|
- match do |block|
- $stderr = $stdout = StringIO.new
-
- begin
- block.call
- ensure
- $stdout.rewind
- @actual = $stdout.read
-
- $stdout = STDOUT
- $stderr = STDERR
- end
-
- if @actual then
- case expected
- when String
- @actual.include? expected
- when Regexp
- expected.match @actual
- else
- raise ArgumentError, "No idea how to match a #{@actual.class.name}"
- end
- end
- end
-
- failure_message_for_should do |actual|
- if actual.nil? then
- "expected #{expected.inspect}, but nothing was printed"
- else
- "expected #{expected.inspect} to be printed; got:\n#{actual}"
- end
- end
-
- description do
- "expect #{expected.inspect} to be printed"
- end
-
- diffable
-end
diff --git a/puppet/modules/stdlib/spec/lib/puppet_spec/verbose.rb b/puppet/modules/stdlib/spec/lib/puppet_spec/verbose.rb
deleted file mode 100755
index d9834f2..0000000
--- a/puppet/modules/stdlib/spec/lib/puppet_spec/verbose.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-# Support code for running stuff with warnings disabled.
-module Kernel
- def with_verbose_disabled
- verbose, $VERBOSE = $VERBOSE, nil
- result = yield
- $VERBOSE = verbose
- return result
- end
-end
diff --git a/puppet/modules/stdlib/spec/monkey_patches/publicize_methods.rb b/puppet/modules/stdlib/spec/monkey_patches/publicize_methods.rb
index b39e9c0..f3a1abf 100755
--- a/puppet/modules/stdlib/spec/monkey_patches/publicize_methods.rb
+++ b/puppet/modules/stdlib/spec/monkey_patches/publicize_methods.rb
@@ -8,4 +8,3 @@ def publicize_methods(*methods)
self.class_eval { private(*saved_private_instance_methods) }
end
end
-
diff --git a/puppet/modules/stdlib/spec/spec.opts b/puppet/modules/stdlib/spec/spec.opts
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/spec_helper.rb b/puppet/modules/stdlib/spec/spec_helper.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/facter/pe_required_facts_spec.rb b/puppet/modules/stdlib/spec/unit/facter/pe_required_facts_spec.rb
new file mode 100755
index 0000000..f219b37
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/spec/unit/facter/pe_version_spec.rb b/puppet/modules/stdlib/spec/unit/facter/pe_version_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/facter/root_home_spec.rb b/puppet/modules/stdlib/spec/unit/facter/root_home_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/facter/util/puppet_settings_spec.rb b/puppet/modules/stdlib/spec/unit/facter/util/puppet_settings_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/any2array_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/any2array_spec.rb
new file mode 100755
index 0000000..b266e84
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/spec/unit/puppet/parser/functions/concat_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/concat_spec.rb
new file mode 100755
index 0000000..123188b
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/spec/unit/puppet/parser/functions/count_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/count_spec.rb
new file mode 100755
index 0000000..2453815
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/spec/unit/puppet/parser/functions/dirname_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/dirname_spec.rb
new file mode 100755
index 0000000..fb3b4fe
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/spec/unit/puppet/parser/functions/flatten_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/flatten_spec.rb
index d4dfd20..dba7a6b 100755
--- a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/flatten_spec.rb
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/flatten_spec.rb
@@ -11,6 +11,10 @@
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"]))
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/floor_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/floor_spec.rb
new file mode 100755
index 0000000..dbc8c77
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb
old mode 100644
new mode 100755
index 4eb799d..2577723
--- a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb
@@ -19,7 +19,7 @@
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.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice
scope.function_fqdn_rotate(["abcdefg"]).should eql(scope.function_fqdn_rotate(["abcdefg"]))
end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/get_module_path_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/get_module_path_spec.rb
old mode 100644
new mode 100755
index e761706..486bef6
--- a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/get_module_path_spec.rb
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/get_module_path_spec.rb
@@ -15,11 +15,11 @@ def scope(environment = "production")
end
it 'should only allow one argument' do
- expect { scope.function_get_module_path([]) }.should raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/)
- expect { scope.function_get_module_path(['1','2','3']) }.should raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/)
+ 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']) }.should raise_error(Puppet::ParseError, /Could not find module/)
+ 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" }
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/getvar_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/getvar_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/has_key_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/has_key_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/hash_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/hash_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_array_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_array_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_domain_name_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_domain_name_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_float_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_float_spec.rb
old mode 100644
new mode 100755
index 2f527d9..b7d73b0
--- a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_float_spec.rb
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_float_spec.rb
@@ -26,4 +26,8 @@
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/modules/stdlib/spec/unit/puppet/parser/functions/is_function_available.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_function_available.rb
new file mode 100755
index 0000000..bd40c51
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/spec/unit/puppet/parser/functions/is_hash_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_hash_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_integer_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_integer_spec.rb
old mode 100644
new mode 100755
index 5afbba4..4335795
--- a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_integer_spec.rb
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_integer_spec.rb
@@ -26,4 +26,9 @@
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/modules/stdlib/spec/unit/puppet/parser/functions/is_ip_address_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_ip_address_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_mac_address_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_mac_address_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_numeric_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_numeric_spec.rb
old mode 100644
new mode 100755
index 4078b37..d7440fb
--- a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_numeric_spec.rb
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_numeric_spec.rb
@@ -22,6 +22,16 @@
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))
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_string_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_string_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/join_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/join_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/keys_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/keys_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/lstrip_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/lstrip_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/max_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/max_spec.rb
index 604927e..ff6f2b3 100755
--- a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/max_spec.rb
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/max_spec.rb
@@ -20,4 +20,8 @@
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/modules/stdlib/spec/unit/puppet/parser/functions/member_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/member_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/merge_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/merge_spec.rb
old mode 100644
new mode 100755
index db7d837..04169e7
--- a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/merge_spec.rb
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/merge_spec.rb
@@ -25,7 +25,7 @@
describe 'when calling merge on the scope instance' do
it 'should require all parameters are hashes' do
- expect { new_hash = scope.function_merge([{}, '2'])}.should raise_error(Puppet::ParseError, /unexpected argument type String/)
+ 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
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/min_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/min_spec.rb
index 781422c..71d593e 100755
--- a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/min_spec.rb
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/min_spec.rb
@@ -20,4 +20,8 @@
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/modules/stdlib/spec/unit/puppet/parser/functions/num2bool_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/num2bool_spec.rb
old mode 100644
new mode 100755
index 640c689..b56196d
--- a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/num2bool_spec.rb
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/num2bool_spec.rb
@@ -8,17 +8,60 @@
Puppet::Parser::Functions.function("num2bool").should == "function_num2bool"
end
- it "should raise a ParseError if there is less than 1 arguments" do
+ it "should raise a ParseError if there are no arguments" do
lambda { scope.function_num2bool([]) }.should( raise_error(Puppet::ParseError))
end
- it "should return true if 1" do
+ 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 false if 0" do
+ 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/modules/stdlib/spec/unit/puppet/parser/functions/parsejson_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/parsejson_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/parseyaml_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/parseyaml_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/pick_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/pick_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/prefix_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/prefix_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/range_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/range_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/reverse_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/reverse_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/rstrip_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/rstrip_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/shuffle_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/shuffle_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/size_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/size_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/sort_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/sort_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/squeeze_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/squeeze_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/str2bool_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/str2bool_spec.rb
old mode 100644
new mode 100755
index 2782bbe..ef6350f
--- a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/str2bool_spec.rb
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/str2bool_spec.rb
@@ -21,4 +21,11 @@
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/modules/stdlib/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb
old mode 100644
new mode 100755
index a692c31..df8fb8e
--- a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb
@@ -9,11 +9,11 @@
end
it "should raise a ParseError if there is less than 1 argument" do
- expect { scope.function_str2saltedsha512([]) }.should( raise_error(Puppet::ParseError) )
+ 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']) }.should( raise_error(Puppet::ParseError) )
+ 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
@@ -22,7 +22,7 @@
end
it "should raise an error if you pass a non-string password" do
- expect { scope.function_str2saltedsha512([1234]) }.should( raise_error(Puppet::ParseError) )
+ expect { scope.function_str2saltedsha512([1234]) }.to( raise_error(Puppet::ParseError) )
end
it "should generate a valid password" do
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/strftime_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/strftime_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/strip_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/strip_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/suffix_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/suffix_spec.rb
new file mode 100755
index 0000000..c28f719
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/spec/unit/puppet/parser/functions/swapcase_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/swapcase_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/time_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/time_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/type_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/type_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/unique_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/unique_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/upcase_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/upcase_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/uriescape_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/uriescape_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_array_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_array_spec.rb
old mode 100644
new mode 100755
index 8eee72a..4b31cfd
--- a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_array_spec.rb
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_array_spec.rb
@@ -9,12 +9,12 @@
%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 }.should raise_error(Puppet::ParseError, /is not an Array/)
+ 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 }.should raise_error(Puppet::ParseError, /is not an Array/)
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/)
end
end
@@ -32,7 +32,7 @@
$foo = undef
validate_array($foo)
ENDofPUPPETcode
- expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not an Array/)
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/)
end
end
end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_augeas_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_augeas_spec.rb
new file mode 100755
index 0000000..ab5c140
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/spec/unit/puppet/parser/functions/validate_bool_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_bool_spec.rb
old mode 100644
new mode 100755
index 31ab8fb..261fb23
--- a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_bool_spec.rb
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_bool_spec.rb
@@ -10,7 +10,7 @@
it "should not compile when #{the_string} is a string" do
Puppet[:code] = "validate_bool('#{the_string}')"
- expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a boolean/)
+ 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
@@ -22,12 +22,12 @@
it "should not compile when an arbitrary string is passed" do
Puppet[:code] = 'validate_bool("jeff and dan are awesome")'
- expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a boolean/)
+ 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 }.should raise_error(Puppet::ParseError, /wrong number of arguments/)
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
end
it "should compile when multiple boolean arguments are passed" do
@@ -45,7 +45,7 @@
$bar = false
validate_bool($foo, $bar, true, false, 'jeff')
ENDofPUPPETcode
- expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a boolean/)
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/)
end
end
end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_cmd_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_cmd_spec.rb
new file mode 100755
index 0000000..69ea7f4
--- /dev/null
+++ b/puppet/modules/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/modules/stdlib/spec/unit/puppet/parser/functions/validate_hash_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_hash_spec.rb
old mode 100644
new mode 100755
index f63db1d..a0c35c2
--- a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_hash_spec.rb
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_hash_spec.rb
@@ -11,12 +11,12 @@
it "should not compile when #{the_string} is a string" do
Puppet[:code] = "validate_hash('#{the_string}')"
- expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a Hash/)
+ 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 }.should raise_error(Puppet::ParseError, /is not a Hash/)
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/)
end
end
@@ -35,10 +35,9 @@
$foo = undef
validate_hash($foo)
ENDofPUPPETcode
- expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a Hash/)
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/)
end
end
end
-
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_re_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_re_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_string_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_string_spec.rb
old mode 100644
new mode 100755
index f40bf2a..3b4fb3e
--- a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_string_spec.rb
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_string_spec.rb
@@ -29,7 +29,7 @@
it "should not compile when #{the_string} is a bare word" do
Puppet[:code] = "validate_string(#{the_string})"
- expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a string/)
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a string/)
end
end
@@ -58,4 +58,3 @@
end
end
end
-
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/values_at_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/values_at_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/values_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/values_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/zip_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/zip_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/provider/file_line/ruby_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/provider/file_line/ruby_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/type/anchor_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/type/anchor_spec.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/spec/unit/puppet/type/file_line_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/type/file_line_spec.rb
old mode 100644
new mode 100755
index 0cd8a26..edc64bd
--- a/puppet/modules/stdlib/spec/unit/puppet/type/file_line_spec.rb
+++ b/puppet/modules/stdlib/spec/unit/puppet/type/file_line_spec.rb
@@ -37,13 +37,13 @@
file_line[:path].should == '/tmp/path'
end
it 'should not accept unqualified path' do
- expect { file_line[:path] = 'file' }.should raise_error(Puppet::Error, /File paths must be fully qualified/)
+ 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') }.should raise_error(Puppet::Error, /Both line and path are required attributes/)
+ 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') }.should raise_error(Puppet::Error, /Both line and path are required attributes/)
+ 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
diff --git a/puppet/modules/stdlib/spec/watchr.rb b/puppet/modules/stdlib/spec/watchr.rb
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/tests/file_line.pp b/puppet/modules/stdlib/tests/file_line.pp
old mode 100644
new mode 100755
diff --git a/puppet/modules/stdlib/tests/has_interface_with.pp b/puppet/modules/stdlib/tests/has_interface_with.pp
old mode 100644
new mode 100755
index 8b9e51e..e1f1353
--- a/puppet/modules/stdlib/tests/has_interface_with.pp
+++ b/puppet/modules/stdlib/tests/has_interface_with.pp
@@ -1,10 +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'))
+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/modules/stdlib/tests/has_ip_address.pp b/puppet/modules/stdlib/tests/has_ip_address.pp
old mode 100644
new mode 100755
index e770a11..8429a88
--- a/puppet/modules/stdlib/tests/has_ip_address.pp
+++ b/puppet/modules/stdlib/tests/has_ip_address.pp
@@ -1,3 +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'))
+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/modules/stdlib/tests/has_ip_network.pp b/puppet/modules/stdlib/tests/has_ip_network.pp
old mode 100644
new mode 100755
index 036d649..a15d8c0
--- a/puppet/modules/stdlib/tests/has_ip_network.pp
+++ b/puppet/modules/stdlib/tests/has_ip_network.pp
@@ -1,4 +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'))
+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/modules/stdlib/tests/init.pp b/puppet/modules/stdlib/tests/init.pp
old mode 100644
new mode 100755
diff --git a/puppet/modules/triggers/files/triggers/backup.sh b/puppet/modules/triggers/files/triggers/backup.sh
new file mode 100644
index 0000000..ca22f73
--- /dev/null
+++ b/puppet/modules/triggers/files/triggers/backup.sh
@@ -0,0 +1,58 @@
+#!/bin/bash
+
+ARCHIVE="${1:-/vagrant/joomla-box-backup.tar}"
+
+if [ ! -e "$ARCHIVE" ] ; then
+ touch "$ARCHIVE"
+fi
+
+if [ ! -w "$ARCHIVE" ] ; then
+ echo "Cannot write to $ARCHIVE!"
+ exit 1
+fi
+
+TMP_ARCHIVE="/tmp/joomla-box-backup.tar"
+TEMP_DIR="/tmp/backup"
+
+MYSQL_USER="root"
+MYSQL_PASSWORD="root"
+
+tar -cvf $TMP_ARCHIVE --files-from /dev/null
+
+mkdir -p "$TEMP_DIR/"
+cd $TEMP_DIR
+
+echo "Backing up your virtual hosts:"
+
+for VHOST in /etc/apache2/sites-available/1-*.conf; do
+ if [ ! -e "$VHOST" ]
+ then
+ echo "No virtual hosts found. Nothing to do."
+ break
+ fi
+
+ FILENAME=$( basename "$VHOST" )
+ SITENAME=${FILENAME%.*}
+ SITENAME=${SITENAME:2}
+
+ echo " * $SITENAME"
+
+ gzip < $VHOST > "$TEMP_DIR/vhost-$FILENAME.gz"
+ tar --append --file=$TMP_ARCHIVE "vhost-$FILENAME.gz"
+ rm -f "vhost-$FILENAME.gz"
+done
+
+echo "Backing up your MySQL databases:"
+
+DATABASES=`mysql --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema|mysql)"`
+
+for DB in $DATABASES; do
+ echo " * $DB"
+
+ mysqldump --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $DB | gzip > "$TEMP_DIR/mysql-$DB.sql.gz"
+ tar --append --file=$TMP_ARCHIVE "mysql-$DB.sql.gz"
+ rm -f mysql-$DB.sql.gz
+done
+
+mv $TMP_ARCHIVE $ARCHIVE
+echo "Backup created in $ARCHIVE"
\ No newline at end of file
diff --git a/puppet/modules/triggers/files/triggers/restore.sh b/puppet/modules/triggers/files/triggers/restore.sh
new file mode 100644
index 0000000..3159769
--- /dev/null
+++ b/puppet/modules/triggers/files/triggers/restore.sh
@@ -0,0 +1,74 @@
+#!/bin/bash
+
+ARCHIVE="${1:-/vagrant/joomla-box-backup.tar}"
+TEMP_DIR="/tmp/restore"
+
+if [ ! -f $ARCHIVE ]; then
+ echo "Backup archive $ARCHIVE not found, aborting." 1>&2
+ exit 1
+fi
+
+if [ -d $TEMP_DIR ]; then
+ rm -f $TEMP_DIR/*.gz
+ rm -f $TEMP_DIR/*.conf
+ rm -f $TEMP_DIR/*.sql
+else
+ mkdir -p $TEMP_DIR
+fi
+
+tar -xf $ARCHIVE -C $TEMP_DIR
+
+echo "Restoring virtual hosts:"
+for VHOST in $TEMP_DIR/vhost-1-*.conf.gz; do
+ if [ ! -e "$VHOST" ]
+ then
+ echo "No virtual hosts found. Nothing to do."
+ break
+ fi
+
+ FILENAME=$(basename "$VHOST")
+ SITENAME="${FILENAME/vhost-1-/}"
+ SITENAME="${SITENAME/.conf.gz/}"
+
+ echo " * $SITENAME"
+
+ gunzip $VHOST
+ VHOST="${VHOST/.gz/}"
+
+ # Make sure VirtualHosts are listening on port 8080 instead of 80
+ # (we changed the port since adding Varnish support)
+ if grep -Fxq "" $VHOST
+ then
+ sed -i'.bak' 's///g' $VHOST
+ fi
+
+ sudo mv $VHOST "/etc/apache2/sites-available/1-${SITENAME}.conf" || { echo "Failed to install $SITENAME! Aborting." 1>&2; exit 1; }
+ sudo a2ensite "1-$SITENAME" &> /dev/null || { echo "Failed to enable $SITENAME! Aborting." 1>&2; exit 1; }
+done
+
+sudo service apache2 restart
+
+echo "Restoring databases:"
+
+for DB in $TEMP_DIR/mysql-*.sql.gz; do
+ if [ ! -e "$DB" ]
+ then
+ echo "No database dumps found. Nothing to do."
+ break
+ fi
+
+ FILENAME=$(basename $DB)
+ DBNAME=${FILENAME%.*}
+ DBNAME="${DBNAME/.sql.gz/}"
+
+ echo " * $DBNAME"
+
+ gunzip $DB
+ DB="${DB/.gz/}"
+
+ mysql -uroot -proot < $DB || { echo "Failed to import database $DBNAME! Aborting." 1>&2; exit 1; }
+done
+
+rm -rf $TEMP_DIR
+
+echo "Succesfully restored your hosts and databases. You can safely delete the joomla-box-backup.tar file after validating your setup."
\ No newline at end of file
diff --git a/puppet/modules/triggers/manifests/init.pp b/puppet/modules/triggers/manifests/init.pp
new file mode 100644
index 0000000..2d52551
--- /dev/null
+++ b/puppet/modules/triggers/manifests/init.pp
@@ -0,0 +1,15 @@
+class triggers {
+
+ file { '/home/vagrant/triggers':
+ source => 'puppet:///modules/triggers/triggers',
+ recurse => true,
+ owner => vagrant,
+ group => vagrant,
+ }
+
+ exec { 'make-triggers-executable':
+ command => 'chmod +x /home/vagrant/triggers/*',
+ subscribe => File['/home/vagrant/triggers']
+ }
+
+}
\ No newline at end of file
diff --git a/puppet/modules/varnish/files/joomla.box.vcl b/puppet/modules/varnish/files/joomla.box.vcl
new file mode 100644
index 0000000..e5c288e
--- /dev/null
+++ b/puppet/modules/varnish/files/joomla.box.vcl
@@ -0,0 +1,140 @@
+vcl 4.0;
+
+# This Varnish configuration is a very basic template to get started with caching Joomla sites.
+# In no way is this configuration complete: every site is unique and needs customisation!
+# For demonstration purposes this VCL will cache all front-end pages (including pages with cookies).
+
+import std;
+
+backend default {
+ .host = "127.0.0.1";
+ .port = "8080";
+ .probe = {
+ .url = "/varnish-enabled";
+ .interval = 1s;
+ .timeout = 1s;
+ }
+}
+
+backend alternative {
+ .host = "127.0.0.1";
+ .port = "8080";
+}
+
+sub vcl_recv {
+ # Forward client's IP to backend
+ unset req.http.X-Forwarded-For;
+ set req.http.X-Forwarded-For = client.ip;
+
+ set req.http.X-Forwarded-By = server.ip;
+ set req.http.X-Forwarded-Port = 80;
+
+ # Check if we've still enabled Varnish, if not, passthrough every request
+ if (! std.healthy(req.backend_hint))
+ {
+ set req.backend_hint = alternative;
+ return (pass);
+ }
+
+ # Do not cache phpmyadmin
+ if (req.http.host == "phpmyadmin.joomla.box") {
+ return (pass);
+ }
+
+ # Do not cache system tools on joomla.box:
+ if (req.http.host == "joomla.box")
+ {
+ if (req.url ~ "^/apc" || req.url ~ "^/phpinfo" || req.url ~ "^/pimpmylog" || req.url ~ "^/dashboard") {
+ return (pass);
+ }
+ }
+
+ # Do not cache POST requests
+ if (req.method == "POST") {
+ return (pass);
+ }
+
+ # Proxy (pass) any request that goes to the backend admin, the banner component links, ..
+ if(req.url ~ "/administrator" || req.url ~ "/component/banners" || req.url ~ "/component/users" || req.url ~ "/installation") {
+ return (pass);
+ }
+
+ # Do not cache if user is logged in
+ if (req.http.Authorization || req.http.Authenticate) {
+ return (pass);
+ }
+
+ # Don't cache ajax requests
+ if(req.http.X-Requested-With == "XMLHttpRequest" || req.url ~ "nocache") {
+ return (pass);
+ }
+
+ # Properly handle different encoding types
+ if (req.http.Accept-Encoding) {
+ if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf)$") {
+ # No point in compressing these
+ unset req.http.Accept-Encoding;
+ } elsif (req.http.Accept-Encoding ~ "gzip") {
+ set req.http.Accept-Encoding = "gzip";
+ } elsif (req.http.Accept-Encoding ~ "deflate") {
+ set req.http.Accept-Encoding = "deflate";
+ } else {
+ # unknown algorithm (aka crappy browser)
+ unset req.http.Accept-Encoding;
+ }
+ }
+
+ return (hash);
+}
+
+sub vcl_backend_response {
+ # Unset the "etag" header (suggested)
+ unset beresp.http.etag;
+
+ # This is Joomla! specific: fix stupid "no-cache" header sent by Joomla! even
+ # when caching is on - make sure to replace 300 with the number of seconds that
+ # you want the browser to cache content
+ if(beresp.http.Cache-Control ~ "no-cache" || beresp.http.Cache-Control == ""){
+ set beresp.http.Cache-Control = "max-age=300, public, must-revalidate";
+ }
+
+ # Check for the custom "x-Logged-In" header to identify if the visitor is a guest,
+ # then unset any cookie (including session cookies) provided it's not a POST request.
+ if(bereq.method != "POST" && beresp.http.X-Logged-In == "false") {
+ unset beresp.http.Set-Cookie;
+ }
+
+ # This is how long Varnish will cache content
+ set beresp.ttl = 1w;
+
+ return (deliver);
+}
+
+sub vcl_hash
+{
+ hash_data(req.url);
+
+ if (req.http.host) {
+ hash_data(req.http.host);
+ } else {
+ hash_data(server.ip);
+ }
+
+ # Hash cookies for requests that have them
+ if (req.http.Cookie) {
+ hash_data(req.http.Cookie);
+ }
+}
+
+sub vcl_deliver {
+ if (resp.http.x-varnish ~ " ") {
+ set resp.http.X-Varnish-Status = "HIT";
+ } else {
+ set resp.http.X-Varnish-Status = "MISS";
+ }
+
+ # Please note that obj.hits behaviour changed in 4.0, now it counts per objecthead, not per object
+ # and obj.hits may not be reset in some cases where bans are in use. See bug 1492 for details.
+ # So take hits with a grain of salt
+ set resp.http.X-Varnish-Hits = obj.hits;
+}
\ No newline at end of file
diff --git a/puppet/modules/varnish/files/varnish.conf b/puppet/modules/varnish/files/varnish.conf
new file mode 100644
index 0000000..2fd9881
--- /dev/null
+++ b/puppet/modules/varnish/files/varnish.conf
@@ -0,0 +1,10 @@
+START=yes
+NFILES=131072
+MEMLOCK=82000
+
+DAEMON_OPTS="-a :80 \
+ -T localhost:6082 \
+ -f /etc/varnish/default.vcl \
+ -S /etc/varnish/secret \
+ -t 120 \
+ -s malloc,128m"
\ No newline at end of file
diff --git a/puppet/modules/varnish/manifests/init.pp b/puppet/modules/varnish/manifests/init.pp
new file mode 100644
index 0000000..555c367
--- /dev/null
+++ b/puppet/modules/varnish/manifests/init.pp
@@ -0,0 +1,47 @@
+class varnish {
+
+ apt::source { 'varnish':
+ location => "http://repo.varnish-cache.org/ubuntu",
+ repos => "varnish-4.0",
+ key => 'C4DEFFEB',
+ key_source => 'http://repo.varnish-cache.org/debian/GPG-key.txt',
+ }
+
+ package { 'varnish':
+ ensure => 'latest',
+ require => Apt::Source['varnish']
+ }
+
+ service {'varnish':
+ ensure => running,
+ restart => 'service varnish restart',
+ require => Package['varnish']
+ }
+
+ file { '/etc/default/varnish':
+ ensure => present,
+ owner => 'root',
+ group => 'root',
+ mode => '0644',
+ source => "puppet:///modules/varnish/varnish.conf",
+ require => Package['varnish'],
+ notify => Service['varnish']
+ }
+
+ file { '/etc/varnish/default.vcl':
+ ensure => present,
+ owner => vagrant,
+ group => vagrant,
+ mode => '0774',
+ source => "puppet:///modules/varnish/joomla.box.vcl",
+ require => Package['varnish'],
+ notify => Service['varnish']
+ }
+
+ file_line { 'apache-listen-port-80':
+ path => '/etc/apache2/ports.conf',
+ line => 'Listen 8080',
+ match => '^Listen (80){1,2}$',
+ require => Class['apache']
+ }
+}
\ No newline at end of file
diff --git a/puppet/modules/webgrind/files/config.php b/puppet/modules/webgrind/files/config.php
new file mode 100644
index 0000000..d4cbd05
--- /dev/null
+++ b/puppet/modules/webgrind/files/config.php
@@ -0,0 +1,120 @@
+ "puppet:///modules/webgrind/webgrind-release-1.0.zip",
+ package { 'graphviz':
+ ensure => installed
}
- exec { 'php-extract-webgrind':
- cwd => '/usr/share',
- command => "unzip /tmp/webgrind.zip",
- creates => '/usr/share/webgrind',
+ archive { 'webgrind-1.2':
+ ensure => present,
+ url => 'https://github.com/alpha0010/webgrind/archive/1.2.tar.gz',
+ target => '/usr/share',
+ follow_redirects => true,
+ checksum => false
}
+ ->
+ file { '/usr/share/webgrind-1.2/config.php':
+ ensure => file,
+ source => 'puppet:///modules/webgrind/config.php'
+ }
+
}
\ No newline at end of file
diff --git a/puppet/modules/xdebug/manifests/init.pp b/puppet/modules/xdebug/manifests/init.pp
index f4a5eb6..7b27473 100644
--- a/puppet/modules/xdebug/manifests/init.pp
+++ b/puppet/modules/xdebug/manifests/init.pp
@@ -9,4 +9,11 @@
notify => Service[$service],
}
+ file { '/etc/php5/mods-available/xdebug.ini':
+ ensure => file,
+ content => '; zend_extension=xdebug.so',
+ require => Package['xdebug'],
+ notify => Service[$service]
+ }
+
}
diff --git a/puppet/modules/zray/manifests/apache/vhost.pp b/puppet/modules/zray/manifests/apache/vhost.pp
new file mode 100644
index 0000000..ca5e133
--- /dev/null
+++ b/puppet/modules/zray/manifests/apache/vhost.pp
@@ -0,0 +1,20 @@
+define zray::apache::vhost (
+ $ensure = present,
+ $path = '/opt/zray',
+ $enable = false
+) {
+
+ file { "/etc/apache2/sites-available/00-${title}.conf":
+ ensure => $ensure,
+ content => template('zray/apache.vhost.erb')
+ }
+
+ if ($enable) {
+ file { "/etc/apache2/sites-enabled/00-${title}.conf":
+ ensure => link,
+ target => "/etc/apache2/sites-available/00-${title}.conf"
+ }
+ }
+
+
+}
\ No newline at end of file
diff --git a/puppet/modules/zray/manifests/init.pp b/puppet/modules/zray/manifests/init.pp
new file mode 100644
index 0000000..815396a
--- /dev/null
+++ b/puppet/modules/zray/manifests/init.pp
@@ -0,0 +1,47 @@
+class zray {
+
+ archive { 'zray-php-101832-php5.6.11-linux-debian7-amd64':
+ ensure => present,
+ url => 'http://repos.zend.com/zend-server/early-access/zray-tech-preview/zray-php-101832-php5.6.11-linux-debian7-amd64.tar.gz',
+ target => '/opt',
+ checksum => false
+ }
+ ->
+ exec {'zray-chown-www-data':
+ command => '/usr/bin/find /opt/zray-php-101832-php5.6.11-linux-debian7-amd64 ! -user www-data -exec /bin/chown www-data:www-data {} \;'
+ }
+ ->
+ zray::apache::vhost { 'zray-php5.6':
+ ensure => present,
+ path => '/opt/zray-php-101832-php5.6.11-linux-debian7-amd64/zray',
+ enable => true
+ }
+ ->
+ zray::php::ini { 'zray-php5.6':
+ ensure => present,
+ path => '/opt/zray-php-101832-php5.6.11-linux-debian7-amd64/zray',
+ enable => true
+ }
+
+ archive { 'zray-php-101832-php5.5.27-linux-debian7-amd64':
+ ensure => present,
+ url => 'http://repos.zend.com/zend-server/early-access/zray-tech-preview/zray-php-101832-php5.5.27-linux-debian7-amd64.tar.gz',
+ target => '/opt',
+ checksum => false
+ }
+ ->
+ exec {'zray-php5.5-chown-www-data':
+ command => '/usr/bin/find /opt/zray-php-101832-php5.5.27-linux-debian7-amd64 ! -user www-data -exec /bin/chown www-data:www-data {} \;'
+ }
+ ->
+ zray::apache::vhost { 'zray-php5.5':
+ ensure => present,
+ path => '/opt/zray-php-101832-php5.5.27-linux-debian7-amd64/zray'
+ }
+ ->
+ zray::php::ini { 'zray-php5.5':
+ ensure => present,
+ path => '/opt/zray-php-101832-php5.5.27-linux-debian7-amd64/zray'
+ }
+
+}
\ No newline at end of file
diff --git a/puppet/modules/zray/manifests/php/ini.pp b/puppet/modules/zray/manifests/php/ini.pp
new file mode 100644
index 0000000..714bbb5
--- /dev/null
+++ b/puppet/modules/zray/manifests/php/ini.pp
@@ -0,0 +1,24 @@
+define zray::php::ini (
+ $ensure = present,
+ $path = '/opt/zray',
+ $enable = false
+) {
+
+ file { "/etc/php5/mods-available/${title}.ini":
+ ensure => $ensure,
+ content => template('zray/php.ini.erb')
+ }
+
+ if ($enable) {
+ file { "/etc/php5/apache2/conf.d/20-${title}.ini":
+ ensure => link,
+ target => "/etc/php5/mods-available/${title}.ini"
+ }
+ }
+ else {
+ file { ["/etc/php5/apache2/conf.d/20-${title}.ini"]:
+ ensure => absent
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/puppet/modules/zray/templates/apache.vhost.erb b/puppet/modules/zray/templates/apache.vhost.erb
new file mode 100644
index 0000000..5bce454
--- /dev/null
+++ b/puppet/modules/zray/templates/apache.vhost.erb
@@ -0,0 +1,10 @@
+Alias /ZendServer <%= @path %>/gui/public
+
+RewriteEngine On
+RewriteRule ^/$ /ZendServer/ [R]
+RewriteRule ^/Login$ /ZendServer/Login [R]
+
+/gui/public>
+ Require all granted
+ AllowOverride All
+
\ No newline at end of file
diff --git a/puppet/modules/zray/templates/php.ini.erb b/puppet/modules/zray/templates/php.ini.erb
new file mode 100644
index 0000000..237fd20
--- /dev/null
+++ b/puppet/modules/zray/templates/php.ini.erb
@@ -0,0 +1,2 @@
+zend_extension=<%= @path %>/lib/zray.so
+zray.install_dir=<%= @path %>
\ No newline at end of file