-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dnfjson: skip TestDepsolver() if no osbuild-depsolve-dnf is installed #321
Conversation
fecdf93
to
7ffefb9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. The tests run with -force-dnf
so we won't accidentally pass if it's missing :)
Maybe we should remove the
aaah yeah the comment matches my initial idea and then I thought it might be better to set the the default so that, when (if) it fails, you get an error that shows the primary default location. I'm not sure which is better. |
Thanks, I think that makes sense, I updated the PR.
I have no strong opinion either way, I pushed a small commit that makes |
Do not fail if `osbuild-depsolve-dnf` is missing.
As suggested by Achilleas this commit removes the dnfInstalled() helper as it's now redundant with the new findDepsolveDnf() check (the osbuild-depsolve-dnf package should depend on libdnf).
0c664d0
to
b94540e
Compare
We don't want this. It makes it impossible (or harder) to set up the solver externally with a depsolver in a non-standard location. For example, this should be possible: solver := NewBaseSolver(cacheDir)
solver.SetDNFJSONPath("/some/odd/path/to/solver") without having So there's a question now about what
EDIT: Oh... Lines 639 to 641 in 721b201
Just set it to an empty slice then. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #321 (comment)
b94540e
to
02ef207
Compare
[..] Thank you, that is an interesting use-case and I have no considered it. I tweaked the PR slightly to run the findDepsolverDnf later. This seems to be the most minimal change and I pushed it. But below another idea if you prefer to detect the missing dnfjson early :) If we don't want this and make any detection of missing dnfjson part of the constructor I wonder if it would make sense to change the signature of diff --git a/pkg/dnfjson/dnfjson.go b/pkg/dnfjson/dnfjson.go
index 9505e09b3..d11ce164a 100644
--- a/pkg/dnfjson/dnfjson.go
+++ b/pkg/dnfjson/dnfjson.go
@@ -61,13 +61,24 @@ func findDepsolveDnf() (string, error) {
return "", fmt.Errorf("cannot find required osbuild-depsolve-dnf in any of %q", depSolveDnfPaths)
}
+type SolverOptions struct {
+ DNFJsonPath string
+}
+
// Create a new unconfigured BaseSolver (without platform information). It can
// be used to create configured Solver instances with the NewWithConfig()
// method.
-func NewBaseSolver(cacheDir string) (*BaseSolver, error) {
- depsolveDnf, err := findDepsolveDnf()
- if err != nil {
- return nil, err
+func NewBaseSolver(cacheDir string, opts *SolverOptions) (*BaseSolver, error) {
+ if opts == nil {
+ opts = &SolverOptions{}
+ }
+ depsolveDnf := opts.DNFJsonPath
+ if depsolveDnf == "" {
+ foundSolver, err := findDepsolveDnf()
+ if err != nil {
+ return nil, err
+ }
+ depsolveDnf = foundSolver
}
return &BaseSolver{
cache: newRPMCache(cacheDir, 1024*1024*1024), // 1 GiB
@@ -135,7 +146,7 @@ type Solver struct {
// Create a new Solver with the given configuration. Initialising a Solver also loads system subscription information.
func NewSolver(modulePlatformID, releaseVer, arch, distro, cacheDir string) (*Solver, error) {
- s, err := NewBaseSolver(cacheDir)
+ s, err := NewBaseSolver(cacheDir, nil)
if err != nil {
return nil, err
} or is an API break like this too annoying? |
Not that annoying. We'll have to change all the calls in composer and bib when we pull in the change but it's not that much work. There's an interesting use case that gets a bit dirty when you want to init the Solver without a solver though (either because you don't intend to use it but need an instance for a test or because you might want to "discover" the solver path later), where the caller would have to do something like: NewBaseSolver(cacheDir, &SolverOptions{DNFJsonPath: "NOTEMPTY"}) and then change it. Would we also add the options to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current state LGTM
Do not fail if
osbuild-depsolve-dnf
is missing.It also fixes
dnfjson.go
so that the comment (and I think intention) matches the code :)