Skip to content

Commit

Permalink
Fix test-cases
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekdwivedi3060 committed Nov 24, 2023
1 parent 745ecdd commit 7f21e86
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 34 deletions.
17 changes: 9 additions & 8 deletions test/batch_restart_pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
const batchClusterName = "batch-restart"

var (
unavailableImage = fmt.Sprintf("%s:%s", baseImage, "6.0.0.99")
availableImage1 = fmt.Sprintf("%s:%s", baseImage, "6.0.0.1")
availableImage2 = fmt.Sprintf("%s:%s", baseImage, "6.0.0.2")
unavailableImage = fmt.Sprintf("%s:%s", baseImage, "7.0.0.99")
availableImage1 = fmt.Sprintf("%s:%s", baseImage, "7.0.0.0_1")
availableImage2 = fmt.Sprintf("%s:%s", baseImage, "7.0.0.0_2")
)

func percent(val string) *intstr.IntOrString {
Expand Down Expand Up @@ -244,8 +244,8 @@ func BatchRollingRestart(ctx goctx.Context, clusterNamespacedName types.Namespac

// Test steps
// 1: update cluster to demand huge resources. It will unschedule batch of pods
// 2: verify if more than 1 pods are in unscheduled state.
// In default mode, there can not be more than 1 unscheduled pods
// 2: verify if more than 1 pod are in unscheduled state.
// In default mode, there cannot be more than 1 unscheduled pods
// 3: update cluster to demand limited resources. It will schedule old unscheduled pods

// Restart full rack at a time
Expand Down Expand Up @@ -331,7 +331,8 @@ func BatchUpgrade(ctx goctx.Context, clusterNamespacedName types.NamespacedName)
aeroCluster, err := getCluster(k8sClient, ctx, clusterNamespacedName)
Expect(err).ToNot(HaveOccurred())

_ = deleteCluster(k8sClient, ctx, aeroCluster)
err = deleteCluster(k8sClient, ctx, aeroCluster)
Expect(err).ToNot(HaveOccurred())
},
)
// Restart 1 node at a time
Expand All @@ -350,8 +351,8 @@ func BatchUpgrade(ctx goctx.Context, clusterNamespacedName types.NamespacedName)

// Test steps
// 1: update cluster with unavailable image. It will unschedule batch of pods
// 2: verify if more than 1 pods are in unscheduled state.
// In default mode, there can not be more than 1 unscheduled pods
// 2: verify if more than 1 pod are in unscheduled state.
// In default mode, there cannot be more than 1 unscheduled pods
// 3: update cluster to demand limited resources. It will schedule old unscheduled pods

// Restart full rack at a time
Expand Down
78 changes: 73 additions & 5 deletions test/cluster_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

const (
baseImage = "aerospike/aerospike-server-enterprise"
prevServerVersion = "6.3.0.0"
prevServerVersion = "6.4.0.0"
pre6Version = "5.7.0.17"
version6 = "6.0.0.5"
latestServerVersion = "7.0.0.0"
Expand Down Expand Up @@ -781,7 +781,7 @@ func createAerospikeClusterPost460(
},
"network": getNetworkTLSConfig(),
"namespaces": []interface{}{
getNonSCNamespaceConfig("test", "/test/dev/xvdf"),
getNonSCNamespaceConfigPre700("test", "/test/dev/xvdf"),
},
},
},
Expand Down Expand Up @@ -842,7 +842,7 @@ func createAerospikeClusterPost560(
"security": map[string]interface{}{},
"network": getNetworkTLSConfig(),
"namespaces": []interface{}{
getNonSCNamespaceConfig("test", "/test/dev/xvdf"),
getNonSCNamespaceConfigPre700("test", "/test/dev/xvdf"),
},
},
},
Expand All @@ -855,6 +855,17 @@ func createAerospikeClusterPost560(
return aeroCluster
}

