Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #36347 - Remove YumMetadataFile #11312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions app/lib/actions/katello/repository/check_matching_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ def run
errata = errata_match?(source_repo, target_repo)
package_groups = package_groups_match?(source_repo, target_repo)
distributions = distributions_match?(source_repo, target_repo)
yum_metadata_files = yum_metadata_files_match?(source_repo, target_repo)
checksum_match = (target_repo.saved_checksum_type == source_repo.saved_checksum_type)

output[:checksum_match] = checksum_match
output[:matching_content] = yum_metadata_files && srpms_match && rpms && errata && package_groups && distributions && target_repo_published && checksum_match
output[:matching_content] = srpms_match && rpms && errata && package_groups && distributions && target_repo_published && checksum_match
end

if source_repo.content_type == ::Katello::Repository::DEB_TYPE
Expand Down Expand Up @@ -66,12 +65,6 @@ def package_groups_match?(source_repo, target_repo)
def distributions_match?(source_repo, target_repo)
source_repo.distribution_information == target_repo.distribution_information
end

def yum_metadata_files_match?(source_repo, target_repo)
source_repo_items = source_repo.yum_metadata_files.pluck(:name, :checksum).sort.uniq
target_repo_items = target_repo.yum_metadata_files.pluck(:name, :checksum).sort.uniq
source_repo_items == target_repo_items
end
end
end
end
Expand Down
54 changes: 12 additions & 42 deletions app/models/katello/concerns/pulp_database_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ module Concerns::PulpDatabaseUnit
extend ActiveSupport::Concern
# Class.repository_association_class
included do
if many_repository_associations
# rubocop:disable Rails/ReflectionClassName
has_many repository_association.to_sym, class_name: repository_association_class_name,
dependent: :delete_all, inverse_of: association_name
has_many :repositories, through: repository_association.to_sym, class_name: "Katello::Repository"
include ::Katello::Concerns::SearchByRepositoryName
end
# rubocop:disable Rails/ReflectionClassName
has_many repository_association.to_sym, class_name: repository_association_class_name,
dependent: :delete_all, inverse_of: association_name
has_many :repositories, through: repository_association.to_sym, class_name: "Katello::Repository"
include ::Katello::Concerns::SearchByRepositoryName
end

def backend_data
Expand Down Expand Up @@ -50,10 +48,6 @@ def content_unit_class
"::Katello::Pulp::#{self.name.demodulize}".constantize
end

def many_repository_associations
self != YumMetadataFile
end

def repository_association
repository_association_class_name.demodulize.pluralize.underscore
end
Expand Down Expand Up @@ -86,27 +80,11 @@ def import_all(unit_ids, repository = nil, options = {})
end

