Red Hat Satellite 6 Upgrade Fails with error "rake aborted! NoMethodError: undefined method `first' for nil:NilClass".

Solution Verified - Updated

Environment

  • Red Hat Satellite 6.2.x and above

Issue

  • Satellite upgrade fails due to below error:

    rake aborted! NoMethodError: undefined method 'first' for nil:NilClass
    
  • After applying the audit patch from below resolution, the upgrade fails again with the following error:

    rake aborted! Unable to create bookmark: Name has already been taken
    

Resolution

For Red Hat Satellite 6.2:

 # cd /usr/share/foreman #Go to foreman directory
 # cp db/seeds.rb db/seeds.rb.bak  #Take a backup of affected files:
 # patch -p1 < audit-6.2-patch.txt #Download the attached `audit-6.2.patch` in the current directory and apply the patch
 # foreman-maintain upgrade run --target-version 6.3 #Re-run satellite upgrade

For Red Hat Satellite 6.3:

# cd /usr/share/foreman #Go to foreman directory
# cp lib/seed_helper.rb lib/seed_helper.rb.bak #Take a backup of affected files
# patch -p1 < audit-6.3-patch.txt #Download the attached `audit-6.3.patch` in the current directory and apply the patch
# foreman-maintain upgrade run --target-version 6.4 #Re-run satellite upgrade

For Red Hat Satellite 6.4, 6.5 and 6.6:

   # cd /usr/share/foreman #Go to foreman directory
   # cp lib/seed_helper.rb lib/seed_helper.rb.bak #Take a backup of affected files
   # patch -p1 < audit-6.4_6.5_6.6-patch.txt #Download the attached `audit-6.4_6.5_6.6-patch.txt` in the current directory and apply the patch
   # satellite-maintain upgrade run --target-version <Satellite Target Version> #Re-run satellite upgrade
  • You can also re-run the satellite upgrade via "satellite-installer" command:
# satellite-installer --scenario satellite --upgrade
  • Note that "satellite-maintain" and "foreman-maintain" run more tests in the pre-upgrade phase, so these are the preferred methods

Bookmark Creation error after applying the patch:

# echo 'Bookmark.find_by_name("list hypervisors").destroy' | foreman-rake console #Remove the default subscription bookmarks
# echo 'Bookmark.find_by_name("future").destroy' | foreman-rake console
# echo 'Bookmark.find_by_name("expiring soon").destroy' | foreman-rake console
# foreman-rake db:seed --trace #Run db:seed to recreate the default subscription bookmarks
# satellite-maintain upgrade run --target-version <Satellite Target Version> #Re-run satellite upgrade

For more KB articles/solutions related to Red Hat Satellite 6.x Installation/Upgrade/Update Issues, please refer to the Red Hat Satellite Consolidated Troubleshooting Article for Red Hat Satellite 6.x Installation/Upgrade/Update Issues.

Root Cause

  • Several audits related to bookmark records are corrupt.
  • The corrupted bookmark might remain after applying the patch, so removing it and then recreation by running db:seed could help

Diagnostic Steps

  • Satellite upgrade fails with error rake aborted! NoMethodError: undefined method 'first' for nil:NilClass

    • There is a known issue in bookmark related audit records, reported in This content is not included.Bugzilla 1543316

    • Observed the following traceback in the /var/log/foreman/foreman-installer/satellite.log:

    • On Red Hat Satellite 6.2:

      Upgrade Step: db_seed...
       rake aborted!
       NoMethodError: undefined method `first' for nil:NilClass
       /usr/share/foreman/db/seeds.rb:25:in `block (2 levels) in audit_modified?'
       /usr/share/foreman/db/seeds.rb:23:in `each'
       /usr/share/foreman/db/seeds.rb:23:in `all?'
       /usr/share/foreman/db/seeds.rb:23:in `block in audit_modified?'
       /opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/relation/query_methods.rb:238:in `block in select'
       /opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/relation/query_methods.rb:238:in `select'
       /opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/relation/query_methods.rb:238:in `select'
       /usr/share/foreman/db/seeds.rb:22:in `audit_modified?'
      
    • On Red Hat Satellite 6.3:

      Seeding /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.4.5.64.2/db/seeds.d/108-subcription-bookmarks.rb 
      Seeding /usr/share/foreman/db/seeds.d/11-smart_proxy_features.rb Seeding /usr/share/foreman/db/seeds.d/13-compute_profiles.rb
      Seeding /usr/share/foreman/db/seeds.d/15-bookmarks.rb 
      rake aborted! 
      NoMethodError: undefined method `first' for nil:NilClass 
      /usr/share/foreman/lib/seed_helper.rb:32:in `block (2 levels) in interesting_audits' 
      /usr/share/foreman/lib/seed_helper.rb:30:in `each' 
      /usr/share/foreman/lib/seed_helper.rb:30:in `all?' 
      /usr/share/foreman/lib/seed_helper.rb:30:in `block in interesting_audits'
      
  • After applying the audit patch the upgrade fails again, because the bookmark's name had already been taken:

rake aborted! Unable to create bookmark: Name has already been taken
SBR
Product(s)
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.