func createAerospikeClusterPost640(
clusterNamespacedName types.NamespacedName, size int32, image string,
) *asdbv1.AerospikeCluster {
// create Aerospike custom resource
aeroCluster := createAerospikeClusterPost560(clusterNamespacedName, size, image)
aeroCluster.Spec.AerospikeConfig.Value["namespaces"] = []interface{}{
getNonSCNamespaceConfig("test", "/test/dev/xvdf"),
}

return aeroCluster
}
func createDummyRackAwareWithStorageAerospikeCluster(
clusterNamespacedName types.NamespacedName, size int32,
) *asdbv1.AerospikeCluster {
Expand Down Expand Up @@ -1039,12 +1050,61 @@ func UpdateClusterImage(
return err
}

ov, err := asconfig.CompareVersions(outgoingVersion, "5.7.0")
ov, err := asconfig.CompareVersions(outgoingVersion, "7.0.0")
if err != nil {
return err
}

nv, err := asconfig.CompareVersions(incomingVersion, "5.7.0")
nv, err := asconfig.CompareVersions(incomingVersion, "7.0.0")
if err != nil {
return err
}

switch {
case nv >= 0 && ov >= 0, nv < 0 && ov < 0:
aerocluster.Spec.Image = image

case nv >= 0 && ov < 0:
aerocluster.Spec.Image = image

namespaces := aerocluster.Spec.AerospikeConfig.Value["namespaces"].([]interface{})
for idx := range namespaces {
ns := namespaces[idx].(map[string]interface{})
delete(ns, "memory-size")

storageEngine := ns["storage-engine"].(map[string]interface{})
if storageEngine["type"] == "memory" {
storageEngine["data-size"] = 1073741824
ns["storage-engine"] = storageEngine
}

namespaces[idx] = ns
}

default:
aerocluster.Spec.Image = image

namespaces := aerocluster.Spec.AerospikeConfig.Value["namespaces"].([]interface{})
for idx := range namespaces {
ns := namespaces[idx].(map[string]interface{})
ns["memory-size"] = 1073741824

storageEngine := ns["storage-engine"].(map[string]interface{})
if storageEngine["type"] == "memory" {
delete(storageEngine, "data-size")
ns["storage-engine"] = storageEngine
}

namespaces[idx] = ns
}
}

ov, err = asconfig.CompareVersions(outgoingVersion, "5.7.0")
if err != nil {
return err
}

nv, err = asconfig.CompareVersions(incomingVersion, "5.7.0")
if err != nil {
return err
}
Expand Down Expand Up @@ -1411,6 +1471,14 @@ func getNonSCNamespaceConfig(name, path string) map[string]interface{} {
return getNonSCNamespaceConfigWithRF(name, path, 2)
}

// getNonSCNamespaceConfigPre700 returns a namespace config for Aerospike version < 7.0.0
func getNonSCNamespaceConfigPre700(name, path string) map[string]interface{} {
config := getNonSCNamespaceConfigWithRF(name, path, 2)
config["memory-size"] = 2000955200

return config
}

func getNonSCNamespaceConfigWithRF(name, path string, rf int) map[string]interface{} {
return map[string]interface{}{
"name": name,
Expand Down
20 changes: 10 additions & 10 deletions test/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ func negativeDeployClusterValidationTest(
It(
"MultipleCertSource: should fail if both SecretCertSource and CertPathInOperator is set",
func() {
aeroCluster := createAerospikeClusterPost560(
aeroCluster := createAerospikeClusterPost640(
clusterNamespacedName, 1, latestImage,
)
aeroCluster.Spec.OperatorClientCertSpec.CertPathInOperator = &asdbv1.AerospikeCertPathInOperatorSource{}
Expand All @@ -972,7 +972,7 @@ func negativeDeployClusterValidationTest(
It(
"MissingClientKeyFilename: should fail if ClientKeyFilename is missing",
func() {
aeroCluster := createAerospikeClusterPost560(
aeroCluster := createAerospikeClusterPost640(
clusterNamespacedName, 1, latestImage,
)
aeroCluster.Spec.OperatorClientCertSpec.SecretCertSource.ClientKeyFilename = ""
Expand All @@ -987,7 +987,7 @@ func negativeDeployClusterValidationTest(
It(
"Should fail if both CaCertsFilename and CaCertsSource is set",
func() {
aeroCluster := createAerospikeClusterPost560(
aeroCluster := createAerospikeClusterPost640(
clusterNamespacedName, 1, latestImage,
)
aeroCluster.Spec.OperatorClientCertSpec.SecretCertSource.CaCertsSource = &asdbv1.CaCertsSource{}
Expand All @@ -1002,7 +1002,7 @@ func negativeDeployClusterValidationTest(
It(
"MissingClientCertPath: should fail if clientCertPath is missing",
func() {
aeroCluster := createAerospikeClusterPost560(
aeroCluster := createAerospikeClusterPost640(
clusterNamespacedName, 1, latestImage,
)
aeroCluster.Spec.OperatorClientCertSpec.SecretCertSource = nil
Expand Down Expand Up @@ -1366,7 +1366,7 @@ func negativeDeployClusterValidationTest(
It(
"WhenFeatureKeyExist: should fail for no feature-key-file path in storage volume",
func() {
aeroCluster := createAerospikeClusterPost560(
aeroCluster := createAerospikeClusterPost640(
clusterNamespacedName, 1, latestImage,
)
aeroCluster.Spec.AerospikeConfig.Value["service"] = map[string]interface{}{
Expand All @@ -1380,7 +1380,7 @@ func negativeDeployClusterValidationTest(
It(
"WhenTLSExist: should fail for no tls path in storage volume",
func() {
aeroCluster := createAerospikeClusterPost560(
aeroCluster := createAerospikeClusterPost640(
clusterNamespacedName, 1, latestImage,
)
aeroCluster.Spec.AerospikeConfig.Value["network"] = map[string]interface{}{
Expand All @@ -1399,7 +1399,7 @@ func negativeDeployClusterValidationTest(
It(
"WhenTLSExist: should fail for both ca-file and ca-path in tls",
func() {
aeroCluster := createAerospikeClusterPost560(
aeroCluster := createAerospikeClusterPost640(
clusterNamespacedName, 1, latestImage,
)
aeroCluster.Spec.AerospikeConfig.Value["network"] = map[string]interface{}{
Expand All @@ -1421,7 +1421,7 @@ func negativeDeployClusterValidationTest(
It(
"WhenTLSExist: should fail for ca-file path pointing to Secret Manager",
func() {
aeroCluster := createAerospikeClusterPost560(
aeroCluster := createAerospikeClusterPost640(
clusterNamespacedName, 1, latestImage,
)
aeroCluster.Spec.AerospikeConfig.Value["network"] = map[string]interface{}{
Expand All @@ -1442,7 +1442,7 @@ func negativeDeployClusterValidationTest(
It(
"WhenTLSExist: should fail for ca-path pointing to Secret Manager",
func() {
aeroCluster := createAerospikeClusterPost560(
aeroCluster := createAerospikeClusterPost640(
clusterNamespacedName, 1, latestImage,
)
aeroCluster.Spec.AerospikeConfig.Value["network"] = map[string]interface{}{
Expand Down Expand Up @@ -1917,7 +1917,7 @@ func negativeUpdateClusterValidationTest(
"InvalidAerospikeConfigSecret", func() {
BeforeEach(
func() {
aeroCluster := createAerospikeClusterPost560(
aeroCluster := createAerospikeClusterPost640(
clusterNamespacedName, 2, latestImage,
)

Expand Down
2 changes: 1 addition & 1 deletion test/host_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var _ = Describe(
clusterNamespacedName := getNamespacedName(
clusterName, namespace,
)
aeroCluster := createAerospikeClusterPost560(
aeroCluster := createAerospikeClusterPost640(
clusterNamespacedName, 2, latestImage,
)
aeroCluster.Spec.PodSpec.HostNetwork = true
Expand Down
30 changes: 23 additions & 7 deletions test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ func NewAerospikeConfSpec(image string) (*AerospikeConfSpec, error) {
"name": "test",
"replication-factor": 1,
"storage-engine": map[string]interface{}{
"type": "memory",
"type": "memory",
"data-size": 1073741824,
},
},
}
Expand Down Expand Up @@ -563,20 +564,35 @@ func getAeroClusterConfig(
return nil, err
}

cmpVal, err := asconfig.CompareVersions(version, "5.7.0")
cmpVal1, err := asconfig.CompareVersions(version, "5.7.0")
if err != nil {
return nil, err
}

if cmpVal >= 0 {
cmpVal2, err := asconfig.CompareVersions(version, "7.0.0")
if err != nil {
return nil, err
}

switch {
case cmpVal2 >= 0:
return createAerospikeClusterPost640(
namespace, 2, image,
), nil

case cmpVal1 >= 0:
return createAerospikeClusterPost560(
namespace, 2, image,
), nil
}

return createAerospikeClusterPost460(
namespace, 2, image,
), nil
case cmpVal1 < 0:
return createAerospikeClusterPost460(
namespace, 2, image,
), nil

default:
return nil, fmt.Errorf("invalid image version %s", version)
}
}

func getAerospikeStorageConfig(
Expand Down
8 changes: 5 additions & 3 deletions test/warm_restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ func rollCluster(ctx goCtx.Context, image string, expectWarmStart bool) {
clusterName := "warm-restart-cluster"
clusterNamespacedName := getNamespacedName(clusterName, namespace)

aeroCluster := createAerospikeClusterPost560(
clusterNamespacedName, 2, image,
aeroCluster, err := getAeroClusterConfig(
clusterNamespacedName, image,
)
Expect(err).ToNot(HaveOccurred())

// Add a volume of type empty dir to figure if pod restarted.
aeroCluster.Spec.Storage.Volumes = append(
aeroCluster.Spec.Storage.Volumes, asdbv1.VolumeSpec{
Expand All @@ -67,7 +69,7 @@ func rollCluster(ctx goCtx.Context, image string, expectWarmStart bool) {
Aerospike: &asdbv1.AerospikeServerVolumeAttachment{Path: tempTestDir},
},
)
err := deployCluster(k8sClient, ctx, aeroCluster)
err = deployCluster(k8sClient, ctx, aeroCluster)
Expect(err).ToNot(HaveOccurred())

defer func(
Expand Down

0 comments on commit 7f21e86

Please sign in to comment.