e2e: extract shared elastic-agent download helpers from AgentInstallSuite#6611
e2e: extract shared elastic-agent download helpers from AgentInstallSuite#6611ycombinator wants to merge 7 commits intoelastic:mainfrom
Conversation
|
This pull request does not have a backport label. Could you fix it @ycombinator? 🙏
|
…uite Extract downloadElasticAgent, extractAgentArchive (and internal tar/zip helpers) into a new agent_download.go file so they can be reused by other E2E tests without duplication. Improvements over the original inline methods: - Caching: the downloaded archive is stored in os.UserCacheDir() and reused on subsequent runs if the remote .sha512 checksum matches, avoiding repeated 600 MB downloads - ExtractFilter callback: lets callers limit which entries are written to disk (complementing the existing FileReplacer) - Explicit chmod after extraction: ensures execute bits are preserved regardless of the process umask AgentInstallSuite is updated to call the shared helpers; behaviour is unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
6f69604 to
1ace6df
Compare
…e methods Replace the FileReplacer callback with the original extractZip/extractTar/copyFleetServer suite methods on AgentInstallSuite, matching the pre-refactor approach. The shared downloadElasticAgent function (with caching) remains in agent_download.go. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…t cache Avoids persistent cache growth in ~/Library/Caches (macOS) or ~/.cache (Linux). TempDir is cleared on reboot and is appropriate for CI/test artifacts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…code Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
michel-laterman
left a comment
There was a problem hiding this comment.
Mostly nitpicks, but we really should check return status codes before handling the response bodies
| // or more contributor license agreements. Licensed under the Elastic License; | ||
| // you may not use this file except in compliance with the Elastic License. | ||
|
|
||
| //go:build e2e && !requirefips |
There was a problem hiding this comment.
Do we need !requirefips?
| func agentCacheDir() string { | ||
| return filepath.Join(os.TempDir(), "fleet-server-e2e") | ||
| } |
There was a problem hiding this comment.
Should we clean the cache on suite teardown?
| if len(draSplit) == 3 { | ||
| draVersion = draSplit[0] + "-" + draSplit[2] // remove hash | ||
| } else if len(draSplit) > 3 { | ||
| t.Fatalf("Unsupported ELASTICSEARCH_VERSION format, expected 3 segments got: %s", draVersion) |
There was a problem hiding this comment.
| t.Fatalf("Unsupported ELASTICSEARCH_VERSION format, expected 3 segments got: %s", draVersion) | |
| t.Fatalf("Unsupported ELASTICSEARCH_VERSION format, expected 3 segments got: %v", draSplit) |
| } else if len(draSplit) > 3 { | ||
| t.Fatalf("Unsupported ELASTICSEARCH_VERSION format, expected 3 segments got: %s", draVersion) | ||
| } | ||
| t.Logf("Using ELASTICSEARCH_VERSION=%s for agent download", draVersion) |
There was a problem hiding this comment.
| t.Logf("Using ELASTICSEARCH_VERSION=%s for agent download", draVersion) | |
| t.Logf("Using version %s for agent download", draVersion) |
| } | ||
| t.Logf("Using ELASTICSEARCH_VERSION=%s for agent download", draVersion) | ||
|
|
||
| req, err := http.NewRequestWithContext(ctx, "GET", "https://artifacts-api.elastic.co/v1/search/"+draVersion, nil) |
There was a problem hiding this comment.
| req, err := http.NewRequestWithContext(ctx, "GET", "https://artifacts-api.elastic.co/v1/search/"+draVersion, nil) | |
| req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://artifacts-api.elastic.co/v1/search/"+draVersion, nil) |
| resp, err := client.Do(req) | ||
| if err != nil { | ||
| t.Fatalf("failed to query artifacts API: %v", err) | ||
| } | ||
|
|
||
| var body SearchResp | ||
| err = json.NewDecoder(resp.Body).Decode(&body) | ||
| resp.Body.Close() |
There was a problem hiding this comment.
We should probably ensure a 200 return before decoding the response
| } | ||
| tmpName := tmp.Name() | ||
|
|
||
| req, err = http.NewRequestWithContext(ctx, "GET", pkg.URL, nil) |
There was a problem hiding this comment.
| req, err = http.NewRequestWithContext(ctx, "GET", pkg.URL, nil) | |
| req, err = http.NewRequestWithContext(ctx, http.MethodGet, pkg.URL, nil) |
| // first whitespace-delimited field is returned. | ||
| func fetchRemoteSHA512(ctx context.Context, t *testing.T, client *http.Client, url string) string { | ||
| t.Helper() | ||
| req, err := http.NewRequestWithContext(ctx, "GET", url, nil) |
There was a problem hiding this comment.
| req, err := http.NewRequestWithContext(ctx, "GET", url, nil) | |
| req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) |
| t.Fatalf("failed to fetch sha512 file: %v", err) | ||
| } | ||
| defer resp.Body.Close() | ||
| data, err := io.ReadAll(resp.Body) |
There was a problem hiding this comment.
Check response code before reading body
Summary
downloadElasticAgent,extractAgentArchive, and internal tar/zip helpers fromAgentInstallSuiteinto a newtesting/e2e/agent_download.gofile so other E2E tests can reuse them without duplication. There will be a follow up PR that adds an E2E test for [OpAMP][E2E Test] Verify that EDOT Collectors can talk to Fleet over OpAMP #6394, and that test will also need to download Elastic Agent / EDOT Collector.os.UserCacheDir()/fleet-server-e2e/and reused on subsequent runs if the remote.sha512checksum matches, avoiding repeated 600 MB downloadsAgentInstallSuiteupdated to call the shared helpers; behaviour is unchanged🤖 Generated with Claude Code