Skip to content

Commit

Permalink
Refs #37552 - add container push CV publish tests and limit PublishCo…
Browse files Browse the repository at this point in the history
…ntainerRespositories to container repos
  • Loading branch information
ianballou committed Jul 1, 2024
1 parent da3f18d commit 17d1606
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 71 deletions.
54 changes: 28 additions & 26 deletions app/controllers/katello/api/registry/registry_proxies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,11 @@ def check_blob_push_org_label(props)
return render_podman_error(
"NAME_INVALID",
_("Due to a change in your organizations, this container name has become "\
"ambiguous (org name '#{org_label}'). If you wish to continue using this "\
"container name, destroy the organization in conflict with '#{o.name} (id "\
"#{o.id}). If you wish to keep both orgs, destroy '#{o.label}/#{prod.label}/"\
"#{root_repos.first.label}' and retry your push using the id format."),
"ambiguous (org name '%{org_label}'). If you wish to continue using this "\
"container name, destroy the organization in conflict with '%{o_name} (id "\
"%{o_id}). If you wish to keep both orgs, destroy '%{o_label}/%{prod_label}/"\
"%{root_repo_label}' and retry your push using the id format.") %
{ org_label: org_label, o_name: o.name, o_id: o.id, o_label: o.label, prod_label: prod.label, root_repo_label: root_repos.first.label },
:conflict
)
end
Expand All @@ -186,14 +187,14 @@ def check_blob_push_org_label(props)
# Otherwise tell them to try pushing with ID format
return render_podman_error(
"NAME_INVALID",
_("Organization label '#{org_label}' is ambiguous. Try using an id-based container name."),
_("Organization label '%s' is ambiguous. Try using an id-based container name.") % org_label,
:conflict
)
end
if org.length == 0
return render_podman_error(
"NAME_UNKNOWN",
_("Organization not found: '#{org_label}'"),
_("Organization not found: '%s'") % org_label,
:not_found
)
end
Expand All @@ -214,7 +215,7 @@ def check_blob_push_org_id(props)
if @organization.nil?
return render_podman_error(
"NAME_UNKNOWN",
_("Organization id not found: '#{org_id}'"),
_("Organization id not found: '%s'") % org_id,
:not_found
)
end
Expand Down Expand Up @@ -242,10 +243,11 @@ def check_blob_push_product_label(props)
return render_podman_error(
"NAME_INVALID",
_("Due to a change in your products, this container name has become ambiguous "\
"(product name '#{prod_label}'). If you wish to continue using this container "\
"name, destroy the product in conflict with '#{prod.name}' (id #{prod.id}). If "\
"you wish to keep both products, destroy '#{@organization.label}/#{prod.label}/"\
"#{root_repos.first.label}' and retry your push using the id format."),
"(product name '%{prod_label}'). If you wish to continue using this container "\
"name, destroy the product in conflict with '%{prod_name}' (id %{prod_id}). If "\
"you wish to keep both products, destroy '%{org_label}/%{prod_dot_label}/"\
"%{root_repo_label}' and retry your push using the id format.") %
{ prod_label: prod_label, prod_name: prod.name, prod_id: prod.id, org_label: @organization.label, prod_dot_label: prod.label, root_repo_label: root_repos.first.label },
:conflict
)
end
Expand All @@ -254,14 +256,14 @@ def check_blob_push_product_label(props)

