Commit graph

291 commits

Author SHA1 Message Date
Alexander Pánek
448e66b8bb Updated docs of validate_string to reflect bug
See: https://tickets.puppetlabs.com/browse/MODULES-457
2014-09-16 17:55:26 +02:00
Hunter Haugen
2ba0e375e2 Merge branch '4.3.x' 2014-08-05 10:55:58 -07:00
Colleen Murphy
85d5eadbab Concatenate arrays without modifying the first array 2014-07-31 11:22:18 -07:00
Thomas Linkin
9fd13be825 (MODULES-1221) Add file_line autorequire documentation
This commit adds additional documentation to the file_line resource
explaining how it will autorequire file resources when present.
2014-07-16 11:45:36 -04:00
Travis Fields
64f0ae2269 Increase resilience if lookup var comes back with nil object 2014-06-23 22:47:03 -07:00
Raphaël Pinson
2062f9734b Add private() function 2014-06-11 16:35:32 +02:00
Ashley Penney
0cda858744 Merge pull request #258 from mckern/enhancement/master/camelcasedembools
(MODULES-905) Narrow the confinement in bool2str
2014-05-15 21:48:40 -04:00
Ryan McKern
93c4151edf (MODULES-905) Narrow the confinement in bool2str
Previously, bool2str() accepted a broad array of boolean values and
bare strings, without any attempt to validate that the strings in any
way resembled "true" or "false" (or any of the other values bool2num()
accepts). This commit narrows the input confinement to TrueClass and
FalseClass, which means that bool2str() will only interpolate
strict boolean values now.
2014-05-15 15:01:14 -07:00
Ashley Penney
c5b06f9bbc Revert "Merge pull request #256 from stbenjam/2571-before"
This reverts commit 8499ebdb7f, reversing
changes made to 08b00d9229.
2014-05-15 17:28:59 -04:00
Ashley Penney
430d821ad3 Merge pull request #255 from mckern/enhancement/master/camelcasedembools
(MODULES-905) Add bool2str() and camelcase() for string manipulation
2014-05-15 17:03:18 -04:00
Stephen Benjamin
6eaa592cd8 (PUP-2571) add 'before' functionality to file_line
file_line supports adding lines after a match, but there are use cases when
having "before" would be useful. For example, in Debian-based OS's, the last
line of /etc/rc.local is "exit 0" it's an incredible pain to deal with
that scenario today.

This commit adds a 'before' parameter to the file_line type, and implements
it for the ruby provider.
2014-05-14 20:33:57 +02:00
Ryan McKern
42743614cb (MODULES-905) Add bool2str() and camelcase() for string manipulation
Python likes to have its constants Capitalized, and the capitalize
function only understands strings... so I shave a yak.

bool2str will convert a boolean to its equivalent string value,
and camelcase extends on uppercase & downcase to convert an underscore
delimited string into a camelcased string.
2014-05-13 15:46:40 -07:00
Hunter Haugen
0804121719 Fix the stdlib functions that fail tests 2014-05-08 14:55:23 -07:00
Ashley Penney
0b59dfe642 Merge pull request #222 from mfoo/fix/master/concat-primitives
Allow concat to take non-array second parameters
2014-04-24 13:41:42 -04:00
Ashley Penney
f42fc4bfd8 Merge pull request #238 from Spredzy/add_default_ensure_packages
(MODULES-603) Add defaults arguments to ensure_packages()
2014-04-24 13:38:07 -04:00
Ashley Penney
68acb59bf7 Adjust the regular expression for facts.
Previously this was incorrectly handling facts that were of the form
foo=1+1=2 due to the ='s in the actual fact contents.  Fix this and
add tests to try and prevent regressions.
2014-04-22 23:15:16 +02:00
Yanis Guenane
d9b5e912bb (MODULES-603) Add defaults arguments to ensure_packages()
Without this patch one can not specify package resource specific
parameters. All the ensure_packages() function does it makes sure
the named packages are installed. This patch allows one to pass
default as a second argument and allow greater flexibility on
packages installations.

Use case like the following are now possible :
  * ensure_packages(['r10k', 'serverspec'], {'provider' => 'gem'})
  * ensure_packages(['ntp'], {'require' => 'Exec[foobar]'})
