diff --git a/doc/usage.rst b/doc/usage.rst index 76a6d31..c76d3d7 100644 --- a/doc/usage.rst +++ b/doc/usage.rst @@ -217,6 +217,18 @@ the override file name *firewall-firewall.yaml* and *openstack-controller-keystone.yaml* if these files are found in the override folders. +Using hiera plugin overrides +---------------------------- + +If you have several additional YAML files that should be applied on top of +the base Hiera files, for example, files, provided or generated by plugins +or the other tasks, you can use the plugin override system. Any files which +have been placed to the *hiera/plugins/${yaml_base_name}/* folder will be +applied on top of this YAML file when it will be used in the Noop tests. + +Multiple files inside this directory will be ordered alphabetically with +the former letters having the higher priority. + Working with report files ------------------------- diff --git a/hiera/plugins/master/.gitkeep b/hiera/plugins/master/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/lib/noop/config/hiera.rb b/lib/noop/config/hiera.rb index ddc5ee3..217a7f4 100644 --- a/lib/noop/config/hiera.rb +++ b/lib/noop/config/hiera.rb @@ -32,5 +32,15 @@ module Noop def self.default_hiera_file_name Pathname.new 'novanet-primary-controller.yaml' end + + # @return [Pathname] + def self.file_name_hiera_plugins + Pathname.new 'plugins' + end + + # @return [Pathname] + def self.file_path_hiera_plugins + Noop::Config.dir_path_hiera + file_name_hiera_plugins + end end end diff --git a/lib/noop/manager/library.rb b/lib/noop/manager/library.rb index e88f92f..3c3dafe 100644 --- a/lib/noop/manager/library.rb +++ b/lib/noop/manager/library.rb @@ -46,7 +46,7 @@ module Noop def hiera_file_names return @hiera_file_names if @hiera_file_names error "No #{Noop::Config.dir_path_hiera} directory!" unless Noop::Config.dir_path_hiera.directory? - exclude = [ Noop::Config.dir_name_hiera_override, Noop::Config.dir_name_globals ] + exclude = [ Noop::Config.dir_name_hiera_override, Noop::Config.dir_name_globals, Noop::Config.file_name_hiera_plugins ] @hiera_file_names = find_files(Noop::Config.dir_path_hiera, Noop::Config.dir_path_hiera, exclude) do |file| file.to_s.end_with? '.yaml' end @@ -393,6 +393,27 @@ module Noop @task_list end + # Collect all hiera plugins into a data structure. + # Used only for debugging purposes. + # @return [Hash Pathname>] + def hiera_plugins + return @hiera_plugins if @hiera_plugins + @hiera_plugins = {} + return @hiera_plugins unless Noop::Config.file_path_hiera_plugins.directory? + Noop::Config.file_path_hiera_plugins.children.each do |hiera| + next unless hiera.directory? + hiera_name = hiera.basename.to_s + hiera.children.each do |file| + next unless file.file? + next unless file.to_s.end_with? '.yaml' + file = file.relative_path_from Noop::Config.dir_path_hiera + @hiera_plugins[hiera_name] = [] unless @hiera_plugins[hiera_name] + @hiera_plugins[hiera_name] << file + end + end + @hiera_plugins + end + # Loop through all task files and find those that # do not have a corresponding spec file present # @return [Array] diff --git a/lib/noop/task/hiera.rb b/lib/noop/task/hiera.rb index dd9efc7..8f94a20 100644 --- a/lib/noop/task/hiera.rb +++ b/lib/noop/task/hiera.rb @@ -60,6 +60,27 @@ module Noop Noop::Config.dir_name_hiera_override + override_file.sub_ext('') end + # @return [Pathname] + def dir_path_task_hiera_plugins + Noop::Config.file_path_hiera_plugins + file_base_hiera + end + + # @return [Array] + def list_hiera_plugins + return @list_hiera_plugins if @list_hiera_plugins + @list_hiera_plugins = [] unless @list_hiera_plugins + return @list_hiera_plugins unless dir_path_task_hiera_plugins.directory? + dir_path_task_hiera_plugins.children.each do |file| + next unless file.file? + next unless file.to_s.end_with? '.yaml' + file = file.relative_path_from Noop::Config.dir_path_hiera + file = file.sub_ext('') + @list_hiera_plugins << file + end + @list_hiera_plugins.sort! + @list_hiera_plugins + end + # @return [String] def hiera_logger if ENV['SPEC_PUPPET_DEBUG'] @@ -72,9 +93,10 @@ module Noop # @return [Array] def hiera_hierarchy elements = [] + elements += list_hiera_plugins.map(&:to_s) if list_hiera_plugins.any? elements << element_hiera_override.to_s if file_present_hiera_override? - elements << element_hiera.to_s if file_present_hiera? elements << element_globals.to_s if file_present_globals? + elements << element_hiera.to_s if file_present_hiera? elements end