-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathall_scripts_test.go
More file actions
181 lines (156 loc) · 5.34 KB
/
all_scripts_test.go
File metadata and controls
181 lines (156 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package installscript
import (
"fmt"
"os"
"regexp"
"strings"
"testing"
"time"
e2eos "github.com/DataDog/datadog-agent/test/e2e-framework/components/os"
"github.com/DataDog/datadog-agent/test/e2e-framework/scenarios/aws/ec2"
"github.com/stretchr/testify/require"
"github.com/DataDog/datadog-agent/test/e2e-framework/testing/e2e"
"github.com/DataDog/datadog-agent/test/e2e-framework/testing/environments"
awshost "github.com/DataDog/datadog-agent/test/e2e-framework/testing/provisioners/aws/host"
"github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/host"
installer "github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/unix"
)
type installerScriptTests func(os e2eos.Descriptor, arch e2eos.Architecture) installerScriptSuite
type installerScriptTestsWithSkippedFlavors struct {
t installerScriptTests
skippedFlavors []e2eos.Descriptor
}
var (
amd64Flavors = []e2eos.Descriptor{
e2eos.Ubuntu2404,
e2eos.AmazonLinux2,
e2eos.Debian12,
e2eos.RedHat9,
e2eos.CentOS7,
e2eos.Suse15,
}
arm64Flavors = []e2eos.Descriptor{
e2eos.Ubuntu2404,
e2eos.AmazonLinux2,
e2eos.Suse15,
}
scriptTestsWithSkippedFlavors = []installerScriptTestsWithSkippedFlavors{
{t: testDatabricksScript},
{t: testDefaultScript, skippedFlavors: []e2eos.Descriptor{e2eos.CentOS7}},
{t: testSSIScript},
}
)
func shouldSkipFlavor(flavors []e2eos.Descriptor, flavor e2eos.Descriptor) bool {
for _, f := range flavors {
if f.Flavor == flavor.Flavor && f.Version == flavor.Version {
return true
}
}
return false
}
func TestScripts(t *testing.T) {
if _, ok := os.LookupEnv("E2E_PIPELINE_ID"); !ok {
if _, ok := os.LookupEnv("CI_COMMIT_SHA"); !ok {
t.Log("CI_COMMIT_SHA & E2E_PIPELINE_ID env var are not set, this test requires one of these two variables to be set to work")
t.FailNow()
}
}
var flavors []e2eos.Descriptor
for _, flavor := range amd64Flavors {
flavor.Architecture = e2eos.AMD64Arch
flavors = append(flavors, flavor)
}
for _, flavor := range arm64Flavors {
flavor.Architecture = e2eos.ARM64Arch
flavors = append(flavors, flavor)
}
for _, f := range flavors {
for _, test := range scriptTestsWithSkippedFlavors {
flavor := f // capture range variable for parallel tests closure
if shouldSkipFlavor(test.skippedFlavors, flavor) {
continue
}
suite := test.t(flavor, flavor.Architecture)
t.Run(suite.Name(), func(t *testing.T) {
t.Parallel()
opts := []awshost.ProvisionerOption{
awshost.WithRunOptions(
ec2.WithEC2InstanceOptions(ec2.WithOSArch(flavor, flavor.Architecture)),
ec2.WithoutAgent(),
),
}
opts = append(opts, suite.ProvisionerOptions()...)
e2e.Run(t, suite,
e2e.WithProvisioner(awshost.Provisioner(opts...)),
e2e.WithStackName(suite.Name()),
)
})
}
}
}
type installerScriptSuite interface {
e2e.Suite[environments.Host]
Name() string
ProvisionerOptions() []awshost.ProvisionerOption
}
func newInstallerScriptSuite(pkg string, e2eos e2eos.Descriptor, arch e2eos.Architecture, opts ...awshost.ProvisionerOption) installerScriptBaseSuite {
return installerScriptBaseSuite{
scriptURLPrefix: "https://" + installer.InstallerScriptBaseURL() + "/scripts/",
os: e2eos,
arch: arch,
pkg: pkg,
opts: opts,
}
}
func (s *installerScriptBaseSuite) Name() string {
return regexp.MustCompile("[^a-zA-Z0-9]+").ReplaceAllString(fmt.Sprintf("%s/%s", s.pkg, s.os), "_")
}
func (s *installerScriptBaseSuite) ProvisionerOptions() []awshost.ProvisionerOption {
return s.opts
}
func (s *installerScriptBaseSuite) SetupSuite() {
s.BaseSuite.SetupSuite()
// SetupSuite needs to defer s.CleanupOnSetupFailure() if what comes after BaseSuite.SetupSuite() can fail.
defer s.CleanupOnSetupFailure()
s.host = host.New(s.T, s.Env().RemoteHost, s.os, s.arch)
}
type installerScriptBaseSuite struct {
scriptURLPrefix string
e2e.BaseSuite[environments.Host]
host *host.Host
opts []awshost.ProvisionerOption
pkg string
arch e2eos.Architecture
os e2eos.Descriptor
}
func (s *installerScriptBaseSuite) RunInstallScript(url string, params ...string) {
err := s.RunInstallScriptWithError(url, params...)
require.NoErrorf(s.T(), err, "install script failed")
}
func (s *installerScriptBaseSuite) RunInstallScriptWithError(url string, params ...string) error {
// Download scripts -- add retries for network issues
var err error
maxRetries := 5
for i := 0; i < maxRetries; i++ {
_, err = s.Env().RemoteHost.Execute(fmt.Sprintf("curl -L %s > install_script", url))
if err == nil {
break
}
if i == maxRetries-1 {
return err
}
time.Sleep(1 * time.Second)
}
scriptParams := append(params, "DD_API_KEY="+installer.GetAPIKey(), "DD_INSTALLER_REGISTRY_URL_INSTALLER_PACKAGE=installtesting.datad0g.com.internal.dda-testing.com")
_, err = s.Env().RemoteHost.Execute(strings.Join(scriptParams, " ") + " bash install_script")
return err
}
func (s *installerScriptBaseSuite) Purge() {
s.Env().RemoteHost.MustExecute("sudo rm -rf install_script")
s.Env().RemoteHost.Execute("sudo datadog-installer purge")
s.Env().RemoteHost.Execute("sudo rm -rf /etc/datadog-agent")
}