Commit graph

434 commits

Author SHA1 Message Date
Justin Lambert
5d5a4d466e str2bool should return a boolean if called with a boolean 2013-03-18 15:37:36 -07:00
Adrien Thebo
967f9916d1 Merge branch 'pull-98' into 2.x 2013-03-18 15:05:23 -07:00
Uwe Stuehler
e80207bede Fix number of arguments check in flatten()
The function only uses the first argument, so raise an error with
too few arguments *and* with too many arguments.
2013-03-18 15:04:50 -07:00
Jeff McCune
1e2ee5bd01 Merge branch 'mhellmic-2.x' into 2.x
* mhellmic-2.x:
  changed .count to .size to support legacy ruby
2013-02-18 12:21:49 -08:00
Martin Hellmich
9fa70ae43f changed .count to .size to support legacy ruby 2013-02-18 12:21:34 -08:00
Jeff McCune
2b7591896d Update Modulefile, CHANGELOG for 2.6.0 2012-11-28 14:38:27 -08:00
Jeff McCune
26819f9688 Merge branch 'duritong-fun/2.x/reject' into 2.x
* duritong-fun/2.x/reject:
  Add reject() function
2012-11-28 14:29:01 -08:00
Peter Meier
a79b2cdf43 Add reject() function
Like the grep function, but we can now reject members of an array
based on a pattern.
2012-11-28 14:28:31 -08:00
Jeff McCune
59cc85deb5 Revert "(Maint) Add spec/functions to rake test task"
This reverts commit dbe3c8ecf6.

Because testing these against Puppet 2.6.x is causing failures.  These
need to be cleaned up, but I want to leave and this was the behavior
before I tried to "fix" it.
2012-11-27 17:06:29 -08:00
Jeff McCune
965245eb97 Merge branch 'metcalfc/2.x/ensure_packages' into 2.x
* metcalfc/2.x/ensure_packages:
  (Maint) Add spec/functions to rake test task
  Add example behaviors for ensure_packages() function
  Add an ensure_packages function.
2012-11-27 16:19:52 -08:00
Jeff McCune
dbe3c8ecf6 (Maint) Add spec/functions to rake test task
Without this patch the `test` rake task does not exercise the
rspec-puppet behaviors located in spec/functions/  This is a
self-evident problem.

This patch fixes the problem by adding spec/functions to the list of
directories scanned for spec tests.
2012-11-27 16:18:07 -08:00
Jeff McCune
616b4521f4 Add example behaviors for ensure_packages() function
Without this patch the ensure_packages() function has no rspec behavior
examples.  This patch fixes the problem by filling out a spec file with
expected behaviors I could think of.
2012-11-27 16:16:28 -08:00
Chad Metcalf
8a8c09ed34 Add an ensure_packages function.
Its often the case that modules need to install a handful of packages.
In some cases its worth breaking these dependencies out into their own
modules (e.g., Java). In others it makes more sense to keep them in the
module. This can be problematic when multiple modules depend on common
packages (git, python ruby, etc). ensure_resource was a good first step
towards solving this problem. ensure_resource does not handle arrays and
for 3 or more packages stamping out ensure_resource declarations is
tedious.

