rpmmd: add Repositories list to PackageSet struct
Attach the repository configurations that are specific to a package set directly on the PackageSet object. This simplifies the Depsolve() signature and avoids requiring a `nil` when no additional repositories are required. More importantly, it makes associating repositories to package sets explicit, no longer relying on matching array indices or map keys.
This commit is contained in:
parent
1c4d8f9988
commit
86536f11e7
10 changed files with 72 additions and 80 deletions
|
|
@ -87,16 +87,16 @@ func NewSolver(modulePlatformID string, releaseVer string, arch string, cacheDir
|
|||
}
|
||||
|
||||
// Depsolve the given packages with explicit excludes using the given configuration and repos
|
||||
func Depsolve(pkgSets []rpmmd.PackageSet, repos []rpmmd.RepoConfig, psRepos [][]rpmmd.RepoConfig, modulePlatformID string, releaseVer string, arch string, cacheDir string) (*DepsolveResult, error) {
|
||||
return NewSolver(modulePlatformID, releaseVer, arch, cacheDir).Depsolve(pkgSets, repos, psRepos)
|
||||
func Depsolve(pkgSets []rpmmd.PackageSet, repos []rpmmd.RepoConfig, modulePlatformID string, releaseVer string, arch string, cacheDir string) (*DepsolveResult, error) {
|
||||
return NewSolver(modulePlatformID, releaseVer, arch, cacheDir).Depsolve(pkgSets, repos)
|
||||
}
|
||||
|
||||
// Depsolve the list of required package sets with explicit excludes using
|
||||
// the given repositories. Each package set is depsolved as a separate
|
||||
// transactions in a chain. It returns a list of all packages (with solved
|
||||
// dependencies) that will be installed into the system.
|
||||
func (s *Solver) Depsolve(pkgSets []rpmmd.PackageSet, repos []rpmmd.RepoConfig, psRepos [][]rpmmd.RepoConfig) (*DepsolveResult, error) {
|
||||
req, repoMap, err := s.makeDepsolveRequest(pkgSets, repos, psRepos)
|
||||
func (s *Solver) Depsolve(pkgSets []rpmmd.PackageSet, baseRepos []rpmmd.RepoConfig) (*DepsolveResult, error) {
|
||||
req, repoMap, err := s.makeDepsolveRequest(pkgSets, baseRepos)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -205,11 +205,7 @@ type repoConfig struct {
|
|||
// NOTE: Due to implementation limitations of DNF and dnf-json, each package set
|
||||
// in the chain must use all of the repositories used by its predecessor.
|
||||
// An error is returned if this requirement is not met.
|
||||
func (s *Solver) makeDepsolveRequest(pkgSets []rpmmd.PackageSet, repoConfigs []rpmmd.RepoConfig, pkgsetsRepos [][]rpmmd.RepoConfig) (*Request, map[string]rpmmd.RepoConfig, error) {
|
||||
// pkgsetsRepos must either be nil (empty) or the same length as the pkgSets array
|
||||
if len(pkgsetsRepos) > 0 && len(pkgSets) != len(pkgsetsRepos) {
|
||||
return nil, nil, fmt.Errorf("depsolve: the number of package set repository configurations (%d) does not match the number of package sets (%d)", len(pkgsetsRepos), len(pkgSets))
|
||||
}
|
||||
func (s *Solver) makeDepsolveRequest(pkgSets []rpmmd.PackageSet, baseRepos []rpmmd.RepoConfig) (*Request, map[string]rpmmd.RepoConfig, error) {
|
||||
|
||||
// dedupe repository configurations but maintain order
|
||||
// the order in which repositories are added to the request affects the
|
||||
|
|
@ -218,17 +214,15 @@ func (s *Solver) makeDepsolveRequest(pkgSets []rpmmd.PackageSet, repoConfigs []r
|
|||
rpmRepoMap := make(map[string]rpmmd.RepoConfig)
|
||||
|
||||
// These repo IDs will be used for all transactions in the chain
|
||||
baseRepoIDs := make([]string, len(repoConfigs))
|
||||
for idx, repo := range repoConfigs {
|
||||
baseRepoIDs := make([]string, len(baseRepos))
|
||||
for idx, repo := range baseRepos {
|
||||
id := repo.Hash()
|
||||
rpmRepoMap[id] = repo
|
||||
baseRepoIDs[idx] = id
|
||||
repos = append(repos, repo)
|
||||
}
|
||||
|
||||
// extra repositories defined for specific package sets
|
||||
for _, jobRepos := range pkgsetsRepos {
|
||||
for _, repo := range jobRepos {
|
||||
for _, ps := range pkgSets {
|
||||
for _, repo := range ps.Repositories {
|
||||
id := repo.Hash()
|
||||
if _, ok := rpmRepoMap[id]; !ok {
|
||||
rpmRepoMap[id] = repo
|
||||
|
|
@ -245,12 +239,7 @@ func (s *Solver) makeDepsolveRequest(pkgSets []rpmmd.PackageSet, repoConfigs []r
|
|||
RepoIDs: baseRepoIDs, // due to its capacity, the slice will be copied when appended to
|
||||
}
|
||||
|
||||
if len(pkgsetsRepos) == 0 {
|
||||
// nothing to do
|
||||
continue
|
||||
}
|
||||
|
||||
for _, jobRepo := range pkgsetsRepos[dsIdx] {
|
||||
for _, jobRepo := range pkgSet.Repositories {
|
||||
transactions[dsIdx].RepoIDs = append(transactions[dsIdx].RepoIDs, jobRepo.Hash())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ func TestDepsolver(t *testing.T) {
|
|||
{ // single depsolve
|
||||
pkgsets := []rpmmd.PackageSet{{Include: []string{"kernel", "vim-minimal", "tmux", "zsh"}}} // everything you'll ever need
|
||||
|
||||
deps, err := solver.Depsolve(pkgsets, []rpmmd.RepoConfig{s.RepoConfig}, nil)
|
||||
deps, err := solver.Depsolve(pkgsets, []rpmmd.RepoConfig{s.RepoConfig})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ func TestDepsolver(t *testing.T) {
|
|||
{Include: []string{"kernel"}},
|
||||
{Include: []string{"vim-minimal", "tmux", "zsh"}},
|
||||
}
|
||||
deps, err := solver.Depsolve(pkgsets, []rpmmd.RepoConfig{s.RepoConfig}, nil)
|
||||
deps, err := solver.Depsolve(pkgsets, []rpmmd.RepoConfig{s.RepoConfig})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -48,7 +48,8 @@ func TestDepsolver(t *testing.T) {
|
|||
{Include: []string{"kernel"}},
|
||||
{Include: []string{"vim-minimal", "tmux", "zsh"}},
|
||||
}
|
||||
deps, err := solver.Depsolve(pkgsets, []rpmmd.RepoConfig{s.RepoConfig}, [][]rpmmd.RepoConfig{nil, {s.RepoConfig}})
|
||||
pkgsets[1].Repositories = []rpmmd.RepoConfig{s.RepoConfig}
|
||||
deps, err := solver.Depsolve(pkgsets, []rpmmd.RepoConfig{s.RepoConfig})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -123,11 +124,11 @@ func TestMakeDepsolveRequest(t *testing.T) {
|
|||
Exclude: []string{"pkg2"},
|
||||
},
|
||||
{
|
||||
Include: []string{"pkg3"},
|
||||
Include: []string{"pkg3"},
|
||||
Repositories: []rpmmd.RepoConfig{userRepo},
|
||||
},
|
||||
},
|
||||
repos: []rpmmd.RepoConfig{baseOS, appstream},
|
||||
packageSetsRepos: [][]rpmmd.RepoConfig{nil, {userRepo}},
|
||||
repos: []rpmmd.RepoConfig{baseOS, appstream},
|
||||
args: []transactionArgs{
|
||||
{
|
||||
PackageSpecs: []string{"pkg1"},
|
||||
|
|
@ -201,14 +202,15 @@ func TestMakeDepsolveRequest(t *testing.T) {
|
|||
Exclude: []string{"pkg2"},
|
||||
},
|
||||
{
|
||||
Include: []string{"pkg3"},
|
||||
Include: []string{"pkg3"},
|
||||
Repositories: []rpmmd.RepoConfig{userRepo},
|
||||
},
|
||||
{
|
||||
Include: []string{"pkg4"},
|
||||
Include: []string{"pkg4"},
|
||||
Repositories: []rpmmd.RepoConfig{userRepo},
|
||||
},
|
||||
},
|
||||
repos: []rpmmd.RepoConfig{baseOS, appstream},
|
||||
packageSetsRepos: [][]rpmmd.RepoConfig{nil, {userRepo}, {userRepo}},
|
||||
repos: []rpmmd.RepoConfig{baseOS, appstream},
|
||||
args: []transactionArgs{
|
||||
{
|
||||
PackageSpecs: []string{"pkg1"},
|
||||
|
|
@ -251,14 +253,15 @@ func TestMakeDepsolveRequest(t *testing.T) {
|
|||
Exclude: []string{"pkg2"},
|
||||
},
|
||||
{
|
||||
Include: []string{"pkg3"},
|
||||
Include: []string{"pkg3"},
|
||||
Repositories: []rpmmd.RepoConfig{userRepo},
|
||||
},
|
||||
{
|
||||
Include: []string{"pkg4"},
|
||||
Include: []string{"pkg4"},
|
||||
Repositories: []rpmmd.RepoConfig{userRepo, userRepo2},
|
||||
},
|
||||
},
|
||||
repos: []rpmmd.RepoConfig{baseOS, appstream},
|
||||
packageSetsRepos: [][]rpmmd.RepoConfig{nil, {userRepo}, {userRepo, userRepo2}},
|
||||
repos: []rpmmd.RepoConfig{baseOS, appstream},
|
||||
args: []transactionArgs{
|
||||
{
|
||||
PackageSpecs: []string{"pkg1"},
|
||||
|
|
@ -305,17 +308,18 @@ func TestMakeDepsolveRequest(t *testing.T) {
|
|||
Exclude: []string{"pkg2"},
|
||||
},
|
||||
{
|
||||
Include: []string{"pkg3"},
|
||||
Include: []string{"pkg3"},
|
||||
Repositories: []rpmmd.RepoConfig{userRepo},
|
||||
},
|
||||
{
|
||||
Include: []string{"pkg4"},
|
||||
Include: []string{"pkg4"},
|
||||
Repositories: []rpmmd.RepoConfig{userRepo2},
|
||||
},
|
||||
},
|
||||
repos: []rpmmd.RepoConfig{baseOS, appstream},
|
||||
packageSetsRepos: [][]rpmmd.RepoConfig{nil, {userRepo}, {userRepo2}},
|
||||
err: true,
|
||||
repos: []rpmmd.RepoConfig{baseOS, appstream},
|
||||
err: true,
|
||||
},
|
||||
// Error: 3 transactions but only 1 packageSetsRepos
|
||||
// Error: 3 transactions but last one doesn't specify user repos in 2nd
|
||||
{
|
||||
packageSets: []rpmmd.PackageSet{
|
||||
{
|
||||
|
|
@ -323,21 +327,21 @@ func TestMakeDepsolveRequest(t *testing.T) {
|
|||
Exclude: []string{"pkg2"},
|
||||
},
|
||||
{
|
||||
Include: []string{"pkg3"},
|
||||
Include: []string{"pkg3"},
|
||||
Repositories: []rpmmd.RepoConfig{userRepo, userRepo2},
|
||||
},
|
||||
{
|
||||
Include: []string{"pkg4"},
|
||||
},
|
||||
},
|
||||
repos: []rpmmd.RepoConfig{baseOS, appstream},
|
||||
packageSetsRepos: [][]rpmmd.RepoConfig{{userRepo, userRepo2}},
|
||||
err: true,
|
||||
repos: []rpmmd.RepoConfig{baseOS, appstream},
|
||||
err: true,
|
||||
},
|
||||
}
|
||||
solver := NewSolver("", "", "", "")
|
||||
for idx, tt := range tests {
|
||||
t.Run(fmt.Sprintf("%d", idx), func(t *testing.T) {
|
||||
req, _, err := solver.makeDepsolveRequest(tt.packageSets, tt.repos, tt.packageSetsRepos)
|
||||
req, _, err := solver.makeDepsolveRequest(tt.packageSets, tt.repos)
|
||||
if tt.err {
|
||||
assert.NotNilf(t, err, "expected an error, but got 'nil' instead")
|
||||
assert.Nilf(t, req, "got non-nill request, but expected an error")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue