Skip to content

Commit

Permalink
taking out CreateLimaOption() + making config option a str instead of…
Browse files Browse the repository at this point in the history
… bool

Signed-off-by: Channing Gaddy <[email protected]>
  • Loading branch information
CodeChanning committed Aug 9, 2023
1 parent 49680dc commit 41a1ae5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 49 deletions.
17 changes: 0 additions & 17 deletions e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,3 @@ func CreateOption() (*option.Option, error) {
}
return o, nil
}

// CreateLimaOption creates an option for shelling into VM in e2e tests.
func CreateLimaOption() (*option.Option, string, error) {
wd, err := os.Getwd()
if err != nil {
return nil, "", fmt.Errorf("failed to get the current working directory: %w", err)
}

subject := "LIMA_HOME=" + filepath.Join(wd, "../../_output/lima/data")
subject2 := filepath.Join(wd, "../../_output/lima/bin/limactl")

o, err := option.New([]string{subject2}, option.Env([]string{subject}))
if err != nil {
return nil, "", fmt.Errorf("failed to initialize a testing option: %w", err)
}
return o, subject, nil
}
32 changes: 24 additions & 8 deletions e2e/vm/soci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package vm

import (
"os"
"path/filepath"
"strings"

"github.com/onsi/ginkgo/v2"
Expand All @@ -13,38 +15,52 @@ import (
"github.com/runfinch/common-tests/option"
)

var testSoci = func(o *option.Option, limactlO *option.Option, limaHomePath string, installed bool) {
const (
FfmpegSociImage = "public.ecr.aws/soci-workshop-examples/ffmpeg:latest"
sociMountString = "fuse.rawBridge"
)

var testSoci = func(o *option.Option, installed bool) {

ginkgo.Describe("SOCI", func() {
var limactlO *option.Option
var limaHomePathEnv string
var wd string

ginkgo.BeforeEach(func() {
wd, _ = os.Getwd()
limaHomePathEnv = "LIMA_HOME=" + filepath.Join(wd, "../../_output/lima/data")
limactlO, _ = option.New([]string{filepath.Join(wd, "../../_output/lima/bin/limactl")},
option.Env([]string{limaHomePathEnv}))
})

ginkgo.Describe("Soci", func() {
ginkgo.It("finch pull should have same mounts as nerdctl pull with SOCI", func() {
resetVM(o, installed)
resetDisks(o, installed)
writeFile(finchConfigFilePath, []byte("cpus: 6\nmemory: 4GiB\nsoci_snapshotter: true\n"+
writeFile(finchConfigFilePath, []byte("cpus: 6\nmemory: 4GiB\nsnapshotter: soci\n"+
"vmType: qemu\nrosetta: false"))
initCmdSession := command.New(o, virtualMachineRootCmd, "init").WithTimeoutInSeconds(600).Run()
gomega.Expect(initCmdSession).Should(gexec.Exit(0))
command.New(o, "pull", FfmpegSociImage).WithTimeoutInSeconds(30).Run()
finchPullMounts := countMounts(limactlO)
command.New(o, "rmi", "-f", FfmpegSociImage).WithTimeoutInSeconds(30).Run()
command.New(limactlO, "shell", "finch", "sudo", "nerdctl", "pull", FfmpegSociImage).WithTimeoutInSeconds(30).Run().Out.Contents()
command.New(limactlO, "shell", "finch", "sudo", "nerdctl", "--snapshotter=soci", "pull", FfmpegSociImage).WithTimeoutInSeconds(30).Run().Out.Contents()
nerdctlPullMounts := countMounts(limactlO)
command.New(o, "rmi", "-f", FfmpegSociImage).WithTimeoutInSeconds(30).Run()
gomega.Expect(finchPullMounts).Should(gomega.Equal(nerdctlPullMounts))
})
})

ginkgo.Describe("Soci", func() {
ginkgo.It("finch run should have same mounts as nerdctl run with SOCI", func() {
resetVM(o, installed)
resetDisks(o, installed)
writeFile(finchConfigFilePath, []byte("cpus: 6\nmemory: 4GiB\nsoci_snapshotter: true\n"+
writeFile(finchConfigFilePath, []byte("cpus: 6\nmemory: 4GiB\nsnapshotter: soci\n"+
"vmType: qemu\nrosetta: false"))
initCmdSession := command.New(o, virtualMachineRootCmd, "init").WithTimeoutInSeconds(600).Run()
gomega.Expect(initCmdSession).Should(gexec.Exit(0))
command.New(o, "run", FfmpegSociImage).WithTimeoutInSeconds(30).Run()
finchPullMounts := countMounts(limactlO)
command.New(o, "rmi", "-f", FfmpegSociImage).WithTimeoutInSeconds(30).Run()
command.New(limactlO, "shell", "finch", "sudo", "nerdctl", "run", FfmpegSociImage).WithTimeoutInSeconds(30).Run().Out.Contents()
command.New(limactlO, "shell", "finch", "sudo", "nerdctl", "--snapshotter=soci", "run", FfmpegSociImage).WithTimeoutInSeconds(30).Run().Out.Contents()
nerdctlPullMounts := countMounts(limactlO)
command.New(o, "rmi", "-f", FfmpegSociImage).WithTimeoutInSeconds(30).Run()
gomega.Expect(finchPullMounts).Should(gomega.Equal(nerdctlPullMounts))
Expand Down
9 changes: 1 addition & 8 deletions e2e/vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (

const (
virtualMachineRootCmd = "vm"
FfmpegSociImage = "public.ecr.aws/soci-workshop-examples/ffmpeg:latest"
sociMountString = "fuse.rawBridge"
)

//nolint:paralleltest // TestVM is like TestMain for the VM-related tests.
Expand All @@ -36,11 +34,6 @@ func TestVM(t *testing.T) {
t.Fatal(err)
}

limactlO, limaHomePath, err := e2e.CreateLimaOption()
if err != nil {
t.Fatal(err)
}

ginkgo.SynchronizedBeforeSuite(func() []byte {
command.New(o, "vm", "init").WithTimeoutInSeconds(600).Run()
return nil
Expand All @@ -60,7 +53,7 @@ func TestVM(t *testing.T) {
testVirtualizationFrameworkAndRosetta(o, *e2e.Installed)
testSupportBundle(o)
testCredHelper(o, *e2e.Installed, *e2e.Registry)
testSoci(o, limactlO, limaHomePath, *e2e.Installed)
testSoci(o, *e2e.Installed)
})

gomega.RegisterFailHandler(ginkgo.Fail)
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ type AdditionalDirectory struct {
type Finch struct {
CPUs *int `yaml:"cpus"`
Memory *string `yaml:"memory"`
//Soci: boolean value of whether user wants SOCI installed
Soci *bool `yaml:"soci_snapshotter,omitempty"`
// Soci: the snapshotter that will be installed and configured automatically on vm init or on vm start
Snapshotter *string `yaml:"snapshotter,omitempty"`
// CredsHelper: the list of credential helpers that will be installed and configured automatically on vm init or on vm start
CredsHelpers []string `yaml:"creds_helpers,omitempty"`
// AdditionalDirectories are the work directories that are not supported by default. In macOS, only home directory is supported by default.
Expand Down
21 changes: 7 additions & 14 deletions pkg/config/lima_config_applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
const (
sociVersion = "0.3.0"
sociInstallationProvisioningScriptHeader = "# soci installation and configuring"
fnameFormat = "soci-snapshotter-%s-linux-%s.tar.gz"
sociFileNameFormat = "soci-snapshotter-%s-linux-%s.tar.gz"
sociDownloadUrlFormat = "https://github.com/awslabs/soci-snapshotter/releases/download/v%s/%s"
sociInstallationScriptFormat = `%s
if [ ! -f /usr/local/bin/soci ]; then
Expand All @@ -32,8 +32,8 @@ fi
#changing containerd config
export config=etc/containerd/config.toml
echo " [proxy_plugins.soci]
type = \"snapshot\"
address = \"/run/soci-snapshotter-grpc/soci-snapshotter-grpc.sock\" " >> $config
type = \"snapshot\"
address = \"/run/soci-snapshotter-grpc/soci-snapshotter-grpc.sock\" " >> $config
sudo systemctl restart containerd.service
sudo soci-snapshotter-grpc &> ~/soci-snapshotter-logs &
Expand Down Expand Up @@ -113,13 +113,6 @@ func (lca *limaConfigApplier) Apply(isInit bool) error {
limaCfg.Rosetta.BinFmt = pointer.Bool(false)
}

var sociEnabled bool
if lca.cfg.Soci == nil {
sociEnabled = false
} else {
sociEnabled = *lca.cfg.Soci
}

if isInit {
cfgAfterInit, err := lca.applyInit(&limaCfg)
if err != nil {
Expand All @@ -128,7 +121,7 @@ func (lca *limaConfigApplier) Apply(isInit bool) error {
limaCfg = *cfgAfterInit
}

toggleSoci(&limaCfg, sociEnabled, sociVersion, system.NewStdLib().Arch())
toggleSoci(&limaCfg, *lca.cfg.Snapshotter == "soci", sociVersion, system.NewStdLib().Arch())

limaCfgBytes, err := yaml.Marshal(limaCfg)
if err != nil {
Expand Down Expand Up @@ -225,9 +218,9 @@ func hasUserModeEmulationInstallationScript(limaCfg *limayaml.LimaYAML) (int, bo

func toggleSoci(limaCfg *limayaml.LimaYAML, enabled bool, sociVersion string, arch string) {
idx, hasScript := hasSociInstallationScript(limaCfg)
fname := fmt.Sprintf(fnameFormat, sociVersion, system.NewStdLib().Arch())
sociDownloadUrl := fmt.Sprintf(sociDownloadUrlFormat, sociVersion, fname)
sociInstallationScript := fmt.Sprintf(sociInstallationScriptFormat, sociInstallationProvisioningScriptHeader, sociDownloadUrl, fname)
sociFileName := fmt.Sprintf(sociFileNameFormat, sociVersion, system.NewStdLib().Arch())
sociDownloadUrl := fmt.Sprintf(sociDownloadUrlFormat, sociVersion, sociFileNameFormat)
sociInstallationScript := fmt.Sprintf(sociInstallationScriptFormat, sociInstallationProvisioningScriptHeader, sociDownloadUrl, sociFileName)
if !hasScript && enabled {
limaCfg.Env = map[string]string{"CONTAINERD_SNAPSHOTTER": "soci"}
limaCfg.Provision = append(limaCfg.Provision, limayaml.Provision{
Expand Down

0 comments on commit 41a1ae5

Please sign in to comment.