Skip to content

Commit b1d54be

Browse files
authored
do not use CI api key in test infra (#41793)
### What does this PR do? Use `E2E_API_KEY` for test infra apikey instead of `DD_API_KEY` ### Motivation https://datadoghq.atlassian.net/browse/WINA-1910 `DD_API_KEY` was referenced to have an option for local testing, but the CI sets this var to report results and other telemetry, and this was overriding the expected API key from the runner config.
1 parent 7bc679d commit b1d54be

File tree

7 files changed

+30
-75
lines changed

7 files changed

+30
-75
lines changed

test/new-e2e/tests/installer/script/all_scripts_test.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ import (
2020
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
2121
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments"
2222
awshost "github.com/DataDog/datadog-agent/test/new-e2e/pkg/provisioners/aws/host"
23-
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner"
24-
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner/parameters"
2523
"github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/host"
24+
installer "github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/unix"
2625
)
2726

2827
type installerScriptTests func(os e2eos.Descriptor, arch e2eos.Architecture) installerScriptSuite
@@ -162,18 +161,6 @@ func (s *installerScriptBaseSuite) RunInstallScript(url string, params ...string
162161
require.NoErrorf(s.T(), err, "install script failed")
163162
}
164163

165-
func (s *installerScriptBaseSuite) getAPIKey() string {
166-
apiKey := os.Getenv("DD_API_KEY")
167-
if apiKey == "" {
168-
var err error
169-
apiKey, err = runner.GetProfile().SecretStore().Get(parameters.APIKey)
170-
if apiKey == "" || err != nil {
171-
apiKey = "deadbeefdeadbeefdeadbeefdeadbeef"
172-
}
173-
}
174-
return apiKey
175-
}
176-
177164
func (s *installerScriptBaseSuite) RunInstallScriptWithError(url string, params ...string) error {
178165
// Download scripts -- add retries for network issues
179166
var err error
@@ -189,7 +176,7 @@ func (s *installerScriptBaseSuite) RunInstallScriptWithError(url string, params
189176
time.Sleep(1 * time.Second)
190177
}
191178

192-
scriptParams := append(params, fmt.Sprintf("DD_API_KEY=%s", s.getAPIKey()), "DD_INSTALLER_REGISTRY_URL_INSTALLER_PACKAGE=installtesting.datad0g.com.internal.dda-testing.com")
179+
scriptParams := append(params, fmt.Sprintf("DD_API_KEY=%s", installer.GetAPIKey()), "DD_INSTALLER_REGISTRY_URL_INSTALLER_PACKAGE=installtesting.datad0g.com.internal.dda-testing.com")
193180
_, err = s.Env().RemoteHost.Execute(fmt.Sprintf("%s bash install_script", strings.Join(scriptParams, " ")))
194181
return err
195182
}

test/new-e2e/tests/installer/script/default_script_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
awshost "github.com/DataDog/datadog-agent/test/new-e2e/pkg/provisioners/aws/host"
1919
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client"
20+
installer "github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/unix"
2021
)
2122

