@@ -3,18 +3,20 @@ package two_node
33import (
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
1517const 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 }
0 commit comments