From f8afbe1906b6f12b18b3a439064c6df5d8fea479 Mon Sep 17 00:00:00 2001 From: Ondrej Ezr Date: Tue, 28 Nov 2023 19:39:37 +0100 Subject: [PATCH] rpmmd: add module_hotfixes flag to RepoConfig 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. --- dnf-json | 5 +++ pkg/blueprint/repository_customizations.go | 46 +++++++++++----------- pkg/dnfjson/dnfjson.go | 3 ++ pkg/dnfjson/dnfjson_test.go | 42 +++++++++++++++++++- pkg/osbuild/yum_repos_stage.go | 23 +++++------ pkg/rpmmd/repository.go | 12 +++++- 6 files changed, 96 insertions(+), 35 deletions(-) diff --git a/dnf-json b/dnf-json index 6f6d97f28c..8b8b50d3e3 100755 --- a/dnf-json +++ b/dnf-json @@ -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 diff --git a/pkg/blueprint/repository_customizations.go b/pkg/blueprint/repository_customizations.go index 465e980250..1159f8d76b 100644 --- a/pkg/blueprint/repository_customizations.go +++ b/pkg/blueprint/repository_customizations.go @@ -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$" @@ -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 { diff --git a/pkg/dnfjson/dnfjson.go b/pkg/dnfjson/dnfjson.go index e5123e2180..ef8f7f03c3 100644 --- a/pkg/dnfjson/dnfjson.go +++ b/pkg/dnfjson/dnfjson.go @@ -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(), } @@ -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 @@ -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 diff --git a/pkg/dnfjson/dnfjson_test.go b/pkg/dnfjson/dnfjson_test.go index 75a5ad40b9..f3d84241cf 100644 --- a/pkg/dnfjson/dnfjson_test.go +++ b/pkg/dnfjson/dnfjson_test.go @@ -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"}, @@ -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 @@ -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 { diff --git a/pkg/osbuild/yum_repos_stage.go b/pkg/osbuild/yum_repos_stage.go index 297811865e..cf2995e250 100644 --- a/pkg/osbuild/yum_repos_stage.go +++ b/pkg/osbuild/yum_repos_stage.go @@ -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 diff --git a/pkg/rpmmd/repository.go b/pkg/rpmmd/repository.go index b185864e0c..be264d7c0d 100644 --- a/pkg/rpmmd/repository.go +++ b/pkg/rpmmd/repository.go @@ -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"` } @@ -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"` @@ -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, "") } @@ -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 @@ -245,6 +254,7 @@ func loadRepositoriesFromFile(filename string) (map[string][]RepoConfig, error) CheckGPG: &repo.CheckGPG, RHSM: repo.RHSM, MetadataExpire: repo.MetadataExpire, + ModuleHotfixes: repo.ModuleHotfixes, ImageTypeTags: repo.ImageTypeTags, }