Browse Source

Merge "Add ROLE: annotation"

Jenkins 3 years ago
parent
commit
90bf154929
2 changed files with 54 additions and 9 deletions
  1. 16
    0
      doc/usage.rst
  2. 38
    9
      lib/noop/manager/library.rb

+ 16
- 0
doc/usage.rst View File

@@ -159,6 +159,13 @@ possible run combinations you can use the **RUN:** annotation.::
159 159
 It can be specified many times an all entered combinations will be added to the
160 160
 list.
161 161
 
162
+You can use **ROLE** annotation to specify the list of node roles this
163
+spec should be running at. It will find the list of Hiera yaml files
164
+that have roles matching this list.::
165
+
166
+  # ROLE: controller
167
+  # ROLE: primary-controller
168
+
162 169
 There is also a way to use the reverse logic. You can specify the Hiera
163 170
 and facts yaml files that you want to exclude from the list instead of
164 171
 providing the list of included files.::
@@ -171,6 +178,15 @@ you have used both include and exclude options, the exclude option will have
171 178
 the priority over the include option. If there are no included Hiera files
172 179
 the list of Hiera files will be generated from the node roles.
173 180
 
181
+Note, that all these options can be combined all together. It will mean
182
+to take all 'compute' yamls, add neut_vlan_l3ha.ceph.ceil-primary-controller
183
+and remove 'neut_vlan.compute.ssl' and then add master/master_centos7 run.::
184
+
185
+  # ROLE: compute
186
+  # HIERA: neut_vlan_l3ha.ceph.ceil-primary-controller.yaml
187
+  # RUN: master master_centos7
188
+  # SKIP_HIERA: neut_vlan.compute.ssl.yaml
189
+
174 190
 The final annotation **DISABLE_SPEC** allows you to temporarily disable the
175 191
 spec from being seen the framework. It can use useful if you want to turn off
176 192
 a spec with run problems and fix them later without breaking the tests.::

+ 38
- 9
lib/noop/manager/library.rb View File

@@ -172,14 +172,7 @@ module Noop
172 172
       return @assign_spec_to_hiera if @assign_spec_to_hiera
173 173
       @assign_spec_to_hiera = {}
174 174
       assign_spec_to_roles.each do |file_name_spec, spec_roles_set|
175
-        if spec_roles_set.include? '*'
176
-          hiera_files = assign_hiera_to_roles.keys
177
-        else
178
-          hiera_files = assign_hiera_to_roles.select do |file_name_hiera, hiera_roles_set|
179
-            roles_intersection = hiera_roles_set & spec_roles_set
180
-            roles_intersection.any?
181
-          end.keys
182
-        end
175
+        hiera_files = get_hiera_for_roles spec_roles_set
183 176
         @assign_spec_to_hiera[file_name_spec] = hiera_files if hiera_files.any?
184 177
       end
185 178
       @assign_spec_to_hiera
@@ -231,10 +224,16 @@ module Noop
231 224
             task_spec_metadata[:skip_facts] += get_list_of_yamls $1
232 225
           end
233 226
 
234
-          if line =~ /disable_spec/
227
+          if line =~ /^\s*#\s*disable_spec/
235 228
             task_spec_metadata[:disable] = true
236 229
           end
237 230
 
231
+          if line =~ /^\s*#\s*role:\s*(.*)/
232
+            task_spec_metadata[:roles] = [] unless task_spec_metadata[:roles].is_a? Array
233
+            roles = line.split /\s*,\s*|\s+/
234
+            task_spec_metadata[:roles] += roles
235
+          end
236
+
238 237
           if line =~ /^\s*#\s*run:\s*(.*)/
239 238
             run_record = get_list_of_yamls $1
240 239
             if run_record.length >= 2
@@ -278,6 +277,13 @@ module Noop
278 277
       file_name_spec = Noop::Utils.convert_to_path file_name_spec
279 278
       metadata = spec_run_metadata.fetch file_name_spec, {}
280 279
       metadata[:facts] = [Noop::Config.default_facts_file_name] unless metadata[:facts]
280
+
281
+      if metadata[:roles]
282
+        metadata[:hiera] = [] unless metadata[:hiera]
283
+        metadata[:hiera] += get_hiera_for_roles metadata[:roles]
284
+      end
285
+
286
+      # the last default way to get hiera files list
281 287
       metadata[:hiera] = assign_spec_to_hiera.fetch file_name_spec, [] unless metadata[:hiera]
282 288
 
283 289
       runs = []
@@ -294,6 +300,29 @@ module Noop
294 300
       runs
295 301
     end
296 302
 
303
+    # Get a list of Hiera YAML files which roles
304
+    # include the given set of roles
305
+    # @param roles [Array,Set,String]
306
+    # @return [Array]
307
+    def get_hiera_for_roles(*roles)
308
+      all_roles = Set.new
309
+      roles.flatten.each do |role|
310
+        if role.is_a? Set
311
+          all_roles += role
312
+        else
313
+          all_roles.add role
314
+        end
315
+      end
316
+      if all_roles.include? '*'
317
+        assign_hiera_to_roles.keys
318
+      else
319
+        assign_hiera_to_roles.select do |_file_name_hiera, hiera_roles_set|
320
+          roles_intersection = hiera_roles_set & all_roles
321
+          roles_intersection.any?
322
+        end.keys
323
+      end
324
+    end
325
+
297 326
     # Check if the given element matches this filter
298 327
     # @param [Array<String>]
299 328
     def filter_is_matched?(filter, element)

Loading…
Cancel
Save