return render_podman_error(
"NAME_INVALID",
_("Product label '#{prod_label}' is ambiguous. Try using an id-based container name."),
_("Product label '%s' is ambiguous. Try using an id-based container name.") % prod_label,
:conflict
)
end
if product.length == 0
return render_podman_error(
"NAME_UNKNOWN",
_("Product not found: '#{prod_label}'"),
_("Product not found: '%s'") % prod_label,
:not_found
)
end
Expand All @@ -282,7 +284,7 @@ def check_blob_push_product_id(props)
if @product.nil?
return render_podman_error(
"NAME_UNKNOWN",
_("Product id not found: '#{prod_id}'"),
_("Product id not found: '%s'") % prod_id,
:not_found
)
end
Expand Down Expand Up @@ -319,7 +321,8 @@ def check_blob_push_container(props)
if !root_repo.nil? && @container_push_name_format != root_repo.container_push_name_format
return render_podman_error(
"NAME_INVALID",
_("Repository name '#{@container_name}' already exists in this product using a different naming scheme. Please retry your request with the #{root_repo.container_push_name_format} format or destroy and recreate the repository using your preferred schema."),
_("Repository name '%{container_name}' already exists in this product using a different naming scheme. Please retry your request with the %{root_repo_container_push_name} format or destroy and recreate the repository using your preferred schema.") %
{container_name: @container_name, root_repo_container_push_name: root_repo.container_push_name_format},
:conflict
)
end
Expand All @@ -328,13 +331,12 @@ def check_blob_push_container(props)
end

def create_container_repo_if_needed
unless @product.organization.library.registry_unauthenticated_pull
unless @product.syncable?
return render_podman_error(
'DENIED',
_("Requested access to '#{@container_name}' is denied")
)
end
unless @product.syncable?
return render_podman_error(
'DENIED',
_("Requested access to '%s' is denied") % @container_name,
:not_found
)
end

if get_root_repo_from_product(@product, @container_name).empty?
Expand Down Expand Up @@ -371,9 +373,6 @@ def blob_push_cleanup
latest_version_href = push_repo_api_response&.latest_version_href
pulp_repo_href = push_repo_api_response&.pulp_href

distribution_api_response = pulp_api.container_push_distribution_for_repository(pulp_repo_href)
pulp_distribution_href = distribution_api_response&.pulp_href

if latest_version_href.empty? || pulp_repo_href.empty?
return render_podman_error(
"BLOB_UPLOAD_UNKNOWN",
Expand All @@ -382,6 +381,9 @@ def blob_push_cleanup
)
end

distribution_api_response = pulp_api.container_push_distribution_for_repository(pulp_repo_href)
pulp_distribution_href = distribution_api_response&.pulp_href

if pulp_distribution_href.empty?
return render_podman_error(
"BLOB_UPLOAD_UNKNOWN",
Expand Down Expand Up @@ -783,7 +785,7 @@ def render_podman_error(code, message, status = :bad_request)
end

def item_not_found(item)
render_podman_error("NAME_UNKNOWN", _("#{item} was not found!"), :not_found)
render_podman_error("NAME_UNKNOWN", _("%s was not found!") % item, :not_found)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PublishContainerRepositories < Actions::EntryAction
end

def plan(env)
repositories = env.repositories
repositories = env.repositories.docker_type
action_subject(env)
concurrence do
repositories.each do |repository|
Expand Down
20 changes: 20 additions & 0 deletions test/actions/katello/environment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ class TestBase < ActiveSupport::TestCase
end
end

class PublishContainerRepositoriesTest < TestBase
let(:action_class) { ::Actions::Katello::Environment::PublishContainerRepositories }
let(:action) { create_action action_class }

let(:environment) { stub }

it 'does not plan for container push library repos' do
container_push_repo = ::Katello::RootRepository.find_by(name: 'busybox').library_instance
container_push_repo.root.update(is_container_push: true)
environment.stubs(:repositories).returns(::Katello::Repository.where(id: container_push_repo.id))
container_push_repo.expects(:set_container_repository_name).never
container_push_repo.expects(:clear_smart_proxy_sync_histories).never
action.stubs(:action_subject).with(environment)

plan_action(action, environment)
refute_action_planned(action, ::Actions::Katello::Repository::InstanceUpdate)
refute_action_planned(action, ::Actions::Katello::Repository::CapsuleSync)
end
end

class DestroyTest < TestBase
let(:action_class) { ::Actions::Katello::Environment::Destroy }
let(:action) { create_action action_class }
Expand Down
Loading

0 comments on commit 17d1606

Please sign in to comment.