Skip to content

Commit c6fa1ec

Browse files
ianballoujlsherrill
authored andcommitted
Fixes #26996 - pulp 3 docker CRUD
1 parent 5b98f31 commit c6fa1ec

File tree

16 files changed

+34006
-0
lines changed

16 files changed

+34006
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
require 'pulp_docker_client'
2+
3+
module Katello
4+
module Pulp3
5+
class Repository
6+
class Docker < ::Katello::Pulp3::Repository
7+
def api_client
8+
PulpDockerClient::ApiClient.new(smart_proxy.pulp3_configuration(PulpDockerClient::Configuration))
9+
end
10+
11+
def api_exception_class
12+
PulpDockerClient::ApiError
13+
end
14+
15+
def remote_class
16+
PulpDockerClient::DockerRemote
17+
end
18+
19+
def remotes_api
20+
PulpDockerClient::RemotesDockerApi.new(api_client)
21+
end
22+
23+
def distribution_class
24+
PulpDockerClient::DockerDistribution
25+
end
26+
27+
def distributions_api
28+
PulpDockerClient::DistributionsDockerApi.new(api_client)
29+
end
30+
31+
def remote_options
32+
if root.url.blank?
33+
super
34+
else
35+
options = {url: root.url, upstream_name: root.docker_upstream_name}
36+
if root.docker_tags_whitelist && root.docker_tags_whitelist.any?
37+
options[:whitelist_tags] = root.docker_tags_whitelist.join(",")
38+
else
39+
options[:whitelist_tags] = nil
40+
end
41+
common_remote_options.merge(options)
42+
end
43+
end
44+
45+
def distribution_options(path)
46+
{
47+
base_path: path,
48+
repository_version: repo.version_href,
49+
name: "#{backend_object_name}"
50+
}
51+
end
52+
end
53+
end
54+
end
55+
end

katello.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Gem::Specification.new do |gem|
4545
gem.add_dependency "pulpcore_client"
4646
gem.add_dependency "pulp_file_client", "< 3.0.0"
4747
gem.add_dependency "pulp_ansible_client"
48+
gem.add_dependency "pulp_docker_client"
4849

4950
# UI
5051
gem.add_dependency "deface", '>= 1.0.2', '< 2.0.0'

lib/katello/repository_types/docker.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Katello::RepositoryTypeManager.register(::Katello::Repository::DOCKER_TYPE) do
22
service_class Katello::Pulp::Repository::Docker
3+
pulp3_service_class Katello::Pulp3::Repository::Docker
4+
pulp3_skip_publication true
5+
pulp3_plugin 'pulp_docker'
36

