1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-27 03:21:29 +03:00

Bug #4030: Do not drop table group_pool in fsck

(cherry picked from commit 2929f05c895483e8d33d0286a057958dcda4c313)
This commit is contained in:
Carlos Martín 2015-10-09 12:42:55 +02:00
parent 9b4f9f6c4f
commit 7def22f7fb

View File

@ -300,56 +300,53 @@ EOT
log_time()
if !db_version[:is_slave]
@db.run "CREATE TABLE group_pool_new (oid INTEGER PRIMARY KEY, name VARCHAR(128), body MEDIUMTEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, UNIQUE(name));"
end
groups_fix = {}
@db.transaction do
@db.fetch("SELECT * from group_pool") do |row|
gid = row[:oid]
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
@db.fetch("SELECT oid,body from group_pool") do |row|
gid = row[:oid]
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
users_elem = doc.root.at_xpath("USERS")
users_elem.remove if !users_elem.nil?
users_elem = doc.root.at_xpath("USERS")
users_elem.remove if !users_elem.nil?
users_new_elem = doc.create_element("USERS")
doc.root.add_child(users_new_elem)
users_new_elem = doc.create_element("USERS")
doc.root.add_child(users_new_elem)
error_found = false
error_found = false
group[gid].each do |id|
id_elem = users_elem.at_xpath("ID[.=#{id}]")
group[gid].each do |id|
id_elem = users_elem.at_xpath("ID[.=#{id}]")
if id_elem.nil?
log_error("User #{id} is missing from Group #{gid} users id list", !db_version[:is_slave])
error_found = true
else
id_elem.remove
end
users_new_elem.add_child(doc.create_element("ID")).content = id.to_s
end
users_elem.xpath("ID").each do |id_elem|
log_error("User #{id_elem.text} is in Group #{gid} users id list, but it should not", !db_version[:is_slave])
if id_elem.nil?
log_error("User #{id} is missing from Group #{gid} users id list", !db_version[:is_slave])
error_found = true
else
id_elem.remove
end
row[:body] = doc.root.to_s
users_new_elem.add_child(doc.create_element("ID")).content = id.to_s
end
if !db_version[:is_slave]
# commit
@db[:group_pool_new].insert(row)
elsif error_found
log_msg("^ Group errors need to be fixed in the master OpenNebula")
end
users_elem.xpath("ID").each do |id_elem|
log_error("User #{id_elem.text} is in Group #{gid} users id list, but it should not", !db_version[:is_slave])
error_found = true
end
if error_found
groups_fix[row[:oid]] = doc.root.to_s
end
end
if !db_version[:is_slave]
# Rename table
@db.run("DROP TABLE group_pool")
@db.run("ALTER TABLE group_pool_new RENAME TO group_pool")
@db.transaction do
groups_fix.each do |id, body|
@db[:group_pool].where(:oid => id).update(
:body => body)
end
end
elsif !groups_fix.empty?
log_msg("^ Group errors need to be fixed in the master OpenNebula")
end
log_time()