summaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)Author
2012-11-07(#13974) Add predicate functions for interface factsWil Cooley
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-07Add function, uriescape, to URI.escape strings. Redmine #17459Joe Julian
2012-11-07Add function, uriescape, to URI.escape strings. Redmine #17459Joe Julian
2012-11-07Add function, uriescape, to URI.escape strings. Redmine #17459Joe Julian
2012-10-25Revert "Revert "Revert "Revert "Merge branch ↵Jeff McCune
'hkenney-ticket/master/2157_remove_facts_dot_d'"""" This reverts commit 2885d314b61055d20d85d36a68214f7d9e1e6ac6. No, really. Keep the !@#$% integration branches around so we don't have this revert nightmare again.
2012-10-25Revert "Revert "Revert "Merge branch ↵Jeff McCune
'hkenney-ticket/master/2157_remove_facts_dot_d'""" This reverts commit 8fc00ea5b6b39b220ebc6391489915dbeeb364ab. 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-25Explicitly load functions used by ensure_resourceDan Bode
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-25re-formattingDan Bode
This commit refactors to ensure 80 character lines.
2012-10-25Add better docs about duplicate resource failuresDan Bode
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-25Handle undef for parameter argumentDan Bode
This commit adds better handling of the case where undef is passed as the parameter value. This works by converting '' into []
2012-10-25Add function ensure_resource and defined_with_paramsDan Bode
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-25Revert "Revert "Merge branch 'haus-add_pe_facts_to_stdlib' into 2.4.x""Jeff McCune
This reverts commit d6d23b495cda0e154b4e73982acc43e586564c0e. 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-25Revert "Revert "Merge branch 'haus-add_pe_facts_to_stdlib' into 2.4.x""Jeff McCune
This reverts commit d6d23b495cda0e154b4e73982acc43e586564c0e. 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-25Merge branch '2.4.x'Jeff McCune
* 2.4.x: Revert "Merge branch 'haus-add_pe_facts_to_stdlib' into 2.4.x"
2012-10-25Revert "Merge branch 'haus-add_pe_facts_to_stdlib' into 2.4.x"Jeff McCune
This reverts commit 74e6411157b8df1af9a24c17971e3236f3096529, reversing changes made to 417d219aa6e42f2a16af42c98aa063fc1d9d2ecd. 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-25Merge branch '2.4.x'Jeff McCune
* 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-25Prevent undefined method `split' for nil:NilClass with pe_foo_version factsJeff McCune
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-24Add PE facts to stdlibMatthaus Owens
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-08-16Revert "Revert "Merge branch 'hkenney-ticket/master/2157_remove_facts_dot_d'""Jeff McCune
This reverts commit d3e30bcdc64964bba82e05e5409c38faa7f2b700.
2012-08-16Revert "Merge branch 'hkenney-ticket/master/2157_remove_facts_dot_d'"Jeff McCune
This reverts commit cc414a422de0d773a1012ca57f41f15b4d6caf06, reversing changes made to 29f8f89c19b2189aa78ab430e94671669cb4716c. 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-15Explicitly load functions used by ensure_resourceDan Bode
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-15Revert "Revert "Merge pull request #86 from bodepd/ensure_resource""Dan Bode
This reverts commit 1e0983362464e8f2832239b09cdbc9175a51e6ec.
2012-08-14Revert "Merge pull request #86 from bodepd/ensure_resource"Jeff McCune
This reverts commit 42ddd7fe54f37b84e34b4a005de2249e53f07469, reversing changes made to 53243605b28fc31618d079155c86b37b4e88a6ca.
2012-08-14Merge pull request #86 from bodepd/ensure_resourceJeff McCune
Add function ensure_resource and defined_with_params
2012-08-14Add support for a 'match' parameter to file_lineChris Price
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-14Merge branch '2.4.x'Jeff McCune
* 2.4.x: (#15872) Add to_bytes function
2012-08-14(#15872) Add to_bytes functionErik Dalén
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-13re-formattingDan Bode
This commit refactors to ensure 80 character lines.
2012-08-13Add better docs about duplicate resource failuresDan Bode
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-13Handle undef for parameter argumentDan Bode
This commit adds better handling of the case where undef is passed as the parameter value. This works by converting '' into []
2012-08-13Add function ensure_resource and defined_with_paramsDan Bode
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-09Merge branch '2.3.x' into 2.4.xPatrick Carlisle
* 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-07-23Merge branch '2.3.x'Jeff McCune
* 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(Maint) Fix up the get_module_path parser functionJeff McCune
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-10(#2157) Make facts_dot_d compatible with external factsHailee Kenney
Since facts_dot_d will eventually be removed and replaced by external facts, warn users who are using a ttl on their external facts that this feature will not be in Facter external facts. Provide a link to a page explaining how to cache fact values without the ttl functionality.
2012-07-10(#2157) Remove facter_dot_d for compatibility with external factsHailee Kenney
Since external facts does the same thing as facts_dot_d (except allow ttl for external facts and allow some Windows executable external facts), and external facts is the prefered solution, remove facts_dot_d in the next major relase of stdlib.
2012-06-07Add support for a 'match' parameter to file_lineChris Price
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-05-23Merge branch '2.3.x'Jeff McCune
* 2.3.x: fix regression in #11017 properly
2012-05-23fix regression in #11017 properlyPeter Meier
We need the defaultvalues for that.
2012-05-10Merge branch '2.3.x'Jeff McCune
* 2.3.x: 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
2012-05-10Make file_line default to ensure => presentJeff McCune
The examples in the file_line resource documentation state the following resource should work: file_line { 'sudo_rule': path => '/etc/sudoers', line => '%sudo ALL=(ALL) ALL', } Without this patch the example does not work because ensure is not set to present. This patch fixes the problem by setting the default value of ensure to present.
2012-04-03add a "step" argument to range()Steve Huff
This patch adds an optional "step" argument to the stdlib range() function. There is no change to the default behavior of the function; however, passing a numeric "step" argument invokes the Ruby Range#step method, e.g. range("0", "9", "2") returns [0,2,4,6,8]
2012-03-29Merge pull request #53 from traylenator/fqdn_rotateJeff McCune
(#13205) Rotate array/string randomley based on fqdn, fqdn_rotate()
2012-03-29Merge branch '2.2.x' into 2.3.xJeff McCune
* 2.2.x: (#13494) Specify the behavior of zero padded strings Update CHANGELOG, Modulefile for 2.1.3 Conflicts: CHANGELOG Modulefile
2012-03-29(#13494) Specify the behavior of zero padded stringsJeff McCune
Without this patch the specified behavior of strings that are numeric only and zero padded is unclear and untested in the spec tests. This is a problem because it's not clear that range('00', '10') will actually return [ "0", "1", ..., "10" ] instead of [ "00", "01", ..., "10" ] This patch addresses the issue by providing explicit test coverage. If the string conversion behavior of puppet changes, this test will begin to fail.
2012-03-18(#13205) Rotate array/string randomley based on fqdn, fqdn_rotate()Steve Traylen
2012-03-13(#13091) Fix LoadError exception with puppet applyJeff McCune
Puppet apply does not add the stdlib lib directory to the $LOAD_PATH. This is a problem because the puppet_vardir fact requires the puppet_settings library to be available for the `with_puppet` utility method. Without this patch, puppet apply will result in the following error: $ puppet apply --modulepath=/vagrant/modules -e 'notice $puppet_vardir' warning: Could not load fact file stdlib/lib/facter/puppet_vardir.rb: no such file to load -- facter/util/puppet_settings notice: Scope(Class[main]): notice: Finished catalog run in 0.01 seconds With this patch applied, puppet apply works as expected: $ puppet apply --modulepath=/vagrant/modules.pe -e 'notice $puppet_vardir' notice: Scope(Class[main]): /Users/jeff/.puppet/var notice: Finished catalog run in 0.01 seconds This patch defensively tries to load facter/util/puppet_settings. If it cannot load it, it falls back to trying to explicitly locate and load the library. Once puppet is fixed such that a modules lib directory is truly in the $LOAD_PATH, the fall back implementation will no longer be exercised since the LoadError should not be raised.
2012-03-12(#12357) Fix broken compatibility with Puppet 2.6Jeff McCune
Without this patch, the previous change set to the validate_absolute_path() parser function contains Puppet 2.6 incompatible changes. stdlib 2.x is compatible with Puppet 2.6. These changes are a problem because we cannot introduce backwards incompatible changes in a minor release. This patch fixes the problem by back porting the implementation of the `Puppet::Util.absolute_path?` from 2.7.x to the function block itself. The function block tests to see if `Puppet::Util.absolute_path?` will respond and if not, falls back to the inline back ported implementation. The spec tests have been updated to simulate the behavior of Puppet 2.6 even when running with Puppet 2.7.
2012-03-09(maint) Comment Ken's fix to String#any?Jeff McCune
Just added a comment about why we're doing what we're doing.
2012-03-07(#13018) Fix missing method any? message for ruby 1.9.xKen Barber
The any? method doesn't exist for 1.9.x, this converts a string to a single element array to work around the problem.