ensure_packages is a convenience function that takes an array of packages
and wraps calls to ensure_resource. Currently users cannot specify
package versions. But the function could be extended to use a hash if
that functionality would be useful.
2012-11-27 16:16:28 -08:00
Jeff McCune
6f76d8dfd1 Merge branch 'fun/2.x/min_max' into 2.x
* fun/2.x/min_max:
  (#17797) min() and max() functions
2012-11-26 16:33:56 -08:00
Erik Dalén
9954133844 (#17797) min() and max() functions
returns the min or max of all arguments given to them
2012-11-26 16:33:44 -08:00
Jeff McCune
b55994b2be Merge branch 'fun/2.x/14670_file_line_autorequire' into 2.x
* fun/2.x/14670_file_line_autorequire:
  (#14670) Fixup file_line autorequire specs
  (#14670) autorequire a file_line resource's path
2012-11-26 11:39:26 -08:00
Jeff McCune
d8cde95295 (#14670) Fixup file_line autorequire specs
Without this patch applied the file_line autorequire examples are
failing.  This is a problem because the failures are false positives and
should be passing given the implementation.

This patch fixes the problem by changing the examples to directly test
the existence of the relationship by finding it in the list of
autorequire relationships.
2012-11-26 11:37:08 -08:00
Peter Meier
dfcee63afb (#14670) autorequire a file_line resource's path
If we manage a file we edit with file_line, it should be autorequired by
file_line.  Without this patch applied the relationship is not
automatically setup and the user is forced to manually manage the
relationship.
2012-11-26 10:35:18 -08:00
Jeff McCune
6c104e5e3a Merge branch 'lifton-feature/2.x/join_keys_to_values_function' into 2.x
* lifton-feature/2.x/join_keys_to_values_function:
  Add join_keys_to_values function
2012-11-20 16:16:37 -05:00
Joshua Harlan Lifton
ee0f2b307d Add join_keys_to_values function
This commit adds a function that joins each of a hash's keys with that
key's corresponding value, separated by a separator string. The
arguments are a hash and separator string. The return value is an
array of joined key/value pairs.
2012-11-20 16:16:03 -05:00
Jeff McCune
6c36b494a0 Merge branch 'lifton-feature/2.x/extend_delete_function' into 2.x
* lifton-feature/2.x/extend_delete_function:
  Extend delete function for strings and hashes
  Fixed typo
2012-11-19 08:45:18 -05:00
Joshua Harlan Lifton
7322e4dc2f Extend delete function for strings and hashes
Previous to this commit, the delete function only acted on
arrays. This commit adds the same functionality for hashes and strings
in the obvious way: delete(h, k) would delete the k key from the h
hash and delete(s, sub) would delete all instances of the sub
substring from the s string.
2012-11-19 08:44:44 -05:00
Joshua Harlan Lifton
0798059361 Fixed typo 2012-11-19 08:44:44 -05:00
Jeff McCune
43dd606982 Merge branch 'feature/2.x/pick' into 2.x
* feature/2.x/pick:
  Add the pick() function
2012-11-15 08:56:52 -05:00
Gary Larizza
ba6dd13990 Add the pick() function
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.
2012-11-15 08:52:19 -05:00
Jeff McCune
f8635584a8 Merge branch 'add/2.x/13974-has_interface_with' into 2.x
* add/2.x/13974-has_interface_with:
  (#13974) Add predicate functions for interface facts
2012-11-07 14:03:08 -08:00
Wil Cooley
f8194176dc (#13974) Add predicate functions for interface facts
If one wishes to test if a host has a particular IP address (such as a floating
virtual address) or has an interface on a particular network (such as a
secondary management network), the facts that provide this information are
difficult to use within Puppet.

This patch addresses these needs by implementing functions
‘has_ip_address(value)’ and ‘has_ip_network(value)’. These functions look
through all interfaces for ipaddress_<interface> and network_<interface>
(respectively) having the requested <value>.

These functions are implemented on top of a lower-level predicate
function, ‘has_interface_with(kind, value)’, which iterates through the
interfaces in the ‘interfaces’ fact and checks the facts <kind>_<interface>
looking for <value>.

Additionally, the existence of a particular named interface can be checked for
by calling with only a single argument: has_interface_with(interface).

A Boolean is returned in all cases.
2012-11-07 14:00:44 -08:00
Jeff McCune
bf66ded063 Merge branch 'add/2.x/joejulian-add_uriescape' into 2.x
* add/2.x/joejulian-add_uriescape:
  Add function, uriescape, to URI.escape strings. Redmine #17459
2012-11-07 09:40:37 -08:00
Joe Julian
70f4a0e9ed Add function, uriescape, to URI.escape strings. Redmine #17459 2012-11-07 09:36:54 -08:00
Jeff McCune
cc670fb3b1 Merge branch '2.5.x' into 2.x
* 2.5.x:
  Update Modulefile, CHANGELOG for 2.5.1
2012-10-25 15:53:40 -07:00
Jeff McCune
1bb4c7a79e Update Modulefile, CHANGELOG for 2.5.1 2012-10-25 15:51:23 -07:00
Jeff McCune
f7baf36750 Merge branch '2.5.x' into 2.x
* 2.5.x:
  (maint) Fix spec failures resulting from Facter API changes
2012-10-25 15:39:27 -07:00
Jeff McCune
3f310ec874 Merge branch 'fix/2.5.x/facter_loader' into 2.5.x
* fix/2.5.x/facter_loader:
  (maint) Fix spec failures resulting from Facter API changes
2012-10-25 15:38:50 -07:00
Jeff McCune
97f836f41b (maint) Fix spec failures resulting from Facter API changes
Without this patch stdlib tests fail against Facter 2.x and master but
not 1.6.x.

This patch fixes the problem by initializing the example group
differently depending on the version of Facter integrating into the
system.  The adjusted methods are:

 1.x - Facter.collection.loader.load
 2.x - Facter.collection.load

The collection actually implements the load method in both version, it's
simply marked as private in 1.x.
2012-10-25 15:36:54 -07:00
Jeff McCune
88af331b0e Update Modulefile, CHANGELOG for 2.5.0 2012-10-25 11:03:27 -07:00
Jeff McCune
12a146058e Merge branch 'maint/2.5.x/pick_compatible_new_functionality' into 2.5.x
* maint/2.5.x/pick_compatible_new_functionality:
  Explicitly load functions used by ensure_resource
  re-formatting
  Add better docs about duplicate resource failures
  Handle undef for parameter argument
  Add function ensure_resource and defined_with_params
2012-10-25 10:58:27 -07:00
Jeff McCune
c2573298a5 Merge branch 'maint/2.5.x/pick_explicitly_load_functions' into maint/2.5.x/pick_compatible_new_functionality
* maint/2.5.x/pick_explicitly_load_functions:
  Explicitly load functions used by ensure_resource
2012-10-25 10:57:45 -07:00
Dan Bode
9fc3063ea9 Explicitly load functions used by ensure_resource
The ensure_resource function actually calls two
other functions, create_resources and defined_with_param.

When calling Puppet functions from Ruby, you sometimes have
to load the functions manually if they have not been called
before.

This commit explicitly loads the functions that ensure_resource
depends on from within the function.
2012-10-25 10:57:40 -07:00
Jeff McCune
699d520e72 Merge branch 'maint/2.5.x/pick_pr86_ensure_resource' into maint/2.5.x/pick_compatible_new_functionality
* maint/2.5.x/pick_pr86_ensure_resource:
  re-formatting
  Add better docs about duplicate resource failures
  Handle undef for parameter argument
  Add function ensure_resource and defined_with_params
2012-10-25 10:54:39 -07:00
Dan Bode
444393bf6b re-formatting
This commit refactors to ensure 80 character lines.
2012-10-25 10:54:33 -07:00
Dan Bode
97d327ae44 Add better docs about duplicate resource failures
This commit adds better inline documentation
explaining how replicate resource definitions can
occur if the resource exists and does not have
matching parameters.
2012-10-25 10:54:33 -07:00
Dan Bode
4f8b133917 Handle undef for parameter argument
This commit adds better handling of the case where
undef is passed as the parameter value.

This works by converting '' into []
2012-10-25 10:54:33 -07:00
Dan Bode
a0cb8cdee4 Add function ensure_resource and defined_with_params
This commit adds 2 new functions with unit tests.

defined_with_params works similarily to puppet's defined
function, except it allows you to also specify a hash of
params. defined_with_params will return true if a resource
also exists that matches the specified type/title (just like
with defined) as well as all of the specified params.

ensure_resource is a function that basically combines defined_with_params
with create_resources to conditionally create resources only if the
specified resource (title, type, params) does not already exist.

These functions are created to serve as an alternative to using
defined as follows:

    if ! defined(Package['some_package']) {
      package { 'some_package': ensure => present,
    }

The issue with this usage is that there is no guarentee about
what parameters were set in the previous definition of the package
that made its way into the catalog.

ensure_resource could be used instead, as:

    ensure_resource('package', 'some_package', { 'ensure' => 'present' })

This will creat the package resources only if another resource does
not exist with the specified parameters.
2012-10-25 10:54:33 -07:00
Jeff McCune
9693c04c9d Revert "Revert "Merge branch 'haus-add_pe_facts_to_stdlib' into 2.4.x""
This reverts commit d6d23b495c.

This backwards-compatible additional functionality is targeted at the
next minor release.  There are already backwards-incompatible changes in
the master branch so we need to establish a new minor branch.
2012-10-25 10:46:57 -07:00
Jeff McCune
d6d23b495c Revert "Merge branch 'haus-add_pe_facts_to_stdlib' into 2.4.x"
This reverts commit 74e6411157, reversing
changes made to 417d219aa6.

Here's why:

Actually... I just screwed this up.

I merged this new fact into 2.4.x but it's not fixing any bug. It's adding a
new fact, so this should go into master and we should release 2.5 since this is
new, backwards-compatible functionality.
2012-10-25 10:41:52 -07:00
Jeff McCune
74e6411157 Merge branch 'haus-add_pe_facts_to_stdlib' into 2.4.x
* haus-add_pe_facts_to_stdlib:
  Prevent undefined method `split' for nil:NilClass with pe_foo_version facts
  (maint) Clear all facts before each example
  Add spec tests for pe_version facts
  Add PE facts to stdlib
2012-10-25 10:06:02 -07:00
Jeff McCune
e68677976b Prevent undefined method `split' for nil:NilClass with pe_foo_version facts
Without this patch the pe_major_version, pe_minor_version, and
pe_patch_version facts directly depend on the pe_version fact in a
manner that calls split directly on the return value.

This is a problem because Fact values are not always guaranteed to
return strings, or objects that respond to split.  This patch is a
defensive measure to ensure we're always calling the split method on a
string object.

If the Fact returns nil, this will be converted to an empty string
responding to split.
2012-10-25 10:00:45 -07:00
Jeff McCune
ba70a3885a (maint) Clear all facts before each example
Without this patch example groups must explicitly call `Facter.clear` to
clear any cached values between examples.  This is a problem because
this behavior is not the concern of the example groups, the behavior is
the concern of the spec_helper or whatever facility we have in place to
initialize the system for testing.

This patch fixes the problem by duplicating the logic in the Facter
spec_helper to ensure facts are cleared out before each example.

This patch requires the example groups to explicitly load the facts they
require if the fact name does not match the filename.
2012-10-24 17:23:42 -07:00
Matthaus Owens
4442f1edb5 Add spec tests for pe_version facts
This commit adds some basic spec tests for the pe_version facts. There are
basic postitive and negative cases.
2012-10-24 17:23:42 -07:00
Matthaus Owens
cdf3b05f35 Add PE facts to stdlib
As many PE modules have PE specific functionality, but are deployed to all
nodes, including FOSS nodes, it is valuable to be able to selectively enable
those PE specific functions. These facts allow modules to use the is_pe fact to
determine whether the module should be used or not. The facts include is_pe,
pe_version, pe_major_version, pe_minor_version, and pe_patch_version. For PE
2.6.0 those facts would have values true, 2.6.0, 2, 6, and 0, respectively.
2012-10-24 17:23:42 -07:00