Skip to content

Commit

Permalink
rpmmd: add module_hotfixes flag to RepoConfig
Browse files Browse the repository at this point in the history
Adds module_hotfixes flag to all repo types so it can be used during osbuild.
This enables users to disable modularity filtering on specific repositories.
  • Loading branch information
ezr-ondrej committed Dec 4, 2023
1 parent a39314a commit 508bc58
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 35 deletions.
5 changes: 5 additions & 0 deletions dnf-json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ class Solver():
# we set the expiration to a short time period, rather than 0.
repo.metadata_expire = desc.get("metadata_expire", "20s")

# This option if True disables modularization filtering. Effectively
# disabling modularity for given repository.
if "module_hotfixes" in desc:
repo.module_hotfixes = desc["module_hotfixes"]

return repo

@staticmethod
Expand Down
46 changes: 24 additions & 22 deletions pkg/blueprint/repository_customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ import (
)

type RepositoryCustomization struct {
Id string `json:"id" toml:"id"`
BaseURLs []string `json:"baseurls,omitempty" toml:"baseurls,omitempty"`
GPGKeys []string `json:"gpgkeys,omitempty" toml:"gpgkeys,omitempty"`
Metalink string `json:"metalink,omitempty" toml:"metalink,omitempty"`
Mirrorlist string `json:"mirrorlist,omitempty" toml:"mirrorlist,omitempty"`
Name string `json:"name,omitempty" toml:"name,omitempty"`
Priority *int `json:"priority,omitempty" toml:"priority,omitempty"`
Enabled *bool `json:"enabled,omitempty" toml:"enabled,omitempty"`
GPGCheck *bool `json:"gpgcheck,omitempty" toml:"gpgcheck,omitempty"`
RepoGPGCheck *bool `json:"repo_gpgcheck,omitempty" toml:"repo_gpgcheck,omitempty"`
SSLVerify *bool `json:"sslverify,omitempty" toml:"sslverify,omitempty"`
Filename string `json:"filename,omitempty" toml:"filename,omitempty"`
Id string `json:"id" toml:"id"`
BaseURLs []string `json:"baseurls,omitempty" toml:"baseurls,omitempty"`
GPGKeys []string `json:"gpgkeys,omitempty" toml:"gpgkeys,omitempty"`
Metalink string `json:"metalink,omitempty" toml:"metalink,omitempty"`
Mirrorlist string `json:"mirrorlist,omitempty" toml:"mirrorlist,omitempty"`
Name string `json:"name,omitempty" toml:"name,omitempty"`
Priority *int `json:"priority,omitempty" toml:"priority,omitempty"`
Enabled *bool `json:"enabled,omitempty" toml:"enabled,omitempty"`
GPGCheck *bool `json:"gpgcheck,omitempty" toml:"gpgcheck,omitempty"`
RepoGPGCheck *bool `json:"repo_gpgcheck,omitempty" toml:"repo_gpgcheck,omitempty"`
SSLVerify *bool `json:"sslverify,omitempty" toml:"sslverify,omitempty"`
ModuleHotfixes *bool `json:"module_hotfixes,omitempty" toml:"module_hotfixes,omitempty"`
Filename string `json:"filename,omitempty" toml:"filename,omitempty"`
}

