Skip to content

master to 4.12.x #595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Apr 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .sync.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sudo: false
language: ruby
cache: bundler
bundler_args: --without system_tests
script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--color --format documentation'"
script: "bundle exec rake validate lint spec"
matrix:
fast_finish: true
include:
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## Supported Release 4.12.0
###Summary

This release provides several new functions, bugfixes, and some documentation updates.

####Features
- Adds `clamp`. This function keeps values within a specified range.
- Adds `validate_x509_rsa_key_pair`. This function validates an x509 RSA certificate and key pair.
- Adds `dig`. This function performs a deep lookup in nested hashes or arrays.
- Extends the `base64` support to fit `rfc2045` and `rfc4648`.
- Adds `is_ipv6_address` and `is_ipv4_address`. These functions validate the specified ipv4 or ipv6 addresses.
- Adds `enclose_ipv6`. This function encloses IPv6 addresses in square brackets.
- Adds `ensure_resources`. This function takes a list of resources and creates them if they don't exist.
- Extends `suffix` to support applying a suffix to keys in a hash.

####Bugfixes
- Fixes `fqdn_rand_string` tests, since Puppet 4.4.0 and later have a higher `fqdn_rand` ceiling.
- (MODULES-3152) Adds a check to `package_provider` to prevent failures if Gem is not installed.

## Supported Release 4.11.0
###Summary

Expand Down
72 changes: 25 additions & 47 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,61 +1,39 @@
source ENV['GEM_SOURCE'] || 'https://rubygems.org'
#This file is generated by ModuleSync, do not edit.

def location_for(place, fake_version = nil)
source ENV['GEM_SOURCE'] || "https://rubygems.org"

