Puppet4 Support: noop fixtures

Change-Id: Ie301faa4585e74f546dff7c845c7d8ef49d87552
This commit is contained in:
Dmitry Ilyin 2016-05-05 16:33:02 +03:00
parent 47d20c9c22
commit da6ea6109e
7 changed files with 53 additions and 13 deletions

View File

@ -3,7 +3,7 @@ source 'https://rubygems.org'
group :development, :test do
gem 'puppetlabs_spec_helper'
gem 'puppet-lint', '~> 0.3.2'
gem 'rspec-puppet', '~> 2.2.0'
gem 'rspec-puppet', '~> 2.4.0'
gem 'rspec-puppet-utils', '~> 2.0.0'
gem 'deep_merge'
gem 'pry'

1
catalogs/.gitignore vendored
View File

@ -0,0 +1 @@
*.pp

View File

@ -18,3 +18,4 @@
:lsbdistcodename: 'trusty'
:os_package_type: 'debian'
:os_service_default: '<SERVICE DEFAULT>'
:libvirt_package_version: '1.2.9'

View File

@ -67,6 +67,7 @@ module Noop
facts_data[:hostname] = hostname if hostname
facts_data[:l3_fqdn_hostname] = hostname if hostname
facts_data[:fqdn] = fqdn if fqdn
facts_data[:puppetversion] = Puppet.version
end
# @return [Hash]

View File

@ -43,8 +43,12 @@ module Noop
def puppet_function(name, *args)
name = name.to_sym unless name.is_a? Symbol
puppet_function_load name
error "Could not load Puppet function '#{name}'!" unless puppet_scope.respond_to? "function_#{name}".to_sym
puppet_scope.send "function_#{name}".to_sym, args
if puppet4?
puppet_scope.call_function name, args
else
error "Could not load Puppet function '#{name}'!" unless puppet_scope.respond_to? "function_#{name}".to_sym
puppet_scope.send "function_#{name}".to_sym, args
end
end
# Take a variable value from the saved puppet scope
@ -66,7 +70,7 @@ module Noop
def puppet_class_include(class_name)
class_name = class_name.to_s
unless puppet_scope.catalog.classes.include? class_name
debug "Dynamicly loading class: '#{class_name}'"
debug "Dynamically loading class: '#{class_name}'"
puppet_scope.compiler.evaluate_classes [class_name], puppet_scope, false
end
end
@ -113,5 +117,32 @@ module Noop
end
end
# check if we're using Puppet4
# @return [true,false]
def puppet4?
Puppet.version.to_f >= 4.0
end
# convert the values in the nested data structure
# from nil to :undef as they are used in Puppet 4
# modifies the argument object and returns it
# @param data [Array, Hash]
# @return [Array, Hash]
def nil2undef(data)
return :undef if data.nil?
if data.is_a? Array
data.each_with_index do |value, index|
data[index] = nil2undef value
end
data
elsif data.is_a? Hash
data.keys.each do |key|
data[key] = nil2undef data[key]
end
data
end
data
end
end
end

View File

@ -17,6 +17,10 @@ module Noop
RSpec.configuration.manifest = file_path_manifest.to_s
RSpec.configuration.module_path = Noop::Config.dir_path_modules_local.to_s
RSpec.configuration.manifest_dir = Noop::Config.dir_path_tasks_local.to_s
# FIXME: kludge to support calling Puppet function outside of the test context
Puppet.settings[:modulepath] = RSpec.configuration.module_path
Puppet.settings[:manifest] = RSpec.configuration.manifest_dir
end
# Override Hiera configuration in the Puppet objects
@ -82,15 +86,15 @@ module Noop
# This results in an rspec failure so we need to initialize the basic
# settings up front to prevent issues with test framework. See PUP-5601
def puppet_default_settings
Puppet.settings.initialize_app_defaults(
{
:logdir => '/dev/null',
:confdir => '/dev/null',
:vardir => '/dev/null',
:rundir => '/dev/null',
:hiera_config => '/dev/null',
}
)
defaults = {
:logdir => '/dev/null',
:confdir => '/dev/null',
:vardir => '/dev/null',
:rundir => '/dev/null',
:hiera_config => '/dev/null',
}
defaults[:codedir] = '/dev/null' if puppet4?
Puppet.settings.initialize_app_defaults(defaults)
end
def rspec_coverage_add_override

View File

@ -63,6 +63,8 @@ def run_test(manifest_file, *args)
Noop::Config.log.progname = 'noop_spec'
Noop::Utils.debug "RSPEC: #{Noop.task.inspect}"
# FIXME: kludge to support calling Puppet function outside of the test context
Noop.setup_overrides
include FuelRelationshipGraphMatchers