Skip to content

Commit 092d205

Browse files
authored
Add upgrade test on an air-gapped environment (elastic#3724)
It uses iptable to block outgoing packets to `artifacts.elastic.co`, which prevents the agent from downloading the upgrade artifact and the PGP key. It uses however a ESS cluster for fleet-server and ES.
1 parent f359bda commit 092d205

File tree

17 files changed

+352
-143
lines changed

17 files changed

+352
-143
lines changed

internal/pkg/composable/providers/host/host_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestContextProvider(t *testing.T) {
3030
require.NoError(t, err)
3131

3232
const checkInterval = 50 * time.Millisecond
33-
const testTimeout = 500 * time.Millisecond
33+
const testTimeout = 1 * time.Second
3434
c, err := config.NewConfigFrom(map[string]interface{}{
3535
"check_interval": checkInterval,
3636
})

pkg/testing/fetcher.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import (
2020
"github.com/hashicorp/go-multierror"
2121
)
2222

23-
const hashExt = ".sha512"
23+
const extAsc = ".asc"
24+
const extHash = ".sha512"
2425

2526
var (
2627
// ErrUnsupportedPlatform returned when the operating system and architecture combination is not supported.
@@ -133,7 +134,7 @@ func untar(archivePath string, extractDir string) error {
133134

134135
fi := f.FileInfo()
135136
mode := fi.Mode()
136-
abs := filepath.Join(extractDir, f.Name)
137+
abs := filepath.Join(extractDir, f.Name) //nolint:gosec // used only in tests
137138
switch {
138139
case mode.IsRegular():
139140
// just to be sure, it should already be created by Dir type
@@ -146,7 +147,7 @@ func untar(archivePath string, extractDir string) error {
146147
return fmt.Errorf("failed creating file %s: %w", abs, err)
147148
}
148149

149-
_, err = io.Copy(wf, tr)
150+
_, err = io.Copy(wf, tr) //nolint:gosec // used only in tests
150151
if closeErr := wf.Close(); closeErr != nil && err == nil {
151152
err = closeErr
152153
}
@@ -193,7 +194,7 @@ func unzip(archivePath string, extractDir string) error {
193194

194195
fi := f.FileInfo()
195196
mode := fi.Mode()
196-
abs := filepath.Join(extractDir, f.Name)
197+
abs := filepath.Join(extractDir, f.Name) //nolint:gosec // used only in tests
197198
switch {
198199
case mode.IsRegular():
199200
// just to be sure, it should already be created by Dir type
@@ -211,6 +212,7 @@ func unzip(archivePath string, extractDir string) error {
211212
}
212213
}()
213214

215+
//nolint:gosec // used only in tests
214216
if _, err = io.Copy(f, rc); err != nil {
215217
return fmt.Errorf("error writing file %s: %w", abs, err)
216218
}

pkg/testing/fetcher_artifact.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,13 @@ func (r *artifactResult) Fetch(ctx context.Context, l Logger, dir string) error
108108
}
109109

110110
// fetch package hash
111-
err = DownloadPackage(ctx, l, r.doer, r.src+hashExt, filepath.Join(dir, r.path+hashExt))
111+
err = DownloadPackage(ctx, l, r.doer, r.src+extHash, filepath.Join(dir, r.path+extHash))
112+
if err != nil {
113+
return fmt.Errorf("failed to download %s: %w", r.src, err)
114+
}
115+
116+
// fetch package asc
117+
err = DownloadPackage(ctx, l, r.doer, r.src+extAsc, filepath.Join(dir, r.path+extAsc))
112118
if err != nil {
113119
return fmt.Errorf("failed to download %s: %w", r.src, err)
114120
}

pkg/testing/fetcher_artifact_test.go

Lines changed: 44 additions & 51 deletions
Large diffs are not rendered by default.

pkg/testing/fetcher_local.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (r *localFetcherResult) Fetch(_ context.Context, _ Logger, dir string) erro
107107
}
108108

109109
// fetch artifact hash
110-
err = copyFile(fullPath+hashExt, path+hashExt)
110+
err = copyFile(fullPath+extHash, path+extHash)
111111
if err != nil {
112112
return fmt.Errorf("error copying file: %w", err)
113113
}

pkg/testing/fetcher_local_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ func TestLocalFetcher(t *testing.T) {
3535

3636
snapshotPath := fmt.Sprintf("elastic-agent-%s-SNAPSHOT-%s", baseVersion, suffix)
3737
require.NoError(t, os.WriteFile(filepath.Join(testdata, snapshotPath), snapshotContent, 0644))
38-
snapshotPathHash := fmt.Sprintf("elastic-agent-%s-SNAPSHOT-%s%s", baseVersion, suffix, hashExt)
38+
snapshotPathHash := fmt.Sprintf("elastic-agent-%s-SNAPSHOT-%s%s", baseVersion, suffix, extHash)
3939
require.NoError(t, os.WriteFile(filepath.Join(testdata, snapshotPathHash), snapshotContentHash, 0644))
4040
notSnapshotPath := fmt.Sprintf("elastic-agent-%s-%s", baseVersion, suffix)
4141
require.NoError(t, os.WriteFile(filepath.Join(testdata, notSnapshotPath), noSnapshotContent, 0644))
42-
notSnapshotPathHash := fmt.Sprintf("elastic-agent-%s-%s%s", baseVersion, suffix, hashExt)
42+
notSnapshotPathHash := fmt.Sprintf("elastic-agent-%s-%s%s", baseVersion, suffix, extHash)
4343
require.NoError(t, os.WriteFile(filepath.Join(testdata, notSnapshotPathHash), noSnapshotContentHash, 0644))
4444

4545
tcs := []struct {
@@ -88,7 +88,7 @@ func TestLocalFetcher(t *testing.T) {
8888
require.NoError(t, err)
8989

9090
assert.Equal(t, string(tc.want), string(content))
91-
contentHash, err := os.ReadFile(filepath.Join(tmp, got.Name()+hashExt))
91+
contentHash, err := os.ReadFile(filepath.Join(tmp, got.Name()+extHash))
9292
require.NoError(t, err)
9393

9494
assert.Equal(t, string(tc.wantHash), string(contentHash))

pkg/testing/fixture.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ type ExecErr struct {
537537
}
538538

539539
func (e *ExecErr) Error() string {
540-
return e.err.Error()
540+
return e.String()
541541
}
542542

543543
func (e *ExecErr) String() string {

pkg/testing/fixture_install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (f *Fixture) Install(ctx context.Context, installOpts *InstallOpts, opts ..
144144
f.collectDiagnostics()
145145
}
146146

147-
// environment variable AGENT_KEEP_INSTALLED=true will skip the uninstall
147+
// environment variable AGENT_KEEP_INSTALLED=true will skip the uninstallation
148148
// useful to debug the issue with the Elastic Agent
149149
if f.t.Failed() && keepInstalledFlag() {
150150
f.t.Logf("skipping uninstall; test failed and AGENT_KEEP_INSTALLED=true")

pkg/testing/multipass/provisioner.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,9 @@ func (p *provisioner) launch(ctx context.Context, cfg runner.Config, batch runne
158158
return fmt.Errorf("failed to marshal cloud-init configuration: %w", err)
159159
}
160160

161-
p.logger.Logf("Launching multipass instance %s", batch.ID)
162161
var output bytes.Buffer
163-
proc, err := process.Start("multipass",
164-
process.WithContext(ctx),
165-
process.WithArgs(args),
166-
process.WithCmdOptions(
167-
runner.AttachOut(&output),
168-
runner.AttachErr(&output)))
162+
p.logger.Logf("Launching multipass image %s", batch.ID)
163+
proc, err := process.Start("multipass", process.WithContext(ctx), process.WithArgs(args), process.WithCmdOptions(runner.AttachOut(&output), runner.AttachErr(&output)))
169164
if err != nil {
170165
return fmt.Errorf("failed to run multipass launch: %w", err)
171166
}

pkg/testing/ogc/provisioner.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (p *provisioner) Provision(ctx context.Context, cfg runner.Config, batches
7979
defer upCancel()
8080
upOutput, err := p.ogcUp(upCtx)
8181
if err != nil {
82-
return nil, err
82+
return nil, fmt.Errorf("ogc up failed: %w", err)
8383
}
8484

8585
// fetch the machines and run the batches on the machine
@@ -100,8 +100,8 @@ func (p *provisioner) Provision(ctx context.Context, cfg runner.Config, batches
100100
for _, b := range batches {
101101
machine, ok := findMachine(machines, b.ID)
102102
if !ok {
103-
// print the output so its clear what went wrong
104-
// without this it's unclear where OGC went wrong it
103+
// print the output so its clear what went wrong.
104+
// Without this it's unclear where OGC went wrong, it
105105
// doesn't do a great job of reporting a clean error
106106
fmt.Fprintf(os.Stdout, "%s\n", upOutput)
107107
return nil, fmt.Errorf("failed to find machine for batch ID: %s", b.ID)

0 commit comments

Comments
 (0)