2223
type installScriptDefaultSuite struct {
@@ -119,7 +120,7 @@ func (s *installScriptDefaultSuite) TestInstallParity() {
119120
s.Env().RemoteHost.MustExecute("sudo systemctl daemon-reexec")
120121
}
121122
_, err := s.Env().RemoteHost.Execute(fmt.Sprintf(`%s bash -c "$(curl -L https://dd-agent.s3.amazonaws.com/scripts/install_script_agent7.sh)"`, strings.Join(params, " ")), client.WithEnvVariables(map[string]string{
122-
"DD_API_KEY": s.getAPIKey(),
123+
"DD_API_KEY": installer.GetAPIKey(),
123124
"TESTING_KEYS_URL": "apttesting.datad0g.com/test-keys",
124125
"TESTING_APT_URL": fmt.Sprintf("s3.amazonaws.com/apttesting.datad0g.com/datadog-agent/pipeline-%s-a7", os.Getenv("E2E_PIPELINE_ID")),
125126
"TESTING_APT_REPO_VERSION": fmt.Sprintf("stable-%s 7", s.arch),
@@ -158,7 +159,7 @@ func (s *installScriptDefaultSuite) TestInstallParity() {
158159
// the major / minor version when installing the agent
159160
func (s *installScriptDefaultSuite) TestInstallIgnoreMajorMinor() {
160161
params := []string{
161-
"DD_API_KEY=" + s.getAPIKey(),
162+
"DD_API_KEY=" + installer.GetAPIKey(),
162163
"DD_REMOTE_UPDATES=true",
163164
"DD_AGENT_MAJOR_VERSION=7",
164165
"DD_AGENT_MINOR_VERSION=65.0",

test/new-e2e/tests/installer/unix/package_definitions.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"strings"
1414
"testing"
1515

16+
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner"
17+
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner/parameters"
1618
e2eos "github.com/DataDog/test-infra-definitions/components/os"
1719
"github.com/google/go-containerregistry/pkg/crane"
1820
v1 "github.com/google/go-containerregistry/pkg/v1"
@@ -82,11 +84,7 @@ var PackagesConfig = []TestPackageConfig{
8284
}
8385

8486
func installScriptPackageManagerEnv(env map[string]string, arch e2eos.Architecture) {
85-
apiKey := os.Getenv("DD_API_KEY")
86-
if apiKey == "" {
87-
apiKey = "deadbeefdeadbeefdeadbeefdeadbeef"
88-
}
89-
env["DD_API_KEY"] = apiKey
87+
env["DD_API_KEY"] = GetAPIKey()
9088
env["DD_SITE"] = "datadoghq.com"
9189
// Install Script env variables
9290
env["TESTING_KEYS_URL"] = "apttesting.datad0g.com/test-keys"
@@ -129,16 +127,26 @@ func InstallScriptEnvWithPackages(arch e2eos.Architecture, packagesConfig []Test
129127
// InstallInstallerScriptEnvWithPackages returns the environment variables for the installer script for the given packages
130128
func InstallInstallerScriptEnvWithPackages() map[string]string {
131129
env := map[string]string{}
132-
apiKey := os.Getenv("DD_API_KEY")
133-
if apiKey == "" {
134-
apiKey = "deadbeefdeadbeefdeadbeefdeadbeef"
135-
}
136-
env["DD_API_KEY"] = apiKey
130+
env["DD_API_KEY"] = GetAPIKey()
137131
env["DD_SITE"] = "datadoghq.com"
138132
installScriptInstallerEnv(env, PackagesConfig)
139133
return env
140134
}
141135

136+
// GetAPIKey returns the API key from the runner config, or a default value if not set
137+
//
138+
// Set the key in ~/.test_infra_config.yaml or use the E2E_API_KEY env var
139+
//
140+
// Do not use the DD_API_KEY env var, the CI uses it to report results to org2, the tests
141+
// should use a different key.
142+
func GetAPIKey() string {
143+
apiKey, err := runner.GetProfile().SecretStore().Get(parameters.APIKey)
144+
if apiKey == "" || err != nil {
145+
apiKey = "deadbeefdeadbeefdeadbeefdeadbeef"
146+
}
147+
return apiKey
148+
}
149+
142150
// PipelineAgentVersion returns the version of the pipeline agent
143151
func PipelineAgentVersion(t *testing.T) string {
144152
ref := fmt.Sprintf("installtesting.datad0g.com/agent-package:pipeline-%s", os.Getenv("E2E_PIPELINE_ID"))

test/new-e2e/tests/installer/windows/install_script.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package installer
77

88
import (
99
"fmt"
10-
"os"
1110
"path/filepath"
1211
"strings"
1312

@@ -75,15 +74,7 @@ func (b *baseInstaller) getInstallerURL(params Params) (string, error) {
7574
// Always sets DD_REMOTE_UPDATES to true to ensure remote updates are enabled.
7675
func (b *baseInstaller) getBaseEnvVars() map[string]string {
7776
envVars := installer.InstallScriptEnv(e2eos.AMD64Arch)
78-
apiKey := os.Getenv("DD_API_KEY")
79-
if apiKey == "" {
80-
var err error
81-
apiKey, err = runner.GetProfile().SecretStore().Get(parameters.APIKey)
82-
if apiKey == "" || err != nil {
83-
apiKey = "deadbeefdeadbeefdeadbeefdeadbeef"
84-
}
85-
}
86-
envVars["DD_API_KEY"] = apiKey
77+
envVars["DD_API_KEY"] = installer.GetAPIKey()
8778
for k, v := range b.params.extraEnvVars {
8879
envVars[k] = v
8980
}

test/new-e2e/tests/installer/windows/installer.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
e2eos "github.com/DataDog/test-infra-definitions/components/os"
2020

2121
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments"
22-
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner"
23-
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner/parameters"
2422
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client"
2523
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/optional"
2624
installer "github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/unix"
@@ -86,16 +84,8 @@ func (d *DatadogInstaller) SetBinaryPath(path string) {
8684

8785
func (d *DatadogInstaller) execute(cmd string, options ...client.ExecuteOption) (string, error) {
8886
// Ensure the API key and site are set for telemetry
89-
apiKey := os.Getenv("DD_API_KEY")
90-
if apiKey == "" {
91-
var err error
92-
apiKey, err = runner.GetProfile().SecretStore().Get(parameters.APIKey)
93-
if apiKey == "" || err != nil {
94-
apiKey = "deadbeefdeadbeefdeadbeefdeadbeef"
95-
}
96-
}
9787
envVars := map[string]string{
98-
"DD_API_KEY": apiKey,
88+
"DD_API_KEY": installer.GetAPIKey(),
9989
"DD_SITE": "datadoghq.com",
10090
}
10191

test/new-e2e/tests/installer/windows/suites/agent-package/upgrade_test.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import (
1717

1818
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
1919
winawshost "github.com/DataDog/datadog-agent/test/new-e2e/pkg/provisioners/aws/host/windows"
20-
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner"
21-
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner/parameters"
20+
installer "github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/unix"
2221
installerwindows "github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/windows"
2322
"github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/windows/consts"
2423
windowscommon "github.com/DataDog/datadog-agent/test/new-e2e/tests/windows/common"
@@ -658,15 +657,7 @@ func (s *testAgentUpgradeSuite) setAgentConfigWithAltDir(path string) {
658657
s.Env().RemoteHost.MkdirAll(path)
659658
configPath := path + `\datadog.yaml`
660659
// Ensure the API key is set for telemetry
661-
apiKey := os.Getenv("DD_API_KEY")
662-
if apiKey == "" {
663-
var err error
664-
apiKey, err = runner.GetProfile().SecretStore().Get(parameters.APIKey)
665-
if apiKey == "" || err != nil {
666-
apiKey = "deadbeefdeadbeefdeadbeefdeadbeef"
667-
}
668-
}
669-
660+
apiKey := installer.GetAPIKey()
670661
s.Env().RemoteHost.WriteFile(configPath, []byte(`
671662
api_key: `+apiKey+`
672663
site: datadoghq.com

test/new-e2e/tests/installer/windows/suites/apm-library-dotnet-package/msi_install_test.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import (
1313
"github.com/DataDog/datadog-agent/pkg/util/testutil/flake"
1414
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
1515
winawshost "github.com/DataDog/datadog-agent/test/new-e2e/pkg/provisioners/aws/host/windows"
16-
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner"
17-
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/runner/parameters"
16+
installer "github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/unix"
1817
installerwindows "github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/windows"
1918
"github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/windows/consts"
2019

@@ -365,7 +364,7 @@ func (s *testAgentMSIInstallsDotnetLibrary) installPreviousAgentVersion(opts ...
365364
options := []installerwindows.MsiOption{
366365
installerwindows.WithOption(installerwindows.WithInstallerURL(s.StableAgentVersion().MSIPackage().URL)),
367366
installerwindows.WithMSILogFile("install-previous-version.log"),
368-
installerwindows.WithMSIArg(fmt.Sprintf("APIKEY=%s", s.getAPIKey())),
367+
installerwindows.WithMSIArg(fmt.Sprintf("APIKEY=%s", installer.GetAPIKey())),
369368
installerwindows.WithMSIArg("SITE=datadoghq.com"),
370369
}
371370
options = append(options, opts...)
@@ -386,7 +385,7 @@ func (s *testAgentMSIInstallsDotnetLibrary) installCurrentAgentVersion(opts ...i
386385
options := []installerwindows.MsiOption{
387386
installerwindows.WithOption(installerwindows.WithInstallerURL(s.CurrentAgentVersion().MSIPackage().URL)),
388387
installerwindows.WithMSILogFile("install-current-version.log"),
389-
installerwindows.WithMSIArg(fmt.Sprintf("APIKEY=%s", s.getAPIKey())),
388+
installerwindows.WithMSIArg(fmt.Sprintf("APIKEY=%s", installer.GetAPIKey())),
390389
installerwindows.WithMSIArg("SITE=datadoghq.com"),
391390
}
392391
options = append(options, opts...)
@@ -402,15 +401,3 @@ func (s *testAgentMSIInstallsDotnetLibrary) installCurrentAgentVersion(opts ...i
402401
s.Require().Contains(version, agentVersion)
403402
})
404403
}
405-
406-
func (s *testAgentMSIInstallsDotnetLibrary) getAPIKey() string {
407-
apiKey := os.Getenv("DD_API_KEY")
408-
if apiKey == "" {
409-
var err error
410-
apiKey, err = runner.GetProfile().SecretStore().Get(parameters.APIKey)
411-
if apiKey == "" || err != nil {
412-
apiKey = "deadbeefdeadbeefdeadbeefdeadbeef"
413-
}
414-
}
415-
return apiKey
416-
}

0 commit comments

Comments
 (0)