All calls to rpmmd.Depsolve() are now replaced with the equivalent call to solver.Depsolve() (or dnfjson.Depsolve() for one-off calls). Attached an unconfigured dnfjson.BaseSolver to all APIs and server configurations where rpmmd.RPMMD used to be. This BaseSolver instance loads the repository credentials from the system and carries the cache directory, much like the RPMMD field used to do. The BaseSolver is used to create an initialised (configured) solver with the platform variables (module platform ID, release ver, and arch) before running a Depsolve() or FetchMetadata() using the NewWithConfig() method. The FillDependencies() call in the modulesInfoHandler() of the weldr API has been replaced by a direct call to the Depsolve() function. This rpmmd function was only used here. Replacing the rpmmd.Depsolve() call in rpmmd.FillDependencies() with dnfjson.Depsolve() would have created an import cycle. The FillDependencies() function could have been moved to dnfjson, but since it's only used in one place, moving the one-line function body into the caller is ok. For testing: The mock-dnf-json is compiled to a temporary directory during test initialisation and used for each Depsolve() or FetchMetadata() call. The weldr API tests now use the mock dnfjson. Each rpmmd_mock.Fixture now also has a dnfjson_mock.ResponseGenerator. All API calls in the tests use the proper functions from dnfjson and only the dnf-json script is mocked. Because of this, some of the expected results in responses_test had to be changed to match correct behaviour: - The "builds" array of each package in the result of a module or project list is now sorted by version number (ascending) because we sort the package list in the result of dnfjson by NVR. - 'check_gpg: true' is added to the expected response of the depsolve test. The repository configs in the test weldr API specify 'CheckGPG: True', but the mock responses returned it as false, so the expected result didn't need to include it. Since now we're using the actual dnfjson code to convert the mock response to the internal structure, the repository settings are correctly used to set flag to true for each package associated with that repository. - The word "occurred" was mistyped as "occured" in rpmmd and is now fixed in dnfjson.
91 lines
3.4 KiB
Go
91 lines
3.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/osbuild/osbuild-composer/internal/dnfjson"
|
|
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
|
"github.com/osbuild/osbuild-composer/internal/worker"
|
|
"github.com/osbuild/osbuild-composer/internal/worker/clienterrors"
|
|
)
|
|
|
|
type DepsolveJobImpl struct {
|
|
RPMMDCache string
|
|
}
|
|
|
|
// depsolve each package set in the pacakgeSets map. The repositories defined
|
|
// in repos are used for all package sets, whereas the repositories in
|
|
// packageSetsRepos are only used for the package set with the same name
|
|
// (matching map keys).
|
|
func (impl *DepsolveJobImpl) depsolve(packageSetsChains map[string][]string, packageSets map[string]rpmmd.PackageSet, repos []rpmmd.RepoConfig, packageSetsRepos map[string][]rpmmd.RepoConfig, modulePlatformID, arch, releasever string) (map[string][]rpmmd.PackageSpec, error) {
|
|
solver := dnfjson.NewSolver(modulePlatformID, releasever, arch, impl.RPMMDCache)
|
|
depsolvedSets := make(map[string][]rpmmd.PackageSpec)
|
|
psRepos := make([][]rpmmd.RepoConfig, 0)
|
|
|
|
// first depsolve package sets that are part of a chain
|
|
for specName, setNames := range packageSetsChains {
|
|
pkgSets := make([]rpmmd.PackageSet, len(setNames))
|
|
for idx, pkgSetName := range setNames {
|
|
pkgSets[idx] = packageSets[pkgSetName]
|
|
psRepos = append(psRepos, packageSetsRepos[pkgSetName]) // will be nil if it doesn't exist
|
|
delete(packageSets, pkgSetName) // will be depsolved here: remove from map
|
|
}
|
|
res, err := solver.ChainDepsolve(pkgSets, repos, psRepos)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
depsolvedSets[specName] = res.Dependencies
|
|
}
|
|
|
|
// depsolve the rest of the package sets
|
|
for name, pkgSet := range packageSets {
|
|
res, err := solver.ChainDepsolve([]rpmmd.PackageSet{pkgSet}, repos, [][]rpmmd.RepoConfig{packageSetsRepos[name]})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
depsolvedSets[name] = res.Dependencies
|
|
}
|
|
return depsolvedSets, nil
|
|
}
|
|
|
|
func (impl *DepsolveJobImpl) Run(job worker.Job) error {
|
|
logWithId := logrus.WithField("jobId", job.Id())
|
|
var args worker.DepsolveJob
|
|
err := job.Args(&args)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var result worker.DepsolveJobResult
|
|
result.PackageSpecs, err = impl.depsolve(args.PackageSetsChains, args.PackageSets, args.Repos, args.PackageSetsRepos, args.ModulePlatformID, args.Arch, args.Releasever)
|
|
if err != nil {
|
|
switch e := err.(type) {
|
|
case *rpmmd.DNFError:
|
|
// Error originates from dnf-json (the http call dnf-json wasn't StatusOK)
|
|
switch e.Kind {
|
|
case "DepsolveError":
|
|
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorDNFDepsolveError, err.Error())
|
|
case "MarkingErrors":
|
|
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorDNFMarkingErrors, err.Error())
|
|
default:
|
|
// This still has the kind/reason format but a kind that's returned
|
|
// by dnf-json and not explicitly handled here.
|
|
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorDNFOtherError, err.Error())
|
|
logWithId.Errorf("Unhandled dnf-json error in depsolve job: %v", err)
|
|
}
|
|
case error:
|
|
// Error originates from internal/rpmmd, not from dnf-json
|
|
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorRPMMDError, err.Error())
|
|
logWithId.Errorf("rpmmd error in depsolve job: %v", err)
|
|
}
|
|
}
|
|
|
|
err = job.Update(&result)
|
|
if err != nil {
|
|
return fmt.Errorf("Error reporting job result: %v", err)
|
|
}
|
|
|
|
return nil
|
|
}
|