From 7396a8f68ebeac7a8b7fa7ab2f72c70cad578fc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 2 Feb 2016 11:54:09 +0100 Subject: [PATCH] Feature #4215: Add vrouter/vms/id to fsck --- src/onedb/fsck.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/onedb/fsck.rb b/src/onedb/fsck.rb index 715008c6ca..65b0c0c3bc 100644 --- a/src/onedb/fsck.rb +++ b/src/onedb/fsck.rb @@ -729,6 +729,7 @@ EOT counters[:host] = {} counters[:image] = {} counters[:vnet] = {} + counters[:vrouter] = {} # Initialize all the host counters to 0 @db.fetch("SELECT oid, name FROM host_pool") do |row| @@ -787,6 +788,15 @@ EOT log_time() + # Initialize all the vrouter counters to 0 + @db.fetch("SELECT oid FROM vrouter_pool") do |row| + counters[:vrouter][row[:oid]] = { + :vms => Set.new + } + end + + log_time() + vms_fix = {} # Aggregate information of the RUNNING vms @@ -863,6 +873,21 @@ EOT end end + # See if it's part of a Virtual Router + vrouter_e = vm_doc.root.at_xpath("TEMPLATE/VROUTER_ID") + + if !vrouter_e.nil? + vr_id = vrouter_e.text.to_i + counters_vrouter = counters[:vrouter][vr_id] + + if counters_vrouter.nil? + log_error("VM #{row[:oid]} is part of VRouter #{vr_id}, but "<< + "it does not exist", false) + else + counters_vrouter[:vms].add(row[:oid]) + end + end + # Host resources # Only states that add to Host resources consumption are @@ -975,6 +1000,7 @@ EOT ######################################################################## # Virtual Routers # + # VROUTER/VMS/ID ######################################################################## vrouters_fix = {} @@ -1043,6 +1069,43 @@ EOT end end end + + # re-do list of VM IDs + error = false + + counters_vrouter = counters[:vrouter][row[:oid]] + + vms_elem = vrouter_doc.root.at_xpath("VMS").remove + + vms_new_elem = vrouter_doc.create_element("VMS") + vrouter_doc.root.add_child(vms_new_elem) + + counters_vrouter[:vms].each do |id| + id_elem = vms_elem.at_xpath("ID[.=#{id}]") + + if id_elem.nil? + log_error( + "VM #{id} is missing from VRouter #{row[:oid]} VM id list") + + error = true + else + id_elem.remove + end + + vms_new_elem.add_child(vrouter_doc.create_element("ID")).content = id.to_s + end + + vms_elem.xpath("ID").each do |id_elem| + log_error( + "VM #{id_elem.text} is in VRouter #{row[:oid]} VM id list, "<< + "but it should not") + + error = true + end + + if (error) + vrouters_fix[row[:oid]] = vrouter_doc.root.to_s + end end @db.transaction do