@@ -28,12 +28,22 @@ func TestProxiedEnvironment(t *testing.T) {
2828 t .Skip ("skipping test for k0s versions < 1.29.0" )
2929 }
3030
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+
3141 tc := lxd .NewCluster (& lxd.ClusterInput {
3242 T : t ,
3343 Nodes : 4 ,
3444 WithProxy : true ,
3545 Image : "debian/12" ,
36- LicensePath : "licenses/license.yaml" ,
46+ LicensePath : "licenses/snapshot- license.yaml" ,
3747 EmbeddedClusterPath : "../output/bin/embedded-cluster" ,
3848 })
3949 defer tc .Cleanup ()
@@ -95,16 +105,78 @@ func TestProxiedEnvironment(t *testing.T) {
95105 // check the installation state
96106 checkInstallationState (t , tc )
97107
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+
98117 appUpgradeVersion := fmt .Sprintf ("appver-%s-upgrade" , os .Getenv ("SHORT_SHA" ))
99- testArgs := []string {appUpgradeVersion }
100118
101119 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 {
103121 t .Fatalf ("fail to run playwright test deploy-app: %v" , err )
104122 }
105123
106124 checkPostUpgradeState (t , tc )
107125
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+
108180 t .Logf ("%s: test complete" , time .Now ().Format (time .RFC3339 ))
109181}
110182
@@ -194,10 +266,9 @@ func TestProxiedCustomCIDR(t *testing.T) {
194266 }
195267
196268 appUpgradeVersion := fmt .Sprintf ("appver-%s-upgrade" , os .Getenv ("SHORT_SHA" ))
197- testArgs := []string {appUpgradeVersion }
198269
199270 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 {
201272 t .Fatalf ("fail to run playwright test deploy-app: %v" , err )
202273 }
203274
@@ -211,13 +282,23 @@ func TestInstallWithMITMProxy(t *testing.T) {
211282 t .Skip ("skipping test for k0s versions < 1.29.0" )
212283 }
213284
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+
214295 tc := lxd .NewCluster (& lxd.ClusterInput {
215296 T : t ,
216297 Nodes : 4 ,
217298 WithProxy : true ,
218299 Image : "debian/12" ,
219300 EmbeddedClusterPath : "../output/bin/embedded-cluster" ,
220- LicensePath : "licenses/license.yaml" ,
301+ LicensePath : "licenses/snapshot- license.yaml" ,
221302 })
222303 defer tc .Cleanup ()
223304
@@ -287,11 +368,19 @@ func TestInstallWithMITMProxy(t *testing.T) {
287368 // check the installation state
288369 checkInstallationState (t , tc )
289370
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+
290380 appUpgradeVersion := fmt .Sprintf ("appver-%s-upgrade" , os .Getenv ("SHORT_SHA" ))
291- testArgs := []string {appUpgradeVersion }
292381
293382 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 {
295384 t .Fatalf ("fail to run playwright test deploy-app: %v" , err )
296385 }
297386
@@ -301,6 +390,61 @@ func TestInstallWithMITMProxy(t *testing.T) {
301390 t .Fatalf ("fail to check postupgrade state: %v" , err )
302391 }
303392
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+
304448 t .Logf ("%s: test complete" , time .Now ().Format (time .RFC3339 ))
305449}
306450
0 commit comments