Skip to content

Commit

Permalink
fix(linux): support bundles (#1101)
Browse files Browse the repository at this point in the history
* fix(linux): support bundles

Signed-off-by: Justin Alvarez <[email protected]>

* fix config file path

Signed-off-by: Justin Alvarez <[email protected]>

* enable support bundle e2e tests

Signed-off-by: Justin Alvarez <[email protected]>

* fix unit tests

Signed-off-by: Justin Alvarez <[email protected]>

* fix linting

Signed-off-by: Justin Alvarez <[email protected]>

---------

Signed-off-by: Justin Alvarez <[email protected]>
  • Loading branch information
pendo324 authored Sep 23, 2024
1 parent d3ab32a commit f32a97f
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 40 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e-linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ jobs:
# required by one of the tests which uses SSH_AUTH_SOCK
eval "$(ssh-agent -s)"
INSTALLED=true REGISTRY=${{ steps.vars.outputs.has_creds == true && env.REGISTRY || '' }} sudo -E make test-e2e-container
INSTALLED=true REGISTRY=${{ steps.vars.outputs.has_creds == true && env.REGISTRY || '' }} sudo -E make test-e2e-vm
- name: Clean up repo AL2
if: ${{ (startsWith(inputs.os, 'amazon') && inputs.version == '2' && always() ) }}
run: |
Expand Down
18 changes: 9 additions & 9 deletions cmd/finch/nerdctl_native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func TestNerdctlCommand_run(t *testing.T) {
_ *testing.T,
ncc *mocks.NerdctlCmdCreator,
_ *mocks.CommandCreator,
ncsd *mocks.NerdctlCommandSystemDeps,
logger *mocks.Logger,
_ *mocks.NerdctlCommandSystemDeps,
_ *mocks.Logger,
ctrl *gomock.Controller,
_ afero.Fs,
) {
Expand All @@ -107,7 +107,7 @@ func TestNerdctlCommand_run(t *testing.T) {
_ *testing.T,
ncc *mocks.NerdctlCmdCreator,
_ *mocks.CommandCreator,
ncsd *mocks.NerdctlCommandSystemDeps,
_ *mocks.NerdctlCommandSystemDeps,
logger *mocks.Logger,
ctrl *gomock.Controller,
_ afero.Fs,
Expand All @@ -128,9 +128,9 @@ func TestNerdctlCommand_run(t *testing.T) {
_ *testing.T,
ncc *mocks.NerdctlCmdCreator,
_ *mocks.CommandCreator,
ncsd *mocks.NerdctlCommandSystemDeps,
logger *mocks.Logger,
ctrl *gomock.Controller,
_ *mocks.NerdctlCommandSystemDeps,
_ *mocks.Logger,
_ *gomock.Controller,
_ afero.Fs,
) {
ncc.EXPECT().RunWithReplacingStdout(
Expand All @@ -147,9 +147,9 @@ func TestNerdctlCommand_run(t *testing.T) {
_ *testing.T,
ncc *mocks.NerdctlCmdCreator,
_ *mocks.CommandCreator,
ncsd *mocks.NerdctlCommandSystemDeps,
logger *mocks.Logger,
ctrl *gomock.Controller,
_ *mocks.NerdctlCommandSystemDeps,
_ *mocks.Logger,
_ *gomock.Controller,
_ afero.Fs,
) {
ncc.EXPECT().RunWithReplacingStdout(
Expand Down
11 changes: 8 additions & 3 deletions cmd/finch/support_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package main

import (
"runtime"

"github.com/spf13/cobra"

"github.com/runfinch/finch/pkg/command"
Expand Down Expand Up @@ -31,9 +33,12 @@ func newSupportBundleGenerateCommand(logger flog.Logger, builder support.BundleB
RunE: newGenerateSupportBundleAction(logger, builder, ncc).runAdapter,
}

supportBundleGenerateCommand.Flags().StringArray("include", []string{},
//nolint:lll // usage string
`additional files to include in the support bundle, specified by absolute or relative path. to include a file from the VM, prefix the file path with "vm:"`)
includeUsage := "additional files to include in the support bundle, specified by absolute or relative path."
if runtime.GOOS != "linux" {
includeUsage += `To include a file from the VM, prefix the file path with "vm:"`
}

supportBundleGenerateCommand.Flags().StringArray("include", []string{}, includeUsage)
supportBundleGenerateCommand.Flags().StringArray("exclude", []string{},
//nolint:lll // usage string
"files to exclude from the support bundle. if you specify a base name, all files matching that base name will be excluded. if you specify an absolute or relative path, only exact matches will be excluded")
Expand Down
16 changes: 8 additions & 8 deletions cmd/finch/version_native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestVersionAction_runAdaptor(t *testing.T) {
return c
},
args: []string{},
mockSvc: func(ncc *mocks.NerdctlCmdCreator, logger *mocks.Logger, ctrl *gomock.Controller) {
mockSvc: func(ncc *mocks.NerdctlCmdCreator, _ *mocks.Logger, ctrl *gomock.Controller) {
command := mocks.NewCommand(ctrl)
ncc.EXPECT().CreateWithoutStdio("version", "--format", "json").Return(command)
//nolint: lll // Version output format is larger than 500
Expand All @@ -105,7 +105,7 @@ func TestVersionAction_runAdaptor(t *testing.T) {
return c
},
args: []string{"--format", "json"},
mockSvc: func(ncc *mocks.NerdctlCmdCreator, logger *mocks.Logger, ctrl *gomock.Controller) {
mockSvc: func(ncc *mocks.NerdctlCmdCreator, _ *mocks.Logger, ctrl *gomock.Controller) {
command := mocks.NewCommand(ctrl)
ncc.EXPECT().CreateWithoutStdio("version", "--format", "json").Return(command)
//nolint: lll // Version output format is larger than 500
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestVersionAction_run(t *testing.T) {

return c
},
mockSvc: func(ncc *mocks.NerdctlCmdCreator, logger *mocks.Logger, ctrl *gomock.Controller) {
mockSvc: func(ncc *mocks.NerdctlCmdCreator, _ *mocks.Logger, ctrl *gomock.Controller) {
command := mocks.NewCommand(ctrl)
ncc.EXPECT().CreateWithoutStdio("version", "--format", "json").Return(command)
command.EXPECT().Output().Return([]byte(nerdctlMockVersion), nil)
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestVersionAction_run(t *testing.T) {

return c
},
mockSvc: func(ncc *mocks.NerdctlCmdCreator, logger *mocks.Logger, ctrl *gomock.Controller) {
mockSvc: func(ncc *mocks.NerdctlCmdCreator, _ *mocks.Logger, ctrl *gomock.Controller) {
command := mocks.NewCommand(ctrl)
ncc.EXPECT().CreateWithoutStdio("version", "--format", "json").Return(command)
command.EXPECT().Output().Return([]byte(nerdctlMockVersion), nil)
Expand All @@ -216,7 +216,7 @@ func TestVersionAction_run(t *testing.T) {

return c
},
mockSvc: func(ncc *mocks.NerdctlCmdCreator, logger *mocks.Logger, ctrl *gomock.Controller) {
mockSvc: func(ncc *mocks.NerdctlCmdCreator, _ *mocks.Logger, ctrl *gomock.Controller) {
command := mocks.NewCommand(ctrl)
ncc.EXPECT().CreateWithoutStdio("version", "--format", "json").Return(command)
command.EXPECT().Output().Return([]byte(nerdctlMockVersion), nil)
Expand All @@ -238,7 +238,7 @@ func TestVersionAction_run(t *testing.T) {

return c
},
mockSvc: func(ncc *mocks.NerdctlCmdCreator, logger *mocks.Logger, ctrl *gomock.Controller) {
mockSvc: func(ncc *mocks.NerdctlCmdCreator, _ *mocks.Logger, ctrl *gomock.Controller) {
command := mocks.NewCommand(ctrl)
ncc.EXPECT().CreateWithoutStdio("version", "--format", "json").Return(command)
command.EXPECT().Output().Return([]byte(nerdctlMockVersion), nil)
Expand All @@ -260,7 +260,7 @@ func TestVersionAction_run(t *testing.T) {

return c
},
mockSvc: func(ncc *mocks.NerdctlCmdCreator, logger *mocks.Logger, ctrl *gomock.Controller) {
mockSvc: func(ncc *mocks.NerdctlCmdCreator, _ *mocks.Logger, ctrl *gomock.Controller) {
command := mocks.NewCommand(ctrl)
ncc.EXPECT().CreateWithoutStdio("version", "--format", "json").Return(command)
command.EXPECT().Output().Return([]byte(nerdctlMockVersion), nil)
Expand All @@ -281,7 +281,7 @@ func TestVersionAction_run(t *testing.T) {

return c
},
mockSvc: func(ncc *mocks.NerdctlCmdCreator, logger *mocks.Logger, ctrl *gomock.Controller) {
mockSvc: func(ncc *mocks.NerdctlCmdCreator, _ *mocks.Logger, ctrl *gomock.Controller) {
command := mocks.NewCommand(ctrl)
ncc.EXPECT().CreateWithoutStdio("version", "--format", "json").Return(command)
command.EXPECT().Output().Return([]byte(nerdctlMockVersion), nil)
Expand Down
6 changes: 4 additions & 2 deletions e2e/vm/support_bundle_remote_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//go:build darwin || windows

package vm

import (
Expand All @@ -11,6 +9,7 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -315,6 +314,9 @@ var testSupportBundle = func(o *option.Option) {
gomega.Expect(bundleExists).Should(gomega.BeTrue())
})
ginkgo.It("Should fail to generate a support bundle when the VM is nonexistent", func() {
if runtime.GOOS == "linux" {
ginkgo.Skip("No VM on Linux")
}
command.New(o, "vm", "stop", "-f").WithoutCheckingExitCode().WithTimeoutInSeconds(30).Run()
time.Sleep(1 * time.Second)
command.New(o, "vm", "remove", "-f").WithoutCheckingExitCode().WithTimeoutInSeconds(20).Run()
Expand Down
33 changes: 33 additions & 0 deletions e2e/vm/vm_linux_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//go:build linux

// Package vm runs tests related to the virtual machine.
package vm

import (
"testing"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"

"github.com/runfinch/finch/e2e"
)

//nolint:paralleltest // TestVM is like TestMain for the VM-related tests.
func TestVM(t *testing.T) {
const description = "Finch Virtual Machine E2E Tests"

o, err := e2e.CreateOption()
if err != nil {
t.Fatal(err)
}

ginkgo.Describe("", func() {
testSupportBundle(o)
})

gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, description)
}
2 changes: 1 addition & 1 deletion pkg/support/config_native_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ func (bc *bundleConfig) LogFiles() []string {

func (bc *bundleConfig) ConfigFiles() []string {
return []string{
bc.rootDir,
bc.finch.ConfigFilePath(),
}
}
16 changes: 13 additions & 3 deletions pkg/support/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ type bufReader interface {
}

func (bb *bundleBuilder) copyFileFromVMOrLocal(writer *zip.Writer, filename, zipPath string) error {
if isFileFromVM(filename) {
if runtime.GOOS != "linux" && isFileFromVM(filename) {
return bb.streamFileFromVM(writer, filename, zipPath)
}
return bb.copyInFile(writer, filename, zipPath)
Expand Down Expand Up @@ -288,11 +288,21 @@ func (bb *bundleBuilder) getPlatformData() (*PlatformData, error) {

func (bb *bundleBuilder) getOSVersion() (string, error) {
var cmd command.Command
if runtime.GOOS == "windows" {
switch runtime.GOOS {
case "windows":
cmd = bb.ecc.Create("cmd", "/c", "ver")
} else {
case "darwin":
cmd = bb.ecc.Create("sw_vers", "-productVersion")
case "linux":
cmd = bb.ecc.Create("uname", "-r")
default:
cmd = nil
}

if cmd == nil {
return "unknown", nil
}

out, err := cmd.Output()
if err != nil {
return "", err
Expand Down
Loading

0 comments on commit f32a97f

Please sign in to comment.