Skip to content

Commit

Permalink
dnfjson: allow (optional) field solver in the dnfjson output
Browse files Browse the repository at this point in the history
With the new "dnf5" solver is seems useful to allow the dnfjson
code return what solver was actually used in the transaction.

This commit allows an (optional) "solver" field in the json
that is returned from the dnfjson helper. It does not do more
yet but we should (probably) make it avaialble for the higher
layers too so that it can be e.g. logged.

See also osbuild/osbuild#1776

Co-authored-by: Achilleas Koutsou <[email protected]>
  • Loading branch information
mvo5 and achilleas-k committed Aug 1, 2024
1 parent ff6bd93 commit a8f9e7d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/dnfjson/dnfjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,9 @@ type packageSpecs []PackageSpec
type depsolveResult struct {
Packages packageSpecs `json:"packages"`
Repos map[string]repoConfig `json:"repos"`

// (optional) contains the solver used, e.g. "dnf5"
Solver string `json:"solver"`
}

// Package specification
Expand Down
26 changes: 26 additions & 0 deletions pkg/dnfjson/dnfjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,3 +788,29 @@ exit 1
_, err = run([]string{fakeDnfJsonPath}, &Request{})
assert.EqualError(t, err, `DNF error occurred: InternalError: dnf-json output was empty`)
}

func TestSolverRunWithSolverNoError(t *testing.T) {
tmpdir := t.TempDir()
fakeSolver := `#!/bin/sh -e
cat - > "$0".stdin
echo '{"solver": "zypper"}'
`
fakeSolverPath := filepath.Join(tmpdir, "fake-solver")
err := os.WriteFile(fakeSolverPath, []byte(fakeSolver), 0755) //nolint:gosec
assert.NoError(t, err)

solver := NewSolver("platform:f38", "38", "x86_64", "fedora-38", "/tmp/cache")
solver.dnfJsonCmd = []string{fakeSolverPath}
pkgSpec, repoCfg, err := solver.Depsolve(nil)
assert.NoError(t, err)

// prerequisite check, i.e. ensure our fake was called in the right way
stdin, err := os.ReadFile(fakeSolverPath + ".stdin")
assert.NoError(t, err)
assert.Contains(t, string(stdin), `"command":"depsolve"`)

// adding the "solver" did not cause any issues
assert.NoError(t, err)
assert.Equal(t, 0, len(pkgSpec))
assert.Equal(t, 0, len(repoCfg))
}

0 comments on commit a8f9e7d

Please sign in to comment.