def copy_repository_associations(source_repo, dest_repo)
if many_repository_associations
delete_query = "delete from #{repository_association_class.table_name} where repository_id = #{dest_repo.id} and
#{unit_id_field} not in (select #{unit_id_field} from #{repository_association_class.table_name} where repository_id = #{source_repo.id})"
ActiveRecord::Base.transaction do
ActiveRecord::Base.connection.execute(delete_query)
self.repository_association_class.import(db_columns_copy, db_values_copy(source_repo, dest_repo), validate: false)
end
else
columns = column_names - ["id", "pulp_id", "created_at", "updated_at", "repository_id"]
queries = []
queries << "delete from #{self.table_name} where repository_id = #{dest_repo.id} and
pulp_id not in (select pulp_id from #{self.table_name} where repository_id = #{source_repo.id})"
queries << "insert into #{self.table_name} (repository_id, pulp_id, #{columns.join(',')})
select #{dest_repo.id} as repository_id, pulp_id, #{columns.join(',')} from #{self.table_name}
where repository_id = #{source_repo.id} and pulp_id not in (select pulp_id
from #{self.table_name} where repository_id = #{dest_repo.id})"
ActiveRecord::Base.transaction do
queries.each do |query|
ActiveRecord::Base.connection.execute(query)
end
end
delete_query = "delete from #{repository_association_class.table_name} where repository_id = #{dest_repo.id} and
#{unit_id_field} not in (select #{unit_id_field} from #{repository_association_class.table_name} where repository_id = #{source_repo.id})"
ActiveRecord::Base.transaction do
ActiveRecord::Base.connection.execute(delete_query)
self.repository_association_class.import(db_columns_copy, db_values_copy(source_repo, dest_repo), validate: false)
end
end

Expand Down Expand Up @@ -168,19 +146,11 @@ def with_identifiers(ids)
end

def orphaned
if many_repository_associations
left_joins(repository_association.to_sym).where("#{repository_association_class.table_name}.#{unit_id_field}" => nil)
else
where.not(:repository_id => ::Katello::Repository.select(:id))
end
left_joins(repository_association.to_sym).where("#{repository_association_class.table_name}.#{unit_id_field}" => nil)
end

def in_repositories(repos)
if many_repository_associations
where(:id => repository_association_class.where(:repository_id => repos).select(unit_id_field))
else
where(:repository_id => repos)
end
where(:id => repository_association_class.where(:repository_id => repos).select(unit_id_field))
end

def pulp_data(pulp_id)
Expand Down
2 changes: 0 additions & 2 deletions app/models/katello/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ class Repository < Katello::Model
has_many :repository_docker_manifest_lists, :class_name => "Katello::RepositoryDockerManifestList", :dependent => :delete_all
has_many :docker_manifest_lists, :through => :repository_docker_manifest_lists

has_many :yum_metadata_files, :dependent => :destroy, :class_name => "Katello::YumMetadataFile"

has_many :repository_docker_tags, :class_name => "Katello::RepositoryDockerTag", :dependent => :delete_all
has_many :docker_tags, :through => :repository_docker_tags

Expand Down
22 changes: 0 additions & 22 deletions app/models/katello/yum_metadata_file.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/services/katello/content_unit_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def import_all(filtered_indexing = false)
import_associations(units) if @repository
end

if @model_class.many_repository_associations && @repository
if @repository
sync_repository_associations(association_tracker, additive: filtered_indexing)
end
end
Expand Down
20 changes: 0 additions & 20 deletions app/services/katello/pulp3/yum_metadata_file.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class AddPulp3HrefsToContentTypes < ActiveRecord::Migration[5.2]
def change
content_models = [Katello::Rpm, Katello::ModuleStream, Katello::Erratum, Katello::PackageGroup, Katello::YumMetadataFile,
content_models = [Katello::Rpm, Katello::ModuleStream, Katello::Erratum, Katello::PackageGroup,
Katello::Srpm, Katello::FileUnit, Katello::DockerManifestList, Katello::DockerManifest, Katello::DockerTag]

content_models.each do |model|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class RemovePulp3MigratedHrefsFromContentTables < ActiveRecord::Migration[6.1]
def change
content_models = [Katello::Rpm, Katello::ModuleStream, Katello::Erratum, Katello::PackageGroup, Katello::YumMetadataFile,
content_models = [Katello::Rpm, Katello::ModuleStream, Katello::Erratum, Katello::PackageGroup,
Katello::Srpm, Katello::FileUnit, Katello::DockerManifestList, Katello::DockerManifest, Katello::DockerTag]

content_models.each do |model|
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20250215143303_drop_katello_yum_metadata_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DropKatelloYumMetadataFile < ActiveRecord::Migration[7.0]
def change
drop_table :katello_yum_metadata_files
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def test_check_matching_content_false_checksum
action_class.any_instance.stubs(:errata_match?).returns(true)
action_class.any_instance.stubs(:package_groups_match?).returns(true)
action_class.any_instance.stubs(:distributions_match?).returns(true)
action_class.any_instance.stubs(:yum_metadata_files_match?).returns(true)
#::Katello::Repository.any_instance.expects(:published?).returns(true)

yum_repo.update_attribute(:saved_checksum_type, "sha512")
Expand Down
17 changes: 0 additions & 17 deletions test/fixtures/models/katello_yum_metadata_files.yml

This file was deleted.

8 changes: 2 additions & 6 deletions test/models/pulp_database_unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ class PulpDatabaseUnitTest < ActiveSupport::TestCase
def test_complete_for
content_types = ::Katello::RepositoryTypeManager.enabled_repository_types.values.map { |t| t.content_types.map(&:model_class) }.flatten.select { |klazz| klazz <= ::Katello::Concerns::PulpDatabaseUnit }
content_types.each do |klazz|
if klazz.many_repository_associations
refute_nil klazz.complete_for("repository="), "asserting #{klazz}"
refute_nil klazz.search_for("repository=foo"), "asserting #{klazz}"
end
refute_nil klazz.complete_for("repository="), "asserting #{klazz}"
refute_nil klazz.search_for("repository=foo"), "asserting #{klazz}"
end

assert_empty ::Katello::YumMetadataFile.methods.grep(/complete_for/)
end

def test_orphaned
Expand Down
58 changes: 0 additions & 58 deletions test/models/yum_metadata_file_test.rb

This file was deleted.

1 change: 0 additions & 1 deletion test/support/fixtures_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ module FixturesSupport
:katello_repository_debs => Katello::RepositoryDeb,
:katello_repository_rpms => Katello::RepositoryRpm,
:katello_repository_srpms => Katello::RepositorySrpm,
:katello_yum_metadata_files => Katello::YumMetadataFile,
:katello_content_facets => Katello::Host::ContentFacet,
:katello_subscription_facets => Katello::Host::SubscriptionFacet,
:katello_docker_manifests => Katello::DockerManifest,
Expand Down