Skip to content

Commit b0e78b9

Browse files
committed
feat: add tests to validate DualReplica topology effects
added test to check platform type is set to baremetal or none added test to check etcd operator is set to external added test to check baremetal hosts are set to detached Signed-off-by: ehila <[email protected]>
1 parent 9810f24 commit b0e78b9

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

test/extended/two_node/common.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
package two_node
22

33
import (
4+
"bytes"
5+
"encoding/json"
46
"fmt"
7+
"strconv"
58

69
v1 "github.com/openshift/api/config/v1"
10+
operatorv1 "github.com/openshift/api/operator/v1"
711
exutil "github.com/openshift/origin/test/extended/util"
12+
13+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
814
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
15+
"sigs.k8s.io/yaml"
916
)
1017

1118
const (
@@ -42,3 +49,38 @@ func isClusterOperatorDegraded(operator *v1.ClusterOperator) bool {
4249
}
4350
return false
4451
}
52+
53+
// getUseExternalEtcdSupport checks if useExternalEtcdSupport is set to true in the etcd operator's unsupported config overrides
54+
// Borrowed from dr/common.go with modifications to use useExternalEtcdSupport. A little duplication to avoid test code dependence.
55+
func getUseExternalEtcdSupport(spec *operatorv1.StaticPodOperatorSpec) (bool, error) {
56+
unsupportedConfig := map[string]interface{}{}
57+
if spec.UnsupportedConfigOverrides.Raw == nil {
58+
return false, nil
59+
}
60+
61+
configJson, err := yaml.YAMLToJSON(spec.UnsupportedConfigOverrides.Raw)
62+
if err != nil {
63+
// maybe it's already json
64+
configJson = spec.UnsupportedConfigOverrides.Raw
65+
}
66+
67+
if err := json.NewDecoder(bytes.NewBuffer(configJson)).Decode(&unsupportedConfig); err != nil {
68+
return false, err
69+
}
70+
71+
value, found, err := unstructured.NestedFieldNoCopy(unsupportedConfig, "useExternalEtcdSupport")
72+
if err != nil {
73+
return false, err
74+
}
75+
if !found {
76+
return false, nil
77+
}
78+
switch val := value.(type) {
79+
case bool:
80+
return val, nil
81+
case string:
82+
return strconv.ParseBool(val)
83+
default:
84+
return false, nil
85+
}
86+
}

test/extended/two_node/tnf_topology.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
v1 "github.com/openshift/api/config/v1"
1111
exutil "github.com/openshift/origin/test/extended/util"
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
14+
"k8s.io/apimachinery/pkg/runtime/schema"
1315
)
1416

