Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for storkctl clusterpair options #1673

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions test/integration_test/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
snapv1 "github.com/kubernetes-incubator/external-storage/snapshot/pkg/apis/crd/v1"
oputils "github.com/libopenstorage/operator/drivers/storage/portworx/util"
opcorev1 "github.com/libopenstorage/operator/pkg/apis/core/v1"
"github.com/libopenstorage/stork/pkg/aetosutils"
aetosLogger "github.com/libopenstorage/stork/pkg/log"
"github.com/portworx/sched-ops/k8s/apps"
"github.com/portworx/sched-ops/k8s/batch"
"github.com/portworx/sched-ops/k8s/core"
Expand Down Expand Up @@ -68,7 +66,9 @@ import (
_ "github.com/libopenstorage/stork/drivers/volume/gcp"
_ "github.com/libopenstorage/stork/drivers/volume/linstor"
_ "github.com/libopenstorage/stork/drivers/volume/portworx"
"github.com/libopenstorage/stork/pkg/aetosutils"
storkv1 "github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1"
aetosLogger "github.com/libopenstorage/stork/pkg/log"
"github.com/libopenstorage/stork/pkg/schedule"
"github.com/libopenstorage/stork/pkg/storkctl"
"github.com/libopenstorage/stork/pkg/version"
Expand Down Expand Up @@ -834,7 +834,7 @@ func scheduleClusterPair(ctx *scheduler.Context, skipStorage, resetConfig bool,
}

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

// Get external object store details and append to the command accordingily
objectStoreArgs, err := getObjectStoreArgs(objectStoreType, secretName)
if err != nil {
return fmt.Errorf("failed to get %s secret in configmap secret-config in default namespace", objectStoreType)
if objectStoreType != "" {
// Get external object store details and append to the command accordingily
objectStoreArgs, err := getObjectStoreArgs(objectStoreType, secretName)
if err != nil {
return fmt.Errorf("failed to get %s secret in configmap secret-config in default namespace", objectStoreType)
}
cmdArgs = append(cmdArgs, objectStoreArgs...)
}

if args != nil {
// Get external object store details and append to the command accordingily
for k, v := range args {
cmdArgs = append(cmdArgs, fmt.Sprintf("--%v", k))
cmdArgs = append(cmdArgs, fmt.Sprintf("%v", v))
}
}

cmdArgs = append(cmdArgs, objectStoreArgs...)
cmd.SetArgs(cmdArgs)
logrus.Infof("Following is the bidirectional command: %v", cmdArgs)
if err := cmd.Execute(); err != nil {
Expand Down
13 changes: 7 additions & 6 deletions test/integration_test/migration_features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import (
"testing"
"time"

storkapi "github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1"
"github.com/libopenstorage/stork/pkg/resourcecollector"
"github.com/portworx/sched-ops/k8s/core"
storkops "github.com/portworx/sched-ops/k8s/stork"
"github.com/portworx/torpedo/pkg/asyncdr"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/clientcmd"

storkapi "github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1"
"github.com/libopenstorage/stork/pkg/resourcecollector"
)

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

err = scheduleBidirectionalClusterPair(clusterPairName, appData.Ns, "", storkapi.BackupLocationType(backupLocation), backupSecret)
err = scheduleBidirectionalClusterPair(clusterPairName, appData.Ns, "", storkapi.BackupLocationType(backupLocation), backupSecret, nil)
require.NoError(t, err, "Error creating cluster pair")

err = setSourceKubeConfig()
Expand Down Expand Up @@ -294,7 +295,7 @@ func testMigrationStashStrategyWithStartApplication(t *testing.T) {
err = setSourceKubeConfig()
require.NoError(t, err, "Error setting source kubeconfig")

err = scheduleBidirectionalClusterPair(clusterPairName, appData.Ns, "", storkapi.BackupLocationType(backupLocation), backupSecret)
err = scheduleBidirectionalClusterPair(clusterPairName, appData.Ns, "", storkapi.BackupLocationType(backupLocation), backupSecret, nil)
require.NoError(t, err, "Error creating cluster pair")

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

err = scheduleBidirectionalClusterPair(clusterPairName, appData.Ns, "", storkapi.BackupLocationType(backupLocation), backupSecret)
err = scheduleBidirectionalClusterPair(clusterPairName, appData.Ns, "", storkapi.BackupLocationType(backupLocation), backupSecret, nil)
require.NoError(t, err, "Error creating cluster pair")

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

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

// set stashstrategy
Expand Down
4 changes: 2 additions & 2 deletions test/integration_test/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ func bidirectionalClusterPairTest(t *testing.T) {
// Scheduler cluster pairs: source cluster --> destination cluster and destination cluster --> source cluster
for location, secret := range cmData {
logrus.Infof("Creating a bidirectional-pair using %s as objectstore.", location)
err := scheduleBidirectionalClusterPair(clusterPairName, clusterPairNamespace, "", storkv1.BackupLocationType(location), secret)
err := scheduleBidirectionalClusterPair(clusterPairName, clusterPairNamespace, "", storkv1.BackupLocationType(location), secret, nil)
require.NoError(t, err, "failed to set bidirectional cluster pair: %v", err)

err = setSourceKubeConfig()
Expand Down Expand Up @@ -2692,7 +2692,7 @@ func scheduleClusterPairGeneric(t *testing.T, ctxs []*scheduler.Context,
logrus.Infof("Namespace: %s", clusterPairNamespace)
logrus.Infof("Backuplocation: %s", defaultBackupLocation)
logrus.Infof("Secret name: %s", defaultSecretName)
err = scheduleBidirectionalClusterPair(remotePairName, clusterPairNamespace, projectIDMappings, defaultBackupLocation, defaultSecretName)
err = scheduleBidirectionalClusterPair(remotePairName, clusterPairNamespace, projectIDMappings, defaultBackupLocation, defaultSecretName, nil)
require.NoError(t, err, "failed to set bidirectional cluster pair: %v", err)
err = setSourceKubeConfig()
require.NoError(t, err, "failed to set kubeconfig to source cluster: %v", err)
Expand Down
5 changes: 3 additions & 2 deletions test/integration_test/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
"testing"
"time"

storkv1 "github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1"
"github.com/portworx/sched-ops/k8s/core"
"github.com/portworx/torpedo/pkg/asyncdr"
"github.com/portworx/torpedo/pkg/log"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"

storkv1 "github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1"
)

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

err = scheduleBidirectionalClusterPair(clusterPairName, appData.Ns, "", storkv1.BackupLocationType(backupLocation), backupSecret)
err = scheduleBidirectionalClusterPair(clusterPairName, appData.Ns, "", storkv1.BackupLocationType(backupLocation), backupSecret, nil)
require.NoError(t, err, "Error creating cluster pair")

logrus.Infof("Migration Started")
Expand Down
Loading