diff --git a/Gemfile b/Gemfile index d886be3..cb312fa 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/catalogs/.gitignore b/catalogs/.gitignore index e69de29..b8cdaf8 100644 --- a/catalogs/.gitignore +++ b/catalogs/.gitignore @@ -0,0 +1 @@ +*.pp diff --git a/facts/ubuntu.yaml b/facts/ubuntu.yaml index b0c3d85..f842575 100644 --- a/facts/ubuntu.yaml +++ b/facts/ubuntu.yaml @@ -18,3 +18,4 @@ :lsbdistcodename: 'trusty' :os_package_type: 'debian' :os_service_default: '' +:libvirt_package_version: '1.2.9' diff --git a/lib/noop/task/facts.rb b/lib/noop/task/facts.rb index 8ccef34..7aaf735 100644 --- a/lib/noop/task/facts.rb +++ b/lib/noop/task/facts.rb @@ -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] diff --git a/lib/noop/task/helpers.rb b/lib/noop/task/helpers.rb index d1b2023..796f476 100644 --- a/lib/noop/task/helpers.rb +++ b/lib/noop/task/helpers.rb @@ -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 diff --git a/lib/noop/task/overrides.rb b/lib/noop/task/overrides.rb index cd8a354..d650efa 100644 --- a/lib/noop/task/overrides.rb +++ b/lib/noop/task/overrides.rb @@ -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 diff --git a/spec/shared-examples.rb b/spec/shared-examples.rb index c587a47..6b7d3c6 100644 --- a/spec/shared-examples.rb +++ b/spec/shared-examples.rb @@ -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