Browse Source

Add plugin hiera files support

* Put plugun files to hiera/plugins/$yaml_name/

Change-Id: I21389dcb9bf065a3a6f09753e423fdf942afb767
Dmitry Ilyin 2 years ago
parent
commit
d8c88d2d9d
5 changed files with 67 additions and 2 deletions
  1. 12
    0
      doc/usage.rst
  2. 0
    0
      hiera/plugins/master/.gitkeep
  3. 10
    0
      lib/noop/config/hiera.rb
  4. 22
    1
      lib/noop/manager/library.rb
  5. 23
    1
      lib/noop/task/hiera.rb

+ 12
- 0
doc/usage.rst View File

@@ -217,6 +217,18 @@ the override file name *firewall-firewall.yaml* and
217 217
 *openstack-controller-keystone.yaml* if these files are found in the
218 218
 override folders.
219 219
 
220
+Using hiera plugin overrides
221
+----------------------------
222
+
223
+If you have several additional YAML files that should be applied on top of
224
+the base Hiera files, for example, files, provided or generated by plugins
225
+or the other tasks, you can use the plugin override system. Any files which
226
+have been placed to the *hiera/plugins/${yaml_base_name}/* folder will be
227
+applied on top of this YAML file when it will be used in the Noop tests.
228
+
229
+Multiple files inside this directory will be ordered alphabetically with
230
+the former letters having the higher priority.
231
+
220 232
 Working with report files
221 233
 -------------------------
222 234
 

+ 0
- 0
hiera/plugins/master/.gitkeep View File


+ 10
- 0
lib/noop/config/hiera.rb View File

@@ -32,5 +32,15 @@ module Noop
32 32
     def self.default_hiera_file_name
33 33
       Pathname.new 'novanet-primary-controller.yaml'
34 34
     end
35
+
36
+    # @return [Pathname]
37
+    def self.file_name_hiera_plugins
38
+      Pathname.new 'plugins'
39
+    end
40
+
41
+    # @return [Pathname]
42
+    def self.file_path_hiera_plugins
43
+      Noop::Config.dir_path_hiera + file_name_hiera_plugins
44
+    end
35 45
   end
36 46
 end

+ 22
- 1
lib/noop/manager/library.rb View File

@@ -46,7 +46,7 @@ module Noop
46 46
     def hiera_file_names
47 47
       return @hiera_file_names if @hiera_file_names
48 48
       error "No #{Noop::Config.dir_path_hiera} directory!" unless Noop::Config.dir_path_hiera.directory?
49
-      exclude = [ Noop::Config.dir_name_hiera_override, Noop::Config.dir_name_globals ]
49
+      exclude = [ Noop::Config.dir_name_hiera_override, Noop::Config.dir_name_globals, Noop::Config.file_name_hiera_plugins ]
50 50
       @hiera_file_names = find_files(Noop::Config.dir_path_hiera, Noop::Config.dir_path_hiera, exclude) do |file|
51 51
         file.to_s.end_with? '.yaml'
52 52
       end
@@ -393,6 +393,27 @@ module Noop
393 393
       @task_list
394 394
     end
395 395
 
396
+    # Collect all hiera plugins into a data structure.
397
+    # Used only for debugging purposes.
398
+    # @return [Hash<String => Pathname>]
399
+    def hiera_plugins
400
+      return @hiera_plugins if @hiera_plugins
401
+      @hiera_plugins = {}
402
+      return @hiera_plugins unless Noop::Config.file_path_hiera_plugins.directory?
403
+      Noop::Config.file_path_hiera_plugins.children.each do |hiera|
404
+        next unless hiera.directory?
405
+        hiera_name = hiera.basename.to_s
406
+        hiera.children.each do |file|
407
+          next unless file.file?
408
+          next unless file.to_s.end_with? '.yaml'
409
+          file = file.relative_path_from Noop::Config.dir_path_hiera
410
+          @hiera_plugins[hiera_name] = [] unless @hiera_plugins[hiera_name]
411
+          @hiera_plugins[hiera_name] << file
412
+        end
413
+      end
414
+      @hiera_plugins
415
+    end
416
+
396 417
     # Loop through all task files and find those that
397 418
     # do not have a corresponding spec file present
398 419
     # @return [Array<Pathname>]

+ 23
- 1
lib/noop/task/hiera.rb View File

@@ -60,6 +60,27 @@ module Noop
60 60
       Noop::Config.dir_name_hiera_override + override_file.sub_ext('')
61 61
     end
62 62
 
63
+    # @return [Pathname]
64
+    def dir_path_task_hiera_plugins
65
+      Noop::Config.file_path_hiera_plugins + file_base_hiera
66
+    end
67
+
68
+    # @return [Array<Pathname>]
69
+    def list_hiera_plugins
70
+      return @list_hiera_plugins if @list_hiera_plugins
71
+      @list_hiera_plugins = [] unless @list_hiera_plugins
72
+      return @list_hiera_plugins unless dir_path_task_hiera_plugins.directory?
73
+      dir_path_task_hiera_plugins.children.each do |file|
74
+        next unless file.file?
75
+        next unless file.to_s.end_with? '.yaml'
76
+        file = file.relative_path_from Noop::Config.dir_path_hiera
77
+        file = file.sub_ext('')
78
+        @list_hiera_plugins << file
79
+      end
80
+      @list_hiera_plugins.sort!
81
+      @list_hiera_plugins
82
+    end
83
+
63 84
     # @return [String]
64 85
     def hiera_logger
65 86
       if ENV['SPEC_PUPPET_DEBUG']
@@ -72,9 +93,10 @@ module Noop
72 93
     # @return [Array<String>]
73 94
     def hiera_hierarchy
74 95
       elements = []
96
+      elements += list_hiera_plugins.map(&:to_s) if list_hiera_plugins.any?
75 97
       elements << element_hiera_override.to_s if file_present_hiera_override?
76
-      elements << element_hiera.to_s if file_present_hiera?
77 98
       elements << element_globals.to_s if file_present_globals?
99
+      elements << element_hiera.to_s if file_present_hiera?
78 100
       elements
79 101
     end
80 102
 

Loading…
Cancel
Save