Bug 2145240 - Upgrade to Satellite 6.12 may fail to apply RemoveDrpmFromIgnorableContent migration if erratum is also a ignorable content type for any repo
Summary: Upgrade to Satellite 6.12 may fail to apply RemoveDrpmFromIgnorableContent mi...
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Repositories
Version: 6.12.0
Hardware: All
OS: All
high
high
Target Milestone: 6.13.0
Assignee: Samir Jha
QA Contact: Cole Higgins
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-11-23 15:07 UTC by Sayan Das
Modified: 2023-02-23 20:12 UTC (History)
4 users (show)

Fixed In Version: rubygem-katello-4.7.0.1
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 2150120 (view as bug list)
Environment:
Last Closed: 2023-02-23 20:12:49 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 35864 0 High Closed Upgrade to 4.5 may fail to apply RemoveDrpmFromIgnorableContent migration if erratum is also a ignorable content type fo... 2023-02-23 20:12:16 UTC
Red Hat Issue Tracker SAT-14070 0 None None None 2022-11-28 14:32:49 UTC
Red Hat Knowledge Base (Solution) 6987408 0 None None None 2022-11-23 22:11:28 UTC
Red Hat Knowledge Base (Solution) 6988713 0 None None None 2022-12-01 18:17:24 UTC

Description Sayan Das 2022-11-23 15:07:16 UTC
Description of problem:

Despite https://bugzilla.redhat.com/show_bug.cgi?id=2055391 was fixed in Satellite 6.12, we only, assumed that we have to deal with "drpm" ignorable content but in some odd cases, "erratum" could also be found mentioned as Ignorable content type for some repos in which case the migration fail to perform root.save! from https://github.com/Katello/katello/pull/9986/files  


Version-Release number of selected component (if applicable):

Satellite 6.12
katello-4.5.0.20

How reproducible:

100% 

Steps to Reproduce:

1. Install satellite 6.11

2. Create a repo by name SLE_12_SP5 under product SLES https://download.opensuse.org/repositories/home:/czanik:/syslog-ng336/SLE_12_SP5/ and enable the "Ignore SRPMs" option for the repo.

3. Now perform the following steps i.e. edit app/lib/actions/katello/repository/update.rb and app/models/katello/root_repository.rb to allow adding drpms and erratum as ignorable content types.

# cd /usr/share/gems/gems/katello-4.3.0.50

# git init .;git add .;git commit -m 'original state'

# vi app/models/katello/root_repository.rb

# vi app/lib/actions/katello/repository/update.rb

# git diff
diff --git a/app/lib/actions/katello/repository/update.rb b/app/lib/actions/katello/repository/update.rb
+++ b/app/lib/actions/katello/repository/update.rb
@@ -10,7 +10,7 @@ module Actions
 
           repo_params[:url] = nil if repo_params[:url] == ''
           update_cv_cert_protected = repo_params.key?(:unprotected) && (repo_params[:unprotected] != repository.unprotected)
-
+          repo_params[:ignorable_content] = ['srpm', 'drpm']
           root.update!(repo_params)
 
           if update_content?(repository)
diff --git a/app/models/katello/root_repository.rb b/app/models/katello/root_repository.rb
index 80c57ba..392b9f1 100644
--- a/app/models/katello/root_repository.rb
+++ b/app/models/katello/root_repository.rb
@@ -17,7 +17,7 @@ module Katello
     DOWNLOAD_ON_DEMAND = 'on_demand'.freeze
     DOWNLOAD_POLICIES = [DOWNLOAD_IMMEDIATE, DOWNLOAD_ON_DEMAND].freeze
 
-    IGNORABLE_CONTENT_UNIT_TYPES = %w(srpm).freeze
+    IGNORABLE_CONTENT_UNIT_TYPES = %w(srpm drpm erratum).freeze
     CHECKSUM_TYPES = %w(sha1 sha256).freeze
 
     SUBSCRIBABLE_TYPES = [Repository::YUM_TYPE, Repository::OSTREE_TYPE, Repository::DEB_TYPE].freeze


