From a419845a2fa3a5f3fea56b65e636e968f878bdb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 11 Jul 2016 12:54:24 +0200 Subject: [PATCH] Bug #4611: Fix missing zone_id in market after migration (cherry picked from commit 02494be37878492018bb8f130a46e400ead89e78) --- src/onedb/fsck.rb | 34 +++++++++++++++++++++------ src/onedb/shared/4.11.80_to_4.90.0.rb | 2 +- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/onedb/fsck.rb b/src/onedb/fsck.rb index a2f8e8e122..6a11699664 100644 --- a/src/onedb/fsck.rb +++ b/src/onedb/fsck.rb @@ -1355,16 +1355,18 @@ EOT @db.fetch("SELECT oid,body FROM marketplace_pool") do |row| market_id = row[:oid] - doc = Document.new(row[:body]) + doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks} - apps_elem = doc.root.elements.delete("MARKETPLACEAPPS") + apps_elem = doc.root.at_xpath("MARKETPLACEAPPS") + apps_elem.remove if !apps_elem.nil? - apps_new_elem = doc.root.add_element("MARKETPLACEAPPS") + apps_new_elem = doc.create_element("MARKETPLACEAPPS") + doc.root.add_child(apps_new_elem) error = false marketplace[market_id][:apps].each do |id| - id_elem = apps_elem.elements.delete("ID[.=#{id}]") + id_elem = apps_elem.at_xpath("ID[.=#{id}]") if id_elem.nil? error = true @@ -1372,12 +1374,14 @@ EOT log_error( "Marketplace App #{id} is missing from Marketplace #{market_id} "<< "app id list") + else + id_elem.remove end - apps_new_elem.add_element("ID").text = id.to_s + apps_new_elem.add_child(doc.create_element("ID")).content = id.to_s end - apps_elem.each_element("ID") do |id_elem| + apps_elem.xpath("ID").each do |id_elem| error = true log_error( @@ -1385,7 +1389,23 @@ EOT "app id list, but it should not") end - markets_fix[row[:oid]] = doc.root.to_s + zone_elem = doc.root.at_xpath("ZONE_ID") + + if (zone_elem.nil? || zone_elem.text == "-1") + error = true + + log_error("Marketplace #{market_id} has an invalid ZONE_ID. Will be set to 0") + + if (zone_elem.nil?) + zone_elem = doc.root.add_child(doc.create_element("ZONE_ID")) + end + + zone_elem.content = "0" + end + + if (error) + markets_fix[row[:oid]] = doc.root.to_s + end end if !db_version[:is_slave] diff --git a/src/onedb/shared/4.11.80_to_4.90.0.rb b/src/onedb/shared/4.11.80_to_4.90.0.rb index f4d3a336cf..83d08e5d08 100644 --- a/src/onedb/shared/4.11.80_to_4.90.0.rb +++ b/src/onedb/shared/4.11.80_to_4.90.0.rb @@ -178,7 +178,7 @@ module Migrator @db.run "CREATE TABLE marketplace_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body MEDIUMTEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER);" - @db.run "INSERT INTO marketplace_pool VALUES(0,'OpenNebula Public','000#{oneadmin_uname}#{oneadmin_gname}OpenNebula Public000111100100',0,0,1,1,1);" + @db.run "INSERT INTO marketplace_pool VALUES(0,'OpenNebula Public','000#{oneadmin_uname}#{oneadmin_gname}OpenNebula Public000111100100',0,0,1,1,1);" @db.run "INSERT INTO pool_control VALUES('marketplace_pool',99);"