Bug #35864
closedUpgrade to 4.5 may fail to apply RemoveDrpmFromIgnorableContent migration if erratum is also a ignorable content type for any repo
Description
Description of problem:
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):
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 Actionsrepo_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
Updated by The Foreman Bot almost 2 years ago
- Status changed from New to Ready For Testing
- Assignee set to Samir Jha
- Pull request https://github.com/Katello/katello/pull/10393 added
Updated by Samir Jha almost 2 years ago
- Subject changed from Upgrade to 4.5 may fail to apply RemoveDrpmFromIgnorableContent migration if erratum is also a ignorable content type for any repo to Upgrade to 4.5 may fail to apply RemoveDrpmFromIgnorableContent migration if erratum is also a ignorable content type for any repo
- Target version set to Katello 4.8.0
- Triaged changed from No to Yes
Updated by The Foreman Bot almost 2 years ago
- Fixed in Releases Katello 4.8.0 added
Updated by Samir Jha almost 2 years ago
- Status changed from Ready For Testing to Closed
Applied in changeset katello|98fe46f4ea32ff10f28f2391b096e06e4fb13f6b.