From 545dcc91f5b4487e91c94b0af96003ad54e10017 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 15 Jul 2014 11:27:47 -0400 Subject: [PATCH 1/6] Prepare a 4.3.2 release. --- CHANGELOG.md | 6 ++++++ metadata.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a63ec60a..fb5fd7f4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +##2014-07-15 - Supported Release 4.3.2 +###Summary + +This release merely updates metadata.json so the module can be uninstalled and +upgraded via the puppet module command. + ##2014-07-14 - Supported Release 4.3.1 ### Summary This supported release updates the metadata.json to work around upgrade behavior of the PMT. diff --git a/metadata.json b/metadata.json index bce75e093..26167b6f0 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-stdlib", - "version": "4.3.1", + "version": "4.3.2", "author": "puppetlabs", "summary": "Puppet Module Standard Library", "license": "Apache 2.0", From 31b02f84922d29ee063fbfc3d6f4d9621c7cc424 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Thu, 17 Jul 2014 10:48:25 -0400 Subject: [PATCH 2/6] (MODULES-927) Add missing functions to README * anchor * bool2str * camelcase * deep_merge * pick_default * validate_ipv4_address * validate_ipv6_address --- README.markdown | 128 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/README.markdown b/README.markdown index e9ad53b8b..e3bc49036 100644 --- a/README.markdown +++ b/README.markdown @@ -77,6 +77,43 @@ Returns the absolute value of a number, for example -34.56 becomes - *Type*: rvalue +anchor +------ +A simple resource type intended to be used as an anchor in a composite class. + +In Puppet 2.6, when a class declares another class, the resources in the +interior class are not contained by the exterior class. This interacts badly +with the pattern of composing complex modules from smaller classes, as it +makes it impossible for end users to specify order relationships between the +exterior class and other modules. + +The anchor type lets you work around this. By sandwiching any interior +classes between two no-op resources that _are_ contained by the exterior +class, you can ensure that all resources in the module are contained. + + class ntp { + # These classes will have the correct order relationship with each + # other. However, without anchors, they won't have any order + # relationship to Class['ntp']. + class { 'ntp::package': } + -> class { 'ntp::config': } + -> class { 'ntp::service': } + + # These two resources "anchor" the composed classes within the ntp + # class. + anchor { 'ntp::begin': } -> Class['ntp::package'] + Class['ntp::service'] -> anchor { 'ntp::end': } + } + +This allows the end user of the ntp module to establish require and before +relationships with Class['ntp']: + + class { 'ntp': } -> class { 'mcollective': } + class { 'mcollective': } -> class { 'ntp': } + + +- *Type*: resource + any2array --------- This converts any object to an array containing that object. Empty argument @@ -103,6 +140,19 @@ true, t, 1, y, and yes to 1 Requires a single boolean or string as an input. +- *Type*: rvalue + +bool2str +-------- +Converts a boolean to a string. +Requires a single boolean as an input. + +- *Type*: rvalue + +camelcase +--------- +Converts the case of a string or all strings in an array to camel case. + - *Type*: rvalue capitalize @@ -160,6 +210,23 @@ Count the number of elements in array that matches second argument. If called with only an array it counts the number of elements that are not nil/undef. +- *Type*: rvalue + +deep_merge +---------- +Recursively merges two or more hashes together and returns the resulting hash. + +*Example:* + + $hash1 = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } } + $hash2 = {'two' => 'dos', 'three' => { 'five' => 5 } } + $merged_hash = deep_merge($hash1, $hash2) + # The resulting hash is equivalent to: + # $merged_hash = { 'one' => 1, 'two' => 'dos', 'three' => { 'four' => 4, 'five' => 5 } } + +When there is a duplicate key that is a hash, they are recursively merged. +When there is a duplicate key that is not a hash, the key in the rightmost hash will "win." + - *Type*: rvalue defined_with_params @@ -713,6 +780,30 @@ failing that, will use a default value of 1.449. - *Type*: rvalue +pick_default +------------ +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). If no value is +found, it will return the last argument. + +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_default($::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. + +Note that, contrary to the pick() function, the pick_default does not fail if +all arguments are empty. This allows pick_default to use an empty value as +default. + +- *Type*: rvalue + prefix ------ This function applies a prefix to all elements in an array. @@ -1166,6 +1257,43 @@ The following values will fail, causing compilation to abort: +- *Type*: statement + +validate_ipv4_address +--------------------- +Validate that all values passed are valid IPv4 addresses. +Fail compilation if any value fails this check. + +The following values will pass: + + $my_ip = "1.2.3.4" + validate_ipv4_address($my_ip) + validate_bool("8.8.8.8", "172.16.0.1", $my_ip) + +The following values will fail, causing compilation to abort: + + $some_array = [ 1, true, false, "garbage string", "3ffe:505:2" ] + validate_ipv4_address($some_array) + +- *Type*: statement + +validate_ipv6_address +--------------------- + Validate that all values passed are valid IPv6 addresses. +Fail compilation if any value fails this check. + +The following values will pass: + + $my_ip = "3ffe:505:2" + validate_ipv6_address(1) + validate_ipv6_address($my_ip) + validate_bool("fe80::baf6:b1ff:fe19:7507", $my_ip) + +The following values will fail, causing compilation to abort: + + $some_array = [ true, false, "garbage string", "1.2.3.4" ] + validate_ipv6_address($some_array) + - *Type*: statement validate_re From b2033a0c114b4bb219502c7704aa747a636968cb Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Thu, 17 Jul 2014 11:06:00 -0400 Subject: [PATCH 3/6] (MODULES-927) Update docs for functions in README * range (take an optional third argument for range step) * validate_slength (take an optional third argument for minimum length) * file_line (take after and multiple attributes) --- README.markdown | 64 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/README.markdown b/README.markdown index e3bc49036..e033b1554 100644 --- a/README.markdown +++ b/README.markdown @@ -381,8 +381,11 @@ the type and parameters specified if it doesn't already exist. file_line --------- -This resource ensures that a given line is contained within a file. You can also use -"match" to replace existing lines. +Ensures that a given line is contained within a file. The implementation +matches the full line, including whitespace at the beginning and end. If +the line is not contained in the given file, Puppet will add the line to +ensure the desired state. Multiple resources may be declared to manage +multiple lines in the same file. *Examples:* @@ -390,13 +393,42 @@ This resource ensures that a given line is contained within a file. You can also path => '/etc/sudoers', line => '%sudo ALL=(ALL) ALL', } - - file_line { 'change_mount': - path => '/etc/fstab', - line => '10.0.0.1:/vol/data /opt/data nfs defaults 0 0', - match => '^172.16.17.2:/vol/old', + file_line { 'sudo_rule_nopw': + path => '/etc/sudoers', + line => '%sudonopw ALL=(ALL) NOPASSWD: ALL', } +In this example, Puppet will ensure both of the specified lines are +contained in the file /etc/sudoers. + +*Parameters within `file_line`:* + +**`after`** + +An optional value used to specify the line after which we will add any new +lines. (Existing lines are added in place) + +**`line`** + +The line to be appended to the file located by the path parameter. + +**`match`** + +An optional regular expression to run against existing lines in the file; +if a match is found, we replace that line rather than adding a new line. + +**`multiple`** + +An optional value to determine if match can change multiple lines. + +**`name`** + +An arbitrary name used as the identity of the resource. + +**`path`** + +The file Puppet will ensure contains the line specified by the line parameter. + - *Type*: resource flatten @@ -840,6 +872,13 @@ Will return: ["a","b","c"] Will return: ["host01", "host02", ..., "host09", "host10"] +Passing a third argument will cause the generated range to step by that +interval, e.g. + + range("0", "9", "2") + +Will return: [0,2,4,6,8] + - *Type*: rvalue reject @@ -1328,21 +1367,22 @@ A helpful error message can be returned like this: validate_slength ---------------- Validate that the first argument is a string (or an array of strings), and -less/equal to than the length of the second argument. It fails if the first -argument is not a string or array of strings, and if arg 2 is not convertable -to a number. +less/equal to than the length of the second argument. An optional third +parameter can be given a the minimum length. It fails if the first +argument is not a string or array of strings, and if arg 2 and arg 3 are +not convertable to a number. The following values will pass: validate_slength("discombobulate",17) validate_slength(["discombobulate","moo"],17) + validate_slength(["discombobulate","moo"],17,3) The following values will not: validate_slength("discombobulate",1) validate_slength(["discombobulate","thermometer"],5) - - + validate_slength(["discombobulate","moo"],17,10) - *Type*: statement From cf8d144caf69d884e77a4c8407083a8b5d78c9d0 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 5 Aug 2014 11:28:18 -0700 Subject: [PATCH 4/6] Remove simplecov simplecov 0.9 dropped ruby 1.8 support, and stdlib is one of the oddball modules that uses it. So we could probably just remove it and be okay. (cherry picked from commit a7c129b22d91fc723a8176c066a3eb96b03a2f56) --- spec/spec_helper.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 78925fdea..b490ca3c9 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,7 +9,6 @@ module PuppetSpec require 'puppet' require 'rspec-puppet' -require 'simplecov' require 'puppetlabs_spec_helper/module_spec_helper' require 'puppet_spec/verbose' require 'puppet_spec/files' @@ -21,10 +20,6 @@ module PuppetSpec require 'mocha/setup' -SimpleCov.start do - add_filter "/spec/" -end - RSpec.configure do |config| config.before :each do From acf435d1ce5916f99a13ef12f5f6560c9e63b935 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Tue, 16 Sep 2014 10:46:19 -0700 Subject: [PATCH 5/6] MODULES-1248 Fix issue with not properly counting regex matches with legacy versions of ruby --- lib/puppet/provider/file_line/ruby.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb index 94e7fac91..ae1a8b3db 100644 --- a/lib/puppet/provider/file_line/ruby.rb +++ b/lib/puppet/provider/file_line/ruby.rb @@ -34,7 +34,7 @@ def lines def handle_create_with_match() regex = resource[:match] ? Regexp.new(resource[:match]) : nil - match_count = lines.select { |l| regex.match(l) }.size + match_count = count_matches(regex) if match_count > 1 && resource[:multiple].to_s != 'true' raise Puppet::Error, "More than one line in file '#{resource[:path]}' matches pattern '#{resource[:match]}'" end @@ -51,9 +51,7 @@ def handle_create_with_match() def handle_create_with_after regex = Regexp.new(resource[:after]) - - count = lines.count {|l| l.match(regex)} - + count = count_matches(regex) case count when 1 # find the line to put our line after File.open(resource[:path], 'w') do |fh| @@ -71,6 +69,10 @@ def handle_create_with_after end end + def count_matches(regex) + lines.select{|l| l.match(regex)}.size + end + ## # append the line to the file. # From 8ad7f68ecaf444b39c4ca89e2e62790bc00ad89a Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Wed, 8 Oct 2014 10:14:10 -0700 Subject: [PATCH 6/6] ENTERPRISE-281 fixes issue with has_interfaces and case mismatch causing us not to return some interfaces --- lib/puppet/parser/functions/has_interface_with.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/has_interface_with.rb b/lib/puppet/parser/functions/has_interface_with.rb index 927b0dfeb..d5dbe473f 100644 --- a/lib/puppet/parser/functions/has_interface_with.rb +++ b/lib/puppet/parser/functions/has_interface_with.rb @@ -34,13 +34,15 @@ module Puppet::Parser::Functions end kind, value = args - + kind.downcase! + if lookupvar(kind) == value return true end result = false interfaces.each do |iface| + iface.downcase! if value == lookupvar("#{kind}_#{iface}") result = true break