rpmmd: require the path to dnf-json to be passed in
RPMMD had hardcoded path to dnf-json helper. This required all executables using RPMMD to be run in the directory where dnf-json was located. This commit makes RPMMD take the path to dnf-json as an argument. This allows its consumers to specify whichever path they want. Not a functional change
This commit is contained in:
parent
5b2c06b3da
commit
b93df4b524
5 changed files with 20 additions and 14 deletions
|
|
@ -87,7 +87,9 @@ func main() {
|
|||
log.Fatal("CACHE_DIRECTORY is not set. Is the service file missing CacheDirectory=?")
|
||||
}
|
||||
|
||||
rpm := rpmmd.NewRPMMD(path.Join(cacheDirectory, "rpmmd"))
|
||||
// osbuild-composer must be run in /usr/libexec/osbuild-composer directory,
|
||||
// therefore use ./dnf-json as the path to dnf-json.
|
||||
rpm := rpmmd.NewRPMMD(path.Join(cacheDirectory, "rpmmd"), "./dnf-json")
|
||||
|
||||
distros, err := distro.NewRegistry(fedora31.New(), fedora32.New(), rhel8.New())
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ func TestFetchChecksum(t *testing.T) {
|
|||
BaseURL: fmt.Sprintf("file://%s", dir),
|
||||
IgnoreSSL: true,
|
||||
}
|
||||
rpmMetadata := rpmmd.NewRPMMD(path.Join(dir, "rpmmd"))
|
||||
|
||||
rpmMetadata := rpmmd.NewRPMMD(path.Join(dir, "rpmmd"), "./dnf-json")
|
||||
_, c, err := rpmMetadata.FetchMetadata([]rpmmd.RepoConfig{repoCfg}, "platform:f31", "x86_64")
|
||||
assert.Nilf(t, err, "Failed to fetch checksum: %v", err)
|
||||
assert.NotEqual(t, "", c["repo"], "The checksum is empty")
|
||||
|
|
@ -58,7 +59,8 @@ func TestCrossArchDepsolve(t *testing.T) {
|
|||
dir, err := ioutil.TempDir("/tmp", "rpmmd-test-")
|
||||
require.Nilf(t, err, "Failed to create tmp dir for depsolve test: %v", err)
|
||||
defer os.RemoveAll(dir)
|
||||
rpm := rpmmd.NewRPMMD(dir)
|
||||
|
||||
rpm := rpmmd.NewRPMMD(dir, "./dnf-json")
|
||||
|
||||
repos, err := rpmmd.LoadRepositories([]string{repoDir}, distroStruct.Name())
|
||||
require.NoErrorf(t, err, "Failed to LoadRepositories %v", distroStruct.Name())
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ func main() {
|
|||
panic("os.UserHomeDir(): " + err.Error())
|
||||
}
|
||||
|
||||
rpmmd := rpmmd.NewRPMMD(path.Join(home, ".cache/osbuild-composer/rpmmd"))
|
||||
rpmmd := rpmmd.NewRPMMD(path.Join(home, ".cache/osbuild-composer/rpmmd"), "./dnf-json")
|
||||
packageSpecs, checksums, err := rpmmd.Depsolve(packages, excludePkgs, repos, d.ModulePlatformID(), arch.Name())
|
||||
if err != nil {
|
||||
panic("Could not depsolve: " + err.Error())
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ func main() {
|
|||
if err != nil {
|
||||
panic("os.UserHomeDir(): " + err.Error())
|
||||
}
|
||||
rpmmd := rpmmd.NewRPMMD(path.Join(homeDir, ".cache/osbuild-composer/rpmmd"))
|
||||
rpmmd := rpmmd.NewRPMMD(path.Join(homeDir, ".cache/osbuild-composer/rpmmd"), "./dnf-json")
|
||||
|
||||
s := store.New(&cwd, a, nil)
|
||||
if s == nil {
|
||||
|
|
|
|||
|
|
@ -232,7 +232,7 @@ func LoadRepositories(confPaths []string, distro string) (map[string][]RepoConfi
|
|||
return repoConfigs, nil
|
||||
}
|
||||
|
||||
func runDNF(command string, arguments interface{}, result interface{}) error {
|
||||
func runDNF(dnfJsonPath string, command string, arguments interface{}, result interface{}) error {
|
||||
var call = struct {
|
||||
Command string `json:"command"`
|
||||
Arguments interface{} `json:"arguments,omitempty"`
|
||||
|
|
@ -241,7 +241,7 @@ func runDNF(command string, arguments interface{}, result interface{}) error {
|
|||
arguments,
|
||||
}
|
||||
|
||||
cmd := exec.Command("python3", "dnf-json")
|
||||
cmd := exec.Command("python3", dnfJsonPath)
|
||||
|
||||
stdin, err := cmd.StdinPipe()
|
||||
if err != nil {
|
||||
|
|
@ -293,14 +293,16 @@ func runDNF(command string, arguments interface{}, result interface{}) error {
|
|||
}
|
||||
|
||||
type rpmmdImpl struct {
|
||||
CacheDir string
|
||||
RHSM *RHSMSecrets
|
||||
CacheDir string
|
||||
RHSM *RHSMSecrets
|
||||
dnfJsonPath string
|
||||
}
|
||||
|
||||
func NewRPMMD(cacheDir string) RPMMD {
|
||||
func NewRPMMD(cacheDir, dnfJsonPath string) RPMMD {
|
||||
return &rpmmdImpl{
|
||||
CacheDir: cacheDir,
|
||||
RHSM: getRHSMSecrets(),
|
||||
CacheDir: cacheDir,
|
||||
RHSM: getRHSMSecrets(),
|
||||
dnfJsonPath: dnfJsonPath,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -347,7 +349,7 @@ func (r *rpmmdImpl) FetchMetadata(repos []RepoConfig, modulePlatformID string, a
|
|||
Packages PackageList `json:"packages"`
|
||||
}
|
||||
|
||||
err := runDNF("dump", arguments, &reply)
|
||||
err := runDNF(r.dnfJsonPath, "dump", arguments, &reply)
|
||||
|
||||
sort.Slice(reply.Packages, func(i, j int) bool {
|
||||
return reply.Packages[i].Name < reply.Packages[j].Name
|
||||
|
|
@ -382,7 +384,7 @@ func (r *rpmmdImpl) Depsolve(specs, excludeSpecs []string, repos []RepoConfig, m
|
|||
Checksums map[string]string `json:"checksums"`
|
||||
Dependencies []PackageSpec `json:"dependencies"`
|
||||
}
|
||||
err := runDNF("depsolve", arguments, &reply)
|
||||
err := runDNF(r.dnfJsonPath, "depsolve", arguments, &reply)
|
||||
|
||||
for i, pack := range reply.Dependencies {
|
||||
id, err := strconv.Atoi(pack.RepoID)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue