diff --git a/src/onedb/fsck.rb b/src/onedb/fsck.rb index bb69087932..f4d1bb3273 100644 --- a/src/onedb/fsck.rb +++ b/src/onedb/fsck.rb @@ -150,6 +150,36 @@ EOT true end + def read_config + begin + require 'augeas' + rescue Gem::LoadError + STDERR.puts( + 'Augeas gem is not installed, run `gem install ' \ + 'opennebula-augeas` to install it' + ) + exit(-1) + end + + work_file_dir = File.dirname(ONED_CONF) + work_file_name = File.basename(ONED_CONF) + + aug = Augeas.create(:no_modl_autoload => true, + :no_load => true, + :root => work_file_dir, + :loadpath => ONED_CONF) + + aug.clear_transforms + aug.transform(:lens => 'Oned.lns', :incl => work_file_name) + aug.context = "/files/#{work_file_name}" + aug.load + + @zone_id = aug.get('FEDERATION/ZONE_ID').to_i + rescue StandardError => e + STDERR.puts "Unable to parse oned.conf: #{e}" + exit(-1) + end + ######################################################################## # Acl ######################################################################## diff --git a/src/onedb/fsck/image.rb b/src/onedb/fsck/image.rb index 8e82bef1a1..310fc8011d 100644 --- a/src/onedb/fsck/image.rb +++ b/src/onedb/fsck/image.rb @@ -85,12 +85,12 @@ module OneDBFsck end # DATA: CHECK: Check number of clones - doc.root.xpath("CLONING_OPS") { |e| - if e.text != n_cloning_ops.to_s - log_error("Image #{oid} CLONING_OPS has #{e.text} \tis\t#{n_cloning_ops}") - e.text = n_cloning_ops - end - } + cloning_ops = doc.root.at_xpath('CLONING_OPS') + + if cloning_ops.text != n_cloning_ops.to_s + log_error("Image #{oid} CLONING_OPS has #{cloning_ops.text} \tis\t#{n_cloning_ops}") + cloning_ops.content = n_cloning_ops + end # re-do list of Images cloning this one clones_elem = doc.root.xpath("CLONES").remove diff --git a/src/onedb/fsck/marketplaceapp.rb b/src/onedb/fsck/marketplaceapp.rb index 9957d0367a..3bead9d3bc 100644 --- a/src/onedb/fsck/marketplaceapp.rb +++ b/src/onedb/fsck/marketplaceapp.rb @@ -27,16 +27,21 @@ module OneDBFsck market_id = doc.root.xpath('MARKETPLACE_ID').text.to_i market_name = doc.root.xpath('MARKETPLACE').text - #################################################################### - # DATA: TODO, BUG: this code will only work for a standalone oned. - # In a federation, the image ID will refer to a different image - # in each zone - #################################################################### + if doc.root.xpath('STATE').text.to_i == 2 # LOCKED + # Note: This code will only function in the zone, where the DB was created + # It may fail if the DB is transfered to a different zones + origin_id = doc.root.xpath('ORIGIN_ID').text.to_i + app_zone = doc.root.xpath('ZONE_ID').text.to_i - # DATA: get image origin id. Does it work? - origin_id = doc.root.xpath('ORIGIN_ID').text.to_i - if origin_id >= 0 && doc.root.xpath('STATE').text.to_i == 2 # LOCKED - counters[:image][origin_id][:app_clones].add(row[:oid]) + if origin_id >= 0 && app_zone == @zone_id && !counters[:image][origin_id].nil? + counters[:image][origin_id][:app_clones].add(row[:oid]) + + log_error("Marketplace App #{row[:oid]} is in locked state. "<< + "The App is probably unusable and needs to be deleted or manually fixed:\n"<< + " * Check the App data in the MarketPlace and "<< + "set state to 1 (READY) by executing `onedb update-body marketplaceapp --id #{row[:oid]}`", + false) + end end error = fix_permissions('MARKETPLACEAPP', row[:oid], doc) diff --git a/src/onedb/onedb.rb b/src/onedb/onedb.rb index f00a70a1b7..26f50042bd 100644 --- a/src/onedb/onedb.rb +++ b/src/onedb/onedb.rb @@ -479,6 +479,8 @@ class OneDB time0 = Time.now + @backend.read_config + result = @backend.fsck if !result