Skip to content

Commit

Permalink
Fixes #29421 - add pulp3 debian support
Browse files Browse the repository at this point in the history
create, update, sync and delete debian repositories on pulp3
  • Loading branch information
m-bucher committed Mar 27, 2020
1 parent 8dd6855 commit 0fd752e
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 2 deletions.
57 changes: 57 additions & 0 deletions app/services/katello/pulp3/api/apt.rb
@@ -0,0 +1,57 @@
require "pulpcore_client"

module Katello
module Pulp3
module Api
class Apt < Core
def self.api_exception_class
PulpDebClient::ApiError
end

def self.client_module
PulpDebClient
end

def self.remote_class
PulpDebClient::DebDebRemote
end

def self.distribution_class
PulpDebClient::DebDebDistribution
end

def self.publication_class
PulpDebClient::DebDebPublication
end

def self.repository_sync_url_class
PulpDebClient::RepositorySyncURL
end

def api_client
PulpDebClient::ApiClient.new(smart_proxy.pulp3_configuration(PulpDebClient::Configuration))
end

def repositories_api
PulpDebClient::RepositoriesAptApi.new(api_client)
end

def repository_versions_api
PulpDebClient::RepositoriesDebVersionsApi.new(api_client)
end

def remotes_api
PulpDebClient::RemotesAptApi.new(api_client)
end

def publications_api
PulpDebClient::PublicationsAptApi.new(api_client)
end

def distributions_api
PulpDebClient::DistributionsAptApi.new(api_client)
end
end
end
end
end
59 changes: 59 additions & 0 deletions app/services/katello/pulp3/deb.rb
@@ -0,0 +1,59 @@
module Katello
module Pulp3
class Deb < PulpContentUnit
include LazyAccessor
CONTENT_TYPE = "deb".freeze

def self.content_api
PulpDebClient::ContentPackagesApi.new(Katello::Pulp3::Api::Apt.new(SmartProxy.pulp_master!).api_client)
end

def self.create_content(options)
fail _("Artifact Id and relative path are needed to create content") unless options.dig(:file_name) && options.dig(:artifact)
PulpDebClient::DebContent.new(relative_path: options[:file_name], artifact: options[:artifact])
end

def self.ids_for_repository(repo_id)
repo = Katello::Pulp3::Repository::Apt.new(Katello::Repository.find(repo_id), SmartProxy.pulp_master)
repo_content_list = repo.content_list
repo_content_list.map { |content| content.try(:pulp_href) }
end

def update_model(model)
# REMOVEME: Only for reference:
# backend_data.keys = [
# "pulp_href",
# "pulp_created",
# "artifact",
# "relative_path",
# "md5",
# "sha1",
# "sha224",
# "sha256",
# "sha384",
# "sha512",
# "package",
# "version",
# "architecture",
# "section",
# "priority",
# "maintainer",
# "description",
# "homepage",
# "depends",
# "recommends",
# "suggests"
# ]

custom_json = {}
custom_json['checksum'] = backend_data['sha256']
custom_json['filename'] = backend_data['relative_path']
custom_json['name'] = backend_data['package']
custom_json['version'] = backend_data['version']
custom_json['description'] = backend_data['description']
custom_json['architecture'] = backend_data['architecture']
model.update_attributes!(custom_json)
end
end
end
end
8 changes: 7 additions & 1 deletion app/services/katello/pulp3/repository.rb
Expand Up @@ -185,10 +185,16 @@ def sync
end

def create_publication
publication_data = api.class.publication_class.new(repository_version: repo.version_href)
publication_data = api.class.publication_class.new(publication_options(repo.version_href))
api.publications_api.create(publication_data)
end

def publication_options(repository_version)
{
repository_version: repository_version
}
end

def relative_path
repo.relative_path.sub(/^\//, '')
end
Expand Down
81 changes: 81 additions & 0 deletions app/services/katello/pulp3/repository/apt.rb
@@ -0,0 +1,81 @@
require 'pulp_deb_client'

module Katello
module Pulp3
class Repository
class Apt < ::Katello::Pulp3::Repository
def remote_options
deb_remote_options = {
distributions: root.deb_releases
}
# TODO: need to define how to set these fields to empty
deb_remote_options[components] = root.deb_components if root.deb_components.present?
deb_remote_options[architectures] = root.deb_architectures if root.deb_architectures.present?

if root.url.blank?
deb_remote_options[:url] = nil
end

common_remote_options.merge(deb_remote_options)
end

def publication_options(repository_version)
super(repository_version).merge(
{
# FIXME: not yet implemented in the current pulp_deb version
#structured: true, # publish real suites (e.g. 'stable')
simple: true # publish all into 'default'-suite
}
)
end

def distribution_options(path)
{
base_path: path,
publication: repo.publication_href,
name: "#{generate_backend_object_name}"
}
end

def import_distribution_data
distribution = ::Katello::Pulp3::Distribution.fetch_content_list(repository_version: repo.version_href)
if distribution.results.present?
repo.update_attributes!(
:distribution_version => distribution.results.first.release_version,
:distribution_arch => distribution.results.first.arch,
:distribution_family => distribution.results.first.release_name,
:distribution_uuid => distribution.results.first.pulp_href,
:distribution_bootable => self.class.distribution_bootable?(distribution)
)
unless distribution.results.first.variants.empty?
unless distribution.results.first.variants.first.name.nil?
repo.update_attributes!(:distribution_variant => distribution.results.first.variants.first.name)
end
end
end
end

def self.distribution_bootable?(distribution)
file_paths = distribution.results.first.images.map(&:path)
file_paths.any? do |path|
path.include?('vmlinuz') || path.include?('pxeboot') || path.include?('kernel.img') || path.include?('initrd.img') || path.include?('boot.iso')
end
end

def partial_repo_path
"/pulp/repos/#{repo.relative_path}/".sub('//', '/')
end

def copy_content_for_source
# TODO
fail NotImplementedError
end

def regenerate_applicability
# TODO
fail NotImplementedError
end
end
end
end
end
1 change: 1 addition & 0 deletions katello.gemspec
Expand Up @@ -48,6 +48,7 @@ Gem::Specification.new do |gem|
gem.add_dependency "pulp_file_client", ">= 0.1.0", "< 0.2.0"
gem.add_dependency "pulp_ansible_client", "<= 0.2.0b7.dev01574717759"
gem.add_dependency "pulp_container_client", ">= 1.0.0", "< 1.1.0"
gem.add_dependency "pulp_deb_client", "<= 2.3.0b1.dev01583866029"
gem.add_dependency "pulp_rpm_client", "<= 3.1.0b1.dev01576187357"
gem.add_dependency "pulp_2to3_migration_client", "< 0.0.2"

Expand Down
10 changes: 9 additions & 1 deletion lib/katello/repository_types/deb.rb
@@ -1,6 +1,14 @@
Katello::RepositoryTypeManager.register(::Katello::Repository::DEB_TYPE) do
service_class Katello::Pulp::Repository::Deb
pulp3_service_class Katello::Pulp3::Repository::Apt
pulp3_api_class Katello::Pulp3::Api::Apt
pulp3_plugin 'pulp_deb'
prevent_unneeded_metadata_publish

default_managed_content_type Katello::Deb
content_type Katello::Deb, :pulp2_service_class => ::Katello::Pulp::Deb, :removable => true, :uploadable => true
content_type Katello::Deb,
:pulp2_service_class => ::Katello::Pulp::Deb,
:pulp3_service_class => ::Katello::Pulp3::Deb,
:removable => true,
:uploadable => true
end

0 comments on commit 0fd752e

Please sign in to comment.