const repoFilenameRegex = "^[\\w.-]{1,250}\\.repo$"
Expand Down Expand Up @@ -117,16 +118,17 @@ func (repo RepositoryCustomization) customRepoToRepoConfig() rpmmd.RepoConfig {
copy(keys, repo.GPGKeys)

repoConfig := rpmmd.RepoConfig{
Id: repo.Id,
BaseURLs: urls,
GPGKeys: keys,
Name: repo.Name,
Metalink: repo.Metalink,
MirrorList: repo.Mirrorlist,
CheckGPG: repo.GPGCheck,
CheckRepoGPG: repo.RepoGPGCheck,
Priority: repo.Priority,
Enabled: repo.Enabled,
Id: repo.Id,
BaseURLs: urls,
GPGKeys: keys,
Name: repo.Name,
Metalink: repo.Metalink,
MirrorList: repo.Mirrorlist,
CheckGPG: repo.GPGCheck,
CheckRepoGPG: repo.RepoGPGCheck,
Priority: repo.Priority,
ModuleHotfixes: repo.ModuleHotfixes,
Enabled: repo.Enabled,
}

if repo.SSLVerify != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/dnfjson/dnfjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func (s *Solver) reposFromRPMMD(rpmRepos []rpmmd.RepoConfig) ([]repoConfig, erro
MirrorList: rr.MirrorList,
GPGKeys: rr.GPGKeys,
MetadataExpire: rr.MetadataExpire,
ModuleHotfixes: rr.ModuleHotfixes,
repoHash: rr.Hash(),
}

Expand Down Expand Up @@ -294,6 +295,7 @@ func (s *Solver) reposFromRPMMD(rpmRepos []rpmmd.RepoConfig) ([]repoConfig, erro
dr.SSLClientKey = secrets.SSLClientKey
dr.SSLClientCert = secrets.SSLClientCert
}

dnfRepos[idx] = dr
}
return dnfRepos, nil
Expand All @@ -315,6 +317,7 @@ type repoConfig struct {
SSLClientKey string `json:"sslclientkey,omitempty"`
SSLClientCert string `json:"sslclientcert,omitempty"`
MetadataExpire string `json:"metadata_expire,omitempty"`
ModuleHotfixes *bool `json:"module_hotfixes,omitempty"`
// set the repo hass from `rpmmd.RepoConfig.Hash()` function
// rather than re-calculating it
repoHash string
Expand Down
42 changes: 41 additions & 1 deletion pkg/dnfjson/dnfjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func TestDepsolver(t *testing.T) {
}

func TestMakeDepsolveRequest(t *testing.T) {

baseOS := rpmmd.RepoConfig{
Name: "baseos",
BaseURLs: []string{"https://example.org/baseos"},
Expand All @@ -86,6 +85,11 @@ func TestMakeDepsolveRequest(t *testing.T) {
Name: "user-repo-2",
BaseURLs: []string{"https://example.org/user-repo-2"},
}
moduleHotfixRepo := rpmmd.RepoConfig{
Name: "module-hotfixes",
BaseURLs: []string{"https://example.org/nginx"},
ModuleHotfixes: common.ToPtr(true),
}
tests := []struct {
packageSets []rpmmd.PackageSet
args []transactionArgs
Expand Down Expand Up @@ -373,6 +377,42 @@ func TestMakeDepsolveRequest(t *testing.T) {
},
err: true,
},
// module hotfixes flag passed
{
packageSets: []rpmmd.PackageSet{
{
Include: []string{"pkg1"},
Repositories: []rpmmd.RepoConfig{baseOS, appstream, moduleHotfixRepo},
},
},
args: []transactionArgs{
{
PackageSpecs: []string{"pkg1"},
RepoIDs: []string{baseOS.Hash(), appstream.Hash(), moduleHotfixRepo.Hash()},
},
},
wantRepos: []repoConfig{
{
ID: baseOS.Hash(),
Name: "baseos",
BaseURLs: []string{"https://example.org/baseos"},
repoHash: "fdc2e5bb6cda8e113308df9396a005b81a55ec00ec29aa0a447952ad4248d803",
},
{
ID: appstream.Hash(),
Name: "appstream",
BaseURLs: []string{"https://example.org/appstream"},
repoHash: "71c280f63a779a8bf53961ec2f15d51d052021de024a4e06ae499b8029701808",
},
{
ID: moduleHotfixRepo.Hash(),
Name: "module-hotfixes",
BaseURLs: []string{"https://example.org/nginx"},
ModuleHotfixes: common.ToPtr(true),
repoHash: "6ab05f54094ff2a0ee86facecae3e75e4065a01cc8caffbbbeb7505c6bfac283",
},
},
},
}
solver := NewSolver("", "", "", "", "")
for idx, tt := range tests {
Expand Down
23 changes: 12 additions & 11 deletions pkg/osbuild/yum_repos_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,18 @@ func repoConfigToYumRepository(repo rpmmd.RepoConfig) YumRepository {
}

yumRepo := YumRepository{
Id: repo.Id,
Name: repo.Name,
Mirrorlist: repo.MirrorList,
Metalink: repo.Metalink,
BaseURLs: urls,
GPGKey: keys,
GPGCheck: repo.CheckGPG,
RepoGPGCheck: repo.CheckRepoGPG,
Enabled: repo.Enabled,
Priority: repo.Priority,
SSLVerify: sslVerify,
Id: repo.Id,
Name: repo.Name,
Mirrorlist: repo.MirrorList,
Metalink: repo.Metalink,
BaseURLs: urls,
GPGKey: keys,
GPGCheck: repo.CheckGPG,
RepoGPGCheck: repo.CheckRepoGPG,
Enabled: repo.Enabled,
Priority: repo.Priority,
SSLVerify: sslVerify,
ModuleHotfixes: repo.ModuleHotfixes,
}

return yumRepo
Expand Down
12 changes: 11 additions & 1 deletion pkg/rpmmd/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type repository struct {
CheckGPG bool `json:"check_gpg,omitempty"`
IgnoreSSL bool `json:"ignore_ssl,omitempty"`
RHSM bool `json:"rhsm,omitempty"`
ModuleHotfixes *bool `json:"module_hotfixes,omitempty"`
MetadataExpire string `json:"metadata_expire,omitempty"`
ImageTypeTags []string `json:"image_type_tags,omitempty"`
}
Expand All @@ -42,6 +43,7 @@ type RepoConfig struct {
Priority *int `json:"priority,omitempty"`
IgnoreSSL *bool `json:"ignore_ssl,omitempty"`
MetadataExpire string `json:"metadata_expire,omitempty"`
ModuleHotfixes *bool `json:"module_hotfixes,omitempty"`
RHSM bool `json:"rhsm,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
ImageTypeTags []string `json:"image_type_tags,omitempty"`
Expand All @@ -58,6 +60,12 @@ func (r *RepoConfig) Hash() string {
bpts := func(b *bool) string {
return fmt.Sprintf("%T", b)
}
bptsIgnoreNil := func(b *bool) string {
if b == nil {
return ""
}
return bts(*b)
}
ats := func(s []string) string {
return strings.Join(s, "")
}
Expand All @@ -69,7 +77,8 @@ func (r *RepoConfig) Hash() string {
bpts(r.CheckRepoGPG)+
bpts(r.IgnoreSSL)+
r.MetadataExpire+
bts(r.RHSM))))
bts(r.RHSM)+
bptsIgnoreNil(r.ModuleHotfixes))))
}

type DistrosRepoConfigs map[string]map[string][]RepoConfig
Expand Down Expand Up @@ -264,6 +273,7 @@ func loadRepositoriesFromFile(filename string) (map[string][]RepoConfig, error)
CheckGPG: &repo.CheckGPG,
RHSM: repo.RHSM,
MetadataExpire: repo.MetadataExpire,
ModuleHotfixes: repo.ModuleHotfixes,
ImageTypeTags: repo.ImageTypeTags,
}

Expand Down

0 comments on commit 508bc58

Please sign in to comment.