@@ -6,11 +6,14 @@ package integrationtest
66import (
77 "fmt"
88 "testing"
9+ "time"
910
1011 "github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1"
1112 "github.com/portworx/sched-ops/k8s/core"
13+ storkops "github.com/portworx/sched-ops/k8s/stork"
1214 "github.com/portworx/sched-ops/task"
1315 "github.com/portworx/torpedo/drivers/scheduler"
16+ "github.com/sirupsen/logrus"
1417 "github.com/stretchr/testify/require"
1518 v1 "k8s.io/api/core/v1"
1619 "k8s.io/apimachinery/pkg/api/errors"
@@ -54,10 +57,11 @@ func testMigrationFailoverFailback(t *testing.T) {
5457
5558 t .Run ("vanillaFailoverAndFailbackMigrationTest" , vanillaFailoverAndFailbackMigrationTest )
5659 t .Run ("rancherFailoverAndFailbackMigrationTest" , rancherFailoverAndFailbackMigrationTest )
60+ t .Run ("stickyFlagFailoverAndFailbackMigrationTest" , stickyFlagFailoverAndFailbackMigrationTest )
5761}
5862
5963func vanillaFailoverAndFailbackMigrationTest (t * testing.T ) {
60- failoverAndFailbackMigrationTest (t )
64+ failoverAndFailbackMigrationTest (t , "mysql-enc-pvc" , "mysql-migration-failover-failback" , true )
6165}
6266
6367func rancherFailoverAndFailbackMigrationTest (t * testing.T ) {
@@ -105,20 +109,22 @@ func rancherFailoverAndFailbackMigrationTest(t *testing.T) {
105109
106110 scaleFactor := testMigrationFailover (t , preMigrationCtx , ctxs , "" , appKey , instanceID )
107111
108- testMigrationFailback (t , preMigrationCtx , ctxs , scaleFactor , projectIDMappingsReverse , appKey , instanceID )
112+ testMigrationFailback (t , preMigrationCtx , ctxs , scaleFactor , projectIDMappingsReverse , appKey , instanceID , true )
109113}
110114
111- func failoverAndFailbackMigrationTest (t * testing.T ) {
115+ func stickyFlagFailoverAndFailbackMigrationTest (t * testing.T ) {
116+ failoverAndFailbackMigrationTest (t , "mysql-sticky" , "mysql-migration-sticky" , false )
117+ }
118+
119+ func failoverAndFailbackMigrationTest (t * testing.T , appKey , migrationKey string , failbackSuccessExpected bool ) {
112120
113- appKey := "mysql-enc-pvc"
114- instanceID := "mysql-migration-failover-failback"
115121 // Migrate the resources
116122 ctxs , preMigrationCtx := triggerMigration (
117123 t ,
118- instanceID ,
124+ migrationKey ,
119125 appKey ,
120126 nil ,
121- []string {instanceID },
127+ []string {migrationKey },
122128 true ,
123129 false ,
124130 false ,
@@ -150,9 +156,9 @@ func failoverAndFailbackMigrationTest(t *testing.T) {
150156 // validate the migration summary based on the application specs that were deployed by the test
151157 validateMigrationSummary (t , preMigrationCtx , expectedResources , expectedVolumes , migrationObj .Name , migrationObj .Namespace )
152158
153- scaleFactor := testMigrationFailover (t , preMigrationCtx , ctxs , "" , appKey , instanceID )
159+ scaleFactor := testMigrationFailover (t , preMigrationCtx , ctxs , "" , appKey , migrationKey )
154160
155- testMigrationFailback (t , preMigrationCtx , ctxs , scaleFactor , "" , appKey , instanceID )
161+ testMigrationFailback (t , preMigrationCtx , ctxs , scaleFactor , "" , appKey , migrationKey , failbackSuccessExpected )
156162}
157163
158164func testMigrationFailover (
@@ -242,6 +248,7 @@ func testMigrationFailback(
242248 scaleFactor map [string ]int32 ,
243249 projectIDMappings string ,
244250 appKey , instanceID string ,
251+ failbackSuccessExpected bool ,
245252) {
246253 // Failback the application
247254 // Trigger a reverse migration
@@ -251,6 +258,8 @@ func testMigrationFailback(
251258 require .NoError (t , err , "Error scheduling task" )
252259 require .Equal (t , 1 , len (ctxsReverse ), "Only one task should have started" )
253260
261+ appCtx := ctxsReverse [0 ]
262+
254263 err = schedulerDriver .WaitForRunning (ctxsReverse [0 ], defaultWaitTimeout , defaultWaitInterval )
255264 require .NoError (t , err , "Error waiting for app to get to running state" )
256265
@@ -265,6 +274,50 @@ func testMigrationFailback(
265274 scheduler.ScheduleOptions {AppKeys : []string {instanceID }})
266275 require .NoError (t , err , "Error scheduling migration specs" )
267276
277+ if ! failbackSuccessExpected {
278+ // In case of sticky volumes migration failure is expected, so will update volume and trigger migration again
279+ err = schedulerDriver .WaitForRunning (ctxsReverse [0 ], defaultWaitTimeout / 10 , defaultWaitInterval )
280+ require .Error (t , err , "Expected failback migration to fail" )
281+
282+ // Get volumes for this migration on source cluster and update sticky flag
283+ err = setSourceKubeConfig ()
284+ require .NoError (t , err , "Error resetting source config, for updating sticky volume" )
285+
286+ vols , err := schedulerDriver .GetVolumes (appCtx )
287+ require .NoError (t , err , "Error getting volumes for app" )
288+ for _ , v := range vols {
289+ err = volumeDriver .UpdateStickyFlag (v .ID , "off" )
290+ require .NoError (t , err , "Error updating sticky flag for volumes %s" , v .Name )
291+ }
292+ time .Sleep (3 * time .Minute )
293+
294+ // Trigger migration on destination cluster again
295+ err = setDestinationKubeConfig ()
296+ require .NoError (t , err , "Error setting destination config after updating sticky volume" )
297+
298+ var failedMigrationObj * v1alpha1.Migration
299+ var ok bool
300+ for _ , specObj := range ctxsReverse [0 ].App .SpecList {
301+ if failedMigrationObj , ok = specObj .(* v1alpha1.Migration ); ok {
302+ break
303+ }
304+ }
305+ failedMigrationObj , err = storkops .Instance ().GetMigration (failedMigrationObj .Name , failedMigrationObj .Namespace )
306+ require .NoError (t , err , "Error getting the failed migration" )
307+ logrus .Infof ("Failed migration object found: %s in namespace: %s. Status: %s" , failedMigrationObj .Name , failedMigrationObj .Namespace , failedMigrationObj .Status .Status )
308+
309+ err = deleteMigrations ([]* v1alpha1.Migration {failedMigrationObj })
310+ require .NoError (t , err , "error in deleting failed migrations." )
311+
312+ // apply migration specs again, it should pass this time
313+ err = schedulerDriver .AddTasks (ctxsReverse [0 ],
314+ scheduler.ScheduleOptions {AppKeys : []string {instanceID }})
315+ require .NoError (t , err , "Error scheduling migration specs" )
316+
317+ err = schedulerDriver .WaitForRunning (ctxsReverse [0 ], defaultWaitTimeout , defaultWaitInterval )
318+ require .NoError (t , err , "Error waiting for migration to complete post sticky flag update" )
319+ }
320+
268321 err = schedulerDriver .WaitForRunning (ctxsReverse [0 ], defaultWaitTimeout , defaultWaitInterval )
269322 require .NoError (t , err , "Error waiting for migration to complete" )
270323
@@ -322,8 +375,16 @@ func testMigrationFailback(
322375 require .Equal (t , projectValue , "project-A" )
323376 }
324377 }
325-
326378 destroyAndWait (t , []* scheduler.Context {postMigrationCtx })
379+ destroyAndWait (t , ctxs )
380+
381+ err = setDestinationKubeConfig ()
382+ require .NoError (t , err , "Error resetting remote config" )
383+ destroyAndWait (t , ctxsReverse )
384+
385+ err = setSourceKubeConfig ()
386+ require .NoError (t , err , "Error resetting remote config" )
387+
327388}
328389
329390// The below two functions are currently not invoked during the tests since the namespaceSelector
0 commit comments