Skip to content

Commit d9f6538

Browse files
author
Helen
committed
Merge pull request #595 from tphoney/4.12.0_release
master to 4.12.x
2 parents 2996121 + 085035d commit d9f6538

27 files changed

+237
-171
lines changed

.sync.yml

-9
This file was deleted.

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sudo: false
44
language: ruby
55
cache: bundler
66
bundler_args: --without system_tests
7-
script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--color --format documentation'"
7+
script: "bundle exec rake validate lint spec"
88
matrix:
99
fast_finish: true
1010
include:

Gemfile

+25-47
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,39 @@
1-
source ENV['GEM_SOURCE'] || 'https://rubygems.org'
1+
#This file is generated by ModuleSync, do not edit.
22

3-
def location_for(place, fake_version = nil)
3+
source ENV['GEM_SOURCE'] || "https://rubygems.org"
4+
5+
def location_for(place, version = nil)
46
if place =~ /^(git[:@][^#]*)#(.*)/
5-
[fake_version, { :git => $1, :branch => $2, :require => false }].compact
7+
[version, { :git => $1, :branch => $2, :require => false}].compact
68
elsif place =~ /^file:\/\/(.*)/
7-
['>= 0', { :path => File.expand_path($1), :require => false }]
9+
['>= 0', { :path => File.expand_path($1), :require => false}]
810
else
9-
[place, { :require => false }]
11+
[place, version, { :require => false}].compact
1012
end
1113
end
1214

1315
group :development, :unit_tests do
14-
# rspec must be v2 for ruby 1.8.7
15-
if RUBY_VERSION >= '1.8.7' and RUBY_VERSION < '1.9'
16-
gem 'rspec', '~> 2.0'
17-
else
18-
gem 'rspec', '~> 3.1.0', :require => false
19-
end
20-
21-
gem 'rake', '~> 10.1.0', :require => false
22-
gem 'rspec-puppet', '~> 2.2', :require => false
23-
gem 'mocha', :require => false
24-
# keep for its rake task for now
25-
gem 'puppetlabs_spec_helper', :require => false
26-
gem 'puppet-lint', :require => false
27-
gem 'metadata-json-lint', :require => false
28-
gem 'pry', :require => false
29-
gem 'simplecov', :require => false
16+
gem 'json', :require => false
17+
gem 'metadata-json-lint', :require => false
18+
gem 'puppet_facts', :require => false
19+
gem 'puppet-blacksmith', :require => false
20+
gem 'puppetlabs_spec_helper', :require => false
21+
gem 'rspec-puppet', '>= 2.3.2', :require => false
22+
gem 'simplecov', :require => false
3023
end
31-
32-
beaker_version = ENV['BEAKER_VERSION']
33-
beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION']
3424
group :system_tests do
35-
if beaker_version
36-
gem 'beaker', *location_for(beaker_version)
37-
end
38-
if beaker_rspec_version
39-
gem 'beaker-rspec', *location_for(beaker_rspec_version)
40-
else
41-
gem 'beaker-rspec', :require => false
42-
end
43-
gem 'serverspec', :require => false
44-
gem 'beaker-puppet_install_helper', :require => false
25+
gem 'beaker-rspec', *location_for(ENV['BEAKER_RSPEC_VERSION'] || '>= 3.4')
26+
gem 'beaker', *location_for(ENV['BEAKER_VERSION'])
27+
gem 'serverspec', :require => false
28+
gem 'beaker-puppet_install_helper', :require => false
29+
gem 'master_manipulator', :require => false
30+
gem 'beaker-hostgenerator', *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION'])
4531
end
4632

47-
facterversion = ENV['GEM_FACTER_VERSION'] || ENV['FACTER_GEM_VERSION']
48-
if facterversion
49-
gem 'facter', *location_for(facterversion)
50-
else
51-
gem 'facter', :require => false
52-
end
33+
gem 'facter', *location_for(ENV['FACTER_GEM_VERSION'])
34+
gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION'])
5335

54-
puppetversion = ENV['GEM_PUPPET_VERSION'] || ENV['PUPPET_GEM_VERSION']
55-
if puppetversion
56-
gem 'puppet', *location_for(puppetversion)
57-
else
58-
gem 'puppet', :require => false
59-
end
6036

61-
# vim:ft=ruby
37+
if File.exists? "#{__FILE__}.local"
38+
eval(File.read("#{__FILE__}.local"), binding)
39+
end

README.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ Takes a resource reference and an optional hash of attributes. Returns 'true' if
265265

266266
#### `delete`
267267

268-
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.
268+
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.
269269

270270
#### `delete_at`
271271

Rakefile

+38-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,42 @@
1-
require 'rubygems'
2-
# keep for compatibility for now
3-
require 'puppetlabs_spec_helper/rake_tasks'
1+
require 'puppet_blacksmith/rake_tasks'
42
require 'puppet-lint/tasks/puppet-lint'
3+
require 'puppetlabs_spec_helper/rake_tasks'
4+
5+
PuppetLint.configuration.fail_on_warnings = true
6+
PuppetLint.configuration.send('relative')
57
PuppetLint.configuration.send('disable_80chars')
8+
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
9+
PuppetLint.configuration.send('disable_documentation')
10+
PuppetLint.configuration.send('disable_single_quote_string_with_variables')
611
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]
712

13+
desc 'Generate pooler nodesets'
14+
task :gen_nodeset do
15+
require 'beaker-hostgenerator'
16+
require 'securerandom'
17+
require 'fileutils'
18+
19+
agent_target = ENV['TEST_TARGET']
20+
if ! agent_target
21+
STDERR.puts 'TEST_TARGET environment variable is not set'
22+
STDERR.puts 'setting to default value of "redhat-64default."'
23+
agent_target = 'redhat-64default.'
24+
end
25+
26+
master_target = ENV['MASTER_TEST_TARGET']
27+
if ! master_target
28+
STDERR.puts 'MASTER_TEST_TARGET environment variable is not set'
29+
STDERR.puts 'setting to default value of "redhat7-64mdcl"'
30+
master_target = 'redhat7-64mdcl'
31+
end
32+
33+
targets = "#{master_target}-#{agent_target}"
34+
cli = BeakerHostGenerator::CLI.new([targets])
35+
nodeset_dir = "tmp/nodesets"
36+
nodeset = "#{nodeset_dir}/#{targets}-#{SecureRandom.uuid}.yaml"
37+
FileUtils.mkdir_p(nodeset_dir)
38+
File.open(nodeset, 'w') do |fh|
39+
fh.print(cli.execute)
40+
end
41+
puts nodeset
42+
end

lib/facter/facter_dot_d.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def txt_parser(file)
4848
end
4949
end
5050
end
51-
rescue Exception => e
51+
rescue StandardError => e
5252
Facter.warn("Failed to handle #{file} as text facts: #{e.class}: #{e}")
5353
end
5454

@@ -65,7 +65,7 @@ def json_parser(file)
6565
setcode { v }
6666
end
6767
end
68-
rescue Exception => e
68+
rescue StandardError => e
6969
Facter.warn("Failed to handle #{file} as json facts: #{e.class}: #{e}")
7070
end
7171

@@ -77,7 +77,7 @@ def yaml_parser(file)
7777
setcode { v }
7878
end
7979
end
80-
rescue Exception => e
80+
rescue StandardError => e
8181
Facter.warn("Failed to handle #{file} as yaml facts: #{e.class}: #{e}")
8282
end
8383

@@ -106,7 +106,7 @@ def script_parser(file)
106106
end
107107
end
108108
end
109-
rescue Exception => e
109+
rescue StandardError => e
110110
Facter.warn("Failed to handle #{file} as script facts: #{e.class}: #{e}")
111111
Facter.debug(e.backtrace.join("\n\t"))
112112
end

lib/puppet/parser/functions/concat.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module Puppet::Parser::Functions
3131
arguments.shift
3232

3333
arguments.each do |x|
34-
result = result + Array(x)
34+
result = result + (x.is_a?(Array) ? x : [x])
3535
end
3636

3737
return result

lib/puppet/parser/functions/delete.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# delete.rb
33
#
44

5-
# TODO(Krzysztof Wilczynski): We need to add support for regular expression ...
6-
75
module Puppet::Parser::Functions
86
newfunction(:delete, :type => :rvalue, :doc => <<-EOS
97
Deletes all instances of a given element from an array, substring from a
@@ -34,7 +32,7 @@ module Puppet::Parser::Functions
3432
Array(arguments[1]).each do |item|
3533
case collection
3634
when Array, Hash
37-
collection.delete item
35+
collection.delete_if { |coll_item| coll_item =~ %r{#{item}} }
3836
when String
3937
collection.gsub! item, ''
4038
else

lib/puppet/parser/functions/hash.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module Puppet::Parser::Functions
2929
# This is to make it compatible with older version of Ruby ...
3030
array = array.flatten
3131
result = Hash[*array]
32-
rescue Exception
32+
rescue StandardError
3333
raise(Puppet::ParseError, 'hash(): Unable to compute ' +
3434
'hash from array given')
3535
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# is_email_address.rb
3+
#
4+
5+
module Puppet::Parser::Functions
6+
newfunction(:is_email_address, type: :rvalue, doc: <<-EOS
7+
Returns true if the string passed to this function is a valid email address.
8+
EOS
9+
) do |arguments|
10+
if arguments.size != 1
11+
raise(Puppet::ParseError, 'is_email_address(): Wrong number of arguments '\
12+
"given #{arguments.size} for 1")
13+
end
14+
15+
# Taken from http://emailregex.com/ (simpler regex)
16+
valid_email_regex = %r{\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z}
17+
return (arguments[0] =~ valid_email_regex) == 0
18+
end
19+
end
20+
21+
# vim: set ts=2 sw=2 et :

lib/puppet/parser/functions/parsejson.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Puppet::Parser::Functions
1515

1616
begin
1717
PSON::load(arguments[0]) || arguments[1]
18-
rescue Exception => e
18+
rescue StandardError => e
1919
if arguments[1]
2020
arguments[1]
2121
else

lib/puppet/parser/functions/parseyaml.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ module Puppet::Parser::Functions
1616

1717
begin
1818
YAML::load(arguments[0]) || arguments[1]
19-
rescue Exception => e
19+
# in ruby 1.9.3 Psych::SyntaxError is a RuntimeException
20+
# this still needs to catch that and work also on rubies that
21+
# do not have Psych available.
22+
rescue StandardError, Psych::SyntaxError => e
2023
if arguments[1]
2124
arguments[1]
2225
else

lib/puppet/parser/functions/validate_cmd.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module Puppet::Parser::Functions
5353
rescue Puppet::ExecutionFailure => detail
5454
msg += "\n#{detail}"
5555
raise Puppet::ParseError, msg
56-
rescue Exception => detail
56+
rescue StandardError => detail
5757
msg += "\n#{detail.class.name} #{detail}"
5858
raise Puppet::ParseError, msg
5959
ensure
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module Puppet::Parser::Functions
2+
newfunction(:validate_email_address, doc: <<-ENDHEREDOC
3+
Validate that all values passed are valid email addresses.
4+
Fail compilation if any value fails this check.
5+
The following values will pass:
6+
$my_email = "[email protected]"
7+
validate_email_address($my_email)
8+
validate_email_address("[email protected]", "[email protected]", $my_email)
9+
10+
The following values will fail, causing compilation to abort:
11+
$some_array = [ 'bad_email@/d/efdf.com' ]
12+
validate_email_address($some_array)
13+
ENDHEREDOC
14+
) do |args|
15+
rescuable_exceptions = [ArgumentError]
16+
17+
if args.empty?
18+
raise Puppet::ParseError, "validate_email_address(): wrong number of arguments (#{args.length}; must be > 0)"
19+
end
20+
21+
args.each do |arg|
22+
raise Puppet::ParseError, "#{arg.inspect} is not a string." unless arg.is_a?(String)
23+
24+
begin
25+
raise Puppet::ParseError, "#{arg.inspect} is not a valid email address" unless function_is_email_address([arg])
26+
rescue *rescuable_exceptions
27+
raise Puppet::ParseError, "#{arg.inspect} is not a valid email address"
28+
end
29+
end
30+
end
31+
end

lib/puppet/type/file_line.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,13 @@
111111
end
112112

113113
validate do
114-
unless self[:line] and self[:path]
115-
raise(Puppet::Error, "Both line and path are required attributes")
114+
unless self[:line]
115+
unless (self[:ensure].to_s == 'absent') and (self[:match_for_absence].to_s == 'true') and self[:match]
116+
raise(Puppet::Error, "line is a required attribute")
117+
end
118+
end
119+
unless self[:path]
120+
raise(Puppet::Error, "path is a required attribute")
116121
end
117122
end
118123
end

spec/acceptance/concat_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@
3434
}
3535
EOS
3636

37+
apply_manifest(pp, :catch_failures => true)
38+
end
39+
it 'should concat hash arguments' do
40+
pp = <<-EOS
41+
$output = concat([{"a" => "b"}], {"c" => "d", "e" => "f"})
42+
validate_array($output)
43+
if size($output) != 2 {
44+
fail("${output} should have 2 elements.")
45+
}
46+
if $output[1] != {"c" => "d", "e" => "f"} {
47+
fail("${output} does not have the expected hash for the second element.")
48+
}
49+
EOS
50+
3751
apply_manifest(pp, :catch_failures => true)
3852
end
3953
end

spec/functions/concat_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
it { is_expected.to run.with_params(['1','2','3'],[['4','5'],'6']).and_return(['1','2','3',['4','5'],'6']) }
1212
it { is_expected.to run.with_params(['1','2'],['3','4'],['5','6']).and_return(['1','2','3','4','5','6']) }
1313
it { is_expected.to run.with_params(['1','2'],'3','4',['5','6']).and_return(['1','2','3','4','5','6']) }
14+
it { is_expected.to run.with_params([{"a" => "b"}], {"c" => "d", "e" => "f"}).and_return([{"a" => "b"}, {"c" => "d", "e" => "f"}]) }
1415

1516
it "should leave the original array intact" do
1617
argument1 = ['1','2','3']

spec/functions/delete_spec.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
it { is_expected.to run.with_params([], 'two').and_return([]) }
1313
it { is_expected.to run.with_params(['two'], 'two').and_return([]) }
1414
it { is_expected.to run.with_params(['two', 'two'], 'two').and_return([]) }
15+
it { is_expected.to run.with_params(['one', 'two', 'three'], '^t.*').and_return(['one']) }
1516
it { is_expected.to run.with_params(['one', 'two', 'three'], 'four').and_return(['one', 'two', 'three']) }
1617
it { is_expected.to run.with_params(['one', 'two', 'three'], 'two').and_return(['one', 'three']) }
1718
it { is_expected.to run.with_params(['two', 'one', 'two', 'three', 'two'], 'two').and_return(['one', 'three']) }
@@ -32,7 +33,7 @@
3233
it { is_expected.to run.with_params('barfoobar', ['foo', 'barbar']).and_return('') }
3334
end
3435

35-
describe 'deleting from an array' do
36+
describe 'deleting from a hash' do
3637
it { is_expected.to run.with_params({}, '').and_return({}) }
3738
it { is_expected.to run.with_params({}, 'key').and_return({}) }
3839
it { is_expected.to run.with_params({'key' => 'value'}, 'key').and_return({}) }
@@ -44,6 +45,10 @@
4445
.with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, ['key1', 'key2']) \
4546
.and_return( {'key3' => 'value3'})
4647
}
48+
it { is_expected.to run \
49+
.with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, ['^key\d']) \
50+
.and_return({})
51+
}
4752
end
4853

4954
it "should leave the original array intact" do

0 commit comments

Comments
 (0)