Skip to content

Commit

Permalink
Updates to infra test code.
Browse files Browse the repository at this point in the history
  • Loading branch information
anathoodell committed Dec 19, 2024
1 parent 7a2560e commit cfb6a41
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
34 changes: 32 additions & 2 deletions pkg/drivers/powerflex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,23 @@ func TestExtractZonesFromSecret(t *testing.T) {
zone:
name: "ZONE-2"
labelKey: "zone.csi-vxflexos.dellemc.com"
`
zoneDataWithMultiArraySomeZone := `
- username: "admin"
password: "password"
systemID: "2b11bb111111bb1b"
endpoint: "https://127.0.0.2"
skipCertificateValidation: true
mdm: "10.0.0.3,10.0.0.4"
- username: "admin"
password: "password"
systemID: "1a99aa999999aa9a"
endpoint: "https://127.0.0.1"
skipCertificateValidation: true
mdm: "10.0.0.5,10.0.0.6"
zone:
name: "ZONE-2"
labelKey: "zone.csi-vxflexos.dellemc.com"
`
dataWithoutZone := `
- username: "admin"
Expand Down Expand Up @@ -279,6 +296,19 @@ func TestExtractZonesFromSecret(t *testing.T) {
client := fake.NewClientBuilder().WithObjects(secret).Build()
return client, map[string]string{"2b11bb111111bb1b": "ZONE-1", "1a99aa999999aa9a": "ZONE-2"}, "vxflexos-config", false
},
"fail multi array but only some zone": func() (client.WithWatch, map[string]string, string, bool) {
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "vxflexos-config",
Namespace: "vxflexos",
},
Data: map[string][]byte{
"config": []byte(zoneDataWithMultiArraySomeZone),
},
}
client := fake.NewClientBuilder().WithObjects(secret).Build()
return client, map[string]string{"2b11bb111111bb1b": "ZONE-1", "1a99aa999999aa9a": "ZONE-2"}, "vxflexos-config", true
},
"success no zone": func() (client.WithWatch, map[string]string, string, bool) {
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -344,12 +374,12 @@ func TestExtractZonesFromSecret(t *testing.T) {
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
client, wantZones, secret, wantErr := tc()
zones, err := ExtractZonesFromSecret(ctx, client, "vxflexos", secret)
err := ValidateZonesInSecret(ctx, client, "vxflexos", secret)
if wantErr {
assert.NotNil(t, err)
} else {
assert.Nil(t, err)
assert.Equal(t, wantZones, zones)
_ = wantZones
}
})
}
Expand Down
5 changes: 1 addition & 4 deletions tests/shared/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,14 @@ func MakeSecretPowerFlex(name, ns, _ string) *corev1.Secret {
return secret
}

func MakeSecretPowerFlexMultiZone(name, ns, _ string) *corev1.Secret {
func MakeSecretPowerFlexMultiZoneInvalid(name, ns, _ string) *corev1.Secret {
dataWithInvalidZone := `
- username: "admin"
password: "password"
systemID: "2b11bb111111bb1b"
endpoint: "https://127.0.0.2"
skipCertificateValidation: true
mdm: "10.0.0.3,10.0.0.4"
zone:
name: "US-EAST"
labelKey: "zone.csi-vxflexos.dellemc.com"
- username: "admin"
password: "password"
systemID: "2b11bb111111bb1b"
Expand Down
29 changes: 12 additions & 17 deletions tests/shared/crclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"reflect"
"time"

"github.com/dell/csm-operator/pkg/logger"
"github.com/dell/csm-operator/tests/shared"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -113,11 +112,9 @@ func (f Client) List(ctx context.Context, list client.ObjectList, opts ...client
// Initialize ListOptions
listOpts := &client.ListOptions{}
// Apply each ListOption to listOpts
if opts != nil {
for _, opt := range opts {
if opt != nil {
opt.ApplyToList(listOpts)
}
for _, opt := range opts {
if opt != nil {
opt.ApplyToList(listOpts)
}
}
s := listOpts.LabelSelector
Expand All @@ -143,21 +140,19 @@ func (f Client) listPodList(list *corev1.PodList) error {
}

func (f Client) listNodeList(list *corev1.NodeList, label string) error {
_, log := logger.GetNewContextWithLogger("0")
for k, v := range f.Objects {
if k.Kind == "Node" {
node := *v.(*corev1.Node)
if label != "" {
for key := range node.ObjectMeta.Labels {
if label == key {
log.Infof("\tadding node name:%v to list matching label key \n", node.Name)
list.Items = append(list.Items, *v.(*corev1.Node))
} else {
log.Infof("\tnon-matching node found. node key:%v incoming label:%v\n", key, label)
node, ok := v.(*corev1.Node)
if ok {
if label != "" {
for key := range (*node).ObjectMeta.Labels {
if label == key {
list.Items = append(list.Items, *node)
}
}
} else {
list.Items = append(list.Items, *node)
}
} else {
list.Items = append(list.Items, *v.(*corev1.Node))
}
}
}
Expand Down

0 comments on commit cfb6a41

Please sign in to comment.