Revision 90496a0a

View differences:

src/onedb/fsck.rb
136 136
        init_log_time()
137 137

  
138 138
        @errors = 0
139
        @repaired_errors = 0
140
        @unrepaired_errors = 0
141

  
139 142
        puts
140 143

  
141 144
        db_version = read_db_version()
......
175 178
            end
176 179

  
177 180
            if ( max_oid > control_oid )
178
                log_error("pool_control for table #{table} has last_oid #{control_oid}, but it is #{max_oid}")
181
                msg = "pool_control for table #{table} has last_oid #{control_oid}, but it is #{max_oid}"
179 182

  
180 183
                if control_oid != -1
181 184
                    if db_version[:is_slave] && federated_tables.include?(table)
182
                        log_error("^ Needs to be fixed in the master OpenNebula")
185
                        log_error(msg, false)
186
                        log_msg("^ Needs to be fixed in the master OpenNebula")
183 187
                    else
188
                        log_error(msg)
184 189
                        @db.run("UPDATE pool_control SET last_oid=#{max_oid} WHERE tablename='#{table}'")
185 190
                    end
186 191
                else
......
221 226
            user_gids = Set.new
222 227

  
223 228
            if group[gid].nil?
224
                log_error("User #{row[:oid]} has primary group #{gid}, but it does not exist")
229
                log_error("User #{row[:oid]} has primary group #{gid}, but it does not exist", !db_version[:is_slave])
225 230

  
226 231
                user_gid = 1
227 232

  
......
247 252
            }
248 253

  
249 254
            if !user_gids.include?(user_gid)
250
                log_error("User #{row[:oid]} does not have his primary group #{user_gid} in the list of secondary groups")
255
                log_error("User #{row[:oid]} does not have his primary group #{user_gid} in the list of secondary groups", !db_version[:is_slave])
251 256

  
252 257
                doc.root.xpath("GROUPS").each { |e|
253 258
                    e.add_child(doc.create_element("ID")).content = user_gid.to_s
......
260 265

  
261 266
            user_gids.each do |secondary_gid|
262 267
                if group[secondary_gid].nil?
263
                    log_error("User #{row[:oid]} has secondary group #{secondary_gid}, but it does not exist")
268
                    log_error("User #{row[:oid]} has secondary group #{secondary_gid}, but it does not exist", !db_version[:is_slave])
264 269

  
265 270
                    doc.root.xpath("GROUPS").each { |e|
266 271
                        e.xpath("ID[.=#{secondary_gid}]").each{|x| x.remove}
......
275 280
            if gid != row[:gid]
276 281
                log_error(
277 282
                    "User #{row[:oid]} is in group #{gid}, but the DB "<<
278
                    "table has GID column #{row[:gid]}")
283
                    "table has GID column #{row[:gid]}", !db_version[:is_slave])
279 284

  
280 285
                users_fix[row[:oid]] = {:body => doc.root.to_s, :gid => user_gid}
281 286
            end
......
290 295
                end
291 296
            end
292 297
        elsif !users_fix.empty?
293
            log_error("^ User errors need to be fixed in the master OpenNebula")
298
            log_msg("^ User errors need to be fixed in the master OpenNebula")
294 299
        end
295 300

  
296 301
        log_time()
......
316 321
                    id_elem = users_elem.at_xpath("ID[.=#{id}]")
317 322

  
318 323
                    if id_elem.nil?
319
                        log_error("User #{id} is missing from Group #{gid} users id list")
324
                        log_error("User #{id} is missing from Group #{gid} users id list", !db_version[:is_slave])
320 325
                        error_found = true
321 326
                    else
322 327
                        id_elem.remove
......
326 331
                end
327 332

  
328 333
                users_elem.xpath("ID").each do |id_elem|
329
                    log_error("User #{id_elem.text} is in Group #{gid} users id list, but it should not")
334
                    log_error("User #{id_elem.text} is in Group #{gid} users id list, but it should not", !db_version[:is_slave])
330 335
                    error_found = true
331 336
                end
332 337

  
......
336 341
                    # commit
337 342
                    @db[:group_pool_new].insert(row)
338 343
                elsif error_found
339
                    log_error("^ Group errors need to be fixed in the master OpenNebula")
344
                    log_msg("^ Group errors need to be fixed in the master OpenNebula")
340 345
                end
341 346
            end
342 347
        end
......
650 655
                        "    #{doc.root.get_text('SOURCE')}\n"<<
651 656
                        "  * The DB entry can be then deleted with the command:\n"<<
652 657
                        "    DELETE FROM image_pool WHERE oid=#{row[:oid]};\n"<<
653
                        "  * Run fsck again.\n")
