Skip to content

Commit 4b4ff4d

Browse files
committed
upgrade status CLI monitortest: test updateLifecycle check
1 parent 9bd4080 commit 4b4ff4d

File tree

1 file changed

+216
-0
lines changed

1 file changed

+216
-0
lines changed
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
package admupgradestatus
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
"github.com/google/go-cmp/cmp"
8+
"github.com/google/go-cmp/cmp/cmpopts"
9+
"github.com/openshift/origin/pkg/test/ginkgo/junitapi"
10+
)
11+
12+
var (
13+
lifecycle01before = `The cluster is not updating.`
14+
15+
lifecycle02updating = `Unable to fetch alerts, ignoring alerts in 'Update Health': failed to get alerts from Thanos: no token is currently in use for this session
16+
= Control Plane =
17+
Assessment: Progressing
18+
Target Version: 4.20.0-0.ci-2025-08-13-121604-test-ci-op-njttt0ww-latest (from 4.20.0-0.ci-2025-08-13-114210-test-ci-op-njttt0ww-initial)
19+
Updating: etcd, kube-apiserver
20+
Completion: 3% (1 operators updated, 2 updating, 31 waiting)
21+
Duration: 3m51s (Est. Time Remaining: 1h7m)
22+
Operator Health: 34 Healthy
23+
24+
Updating Cluster Operators
25+
NAME SINCE REASON MESSAGE
26+
etcd 2m53s NodeInstaller NodeInstallerProgressing: 2 nodes are at revision 8; 1 node is at revision 9
27+
kube-apiserver 2m21s NodeInstaller NodeInstallerProgressing: 3 nodes are at revision 7; 0 nodes have achieved new revision 8
28+
29+
Control Plane Nodes
30+
NAME ASSESSMENT PHASE VERSION EST MESSAGE
31+
ip-10-0-111-19.us-west-1.compute.internal Outdated Pending 4.20.0-0.ci-2025-08-13-114210-test-ci-op-njttt0ww-initial ?
32+
ip-10-0-53-218.us-west-1.compute.internal Outdated Pending 4.20.0-0.ci-2025-08-13-114210-test-ci-op-njttt0ww-initial ?
33+
ip-10-0-99-189.us-west-1.compute.internal Outdated Pending 4.20.0-0.ci-2025-08-13-114210-test-ci-op-njttt0ww-initial ?
34+
35+
= Worker Upgrade =
36+
37+
WORKER POOL ASSESSMENT COMPLETION STATUS
38+
worker Pending 0% (0/3) 3 Available, 0 Progressing, 0 Draining
39+
40+
Worker Pool Nodes: worker
41+
NAME ASSESSMENT PHASE VERSION EST MESSAGE
42+
ip-10-0-0-72.us-west-1.compute.internal Outdated Pending 4.20.0-0.ci-2025-08-13-114210-test-ci-op-njttt0ww-initial ?
43+
ip-10-0-100-255.us-west-1.compute.internal Outdated Pending 4.20.0-0.ci-2025-08-13-114210-test-ci-op-njttt0ww-initial ?
44+
ip-10-0-106-212.us-west-1.compute.internal Outdated Pending 4.20.0-0.ci-2025-08-13-114210-test-ci-op-njttt0ww-initial ?
45+
46+
= Update Health =
47+
SINCE LEVEL IMPACT MESSAGE
48+
3m51s Info None Update is proceeding well`
49+
50+
lifecycle03controlPlaneNodesUpdated = `Unable to fetch alerts, ignoring alerts in 'Update Health': failed to get alerts from Thanos: no token is currently in use for this session
51+
= Control Plane =
52+
Assessment: Progressing - Slow
53+
Target Version: 4.20.0-0.ci-2025-08-13-121604-test-ci-op-njttt0ww-latest (from 4.20.0-0.ci-2025-08-13-114210-test-ci-op-njttt0ww-initial)
54+
Updating: machine-config
55+
Completion: 97% (33 operators updated, 1 updating, 0 waiting)
56+
Duration: 1h1m (Est. Time Remaining: <10m)
57+
Operator Health: 30 Healthy, 4 Available but degraded
58+
59+
Updating Cluster Operators
60+
NAME SINCE REASON MESSAGE
61+
machine-config 22m21s - Working towards 4.20.0-0.ci-2025-08-13-121604-test-ci-op-njttt0ww-latest
62+
63+
All control plane nodes successfully updated to 4.20.0-0.ci-2025-08-13-121604-test-ci-op-njttt0ww-latest
64+
65+
= Worker Upgrade =
66+
67+
WORKER POOL ASSESSMENT COMPLETION STATUS
68+
worker Completed 100% (3/3) 3 Available, 0 Progressing, 0 Draining
69+
70+
Worker Pool Nodes: worker
71+
NAME ASSESSMENT PHASE VERSION EST MESSAGE
72+
ip-10-0-0-72.us-west-1.compute.internal Completed Updated 4.20.0-0.ci-2025-08-13-121604-test-ci-op-njttt0ww-latest -
73+
ip-10-0-100-255.us-west-1.compute.internal Completed Updated 4.20.0-0.ci-2025-08-13-121604-test-ci-op-njttt0ww-latest -
74+
ip-10-0-106-212.us-west-1.compute.internal Completed Updated 4.20.0-0.ci-2025-08-13-121604-test-ci-op-njttt0ww-latest -
75+
76+
= Update Health =
77+
SINCE LEVEL IMPACT MESSAGE
78+
1h1m36s Info None Update is proceeding well`
79+
80+
lifecycle04controlPlaneUpdated = `Unable to fetch alerts, ignoring alerts in 'Update Health': failed to get alerts from Thanos: no token is currently in use for this session
81+
= Control Plane =
82+
Update to 4.20.0-0.ci-2025-08-13-121604-test-ci-op-njttt0ww-latest successfully completed at 2025-08-13T14:15:18Z (duration: 1h2m)
83+
84+
All control plane nodes successfully updated to 4.20.0-0.ci-2025-08-13-121604-test-ci-op-njttt0ww-latest
85+
86+
= Worker Upgrade =
87+
88+
WORKER POOL ASSESSMENT COMPLETION STATUS
89+
worker Completed 100% (3/3) 3 Available, 0 Progressing, 0 Draining
90+
91+
Worker Pool Nodes: worker
92+
NAME ASSESSMENT PHASE VERSION EST MESSAGE
93+
ip-10-0-0-72.us-west-1.compute.internal Completed Updated 4.20.0-0.ci-2025-08-13-121604-test-ci-op-njttt0ww-latest -
94+
ip-10-0-100-255.us-west-1.compute.internal Completed Updated 4.20.0-0.ci-2025-08-13-121604-test-ci-op-njttt0ww-latest -
95+
ip-10-0-106-212.us-west-1.compute.internal Completed Updated 4.20.0-0.ci-2025-08-13-121604-test-ci-op-njttt0ww-latest -
96+
97+
= Update Health =
98+
SINCE LEVEL IMPACT MESSAGE
99+
1h1m36s Info None Update is proceeding well`
100+
101+
lifecycle05after = `The cluster is not updating.`
102+
)
103+
104+
func TestMonitor_UpdateLifecycle(t *testing.T) {
105+
t.Parallel()
106+
107+
testCases := []struct {
108+
name string
109+
snapshots []snapshot
110+
wasUpdated bool
111+
expected *junitapi.JUnitTestCase
112+
}{
113+
{
114+
name: "no snapshots -> test skipped",
115+
expected: &junitapi.JUnitTestCase{
116+
Name: "[sig-cli][OCPFeatureGate:UpgradeStatus] oc adm upgrade status snapshots reflect the cluster upgrade lifecycle",
117+
SkipMessage: &junitapi.SkipMessage{
118+
Message: "Test skipped because no oc adm upgrade status output was successfully collected",
119+
},
120+
},
121+
},
122+
{
123+
name: "model update",
124+
snapshots: []snapshot{
125+
{when: time.Now(), out: lifecycle01before},
126+
{when: time.Now(), out: lifecycle02updating},
127+
{when: time.Now(), out: lifecycle03controlPlaneNodesUpdated},
128+
{when: time.Now(), out: lifecycle04controlPlaneUpdated},
129+
{when: time.Now(), out: lifecycle05after},
130+
},
131+
wasUpdated: true,
132+
expected: &junitapi.JUnitTestCase{
133+
Name: "[sig-cli][OCPFeatureGate:UpgradeStatus] oc adm upgrade status snapshots reflect the cluster upgrade lifecycle",
134+
},
135+
},
136+
{
137+
name: "sometimes we miss the control plane updated state, this is okay",
138+
snapshots: []snapshot{
139+
{when: time.Now(), out: lifecycle01before},
140+
{when: time.Now(), out: lifecycle02updating},
141+
{when: time.Now(), out: lifecycle05after},
142+
},
143+
wasUpdated: true,
144+
expected: &junitapi.JUnitTestCase{
145+
Name: "[sig-cli][OCPFeatureGate:UpgradeStatus] oc adm upgrade status snapshots reflect the cluster upgrade lifecycle",
146+
},
147+
},
148+
{
149+
name: "completed control plane nodes went back to updating",
150+
snapshots: []snapshot{
151+
{when: time.Now(), out: lifecycle01before},
152+
{when: time.Now(), out: lifecycle02updating},
153+
{when: time.Now(), out: lifecycle03controlPlaneNodesUpdated},
154+
{when: time.Now(), out: lifecycle02updating},
155+
{when: time.Now(), out: lifecycle05after},
156+
},
157+
wasUpdated: true,
158+
expected: &junitapi.JUnitTestCase{
159+
Name: "[sig-cli][OCPFeatureGate:UpgradeStatus] oc adm upgrade status snapshots reflect the cluster upgrade lifecycle",
160+
FailureOutput: &junitapi.FailureOutput{
161+
Message: "observed unexpected update lifecycle transition in oc adm upgrade status",
162+
},
163+
},
164+
},
165+
{
166+
name: "no update observed when cluster was not updated",
167+
snapshots: []snapshot{
168+
{when: time.Now(), out: lifecycle01before},
169+
{when: time.Now(), out: lifecycle01before},
170+
{when: time.Now(), out: lifecycle01before},
171+
},
172+
wasUpdated: false,
173+
expected: &junitapi.JUnitTestCase{
174+
Name: "[sig-cli][OCPFeatureGate:UpgradeStatus] oc adm upgrade status snapshots reflect the cluster upgrade lifecycle",
175+
},
176+
},
177+
{
178+
name: "update observed when cluster was not updated",
179+
snapshots: []snapshot{
180+
{when: time.Now(), out: lifecycle01before},
181+
{when: time.Now(), out: lifecycle02updating},
182+
{when: time.Now(), out: lifecycle01before},
183+
},
184+
wasUpdated: false,
185+
expected: &junitapi.JUnitTestCase{
186+
Name: "[sig-cli][OCPFeatureGate:UpgradeStatus] oc adm upgrade status snapshots reflect the cluster upgrade lifecycle",
187+
FailureOutput: &junitapi.FailureOutput{
188+
Message: "observed unexpected update lifecycle transition in oc adm upgrade status",
189+
},
190+
},
191+
},
192+
}
193+
194+
for _, tc := range testCases {
195+
t.Run(tc.name, func(t *testing.T) {
196+
t.Parallel()
197+
198+
m := NewOcAdmUpgradeStatusChecker().(*monitor)
199+
m.ocAdmUpgradeStatus = append(m.ocAdmUpgradeStatus, tc.snapshots...)
200+
201+
ignoreOutput := cmpopts.IgnoreFields(junitapi.FailureOutput{}, "Output")
202+
203+
// Process snapshots into models for the health check to work with
204+
_ = m.expectedLayout()
205+
206+
wasUpdated := func() (bool, error) {
207+
return tc.wasUpdated, nil
208+
}
209+
210+
result := m.updateLifecycle(wasUpdated)
211+
if diff := cmp.Diff(tc.expected, result, ignoreOutput); diff != "" {
212+
t.Errorf("unexpected result (-want +got):\n%s", diff)
213+
}
214+
})
215+
}
216+
}

0 commit comments

Comments
 (0)