1517
const ensurePodmanEtcdContainerIsRunning = "podman inspect --format '{{.State.Running}}' etcd"
@@ -43,6 +45,55 @@ var _ = g.Describe("[sig-node][apigroup:config.openshift.io][OCPFeatureGate:Dual
4345
o.Expect(err).ShouldNot(o.HaveOccurred(), "Expected to retrieve arbiter nodes without error")
4446
o.Expect(len(arbiterNodes.Items)).To(o.Equal(expectedArbiters), fmt.Sprintf("Expected %d Arbiter Nodes, found %d", expectedArbiters, len(arbiterNodes.Items)))
4547
})
48+
49+
g.It("should have infrastructure set to baremetal or none", func() {
50+
g.By("Checking that the infrastructure platform is set to baremetal or none")
51+
infrastructure, err := oc.AdminConfigClient().ConfigV1().Infrastructures().Get(context.Background(), "cluster", metav1.GetOptions{})
52+
o.Expect(err).ShouldNot(o.HaveOccurred(), "Expected to retrieve infrastructure configuration without error")
53+
54+
platformType := infrastructure.Status.PlatformStatus.Type
55+
o.Expect(platformType).To(o.Or(o.Equal(v1.BareMetalPlatformType), o.Equal(v1.NonePlatformType)),
56+
fmt.Sprintf("Expected infrastructure platform to be baremetal or none, but found %s", platformType))
57+
})
58+
59+
g.It("should have etcd operator configured for external etcd support", func() {
60+
g.By("Checking that the etcd operator has useExternalEtcdSupport set to true")
61+
etcdOperator, err := oc.AdminOperatorClient().OperatorV1().Etcds().Get(context.Background(), "cluster", metav1.GetOptions{})
62+
o.Expect(err).ShouldNot(o.HaveOccurred(), "Expected to retrieve etcd operator configuration without error")
63+
64+
// Check if useExternalEtcdSupport is set to true in unsupported config overrides
65+
useExternalEtcdSupport, err := getUseExternalEtcdSupport(&etcdOperator.Spec.StaticPodOperatorSpec)
66+
o.Expect(err).ShouldNot(o.HaveOccurred(), "Expected to parse etcd operator unsupported config overrides without error")
67+
o.Expect(useExternalEtcdSupport).To(o.BeTrue(), "Expected useExternalEtcdSupport to be set to true in etcd operator configuration")
68+
})
69+
70+
g.It("should have BareMetalHost operational status set to detached if they exist", func() {
71+
g.By("Checking that BareMetalHost objects have operational status set to detached")
72+
dc := oc.AdminDynamicClient()
73+
74+
// Use Dynamic Client to get BareMetalHost objects
75+
// Note: move this to common.go if this is used in other tests
76+
baremetalGVR := schema.GroupVersionResource{Group: "metal3.io", Resource: "baremetalhosts", Version: "v1alpha1"}
77+
baremetalClient := dc.Resource(baremetalGVR).Namespace("openshift-machine-api")
78+
79+
hosts, err := baremetalClient.List(context.Background(), metav1.ListOptions{})
80+
o.Expect(err).ShouldNot(o.HaveOccurred(), "Expected to retrieve BareMetalHost objects without error")
81+
82+
// If no BareMetalHost objects exist, skip the test, this is valid for TNF deployments
83+
if len(hosts.Items) == 0 {
84+
g.Skip("No BareMetalHost objects found in openshift-machine-api namespace")
85+
}
86+
87+
// Check each BareMetalHost has operational status set to detached
88+
for _, host := range hosts.Items {
89+
operationalStatus, found, err := unstructured.NestedString(host.Object, "status", "operationalStatus")
90+
o.Expect(err).ShouldNot(o.HaveOccurred(), fmt.Sprintf("Expected to parse operational status for BareMetalHost %s without error", host.GetName()))
91+
o.Expect(found).To(o.BeTrue(), fmt.Sprintf("Expected operational status field to exist for BareMetalHost %s", host.GetName()))
92+
o.Expect(operationalStatus).To(o.Equal("detached"),
93+
fmt.Sprintf("Expected BareMetalHost %s operational status to be 'detached', but found '%s'", host.GetName(), operationalStatus))
94+
}
95+
})
96+
4697
})
4798

4899
var _ = g.Describe("[sig-etcd][apigroup:config.openshift.io][OCPFeatureGate:DualReplica] Two Node with Fencing", func() {

test/extended/util/annotate/generated/zz_generated.annotations.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zz_generated.manifests/test-reporting.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ spec:
194194
- testName: '[sig-etcd][apigroup:config.openshift.io][OCPFeatureGate:DualReplica][Suite:openshift/two-node][Disruptive]
195195
Two Node with Fencing etcd recovery Should recover from ungraceful node shutdown
196196
with etcd member re-addition'
197+
- testName: '[sig-node][apigroup:config.openshift.io][OCPFeatureGate:DualReplica]
198+
Two Node with Fencing topology should have BareMetalHost operational status
199+
set to detached if they exist'
200+
- testName: '[sig-node][apigroup:config.openshift.io][OCPFeatureGate:DualReplica]
201+
Two Node with Fencing topology should have etcd operator configured for external
202+
etcd support'
203+
- testName: '[sig-node][apigroup:config.openshift.io][OCPFeatureGate:DualReplica]
204+
Two Node with Fencing topology should have infrastructure set to baremetal
205+
or none'
197206
- testName: '[sig-node][apigroup:config.openshift.io][OCPFeatureGate:DualReplica]
198207
Two Node with Fencing topology should only have two control plane nodes and
199208
no arbiter nodes'

0 commit comments

Comments
 (0)