Skip to content

Commit

Permalink
depsolve: add modules support
Browse files Browse the repository at this point in the history
Since the modularity PR landed in `osbuild` the depsolve result now
contains a `modules` key with data if modules were resolved.

Add the appropriate structures to the depsolve result, without
propagating them into rpmmd for now.

Also adds a quick test for the internal `depsolveResult` type
deserialization to ensure it understands some JSON serialized data that
contains a `modules` key.

Signed-off-by: Simon de Vlieger <[email protected]>
  • Loading branch information
supakeen committed Jan 24, 2025
1 parent b49e4a5 commit 58bc61d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/dnfjson/dnfjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,10 +722,12 @@ type transactionArgs struct {
}

type packageSpecs []PackageSpec
type moduleSpecs map[string]ModuleSpec

type depsolveResult struct {
Packages packageSpecs `json:"packages"`
Repos map[string]repoConfig `json:"repos"`
Modules moduleSpecs `json:"modules"`

// (optional) contains the solver used, e.g. "dnf5"
Solver string `json:"solver,omitempty"`
Expand All @@ -748,6 +750,29 @@ type PackageSpec struct {
Secrets string `json:"secrets,omitempty"`
}

// Module specification
type ModuleSpec struct {
ModuleConfigFile ModuleConfigFile `json:"module-file"`
FailsafeFile ModuleFailsafeFile `json:"failsafe-file"`
}

type ModuleConfigFile struct {
Path string `json:"path"`
Data ModuleConfigData `json:"data"`
}

type ModuleConfigData struct {
Name string `json:"name"`
Stream string `json:"stream"`
Profiles []string `json:"profiles"`
State string `json:"state"`
}

type ModuleFailsafeFile struct {
Path string `json:"path"`
Data string `json:"string"`
}

// dnf-json error structure
type Error struct {
Kind string `json:"kind"`
Expand Down
15 changes: 15 additions & 0 deletions pkg/dnfjson/dnfjson_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dnfjson

import (
"bytes"
"encoding/json"
"flag"
"fmt"
Expand Down Expand Up @@ -887,3 +888,17 @@ echo '{"solver": "zypper"}'
assert.Equal(t, 0, len(res.Packages))
assert.Equal(t, 0, len(res.Repos))
}

func TestDepsolveResultWithModulesKey(t *testing.T) {
// quick test that verifies that `depsolveResult` understands JSON that contains
// a `modules` key
data := []byte(`{"modules": {}}`)

var result depsolveResult
dec := json.NewDecoder(bytes.NewReader(data))
dec.DisallowUnknownFields()

err := dec.Decode(&result)

assert.NoError(t, err)
}

0 comments on commit 58bc61d

Please sign in to comment.