From 356d5381efb82e8de3858d3c317ff595f3d44dde Mon Sep 17 00:00:00 2001
From: Lucas Nussbaum <lucas.nussbaum@inria.fr>
Date: Tue, 4 Mar 2025 09:58:12 +0100
Subject: [PATCH 1/3] [dev] always use the first node to generate descriptions

Some clusters are heterogeneous. We sort nodes before picking the first
node to avoid cases where we would use different nodes to generate
descriptions. Apparently different ruby versions sort hashes
differently.
---
 lib/refrepo/gen/reference-api.rb | 3 ++-
 lib/refrepo/utils.rb             | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/refrepo/gen/reference-api.rb b/lib/refrepo/gen/reference-api.rb
index 52b4077495c..e6361053cf1 100644
--- a/lib/refrepo/gen/reference-api.rb
+++ b/lib/refrepo/gen/reference-api.rb
@@ -210,7 +210,8 @@ def generate_reference_api
 
       # Add nodes details to cluster description
       cluster['nodes_count'] = cluster['nodes'].length
-      cluster['nodes_description'] = gen_node_description(cluster['nodes'].values.first)
+      first_node = cluster['nodes'].values.select { |x| not x['status'] == 'retired' }.sort_by { |x| split_cluster_node(x['uid']) }.first # use first non-retired node
+      cluster['nodes_description'] = gen_node_description(first_node)
 
       # Write cluster info w/o nodes entries
       write_json(cluster_path.join("#{cluster_uid}.json"),
diff --git a/lib/refrepo/utils.rb b/lib/refrepo/utils.rb
index aa7c1f5e2fc..a8a3620faf8 100644
--- a/lib/refrepo/utils.rb
+++ b/lib/refrepo/utils.rb
@@ -52,3 +52,7 @@ class Hash
     h2
   end
 end
+
+def split_cluster_node(k)
+  [k[/(\D+)/, 1], k[/(\d+)/, 1].to_i, k[/-(\d+)/, 1].to_i]
+end
-- 
GitLab


From 6c23f7341a7ddee548710e922fdeb8bda3441f11 Mon Sep 17 00:00:00 2001
From: Lucas Nussbaum <lucas.nussbaum@inria.fr>
Date: Tue, 4 Mar 2025 10:51:17 +0100
Subject: [PATCH 2/3] [dev] use split_cluster_node everywhere relevant to avoid
 duplicating this logic

---
 lib/refrepo/gen/puppet/clusters.rb                  | 4 ++--
 lib/refrepo/gen/puppet/oarsub-simplifier-aliases.rb | 2 +-
 lib/refrepo/gen/puppet/webfish.rb                   | 4 ++--
 lib/refrepo/gen/wiki/generators/site_hardware.rb    | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/lib/refrepo/gen/puppet/clusters.rb b/lib/refrepo/gen/puppet/clusters.rb
index d75dfcf55f1..692f3240011 100644
--- a/lib/refrepo/gen/puppet/clusters.rb
+++ b/lib/refrepo/gen/puppet/clusters.rb
@@ -17,7 +17,7 @@ def generate_puppet_clusters(options)
             puts "Add #{s_uid}"
             hiera[s_uid] = {}
         end
-        s_hash['clusters'].sort_by{|c_uid, _c_hash| [c_uid[/(\D+)/, 1], c_uid[/(\d+)/, 1].to_i]}.each do |c_uid, c_hash|
+        s_hash['clusters'].sort_by{|c_uid, _c_hash| split_cluster_node(c_uid) }.each do |c_uid, c_hash|
             if ! hiera[s_uid].key? c_uid
                 puts "  Add #{s_uid}"
                 hiera[s_uid][c_uid] = {}
@@ -46,4 +46,4 @@ def generate_puppet_clusters(options)
 
     outfile = File.open("#{options[:conf_dir]}clusters.yaml", "w")
     outfile.write({'grid5000::clusters' => hiera}.to_yaml)
-end
\ No newline at end of file
+end
diff --git a/lib/refrepo/gen/puppet/oarsub-simplifier-aliases.rb b/lib/refrepo/gen/puppet/oarsub-simplifier-aliases.rb
index 29a6d27be06..c50c8fe6faa 100644
--- a/lib/refrepo/gen/puppet/oarsub-simplifier-aliases.rb
+++ b/lib/refrepo/gen/puppet/oarsub-simplifier-aliases.rb
@@ -61,7 +61,7 @@ def generate_all_sites_aliases
       aliases[site][cluster] = "cluster='#{cluster}'"
       aliases[site]["#{cluster}-%d"] = "host='#{cluster}-%d.#{site}.grid5000.fr'"
     end
-    aliases[site] = aliases[site].sort_by { |cluster, _| [cluster[/(\D+)/, 1], cluster[/(\d+)/, 1].to_i] }.to_h
+    aliases[site] = aliases[site].sort_by { |cluster, _| split_cluster_node(cluster) }.to_h
   end
 
   aliases = aliases.sort_by { |site, _| site }.to_h
diff --git a/lib/refrepo/gen/puppet/webfish.rb b/lib/refrepo/gen/puppet/webfish.rb
index ad234f0295a..7fdf0ed813d 100644
--- a/lib/refrepo/gen/puppet/webfish.rb
+++ b/lib/refrepo/gen/puppet/webfish.rb
@@ -101,7 +101,7 @@ def gen_json_files(allBmc, options)
     dir = "#{options[:output_dir]}/platforms/production/modules/generated/files/grid5000/webfish"
     checks_dir_creation(dir)
     allBmc.sort_by{ |s_site, _d_site| s_site}.each do |s_site, _d_array|
-        actualFile = allBmc[s_site].sort_by{|k, _| [k[/(\D+)/, 1], k[/(\d+)/, 1].to_i, k[/-(\d+)/, 1].to_i]}.to_h
+        actualFile = allBmc[s_site].sort_by{|k, _| split_cluster_node(k) }.to_h
         siteLocation = dir + "/" + s_site
         checks_dir_creation(siteLocation)
         fileLocation =  siteLocation + "/webfish.json"
@@ -109,4 +109,4 @@ def gen_json_files(allBmc, options)
             f.write(JSON.pretty_generate(actualFile))
         end
     end
-end
\ No newline at end of file
+end
diff --git a/lib/refrepo/gen/wiki/generators/site_hardware.rb b/lib/refrepo/gen/wiki/generators/site_hardware.rb
index b921ac24a70..12ec69699e9 100644
--- a/lib/refrepo/gen/wiki/generators/site_hardware.rb
+++ b/lib/refrepo/gen/wiki/generators/site_hardware.rb
@@ -189,7 +189,7 @@ class SiteHardwareGenerator < WikiGenerator
       site_accelerators += cluster_hash.select { |_k, v| v['accelerators'] != '' }.count
     }
 