47
content_type Katello::DockerManifest, :priority => 1, :pulp2_service_class => ::Katello::Pulp::DockerManifest, :user_removable => true
58
content_type Katello::DockerManifestList, :priority => 2, :pulp2_service_class => ::Katello::Pulp::DockerManifestList
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'katello_test_helper'
2+
3+
module ::Actions::Pulp3
4+
class DockerCreateTest < ActiveSupport::TestCase
5+
include Katello::Pulp3Support
6+
7+
def setup
8+
@master = FactoryBot.create(:smart_proxy, :default_smart_proxy, :with_pulp3)
9+
@repo = katello_repositories(:busybox)
10+
ensure_creatable(@repo, @master)
11+
end
12+
13+
def test_create
14+
ForemanTasks.sync_task(::Actions::Pulp3::Orchestration::Repository::Create, @repo, @master)
15+
@repo.reload
16+
17+
assert @repo.remote_href
18+
refute @repo.version_href
19+
20+
repo_reference = Katello::Pulp3::RepositoryReference.find_by(:root_repository_id => @repo.root.id,
21+
:content_view_id => @repo.content_view.id)
22+
assert repo_reference
23+
assert repo_reference.repository_href
24+
end
25+
end
26+
end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require 'katello_test_helper'
2+
3+
module ::Actions::Pulp3
4+
class DockerDeleteTest < ActiveSupport::TestCase
5+
include ::Katello::Pulp3Support
6+
7+
def setup
8+
@master = FactoryBot.create(:smart_proxy, :default_smart_proxy, :with_pulp3)
9+
@repo = katello_repositories(:busybox)
10+
create_repo(@repo, @master)
11+
ForemanTasks.sync_task(
12+
::Actions::Katello::Repository::MetadataGenerate, @repo,
13+
repository_creation: true)
14+
15+
assert Katello::Pulp3::RepositoryReference.find_by(
16+
:root_repository_id => @repo.root.id,
17+
:content_view_id => @repo.content_view.id)
18+
19+
refute_empty Katello::Pulp3::DistributionReference.where(
20+
root_repository_id: @repo.root.id)
21+
22+
ForemanTasks.sync_task(
23+
::Actions::Pulp3::Orchestration::Repository::Delete, @repo, @master)
24+
@repo.reload
25+
end
26+
27+
def test_repository_reference_is_deleted
28+
repo_reference = Katello::Pulp3::RepositoryReference.find_by(
29+
:root_repository_id => @repo.root.id,
30+
:content_view_id => @repo.content_view.id)
31+
32+
assert_nil repo_reference
33+
end
34+
35+
def test_distribution_references_are_deleted
36+
distribution_references = Katello::Pulp3::DistributionReference.where(
37+
root_repository_id: @repo.root.id)
38+
39+
assert_empty distribution_references
40+
end
41+
end
42+
end
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
require 'katello_test_helper'
2+
3+
module ::Actions::Pulp3
4+
class DockerUpdateTest < ActiveSupport::TestCase
5+
include Katello::Pulp3Support
6+
7+
def setup
8+
@master = FactoryBot.create(:smart_proxy, :default_smart_proxy, :with_pulp3)
9+
@repo = katello_repositories(:busybox)
10+
create_repo(@repo, @master)
11+
12+
ForemanTasks.sync_task(
13+
::Actions::Katello::Repository::MetadataGenerate, @repo,
14+
repository_creation: true)
15+
16+
assert_equal 1,
17+
Katello::Pulp3::DistributionReference.where(root_repository_id: @repo.root.id).count,
18+
"Expected a distribution reference."
19+
@repo.root.update_attributes(
20+
verify_ssl_on_sync: false,
21+
ssl_ca_cert: katello_gpg_keys(:unassigned_gpg_key),
22+
ssl_client_cert: katello_gpg_keys(:unassigned_gpg_key),
23+
ssl_client_key: katello_gpg_keys(:unassigned_gpg_key))
24+
end
25+
26+
def test_update_ssl_validation
27+
refute @repo.root.verify_ssl_on_sync, "Respository verify_ssl_on_sync option was false."
28+
@repo.root.update_attributes(
29+
verify_ssl_on_sync: true)
30+
31+
ForemanTasks.sync_task(
32+
::Actions::Pulp3::Orchestration::Repository::Update,
33+
@repo,
34+
@master)
35+
end
36+
37+
def test_update_url
38+
@repo.root.update_attributes(
39+
url: 'http://website.com/')
40+
41+
ForemanTasks.sync_task(
42+
::Actions::Pulp3::Orchestration::Repository::Update,
43+
@repo,
44+
@master)
45+
end
46+
47+
def test_update_upstream_name
48+
@repo.root.update_attributes(
49+
docker_upstream_name: 'test')
50+
51+
ForemanTasks.sync_task(
52+
::Actions::Pulp3::Orchestration::Repository::Update,
53+
@repo,
54+
@master)
55+
end
56+
57+
def test_update_whitelist_tags
58+
@repo.root.update_attributes(
59+
docker_tags_whitelist: 'test_tag')
60+
61+
ForemanTasks.sync_task(
62+
::Actions::Pulp3::Orchestration::Repository::Update,
63+
@repo,
64+
@master)
65+
end
66+
67+
def test_update_whitelist_tags_empty
68+
@repo.root.update_attributes(
69+
docker_tags_whitelist: nil)
70+
71+
ForemanTasks.sync_task(
72+
::Actions::Pulp3::Orchestration::Repository::Update,
73+
@repo,
74+
@master)
75+
end
76+
77+
def test_update_unset_unprotected
78+
assert @repo.root.unprotected
79+
assert_equal 1, Katello::Pulp3::DistributionReference.where(
80+
root_repository_id: @repo.root.id).count
81+
82+
@repo.root.update_attributes(unprotected: false)
83+
84+
ForemanTasks.sync_task(
85+
::Actions::Pulp3::Orchestration::Repository::Update,
86+
@repo,
87+
@master)
88+
89+
dist_refs = Katello::Pulp3::DistributionReference.where(
90+
root_repository_id: @repo.root.id)
91+
92+
assert_equal 1, dist_refs.count, "Expected 1 distribution reference."
93+
end
94+
95+
def test_update_set_unprotected
96+
@repo.root.update_attributes(unprotected: false)
97+
98+
ForemanTasks.sync_task(
99+
::Actions::Pulp3::Orchestration::Repository::Update,
100+
@repo,
101+
@master)
102+
103+
dist_refs = Katello::Pulp3::DistributionReference.where(
104+
root_repository_id: @repo.root.id)
105+
106+
assert_equal 1, dist_refs.count, "Expected only 1 distribution reference."
107+
@repo.root.update_attributes(unprotected: true)
108+
109+
ForemanTasks.sync_task(
110+
::Actions::Pulp3::Orchestration::Repository::Update,
111+
@repo,
112+
@master)
113+
114+
dist_refs = Katello::Pulp3::DistributionReference.where(
115+
root_repository_id: @repo.root.id)
116+
assert_equal 1, dist_refs.count, "Expected a distribution reference."
117+
end
118+
end
119+
end

0 commit comments

Comments
 (0)