@@ -28,12 +28,22 @@ func TestProxiedEnvironment(t *testing.T) {
28
28
t .Skip ("skipping test for k0s versions < 1.29.0" )
29
29
}
30
30
31
+ requiredEnvVars := []string {
32
+ "DR_S3_ENDPOINT" ,
33
+ "DR_S3_REGION" ,
34
+ "DR_S3_BUCKET" ,
35
+ "DR_S3_PREFIX" ,
36
+ "DR_ACCESS_KEY_ID" ,
37
+ "DR_SECRET_ACCESS_KEY" ,
38
+ }
39
+ RequireEnvVars (t , requiredEnvVars )
40
+
31
41
tc := lxd .NewCluster (& lxd.ClusterInput {
32
42
T : t ,
33
43
Nodes : 4 ,
34
44
WithProxy : true ,
35
45
Image : "debian/12" ,
36
- LicensePath : "licenses/license.yaml" ,
46
+ LicensePath : "licenses/snapshot- license.yaml" ,
37
47
EmbeddedClusterPath : "../output/bin/embedded-cluster" ,
38
48
})
39
49
defer tc .Cleanup ()
@@ -95,16 +105,78 @@ func TestProxiedEnvironment(t *testing.T) {
95
105
// check the installation state
96
106
checkInstallationState (t , tc )
97
107
108
+ testArgs := []string {}
109
+ for _ , envVar := range requiredEnvVars {
110
+ testArgs = append (testArgs , os .Getenv (envVar ))
111
+ }
112
+
113
+ if stdout , stderr , err := tc .RunPlaywrightTest ("create-backup" , testArgs ... ); err != nil {
114
+ t .Fatalf ("fail to run playwright test create-backup: %v: %s: %s" , err , stdout , stderr )
115
+ }
116
+
98
117
appUpgradeVersion := fmt .Sprintf ("appver-%s-upgrade" , os .Getenv ("SHORT_SHA" ))
99
- testArgs := []string {appUpgradeVersion }
100
118
101
119
t .Logf ("%s: upgrading cluster" , time .Now ().Format (time .RFC3339 ))
102
- if _ , _ , err := tc .RunPlaywrightTest ("deploy-upgrade" , testArgs ... ); err != nil {
120
+ if _ , _ , err := tc .RunPlaywrightTest ("deploy-upgrade" , appUpgradeVersion ); err != nil {
103
121
t .Fatalf ("fail to run playwright test deploy-app: %v" , err )
104
122
}
105
123
106
124
checkPostUpgradeState (t , tc )
107
125
126
+ // reset the cluster
127
+ runInParallel (t ,
128
+ func (t * testing.T ) error {
129
+ stdout , stderr , err := resetInstallationWithError (t , tc , 3 , resetInstallationOptions {force : true })
130
+ if err != nil {
131
+ return fmt .Errorf ("fail to reset the installation on node 3: %v: %s: %s" , err , stdout , stderr )
132
+ }
133
+ return nil
134
+ }, func (t * testing.T ) error {
135
+ stdout , stderr , err := resetInstallationWithError (t , tc , 2 , resetInstallationOptions {force : true })
136
+ if err != nil {
137
+ return fmt .Errorf ("fail to reset the installation on node 2: %v: %s: %s" , err , stdout , stderr )
138
+ }
139
+ return nil
140
+ }, func (t * testing.T ) error {
141
+ stdout , stderr , err := resetInstallationWithError (t , tc , 1 , resetInstallationOptions {force : true })
142
+ if err != nil {
143
+ return fmt .Errorf ("fail to reset the installation on node 1: %v: %s: %s" , err , stdout , stderr )
144
+ }
145
+ return nil
146
+ }, func (t * testing.T ) error {
147
+ stdout , stderr , err := resetInstallationWithError (t , tc , 0 , resetInstallationOptions {force : true })
148
+ if err != nil {
149
+ return fmt .Errorf ("fail to reset the installation on node 0: %v: %s: %s" , err , stdout , stderr )
150
+ }
151
+ return nil
152
+ },
153
+ )
154
+
155
+ t .Logf ("%s: waiting for nodes to reboot" , time .Now ().Format (time .RFC3339 ))
156
+ time .Sleep (30 * time .Second )
157
+
158
+ t .Logf ("%s: restoring the installation" , time .Now ().Format (time .RFC3339 ))
159
+ line = append ([]string {"restore-installation.exp" }, testArgs ... )
160
+ line = append (line , "--http-proxy" , lxd .HTTPProxy )
161
+ line = append (line , "--https-proxy" , lxd .HTTPProxy )
162
+ line = append (line , "--no-proxy" , strings .Join (tc .IPs , "," ))
163
+ if _ , _ , err := tc .RunCommandOnNode (0 , line , lxd .WithProxyEnv (tc .IPs )); err != nil {
164
+ t .Fatalf ("fail to restore the installation: %v" , err )
165
+ }
166
+
167
+ checkInstallationState (t , tc )
168
+
169
+ t .Logf ("%s: checking post-restore state" , time .Now ().Format (time .RFC3339 ))
170
+ line = []string {"check-post-restore.sh" }
171
+ if stdout , stderr , err := tc .RunCommandOnNode (0 , line ); err != nil {
172
+ t .Fatalf ("fail to check post-restore state: %v: %s: %s" , err , stdout , stderr )
173
+ }
174
+
175
+ t .Logf ("%s: validating restored app" , time .Now ().Format (time .RFC3339 ))
176
+ if _ , _ , err := tc .SetupPlaywrightAndRunTest ("validate-restore-app" ); err != nil {
177
+ t .Fatalf ("fail to run playwright test validate-restore-app: %v" , err )
178
+ }
179
+
108
180
t .Logf ("%s: test complete" , time .Now ().Format (time .RFC3339 ))
109
181
}
110
182
@@ -194,10 +266,9 @@ func TestProxiedCustomCIDR(t *testing.T) {
194
266
}
195
267
196
268
appUpgradeVersion := fmt .Sprintf ("appver-%s-upgrade" , os .Getenv ("SHORT_SHA" ))
197
- testArgs := []string {appUpgradeVersion }
198
269
199
270
t .Logf ("%s: upgrading cluster" , time .Now ().Format (time .RFC3339 ))
200
- if _ , _ , err := tc .RunPlaywrightTest ("deploy-upgrade" , testArgs ... ); err != nil {
271
+ if _ , _ , err := tc .RunPlaywrightTest ("deploy-upgrade" , appUpgradeVersion ); err != nil {
201
272
t .Fatalf ("fail to run playwright test deploy-app: %v" , err )
202
273
}
203
274
@@ -211,13 +282,23 @@ func TestInstallWithMITMProxy(t *testing.T) {
211
282
t .Skip ("skipping test for k0s versions < 1.29.0" )
212
283
}
213
284
285
+ requiredEnvVars := []string {
286
+ "DR_S3_ENDPOINT" ,
287
+ "DR_S3_REGION" ,
288
+ "DR_S3_BUCKET" ,
289
+ "DR_S3_PREFIX" ,
290
+ "DR_ACCESS_KEY_ID" ,
291
+ "DR_SECRET_ACCESS_KEY" ,
292
+ }
293
+ RequireEnvVars (t , requiredEnvVars )
294
+
214
295
tc := lxd .NewCluster (& lxd.ClusterInput {
215
296
T : t ,
216
297
Nodes : 4 ,
217
298
WithProxy : true ,
218
299
Image : "debian/12" ,
219
300
EmbeddedClusterPath : "../output/bin/embedded-cluster" ,
220
- LicensePath : "licenses/license.yaml" ,
301
+ LicensePath : "licenses/snapshot- license.yaml" ,
221
302
})
222
303
defer tc .Cleanup ()
223
304
@@ -287,11 +368,19 @@ func TestInstallWithMITMProxy(t *testing.T) {
287
368
// check the installation state
288
369
checkInstallationState (t , tc )
289
370
371
+ testArgs := []string {}
372
+ for _ , envVar := range requiredEnvVars {
373
+ testArgs = append (testArgs , os .Getenv (envVar ))
374
+ }
375
+
376
+ if stdout , stderr , err := tc .RunPlaywrightTest ("create-backup" , testArgs ... ); err != nil {
377
+ t .Fatalf ("fail to run playwright test create-backup: %v: %s: %s" , err , stdout , stderr )
378
+ }
379
+
290
380
appUpgradeVersion := fmt .Sprintf ("appver-%s-upgrade" , os .Getenv ("SHORT_SHA" ))
291
- testArgs := []string {appUpgradeVersion }
292
381
293
382
t .Logf ("%s: upgrading cluster" , time .Now ().Format (time .RFC3339 ))
294
- if _ , _ , err := tc .RunPlaywrightTest ("deploy-upgrade" , testArgs ... ); err != nil {
383
+ if _ , _ , err := tc .RunPlaywrightTest ("deploy-upgrade" , appUpgradeVersion ); err != nil {
295
384
t .Fatalf ("fail to run playwright test deploy-app: %v" , err )
296
385
}
297
386
@@ -301,6 +390,61 @@ func TestInstallWithMITMProxy(t *testing.T) {
301
390
t .Fatalf ("fail to check postupgrade state: %v" , err )
302
391
}
303
392
393
+ // reset the cluster
394
+ runInParallel (t ,
395
+ func (t * testing.T ) error {
396
+ stdout , stderr , err := resetInstallationWithError (t , tc , 3 , resetInstallationOptions {force : true })
397
+ if err != nil {
398
+ return fmt .Errorf ("fail to reset the installation on node 3: %v: %s: %s" , err , stdout , stderr )
399
+ }
400
+ return nil
401
+ }, func (t * testing.T ) error {
402
+ stdout , stderr , err := resetInstallationWithError (t , tc , 2 , resetInstallationOptions {force : true })
403
+ if err != nil {
404
+ return fmt .Errorf ("fail to reset the installation on node 2: %v: %s: %s" , err , stdout , stderr )
405
+ }
406
+ return nil
407
+ }, func (t * testing.T ) error {
408
+ stdout , stderr , err := resetInstallationWithError (t , tc , 1 , resetInstallationOptions {force : true })
409
+ if err != nil {
410
+ return fmt .Errorf ("fail to reset the installation on node 1: %v: %s: %s" , err , stdout , stderr )
411
+ }
412
+ return nil
413
+ }, func (t * testing.T ) error {
414
+ stdout , stderr , err := resetInstallationWithError (t , tc , 0 , resetInstallationOptions {force : true })
415
+ if err != nil {
416
+ return fmt .Errorf ("fail to reset the installation on node 0: %v: %s: %s" , err , stdout , stderr )
417
+ }
418
+ return nil
419
+ },
420
+ )
421
+
422
+ t .Logf ("%s: waiting for nodes to reboot" , time .Now ().Format (time .RFC3339 ))
423
+ time .Sleep (30 * time .Second )
424
+
425
+ t .Logf ("%s: restoring the installation" , time .Now ().Format (time .RFC3339 ))
426
+ line = append ([]string {"restore-installation.exp" }, testArgs ... )
427
+ line = append (line , "--http-proxy" , lxd .HTTPMITMProxy )
428
+ line = append (line , "--https-proxy" , lxd .HTTPMITMProxy )
429
+ line = append (line , "--no-proxy" , strings .Join (tc .IPs , "," ))
430
+ line = append (line , "--private-ca" , "/usr/local/share/ca-certificates/proxy/ca.crt" )
431
+ if _ , _ , err := tc .RunCommandOnNode (0 , line , lxd .WithMITMProxyEnv (tc .IPs )); err != nil {
432
+ t .Fatalf ("fail to restore the installation: %v" , err )
433
+ }
434
+
435
+ checkInstallationState (t , tc )
436
+
437
+ t .Logf ("%s: checking post-restore state" , time .Now ().Format (time .RFC3339 ))
438
+ line = []string {"check-post-restore.sh" }
439
+ if stdout , stderr , err := tc .RunCommandOnNode (0 , line ); err != nil {
440
+ t .Fatalf ("fail to check post-restore state: %v: %s: %s" , err , stdout , stderr )
441
+ }
442
+
443
+ t .Logf ("%s: validating restored app" , time .Now ().Format (time .RFC3339 ))
444
+ if _ , _ , err := tc .SetupPlaywrightAndRunTest ("validate-restore-app" ); err != nil {
445
+ t .Fatalf ("fail to run playwright test validate-restore-app: %v" , err )
446
+ }
447
+
304
448
t .Logf ("%s: test complete" , time .Now ().Format (time .RFC3339 ))
305
449
}
306
450
0 commit comments