Puppet4 Support: noop fixtures
Change-Id: Ie301faa4585e74f546dff7c845c7d8ef49d87552
This commit is contained in:
parent
47d20c9c22
commit
da6ea6109e
2
Gemfile
2
Gemfile
|
@ -3,7 +3,7 @@ source 'https://rubygems.org'
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
gem 'puppetlabs_spec_helper'
|
gem 'puppetlabs_spec_helper'
|
||||||
gem 'puppet-lint', '~> 0.3.2'
|
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 'rspec-puppet-utils', '~> 2.0.0'
|
||||||
gem 'deep_merge'
|
gem 'deep_merge'
|
||||||
gem 'pry'
|
gem 'pry'
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
*.pp
|
|
@ -18,3 +18,4 @@
|
||||||
:lsbdistcodename: 'trusty'
|
:lsbdistcodename: 'trusty'
|
||||||
:os_package_type: 'debian'
|
:os_package_type: 'debian'
|
||||||
:os_service_default: '<SERVICE DEFAULT>'
|
:os_service_default: '<SERVICE DEFAULT>'
|
||||||
|
:libvirt_package_version: '1.2.9'
|
||||||
|
|
|
@ -67,6 +67,7 @@ module Noop
|
||||||
facts_data[:hostname] = hostname if hostname
|
facts_data[:hostname] = hostname if hostname
|
||||||
facts_data[:l3_fqdn_hostname] = hostname if hostname
|
facts_data[:l3_fqdn_hostname] = hostname if hostname
|
||||||
facts_data[:fqdn] = fqdn if fqdn
|
facts_data[:fqdn] = fqdn if fqdn
|
||||||
|
facts_data[:puppetversion] = Puppet.version
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
|
|
|
@ -43,8 +43,12 @@ module Noop
|
||||||
def puppet_function(name, *args)
|
def puppet_function(name, *args)
|
||||||
name = name.to_sym unless name.is_a? Symbol
|
name = name.to_sym unless name.is_a? Symbol
|
||||||
puppet_function_load name
|
puppet_function_load name
|
||||||
error "Could not load Puppet function '#{name}'!" unless puppet_scope.respond_to? "function_#{name}".to_sym
|
if puppet4?
|
||||||
puppet_scope.send "function_#{name}".to_sym, args
|
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
|
end
|
||||||
|
|
||||||
# Take a variable value from the saved puppet scope
|
# Take a variable value from the saved puppet scope
|
||||||
|
@ -66,7 +70,7 @@ module Noop
|
||||||
def puppet_class_include(class_name)
|
def puppet_class_include(class_name)
|
||||||
class_name = class_name.to_s
|
class_name = class_name.to_s
|
||||||
unless puppet_scope.catalog.classes.include? class_name
|
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
|
puppet_scope.compiler.evaluate_classes [class_name], puppet_scope, false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -113,5 +117,32 @@ module Noop
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,6 +17,10 @@ module Noop
|
||||||
RSpec.configuration.manifest = file_path_manifest.to_s
|
RSpec.configuration.manifest = file_path_manifest.to_s
|
||||||
RSpec.configuration.module_path = Noop::Config.dir_path_modules_local.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
|
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
|
end
|
||||||
|
|
||||||
# Override Hiera configuration in the Puppet objects
|
# 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
|
# 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
|
# settings up front to prevent issues with test framework. See PUP-5601
|
||||||
def puppet_default_settings
|
def puppet_default_settings
|
||||||
Puppet.settings.initialize_app_defaults(
|
defaults = {
|
||||||
{
|
:logdir => '/dev/null',
|
||||||
:logdir => '/dev/null',
|
:confdir => '/dev/null',
|
||||||
:confdir => '/dev/null',
|
:vardir => '/dev/null',
|
||||||
:vardir => '/dev/null',
|
:rundir => '/dev/null',
|
||||||
:rundir => '/dev/null',
|
:hiera_config => '/dev/null',
|
||||||
:hiera_config => '/dev/null',
|
}
|
||||||
}
|
defaults[:codedir] = '/dev/null' if puppet4?
|
||||||
)
|
Puppet.settings.initialize_app_defaults(defaults)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rspec_coverage_add_override
|
def rspec_coverage_add_override
|
||||||
|
|
|
@ -63,6 +63,8 @@ def run_test(manifest_file, *args)
|
||||||
|
|
||||||
Noop::Config.log.progname = 'noop_spec'
|
Noop::Config.log.progname = 'noop_spec'
|
||||||
Noop::Utils.debug "RSPEC: #{Noop.task.inspect}"
|
Noop::Utils.debug "RSPEC: #{Noop.task.inspect}"
|
||||||
|
|
||||||
|
# FIXME: kludge to support calling Puppet function outside of the test context
|
||||||
Noop.setup_overrides
|
Noop.setup_overrides
|
||||||
|
|
||||||
include FuelRelationshipGraphMatchers
|
include FuelRelationshipGraphMatchers
|
||||||
|
|
Loading…
Reference in New Issue