Skip to content

Commit f32a97f

Browse files
authored
fix(linux): support bundles (#1101)
* 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]>
1 parent d3ab32a commit f32a97f

9 files changed

+190
-40
lines changed

Diff for: .github/workflows/e2e-linux.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ jobs:
9494
# required by one of the tests which uses SSH_AUTH_SOCK
9595
eval "$(ssh-agent -s)"
9696
INSTALLED=true REGISTRY=${{ steps.vars.outputs.has_creds == true && env.REGISTRY || '' }} sudo -E make test-e2e-container
97+
INSTALLED=true REGISTRY=${{ steps.vars.outputs.has_creds == true && env.REGISTRY || '' }} sudo -E make test-e2e-vm
9798
- name: Clean up repo AL2
9899
if: ${{ (startsWith(inputs.os, 'amazon') && inputs.version == '2' && always() ) }}
99100
run: |

Diff for: cmd/finch/nerdctl_native_test.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ func TestNerdctlCommand_run(t *testing.T) {
8787
_ *testing.T,
8888
ncc *mocks.NerdctlCmdCreator,
8989
_ *mocks.CommandCreator,
90-
ncsd *mocks.NerdctlCommandSystemDeps,
91-
logger *mocks.Logger,
90+
_ *mocks.NerdctlCommandSystemDeps,
91+
_ *mocks.Logger,
9292
ctrl *gomock.Controller,
9393
_ afero.Fs,
9494
) {
@@ -107,7 +107,7 @@ func TestNerdctlCommand_run(t *testing.T) {
107107
_ *testing.T,
108108
ncc *mocks.NerdctlCmdCreator,
109109
_ *mocks.CommandCreator,
110-
ncsd *mocks.NerdctlCommandSystemDeps,
110+
_ *mocks.NerdctlCommandSystemDeps,
111111
logger *mocks.Logger,
112112
ctrl *gomock.Controller,
113113
_ afero.Fs,
@@ -128,9 +128,9 @@ func TestNerdctlCommand_run(t *testing.T) {
128128
_ *testing.T,
129129
ncc *mocks.NerdctlCmdCreator,
130130
_ *mocks.CommandCreator,
131-
ncsd *mocks.NerdctlCommandSystemDeps,
132-
logger *mocks.Logger,
133-
ctrl *gomock.Controller,
131+
_ *mocks.NerdctlCommandSystemDeps,
132+
_ *mocks.Logger,
133+
_ *gomock.Controller,
134134
_ afero.Fs,
135135
) {
136136
ncc.EXPECT().RunWithReplacingStdout(
@@ -147,9 +147,9 @@ func TestNerdctlCommand_run(t *testing.T) {
147147
_ *testing.T,
148148
ncc *mocks.NerdctlCmdCreator,
149149
_ *mocks.CommandCreator,
150-
ncsd *mocks.NerdctlCommandSystemDeps,
151-
logger *mocks.Logger,
152-
ctrl *gomock.Controller,
150+
_ *mocks.NerdctlCommandSystemDeps,
151+
_ *mocks.Logger,
152+
_ *gomock.Controller,
153153
_ afero.Fs,
154154
) {
155155
ncc.EXPECT().RunWithReplacingStdout(

Diff for: cmd/finch/support_bundle.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package main
55

66
import (
7+
"runtime"
8+
79
"github.com/spf13/cobra"
810

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

34-
supportBundleGenerateCommand.Flags().StringArray("include", []string{},
35-
//nolint:lll // usage string
36-
`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:"`)
36+
includeUsage := "additional files to include in the support bundle, specified by absolute or relative path."
37+
if runtime.GOOS != "linux" {
38+
includeUsage += `To include a file from the VM, prefix the file path with "vm:"`
39+
}
40+
41+
supportBundleGenerateCommand.Flags().StringArray("include", []string{}, includeUsage)
3742
supportBundleGenerateCommand.Flags().StringArray("exclude", []string{},
3843
//nolint:lll // usage string
3944
"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")

Diff for: cmd/finch/version_native_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func TestVersionAction_runAdaptor(t *testing.T) {
8787
return c
8888
},
8989
args: []string{},
90-
mockSvc: func(ncc *mocks.NerdctlCmdCreator, logger *mocks.Logger, ctrl *gomock.Controller) {
90+
mockSvc: func(ncc *mocks.NerdctlCmdCreator, _ *mocks.Logger, ctrl *gomock.Controller) {
9191
command := mocks.NewCommand(ctrl)
9292
ncc.EXPECT().CreateWithoutStdio("version", "--format", "json").Return(command)
9393
//nolint: lll // Version output format is larger than 500
@@ -105,7 +105,7 @@ func TestVersionAction_runAdaptor(t *testing.T) {
105105
return c
106106
},
107107
args: []string{"--format", "json"},
108-
mockSvc: func(ncc *mocks.NerdctlCmdCreator, logger *mocks.Logger, ctrl *gomock.Controller) {
108+
mockSvc: func(ncc *mocks.NerdctlCmdCreator, _ *mocks.Logger, ctrl *gomock.Controller) {
109109
command := mocks.NewCommand(ctrl)
110110
ncc.EXPECT().CreateWithoutStdio("version", "--format", "json").Return(command)
111111
//nolint: lll // Version output format is larger than 500
@@ -152,7 +152,7 @@ func TestVersionAction_run(t *testing.T) {
152152

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

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

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

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

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

282282
return c
283283
},
284-
mockSvc: func(ncc *mocks.NerdctlCmdCreator, logger *mocks.Logger, ctrl *gomock.Controller) {
284+
mockSvc: func(ncc *mocks.NerdctlCmdCreator, _ *mocks.Logger, ctrl *gomock.Controller) {
285285
command := mocks.NewCommand(ctrl)
286286
ncc.EXPECT().CreateWithoutStdio("version", "--format", "json").Return(command)
287287
command.EXPECT().Output().Return([]byte(nerdctlMockVersion), nil)

Diff for: e2e/vm/support_bundle_remote_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
//go:build darwin || windows
5-
64
package vm
75

86
import (
@@ -11,6 +9,7 @@ import (
119
"os"
1210
"path"
1311
"path/filepath"
12+
"runtime"
1413
"strings"
1514
"time"
1615

@@ -315,6 +314,9 @@ var testSupportBundle = func(o *option.Option) {
315314
gomega.Expect(bundleExists).Should(gomega.BeTrue())
316315
})
317316
ginkgo.It("Should fail to generate a support bundle when the VM is nonexistent", func() {
317+
if runtime.GOOS == "linux" {
318+
ginkgo.Skip("No VM on Linux")
319+
}
318320
command.New(o, "vm", "stop", "-f").WithoutCheckingExitCode().WithTimeoutInSeconds(30).Run()
319321
time.Sleep(1 * time.Second)
320322
command.New(o, "vm", "remove", "-f").WithoutCheckingExitCode().WithTimeoutInSeconds(20).Run()

Diff for: e2e/vm/vm_linux_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//go:build linux
5+
6+
// Package vm runs tests related to the virtual machine.
7+
package vm
8+
9+
import (
10+
"testing"
11+
12+
"github.com/onsi/ginkgo/v2"
13+
"github.com/onsi/gomega"
14+
15+
"github.com/runfinch/finch/e2e"
16+
)
17+
18+
//nolint:paralleltest // TestVM is like TestMain for the VM-related tests.
19+
func TestVM(t *testing.T) {
20+
const description = "Finch Virtual Machine E2E Tests"
21+
22+
o, err := e2e.CreateOption()
23+
if err != nil {
24+
t.Fatal(err)
25+
}
26+
27+
ginkgo.Describe("", func() {
28+
testSupportBundle(o)
29+
})
30+
31+
gomega.RegisterFailHandler(ginkgo.Fail)
32+
ginkgo.RunSpecs(t, description)
33+
}

Diff for: pkg/support/config_native_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ func (bc *bundleConfig) LogFiles() []string {
1313

1414
func (bc *bundleConfig) ConfigFiles() []string {
1515
return []string{
16-
bc.rootDir,
16+
bc.finch.ConfigFilePath(),
1717
}
1818
}

Diff for: pkg/support/support.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ type bufReader interface {
160160
}
161161

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

289289
func (bb *bundleBuilder) getOSVersion() (string, error) {
290290
var cmd command.Command
291-
if runtime.GOOS == "windows" {
291+
switch runtime.GOOS {
292+
case "windows":
292293
cmd = bb.ecc.Create("cmd", "/c", "ver")
293-
} else {
294+
case "darwin":
294295
cmd = bb.ecc.Create("sw_vers", "-productVersion")
296+
case "linux":
297+
cmd = bb.ecc.Create("uname", "-r")
298+
default:
299+
cmd = nil
300+
}
301+
302+
if cmd == nil {
303+
return "unknown", nil
295304
}
305+
296306
out, err := cmd.Output()
297307
if err != nil {
298308
return "", err

0 commit comments

Comments
 (0)