Skip to content

Commit f30e510

Browse files
committed
Added tests for storkctl clusterpair options
1 parent fde4888 commit f30e510

File tree

5 files changed

+311
-18
lines changed

5 files changed

+311
-18
lines changed

test/integration_test/common_test.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import (
2020
snapv1 "github.com/kubernetes-incubator/external-storage/snapshot/pkg/apis/crd/v1"
2121
oputils "github.com/libopenstorage/operator/drivers/storage/portworx/util"
2222
opcorev1 "github.com/libopenstorage/operator/pkg/apis/core/v1"
23-
"github.com/libopenstorage/stork/pkg/aetosutils"
24-
aetosLogger "github.com/libopenstorage/stork/pkg/log"
2523
"github.com/portworx/sched-ops/k8s/apps"
2624
"github.com/portworx/sched-ops/k8s/batch"
2725
"github.com/portworx/sched-ops/k8s/core"
@@ -68,7 +66,9 @@ import (
6866
_ "github.com/libopenstorage/stork/drivers/volume/gcp"
6967
_ "github.com/libopenstorage/stork/drivers/volume/linstor"
7068
_ "github.com/libopenstorage/stork/drivers/volume/portworx"
69+
"github.com/libopenstorage/stork/pkg/aetosutils"
7170
storkv1 "github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1"
71+
aetosLogger "github.com/libopenstorage/stork/pkg/log"
7272
"github.com/libopenstorage/stork/pkg/schedule"
7373
"github.com/libopenstorage/stork/pkg/storkctl"
7474
"github.com/libopenstorage/stork/pkg/version"
@@ -834,7 +834,7 @@ func scheduleClusterPair(ctx *scheduler.Context, skipStorage, resetConfig bool,
834834
}
835835

836836
// Create a cluster pair from source to destination and another cluster pair from destination to source
837-
func scheduleBidirectionalClusterPair(cpName, cpNamespace, projectMappings string, objectStoreType storkv1.BackupLocationType, secretName string) error {
837+
func scheduleBidirectionalClusterPair(cpName, cpNamespace, projectMappings string, objectStoreType storkv1.BackupLocationType, secretName string, args map[string]string) error {
838838
//var token string
839839
// Setting kubeconfig to source because we will create bidirectional cluster pair based on source as reference
840840
err := setSourceKubeConfig()
@@ -937,13 +937,23 @@ func scheduleBidirectionalClusterPair(cpName, cpNamespace, projectMappings strin
937937
cmdArgs = append(cmdArgs, projectMappings)
938938
}
939939

940-
// Get external object store details and append to the command accordingily
941-
objectStoreArgs, err := getObjectStoreArgs(objectStoreType, secretName)
942-
if err != nil {
943-
return fmt.Errorf("failed to get %s secret in configmap secret-config in default namespace", objectStoreType)
940+
if objectStoreType != "" {
941+
// Get external object store details and append to the command accordingily
942+
objectStoreArgs, err := getObjectStoreArgs(objectStoreType, secretName)
943+
if err != nil {
944+
return fmt.Errorf("failed to get %s secret in configmap secret-config in default namespace", objectStoreType)
945+
}
946+
cmdArgs = append(cmdArgs, objectStoreArgs...)
947+
}
948+
949+
if args != nil {
950+
// Get external object store details and append to the command accordingily
951+
for k, v := range args {
952+
cmdArgs = append(cmdArgs, fmt.Sprintf("--%v", k))
953+
cmdArgs = append(cmdArgs, fmt.Sprintf("%v", v))
954+
}
944955
}
945956

946-
cmdArgs = append(cmdArgs, objectStoreArgs...)
947957
cmd.SetArgs(cmdArgs)
948958
logrus.Infof("Following is the bidirectional command: %v", cmdArgs)
949959
if err := cmd.Execute(); err != nil {

test/integration_test/migration_features_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ import (
99
"testing"
1010
"time"
1111

12-
storkapi "github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1"
13-
"github.com/libopenstorage/stork/pkg/resourcecollector"
1412
"github.com/portworx/sched-ops/k8s/core"
1513
storkops "github.com/portworx/sched-ops/k8s/stork"
1614
"github.com/portworx/torpedo/pkg/asyncdr"
1715
"github.com/sirupsen/logrus"
1816
"github.com/stretchr/testify/require"
1917
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2018
"k8s.io/client-go/tools/clientcmd"
19+
20+
storkapi "github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1"
21+
"github.com/libopenstorage/stork/pkg/resourcecollector"
2122
)
2223

2324
var (
@@ -92,7 +93,7 @@ func migrationStashStrategy(t *testing.T, appName string, appPath string) {
9293
err = setSourceKubeConfig()
9394
require.NoError(t, err, "Error setting source kubeconfig")
9495

95-
err = scheduleBidirectionalClusterPair(clusterPairName, appData.Ns, "", storkapi.BackupLocationType(backupLocation), backupSecret)
96+
err = scheduleBidirectionalClusterPair(clusterPairName, appData.Ns, "", storkapi.BackupLocationType(backupLocation), backupSecret, nil)
9697
require.NoError(t, err, "Error creating cluster pair")
9798

9899
err = setSourceKubeConfig()
@@ -294,7 +295,7 @@ func testMigrationStashStrategyWithStartApplication(t *testing.T) {
294295
err = setSourceKubeConfig()
295296
require.NoError(t, err, "Error setting source kubeconfig")
296297

297-
err = scheduleBidirectionalClusterPair(clusterPairName, appData.Ns, "", storkapi.BackupLocationType(backupLocation), backupSecret)
298+
err = scheduleBidirectionalClusterPair(clusterPairName, appData.Ns, "", storkapi.BackupLocationType(backupLocation), backupSecret, nil)
298299
require.NoError(t, err, "Error creating cluster pair")
299300

300301
// set stashstrategy
@@ -393,7 +394,7 @@ func testMultipleTimesMigrationsWithStashStrategy(t *testing.T) {
393394
err = setSourceKubeConfig()
394395
require.NoError(t, err, "Error setting source kubeconfig")
395396

396-
err = scheduleBidirectionalClusterPair(clusterPairName, appData.Ns, "", storkapi.BackupLocationType(backupLocation), backupSecret)
397+
err = scheduleBidirectionalClusterPair(clusterPairName, appData.Ns, "", storkapi.BackupLocationType(backupLocation), backupSecret, nil)
397398
require.NoError(t, err, "Error creating cluster pair")
398399

399400
// set stashstrategy
@@ -535,7 +536,7 @@ func testFailbackWithStashStrategy(t *testing.T) {
535536

536537
// creating migration and clusterpair in kube-system namespace as we have to delete the ns in source for failback
537538
migrationNamespace := "kube-system"
538-
err = scheduleBidirectionalClusterPair(clusterPairName, migrationNamespace, "", storkapi.BackupLocationType(backupLocation), backupSecret)
539+
err = scheduleBidirectionalClusterPair(clusterPairName, migrationNamespace, "", storkapi.BackupLocationType(backupLocation), backupSecret, nil)
539540
require.NoError(t, err, "Error creating cluster pair")
540541

541542
// set stashstrategy

test/integration_test/migration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ func bidirectionalClusterPairTest(t *testing.T) {
15091509
// Scheduler cluster pairs: source cluster --> destination cluster and destination cluster --> source cluster
15101510
for location, secret := range cmData {
15111511
logrus.Infof("Creating a bidirectional-pair using %s as objectstore.", location)
1512-
err := scheduleBidirectionalClusterPair(clusterPairName, clusterPairNamespace, "", storkv1.BackupLocationType(location), secret)
1512+
err := scheduleBidirectionalClusterPair(clusterPairName, clusterPairNamespace, "", storkv1.BackupLocationType(location), secret, nil)
15131513
require.NoError(t, err, "failed to set bidirectional cluster pair: %v", err)
15141514

15151515
err = setSourceKubeConfig()
@@ -2692,7 +2692,7 @@ func scheduleClusterPairGeneric(t *testing.T, ctxs []*scheduler.Context,
26922692
logrus.Infof("Namespace: %s", clusterPairNamespace)
26932693
logrus.Infof("Backuplocation: %s", defaultBackupLocation)
26942694
logrus.Infof("Secret name: %s", defaultSecretName)
2695-
err = scheduleBidirectionalClusterPair(remotePairName, clusterPairNamespace, projectIDMappings, defaultBackupLocation, defaultSecretName)
2695+
err = scheduleBidirectionalClusterPair(remotePairName, clusterPairNamespace, projectIDMappings, defaultBackupLocation, defaultSecretName, nil)
26962696
require.NoError(t, err, "failed to set bidirectional cluster pair: %v", err)
26972697
err = setSourceKubeConfig()
26982698
require.NoError(t, err, "failed to set kubeconfig to source cluster: %v", err)

test/integration_test/operator_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import (
99
"testing"
1010
"time"
1111

12-
storkv1 "github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1"
1312
"github.com/portworx/sched-ops/k8s/core"
1413
"github.com/portworx/torpedo/pkg/asyncdr"
1514
"github.com/portworx/torpedo/pkg/log"
1615
"github.com/sirupsen/logrus"
1716
"github.com/stretchr/testify/require"
17+
18+
storkv1 "github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1"
1819
)
1920

2021
var (
@@ -83,7 +84,7 @@ func validateAndDestroyCrMigration(t *testing.T, appName string, appPath string)
8384
err = asyncdr.ValidateCRD(appData.ExpectedCrdList, sourceClusterConfigPath)
8485
require.NoError(t, err, "Error validating source crds")
8586

86-
err = scheduleBidirectionalClusterPair(clusterPairName, appData.Ns, "", storkv1.BackupLocationType(backupLocation), backupSecret)
87+
err = scheduleBidirectionalClusterPair(clusterPairName, appData.Ns, "", storkv1.BackupLocationType(backupLocation), backupSecret, nil)
8788
require.NoError(t, err, "Error creating cluster pair")
8889

8990
logrus.Infof("Migration Started")

0 commit comments

Comments
 (0)