Skip to content

Commit 187efd4

Browse files
Merge pull request #30252 from eggfoobar/add-tnf-check-tests
OCPEDGE-2090: Add validation tests for tnf topology effects
2 parents 79c3be0 + f31169c commit 187efd4

File tree

4 files changed

+87
-42
lines changed

4 files changed

+87
-42
lines changed

pkg/testsuites/standard_suites.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ var staticSuites = []ginkgo.TestSuite{
426426
This test suite runs tests to validate two-node.
427427
`),
428428
Qualifiers: []string{
429-
`name.contains("[Suite:openshift/two-node") || name.contains("[FeatureGate:DualReplica]") || name.contains("[FeatureGate:HighlyAvailableArbiter]")`,
429+
`name.contains("[Suite:openshift/two-node") || name.contains("[OCPFeatureGate:DualReplica]") || name.contains("[OCPFeatureGate:HighlyAvailableArbiter]")`,
430430
},
431431
TestTimeout: 60 * time.Minute,
432432
},

test/extended/two_node/tnf_topology.go

Lines changed: 66 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@ package two_node
33
import (
44
"context"
55
"fmt"
6+
"strings"
67

78
g "github.com/onsi/ginkgo/v2"
89
o "github.com/onsi/gomega"
910
v1 "github.com/openshift/api/config/v1"
1011
exutil "github.com/openshift/origin/test/extended/util"
11-
corev1 "k8s.io/api/core/v1"
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"
1618

17-
var _ = g.Describe("[sig-node][apigroup:config.openshift.io][OCPFeatureGate:DualReplica][Suite:openshift/two-node] Two Node with Fencing topology", func() {
19+
var _ = g.Describe("[sig-node][apigroup:config.openshift.io][OCPFeatureGate:DualReplica] Two Node with Fencing topology", func() {
1820
defer g.GinkgoRecover()
1921
var (
2022
oc = exutil.NewCLIWithoutNamespace("")
@@ -24,13 +26,13 @@ var _ = g.Describe("[sig-node][apigroup:config.openshift.io][OCPFeatureGate:Dual
2426
skipIfNotTopology(oc, v1.DualReplicaTopologyMode)
2527
})
2628

27-
g.It("Should validate the number of control-planes, arbiters as configured", func() {
29+
g.It("should only have two control plane nodes and no arbiter nodes", func() {
2830
const (
2931
expectedControlPlanes = 2
3032
expectedArbiters = 0
3133
)
3234

33-
g.By(fmt.Sprintf("Ensuring only %d Control-plane nodes in the cluster, and %d Arbiter nodes", expectedControlPlanes, expectedArbiters))
35+
g.By(fmt.Sprintf("Ensuring only %d control-plane nodes in the cluster and no arbiter nodes", expectedControlPlanes))
3436
controlPlaneNodes, err := oc.AdminKubeClient().CoreV1().Nodes().List(context.Background(), metav1.ListOptions{
3537
LabelSelector: labelNodeRoleControlPlane,
3638
})
@@ -43,61 +45,96 @@ 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 platform type set correctly", func() {
50+
g.By("Checking that the infrastructure platform is set to baremetal or none or external")
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), o.Equal(v1.ExternalPlatformType)),
56+
fmt.Sprintf("Expected infrastructure platform to be baremetal or none or external, but found %s", platformType))
57+
})
58+
59+
g.It("should have BareMetalHost operational status set to detached if they exist", func() {
60+
g.By("Checking that BareMetalHost objects have operational status set to detached")
61+
dc := oc.AdminDynamicClient()
62+
63+
// Use Dynamic Client to get BareMetalHost objects
64+
// Note: move this to common.go if this is used in other tests
65+
baremetalGVR := schema.GroupVersionResource{Group: "metal3.io", Resource: "baremetalhosts", Version: "v1alpha1"}
66+
baremetalClient := dc.Resource(baremetalGVR).Namespace("openshift-machine-api")
67+
68+
hosts, err := baremetalClient.List(context.Background(), metav1.ListOptions{})
69+
o.Expect(err).ShouldNot(o.HaveOccurred(), "Expected to retrieve BareMetalHost objects without error")
70+
71+
// If no BareMetalHost objects exist, skip the test, this is valid for TNF deployments
72+
if len(hosts.Items) == 0 {
73+
g.Skip("No BareMetalHost objects found in openshift-machine-api namespace")
74+
}
75+
76+
// Check each BareMetalHost has operational status set to detached
77+
for _, host := range hosts.Items {
78+
operationalStatus, found, err := unstructured.NestedString(host.Object, "status", "operationalStatus")
79+
o.Expect(err).ShouldNot(o.HaveOccurred(), fmt.Sprintf("Expected to parse operational status for BareMetalHost %s without error", host.GetName()))
80+
o.Expect(found).To(o.BeTrue(), fmt.Sprintf("Expected operational status field to exist for BareMetalHost %s", host.GetName()))
81+
o.Expect(operationalStatus).To(o.Equal("detached"),
82+
fmt.Sprintf("Expected BareMetalHost %s operational status to be 'detached', but found '%s'", host.GetName(), operationalStatus))
83+
}
84+
})
85+
4686
})
4787

48-
var _ = g.Describe("[sig-etcd][apigroup:config.openshift.io][OCPFeatureGate:DualReplica][Suite:openshift/two-node] Two Node with Fencing pods and podman containers", func() {
88+
var _ = g.Describe("[sig-etcd][apigroup:config.openshift.io][OCPFeatureGate:DualReplica] Two Node with Fencing", func() {
4989
defer g.GinkgoRecover()
5090
var (
51-
oc = exutil.NewCLIWithoutNamespace("")
52-
nodes *corev1.NodeList
91+
oc = exutil.NewCLIWithoutNamespace("")
5392
)
5493

5594
g.BeforeEach(func() {
5695
skipIfNotTopology(oc, v1.DualReplicaTopologyMode)
57-
58-
var err error
59-
nodes, err = oc.AdminKubeClient().CoreV1().Nodes().List(context.Background(), metav1.ListOptions{})
60-
o.Expect(err).To(o.BeNil(), "Expected to retrieve all nodes without error")
6196
})
62-
g.It("Should validate the number of etcd pods and containers as configured", func() {
97+
g.It("should have etcd pods and containers configured correctly", func() {
6398
const (
6499
expectedEtcdPod = 2
65100
expectedEtcdCtlContainers = 2
66101
expectedEtcdContainers = 0
67102
)
68103

69-
nodeNameA := nodes.Items[0].Name
70-
nodeNameB := nodes.Items[1].Name
71-
72104
g.By("Ensuring 0 etcd pod containers and 2 etcdctl pod containers are running in the cluster ")
73-
pods, err := oc.AdminKubeClient().CoreV1().Pods("openshift-etcd").List(context.Background(), metav1.ListOptions{})
105+
pods, err := oc.AdminKubeClient().CoreV1().Pods("openshift-etcd").List(context.Background(), metav1.ListOptions{
106+
LabelSelector: "app=etcd",
107+
})
74108
o.Expect(err).To(o.BeNil(), "Expected to retrieve etcd pods in openshift-etcd namespace without error")
109+
o.Expect(pods.Items).To(o.HaveLen(expectedEtcdPod), "Expected to retrieve %d etcd pods in openshift-etcd namespace", expectedEtcdPod)
75110

76-
etcdPodCount := 0
77111
etcdContainerCount := 0
78112
etcdctlContainerCount := 0
113+
79114
for _, pod := range pods.Items {
80-
if pod.Name == "etcd-"+nodeNameA || pod.Name == "etcd-"+nodeNameB {
81-
etcdPodCount += 1
82-
for _, container := range pod.Spec.Containers {
83-
if container.Name == "etcd" {
84-
etcdContainerCount += 1
85-
}
86-
if container.Name == "etcdctl" {
87-
etcdctlContainerCount += 1
88-
}
115+
for _, container := range pod.Spec.Containers {
116+
if container.Name == "etcd" {
117+
etcdContainerCount += 1
118+
}
119+
if container.Name == "etcdctl" {
120+
etcdctlContainerCount += 1
89121
}
90122
}
91123
}
92-
o.Expect(etcdPodCount).To(o.Equal(expectedEtcdPod))
93124
o.Expect(etcdctlContainerCount).To(o.Equal(expectedEtcdCtlContainers))
94125
o.Expect(etcdContainerCount).To(o.Equal(expectedEtcdContainers))
95126
})
96127

97-
g.It("Should verify the number of podman-etcd containers as configured", func() {
128+
g.It("should have podman etcd containers running on each node", func() {
129+
nodes, err := oc.AdminKubeClient().CoreV1().Nodes().List(context.Background(), metav1.ListOptions{
130+
LabelSelector: labelNodeRoleControlPlane,
131+
})
132+
o.Expect(err).To(o.BeNil(), "Expected to retrieve control plane nodes without error")
133+
o.Expect(nodes.Items).To(o.HaveLen(2), "Expected to retrieve two control plane nodes for DualReplica topology")
134+
98135
g.By("Ensuring one podman etcd container is running on each node")
99136
for _, node := range nodes.Items {
100-
got, err := exutil.DebugNodeRetryWithOptionsAndChroot(oc, node.Name, "openshift-etcd", "podman", "inspect", "--format", "'{{.State.Running}}'", "etcd")
137+
got, err := exutil.DebugNodeRetryWithOptionsAndChroot(oc, node.Name, "openshift-etcd", strings.Split(ensurePodmanEtcdContainerIsRunning, " ")...)
101138
o.Expect(err).To(o.BeNil(), fmt.Sprintf("expected to call podman without errors on Node %s: error %v", node.Name, err))
102139
o.Expect(got).To(o.Equal("'true'"), fmt.Sprintf("expected a podman etcd container running on Node %s: got running %s", node.Name, got))
103140
}

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

Lines changed: 7 additions & 3 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: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,25 @@ spec:
184184
[Beta] [Feature:OffByDefault]'
185185
- featureGate: DualReplica
186186
tests:
187-
- testName: '[sig-etcd][apigroup:config.openshift.io][OCPFeatureGate:DualReplica][Suite:openshift/two-node]
188-
Two Node with Fencing pods and podman containers Should validate the number
189-
of etcd pods and containers as configured'
190-
- testName: '[sig-etcd][apigroup:config.openshift.io][OCPFeatureGate:DualReplica][Suite:openshift/two-node]
191-
Two Node with Fencing pods and podman containers Should verify the number
192-
of podman-etcd containers as configured'
187+
- testName: '[sig-etcd][apigroup:config.openshift.io][OCPFeatureGate:DualReplica]
188+
Two Node with Fencing should have etcd pods and containers configured correctly'
189+
- testName: '[sig-etcd][apigroup:config.openshift.io][OCPFeatureGate:DualReplica]
190+
Two Node with Fencing should have podman etcd containers running on each node'
193191
- testName: '[sig-etcd][apigroup:config.openshift.io][OCPFeatureGate:DualReplica][Suite:openshift/two-node][Disruptive]
194192
Two Node with Fencing etcd recovery Should recover from graceful node shutdown
195193
with etcd member re-addition'
196194
- testName: '[sig-etcd][apigroup:config.openshift.io][OCPFeatureGate:DualReplica][Suite:openshift/two-node][Disruptive]
197195
Two Node with Fencing etcd recovery Should recover from ungraceful node shutdown
198196
with etcd member re-addition'
199-
- testName: '[sig-node][apigroup:config.openshift.io][OCPFeatureGate:DualReplica][Suite:openshift/two-node]
200-
Two Node with Fencing topology Should validate the number of control-planes,
201-
arbiters as configured'
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 infrastructure platform type set
202+
correctly'
203+
- testName: '[sig-node][apigroup:config.openshift.io][OCPFeatureGate:DualReplica]
204+
Two Node with Fencing topology should only have two control plane nodes and
205+
no arbiter nodes'
202206
- featureGate: DynamicResourceAllocation
203207
tests:
204208
- testName: '[sig-node] DRA [Feature:DynamicResourceAllocation] [FeatureGate:DynamicResourceAllocation]

0 commit comments

Comments
 (0)