Commit b2839870 authored by MICHON Nicolas's avatar MICHON Nicolas
Browse files

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

parent 1b59a890
......@@ -140,7 +140,8 @@ def cluster_homogeneity(refapi_hash, options = {:verbose => false})
refapi_hash = load_yaml_file_hierarchy("../../input/grid5000/")
count = {}
total_count = 0
refapi_hash["sites"].sort.each do |site_uid, site|
next if options.key?(:sites) && !options[:sites].include?(site_uid)
......@@ -153,10 +154,10 @@ def cluster_homogeneity(refapi_hash, options = {:verbose => false})
refnode_uid = cluster['nodes'].keys.sort.first
refnode = cluster['nodes'][refnode_uid]
cluster["nodes"].each_sort_by_node_uid do |node_uid, node|
#next if node_uid != 'graphene-2'
diffs = HashDiff.diff(refnode, node)
# Hack HashDiff output for arrays:
......@@ -184,8 +185,8 @@ def cluster_homogeneity(refapi_hash, options = {:verbose => false})
# Remove keys that are specific to each nodes (ip, mac etc.)
ikeys = cignore_keys[site_uid][node_uid] rescue nil
diffs.clone.each { |diff|
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 ignore_keys.include?(diff[0] + diff[1])
diffs.delete(diff) if ikeys && ikeys.include?(diff[0] + diff[1])
}
if verbose && !diffs.empty?
......@@ -193,32 +194,31 @@ def cluster_homogeneity(refapi_hash, options = {:verbose => false})
pp diffs
end
total_count += 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
refnode_uid = node_uid
refnode = node
end
end
end
return count
return [total_count, count]
end
def check_cluster_homogeneity(refapi_hash, options = {:verbose => false})
verbose = options[:verbose]
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 count.to_yaml unless verbose
puts "\nUse '../input-validators/check-cluster-homogeneity.rb -v' for details." unless verbose
return count
return total_count
end
if __FILE__ == $0
......@@ -229,25 +229,25 @@ if __FILE__ == $0
OptionParser.new do |opts|
opts.banner = "Usage: check-cluster-homogeneity.rb [options]"
opts.separator ""
opts.separator "Example: ruby check-cluster-homogeneity.rb -v"
###
opts.separator ""
opts.separator "Filters:"
opts.on('-s', '--sites a,b,c', Array, 'Select site(s)',
"Default: "+options[:sites].join(", ")) do |s|
raise "Wrong argument for -s option." unless (s - options[:sites]).empty?
options[:sites] = s
end
opts.on('-c', '--clusters a,b,c', Array, 'Select clusters(s). Default: all') do |s|
options[:clusters] = s
end
opts.separator ""
opts.separator "Common options:"
......@@ -255,14 +255,18 @@ if __FILE__ == $0
options[:verbose] ||= 0
options[:verbose] = options[:verbose] + 1
end
# Print an options summary.
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
end.parse!
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
......@@ -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_cluster = load_yaml_schema("#{dir}/schema-cluster.yaml")
schema_node = load_yaml_schema("#{dir}/schema-node.yaml")
r = true
r &= run_validator('global', global_hash, schema_global) #
global_hash["sites"].each do |site_uid, site|
next if sites and not sites.include?(site_uid)
r &= run_validator(site_uid, site, schema_site) #
site["clusters"].each do |cluster_uid, cluster|
next if clusters and not clusters.include?(cluster_uid)
r &= run_validator(cluster_uid, cluster, schema_cluster) #
cluster["nodes"].each do |node_uid, node|
r &= run_validator(node_uid, node, schema_node) #
end
end
end
......@@ -60,21 +60,21 @@ if __FILE__ == $0
OptionParser.new do |opts|
opts.banner = "Usage: yaml-input-schema-validator.rb [options]"
###
opts.separator ""
opts.separator "Filters:"
opts.on('-s', '--sites a,b,c', Array, 'Select site(s)',
"Default: all sites") do |s|
options[:sites] = s
end
opts.on('-c', '--clusters a,b,c', Array, 'Select clusters(s). Default: all') do |s|
options[:clusters] = s
end
# Print an options summary.
opts.on_tail("-h", "--help", "Show this message") do
puts opts
......@@ -86,4 +86,5 @@ if __FILE__ == $0
global_hash = load_yaml_file_hierarchy("#{dir}/../../input/grid5000/")
r = yaml_input_schema_validator(global_hash, options[:sites], options[:clusters])
puts 'OK' if r
exit r
end
......@@ -71,12 +71,13 @@ OptionParser.new do |opts|
opts.on("-d", "--diff [YAML filename]",
"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 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|
d = true if d == nil
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
###
......@@ -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]
ret = true
nodelist_properties = {} # ["ref"] : properties from the reference-repo
# ["oar"] : properties from the OAR server
# ["diff"] : diff between "ref" and "oar"
......@@ -153,8 +156,8 @@ nodelist_properties = {} # ["ref"] : properties from the reference-repo
nodelist_properties["ref"] = {}
global_hash = load_yaml_file_hierarchy('../../input/grid5000/')
options[:sites].each { |site_uid|
nodelist_properties["ref"][site_uid] = get_nodelist_properties(site_uid, global_hash["sites"][site_uid])
options[:sites].each { |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"])
......@@ -193,10 +196,15 @@ if options[:diff]
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
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" if missings_dead.size > 0 && options[:check]
if missings_alive.size > 0
puts "*** Error: The following nodes exist in the OAR server but are missing in the reference-repo: #{missings_alive.join(', ')}.\n"
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
#
......@@ -210,7 +218,7 @@ if options[:diff]
#
header = false
prev_diff = {}
nodelist_properties["diff"] = {}
properties_keys["oar"] = Set.new []
......@@ -226,7 +234,7 @@ if options[:diff]
nodelist_properties["diff"][site_uid][node_uid] = node_properties_ref.select { |key, value| diff_keys.include?(key) }
# 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]
when 1
puts "#{node_uid}:#{info}" if info != ""
......@@ -238,7 +246,7 @@ if options[:diff]
header = true
puts "Output format: ['~', 'key', 'old value', 'new value']"
end
if diff.size==0
if diff.size == 0
puts " #{node_uid}: OK#{info}"
elsif diff == prev_diff
puts " #{node_uid}:#{info} same modifications as above"
......@@ -252,8 +260,10 @@ if options[:diff]
puts "#{node_uid}:#{info}" if info != ""
puts JSON.pretty_generate({node_uid => {"old values" => node_properties_oar, "new values" => node_properties_ref}})
end
if diff.size != 0
ret = false unless options[:exec] || options[:output]
end
}
}
# Get the list of property keys from the OAR scheduler (["oar"])
......@@ -267,17 +277,19 @@ if options[:diff]
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.
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
}
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
unknown_properties = properties_keys["oar"].keys.to_set - properties_keys["ref"].keys.to_set
ignore_keys.each { |key| unknown_properties.delete(key) }
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 "Hint: you can delete properties with 'oarproperty -d <property>' or add them to the ignore list in lib/lib-oar-properties.rb."
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 "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 # if options[:diff]
......@@ -286,8 +298,8 @@ end # if options[:diff]
#
if options[:output] || options[:exec]
opt = options[:diff] ? 'diff' : 'ref'
nodelist_properties[opt].each { |site_uid, site_properties|
nodelist_properties[opt].each { |site_uid, site_properties|
# Init
options[:output].is_a?(String) ? o = File.open(options[:output].gsub("%s", site_uid),'w') : o = $stdout.dup
ssh_cmd = []
......@@ -344,3 +356,5 @@ if options[:output] || options[:exec]
end
} # site loop
end # if options[:output] || options[:exec]
exit ret
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment