Skip to content

Commit 7b4ff51

Browse files
authored
Add assertion for lifecycle test (#1234)
* Add assertion for lifecycle test * Remove 'wait for pods' loop
1 parent f0d14d3 commit 7b4ff51

File tree

4 files changed

+334
-13
lines changed

4 files changed

+334
-13
lines changed

.github/workflows/qe-ocp.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ concurrency:
2121

2222
env:
2323
TEST_REPO: redhat-best-practices-for-k8s/certsuite
24+
CERTSUITE_REF: main
2425
ENABLE_CERTSUITE_MEMORY_LIMIT: true
2526

2627
jobs:
@@ -42,7 +43,7 @@ jobs:
4243
with:
4344
repository: ${{ env.TEST_REPO }}
4445
path: certsuite
45-
ref: main
46+
ref: ${{ env.CERTSUITE_REF }}
4647

4748
- name: Extract dependent Pull Requests
4849
uses: depends-on/depends-on-action@61cb3f4a0e2c8ae4b90c9448dc57c7ba9ca24c35 # main
@@ -129,18 +130,12 @@ jobs:
129130
env:
130131
OCP_PULL_SECRET: ${{ secrets.CRC_PULL_SECRET }}
131132

132-
- name: Wait for all pods to be ready and show them
133-
if: steps.check-secret.outputs.has-secret == 'true'
134-
run: |
135-
while oc get pods --all-namespaces --no-headers | grep -vE 'Running|Completed'; do echo "⏳ Waiting for pods..."; sleep 5; done; echo "✅ All pods are Running or Completed."
136-
oc get pods -A
137-
138133
- name: Clone the certsuite repository
139134
uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493 # v5.0.0
140135
with:
141136
repository: ${{ env.TEST_REPO }}
142137
path: certsuite
143-
ref: main
138+
ref: ${{ env.CERTSUITE_REF }}
144139

145140
- name: Download pre-built certsuite binary
146141
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0

.github/workflows/qe.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ concurrency:
2121

2222
env:
2323
TEST_REPO: redhat-best-practices-for-k8s/certsuite
24+
CERTSUITE_REF: main
2425

2526
jobs:
2627
build-and-store-image:
@@ -36,7 +37,7 @@ jobs:
3637
with:
3738
repository: ${{ env.TEST_REPO }}
3839
path: certsuite
39-
ref: main
40+
ref: ${{ env.CERTSUITE_REF }}
4041

4142
- name: Setup docker buildx
4243
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
@@ -74,7 +75,7 @@ jobs:
7475
with:
7576
repository: ${{ env.TEST_REPO }}
7677
path: certsuite
77-
ref: main
78+
ref: ${{ env.CERTSUITE_REF }}
7879

7980
- name: Extract dependent Pull Requests
8081
uses: depends-on/depends-on-action@61cb3f4a0e2c8ae4b90c9448dc57c7ba9ca24c35 # main
@@ -168,7 +169,7 @@ jobs:
168169
with:
169170
repository: ${{ env.TEST_REPO }}
170171
path: certsuite
171-
ref: main
172+
ref: ${{ env.CERTSUITE_REF }}
172173

173174
- name: Extract dependent Pull Requests
174175
uses: depends-on/depends-on-action@61cb3f4a0e2c8ae4b90c9448dc57c7ba9ca24c35 # main

tests/platformalteration/tests/platform_alteration_ocp_lifecycle.go

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
package tests
22

33
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
"path/filepath"
8+
"strings"
9+
410
. "github.com/onsi/ginkgo/v2"
511
. "github.com/onsi/gomega"
6-
tsparams "github.com/redhat-best-practices-for-k8s/certsuite-qe/tests/platformalteration/parameters"
12+
corev1 "k8s.io/api/core/v1"
13+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
714

815
"github.com/redhat-best-practices-for-k8s/certsuite-qe/tests/globalhelper"
916
"github.com/redhat-best-practices-for-k8s/certsuite-qe/tests/globalparameters"
17+
tsparams "github.com/redhat-best-practices-for-k8s/certsuite-qe/tests/platformalteration/parameters"
18+
)
19+
20+
const (
21+
// rhcosVersionMapRelativePath is the path to the rhcos_version_map file relative to the certsuite repo root.
22+
rhcosVersionMapRelativePath = "tests/platform/operatingsystem/files/rhcos_version_map"
1023
)
1124

