Skip to content
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

Add JSON formatting check to the add-ign function #189

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind changing to 41?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed this as well in my image update Pr and tried to do a quick fix #197

Anyway it is complicated as there is no f41 on the server: i.e. 404 https://kojipkgs.fedoraproject.org/compose/cloud/latest-Fedora-Cloud-41/

I asked in the Fedora cloud matrix to see if this is a bug or not on their end. So Sticking to f40 seems to be the right call for now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works for me

)

// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return vhdPath, err wdyt ?

}

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just return err

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