-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathmsi_install_test.go
More file actions
381 lines (323 loc) · 15.9 KB
/
Copy pathmsi_install_test.go
File metadata and controls
381 lines (323 loc) · 15.9 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
// 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 dotnettests
import (
_ "embed"
"fmt"
"os"
"github.com/DataDog/datadog-agent/pkg/util/testutil/flake"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
winawshost "github.com/DataDog/datadog-agent/test/new-e2e/pkg/provisioners/aws/host/windows"
installer "github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/unix"
installerwindows "github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/windows"
"github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/windows/consts"
"testing"
)
type testAgentMSIInstallsDotnetLibrary struct {
baseIISSuite
previousDotnetLibraryVersion installerwindows.PackageVersion
currentDotnetLibraryVersion installerwindows.PackageVersion
}
// TestDotnetInstalls tests the usage of the Datadog installer and the MSI to install the apm-library-dotnet-package package.
func TestAgentMSIInstallsDotnetLibrary(t *testing.T) {
e2e.Run(t, &testAgentMSIInstallsDotnetLibrary{},
e2e.WithProvisioner(
winawshost.ProvisionerNoAgentNoFakeIntake()))
}
func (s *testAgentMSIInstallsDotnetLibrary) SetupSuite() {
s.baseIISSuite.SetupSuite()
s.previousDotnetLibraryVersion = installerwindows.NewVersionFromPackageVersion(os.Getenv("PREVIOUS_DOTNET_VERSION_PACKAGE"))
if s.previousDotnetLibraryVersion.PackageVersion() == "" {
s.previousDotnetLibraryVersion = installerwindows.NewVersionFromPackageVersion("3.19.0-pipeline.67299728.beta.sha-c05ddfb1-1")
}
s.currentDotnetLibraryVersion = installerwindows.NewVersionFromPackageVersion(os.Getenv("CURRENT_DOTNET_VERSION_PACKAGE"))
if s.currentDotnetLibraryVersion.PackageVersion() == "" {
s.currentDotnetLibraryVersion = installerwindows.NewVersionFromPackageVersion("3.19.0-pipeline.67351320.beta.sha-c05ddfb1-1")
}
}
func (s *testAgentMSIInstallsDotnetLibrary) AfterTest(suiteName, testName string) {
s.Installer().Purge()
s.baseIISSuite.AfterTest(suiteName, testName)
}
// TestInstallFromMSI tests the Agent MSI can install the dotnet library OCI package
func (s *testAgentMSIInstallsDotnetLibrary) TestInstallFromMSI() {
// Arrange
version := s.currentDotnetLibraryVersion
// Act
s.installCurrentAgentVersion(
installerwindows.WithMSIArg("DD_APM_INSTRUMENTATION_ENABLED=iis"),
// TODO: remove override once image is published in prod
installerwindows.WithMSIArg("DD_INSTALLER_REGISTRY_URL=install.datad0g.com.internal.dda-testing.com"),
installerwindows.WithMSIArg(fmt.Sprintf("DD_APM_INSTRUMENTATION_LIBRARIES=dotnet:%s", version.Version())),
installerwindows.WithMSILogFile("install.log"),
)
// Start the IIS app to load the library
defer s.stopIISApp()
s.startIISApp(webConfigFile, aspxFile)
// Assert
s.assertSuccessfulPromoteExperiment(version.Version())
// Check that the expected version of the library is loaded
oldLibraryPath := s.getLibraryPathFromInstrumentedIIS()
s.Require().Contains(oldLibraryPath, version.Version())
}
// TestMSIThenRemoteUpgrade tests the dotnet library can be remotely upgraded from an Agent MSI installed version
func (s *testAgentMSIInstallsDotnetLibrary) TestMSIThenRemoteUpgrade() {
defer s.cleanupAgentConfig()
s.setAgentConfig()
oldVersion := s.previousDotnetLibraryVersion
newVersion := s.currentDotnetLibraryVersion
// Install first version
s.installCurrentAgentVersion(
installerwindows.WithMSIArg("DD_APM_INSTRUMENTATION_ENABLED=iis"),
// TODO: remove override once image is published in prod
// TODO: support DD_INSTALLER_REGISTRY_URL
installerwindows.WithMSIArg("DD_INSTALLER_REGISTRY_URL=install.datad0g.com.internal.dda-testing.com"),
installerwindows.WithMSIArg(fmt.Sprintf("DD_APM_INSTRUMENTATION_LIBRARIES=dotnet:%s", oldVersion.Version())),
installerwindows.WithMSILogFile("install.log"),
)
// Start the IIS app to load the library
defer s.stopIISApp()
s.startIISApp(webConfigFile, aspxFile)
// Check that the expected version of the library is loaded
s.assertSuccessfulPromoteExperiment(oldVersion.Version())
oldLibraryPath := s.getLibraryPathFromInstrumentedIIS()
s.Require().Contains(oldLibraryPath, oldVersion.Version())
// Start remote upgrade experiment
_, err := s.startExperimentCurrentDotnetLibrary(newVersion)
s.Require().NoError(err)
s.assertSuccessfulStartExperiment(newVersion.Version())
// Check that the old version of the library is still loaded since we have not restarted yet
oldLibraryPathAgain := s.getLibraryPathFromInstrumentedIIS()
s.Require().Contains(oldLibraryPathAgain, oldVersion.Version())
s.Require().Equal(oldLibraryPath, oldLibraryPathAgain)
// Restart the IIS application
s.startIISApp(webConfigFile, aspxFile)
// Check that the new version of the library is loaded
newLibraryPath := s.getLibraryPathFromInstrumentedIIS()
s.Require().Contains(newLibraryPath, newVersion.Version())
s.Require().NotEqual(oldLibraryPath, newLibraryPath)
// Promote the experiment
_, err = s.Installer().PromoteExperiment("datadog-apm-library-dotnet")
s.Require().NoError(err)
s.assertSuccessfulPromoteExperiment(newVersion.Version())
}
// TestUpgradeWithMSI tests the dotnet library can be upgraded from the MSI
func (s *testAgentMSIInstallsDotnetLibrary) TestUpgradeWithMSI() {
flake.Mark(s.T())
oldVersion := s.previousDotnetLibraryVersion
newVersion := s.currentDotnetLibraryVersion
// Install first version
s.installPreviousAgentVersion(
installerwindows.WithMSIArg("DD_APM_INSTRUMENTATION_ENABLED=iis"),
// TODO: remove override once image is published in prod
// TODO: support DD_INSTALLER_REGISTRY_URL
installerwindows.WithMSIArg("DD_INSTALLER_REGISTRY_URL=install.datad0g.com.internal.dda-testing.com"),
// TODO: update to use Version() when stable is updated
installerwindows.WithMSIArg(fmt.Sprintf("DD_APM_INSTRUMENTATION_LIBRARIES=dotnet:%s", oldVersion.PackageVersion())),
installerwindows.WithMSILogFile("install.log"),
)
// Start the IIS app to load the library
defer s.stopIISApp()
s.startIISApp(webConfigFile, aspxFile)
// Check that the expected version of the library is loaded
s.assertSuccessfulPromoteExperiment(oldVersion.Version())
oldLibraryPath := s.getLibraryPathFromInstrumentedIIS()
s.Require().Contains(oldLibraryPath, oldVersion.Version())
// Install the second version using a new Agent MSI
s.installCurrentAgentVersion(
installerwindows.WithMSIArg("DD_APM_INSTRUMENTATION_ENABLED=iis"),
// TODO: remove override once image is published in prod
// TODO: support DD_INSTALLER_REGISTRY_URL
installerwindows.WithMSIArg("DD_INSTALLER_REGISTRY_URL=install.datad0g.com.internal.dda-testing.com"),
installerwindows.WithMSIArg(fmt.Sprintf("DD_APM_INSTRUMENTATION_LIBRARIES=dotnet:%s", newVersion.Version())),
installerwindows.WithMSILogFile("upgrade.log"),
)
// Check that the new version became the stable version
s.assertSuccessfulPromoteExperiment(newVersion.Version())
// Check that the old version of the library is still loaded since we have not restarted yet
oldLibraryPathAgain := s.getLibraryPathFromInstrumentedIIS()
s.Require().Contains(oldLibraryPathAgain, oldVersion.Version())
s.Require().Equal(oldLibraryPath, oldLibraryPathAgain)
// Restart the IIS application
s.startIISApp(webConfigFile, aspxFile)
// Check that the new version of the library is loaded
newLibraryPath := s.getLibraryPathFromInstrumentedIIS()
s.Require().Contains(newLibraryPath, newVersion.Version())
s.Require().NotEqual(oldLibraryPath, newLibraryPath)
}
// TestMSIRollbackRemovesLibrary tests that the dotnet library is removed when the MSI installation fails
func (s *testAgentMSIInstallsDotnetLibrary) TestMSIRollbackRemovesLibrary() {
// Arrange
version := s.currentDotnetLibraryVersion
// Act
err := s.Installer().Install(
installerwindows.WithMSIArg("DD_APM_INSTRUMENTATION_ENABLED=iis"),
// TODO: remove override once image is published in prod
// TODO: support DD_INSTALLER_REGISTRY_URL
installerwindows.WithMSIArg("DD_INSTALLER_REGISTRY_URL=install.datad0g.com.internal.dda-testing.com"),
installerwindows.WithMSIArg(fmt.Sprintf("DD_APM_INSTRUMENTATION_LIBRARIES=dotnet:%s", version.Version())),
installerwindows.WithMSILogFile("install-rollback.log"),
installerwindows.WithMSIArg("WIXFAILWHENDEFERRED=1"),
)
s.Require().Error(err)
// Assert
s.Require().Host(s.Env().RemoteHost).
NoDirExists(`C:/ProgramData/Datadog/Installer/packages/datadog-apm-library-dotnet`)
}
// TestMSISkipRollbackIfInstalled tests that the newly installed dotnet library is not removed when the MSI upgrade fails
// if another version of the library was already installed.
func (s *testAgentMSIInstallsDotnetLibrary) TestMSISkipRollbackIfInstalled() {
// Arrange
oldVersion := s.previousDotnetLibraryVersion
newVersion := s.currentDotnetLibraryVersion
// Install first version
s.installPreviousAgentVersion(
installerwindows.WithMSIArg("DD_APM_INSTRUMENTATION_ENABLED=iis"),
// TODO: remove override once image is published in prod
// TODO: support DD_INSTALLER_REGISTRY_URL
installerwindows.WithMSIArg("DD_INSTALLER_REGISTRY_URL=install.datad0g.com.internal.dda-testing.com"),
// TODO: update to use Version() when stable is updated
installerwindows.WithMSIArg(fmt.Sprintf("DD_APM_INSTRUMENTATION_LIBRARIES=dotnet:%s", oldVersion.PackageVersion())),
installerwindows.WithMSILogFile("install.log"),
)
// Rollback during upgrade to the new version
err := s.Installer().Install(
installerwindows.WithMSIArg("DD_APM_INSTRUMENTATION_ENABLED=iis"),
// TODO: remove override once image is published in prod
// TODO: support DD_INSTALLER_REGISTRY_URL
installerwindows.WithMSIArg("DD_INSTALLER_REGISTRY_URL=install.datad0g.com.internal.dda-testing.com"),
installerwindows.WithMSIArg(fmt.Sprintf("DD_APM_INSTRUMENTATION_LIBRARIES=dotnet:%s", newVersion.Version())),
installerwindows.WithMSILogFile("install-rollback.log"),
installerwindows.WithMSIArg("WIXFAILWHENDEFERRED=1"),
)
s.Require().Error(err)
// Start IIS and check that the NEW version of the library is loaded
defer s.stopIISApp()
s.startIISApp(webConfigFile, aspxFile)
newLibraryPath := s.getLibraryPathFromInstrumentedIIS()
s.Require().Contains(newLibraryPath, newVersion.Version())
}
// TestUninstallKeepsLibrary tests that the dotnet library is not removed when the Agent MSI is uninstalled
func (s *testAgentMSIInstallsDotnetLibrary) TestUninstallKeepsLibrary() {
version := s.currentDotnetLibraryVersion
// Install the dotnet library with the Agent MSI
s.installCurrentAgentVersion(
installerwindows.WithMSIArg("DD_APM_INSTRUMENTATION_ENABLED=iis"),
// TODO: remove override once image is published in prod
installerwindows.WithMSIArg("DD_INSTALLER_REGISTRY_URL=install.datad0g.com.internal.dda-testing.com"),
installerwindows.WithMSIArg(fmt.Sprintf("DD_APM_INSTRUMENTATION_LIBRARIES=dotnet:%s", version.Version())),
installerwindows.WithMSILogFile("install.log"),
)
// Uninstall the Agent
err := s.Installer().Uninstall(
installerwindows.WithMSILogFile("uninstall.log"),
)
s.Require().NoError(err)
// Start the IIS app to load the library
defer s.stopIISApp()
s.startIISApp(webConfigFile, aspxFile)
// Check that the expected version of the library is loaded
oldLibraryPath := s.getLibraryPathFromInstrumentedIIS()
s.Require().Contains(oldLibraryPath, version.Version())
}
// TestUninstallScript validates that instrumentation is disabled after we run the uninstall script
func (s *testAgentMSIInstallsDotnetLibrary) TestUninstallScript() {
// Arrange
version := s.currentDotnetLibraryVersion
// Act
s.installCurrentAgentVersion(
installerwindows.WithMSIArg("DD_APM_INSTRUMENTATION_ENABLED=iis"),
// TODO: remove override once image is published in prod
installerwindows.WithMSIArg("DD_INSTALLER_REGISTRY_URL=install.datad0g.com.internal.dda-testing.com"),
installerwindows.WithMSIArg(fmt.Sprintf("DD_APM_INSTRUMENTATION_LIBRARIES=dotnet:%s", version.Version())),
installerwindows.WithMSILogFile("install.log"),
)
// Start the IIS app to load the library
defer s.stopIISApp()
s.startIISApp(webConfigFile, aspxFile)
// Assert
s.assertSuccessfulPromoteExperiment(version.Version())
// Check that the expected version of the library is loaded
oldLibraryPath := s.getLibraryPathFromInstrumentedIIS()
s.Require().Contains(oldLibraryPath, version.Version())
output, err := s.Env().RemoteHost.Execute(`&"C:\Program Files\Datadog\Datadog Agent\bin\scripts\iis-instrumentation.bat" --uninstall`)
s.Require().NoErrorf(err, "failed to run uninstall script: %s", output)
s.stopIISApp()
defer s.stopIISApp()
s.startIISApp(webConfigFile, aspxFile)
newLibraryPath := s.getLibraryPathFromInstrumentedIIS()
s.Require().Empty(newLibraryPath)
}
// TestUninstallScript validates that instrumentation is disabled after we run the uninstall script
func (s *testAgentMSIInstallsDotnetLibrary) TestMSIPurge() {
// Arrange
version := s.currentDotnetLibraryVersion
// Act
s.installCurrentAgentVersion(
installerwindows.WithMSIArg("DD_APM_INSTRUMENTATION_ENABLED=iis"),
// TODO: remove override once image is published in prod
installerwindows.WithMSIArg("DD_INSTALLER_REGISTRY_URL=install.datad0g.com.internal.dda-testing.com"),
installerwindows.WithMSIArg(fmt.Sprintf("DD_APM_INSTRUMENTATION_LIBRARIES=dotnet:%s", version.Version())),
installerwindows.WithMSILogFile("install.log"),
)
// Start the IIS app to load the library
defer s.stopIISApp()
s.startIISApp(webConfigFile, aspxFile)
// Assert
s.assertSuccessfulPromoteExperiment(version.Version())
// Check that the expected version of the library is loaded
oldLibraryPath := s.getLibraryPathFromInstrumentedIIS()
s.Require().Contains(oldLibraryPath, version.Version())
// uninstall the MSI with PURGE=1
options := []installerwindows.MsiOption{
installerwindows.WithMSILogFile("uninstall.log"),
installerwindows.WithMSIArg("PURGE=1"),
}
s.Require().NoError(s.Installer().Uninstall(options...))
// verify it is uninstalled
s.stopIISApp()
defer s.stopIISApp()
s.startIISApp(webConfigFile, aspxFile)
newLibraryPath := s.getLibraryPathFromInstrumentedIIS()
s.Require().Empty(newLibraryPath)
}
func (s *testAgentMSIInstallsDotnetLibrary) installPreviousAgentVersion(opts ...installerwindows.MsiOption) {
agentVersion := s.StableAgentVersion().Version()
options := []installerwindows.MsiOption{
installerwindows.WithOption(installerwindows.WithInstallerURL(s.StableAgentVersion().MSIPackage().URL)),
installerwindows.WithMSILogFile("install-previous-version.log"),
installerwindows.WithMSIArg(fmt.Sprintf("APIKEY=%s", installer.GetAPIKey())),
installerwindows.WithMSIArg("SITE=datadoghq.com"),
}
options = append(options, opts...)
s.Require().NoError(s.Installer().Install(options...))
// sanity check: make sure we did indeed install the stable version
s.Require().Host(s.Env().RemoteHost).
HasBinary(consts.BinaryPath).
// Don't check the binary signature because it could have been updated since the last stable was built
WithVersionMatchPredicate(func(version string) {
s.Require().Contains(version, agentVersion)
})
}
func (s *testAgentMSIInstallsDotnetLibrary) installCurrentAgentVersion(opts ...installerwindows.MsiOption) {
agentVersion := s.CurrentAgentVersion().Version()
options := []installerwindows.MsiOption{
installerwindows.WithOption(installerwindows.WithInstallerURL(s.CurrentAgentVersion().MSIPackage().URL)),
installerwindows.WithMSILogFile("install-current-version.log"),
installerwindows.WithMSIArg(fmt.Sprintf("APIKEY=%s", installer.GetAPIKey())),
installerwindows.WithMSIArg("SITE=datadoghq.com"),
}
options = append(options, opts...)
s.Require().NoError(s.Installer().Install(
options...,
))
// sanity check: make sure we did indeed install the stable version
s.Require().Host(s.Env().RemoteHost).
HasBinary(consts.BinaryPath).
// Don't check the binary signature because it could have been updated since the last stable was built
WithVersionMatchPredicate(func(version string) {
s.Require().Contains(version, agentVersion)
})
}