Skip to content
Merged
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
44 changes: 33 additions & 11 deletions pkg/tasks/candlepin_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func UnneededOverrides(existingDtos []caliri.ContentOverrideDTO, expectedDTOs []
// genOverrideDTOs uses the RepoConfigUUIDs to query the db and generate a mapping of content labels to distribution URLs
// for the snapshot within the template. For all repos, we include an override for an 'empty' sslcacert, so it does not use the configured default
// on the client. For custom repos, we override the base URL, due to the fact that we use different domains for RH and custom repos.
func GenOverrideDTO(ctx context.Context, daoReg *dao.DaoRegistry, orgId, domainName, contentPath string, template api.TemplateResponse) ([]caliri.ContentOverrideDTO, error) {
func GenOverrideDTO(ctx context.Context, daoReg *dao.DaoRegistry, orgId, domainName, rhDomainName, contentPath string, template api.TemplateResponse) ([]caliri.ContentOverrideDTO, error) {
mapping := []caliri.ContentOverrideDTO{}

uuids := strings.Join(template.RepositoryUUIDS, ",")
Expand All @@ -75,7 +75,16 @@ func GenOverrideDTO(ctx context.Context, daoReg *dao.DaoRegistry, orgId, domainN
return mapping, err
}
for _, repo := range repos.Data {
repoOver, err := ContentOverridesForRepo(orgId, domainName, template.UUID, contentPath, repo)
var domain string
switch repo.OrgID {
case config.RedHatOrg:
domain = rhDomainName
case config.CommunityOrg:
domain = config.CommunityDomainName
default:
domain = domainName
}
repoOver, err := ContentOverridesForRepo(domain, template.UUID, contentPath, repo)
if err != nil {
return mapping, err
}
Expand All @@ -99,42 +108,55 @@ func RemoveUneededOverrides(ctx context.Context, cpClient candlepin_client.Candl
return nil
}

func ContentOverridesForRepo(orgId string, domainName string, templateUUID string, pulpContentPath string, repo api.RepositoryResponse) ([]caliri.ContentOverrideDTO, error) {
func ContentOverridesForRepo(domainName string, templateUUID string, pulpContentPath string, repo api.RepositoryResponse) ([]caliri.ContentOverrideDTO, error) {
mapping := []caliri.ContentOverrideDTO{}
if repo.LastSnapshot == nil { // ignore repos without a snapshot
return mapping, nil
}

isExtendedReleaseRepo := repo.OrgID == config.RedHatOrg && repo.ExtendedRelease != ""
shouldOverrideURL := isExtendedReleaseRepo ||
repo.Origin == config.OriginExternal ||
repo.Origin == config.OriginCommunity ||
repo.Origin == config.OriginUpload

contentLabel := repo.Label
if isExtendedReleaseRepo {
contentLabel = normalizeExtendedReleaseLabel(repo.Label)
}

mapping = append(mapping, caliri.ContentOverrideDTO{
Name: utils.Ptr(candlepin_client.OverrideNameCaCert),
ContentLabel: &repo.Label,
ContentLabel: &contentLabel,
Value: utils.Ptr(" "), // use a single space because candlepin doesn't allow "" or null
})
// Disable OCSP checking, as aws doesn't support it?
mapping = append(mapping, caliri.ContentOverrideDTO{
Name: utils.Ptr(candlepin_client.OverrideSSLVerifyStatus),
ContentLabel: &repo.Label,
ContentLabel: &contentLabel,
Value: utils.Ptr("0"),
})

if repo.OrgID == orgId || repo.OrgID == config.CommunityOrg { // Don't override RH repo baseurls
distPath := customTemplateSnapshotPath(templateUUID, repo.UUID)
if repo.OrgID == config.CommunityOrg {
domainName = config.CommunityDomainName
if shouldOverrideURL {
distPath, _, err := getDistPathAndName(repo, templateUUID)
if err != nil {
return mapping, err
}

path, err := url.JoinPath(pulpContentPath, domainName, distPath)
if err != nil {
return mapping, err
}

mapping = append(mapping, caliri.ContentOverrideDTO{
Name: utils.Ptr(candlepin_client.OverrideNameBaseUrl),
ContentLabel: &repo.Label,
ContentLabel: &contentLabel,
Value: &path,
})
if repo.ModuleHotfixes {
mapping = append(mapping, caliri.ContentOverrideDTO{
Name: utils.Ptr(candlepin_client.OverrideModuleHotfixes),
ContentLabel: &repo.Label,
ContentLabel: &contentLabel,
Value: utils.Ptr("1"),
})
}
Expand Down
49 changes: 46 additions & 3 deletions pkg/tasks/candlepin_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ func (s *CandlepinHelpersTest) TestContentOverridesForRepo() {
GpgKey: "",
ModuleHotfixes: false,
LastSnapshot: utils.Ptr(api.SnapshotResponse{}),
Origin: config.OriginExternal,
}
overrides, err := ContentOverridesForRepo(orgId, domain, templateUUID, pulpContentPath, Repo)
overrides, err := ContentOverridesForRepo(domain, templateUUID, pulpContentPath, Repo)
assert.NoError(s.T(), err)

assert.Len(s.T(), overrides, 3)
Expand All @@ -125,7 +126,7 @@ func (s *CandlepinHelpersTest) TestContentOverridesForRepo() {
})

Repo.ModuleHotfixes = true
overrides, err = ContentOverridesForRepo(orgId, domain, templateUUID, pulpContentPath, Repo)
overrides, err = ContentOverridesForRepo(domain, templateUUID, pulpContentPath, Repo)
assert.NoError(s.T(), err)
assert.Len(s.T(), overrides, 4)
assert.Contains(s.T(), overrides, caliri.ContentOverrideDTO{
Expand All @@ -135,7 +136,7 @@ func (s *CandlepinHelpersTest) TestContentOverridesForRepo() {
})
Repo.OrgID = config.RedHatOrg
Repo.Origin = config.OriginRedHat
overrides, err = ContentOverridesForRepo(orgId, domain, templateUUID, pulpContentPath, Repo)
overrides, err = ContentOverridesForRepo(domain, templateUUID, pulpContentPath, Repo)
assert.NoError(s.T(), err)
assert.Len(s.T(), overrides, 2)
assert.Contains(s.T(), overrides, caliri.ContentOverrideDTO{
Expand All @@ -149,3 +150,45 @@ func (s *CandlepinHelpersTest) TestContentOverridesForRepo() {
Value: utils.Ptr("0"),
})
}

func (s *CandlepinHelpersTest) TestContentOverridesForExtendedReleaseRepo() {
templateUUID := "template-uuid-123"
pulpContentPath := "/pulp"

eusRepo := api.RepositoryResponse{
OrgID: config.RedHatOrg,
UUID: "eus-repo-uuid",
Name: "RHEL 9.4 BaseOS EUS",
Label: "rhel-9.4-for-x86_64-baseos-eus-rpms",
URL: "https://cdn.redhat.com/content/eus/rhel9/9.4/x86_64/baseos/os/",
ExtendedRelease: "eus",
ExtendedReleaseVersion: "9.4",
Origin: config.OriginRedHat,
LastSnapshot: utils.Ptr(api.SnapshotResponse{}),
ModuleHotfixes: false,
}

overrides, err := ContentOverridesForRepo(config.RedHatDomainName, templateUUID, pulpContentPath, eusRepo)
assert.NoError(s.T(), err)
assert.Len(s.T(), overrides, 3)

normalizedLabel := "rhel-9-for-x86_64-baseos-eus-rpms"

assert.Contains(s.T(), overrides, caliri.ContentOverrideDTO{
Name: utils.Ptr("sslcacert"),
ContentLabel: &normalizedLabel,
Value: utils.Ptr(" "),
})
assert.Contains(s.T(), overrides, caliri.ContentOverrideDTO{
Name: utils.Ptr("sslverifystatus"),
ContentLabel: &normalizedLabel,
Value: utils.Ptr("0"),
})

expectedPath := "/pulp/cs-redhat/templates/template-uuid-123/content/eus/rhel9/9.4/x86_64/baseos/os"
assert.Contains(s.T(), overrides, caliri.ContentOverrideDTO{
Name: utils.Ptr("baseurl"),
ContentLabel: &normalizedLabel,
Value: &expectedPath,
})
}
2 changes: 1 addition & 1 deletion pkg/tasks/update_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (ur *UpdateRepository) UpdateContentOverrides() error {
if err != nil {
return err
}
expected, err := ContentOverridesForRepo(ur.orgID, ur.domainName, template.UUID, path, ur.repoConfig)
expected, err := ContentOverridesForRepo(ur.domainName, template.UUID, path, ur.repoConfig)
if err != nil {
return fmt.Errorf("could not generate overrides %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/tasks/update_template_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func (t *UpdateTemplateContent) RunCandlepin(env *caliri.EnvironmentDTO) error {
return err
}

overrideDtos, err := GenOverrideDTO(t.ctx, t.daoReg, t.orgId, t.domainName, rhContentPath, t.template)
overrideDtos, err := GenOverrideDTO(t.ctx, t.daoReg, t.orgId, t.domainName, t.rhDomainName, rhContentPath, t.template)
if err != nil {
return err
}
Expand Down