Merge "Add ROLE: annotation"

This commit is contained in:
Jenkins 2016-04-04 16:00:40 +00:00 committed by Gerrit Code Review
commit 90bf154929
2 changed files with 54 additions and 9 deletions

View File

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

View File

@ -172,14 +172,7 @@ module Noop
return @assign_spec_to_hiera if @assign_spec_to_hiera return @assign_spec_to_hiera if @assign_spec_to_hiera
@assign_spec_to_hiera = {} @assign_spec_to_hiera = {}
assign_spec_to_roles.each do |file_name_spec, spec_roles_set| assign_spec_to_roles.each do |file_name_spec, spec_roles_set|
if spec_roles_set.include? '*' hiera_files = get_hiera_for_roles spec_roles_set
hiera_files = assign_hiera_to_roles.keys
else
hiera_files = assign_hiera_to_roles.select do |file_name_hiera, hiera_roles_set|
roles_intersection = hiera_roles_set & spec_roles_set
roles_intersection.any?
end.keys
end
@assign_spec_to_hiera[file_name_spec] = hiera_files if hiera_files.any? @assign_spec_to_hiera[file_name_spec] = hiera_files if hiera_files.any?
end end
@assign_spec_to_hiera @assign_spec_to_hiera
@ -231,10 +224,16 @@ module Noop
task_spec_metadata[:skip_facts] += get_list_of_yamls $1 task_spec_metadata[:skip_facts] += get_list_of_yamls $1
end end
if line =~ /disable_spec/ if line =~ /^\s*#\s*disable_spec/
task_spec_metadata[:disable] = true task_spec_metadata[:disable] = true
end end
if line =~ /^\s*#\s*role:\s*(.*)/
task_spec_metadata[:roles] = [] unless task_spec_metadata[:roles].is_a? Array
roles = line.split /\s*,\s*|\s+/
task_spec_metadata[:roles] += roles
end
if line =~ /^\s*#\s*run:\s*(.*)/ if line =~ /^\s*#\s*run:\s*(.*)/
run_record = get_list_of_yamls $1 run_record = get_list_of_yamls $1
if run_record.length >= 2 if run_record.length >= 2
@ -278,6 +277,13 @@ module Noop
file_name_spec = Noop::Utils.convert_to_path file_name_spec file_name_spec = Noop::Utils.convert_to_path file_name_spec
metadata = spec_run_metadata.fetch file_name_spec, {} metadata = spec_run_metadata.fetch file_name_spec, {}
metadata[:facts] = [Noop::Config.default_facts_file_name] unless metadata[:facts] metadata[:facts] = [Noop::Config.default_facts_file_name] unless metadata[:facts]
if metadata[:roles]
metadata[:hiera] = [] unless metadata[:hiera]
metadata[:hiera] += get_hiera_for_roles metadata[:roles]
end
# the last default way to get hiera files list
metadata[:hiera] = assign_spec_to_hiera.fetch file_name_spec, [] unless metadata[:hiera] metadata[:hiera] = assign_spec_to_hiera.fetch file_name_spec, [] unless metadata[:hiera]
runs = [] runs = []
@ -294,6 +300,29 @@ module Noop
runs runs
end end
# Get a list of Hiera YAML files which roles
# include the given set of roles
# @param roles [Array,Set,String]
# @return [Array]
def get_hiera_for_roles(*roles)
all_roles = Set.new
roles.flatten.each do |role|
if role.is_a? Set
all_roles += role
else
all_roles.add role
end
end
if all_roles.include? '*'
assign_hiera_to_roles.keys
else
assign_hiera_to_roles.select do |_file_name_hiera, hiera_roles_set|
roles_intersection = hiera_roles_set & all_roles
roles_intersection.any?
end.keys
end
end
# Check if the given element matches this filter # Check if the given element matches this filter
# @param [Array<String>] # @param [Array<String>]
def filter_is_matched?(filter, element) def filter_is_matched?(filter, element)