658
                        "  * Run fsck again.\n", false)
654 659
                else
655 660
                    if ds_name != ds_entry[:name]
656 661
                        log_error("Image #{row[:oid]} has a wrong name for datastore #{ds_id}, #{ds_name}. It will be changed to #{ds_entry[:name]}")
......
799 804

  
800 805
                if counters[:image][img_id].nil?
801 806
                    log_error("VM #{row[:oid]} is using Image #{img_id}, but "<<
802
                        "it does not exist")
807
                        "it does not exist", false)
803 808
                else
804 809
                    counters[:image][img_id][:vms].add(row[:oid])
805 810
                end
......
815 820
                if !net_id.nil?
816 821
                    if counters[:vnet][net_id].nil?
817 822
                        log_error("VM #{row[:oid]} is using VNet #{net_id}, "<<
818
                            "but it does not exist")
823
                            "but it does not exist", false)
819 824
                    else
820 825
                        mac = nic.at_xpath("MAC").nil? ? nil : nic.at_xpath("MAC").text
821 826

  
......
824 829
                        if ar_id_e.nil?
825 830
                            if !counters[:vnet][net_id][:no_ar_leases][mac_s_to_i(mac)].nil?
826 831
                                log_error("VNet has more than one VM with the same MAC address (#{mac}). "<<
827
                                    "FSCK can't handle this, and consistency is not guaranteed")
832
                                    "FSCK can't handle this, and consistency is not guaranteed", false)
828 833
                            end
829 834

  
830 835
                            counters[:vnet][net_id][:no_ar_leases][mac_s_to_i(mac)] = {
......
841 846

  
842 847
                            if counters[:vnet][net_id][:ar_leases][ar_id].nil?
843 848
                                log_error("VM #{row[:oid]} is using VNet #{net_id}, AR #{ar_id}, "<<
844
                                    "but the AR does not exist")
849
                                    "but the AR does not exist", false)
845 850
                            else
846 851
                                counters[:vnet][net_id][:ar_leases][ar_id][mac_s_to_i(mac)] = {
847 852
                                    :ip         => nic.at_xpath("IP").nil? ? nil : nic.at_xpath("IP").text,
......
885 890

  
886 891
            if counters_host.nil?
887 892
                log_error("VM #{row[:oid]} is using Host #{hid}, "<<
888
                    "but it does not exist")
893
                    "but it does not exist", false)
889 894
            else
890 895
                if counters_host[:name] != hostname
891 896
                    log_error("VM #{row[:oid]} has a wrong hostname for "<<
......
1169 1174
                        log_error(
1170 1175
                            "VNet #{row[:oid]} is using parent "<<
1171 1176
                            "VNet #{parent_vnet}, AR #{parent_ar}, "<<
1172
                            "but the AR does not exist")
1177
                            "but the AR does not exist", false)
1173 1178
                    end
1174 1179

  
1175 1180
                    # MAC
......
1437 1442
                                    "#{lease_obj} #{lease_oid}. #{key.to_s.upcase} "<<
1438 1443
                                    "does not match: "<<
1439 1444
                                    "#{counter_lease[key]} != #{lease[key]}. "<<
1440
                                    "This can't be fixed")
1445
                                    "This can't be fixed", false)
1441 1446
                                end
1442 1447
                            end
1443 1448
                        end
......
1493 1498

  
1494 1499
            counter_no_ar.each do |mac, counter_lease|
1495 1500
                log_error("VM #{counter_lease[:vm]} has a lease from "<<
1496
                    "VNet #{oid}, but it could not be matched to any AR")
1501
                    "VNet #{oid}, but it could not be matched to any AR", false)
1497 1502
            end
1498 1503

  
1499 1504
            row[:body] = doc.root.to_s
......
1611 1616
        return true
1612 1617
    end
1613 1618

  
1614
    def log_error(message)
1619
    def log_error(message, repaired=true)
1615 1620
        @errors += 1
1616 1621

  
1622
        if repaired
1623
            @repaired_errors += 1
1624
        else
1625
            @unrepaired_errors += 1
1626
        end
1627

  
1628
        if !repaired
1629
            message = "[UNREPAIRED] " + message
1630
        end
1631

  
1617 1632
        log_msg(message)
1618 1633
    end
1619 1634

  
......
1629 1644
    def log_total_errors()
1630 1645
        puts
1631 1646
        log_msg "Total errors found: #{@errors}"
1647
        log_msg "Total errors repaired: #{@repaired_errors}"
1648
        log_msg "Total errors unrepaired: #{@unrepaired_errors}"
1649

  
1632 1650
        puts "A copy of this output was stored in #{LOG}"
1633 1651
    end
1634 1652

  

Also available in: Unified diff