From 6d131a85552f22135fe8a2719d0234e84c3db76e Mon Sep 17 00:00:00 2001
From: Lucas Nussbaum <lucas.nussbaum@loria.fr>
Date: Tue, 16 Apr 2019 20:52:48 +0200
Subject: [PATCH] [dev] OAR properties generator: unify DO= arguments with
 other generators

---
 Rakefile                          | 10 +++++-----
 lib/refrepo/gen/oar-properties.rb | 24 ++++++++++++------------
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/Rakefile b/Rakefile
index 0aa9d0c7eec..55e5823d34f 100644
--- a/Rakefile
+++ b/Rakefile
@@ -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="
diff --git a/lib/refrepo/gen/oar-properties.rb b/lib/refrepo/gen/oar-properties.rb
index 8ee98f0864f..0cc073348bf 100644
--- a/lib/refrepo/gen/oar-properties.rb
+++ b/lib/refrepo/gen/oar-properties.rb
@@ -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
-- 
GitLab