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
exit(ret)
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
require 'refrepo/gen/oar-properties'
options = {}
......@@ -140,14 +140,14 @@ namespace :gen do
options[:ssh] ||= {}
options[:ssh][:host] = ENV['OAR_SERVER']
end
options[:output] = false
options[:diff] = false
options[:exec] = false
options[:print] = false
options[:update] = false
if ENV['DO']
ENV['DO'].split(',').each do |t|
options[:diff] = true if t == 'diff'
options[:output] = true if t == 'output'
options[:exec] = true if t == 'exec'
options[:print] = true if t == 'print'
options[:update] = true if t == 'update'
end
else
puts "You must specify something to do using DO="
......
......@@ -629,7 +629,7 @@ def generate_oar_properties(options)
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]
ret = false unless options[:update] || options[:print]
end
skipped_nodes = []
......@@ -684,7 +684,7 @@ def generate_oar_properties(options)
puts JSON.pretty_generate(key => { 'old values' => properties_oar, 'new values' => properties_ref })
end
if diff.size != 0
ret = false unless options[:exec] || options[:output]
ret = false unless options[:update] || options[:print]
end
end
end
......@@ -700,7 +700,7 @@ def generate_oar_properties(options)
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 #{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
......@@ -715,19 +715,19 @@ def generate_oar_properties(options)
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 "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
puts "Skipped retired nodes: #{skipped_nodes}" if skipped_nodes.any?
end # if options[:diff]
end
# Build and execute commands
if options[:output] || options[:exec]
if options[:print] || options[:update]
skipped_nodes = [] unless options[:diff]
opt = options[:diff] ? 'diff' : 'ref'
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 = []
cmd = []
......@@ -767,8 +767,8 @@ def generate_oar_properties(options)
cmd << oarcmd_set_node_properties(node_address, node_properties)
cmd << oarcmd_separator
end
ssh_cmd += cmd if options[:exec]
o.write(cmd.join('')) if options[:output]
ssh_cmd += cmd if options[:update]
o.write(cmd.join('')) if options[:print]
cmd = []
end
......@@ -792,14 +792,14 @@ def generate_oar_properties(options)
cmd << oarcmd_separator
end
ssh_cmd += cmd if options[:exec]
o.write(cmd.join('')) if options[:output]
ssh_cmd += cmd if options[:update]
o.write(cmd.join('')) if options[:print]
cmd = []
end
o.close
# Execute commands
if options[:exec]
if options[:update]
printf 'Apply changes to the OAR server ' + options[:ssh][:host].gsub('%s', site_uid) + ' ? (y/N) '
prompt = STDIN.gets.chomp
ssh_exec(ssh_cmd, options, site_uid) if prompt.downcase == 'y'
......@@ -809,7 +809,7 @@ def generate_oar_properties(options)
if skipped_nodes.any?
puts "Skipped retired nodes: #{skipped_nodes}" unless options[:diff]
end
end # if options[:output] || options[:exec]
end # if options[:print] || options[:update]
return ret
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