2014-03-30 18:47:36 -04:00
Martin Foot
35bf5fd8c9 Allow concat to take non-array second parameters
Also improve and extend concat tests to lock down functionality
2014-02-21 15:48:27 +00:00
Justin Burnham
c12e9afc97 PUP-1724 Don't modify the paramaters to deep_merge
Instead of modifying the first paramater of deep_merge due to the
use of the merge! function, instead use merge to return a copy of
the merged object. This allows one to continue to use the original
first parameter after the call to deep_merge.
2014-02-17 12:19:40 -08:00
Sharif Nassar
a972e0645b Remove trailing whitespace 2014-02-05 15:01:45 -08:00
David Schmitt
52fcef573f (PUP-638) Add a pick_default() function that always returns a value.
This version of pick() does not error out, instead always returning at least
the last argument, even if that too has no "real" value.
2014-01-29 09:26:35 -08:00
Andrew Parker
a2e9d005c7 Merge pull request #215 from blkperl/add_root_home_to_mavericks
(PUP-1459) Add support for root_home on OS X 10.9
2014-01-28 10:52:58 -08:00
Henrik Lindberg
2c8450d830 (PUP-1195) Rephrase documentation for is_integer and is_numeric
The documentation contained references to future decisions about
functionality. 
Text rephrased for clarity.
2014-01-24 00:22:09 +01:00
Simon Effenberg
264dc9bbde (PUP-1195) Fix is_numeric/is_integer when checking non-string parameters
I expect a function called "is_numeric" or "is_integer" to check if a
variable is an integer or a number even if the variable passed by isn't
a string nor a number at all. Otherwise we should call them
is_string_a_number and is_string_an_integer and we have then to remove
the check for .is_a?(Number) and .is_a?(FixNum)

now checking also if it is a hex or octal number

improved/corrected checking for integer

* checking against Integer instead of Fixnum so that
  also Bignum is matching
* now .is_a? Integer is done first so this is quiet fast

Now many types of numerics are recognized.

1. Float/Integer values (signed or unsigned, with exponent or without)
2. octal and hex check
3. except hex numbers and the "0." in a float lower than 1 can be prefixed
   with a '0'.

whitespaces shouldn't be allowed as prefix/suffix

string representation of numbers should not contain any type of
whitespace.. the user is responsible to clean a string before checking
it..

fix documentation and added more checks

tried to be 99.9% backward compatible

* for now the decission is post poned if hex and octal numbers
  should be allowed or not (is_numeric)
* native Bignum is now also a valid integer class

fix problem with old 1.8 ruby and Hash.to_s/Array.to_s

In ruby < 1.9 array and hashes would be recognized as numeric
if they have a special format:

1.8:

  [1,2,3,4].to_s = "1234"
  {1=>2}.to_s    = "12"

1.9:

  [1,2,3,4].to_s = "[1, 2, 3, 4]"
  {1=>2}.to_s    = "{1=>2}"