4. Now, Add the drpm and erratum as the ignorable content types for the SLE_12_SP5 repo


# cat << EOF |foreman-rake console
Katello::RootRepository.select { |r| r&.ignorable_content&.include? "srpm" }.each do |root|
 root.ignorable_content = root.ignorable_content + ["drpm", "erratum"]
 root.save!
end
EOF

# echo "select id,name,product_id,content_type,ignorable_content from katello_root_repositories;" | su - postgres -c "psql foreman"


5. Revert back the changes done in the katello code

# cd /usr/share/gems/gems/katello-4.3.0.50

# git reset --hard


6. Upgrade to Satellite 6.12 and observe the results. 



Actual Results:

Upgrade will fail on the db:migrate step , to perform the RemoveDrpmFromIgnorableContent migration as the current code https://github.com/Katello/katello/pull/9986/files only assumes that drpm would the only additional ignorable content and hence it tries to just remove it and the save the repo but sinc erratum is present as well and it is not a supported content type, The root.save! fails. 

~~~
2022-11-23 20:26:27 [INFO  ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns:
2022-11-23 20:26:27 [INFO  ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: == 20220228173251 RemoveDrpmFromIgnorableContent: migrating ===================
2022-11-23 20:26:27 [ERROR ] [configure] '/usr/sbin/foreman-rake db:migrate' returned 1 instead of one of [0]
2022-11-23 20:26:27 [ERROR ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: change from 'notrun' to ['0'] failed: '/usr/sbin/foreman-rake db:migrate' returned 1 instead of one of [0]

~~~


Expected Results: 

No such errors.


Additional info:

At this stage, To fix the issue, 

# cd /usr/share/gems/gems/katello-4.5.0.20

--> Create this file :

# cat migration_fix.patch
diff --git a/db/migrate/20220228173251_remove_drpm_from_ignorable_content.rb b/db/migrate/20220228173251_remove_drpm_from_ignorable_content.rb
index a690c9e..39c0bca 100644
--- a/db/migrate/20220228173251_remove_drpm_from_ignorable_content.rb
+++ b/db/migrate/20220228173251_remove_drpm_from_ignorable_content.rb
@@ -1,8 +1,15 @@
 class RemoveDrpmFromIgnorableContent < ActiveRecord::Migration[6.0]
   def up
-    Katello::RootRepository.select { |r| r&.ignorable_content&.include? "drpm" }.each do |root|
-      root.ignorable_content = root.ignorable_content - ["drpm"]
-      root.save!
+    Katello::RootRepository.select { |r| r&.ignorable_content&.include?("drpm") || r&.ignorable_content&.include?("erratum") }.each do |root|
+       ignorable_content_to_remove = []
+       if(root&.ignorable_content&.include? "drpm")
+            ignorable_content_to_remove << "drpm"
+       end
+       if(root&.ignorable_content&.include? "erratum")
+            ignorable_content_to_remove << "erratum"
+       end
+       root.ignorable_content = root.ignorable_content - ignorable_content_to_remove
+       root.save!
     end
   end
 
--> Apply the patch

# patch -p1 < migration_fix.patch 
patching file db/migrate/20220228173251_remove_drpm_from_ignorable_content.rb


--> Run db:migrate manually 

# cd ~

# foreman-rake db:migrate --trace

--> And confirm that, Now only srpms are showing up as the IGNORABLE CONTENT for the same repo

# echo "select id,name,product_id,content_type,ignorable_content from katello_root_repositories;" | su - postgres -c "psql foreman"


--> Re-run the upgrade and it should be completed successfully

Comment 1 Samir Jha 2022-12-13 19:03:54 UTC
Created redmine issue https://projects.theforeman.org/issues/35864 from this bug

Comment 4 Bryan Kearney 2022-12-22 20:03:25 UTC
Moving this bug to POST for triage into Satellite since the upstream issue https://projects.theforeman.org/issues/35864 has been resolved.


Note You need to log in before you can comment on or make changes to this bug.