summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml2
-rw-r--r--CONTRIBUTING.md22
-rw-r--r--README.markdown11
-rw-r--r--lib/puppet/parser/functions/basename.rb34
-rw-r--r--lib/puppet/parser/functions/concat.rb18
-rw-r--r--metadata.json2
-rwxr-xr-xspec/acceptance/concat_spec.rb22
-rwxr-xr-xspec/functions/concat_spec.rb17
-rwxr-xr-xspec/unit/puppet/parser/functions/basename_spec.rb46
9 files changed, 146 insertions, 28 deletions
diff --git a/.travis.yml b/.travis.yml
index 3ed1153..f531306 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,6 @@
---
language: ruby
-bundler_args: --without development
+bundler_args: --without system_tests
script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--color --format documentation'"
matrix:
fast_finish: true
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index e128847..f1cbde4 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -41,11 +41,9 @@ Checklist (and a short version for the impatient)
* Pre-requisites:
- - Sign the [Contributor License Agreement](https://cla.puppetlabs.com/)
-
- Make sure you have a [GitHub account](https://github.com/join)
- - [Create a ticket](http://projects.puppetlabs.com/projects/modules/issues/new), or [watch the ticket](http://projects.puppetlabs.com/projects/modules/issues) you are patching for.
+ - [Create a ticket](https://tickets.puppetlabs.com/secure/CreateIssue!default.jspa), or [watch the ticket](https://tickets.puppetlabs.com/browse/) you are patching for.
* Preferred method:
@@ -94,17 +92,7 @@ The long version
whitespace or other "whitespace errors". You can do this by
running "git diff --check" on your changes before you commit.
- 2. Sign the Contributor License Agreement
-
- Before we can accept your changes, we do need a signed Puppet
- Labs Contributor License Agreement (CLA).
-
- You can access the CLA via the [Contributor License Agreement link](https://cla.puppetlabs.com/)
-
- If you have any questions about the CLA, please feel free to
- contact Puppet Labs via email at cla-submissions@puppetlabs.com.
-
- 3. Sending your patches
+ 2. Sending your patches
To submit your changes via a GitHub pull request, we _highly_
recommend that you have them on a topic branch, instead of
@@ -124,7 +112,7 @@ The long version
in order to open a pull request.
- 4. Update the related GitHub issue.
+ 3. Update the related GitHub issue.
If there is a GitHub issue associated with the change you
submitted, then you should update the ticket to include the
@@ -220,14 +208,12 @@ review.
Additional Resources
====================
-* [Getting additional help](http://projects.puppetlabs.com/projects/puppet/wiki/Getting_Help)
+* [Getting additional help](http://puppetlabs.com/community/get-help)
* [Writing tests](http://projects.puppetlabs.com/projects/puppet/wiki/Development_Writing_Tests)
* [Patchwork](https://patchwork.puppetlabs.com)
-* [Contributor License Agreement](https://projects.puppetlabs.com/contributor_licenses/sign)
-
* [General GitHub documentation](http://help.github.com/)
* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
diff --git a/README.markdown b/README.markdown
index 957be9b..7e0d0d5 100644
--- a/README.markdown
+++ b/README.markdown
@@ -27,6 +27,8 @@ modules. Puppet modules make heavy use of this standard library. The stdlib modu
* Defined resource types
* Types
* Providers
+
+> *Note:* As of version 3.7, Puppet Enterprise no longer includes the stdlib module. If you're running Puppet Enterprise, you should install the most recent release of stdlib for compatibility with Puppet modules.
##Setup
@@ -84,6 +86,13 @@ If you want to use a standardized set of run stages for Puppet, `include stdlib`
Requires an action ('encode', 'decode') and either a plain or base64-encoded
string. *Type*: rvalue
+* `basename`: Returns the `basename` of a path (optionally stripping an extension). For example:
+ * ('/path/to/a/file.ext') returns 'file.ext'
+ * ('relative/path/file.ext') returns 'file.ext'
+ * ('/path/to/a/file.ext', '.ext') returns 'file'
+
+ *Type*: rvalue
+
* `bool2num`: Converts a boolean to a number. Converts values:
* 'false', 'f', '0', 'n', and 'no' to 0.
* 'true', 't', '1', 'y', and 'yes' to 1.
@@ -683,6 +692,8 @@ of the regular expressions match the string passed in, compilation aborts with a
##Limitations
+As of Puppet Enterprise version 3.7, the stdlib module is no longer included in PE. PE users should install the most recent release of stdlib for compatibility with Puppet modules.
+
###Version Compatibility
Versions | Puppet 2.6 | Puppet 2.7 | Puppet 3.x | Puppet 4.x |
diff --git a/lib/puppet/parser/functions/basename.rb b/lib/puppet/parser/functions/basename.rb
new file mode 100644
index 0000000..f7e4438
--- /dev/null
+++ b/lib/puppet/parser/functions/basename.rb
@@ -0,0 +1,34 @@
+module Puppet::Parser::Functions
+ newfunction(:basename, :type => :rvalue, :doc => <<-EOS
+ Strips directory (and optional suffix) from a filename
+ EOS
+ ) do |arguments|
+
+ if arguments.size < 1 then
+ raise(Puppet::ParseError, "basename(): No arguments given")
+ elsif arguments.size > 2 then
+ raise(Puppet::ParseError, "basename(): Too many arguments given (#{arguments.size})")
+ else
+
+ unless arguments[0].is_a?(String)
+ raise(Puppet::ParseError, 'basename(): Requires string as first argument')
+ end
+
+ if arguments.size == 1 then
+ rv = File.basename(arguments[0])
+ elsif arguments.size == 2 then
+
+ unless arguments[1].is_a?(String)
+ raise(Puppet::ParseError, 'basename(): Requires string as second argument')
+ end
+
+ rv = File.basename(arguments[0], arguments[1])
+ end
+
+ end
+
+ return rv
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/lib/puppet/parser/functions/concat.rb b/lib/puppet/parser/functions/concat.rb
index 0d35b07..618e62d 100644
--- a/lib/puppet/parser/functions/concat.rb
+++ b/lib/puppet/parser/functions/concat.rb
@@ -4,31 +4,35 @@
module Puppet::Parser::Functions
newfunction(:concat, :type => :rvalue, :doc => <<-EOS
-Appends the contents of array 2 onto array 1.
+Appends the contents of multiple arrays into array 1.
*Example:*
- concat(['1','2','3'],['4','5','6'])
+ concat(['1','2','3'],['4','5','6'],['7','8','9'])
Would result in:
- ['1','2','3','4','5','6']
+ ['1','2','3','4','5','6','7','8','9']
EOS
) do |arguments|
- # Check that 2 arguments have been given ...
+ # Check that more than 2 arguments have been given ...
raise(Puppet::ParseError, "concat(): Wrong number of arguments " +
- "given (#{arguments.size} for 2)") if arguments.size != 2
+ "given (#{arguments.size} for < 2)") if arguments.size < 2
a = arguments[0]
- b = arguments[1]
# Check that the first parameter is an array
unless a.is_a?(Array)
raise(Puppet::ParseError, 'concat(): Requires array to work with')
end
- result = a + Array(b)
+ result = a
+ arguments.shift
+
+ arguments.each do |x|
+ result = result + Array(x)
+ end
return result
end
diff --git a/metadata.json b/metadata.json
index f049cfb..6bdf82d 100644
--- a/metadata.json
+++ b/metadata.json
@@ -2,7 +2,7 @@
"name": "puppetlabs-stdlib",
"version": "4.4.0",
"author": "puppetlabs",
- "summary": "Puppet Module Standard Library",
+ "summary": "Standard library of resources for Puppet modules.",
"license": "Apache 2.0",
"source": "git://github.com/puppetlabs/puppetlabs-stdlib",
"project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
diff --git a/spec/acceptance/concat_spec.rb b/spec/acceptance/concat_spec.rb
index 7bda365..caf2f7d 100755
--- a/spec/acceptance/concat_spec.rb
+++ b/spec/acceptance/concat_spec.rb
@@ -14,5 +14,27 @@ describe 'concat function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('oper
apply_manifest(pp, :catch_failures => true)
end
+ it 'should concat arrays and primitives to array' do
+ pp = <<-EOS
+ $output = concat(['1','2','3'],'4','5','6',['7','8','9'])
+ validate_array($output)
+ if size($output) != 9 {
+ fail("${output} should have 9 elements.")
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
+ it 'should concat multiple arrays to one' do
+ pp = <<-EOS
+ $output = concat(['1','2','3'],['4','5','6'],['7','8','9'])
+ validate_array($output)
+ if size($output) != 6 {
+ fail("${output} should have 9 elements.")
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
end
end
diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb
index 49cb2ad..49fa6bb 100755
--- a/spec/functions/concat_spec.rb
+++ b/spec/functions/concat_spec.rb
@@ -4,14 +4,19 @@ require 'spec_helper'
describe "the concat function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
- it "should raise a ParseError if the client does not provide two arguments" do
+ it "should raise a ParseError if the client does not provide at least two arguments" do
expect { scope.function_concat([]) }.to(raise_error(Puppet::ParseError))
+ expect { scope.function_concat([[1]]) }.to(raise_error(Puppet::ParseError))
end
it "should raise a ParseError if the first parameter is not an array" do
expect { scope.function_concat([1, []])}.to(raise_error(Puppet::ParseError))
end
+ it "should not raise a ParseError if the client provides more than two arguments" do
+ expect { scope.function_concat([[1],[2],[3]]) }.not_to raise_error
+ end
+
it "should be able to concat an array" do
result = scope.function_concat([['1','2','3'],['4','5','6']])
expect(result).to(eq(['1','2','3','4','5','6']))
@@ -32,4 +37,14 @@ describe "the concat function" do
result = scope.function_concat([array_original,['4','5','6']])
array_original.should(eq(['1','2','3']))
end
+
+ it "should be able to concat multiple arrays" do
+ result = scope.function_concat([['1','2','3'],['4','5','6'],['7','8','9']])
+ expect(result).to(eq(['1','2','3','4','5','6','7','8','9']))
+ end
+
+ it "should be able to concat mix of primitives and arrays to a final array" do
+ result = scope.function_concat([['1','2','3'],'4',['5','6','7']])
+ expect(result).to(eq(['1','2','3','4','5','6','7']))
+ end
end
diff --git a/spec/unit/puppet/parser/functions/basename_spec.rb b/spec/unit/puppet/parser/functions/basename_spec.rb
new file mode 100755
index 0000000..8a2d0dc
--- /dev/null
+++ b/spec/unit/puppet/parser/functions/basename_spec.rb
@@ -0,0 +1,46 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the basename function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("basename").should == "function_basename"
+ end
+
+ it "should raise a ParseError if there is less than 1 argument" do
+ lambda { scope.function_basename([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if there are more than 2 arguments" do
+ lambda { scope.function_basename(['a', 'b', 'c']) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return basename for an absolute path" do
+ result = scope.function_basename(['/path/to/a/file.ext'])
+ result.should(eq('file.ext'))
+ end
+
+ it "should return basename for a relative path" do
+ result = scope.function_basename(['path/to/a/file.ext'])
+ result.should(eq('file.ext'))
+ end
+
+ it "should strip extention when extension specified (absolute path)" do
+ result = scope.function_basename(['/path/to/a/file.ext', '.ext'])
+ result.should(eq('file'))
+ end
+
+ it "should strip extention when extension specified (relative path)" do
+ result = scope.function_basename(['path/to/a/file.ext', '.ext'])
+ result.should(eq('file'))
+ end
+
+ it "should complain about non-string first argument" do
+ lambda { scope.function_basename([[]]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should complain about non-string second argument" do
+ lambda { scope.function_basename(['/path/to/a/file.ext', []]) }.should( raise_error(Puppet::ParseError))
+ end
+end