-    hardware[site].sort_by{|cluster_uid, _cluster_hash| [cluster_uid[/(\D+)/, 1], cluster_uid[/(\d+)/, 1].to_i]}.to_h.each { |cluster_uid, cluster_hash|
+    hardware[site].sort_by{|cluster_uid, _cluster_hash| split_cluster_node(cluster_uid) }.to_h.each { |cluster_uid, cluster_hash|
       cluster_nodes = cluster_hash.keys.flatten.count
       queue = cluster_hash.map { |_k, v| v['queue']}.first
       access_conditions = []
@@ -253,7 +253,7 @@ class SiteHardwareGenerator < WikiGenerator
       else
         text_data << "\n= Clusters in the #{queue} queue ="
       end
-      clusters.sort_by{|cluster_uid, _cluster_hash| [cluster_uid[/(\D+)/, 1], cluster_uid[/(\d+)/, 1].to_i]}.to_h.each { |cluster_uid, cluster_hash|
+      clusters.sort_by{|cluster_uid, _cluster_hash| split_cluster_node(cluster_uid) }.to_h.each { |cluster_uid, cluster_hash|
         subclusters = cluster_hash.keys.count != 1
         cluster_nodes = cluster_hash.keys.flatten.count
         cluster_cpus = cluster_hash.map { |k, v| k.count * v['cpus_per_node'] }.reduce(:+)
-- 
GitLab


From 7c81037e53d51700f88cd624fe6e084c82267898 Mon Sep 17 00:00:00 2001
From: Lucas Nussbaum <lucas.nussbaum@inria.fr>
Date: Tue, 4 Mar 2025 11:15:05 +0100
Subject: [PATCH 3/3] [dev] Improve extraction to handle case of gros-1 and
 gros1-18 for example

---
 lib/refrepo/utils.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/refrepo/utils.rb b/lib/refrepo/utils.rb
index a8a3620faf8..772ed3b3f39 100644
--- a/lib/refrepo/utils.rb
+++ b/lib/refrepo/utils.rb
@@ -54,5 +54,5 @@ class Hash
 end
 
 def split_cluster_node(k)
-  [k[/(\D+)/, 1], k[/(\d+)/, 1].to_i, k[/-(\d+)/, 1].to_i]
+  [k[/([a-z]+)/, 1], k[/[a-z](\d+)/, 1].to_i, k[/-(\d+)/, 1].to_i]
 end
-- 
GitLab