summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.sync.yml9
-rw-r--r--.travis.yml2
-rw-r--r--Gemfile72
-rw-r--r--Rakefile41
-rw-r--r--lib/facter/facter_dot_d.rb8
-rw-r--r--lib/facter/package_provider.rb2
-rw-r--r--lib/puppet/parser/functions/hash.rb2
-rw-r--r--lib/puppet/parser/functions/parsejson.rb2
-rw-r--r--lib/puppet/parser/functions/parseyaml.rb5
-rw-r--r--lib/puppet/parser/functions/validate_cmd.rb2
-rw-r--r--lib/puppet/type/file_line.rb9
-rwxr-xr-xspec/functions/get_module_path_spec.rb6
-rw-r--r--spec/puppetlabs_spec_helper_clone.rb34
-rw-r--r--spec/spec.opts6
-rwxr-xr-xspec/spec_helper.rb51
-rw-r--r--spec/spec_helper_local.rb29
-rwxr-xr-xspec/unit/puppet/provider/file_line/ruby_spec.rb4
-rwxr-xr-xspec/unit/puppet/type/file_line_spec.rb7
18 files changed, 125 insertions, 166 deletions
diff --git a/.sync.yml b/.sync.yml
deleted file mode 100644
index 21e872e..0000000
--- a/.sync.yml
+++ /dev/null
@@ -1,9 +0,0 @@
----
-.travis.yml:
- script: "\"bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--color --format documentation'\""
-Rakefile:
- unmanaged: true
-Gemfile:
- unmanaged: true
-spec/spec_helper.rb:
- unmanaged: true
diff --git a/.travis.yml b/.travis.yml
index 1f22c6c..588fb5b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -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:
diff --git a/Gemfile b/Gemfile
index 8221514..e490bc9 100644
--- a/Gemfile
+++ b/Gemfile
@@ -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
diff --git a/Rakefile b/Rakefile
index e136b8e..7e9a13d 100644
--- a/Rakefile
+++ b/Rakefile
@@ -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
diff --git a/lib/facter/facter_dot_d.rb b/lib/facter/facter_dot_d.rb
index d85940d..5c5fb1f 100644
--- a/lib/facter/facter_dot_d.rb
+++ b/lib/facter/facter_dot_d.rb
@@ -48,7 +48,7 @@ class Facter::Util::DotD
end
end
end
- rescue Exception => e
+ rescue StandardError => e
Facter.warn("Failed to handle #{file} as text facts: #{e.class}: #{e}")
end
@@ -65,7 +65,7 @@ class Facter::Util::DotD
setcode { v }
end
end
- rescue Exception => e
+ rescue StandardError => e
Facter.warn("Failed to handle #{file} as json facts: #{e.class}: #{e}")
end
@@ -77,7 +77,7 @@ class Facter::Util::DotD
setcode { v }
end
end
- rescue Exception => e
+ rescue StandardError => e
Facter.warn("Failed to handle #{file} as yaml facts: #{e.class}: #{e}")
end
@@ -106,7 +106,7 @@ class Facter::Util::DotD
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
diff --git a/lib/facter/package_provider.rb b/lib/facter/package_provider.rb
index 1a0bac9..3a9117f 100644
--- a/lib/facter/package_provider.rb
+++ b/lib/facter/package_provider.rb
@@ -12,7 +12,7 @@ require 'puppet/type/package'
Facter.add(:package_provider) do
setcode do
- if Gem::Version.new(Facter.value(:puppetversion).split(' ')[0]) >= Gem::Version.new('3.6')
+ if defined? Gem and Gem::Version.new(Facter.value(:puppetversion).split(' ')[0]) >= Gem::Version.new('3.6')
Puppet::Type.type(:package).newpackage(:name => 'dummy', :allow_virtual => 'true')[:provider].to_s
else
Puppet::Type.type(:package).newpackage(:name => 'dummy')[:provider].to_s
diff --git a/lib/puppet/parser/functions/hash.rb b/lib/puppet/parser/functions/hash.rb
index 8cc4823..89d0e07 100644
--- a/lib/puppet/parser/functions/hash.rb
+++ b/lib/puppet/parser/functions/hash.rb
@@ -29,7 +29,7 @@ Would return: {'a'=>1,'b'=>2,'c'=>3}
# 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
diff --git a/lib/puppet/parser/functions/parsejson.rb b/lib/puppet/parser/functions/parsejson.rb
index b4af40e..f7c2896 100644
--- a/lib/puppet/parser/functions/parsejson.rb
+++ b/lib/puppet/parser/functions/parsejson.rb
@@ -15,7 +15,7 @@ be returned if the parsing of YAML string have failed.
begin
PSON::load(arguments[0]) || arguments[1]
- rescue Exception => e
+ rescue StandardError => e
if arguments[1]
arguments[1]
else
diff --git a/lib/puppet/parser/functions/parseyaml.rb b/lib/puppet/parser/functions/parseyaml.rb
index 66d0413..ba9d98a 100644
--- a/lib/puppet/parser/functions/parseyaml.rb
+++ b/lib/puppet/parser/functions/parseyaml.rb
@@ -16,7 +16,10 @@ be returned if the parsing of YAML string have failed.
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
diff --git a/lib/puppet/parser/functions/validate_cmd.rb b/lib/puppet/parser/functions/validate_cmd.rb
index 5df3c60..685162b 100644
--- a/lib/puppet/parser/functions/validate_cmd.rb
+++ b/lib/puppet/parser/functions/validate_cmd.rb
@@ -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
diff --git a/lib/puppet/type/file_line.rb b/lib/puppet/type/file_line.rb
index 77d3be2..f2c6937 100644
--- a/lib/puppet/type/file_line.rb
+++ b/lib/puppet/type/file_line.rb
@@ -111,8 +111,13 @@ Puppet::Type.newtype(:file_line) do
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
diff --git a/spec/functions/get_module_path_spec.rb b/spec/functions/get_module_path_spec.rb
index b1f682f..a39e413 100755
--- a/spec/functions/get_module_path_spec.rb
+++ b/spec/functions/get_module_path_spec.rb
@@ -5,11 +5,7 @@ describe 'get_module_path' do
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) }
it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) }
it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) }
- if Puppet.version.to_f >= 4.0
- it { is_expected.to run.with_params('one').and_raise_error(Puppet::Environments::EnvironmentNotFound, /Could not find a directory environment/) }
- else
- it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /Could not find module/) }
- end
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /Could not find module/) }
class StubModule
attr_reader :path
diff --git a/spec/puppetlabs_spec_helper_clone.rb b/spec/puppetlabs_spec_helper_clone.rb
deleted file mode 100644
index 6a94a3b..0000000
--- a/spec/puppetlabs_spec_helper_clone.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-#This file pulls in only the minimum necessary to let unmigrated specs still work
-
-# Define the main module namespace for use by the helper modules
-module PuppetlabsSpec
- # FIXTURE_DIR represents the standard locations of all fixture data. Normally
- # this represents <project>/spec/fixtures. This will be used by the fixtures
- # library to find relative fixture data.
- FIXTURE_DIR = File.join("spec", "fixtures") unless defined?(FIXTURE_DIR)
-end
-
-# Require all necessary helper libraries so they can be used later
-require 'puppetlabs_spec_helper/puppetlabs_spec/files'
-require 'puppetlabs_spec_helper/puppetlabs_spec/fixtures'
-#require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
-require 'puppetlabs_spec_helper/puppetlabs_spec/matchers'
-
-RSpec.configure do |config|
- # Include PuppetlabsSpec helpers so they can be called at convenience
- config.extend PuppetlabsSpec::Files
- config.extend PuppetlabsSpec::Fixtures
- config.include PuppetlabsSpec::Fixtures
-
- config.parser = 'future' if ENV['FUTURE_PARSER'] == 'yes'
- config.strict_variables = true if ENV['STRICT_VARIABLES'] == 'yes'
- config.stringify_facts = false if ENV['STRINGIFY_FACTS'] == 'no'
- config.trusted_node_data = true if ENV['TRUSTED_NODE_DATA'] == 'yes'
- config.ordering = ENV['ORDERING'] if ENV['ORDERING']
-
- # This will cleanup any files that were created with tmpdir or tmpfile
- config.after :each do
- PuppetlabsSpec::Files.cleanup
- end
-end
-
diff --git a/spec/spec.opts b/spec/spec.opts
deleted file mode 100644
index 91cd642..0000000
--- a/spec/spec.opts
+++ /dev/null
@@ -1,6 +0,0 @@
---format
-s
---colour
---loadby
-mtime
---backtrace
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 416036b..22d5d68 100755
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,49 +1,8 @@
-#! /usr/bin/env ruby -S rspec
-dir = File.expand_path(File.dirname(__FILE__))
-$LOAD_PATH.unshift File.join(dir, 'lib')
-
-# So everyone else doesn't have to include this base constant.
-module PuppetSpec
- FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), "fixtures") unless defined?(FIXTURE_DIR)
-end
-
-require 'puppet'
-require 'rspec-puppet'
+#This file is generated by ModuleSync, do not edit.
require 'puppetlabs_spec_helper/module_spec_helper'
-require 'monkey_patches/alias_should_to_must'
-require 'mocha/api'
-#require 'puppetlabs_spec_helper/module_spec_helper'
-require 'puppetlabs_spec_helper_clone'
-
-# hack to enable all the expect syntax (like allow_any_instance_of) in rspec-puppet examples
-RSpec::Mocks::Syntax.enable_expect(RSpec::Puppet::ManifestMatchers)
-
-RSpec.configure do |config|
- config.module_path = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'modules')
- config.manifest_dir = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'manifests')
- config.environmentpath = spec_path = File.expand_path(File.join(Dir.pwd, 'spec'))
-
- config.add_setting :puppet_future
- #config.puppet_future = (ENV['FUTURE_PARSER'] == 'yes' or Puppet.version.to_f >= 4.0)
- config.puppet_future = Puppet.version.to_f >= 4.0
-
- config.before :each do
- # Ensure that we don't accidentally cache facts and environment between
- # test cases. This requires each example group to explicitly load the
- # facts being exercised with something like
- # Facter.collection.loader.load(:ipaddress)
- Facter.clear
- Facter.clear_messages
-
- RSpec::Mocks.setup
- end
-
- config.after :each do
- RSpec::Mocks.verify
- RSpec::Mocks.teardown
- end
-end
-# Helper class to test handling of arguments which are derived from string
-class AlsoString < String
+# put local configuration and setup into spec_helper_local
+begin
+ require 'spec_helper_local'
+rescue LoadError
end
diff --git a/spec/spec_helper_local.rb b/spec/spec_helper_local.rb
new file mode 100644
index 0000000..023a862
--- /dev/null
+++ b/spec/spec_helper_local.rb
@@ -0,0 +1,29 @@
+
+# hack to enable all the expect syntax (like allow_any_instance_of) in rspec-puppet examples
+RSpec::Mocks::Syntax.enable_expect(RSpec::Puppet::ManifestMatchers)
+
+RSpec.configure do |config|
+ # supply tests with a possibility to test for the future parser
+ config.add_setting :puppet_future
+ config.puppet_future = Puppet.version.to_f >= 4.0
+
+ config.before :each do
+ # Ensure that we don't accidentally cache facts and environment between
+ # test cases. This requires each example group to explicitly load the
+ # facts being exercised with something like
+ # Facter.collection.loader.load(:ipaddress)
+ Facter.clear
+ Facter.clear_messages
+
+ RSpec::Mocks.setup
+ end
+
+ config.after :each do
+ RSpec::Mocks.verify
+ RSpec::Mocks.teardown
+ end
+end
+
+# Helper class to test handling of arguments which are derived from string
+class AlsoString < String
+end
diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb
index 23e649c..fdeaf1a 100755
--- a/spec/unit/puppet/provider/file_line/ruby_spec.rb
+++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb
@@ -398,7 +398,7 @@ describe provider_class do
expect(File.read(@tmpfile)).to eql("foo1\nfoo2\n")
end
- it 'should ignore the match if match_for_absense is not specified' do
+ it 'should ignore the match if match_for_absence is not specified' do
@resource = Puppet::Type::File_line.new(
{
:name => 'foo',
@@ -416,7 +416,7 @@ describe provider_class do
expect(File.read(@tmpfile)).to eql("foo1\nfoo\n")
end
- it 'should ignore the match if match_for_absense is false' do
+ it 'should ignore the match if match_for_absence is false' do
@resource = Puppet::Type::File_line.new(
{
:name => 'foo',
diff --git a/spec/unit/puppet/type/file_line_spec.rb b/spec/unit/puppet/type/file_line_spec.rb
index f1430f2..48e2670 100755
--- a/spec/unit/puppet/type/file_line_spec.rb
+++ b/spec/unit/puppet/type/file_line_spec.rb
@@ -41,10 +41,13 @@ describe Puppet::Type.type(:file_line) do
expect { file_line[:path] = 'file' }.to raise_error(Puppet::Error, /File paths must be fully qualified/)
end
it 'should require that a line is specified' do
- expect { Puppet::Type.type(:file_line).new(:name => 'foo', :path => '/tmp/file') }.to raise_error(Puppet::Error, /Both line and path are required attributes/)
+ expect { Puppet::Type.type(:file_line).new(:name => 'foo', :path => '/tmp/file') }.to raise_error(Puppet::Error, /line is a required attribute/)
+ end
+ it 'should not require that a line is specified when matching for absence' do
+ expect { Puppet::Type.type(:file_line).new(:name => 'foo', :path => '/tmp/file', :ensure => :absent, :match_for_absence => :true, :match => 'match') }.not_to raise_error
end
it 'should require that a file is specified' do
- expect { Puppet::Type.type(:file_line).new(:name => 'foo', :line => 'path') }.to raise_error(Puppet::Error, /Both line and path are required attributes/)
+ expect { Puppet::Type.type(:file_line).new(:name => 'foo', :line => 'path') }.to raise_error(Puppet::Error, /path is a required attribute/)
end
it 'should default to ensure => present' do
expect(file_line[:ensure]).to eq :present