2014-01-23 23:59:28 +01:00
William Van Hevelingen
fe676f0ac4 (PUP-1459) Add support for root_home on OS X 10.9
getent does not exist on 10.9 so this commit uses
dscacheutil to query the homedir for the root user.
2014-01-22 22:54:34 -08:00
Adrien Thebo
686a05aea2 (maint) refactor ensure_packages for clarity 2014-01-15 11:03:49 -08:00
Tomas Doran
735db82bef Allow a single argument, rather than an array 2014-01-15 11:03:33 -08:00
Franco Catena
7991dd2073 Fix prefix exception message (Closes #23364) 2013-12-20 14:50:57 -08:00
Joshua Hoblitt
1077881873 (#23381) add is_bool() function 2013-12-09 11:50:03 -07:00
Justin Burnham
199ca9c78b (#20200) Add a recursive merge function.
Issue #20200 notes that the merge function does not
support nested hashes.

To prevent unintended side effects with changing merge,
add a deep_merge function instead.
2013-10-29 12:22:49 -07:00
Matthew Haughton
57a5c0b3e3 (Main) fix typo in pick error message
Update pick error message "at least one non empty value"
2013-10-29 12:01:25 -07:00
Tehmasp Chaudhri
753801537f Fixed 'separator' typos 2013-10-25 15:26:21 -06:00
Adrien Thebo
d60d872c1a Merge branch 'pull-180'
This closes GH-180
2013-09-18 21:56:16 -07:00
sgzijl
9e0d8a8e0a (#22214): close content file before executing checkscript
Right now validation seems to be done against zero byte generated temp
files. We need to close the file before executing validation against it.
2013-09-18 21:32:07 -07:00
Adrien Thebo
7ccf8cf09b Merge pull request #184 from lmello/fix_bug_20681_delete_undef_values
delete_undef_values function fix bug #20681
2013-09-18 10:08:49 -07:00
Leonardo Rodrigues de Mello
80a8b7bd1f (#20681) fix behaviour of delete_undef_values
The issue #20681 describe the error of delete() function
removing the elements from the origin array/hash/string.

This issue affected other delete functions. Because
ruby delete and delete_if functions make destructive
changes to the origin array/hash.

The delete_undef_values removed elements from the
origin array/hash and this is not the desired behaviour.

To solve this, we should dup or clone the array/hash
before using the delete or delete_if ruby functions.

We should also check if args[0] is not nil before using
dup, since dup on nil raises exception.

This fix the problem and add unit tests, so we could
enforce this behaviour and prevent regressions.
2013-09-18 11:19:52 -03:00
Adrien Thebo
1011670bad Merge pull request #182 from lmello/fix_bug_20681_delete_values
delete_values() fix bug #20681.
2013-09-17 11:35:57 -07:00
Adrien Thebo
5cc5e293cf Merge pull request #178 from lmello/fix_bug_20681
bug # 20681 delete() function should not remove elements from original list
2013-09-17 11:07:21 -07:00
Leonardo Rodrigues de Mello
51d96088c1 (#20681) fix behaviour of delete_values
The issue #20681 describe the error of delete() function
removing the elements from the origin array/hash/string.

This issue affected other delete functions. Because
ruby delete and delete_if functions make destructive
changes to the origin array/hash.

The delete_undef_values removed elements from the
origin hash and this is not the desired behaviour.

To solve this, we should dup or clone the hash
before using the delete or delete_if ruby functions.

This fix the problem and add unit tests, so we could
enforce this behaviour and prevent regressions.
2013-09-17 12:05:23 -03:00
Adrien Thebo
ebec9de534 Merge pull request #179 from lmello/function_pick_error_msg
enhanced the error message of pick function.
2013-09-16 13:45:24 -07:00
Leonardo Rodrigues de Mello
c14cbf31e2 bug # 20681 delete() function should not remove elements from original list
The setup: list with 3 elements, delete one:
$test_list = [‘a’, ‘b’, ‘c’]
$test_deleted = delete($test_list, ‘a’)

Print out the elements in ‘test_deleted’:
notify { ‘group_output2’:  withpath => true, name     => “$cfeng::test_deleted”, }
Notice: /Stage[main]/Syslog/Notify[group_output2]/message: bc

Good!  Run-on output shows that ‘a’ was deleted

Print out the elements in ‘test_list’:
notify { ‘group_output1’: withpath => true, name     => “$cfeng::test_list”, }
Notice: /Stage[main]/Syslog/Notify[group_output1]/message: bc

WHAT!?  'a' was deleted from ‘test_list’ as well! Expected abc as output!

This behaviour is confirmed for string, hash and array.
This is fixed on this commit, I had  added two spec tests to cover that cases.

bug #20681 spec test for delete() function.

I had forgot in the last commit the spec test for hash in the
delete function.

bug # 20681 delete() function change aproach.

Instead of rejecting elements from the original list, we use
collection = arguments[0].dup .
then latter we could continue to use delete and gsub! on collection
without impact on original argument.

this is a better solution than the previous one, and works on ruby
1.8.7, 1.9.3 and 2.0.0.

The previous solution does not work on ruby 1.8.7.

delete function remove typo whitespace.

fix typo whitespaces.
2013-09-16 10:19:35 -03:00
Leonardo Rodrigues de Mello
30e994fb6e enhanced the error message of pick function.
When pick function fail return a better error message like
the other stdlib functions, indicating that the error
is on function pick.

This would help people that see the error to identity it is
related to a incorrect use of stdlib function pick, instead of having
to grep all puppet libraries and manifests source for the old message.

I had also changed the spec test.

pick function change spec  as suggested GH-179

Fix the spec test to use expect {}.to instead of lambda {}.should
as explained by Adrienthebo.

"Using expect { }.to is preferred over lambda { }.should.
 In addition it's best practice to do a string match against the
error message to ensure that we're catching the right error,
instead of any error of the right type."

Also fixed a typo on the error message, it was missing one space.

pick function stylish fix as suggested on GH179
2013-09-16 10:03:20 -03:00
Jeff McCune
948be0bb99 (maint) Improve the tests and readability of file_line
Without this patch the implementation of the file_line provider is a bit
convoluted with respect to the newly introduced "after" parameter.

This patch addresses the problem by separating out the concerns of each
case into their own methods of handling the behavior with the match
parameter, handling the behavior with the after parameter, or simply
appending the line.
2013-08-29 16:27:27 -07:00
Dan Prince
221277e852 Update file_line resource to support 'after'.
When adding new lines to a file the 'after' option can be useful
when you need to insert file lines into the middle of a file.

This is particularly helpful when using file_line with sectioned
config files.

NOTE: the after option only works when adding new lines. If you are
updating an existing (matched) line it will simply modify it in place.
This assumes it was in the right place to begin with.
2013-08-29 15:07:29 -07:00
Adrien Thebo
2a78cbfaad Merge pull request #170 from ptomulik/fix_delete_values
minor corrections to delete_values()
2013-08-13 10:27:42 -07:00
Adrien Thebo
24911db44c (maint) Validate input argument in a single location 2013-08-12 12:56:00 -07:00
Adrien Thebo
1950b605fb (maint) reindent case statement to match standard indentation 2013-08-12 12:55:46 -07:00
Adrien Thebo
b41883933c (maint) collapse String/Array validation into shared lambda 2013-08-12 12:55:46 -07:00
Adrien Thebo
6df05cbc2d (maint) clean up validate_slength argument validation 2013-08-12 12:55:46 -07:00
Adrien Thebo
e63715ddaf (maint) reword error messages for validate_slength 2013-08-12 11:20:46 -07:00