Fix module support in blueprints/depsolve

This adds the modules to the list of package specs to be depsolved. It
includes a new function to build the version glob package string, as
well as tests for the new function and for depsolving with modules in
the blueprint.
This commit is contained in:
Brian C. Lane 2020-01-30 14:44:46 -08:00 committed by Tom Gundersen
parent 248f0a6d55
commit a84593645b
2 changed files with 37 additions and 12 deletions

View file

@ -1829,6 +1829,17 @@ func (api *API) fetchPackageList() (rpmmd.PackageList, error) {
return packages, err
}
func getPkgNameGlob(pkg blueprint.Package) string {
// If a package has version "*" the package name suffix must be equal to "-*-*.*"
// Using just "-*" would find any other package containing the package name
if pkg.Version == "*" {
return fmt.Sprintf("%s-*-*.*", pkg.Name)
} else if pkg.Version != "" {
return fmt.Sprintf("%s-%s", pkg.Name, pkg.Version)
}
return pkg.Name
}
func (api *API) depsolveBlueprint(bp *blueprint.Blueprint, outputType, arch string, clean bool) ([]rpmmd.PackageSpec, []rpmmd.PackageSpec, map[string]string, error) {
var repos []rpmmd.RepoConfig
for _, repo := range api.distro.Repositories(api.arch) {
@ -1837,16 +1848,12 @@ func (api *API) depsolveBlueprint(bp *blueprint.Blueprint, outputType, arch stri
for _, source := range api.store.GetAllSources() {
repos = append(repos, source.RepoConfig())
}
specs := make([]string, len(bp.Packages))
for i, pkg := range bp.Packages {
specs[i] = pkg.Name
// If a package has version "*" the package name suffix must be equal to "-*-*.*"
// Using just "-*" would find any other package containing the package name
if pkg.Version != "" && pkg.Version != "*" {
specs[i] += "-" + pkg.Version
} else if pkg.Version == "*" {
specs[i] += "-*-*.*"
}
var specs []string
for _, pkg := range bp.Packages {
specs = append(specs, getPkgNameGlob(pkg))
}
for _, mod := range bp.Modules {
specs = append(specs, getPkgNameGlob(mod))
}
excludeSpecs := []string{}
if outputType != "" {

View file

@ -327,20 +327,38 @@ func TestBlueprintsChanges(t *testing.T) {
test.SendHTTP(api, true, "DELETE", "/api/v0/blueprints/delete/"+id, ``)
}
func TestGetPkgNameGlob(t *testing.T) {
var cases = []struct {
pkg blueprint.Package
result string
}{
{blueprint.Package{Name: "dep-package1", Version: "*"}, "dep-package1-*-*.*"},
{blueprint.Package{Name: "dep-package2", Version: "1.23"}, "dep-package2-1.23"},
{blueprint.Package{Name: "dep-package3", Version: ""}, "dep-package3"},
}
for _, c := range cases {
result := getPkgNameGlob(c.pkg)
if result != c.result {
t.Fatalf("getPkgNameGlob failed: %s != %s", result, c.result)
}
}
}
func TestBlueprintsDepsolve(t *testing.T) {
var cases = []struct {
Fixture rpmmd_mock.FixtureGenerator
ExpectedStatus int
ExpectedJSON string
}{
{rpmmd_mock.BaseFixture, http.StatusOK, `{"blueprints":[{"blueprint":{"name":"test","description":"Test","version":"0.0.1","packages":[{"name":"dep-package1","version":"*"}],"groups":[],"modules":[]},"dependencies":[{"name":"dep-package3","epoch":0,"version":"3.0.3","release":"1.fc30","arch":"x86_64"},{"name":"dep-package1","epoch":0,"version":"1.33","release":"2.fc30","arch":"x86_64"},{"name":"dep-package2","epoch":0,"version":"2.9","release":"1.fc30","arch":"x86_64"}]}],"errors":[]}`},
{rpmmd_mock.BaseFixture, http.StatusOK, `{"blueprints":[{"blueprint":{"name":"test","description":"Test","version":"0.0.1","packages":[{"name":"dep-package1","version":"*"}],"groups":[],"modules":[{"name":"dep-package3","version":"*"}]},"dependencies":[{"name":"dep-package3","epoch":0,"version":"3.0.3","release":"1.fc30","arch":"x86_64"},{"name":"dep-package1","epoch":0,"version":"1.33","release":"2.fc30","arch":"x86_64"},{"name":"dep-package2","epoch":0,"version":"2.9","release":"1.fc30","arch":"x86_64"}]}],"errors":[]}`},
{rpmmd_mock.NonExistingPackage, http.StatusBadRequest, `{"status":false,"errors":[{"id":"BlueprintsError","msg":"test: DNF error occured: MarkingErrors: Error occurred when marking packages for installation: Problems in request:\nmissing packages: fash"}]}`},
{rpmmd_mock.BadDepsolve, http.StatusBadRequest, `{"status":false,"errors":[{"id":"BlueprintsError","msg":"test: DNF error occured: DepsolveError: There was a problem depsolving ['go2rpm']: \n Problem: conflicting requests\n - nothing provides askalono-cli needed by go2rpm-1-4.fc31.noarch"}]}`},
}
for _, c := range cases {
api, _ := createWeldrAPI(c.Fixture)
test.SendHTTP(api, false, "POST", "/api/v0/blueprints/new", `{"name":"test","description":"Test","packages":[{"name":"dep-package1","version":"*"}],"version":"0.0.0"}`)
test.SendHTTP(api, false, "POST", "/api/v0/blueprints/new", `{"name":"test","description":"Test","packages":[{"name":"dep-package1","version":"*"}],"modules":[{"name":"dep-package3","version":"*"}],"version":"0.0.0"}`)
test.TestRoute(t, api, false, "GET", "/api/v0/blueprints/depsolve/test", ``, c.ExpectedStatus, c.ExpectedJSON)
test.SendHTTP(api, false, "DELETE", "/api/v0/blueprints/delete/test", ``)
}