Skip to content

Commit

Permalink
Fixes #36776 - Fixed issue where composite content views promoted to …
Browse files Browse the repository at this point in the history
…lifecycle environments referencing the env name would error on promotion.

Changed env replacement source.

Force pushing to rerun tests.

Rubocop fixes

Changed several factors for how the container name is rendered. Documented thought process.

Fixed existing unit test to test on new naming schema instead of testing for overlap with a poor env pattern.

Rubocop fixes
  • Loading branch information
qcjames53 committed Sep 27, 2023
1 parent e75f1f1 commit cbc68e0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
33 changes: 27 additions & 6 deletions app/models/katello/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -860,20 +860,41 @@ def self.search_by_content_label(_key, operator, value)
end

def self.safe_render_container_name(repository, pattern = nil)
if (pattern && !pattern.blank?) || (repository.environment && !repository.environment.registry_name_pattern.empty?)
# require 'byebug'; byebug
# pattern provided / env pattern provided
# | 00 | 01 | 11 | 10
# ----------------+-----+-----+-----+------
# env exists / 00| 4 | n/a | n/a | 4
# is cv default 01| 2 | n/a | n/a | 4
# 11| 2 | 1 | 1 | 1
# 10| 3 | 1 | 1 | 1
#
# This diagram shows the name to render given the properties of
# the container provided. Branches numbered as ordered below.
is_pattern_provided = pattern.present?
env_exists = repository.environment.present?
is_env_pattern_provided = env_exists && repository.environment.registry_name_pattern.present?
is_cv_default = repository.content_view.default?

if is_env_pattern_provided || (is_pattern_provided && env_exists)
pattern ||= repository.environment.registry_name_pattern
allowed_methods = {}
allowed_vars = {}
scope_variables = {repository: repository, organization: repository.organization, product: repository.product,
lifecycle_environment: repository.environment, content_view: repository.content_view_version.content_view,
content_view_version: repository.content_view_version}
scope_variables = {
repository: repository,
organization: repository.organization,
product: repository.product,
lifecycle_environment: repository.environment,
content_view: repository.content_view_version.content_view,
content_view_version: repository.content_view_version
}
box = Safemode::Box.new(repository, allowed_methods)
erb = ERB.new(pattern)
pattern = box.eval(erb.src, allowed_vars, scope_variables)
return Repository.clean_container_name(pattern)
elsif repository.content_view.default?
elsif is_cv_default && !is_pattern_provided
items = [repository.organization.label, repository.product.label, repository.label]
elsif repository.environment
elsif env_exists
items = [repository.organization.label, repository.environment.label, repository.content_view.label, repository.product.label, repository.label]
else
items = [repository.organization.label, repository.content_view.label, repository.content_view_version.version, repository.product.label, repository.label]
Expand Down
17 changes: 10 additions & 7 deletions test/models/content_view_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def test_docker_repo_conflicts
assert composite.errors.full_messages.first =~ /^Container Image repo '#{repo.name}' is present in multiple/
end

def test_docker_repo_container_names
def test_docker_repo_container_names # rubocop:disable Metrics/AbcSize
composite = ContentView.find(katello_content_views(:composite_view).id)
product = create(:katello_product, provider: @organization.anonymous_provider, organization: @organization)

Expand All @@ -391,15 +391,18 @@ def test_docker_repo_container_names
repo2_cv = build(:docker_repository, product: product, content_view_version: @organization.default_content_view.versions.first, library_instance_id: repo2_lib.id)
version2 = create(:katello_content_view_version, :content_view => view2, :repositories => [repo2_cv])

composite.update(component_ids: [version1.id])
composite.update(component_ids: [version1.id, version2.id])
assert composite.valid?
@dev.registry_name_pattern = "abcdef"
assert composite.check_docker_repository_names!([@dev])

composite.update(component_ids: [version1.id, version2.id])
assert composite.valid?
assert_raises(RuntimeError) do
composite.check_docker_repository_names!([@dev])
# ensure that all containers are stored with the proper auto-generated names
[version1, version2].each do |version|
name = "#{@dev.organization.name.downcase.sub!(" ", "_")}-"\
"#{version.content_view.label.downcase}-"\
"#{version.content_view.content_view_versions[0].version.sub!(".", "_")}-"\
"#{version.repositories[0].product.label.downcase}-"\
"#{version.repositories[0].name.downcase.sub!(" ", "_")}"
assert_equal name, version.repositories[0].container_repository_name
end
end

Expand Down

0 comments on commit cbc68e0

Please sign in to comment.