Skip to content

Commit

Permalink
do not merge: this is a test
Browse files Browse the repository at this point in the history
Signed-off-by: Mahe Tardy <[email protected]>
  • Loading branch information
mtardy committed Apr 15, 2024
1 parent de827f6 commit cc43ac5
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 100 deletions.
6 changes: 1 addition & 5 deletions cmd/tetragon-vmtests-run/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,20 @@ import (

// NB: we should use lvh's RunConf to avoid duplicating code
type RunConf struct {
runner.RunConf
testImage string
baseFname string
kernelFname string
dontRebuildImage bool
useTetragonTesterInit bool
testerOut string
qemuPrint bool
justBoot bool
justBuildImage bool
disableKVM bool
enableHVF bool
btfFile string
disableUnifiedCgroups bool
portForwards runner.PortForwards
testerConf vmtests.Conf
detailedResults bool
keepAllLogs bool
rootDev string

filesystems []QemuFS
}
Expand Down
49 changes: 41 additions & 8 deletions cmd/tetragon-vmtests-run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"time"

"github.com/cilium/little-vm-helper/pkg/arch"
"github.com/cilium/little-vm-helper/pkg/runner"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -30,7 +31,7 @@ func main() {
t0 := time.Now()

var err error
rcnf.portForwards, err = runner.ParsePortForward(ports)
rcnf.ForwardedPorts, err = runner.ParsePortForward(ports)
if err != nil {
return fmt.Errorf("error parseing ports: %w", err)
}
Expand Down Expand Up @@ -84,10 +85,16 @@ func main() {
return err
}

qemuBin := "qemu-system-x86_64"
qemuArgs, err := buildQemuArgs(log, &rcnf)
rcnf.Image = rcnf.testImageFname()

qemuBin, err := arch.QemuBinary()
if err != nil {
return err
return fmt.Errorf("failed to get QEMU binary: %w", err)
}

qemuArgs, err := buildQemuArgs(log, rcnf)
if err != nil {
return fmt.Errorf("failed to build qemu args: %w", err)
}

if rcnf.qemuPrint {
Expand All @@ -104,6 +111,7 @@ func main() {
fmt.Printf("%s\n", sb.String())
return nil
}
fmt.Println(qemuArgs)

// if we don't need to run tests, just exec() so that user will be able to
// login to the VM.
Expand Down Expand Up @@ -144,12 +152,11 @@ func main() {
cmd.Flags().StringVar(&rcnf.baseFname, "base", "", "base image filename")
cmd.MarkFlagRequired("base")
cmd.Flags().StringVar(&rcnf.testImage, "name", "tetragon", "new vm (and basis for the image name). New vm image will be in the directory of the base image")
cmd.Flags().StringVar(&rcnf.kernelFname, "kernel", "", "kernel filename to boot with. (if empty no -kernel option will be passed to qemu)")
cmd.Flags().StringVar(&rcnf.KernelFname, "kernel", "", "kernel filename to boot with. (if empty no -kernel option will be passed to qemu)")
cmd.Flags().BoolVar(&rcnf.dontRebuildImage, "dont-rebuild-image", false, "dont rebuild image")
cmd.Flags().BoolVar(&rcnf.useTetragonTesterInit, "use-tetragon-init", false, "use tetragon-vmtests-init as init process in the VM")
cmd.Flags().BoolVar(&rcnf.qemuPrint, "qemu-cmd-print", false, "Do not run the qemu command, just print it")
cmd.Flags().BoolVar(&rcnf.disableKVM, "qemu-disable-kvm", false, "Do not use KVM acceleration, even if /dev/kvm exists")
cmd.Flags().BoolVar(&rcnf.enableHVF, "qemu-enable-hvf", false, "Use hvf acceleration")
cmd.Flags().BoolVar(&rcnf.DisableKVM, "qemu-disable-kvm", false, "Do not use KVM acceleration, even if /dev/kvm exists")
cmd.Flags().BoolVar(&rcnf.justBoot, "just-boot", false, "Do not actually run any tests. Just setup everything and start the VM. User will be able to login to the VM.")
cmd.Flags().BoolVar(&rcnf.justBuildImage, "just-build-image", false, "Just build an image. Do not actually run any tests or boot the VM.")
cmd.Flags().BoolVar(&rcnf.testerConf.NoPowerOff, "no-poweroff", false, "Do not poweroff the VM at the end of the run")
Expand All @@ -161,9 +168,35 @@ func main() {
cmd.Flags().StringArrayVarP(&ports, "port", "p", nil, "Forward a port (hostport[:vmport[:tcp|udp]])")
cmd.Flags().StringVar(&rcnf.testerConf.KernelVer, "kernel-ver", "", "kenel version")
cmd.Flags().BoolVar(&rcnf.detailedResults, "enable-detailed-results", false, "produce detailed results")
cmd.Flags().StringVar(&rcnf.rootDev, "root-dev", "vda", "type of root device (hda or vda)")
cmd.Flags().StringVar(&rcnf.RootDev, "root-dev", "vda", "type of root device (hda or vda)")

if err := cmd.Execute(); err != nil {
os.Exit(1)
}
}

// buildQemuArgs calls lvh's runner.BuildQemuArgs and handles custom
// configuration from vmtests
func buildQemuArgs(log *logrus.Logger, rcnf RunConf) ([]string, error) {
if rcnf.KernelFname != "" {
if rcnf.disableUnifiedCgroups {
rcnf.KernelAppendArgs = append(rcnf.KernelAppendArgs, "systemd.unified_cgroup_hierarchy=0")
}
if rcnf.useTetragonTesterInit {
rcnf.KernelAppendArgs = append(rcnf.KernelAppendArgs, fmt.Sprintf("init=%s", TetragonTesterBin))
}
}
rcnf.CPU = 2
rcnf.Mem = "4G"

qemuArgs, err := runner.BuildQemuArgs(log, &rcnf.RunConf)
if err != nil {
return nil, err
}

for _, fs := range rcnf.filesystems {
qemuArgs = append(qemuArgs, fs.qemuArgs()...)
}

return qemuArgs, nil
}
85 changes: 0 additions & 85 deletions cmd/tetragon-vmtests-run/qemu.go

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/bombsimon/logrusr/v4 v4.1.0
github.com/cilium/cilium v1.15.3
github.com/cilium/ebpf v0.14.0
github.com/cilium/little-vm-helper v0.0.17
github.com/cilium/little-vm-helper v0.0.18-0.20240412153556-e8c483732639
github.com/cilium/lumberjack/v2 v2.3.0
github.com/cilium/tetragon/api v0.0.0-00010101000000-000000000000
github.com/cilium/tetragon/pkg/k8s v0.0.0-00010101000000-000000000000
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ github.com/cilium/ebpf v0.14.0 h1:0PsxAjO6EjI1rcT+rkp6WcCnE0ZvfkXBYiMedJtrSUs=
github.com/cilium/ebpf v0.14.0/go.mod h1:DHp1WyrLeiBh19Cf/tfiSMhqheEiK8fXFZ4No0P1Hso=
github.com/cilium/little-vm-helper v0.0.17 h1:uKS/wQSPeFqgZk6fFRhnreGvhuQCnWsZvqhkF/PS/OM=
github.com/cilium/little-vm-helper v0.0.17/go.mod h1:2q3DGb/ptNd+jnenMpx0l++PX6r85FzvaTvZG31pGAQ=
github.com/cilium/little-vm-helper v0.0.18-0.20240412094937-f1c38b8ed8c0 h1:i84xd6IBX9I6gvVj61SvuCmg5T3cOxK3dt8uNNjfroE=
github.com/cilium/little-vm-helper v0.0.18-0.20240412094937-f1c38b8ed8c0/go.mod h1:2q3DGb/ptNd+jnenMpx0l++PX6r85FzvaTvZG31pGAQ=
github.com/cilium/little-vm-helper v0.0.18-0.20240412153556-e8c483732639 h1:m5weN2xOecWVYsEBFbY4He+h9IfS5yC5Bddt74+ecyM=
github.com/cilium/little-vm-helper v0.0.18-0.20240412153556-e8c483732639/go.mod h1:2q3DGb/ptNd+jnenMpx0l++PX6r85FzvaTvZG31pGAQ=
github.com/cilium/lumberjack/v2 v2.3.0 h1:IhVJMvPpqDYmQzC0KDhAoy7KlaRsyOsZnT97Nsa3u0o=
github.com/cilium/lumberjack/v2 v2.3.0/go.mod h1:yfbtPGmg4i//5oEqzaMxDqSWqgfZFmMoV70Mc2k6v0A=
github.com/cilium/proxy v0.0.0-20231031145409-f19708f3d018 h1:R/QlThqx099hS6req1k2Q87fvLSRgCEicQGate9vxO4=
Expand Down

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

Loading

0 comments on commit cc43ac5

Please sign in to comment.