1225
var _ = Describe("platform-alteration-ocp-lifecycle", func() {
@@ -40,12 +53,95 @@ var _ = Describe("platform-alteration-ocp-lifecycle", func() {
4053
Skip("OCP version is not applicable for Kind cluster")
4154
}
4255

56+
By("Verify RHCOS versions exist in certsuite rhcos_version_map")
57+
err := verifyRHCOSVersionsInCertsuite()
58+
Expect(err).ToNot(HaveOccurred(), "RHCOS version validation failed")
59+
4360
By("Start platform-alteration-ocp-lifecycle test")
44-
err := globalhelper.LaunchTests(tsparams.CertsuiteOCPLifecycleName,
61+
err = globalhelper.LaunchTests(tsparams.CertsuiteOCPLifecycleName,
4562
globalhelper.ConvertSpecNameToFileName(CurrentSpecReport().FullText()), randomReportDir, randomCertsuiteConfigDir)
4663
Expect(err).ToNot(HaveOccurred())
4764

4865
err = globalhelper.ValidateIfReportsAreValid(tsparams.CertsuiteOCPLifecycleName, globalparameters.TestCasePassed, randomReportDir)
4966
Expect(err).ToNot(HaveOccurred())
5067
})
5168
})
69+
70+
// verifyRHCOSVersionsInCertsuite verifies that the RHCOS version from each node's OSImage
71+
// exists in the certsuite rhcos_version_map file.
72+
func verifyRHCOSVersionsInCertsuite() error {
73+
// Get all nodes
74+
nodesList, err := globalhelper.GetAPIClient().Nodes().List(context.TODO(), metav1.ListOptions{})
75+
if err != nil {
76+
return fmt.Errorf("failed to list nodes: %w", err)
77+
}
78+
79+
// Get certsuite repo path from config
80+
certsuiteRepoPath := globalhelper.GetConfiguration().General.CertsuiteRepoPath
81+
if certsuiteRepoPath == "" {
82+
return fmt.Errorf("CERTSUITE_REPO_PATH is not configured")
83+
}
84+
85+
// Path to rhcos_version_map file - split the relative path and join with certsuite repo path
86+
pathParts := strings.Split(rhcosVersionMapRelativePath, "/")
87+
pathComponents := append([]string{certsuiteRepoPath}, pathParts...)
88+
rhcosVersionMapPath := filepath.Join(pathComponents...)
89+
90+
// Read the rhcos_version_map file
91+
rhcosVersionMapData, err := os.ReadFile(rhcosVersionMapPath)
92+
if err != nil {
93+
return fmt.Errorf("failed to read rhcos_version_map file at %s: %w", rhcosVersionMapPath, err)
94+
}
95+
96+
return verifyRHCOSVersions(nodesList.Items, string(rhcosVersionMapData))
97+
}
98+
99+
// verifyRHCOSVersions is a parameterized function that verifies RHCOS versions from nodes
100+
// against the rhcos_version_map content. This function is designed to be testable.
101+
func verifyRHCOSVersions(nodes []corev1.Node, rhcosVersionMapContent string) error {
102+
const rhcosName = "Red Hat Enterprise Linux CoreOS"
103+
104+
if len(nodes) == 0 {
105+
return fmt.Errorf("no nodes provided for verification")
106+
}
107+
108+
if rhcosVersionMapContent == "" {
109+
return fmt.Errorf("rhcos_version_map content is empty")
110+
}
111+
112+
// Check each node's RHCOS version
113+
for _, node := range nodes {
114+
osImage := node.Status.NodeInfo.OSImage
115+
116+
// Extract RHCOS version from OSImage
117+
// e.g., "Red Hat Enterprise Linux CoreOS 410.84.202205031645-0 (Ootpa)" -> "410.84.202205031645-0"
118+
if !strings.Contains(osImage, rhcosName) {
119+
return fmt.Errorf("node %s has unexpected OS image format: %s (does not contain %s)",
120+
node.Name, osImage, rhcosName)
121+
}
122+
123+
splitStr := strings.Split(osImage, rhcosName)
124+
if len(splitStr) < 2 {
125+
return fmt.Errorf("node %s has unexpected OS image format: %s (cannot split by %s)",
126+
node.Name, osImage, rhcosName)
127+
}
128+
129+
longVersionSplit := strings.Split(strings.TrimSpace(splitStr[1]), " ")
130+
if len(longVersionSplit) == 0 || longVersionSplit[0] == "" {
131+
return fmt.Errorf("node %s has unexpected OS image format: %s (cannot extract version)",
132+
node.Name, osImage)
133+
}
134+
135+
rhcosVersion := longVersionSplit[0]
136+
137+
// Check if the version exists in the rhcos_version_map file
138+
if !strings.Contains(rhcosVersionMapContent, rhcosVersion) {
139+
return fmt.Errorf("RHCOS version %s from node %s not found in rhcos_version_map",
140+
rhcosVersion, node.Name)
141+
}
142+
143+
fmt.Printf("✓ Node %s RHCOS version %s found in rhcos_version_map\n", node.Name, rhcosVersion)
144+
}
145+
146+
return nil
147+
}

0 commit comments

Comments
 (0)