diff --git a/.circleci/config.yml b/.circleci/config.yml index 3e290b4c..5d03e8f4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -34,7 +34,8 @@ jobs: make test | tee ${TEST_RESULTS}/go-test.out build-mac: macos: - xcode: "15.3.0" + xcode: "15.4.0" + resource_class: macos.m1.medium.gen1 environment: TEST_RESULTS: /tmp/test-results steps: @@ -42,16 +43,15 @@ jobs: - run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - run: brew update && brew install go && brew tap nanovms/homebrew-qemu && brew install nanovms/homebrew-qemu/qemu && brew install wget && brew install protoc-gen-go-grpc - run: go install github.com/jstemmer/go-junit-report@latest - - run: wget https://github.com/bufbuild/buf/releases/download/v1.13.1/buf-Darwin-x86_64 && sudo mv buf-Darwin-x86_64 /usr/local/bin/buf && sudo chmod +x /usr/local/bin/buf - # - run: brew install bufbuild/buf/buf + - run: wget https://github.com/bufbuild/buf/releases/download/v1.13.1/buf-Darwin-arm64 && sudo mv buf-Darwin-arm64 /usr/local/bin/buf && sudo chmod +x /usr/local/bin/buf - run: go install google.golang.org/protobuf/cmd/protoc-gen-go@latest - run: go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest - - run: curl -L https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v2.15.0/protoc-gen-openapiv2-v2.15.0-darwin-x86_64 -o ~/go/bin/protoc-gen-openapiv2 && chmod +x ~/go/bin/protoc-gen-openapiv2 - - run: curl -L https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v2.15.0/protoc-gen-grpc-gateway-v2.15.0-darwin-x86_64 -o ~/go/bin/protoc-gen-grpc-gateway && chmod +x ~/go/bin/protoc-gen-grpc-gateway + - run: curl -L https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v2.15.0/protoc-gen-openapiv2-v2.15.0-darwin-arm64 -o ~/go/bin/protoc-gen-openapiv2 && chmod +x ~/go/bin/protoc-gen-openapiv2 + - run: curl -L https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v2.15.0/protoc-gen-grpc-gateway-v2.15.0-darwin-arm64 -o ~/go/bin/protoc-gen-grpc-gateway && chmod +x ~/go/bin/protoc-gen-grpc-gateway - run: make deps - run: make generate PATH=$PATH:~/go/bin - run: mkdir -p $TEST_RESULTS - - run: go run ops.go update + - run: go run ops.go update --arm - run: name: macbuild command: | diff --git a/cmd/cmd_build_test.go b/cmd/cmd_build_test.go index 91899735..5450ec11 100644 --- a/cmd/cmd_build_test.go +++ b/cmd/cmd_build_test.go @@ -10,6 +10,8 @@ import ( ) func TestCmdBuild(t *testing.T) { + stubUpdate() + programPath := testutils.BuildBasicProgram() defer os.Remove(programPath) diff --git a/cmd/cmd_pkg_test.go b/cmd/cmd_pkg_test.go index fad49f66..389b8f80 100644 --- a/cmd/cmd_pkg_test.go +++ b/cmd/cmd_pkg_test.go @@ -4,10 +4,35 @@ import ( "os" "testing" + // FIXME: why are there 2 pkgs here? "github.com/nanovms/ops/cmd" "github.com/stretchr/testify/assert" ) +// FIXME +// memoize +func stubAMDUpdate() error { + upPkgCmd := cmd.UpdateCommand() + return upPkgCmd.Execute() +} + +func stubARMUpdate() error { + upPkgCmd := cmd.UpdateCommand() + upPkgCmd.SetArgs([]string{"--arm"}) + return upPkgCmd.Execute() +} + +func stubUpdate() error { + upPkgCmd := cmd.UpdateCommand() + + a := cmd.ArchPath() + if a != "" { + upPkgCmd.SetArgs([]string{"--arm"}) + } + + return upPkgCmd.Execute() +} + func TestListPkgCommand(t *testing.T) { listPkgCmd := cmd.PackageCommands() @@ -50,6 +75,8 @@ func TestPkgDescribeCommand(t *testing.T) { func TestLoad(t *testing.T) { + stubAMDUpdate() + getPkgCmd := cmd.PackageCommands() program := buildNodejsProgram() diff --git a/cmd/cmd_run_test.go b/cmd/cmd_run_test.go index 8eb64a3d..54a4f530 100644 --- a/cmd/cmd_run_test.go +++ b/cmd/cmd_run_test.go @@ -10,6 +10,9 @@ import ( ) func TestRunCommand(t *testing.T) { + + stubUpdate() + programPath := testutils.BuildBasicProgram() defer os.Remove(programPath) diff --git a/cmd/cmd_update.go b/cmd/cmd_update.go index 2a18e65e..c10fd9b6 100644 --- a/cmd/cmd_update.go +++ b/cmd/cmd_update.go @@ -67,5 +67,4 @@ func updateCommandHandler(cmd *cobra.Command, args []string) { api.UpdateLocalRelease(remote) fmt.Printf("Update nanos to %s version.\n", remote) } - os.Exit(0) } diff --git a/cmd/cmd_volume_test.go b/cmd/cmd_volume_test.go index edb5753c..88309393 100644 --- a/cmd/cmd_volume_test.go +++ b/cmd/cmd_volume_test.go @@ -66,9 +66,6 @@ func TestAttachVolumeCommand(t *testing.T) { attachVolumeCmd.SetArgs([]string{"attach", instanceName, volumeName, "does not matter"}) - // FIXME: tests prob. should not be spawning - time.Sleep(1 * time.Second) - err := attachVolumeCmd.Execute() assert.Nil(t, err) diff --git a/cmd/flags_nanos_version.go b/cmd/flags_nanos_version.go index d4e43d99..a18ad14f 100644 --- a/cmd/flags_nanos_version.go +++ b/cmd/flags_nanos_version.go @@ -14,6 +14,12 @@ type NanosVersionCommandFlags struct { NanosVersion string } +// FIXME - no need for sep pkgs; now having to export this because of +// this issue. +func ArchPath() string { + return archPath() +} + func archPath() string { if runtime.GOARCH == "arm64" || lepton.AltGOARCH == "arm64" { return "arm" @@ -28,13 +34,13 @@ func (flags *NanosVersionCommandFlags) MergeToConfig(config *types.Config) (err if nanosVersion != "" { var exists bool - exists, err = lepton.CheckNanosVersionExists(nanosVersion) + arch := archPath() + exists, err = lepton.CheckNanosVersionExists(nanosVersion, arch) if err != nil { return err } if !exists { - arch := archPath() err = lepton.DownloadReleaseImages(nanosVersion, arch) if err != nil { return diff --git a/cmd/flags_nanos_version_test.go b/cmd/flags_nanos_version_test.go index 384deaa9..47e957ef 100644 --- a/cmd/flags_nanos_version_test.go +++ b/cmd/flags_nanos_version_test.go @@ -1,7 +1,9 @@ package cmd import ( + "os" "path" + "strings" "testing" "github.com/nanovms/ops/lepton" @@ -23,9 +25,45 @@ func TestCreateVersionFlags(t *testing.T) { assert.Equal(t, versionFlags.NanosVersion, "0.1.37") } +// stubs a 'release' +func stubRelease(versionPath string) error { + err := os.MkdirAll(versionPath, 0750) + if err != nil { + return err + } + + f, err := os.OpenFile(versionPath+"/kernel.img", os.O_RDONLY|os.O_CREATE, 0644) + if err != nil { + return err + } + f.Close() + + if !strings.Contains(versionPath, "-arm") { + f, err := os.OpenFile(versionPath+"/boot.img", os.O_RDONLY|os.O_CREATE, 0644) + if err != nil { + return err + } + f.Close() + } + + return nil +} + func TestVersionFlagsMergeToConfig(t *testing.T) { versionPath := path.Join(lepton.GetOpsHome(), "0.1.37") + + a := archPath() + + if a != "" { + versionPath = versionPath + "-" + a + } + + err := stubRelease(versionPath) + if err != nil { + t.Fatal(err) + } + currentOpsPath := path.Join(lepton.GetOpsHome(), lepton.LocalReleaseVersion) t.Run("if nano-version flag is enabled should set boot and kernel paths", func(t *testing.T) { @@ -37,9 +75,14 @@ func TestVersionFlagsMergeToConfig(t *testing.T) { versionFlags := NewNanosVersionCommandFlags(flagSet) + boot := path.Join(versionPath, "boot.img") + if a != "" { + boot = "" + } + c := &types.Config{} expected := &types.Config{ - Boot: path.Join(versionPath, "boot.img"), + Boot: boot, Kernel: path.Join(versionPath, "kernel.img"), } @@ -59,12 +102,20 @@ func TestVersionFlagsMergeToConfig(t *testing.T) { versionFlags := NewNanosVersionCommandFlags(flagSet) + cBoot := currentOpsPath + "/boot.img" + vBoot := versionPath + "/boot.img" + + if a != "" { + cBoot = "" + vBoot = "" + } + c := &types.Config{ Kernel: currentOpsPath + "/kernel.img", - Boot: currentOpsPath + "/boot.img", + Boot: cBoot, } expected := &types.Config{ - Boot: versionPath + "/boot.img", + Boot: vBoot, Kernel: versionPath + "/kernel.img", } diff --git a/lepton/image.go b/lepton/image.go index 2869071e..87bce0b1 100644 --- a/lepton/image.go +++ b/lepton/image.go @@ -581,7 +581,11 @@ func DownloadCommonFiles() error { } // CheckNanosVersionExists verifies whether version exists in filesystem -func CheckNanosVersionExists(version string) (bool, error) { +func CheckNanosVersionExists(version string, arch string) (bool, error) { + if arch != "" { + version = version + "-" + arch + } + _, err := os.Stat(path.Join(GetOpsHome(), version)) if err != nil && os.IsNotExist(err) { return false, nil diff --git a/provider/onprem/onprem_instance.go b/provider/onprem/onprem_instance.go index 17dde7a8..1b7e308e 100644 --- a/provider/onprem/onprem_instance.go +++ b/provider/onprem/onprem_instance.go @@ -569,14 +569,13 @@ func (p *OnPrem) StartInstance(ctx *lepton.Context, instancename string) error { `{ "execute": "cont" }`, } - executeQMP(commands, last) - return nil + return executeQMP(commands, last) } -func executeQMP(commands []string, last string) { - c, err := net.Dial("tcp", "localhost:"+last) +func executeQMP(commands []string, last string) error { + c, err := net.Dial("tcp", "127.0.0.1:"+last) if err != nil { - fmt.Println(err) + return err } defer c.Close() @@ -592,6 +591,8 @@ func executeQMP(commands []string, last string) { os.Exit(1) } } + + return nil } // RebootInstance from on premise @@ -608,9 +609,7 @@ func (p *OnPrem) RebootInstance(ctx *lepton.Context, instancename string) error `{ "execute": "system_reset" }`, } - executeQMP(commands, last) - - return nil + return executeQMP(commands, last) } // StopInstance from on premise @@ -627,8 +626,7 @@ func (p *OnPrem) StopInstance(ctx *lepton.Context, instancename string) error { `{ "execute": "stop" }`, } - executeQMP(commands, last) - return nil + return executeQMP(commands, last) } // DeleteInstance from on premise diff --git a/provider/onprem/onprem_volume.go b/provider/onprem/onprem_volume.go index 83cb8daa..2f288fc8 100644 --- a/provider/onprem/onprem_volume.go +++ b/provider/onprem/onprem_volume.go @@ -150,6 +150,7 @@ func (op *OnPrem) DetachVolume(ctx *lepton.Context, instanceName string, volumeN c, err := net.Dial("tcp", "localhost:"+last) if err != nil { fmt.Println(err) + return err } defer c.Close()