Attention une mise à jour du serveur va être effectuée le lundi 17 mai entre 13h et 13h30. Cette mise à jour va générer une interruption du service de quelques minutes.

Commit 6d131a85 authored by Lucas Nussbaum's avatar Lucas Nussbaum

[dev] OAR properties generator: unify DO= arguments with other generators

parent 6130626a
Pipeline #74394 passed with stages
in 1 minute and 32 seconds
...@@ -125,7 +125,7 @@ namespace :gen do ...@@ -125,7 +125,7 @@ namespace :gen do
exit(ret) exit(ret)
end end
desc "Generate OAR properties -- parameters: [SITE={grenoble,...}] [CLUSTER={yeti,...}] [NODE={dahu-1,...}] DO={output,exec,diff} [VERBOSE={0,1,2,3}]" desc "Generate OAR properties -- parameters: [SITE={grenoble,...}] [CLUSTER={yeti,...}] [NODE={dahu-1,...}] DO={diff,print,update} [VERBOSE={0,1,2,3}]"
task "oar-properties" do task "oar-properties" do
require 'refrepo/gen/oar-properties' require 'refrepo/gen/oar-properties'
options = {} options = {}
...@@ -140,14 +140,14 @@ namespace :gen do ...@@ -140,14 +140,14 @@ namespace :gen do
options[:ssh] ||= {} options[:ssh] ||= {}
options[:ssh][:host] = ENV['OAR_SERVER'] options[:ssh][:host] = ENV['OAR_SERVER']
end end
options[:output] = false
options[:diff] = false options[:diff] = false
options[:exec] = false options[:print] = false
options[:update] = false
if ENV['DO'] if ENV['DO']
ENV['DO'].split(',').each do |t| ENV['DO'].split(',').each do |t|
options[:diff] = true if t == 'diff' options[:diff] = true if t == 'diff'
options[:output] = true if t == 'output' options[:print] = true if t == 'print'
options[:exec] = true if t == 'exec' options[:update] = true if t == 'update'
end end
else else
puts "You must specify something to do using DO=" puts "You must specify something to do using DO="
......
...@@ -629,7 +629,7 @@ def generate_oar_properties(options) ...@@ -629,7 +629,7 @@ def generate_oar_properties(options)
if missings_alive.size > 0 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" 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] ret = false unless options[:update] || options[:print]
end end
skipped_nodes = [] skipped_nodes = []
...@@ -684,7 +684,7 @@ def generate_oar_properties(options) ...@@ -684,7 +684,7 @@ def generate_oar_properties(options)
puts JSON.pretty_generate(key => { 'old values' => properties_oar, 'new values' => properties_ref }) puts JSON.pretty_generate(key => { 'old values' => properties_oar, 'new values' => properties_ref })
end end
if diff.size != 0 if diff.size != 0
ret = false unless options[:exec] || options[:output] ret = false unless options[:update] || options[:print]
end end
end end
end end
...@@ -700,7 +700,7 @@ def generate_oar_properties(options) ...@@ -700,7 +700,7 @@ def generate_oar_properties(options)
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 #{site_uid} server and this script uses '#{v_ref}' for this property." puts "Error: the OAR property '#{k}' is a '#{v_oar}' on the #{site_uid} server and this script uses '#{v_ref}' for this property."
ret = false unless options[:exec] || options[:output] ret = false unless options[:update] || options[:print]
end end
end end
...@@ -715,19 +715,19 @@ def generate_oar_properties(options) ...@@ -715,19 +715,19 @@ def generate_oar_properties(options)
if options[:verbose] && unknown_properties.size > 0 if options[:verbose] && unknown_properties.size > 0
puts "Properties existing on the #{site_uid} server but not managed/known by the generator: #{unknown_properties.to_a.join(', ')}." puts "Properties existing on the #{site_uid} 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] ret = false unless options[:update] || options[:print]
end end
puts "Skipped retired nodes: #{skipped_nodes}" if skipped_nodes.any? puts "Skipped retired nodes: #{skipped_nodes}" if skipped_nodes.any?
end # if options[:diff] end # if options[:diff]
end end
# Build and execute commands # Build and execute commands
if options[:output] || options[:exec] if options[:print] || options[:update]
skipped_nodes = [] unless options[:diff] skipped_nodes = [] unless options[:diff]
opt = options[:diff] ? 'diff' : 'ref' opt = options[:diff] ? 'diff' : 'ref'
properties[opt].each do |site_uid, site_properties| properties[opt].each do |site_uid, site_properties|
options[:output].is_a?(String) ? o = File.open(options[:output].gsub('%s', site_uid), 'w') : o = $stdout.dup options[:print].is_a?(String) ? o = File.open(options[:print].gsub('%s', site_uid), 'w') : o = $stdout.dup
ssh_cmd = [] ssh_cmd = []
cmd = [] cmd = []
...@@ -767,8 +767,8 @@ def generate_oar_properties(options) ...@@ -767,8 +767,8 @@ def generate_oar_properties(options)
cmd << oarcmd_set_node_properties(node_address, node_properties) cmd << oarcmd_set_node_properties(node_address, node_properties)
cmd << oarcmd_separator cmd << oarcmd_separator
end end
ssh_cmd += cmd if options[:exec] ssh_cmd += cmd if options[:update]
o.write(cmd.join('')) if options[:output] o.write(cmd.join('')) if options[:print]
cmd = [] cmd = []
end end
...@@ -792,14 +792,14 @@ def generate_oar_properties(options) ...@@ -792,14 +792,14 @@ def generate_oar_properties(options)
cmd << oarcmd_separator cmd << oarcmd_separator
end end
ssh_cmd += cmd if options[:exec] ssh_cmd += cmd if options[:update]
o.write(cmd.join('')) if options[:output] o.write(cmd.join('')) if options[:print]
cmd = [] cmd = []
end end
o.close o.close
# Execute commands # Execute commands
if options[:exec] if options[:update]
printf 'Apply changes to the OAR server ' + options[:ssh][:host].gsub('%s', site_uid) + ' ? (y/N) ' printf 'Apply changes to the OAR server ' + options[:ssh][:host].gsub('%s', site_uid) + ' ? (y/N) '
prompt = STDIN.gets.chomp prompt = STDIN.gets.chomp
ssh_exec(ssh_cmd, options, site_uid) if prompt.downcase == 'y' ssh_exec(ssh_cmd, options, site_uid) if prompt.downcase == 'y'
...@@ -809,7 +809,7 @@ def generate_oar_properties(options) ...@@ -809,7 +809,7 @@ def generate_oar_properties(options)
if skipped_nodes.any? if skipped_nodes.any?
puts "Skipped retired nodes: #{skipped_nodes}" unless options[:diff] puts "Skipped retired nodes: #{skipped_nodes}" unless options[:diff]
end end
end # if options[:output] || options[:exec] end # if options[:print] || options[:update]
return ret return ret
end end
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