def location_for(place, version = nil)
if place =~ /^(git[:@][^#]*)#(.*)/
[fake_version, { :git => $1, :branch => $2, :require => false }].compact
[version, { :git => $1, :branch => $2, :require => false}].compact
elsif place =~ /^file:\/\/(.*)/
['>= 0', { :path => File.expand_path($1), :require => false }]
['>= 0', { :path => File.expand_path($1), :require => false}]
else
[place, { :require => false }]
[place, version, { :require => false}].compact
end
end

group :development, :unit_tests do
# rspec must be v2 for ruby 1.8.7
if RUBY_VERSION >= '1.8.7' and RUBY_VERSION < '1.9'
gem 'rspec', '~> 2.0'
else
gem 'rspec', '~> 3.1.0', :require => false
end

gem 'rake', '~> 10.1.0', :require => false
gem 'rspec-puppet', '~> 2.2', :require => false
gem 'mocha', :require => false
# keep for its rake task for now
gem 'puppetlabs_spec_helper', :require => false
gem 'puppet-lint', :require => false
gem 'metadata-json-lint', :require => false
gem 'pry', :require => false
gem 'simplecov', :require => false
gem 'json', :require => false
gem 'metadata-json-lint', :require => false
gem 'puppet_facts', :require => false
gem 'puppet-blacksmith', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'rspec-puppet', '>= 2.3.2', :require => false
gem 'simplecov', :require => false
end

beaker_version = ENV['BEAKER_VERSION']
beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION']
group :system_tests do
if beaker_version
gem 'beaker', *location_for(beaker_version)
end
if beaker_rspec_version
gem 'beaker-rspec', *location_for(beaker_rspec_version)
else
gem 'beaker-rspec', :require => false
end
gem 'serverspec', :require => false
gem 'beaker-puppet_install_helper', :require => false
gem 'beaker-rspec', *location_for(ENV['BEAKER_RSPEC_VERSION'] || '>= 3.4')
gem 'beaker', *location_for(ENV['BEAKER_VERSION'])
gem 'serverspec', :require => false
gem 'beaker-puppet_install_helper', :require => false
gem 'master_manipulator', :require => false
gem 'beaker-hostgenerator', *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION'])
end

facterversion = ENV['GEM_FACTER_VERSION'] || ENV['FACTER_GEM_VERSION']
if facterversion
gem 'facter', *location_for(facterversion)
else
gem 'facter', :require => false
end
gem 'facter', *location_for(ENV['FACTER_GEM_VERSION'])
gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION'])

puppetversion = ENV['GEM_PUPPET_VERSION'] || ENV['PUPPET_GEM_VERSION']
if puppetversion
gem 'puppet', *location_for(puppetversion)
else
gem 'puppet', :require => false
end

# vim:ft=ruby
if File.exists? "#{__FILE__}.local"
eval(File.read("#{__FILE__}.local"), binding)
end
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ Takes a resource reference and an optional hash of attributes. Returns 'true' if

#### `delete`

Deletes all instances of a given element from an array, substring from a string, or key from a hash. For example, `delete(['a','b','c','b'], 'b')` returns ['a','c']; `delete('abracadabra', 'bra')` returns 'acada'. `delete({'a' => 1,'b' => 2,'c' => 3},['b','c'])` returns {'a'=> 1}. *Type*: rvalue.
Deletes all instances of a given element from an array, substring from a string, or key from a hash. Arrays and hashes may also match on regular expressions. For example, `delete(['a','b','c','b'], 'b')` returns ['a','c']; `delete('abracadabra', 'bra')` returns 'acada'. `delete({'a' => 1,'b' => 2,'c' => 3},['b','c'])` returns {'a'=> 1}, `delete(['abf', 'ab', 'ac'], '^ab.*')` returns ['ac']. *Type*: rvalue.

#### `delete_at`

Expand Down
41 changes: 38 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
require 'rubygems'
# keep for compatibility for now
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet_blacksmith/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
require 'puppetlabs_spec_helper/rake_tasks'

PuppetLint.configuration.fail_on_warnings = true
PuppetLint.configuration.send('relative')
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
PuppetLint.configuration.send('disable_documentation')
PuppetLint.configuration.send('disable_single_quote_string_with_variables')
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]

desc 'Generate pooler nodesets'
task :gen_nodeset do
require 'beaker-hostgenerator'
require 'securerandom'
require 'fileutils'

agent_target = ENV['TEST_TARGET']
if ! agent_target
STDERR.puts 'TEST_TARGET environment variable is not set'
STDERR.puts 'setting to default value of "redhat-64default."'
agent_target = 'redhat-64default.'
end

master_target = ENV['MASTER_TEST_TARGET']
if ! master_target
STDERR.puts 'MASTER_TEST_TARGET environment variable is not set'
STDERR.puts 'setting to default value of "redhat7-64mdcl"'
master_target = 'redhat7-64mdcl'
end

targets = "#{master_target}-#{agent_target}"
cli = BeakerHostGenerator::CLI.new([targets])
nodeset_dir = "tmp/nodesets"
nodeset = "#{nodeset_dir}/#{targets}-#{SecureRandom.uuid}.yaml"
FileUtils.mkdir_p(nodeset_dir)
File.open(nodeset, 'w') do |fh|
fh.print(cli.execute)
end
puts nodeset
end
8 changes: 4 additions & 4 deletions lib/facter/facter_dot_d.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def txt_parser(file)
end
end
end
rescue Exception => e
rescue StandardError => e
Facter.warn("Failed to handle #{file} as text facts: #{e.class}: #{e}")
end

Expand All @@ -65,7 +65,7 @@ def json_parser(file)
setcode { v }
end
end
rescue Exception => e
rescue StandardError => e
Facter.warn("Failed to handle #{file} as json facts: #{e.class}: #{e}")
end

Expand All @@ -77,7 +77,7 @@ def yaml_parser(file)
setcode { v }
end
end
rescue Exception => e
rescue StandardError => e
Facter.warn("Failed to handle #{file} as yaml facts: #{e.class}: #{e}")
end

Expand Down Expand Up @@ -106,7 +106,7 @@ def script_parser(file)
end
end
end
rescue Exception => e
rescue StandardError => e
Facter.warn("Failed to handle #{file} as script facts: #{e.class}: #{e}")
Facter.debug(e.backtrace.join("\n\t"))
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/concat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Puppet::Parser::Functions
arguments.shift

arguments.each do |x|
result = result + Array(x)
result = result + (x.is_a?(Array) ? x : [x])
end

return result
Expand Down
4 changes: 1 addition & 3 deletions lib/puppet/parser/functions/delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# delete.rb
#

# TODO(Krzysztof Wilczynski): We need to add support for regular expression ...

module Puppet::Parser::Functions
newfunction(:delete, :type => :rvalue, :doc => <<-EOS
Deletes all instances of a given element from an array, substring from a
Expand Down Expand Up @@ -34,7 +32,7 @@ module Puppet::Parser::Functions
Array(arguments[1]).each do |item|
case collection
when Array, Hash
collection.delete item
collection.delete_if { |coll_item| coll_item =~ %r{#{item}} }
when String
collection.gsub! item, ''
else
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Puppet::Parser::Functions
# This is to make it compatible with older version of Ruby ...
array = array.flatten
result = Hash[*array]
rescue Exception
rescue StandardError
raise(Puppet::ParseError, 'hash(): Unable to compute ' +
'hash from array given')
end
Expand Down
21 changes: 21 additions & 0 deletions lib/puppet/parser/functions/is_email_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# is_email_address.rb
#

module Puppet::Parser::Functions
newfunction(:is_email_address, type: :rvalue, doc: <<-EOS
Returns true if the string passed to this function is a valid email address.
EOS
) do |arguments|
if arguments.size != 1
raise(Puppet::ParseError, 'is_email_address(): Wrong number of arguments '\
"given #{arguments.size} for 1")
end

# Taken from http://emailregex.com/ (simpler regex)
valid_email_regex = %r{\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z}
return (arguments[0] =~ valid_email_regex) == 0
end
end

# vim: set ts=2 sw=2 et :
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/parsejson.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Puppet::Parser::Functions

begin
PSON::load(arguments[0]) || arguments[1]
rescue Exception => e
rescue StandardError => e
if arguments[1]
arguments[1]
else
Expand Down
5 changes: 4 additions & 1 deletion lib/puppet/parser/functions/parseyaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ module Puppet::Parser::Functions

begin
YAML::load(arguments[0]) || arguments[1]
rescue Exception => e
# in ruby 1.9.3 Psych::SyntaxError is a RuntimeException
# this still needs to catch that and work also on rubies that
# do not have Psych available.
rescue StandardError, Psych::SyntaxError => e
if arguments[1]
arguments[1]
else
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/validate_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module Puppet::Parser::Functions
rescue Puppet::ExecutionFailure => detail
msg += "\n#{detail}"
raise Puppet::ParseError, msg
rescue Exception => detail
rescue StandardError => detail
msg += "\n#{detail.class.name} #{detail}"
raise Puppet::ParseError, msg
ensure
Expand Down
31 changes: 31 additions & 0 deletions lib/puppet/parser/functions/validate_email_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Puppet::Parser::Functions
newfunction(:validate_email_address, doc: <<-ENDHEREDOC
Validate that all values passed are valid email addresses.
Fail compilation if any value fails this check.
The following values will pass:
$my_email = "[email protected]"
validate_email_address($my_email)
validate_email_address("[email protected]", "[email protected]", $my_email)

The following values will fail, causing compilation to abort:
$some_array = [ 'bad_email@/d/efdf.com' ]
validate_email_address($some_array)
ENDHEREDOC
) do |args|
rescuable_exceptions = [ArgumentError]

if args.empty?
raise Puppet::ParseError, "validate_email_address(): wrong number of arguments (#{args.length}; must be > 0)"
end

args.each do |arg|
raise Puppet::ParseError, "#{arg.inspect} is not a string." unless arg.is_a?(String)

begin
raise Puppet::ParseError, "#{arg.inspect} is not a valid email address" unless function_is_email_address([arg])
rescue *rescuable_exceptions
raise Puppet::ParseError, "#{arg.inspect} is not a valid email address"
end
end
end
end
9 changes: 7 additions & 2 deletions lib/puppet/type/file_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,13 @@
end

validate do
unless self[:line] and self[:path]
raise(Puppet::Error, "Both line and path are required attributes")
unless self[:line]
unless (self[:ensure].to_s == 'absent') and (self[:match_for_absence].to_s == 'true') and self[:match]
raise(Puppet::Error, "line is a required attribute")
end
end
unless self[:path]
raise(Puppet::Error, "path is a required attribute")
end
end
end
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppetlabs-stdlib",
"version": "4.11.0",
"version": "4.12.0",
"author": "puppetlabs",
"summary": "Standard library of resources for Puppet modules.",
"license": "Apache-2.0",
Expand Down
14 changes: 14 additions & 0 deletions spec/acceptance/concat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@
}
EOS

apply_manifest(pp, :catch_failures => true)
end
it 'should concat hash arguments' do
pp = <<-EOS
$output = concat([{"a" => "b"}], {"c" => "d", "e" => "f"})
validate_array($output)
if size($output) != 2 {
fail("${output} should have 2 elements.")
}
if $output[1] != {"c" => "d", "e" => "f"} {
fail("${output} does not have the expected hash for the second element.")
}
EOS

apply_manifest(pp, :catch_failures => true)
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/functions/concat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
it { is_expected.to run.with_params(['1','2','3'],[['4','5'],'6']).and_return(['1','2','3',['4','5'],'6']) }
it { is_expected.to run.with_params(['1','2'],['3','4'],['5','6']).and_return(['1','2','3','4','5','6']) }
it { is_expected.to run.with_params(['1','2'],'3','4',['5','6']).and_return(['1','2','3','4','5','6']) }
it { is_expected.to run.with_params([{"a" => "b"}], {"c" => "d", "e" => "f"}).and_return([{"a" => "b"}, {"c" => "d", "e" => "f"}]) }

it "should leave the original array intact" do
argument1 = ['1','2','3']
Expand Down
Loading