Skip to content

Commit

Permalink
Merge pull request #189 from skyblaster/main
Browse files Browse the repository at this point in the history
Add JSON formatting check to the  add-ign function
  • Loading branch information
openshift-merge-bot[bot] authored Jan 9, 2025
2 parents 24e21b4 + 4535f13 commit 4c29552
Show file tree
Hide file tree
Showing 54 changed files with 7,596 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cmd/kvpctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main

import (
"bytes"
"encoding/json"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -225,6 +226,10 @@ func addIgnFile(vm *hypervctl.VirtualMachine, inputFilename string) error {
if err != nil {
return err
}
var js json.RawMessage
if err := json.Unmarshal(b, &js); err != nil {
return fmt.Errorf("invalid JSON format: %v", err)
}
parts, err := ginsu.Dice(bytes.NewReader(b))
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/onsi/gomega v1.36.1
github.com/schollz/progressbar/v3 v3.17.1
github.com/sirupsen/logrus v1.9.3
github.com/ulikunitz/xz v0.5.12
golang.org/x/sys v0.28.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
39 changes: 36 additions & 3 deletions test/e2e/fedora_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (
"os"
"path/filepath"
"runtime"
"github.com/ulikunitz/xz"
)

const (
fedoraBaseDirEndpoint = "https://kojipkgs.fedoraproject.org/compose/cloud/latest-Fedora-Cloud-39/compose"
fedoraBaseDirEndpoint = "https://kojipkgs.fedoraproject.org/compose/cloud/latest-Fedora-Cloud-40/compose"
)

// Fedora metadata for cloud downloads
Expand Down Expand Up @@ -100,7 +101,7 @@ func (m fedoraCloudMetadata) downloadPathForVHD() (string, string, error) {
return "", "", errors.New("unable to parse metadata for cloud image")
}
for _, ci := range val {
if ci.Format == "vhd" { // fedora does not make a vhdx
if ci.Format == "vhd.xz" { // fedora does not make a vhdx
return fmt.Sprintf("%s/%s", fedoraBaseDirEndpoint, ci.Path), ci.Checksums["sha256"], nil
}
}
Expand Down Expand Up @@ -166,7 +167,39 @@ func getTestImage() (string, error) {
return "", err
}
}
return dstPath, nil
// Decompress the downloaded vhdfixed.xz file
vhdPath := filepath.Join(defaultCacheDirPath, filepath.Base(downloadPath[:len(downloadPath)-len(".vhdfixed.xz")])) + ".vhd"
err = decompressVhdXZ(dstPath, vhdPath)
if err != nil {
return "", err
}
return vhdPath, nil
}

func decompressVhdXZ(src string, dst string) error {
f, err := os.Open(src)
if err != nil {
return err
}
defer f.Close()

r, err := xz.NewReader(f)
if err != nil {
return fmt.Errorf("xz decompression failed: %v", err)
}

// Directly copy the decompressed data to the destination file
outFile, err := os.Create(dst)
if err != nil {
return err
}
defer outFile.Close()

_, err = io.Copy(outFile, r)
if err != nil {
return err
}
return nil
}

func archFromGOOS() string {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
. "github.com/onsi/ginkgo/v2"
)

const defaultDiskSize = 10
const defaultDiskSize = 5

func setDiskDir() string {
hd, err := os.UserHomeDir()
Expand Down
28 changes: 28 additions & 0 deletions vendor/github.com/ulikunitz/xz/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions vendor/github.com/ulikunitz/xz/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions vendor/github.com/ulikunitz/xz/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions vendor/github.com/ulikunitz/xz/SECURITY.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4c29552

Please sign in to comment.