Commit graph

146 commits

Author SHA1 Message Date
stephen
a773281760 Add test/validation for is_float if created from an arithmetical operation 2013-01-03 13:37:55 -08:00
stephen
b86f5dc129 Add test/validation for is_integer if created from an arithmetical operation 2013-01-03 13:37:55 -08:00
stephen
190b9438c5 Add test/validation for is_numeric if created from an arithmetical operation 2013-01-03 13:37:55 -08:00
Jeff McCune
16fe71867c Merge branch '2.x' into 3.x
* 2.x:
  Add reject() function
2012-11-28 14:29:14 -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
aa1e743e38 Merge branch '2.x' into 3.x
* 2.x:
  (Maint) Add spec/functions to rake test task
  Add example behaviors for ensure_packages() function
  Add an ensure_packages function.

Conflicts:
	Rakefile
2012-11-27 16:22:11 -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
276abac257 Merge branch '2.x' into 3.x
* 2.x:
  (#17797) min() and max() functions
2012-11-26 16:34:04 -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
0648148bfb Merge branch '2.x' into 3.x
* 2.x:
  (#14670) Fixup file_line autorequire specs
  (#14670) autorequire a file_line resource's path
2012-11-26 11:41:01 -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
ad262b56a4 Merge branch '2.x' into 3.x
* 2.x:
  Add join_keys_to_values function
2012-11-20 16:16:50 -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
824ea6d49f Merge branch '2.x' into 3.x
* 2.x:
  Extend delete function for strings and hashes
  Fixed typo
2012-11-19 08:45:31 -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
Jeff McCune
5353cd77b7 Merge branch '2.x' into 3.x
* 2.x:
  Add the pick() function
2012-11-15 08:57:21 -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
b97e053cad Merge branch '2.x' into 3.x
* 2.x:
  (#13974) Add predicate functions for interface facts
2012-11-07 14:03:22 -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
Joe Julian
2fc85d25d2 Add function, uriescape, to URI.escape strings. Redmine #17459 2012-11-07 09:36:54 -08:00
Joe Julian
70f4a0e9ed Add function, uriescape, to URI.escape strings. Redmine #17459 2012-11-07 09:36:54 -08:00
Jeff McCune
2885d314b6 Revert "Revert "Revert "Merge branch 'hkenney-ticket/master/2157_remove_facts_dot_d'"""
This reverts commit 8fc00ea5b6.

I really wish we could get this right.

Without this patch there is no branch that contains backwards-comaptible
new functionality relative to the current 3.0.1.  There are only
branches that contain backwards-incompatible functionality relative to
3.0.1.

This is a problem because I need to do a release of stdlib that contains
backwards compatible facts but does not contain any breaking changes.

This patch fixes the problem by establishing the 3.1.x branch.  This
branch will then revert the backwards incompatible changes from the
3.1.x branch and revert the revets in the 4.x and master branches.

I'll review our merge process, but it seems wrong that there is no place
to separate out incompatible from compatible changes when working beyond
the most recent patch release.
2012-10-25 11:20:50 -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
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
ee05c32e49 Revert "Revert "Merge branch 'haus-add_pe_facts_to_stdlib' into 2.4.x""
This reverts commit d6d23b495c.

Why?  Because this change set should actually be in master and our
merge-up process reverted the change set in master when I reverted from
2.4.x.

This patch reverts the revert, restoring the original change set.
2012-10-25 10:43:51 -07:00
Jeff McCune
43c80e800d Merge branch '2.4.x'
* 2.4.x:
  Revert "Merge branch 'haus-add_pe_facts_to_stdlib' into 2.4.x"
2012-10-25 10:43:11 -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
b8a0f28172 Merge branch '2.4.x'
* 2.4.x:
  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

Conflicts:
	spec/spec_helper.rb
2012-10-25 10:30:14 -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
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
Jeff McCune
8fc00ea5b6 Revert "Revert "Merge branch 'hkenney-ticket/master/2157_remove_facts_dot_d'""
This reverts commit d3e30bcdc6.
2012-08-16 19:49:47 -07:00
Jeff McCune
d3e30bcdc6 Revert "Merge branch 'hkenney-ticket/master/2157_remove_facts_dot_d'"
This reverts commit cc414a422d, reversing
changes made to 29f8f89c19.

Conflicts:
	README.markdown

Without this patch, there is no facts_dot_d functionality and we don't
have it implemented in Facter 2.0.  This is a problem because Puppet
Enterprise and many users rely on facts.d support.  We're also backwards
compatible with Facter 1.6 in stdlib 3.0 so this is a bug fix.
2012-08-16 19:28:13 -07:00
Dan Bode
5d99cdf09c 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-08-15 15:57:45 -07:00
Dan Bode
b42c82af19 Revert "Revert "Merge pull request #86 from bodepd/ensure_resource""
This reverts commit 1e09833624.
2012-08-15 15:56:57 -07:00
Jeff McCune
1e09833624 Revert "Merge pull request #86 from bodepd/ensure_resource"
This reverts commit 42ddd7fe54, reversing
changes made to 53243605b2.
2012-08-14 18:26:17 -07:00
Jeff McCune
42ddd7fe54 Merge pull request #86 from bodepd/ensure_resource
Add function ensure_resource and defined_with_params
2012-08-14 18:11:15 -07:00
Chris Price
a06c0d8115 Add support for a 'match' parameter to file_line
This commit adds a new parameter called "match"
to the file_line resource type, and support for
this new parameter to the corresponding ruby
provider.

This parameter is optional; file_line should work
just as before if you do not specify this parameter...
so this change should be backwards-compatible.

If you do specify the parameter, it is treated
as a regular expression that should be used when
looking through the file for a line.  This allows
you to do things like find a line that begins with
a certain prefix (e.g., "foo=.*"), and *replace*
the existing line with the line you specify in your
"line" parameter.  Without this capability, if you
already had a line "foo=bar" in your file and your
"line" parameter was set to "foo=baz", you'd end up
with *both* lines in the final file.  In many cases
this is undesirable.
2012-08-14 09:55:30 -07:00
Jeff McCune
29aec0df1e Merge branch '2.4.x'
* 2.4.x:
  (#15872) Add to_bytes function
2012-08-14 08:48:25 -07:00
Erik Dalén
247b69cbc0 (#15872) Add to_bytes function
Converts a string like "2 MB" to the value in bytes. Useful for
comparisons on facts that return a human readable number instead of
machine readable.
2012-08-14 08:43:36 -07:00
Dan Bode
5ffd33e8f1 re-formatting
This commit refactors to ensure 80 character lines.
2012-08-13 18:53:47 -07:00
Dan Bode
222a65dfe2 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-08-13 18:52:56 -07:00
Dan Bode
fe85f467c8 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-08-13 18:52:00 -07:00
Dan Bode
ba789deac5 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-08-13 17:09:10 -07:00
Patrick Carlisle
cdd4529833 Merge branch '2.3.x' into 2.4.x
* 2.3.x:
  Make sure functions are loaded for each test
  Use rvalue functions correctly
  (Maint) Don't mock with mocha
  (Maint) Fix up the get_module_path parser function
  (Maint) use PuppetlabsSpec::PuppetSeams.parser_scope (2.3.x)
  (Maint) Rename PuppetlabsSpec::Puppet{Seams,Internals}
  (Maint) use PuppetlabsSpec::PuppetSeams.parser_scope
  (Maint) Fix interpreter lines
  Update CHANGELOG, Modulefile for 2.3.3
  fix regression in #11017 properly
  Fix spec tests using the new spec_helper
  Update CHANGELOG for 2.3.2 release
  Make file_line default to ensure => present
  Memoize file_line spec instance variables
  Fix spec tests using the new spec_helper
  Revert "Merge remote-tracking branch 'eshamow/tickets/bug/13595_restrict_initialize_everything_for_tests' into 2.2.x"
  (#13595) initialize_everything_for_tests couples modules Puppet ver
2012-08-09 14:52:08 -07:00
Jeff McCune
243c7c2a49 Merge branch '2.3.x'
* 2.3.x:
  (Maint) Don't mock with mocha
  (Maint) Fix up the get_module_path parser function
  (Maint) use PuppetlabsSpec::PuppetSeams.parser_scope (2.3.x)
  (Maint) Rename PuppetlabsSpec::Puppet{Seams,Internals}
  (Maint) use PuppetlabsSpec::PuppetSeams.parser_scope
  (Maint) Fix interpreter lines

Conflicts:
	spec/spec_helper.rb
	spec/unit/puppet/parser/functions/get_module_path_spec.rb
2012-07-23 15:59:52 -07:00
Jeff McCune
c1297755d4 (Maint) Fix up the get_module_path parser function
This patch switches the spec tests for the get_module_path function to
use mock objects.  The underlying Puppet::Module.find method has
reasonable test coverage inside of Puppet core so we might as well break
the tight dependency while we're fixing up the specs to use the new
parser scope.

The behavior of the parser function itself should still have complete
coverage even though the tests have switched to mock the implementation
inside of Puppet.
2012-07-23 09:21:22 -07:00