Mentions légales du service

Skip to content
Snippets Groups Projects
Commit b2839870 authored by MICHON Nicolas's avatar MICHON Nicolas
Browse files

[dev] correct return codes of scripts used by jenkins tests

parent 1b59a890
Branches
No related tags found
No related merge requests found
...@@ -140,7 +140,8 @@ def cluster_homogeneity(refapi_hash, options = {:verbose => false}) ...@@ -140,7 +140,8 @@ def cluster_homogeneity(refapi_hash, options = {:verbose => false})
refapi_hash = load_yaml_file_hierarchy("../../input/grid5000/") refapi_hash = load_yaml_file_hierarchy("../../input/grid5000/")
count = {} count = {}
total_count = 0
refapi_hash["sites"].sort.each do |site_uid, site| refapi_hash["sites"].sort.each do |site_uid, site|
next if options.key?(:sites) && !options[:sites].include?(site_uid) next if options.key?(:sites) && !options[:sites].include?(site_uid)
...@@ -153,10 +154,10 @@ def cluster_homogeneity(refapi_hash, options = {:verbose => false}) ...@@ -153,10 +154,10 @@ def cluster_homogeneity(refapi_hash, options = {:verbose => false})
refnode_uid = cluster['nodes'].keys.sort.first refnode_uid = cluster['nodes'].keys.sort.first
refnode = cluster['nodes'][refnode_uid] refnode = cluster['nodes'][refnode_uid]
cluster["nodes"].each_sort_by_node_uid do |node_uid, node| cluster["nodes"].each_sort_by_node_uid do |node_uid, node|
#next if node_uid != 'graphene-2' #next if node_uid != 'graphene-2'
diffs = HashDiff.diff(refnode, node) diffs = HashDiff.diff(refnode, node)
# Hack HashDiff output for arrays: # Hack HashDiff output for arrays:
...@@ -184,8 +185,8 @@ def cluster_homogeneity(refapi_hash, options = {:verbose => false}) ...@@ -184,8 +185,8 @@ def cluster_homogeneity(refapi_hash, options = {:verbose => false})
# Remove keys that are specific to each nodes (ip, mac etc.) # Remove keys that are specific to each nodes (ip, mac etc.)
ikeys = cignore_keys[site_uid][node_uid] rescue nil ikeys = cignore_keys[site_uid][node_uid] rescue nil
diffs.clone.each { |diff| diffs.clone.each { |diff|
diffs.delete(diff) if ignore_keys.include?(diff[0] + diff[1]) diffs.delete(diff) if ignore_keys.include?(diff[0] + diff[1])
diffs.delete(diff) if ikeys && ikeys.include?(diff[0] + diff[1]) diffs.delete(diff) if ikeys && ikeys.include?(diff[0] + diff[1])
} }
if verbose && !diffs.empty? if verbose && !diffs.empty?
...@@ -193,32 +194,31 @@ def cluster_homogeneity(refapi_hash, options = {:verbose => false}) ...@@ -193,32 +194,31 @@ def cluster_homogeneity(refapi_hash, options = {:verbose => false})
pp diffs pp diffs
end end
total_count += diffs.size
count[site_uid][cluster_uid] += diffs.size count[site_uid][cluster_uid] += diffs.size
# Remove the following line if you want to compare each nodes to the first cluster node # Remove the following line if you want to compare each nodes to the first cluster node
refnode_uid = node_uid refnode_uid = node_uid
refnode = node refnode = node
end end
end end
end end
return count return [total_count, count]
end end
def check_cluster_homogeneity(refapi_hash, options = {:verbose => false}) def check_cluster_homogeneity(refapi_hash, options = {:verbose => false})
verbose = options[:verbose] verbose = options[:verbose]
puts "Differences found between successive nodes, per cluster:\n\n" puts "Differences found between successive nodes, per cluster:\n\n"
count = cluster_homogeneity(refapi_hash, options) total_count, count = cluster_homogeneity(refapi_hash, options)
puts "\n" if verbose puts "\n" if verbose
puts count.to_yaml unless verbose puts count.to_yaml unless verbose
puts "\nUse '../input-validators/check-cluster-homogeneity.rb -v' for details." unless verbose puts "\nUse '../input-validators/check-cluster-homogeneity.rb -v' for details." unless verbose
return count return total_count
end end
if __FILE__ == $0 if __FILE__ == $0
...@@ -229,25 +229,25 @@ if __FILE__ == $0 ...@@ -229,25 +229,25 @@ if __FILE__ == $0
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "Usage: check-cluster-homogeneity.rb [options]" opts.banner = "Usage: check-cluster-homogeneity.rb [options]"
opts.separator "" opts.separator ""
opts.separator "Example: ruby check-cluster-homogeneity.rb -v" opts.separator "Example: ruby check-cluster-homogeneity.rb -v"
### ###
opts.separator "" opts.separator ""
opts.separator "Filters:" opts.separator "Filters:"
opts.on('-s', '--sites a,b,c', Array, 'Select site(s)', opts.on('-s', '--sites a,b,c', Array, 'Select site(s)',
"Default: "+options[:sites].join(", ")) do |s| "Default: "+options[:sites].join(", ")) do |s|
raise "Wrong argument for -s option." unless (s - options[:sites]).empty? raise "Wrong argument for -s option." unless (s - options[:sites]).empty?
options[:sites] = s options[:sites] = s
end end
opts.on('-c', '--clusters a,b,c', Array, 'Select clusters(s). Default: all') do |s| opts.on('-c', '--clusters a,b,c', Array, 'Select clusters(s). Default: all') do |s|
options[:clusters] = s options[:clusters] = s
end end
opts.separator "" opts.separator ""
opts.separator "Common options:" opts.separator "Common options:"
...@@ -255,14 +255,18 @@ if __FILE__ == $0 ...@@ -255,14 +255,18 @@ if __FILE__ == $0
options[:verbose] ||= 0 options[:verbose] ||= 0
options[:verbose] = options[:verbose] + 1 options[:verbose] = options[:verbose] + 1
end end
# Print an options summary. # Print an options summary.
opts.on_tail("-h", "--help", "Show this message") do opts.on_tail("-h", "--help", "Show this message") do
puts opts puts opts
exit exit
end end
end.parse! end.parse!
refapi_hash = load_yaml_file_hierarchy("#{dir}/../../input/grid5000/") refapi_hash = load_yaml_file_hierarchy("#{dir}/../../input/grid5000/")
check_cluster_homogeneity(refapi_hash, options) total_count = check_cluster_homogeneity(refapi_hash, options)
# return 0 if all nodes are homogeneous, 1 otherwise
exit total_count == 0
end end
...@@ -30,23 +30,23 @@ def yaml_input_schema_validator(global_hash, sites = nil, clusters = nil) ...@@ -30,23 +30,23 @@ def yaml_input_schema_validator(global_hash, sites = nil, clusters = nil)
schema_site = load_yaml_schema("#{dir}/schema-site.yaml") schema_site = load_yaml_schema("#{dir}/schema-site.yaml")
schema_cluster = load_yaml_schema("#{dir}/schema-cluster.yaml") schema_cluster = load_yaml_schema("#{dir}/schema-cluster.yaml")
schema_node = load_yaml_schema("#{dir}/schema-node.yaml") schema_node = load_yaml_schema("#{dir}/schema-node.yaml")
r = true
r &= run_validator('global', global_hash, schema_global) # r &= run_validator('global', global_hash, schema_global) #
global_hash["sites"].each do |site_uid, site| global_hash["sites"].each do |site_uid, site|
next if sites and not sites.include?(site_uid) next if sites and not sites.include?(site_uid)
r &= run_validator(site_uid, site, schema_site) # r &= run_validator(site_uid, site, schema_site) #
site["clusters"].each do |cluster_uid, cluster| site["clusters"].each do |cluster_uid, cluster|
next if clusters and not clusters.include?(cluster_uid) next if clusters and not clusters.include?(cluster_uid)
r &= run_validator(cluster_uid, cluster, schema_cluster) # r &= run_validator(cluster_uid, cluster, schema_cluster) #
cluster["nodes"].each do |node_uid, node| cluster["nodes"].each do |node_uid, node|
r &= run_validator(node_uid, node, schema_node) # r &= run_validator(node_uid, node, schema_node) #
end end
end end
end end
...@@ -60,21 +60,21 @@ if __FILE__ == $0 ...@@ -60,21 +60,21 @@ if __FILE__ == $0
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "Usage: yaml-input-schema-validator.rb [options]" opts.banner = "Usage: yaml-input-schema-validator.rb [options]"
### ###
opts.separator "" opts.separator ""
opts.separator "Filters:" opts.separator "Filters:"
opts.on('-s', '--sites a,b,c', Array, 'Select site(s)', opts.on('-s', '--sites a,b,c', Array, 'Select site(s)',
"Default: all sites") do |s| "Default: all sites") do |s|
options[:sites] = s options[:sites] = s
end end
opts.on('-c', '--clusters a,b,c', Array, 'Select clusters(s). Default: all') do |s| opts.on('-c', '--clusters a,b,c', Array, 'Select clusters(s). Default: all') do |s|
options[:clusters] = s options[:clusters] = s
end end
# Print an options summary. # Print an options summary.
opts.on_tail("-h", "--help", "Show this message") do opts.on_tail("-h", "--help", "Show this message") do
puts opts puts opts
...@@ -86,4 +86,5 @@ if __FILE__ == $0 ...@@ -86,4 +86,5 @@ if __FILE__ == $0
global_hash = load_yaml_file_hierarchy("#{dir}/../../input/grid5000/") global_hash = load_yaml_file_hierarchy("#{dir}/../../input/grid5000/")
r = yaml_input_schema_validator(global_hash, options[:sites], options[:clusters]) r = yaml_input_schema_validator(global_hash, options[:sites], options[:clusters])
puts 'OK' if r puts 'OK' if r
exit r
end end
...@@ -71,12 +71,13 @@ OptionParser.new do |opts| ...@@ -71,12 +71,13 @@ OptionParser.new do |opts|
opts.on("-d", "--diff [YAML filename]", opts.on("-d", "--diff [YAML filename]",
"Only generates the minimal list of commands needed to update the site configuration", "Only generates the minimal list of commands needed to update the site configuration",
"The optional YAML file is suppose to be the output of the 'oarnodes -Y' command.", "The optional YAML file is supposed to be the output of the 'oarnodes -Y' command.",
"If the file does not exist, the script will get the data from the OAR server and save the result on disk for future use.", "If the file does not exist, the script will get the data from the OAR server and save the result on disk for future use.",
"If no filename is specified, the script will simply connect to the OAR server.", "If no filename is specified, the script will simply connect to the OAR server.",
"You can use the '%s' placeholder for 'site'. Ex: oarnodes-%s.yaml") do |d| "You can use the '%s' placeholder for 'site'. Ex: oarnodes-%s.yaml") do |d|
d = true if d == nil d = true if d == nil
options[:diff] = d options[:diff] = d
#If diff is set with no --output or --exec, the return code will be 0 if there are no differences, 1 otherwise
end end
### ###
...@@ -143,6 +144,8 @@ puts "Options: #{options}" if options[:verbose] ...@@ -143,6 +144,8 @@ puts "Options: #{options}" if options[:verbose]
puts "Hint: You might want to use either --verbose, --output or --exec." unless options[:verbose] || options[:output] || options[:exec] puts "Hint: You might want to use either --verbose, --output or --exec." unless options[:verbose] || options[:output] || options[:exec]
ret = true
nodelist_properties = {} # ["ref"] : properties from the reference-repo nodelist_properties = {} # ["ref"] : properties from the reference-repo
# ["oar"] : properties from the OAR server # ["oar"] : properties from the OAR server
# ["diff"] : diff between "ref" and "oar" # ["diff"] : diff between "ref" and "oar"
...@@ -153,8 +156,8 @@ nodelist_properties = {} # ["ref"] : properties from the reference-repo ...@@ -153,8 +156,8 @@ nodelist_properties = {} # ["ref"] : properties from the reference-repo
nodelist_properties["ref"] = {} nodelist_properties["ref"] = {}
global_hash = load_yaml_file_hierarchy('../../input/grid5000/') global_hash = load_yaml_file_hierarchy('../../input/grid5000/')
options[:sites].each { |site_uid| options[:sites].each { |site_uid|
nodelist_properties["ref"][site_uid] = get_nodelist_properties(site_uid, global_hash["sites"][site_uid]) nodelist_properties["ref"][site_uid] = get_nodelist_properties(site_uid, global_hash["sites"][site_uid])
} }
# Get the list of property keys from the reference-repo (["ref"]) # Get the list of property keys from the reference-repo (["ref"])
...@@ -193,10 +196,15 @@ if options[:diff] ...@@ -193,10 +196,15 @@ if options[:diff]
end end
} }
} }
puts "*** Error: The following nodes exist in the OAR server but are missing in the reference-repo: #{missings_alive.join(', ')}.\n" if missings_alive.size > 0 if missings_alive.size > 0
puts "*** Warning: The following 'Dead' nodes exist in the OAR server but are missing in the reference-repo: #{missings_dead.join(', ')}. puts "*** Error: The following nodes exist in the OAR server but are missing in the reference-repo: #{missings_alive.join(', ')}.\n"
Those nodes should be marked as 'retired' in the reference-repo.\n" if missings_dead.size > 0 && options[:check] ret = false unless options[:exec] || options[:output]
end
if missings_dead.size > 0 && options[:check]
puts "*** Warning: The following 'Dead' nodes exist in the OAR server but are missing in the reference-repo: #{missings_dead.join(', ')}.
Those nodes should be marked as 'retired' in the reference-repo.\n"
ret = false unless options[:exec] || options[:output]
end
end end
# #
...@@ -210,7 +218,7 @@ if options[:diff] ...@@ -210,7 +218,7 @@ if options[:diff]
# #
header = false header = false
prev_diff = {} prev_diff = {}
nodelist_properties["diff"] = {} nodelist_properties["diff"] = {}
properties_keys["oar"] = Set.new [] properties_keys["oar"] = Set.new []
...@@ -226,7 +234,7 @@ if options[:diff] ...@@ -226,7 +234,7 @@ if options[:diff]
nodelist_properties["diff"][site_uid][node_uid] = node_properties_ref.select { |key, value| diff_keys.include?(key) } nodelist_properties["diff"][site_uid][node_uid] = node_properties_ref.select { |key, value| diff_keys.include?(key) }
# Verbose output # Verbose output
info = (nodelist_properties["oar"][site_uid][node_uid] == nil ? " new node !" : "") info = (nodelist_properties["oar"][site_uid][node_uid] == nil ? " new node !" : "")
case options[:verbose] case options[:verbose]
when 1 when 1
puts "#{node_uid}:#{info}" if info != "" puts "#{node_uid}:#{info}" if info != ""
...@@ -238,7 +246,7 @@ if options[:diff] ...@@ -238,7 +246,7 @@ if options[:diff]
header = true header = true
puts "Output format: ['~', 'key', 'old value', 'new value']" puts "Output format: ['~', 'key', 'old value', 'new value']"
end end
if diff.size==0 if diff.size == 0
puts " #{node_uid}: OK#{info}" puts " #{node_uid}: OK#{info}"
elsif diff == prev_diff elsif diff == prev_diff
puts " #{node_uid}:#{info} same modifications as above" puts " #{node_uid}:#{info} same modifications as above"
...@@ -252,8 +260,10 @@ if options[:diff] ...@@ -252,8 +260,10 @@ if options[:diff]
puts "#{node_uid}:#{info}" if info != "" puts "#{node_uid}:#{info}" if info != ""
puts JSON.pretty_generate({node_uid => {"old values" => node_properties_oar, "new values" => node_properties_ref}}) puts JSON.pretty_generate({node_uid => {"old values" => node_properties_oar, "new values" => node_properties_ref}})
end end
if diff.size != 0
ret = false unless options[:exec] || options[:output]
end
} }
} }
# Get the list of property keys from the OAR scheduler (["oar"]) # Get the list of property keys from the OAR scheduler (["oar"])
...@@ -267,17 +277,19 @@ if options[:diff] ...@@ -267,17 +277,19 @@ if options[:diff]
if v_oar && v_oar != v_ref && v_ref != NilClass && v_oar != NilClass if v_oar && v_oar != v_ref && v_ref != NilClass && v_oar != NilClass
# Detect inconsistency between the type (String/Fixnum) of properties generated by this script and the existing values on the server. # Detect inconsistency between the type (String/Fixnum) of properties generated by this script and the existing values on the server.
puts "Error: the OAR property '#{k}' is a '#{v_oar}' on the server and this script uses '#{v_ref}' for this property." puts "Error: the OAR property '#{k}' is a '#{v_oar}' on the server and this script uses '#{v_ref}' for this property."
ret = false unless options[:exec] || options[:output]
end end
} }
puts "Properties that need to be created on the server: #{properties_keys["diff"].keys.to_a.join(', ')}" if options[:verbose] && properties_keys["diff"].keys.size>0 puts "Properties that need to be created on the server: #{properties_keys["diff"].keys.to_a.join(', ')}" if options[:verbose] && properties_keys["diff"].keys.size > 0
# Detect unknown properties # Detect unknown properties
unknown_properties = properties_keys["oar"].keys.to_set - properties_keys["ref"].keys.to_set unknown_properties = properties_keys["oar"].keys.to_set - properties_keys["ref"].keys.to_set
ignore_keys.each { |key| unknown_properties.delete(key) } ignore_keys.each { |key| unknown_properties.delete(key) }
if options[:verbose] && unknown_properties.size>0 if options[:verbose] && unknown_properties.size > 0
puts "Properties existing on the server but not managed/known by the generator: #{unknown_properties.to_a.join(', ')}." puts "Properties existing on the server but not managed/known by the generator: #{unknown_properties.to_a.join(', ')}."
puts "Hint: you can delete properties with 'oarproperty -d <property>' or add them to the ignore list in lib/lib-oar-properties.rb." puts "Hint: you can delete properties with 'oarproperty -d <property>' or add them to the ignore list in lib/lib-oar-properties.rb."
ret = false unless options[:exec] || options[:output]
end end
end # if options[:diff] end # if options[:diff]
...@@ -286,8 +298,8 @@ end # if options[:diff] ...@@ -286,8 +298,8 @@ end # if options[:diff]
# #
if options[:output] || options[:exec] if options[:output] || options[:exec]
opt = options[:diff] ? 'diff' : 'ref' opt = options[:diff] ? 'diff' : 'ref'
nodelist_properties[opt].each { |site_uid, site_properties| nodelist_properties[opt].each { |site_uid, site_properties|
# Init # Init
options[:output].is_a?(String) ? o = File.open(options[:output].gsub("%s", site_uid),'w') : o = $stdout.dup options[:output].is_a?(String) ? o = File.open(options[:output].gsub("%s", site_uid),'w') : o = $stdout.dup
ssh_cmd = [] ssh_cmd = []
...@@ -344,3 +356,5 @@ if options[:output] || options[:exec] ...@@ -344,3 +356,5 @@ if options[:output] || options[:exec]
end end
} # site loop } # site loop
end # if options[:output] || options[:exec] end # if options[:output] || options[:exec]
exit ret
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment