|
| 1 | +package admupgradestatus |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + "testing" |
| 6 | + "time" |
| 7 | + |
| 8 | + "github.com/google/go-cmp/cmp" |
| 9 | + "github.com/google/go-cmp/cmp/cmpopts" |
| 10 | + "github.com/openshift/origin/pkg/test/ginkgo/junitapi" |
| 11 | +) |
| 12 | + |
| 13 | +var workersExampleOutput = `Unable to fetch alerts, ignoring alerts in 'Update Health': failed to get alerts from Thanos: no token is currently in use for this session |
| 14 | += Control Plane = |
| 15 | +Assessment: Progressing |
| 16 | +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) |
| 17 | +Updating: kube-apiserver |
| 18 | +Completion: 6% (2 operators updated, 1 updating, 31 waiting) |
| 19 | +Duration: 8m57s (Est. Time Remaining: 1h9m) |
| 20 | +Operator Health: 34 Healthy |
| 21 | +
|
| 22 | +Updating Cluster Operators |
| 23 | +NAME SINCE REASON MESSAGE |
| 24 | +kube-apiserver 7m27s NodeInstaller NodeInstallerProgressing: 1 node is at revision 7; 2 nodes are at revision 8 |
| 25 | +
|
| 26 | +Control Plane Nodes |
| 27 | +NAME ASSESSMENT PHASE VERSION EST MESSAGE |
| 28 | +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 ? |
| 29 | +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 ? |
| 30 | +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 ? |
| 31 | +
|
| 32 | += Worker Upgrade = |
| 33 | +
|
| 34 | +WORKER POOL ASSESSMENT COMPLETION STATUS |
| 35 | +worker Pending 0% (0/3) 3 Available, 0 Progressing, 0 Draining |
| 36 | +
|
| 37 | +Worker Pool Nodes: worker |
| 38 | +NAME ASSESSMENT PHASE VERSION EST MESSAGE |
| 39 | +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 ? |
| 40 | +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 ? |
| 41 | +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 ? |
| 42 | +
|
| 43 | += Update Health = |
| 44 | +SINCE LEVEL IMPACT MESSAGE |
| 45 | +8m57s Info None Update is proceeding well` |
| 46 | + |
| 47 | +var workersBadOutput = `= Control Plane = |
| 48 | +Assessment: Progressing |
| 49 | +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) |
| 50 | +Completion: 6% (2 operators updated, 1 updating, 31 waiting) |
| 51 | +Duration: 8m57s (Est. Time Remaining: 1h9m) |
| 52 | +Operator Health: 34 Healthy |
| 53 | +
|
| 54 | +Control Plane Nodes |
| 55 | +NAME ASSESSMENT PHASE VERSION EST MESSAGE |
| 56 | +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 ? |
| 57 | +
|
| 58 | +SOMETHING UNEXPECTED HERE |
| 59 | +
|
| 60 | += Update Health = |
| 61 | +SINCE LEVEL IMPACT MESSAGE |
| 62 | +8m57s Info None Update is proceeding well` |
| 63 | + |
| 64 | +var workersInEmptyPool = `= Control Plane = |
| 65 | +Assessment: Progressing |
| 66 | +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) |
| 67 | +Completion: 6% (2 operators updated, 1 updating, 31 waiting) |
| 68 | +Duration: 8m57s (Est. Time Remaining: 1h9m) |
| 69 | +Operator Health: 34 Healthy |
| 70 | +
|
| 71 | +Control Plane Nodes |
| 72 | +NAME ASSESSMENT PHASE VERSION EST MESSAGE |
| 73 | +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 ? |
| 74 | +
|
| 75 | += Worker Upgrade = |
| 76 | +
|
| 77 | +WORKER POOL ASSESSMENT COMPLETION STATUS |
| 78 | +zbeast Empty 0 Total |
| 79 | +
|
| 80 | +Worker Pool Nodes: zbeast |
| 81 | +NAME ASSESSMENT PHASE VERSION EST MESSAGE |
| 82 | +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 ? |
| 83 | +
|
| 84 | += Update Health = |
| 85 | +SINCE LEVEL IMPACT MESSAGE |
| 86 | +8m57s Info None Update is proceeding well` |
| 87 | + |
| 88 | +var moreNodeTables = `= Control Plane = |
| 89 | +Assessment: Progressing |
| 90 | +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) |
| 91 | +Completion: 6% (2 operators updated, 1 updating, 31 waiting) |
| 92 | +Duration: 8m57s (Est. Time Remaining: 1h9m) |
| 93 | +Operator Health: 34 Healthy |
| 94 | +
|
| 95 | +Control Plane Nodes |
| 96 | +NAME ASSESSMENT PHASE VERSION EST MESSAGE |
| 97 | +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 ? |
| 98 | +
|
| 99 | += Worker Upgrade = |
| 100 | +
|
| 101 | +WORKER POOL ASSESSMENT COMPLETION STATUS |
| 102 | +worker Pending 0% (0/3) 3 Available, 0 Progressing, 0 Draining |
| 103 | +
|
| 104 | +Worker Pool Nodes: worker |
| 105 | +NAME ASSESSMENT PHASE VERSION EST MESSAGE |
| 106 | +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 ? |
| 107 | +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 ? |
| 108 | +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 ? |
| 109 | +
|
| 110 | +Worker Pool Nodes: what-is-this |
| 111 | +NAME ASSESSMENT PHASE VERSION EST MESSAGE |
| 112 | +nope-nope-nope Outdated Pending 4.20.0-0.ci-2025-08-13-114210-test-ci-op-njttt0ww-initial ? |
| 113 | +
|
| 114 | += Update Health = |
| 115 | +SINCE LEVEL IMPACT MESSAGE |
| 116 | +8m57s Info None Update is proceeding well` |
| 117 | + |
| 118 | +func TestMonitor_Workers(t *testing.T) { |
| 119 | + t.Parallel() |
| 120 | + |
| 121 | + testCases := []struct { |
| 122 | + name string |
| 123 | + snapshots []snapshot |
| 124 | + expected *junitapi.JUnitTestCase |
| 125 | + }{ |
| 126 | + { |
| 127 | + name: "no snapshots -> test skipped", |
| 128 | + expected: &junitapi.JUnitTestCase{ |
| 129 | + Name: "[sig-cli][OCPFeatureGate:UpgradeStatus] oc adm upgrade status workers section is consistent", |
| 130 | + SkipMessage: &junitapi.SkipMessage{ |
| 131 | + Message: "Test skipped because no oc adm upgrade status output was successfully collected", |
| 132 | + }, |
| 133 | + }, |
| 134 | + }, |
| 135 | + { |
| 136 | + name: "good snapshots", |
| 137 | + snapshots: []snapshot{ |
| 138 | + {when: time.Now(), out: workersExampleOutput}, |
| 139 | + {when: time.Now(), out: workersExampleOutput}, |
| 140 | + {when: time.Now(), out: workersExampleOutput}, |
| 141 | + }, |
| 142 | + expected: &junitapi.JUnitTestCase{ |
| 143 | + Name: "[sig-cli][OCPFeatureGate:UpgradeStatus] oc adm upgrade status workers section is consistent", |
| 144 | + }, |
| 145 | + }, |
| 146 | + { |
| 147 | + name: "errored snapshots are skipped", |
| 148 | + snapshots: []snapshot{ |
| 149 | + {when: time.Now(), out: workersExampleOutput}, |
| 150 | + {when: time.Now(), out: workersBadOutput, err: errors.New("some error")}, |
| 151 | + {when: time.Now(), out: workersExampleOutput}, |
| 152 | + }, |
| 153 | + expected: &junitapi.JUnitTestCase{ |
| 154 | + Name: "[sig-cli][OCPFeatureGate:UpgradeStatus] oc adm upgrade status workers section is consistent", |
| 155 | + }, |
| 156 | + }, |
| 157 | + { |
| 158 | + name: "unparseable snapshots are skipped", |
| 159 | + snapshots: []snapshot{ |
| 160 | + {when: time.Now(), out: workersExampleOutput}, |
| 161 | + {when: time.Now(), out: "unparseable output"}, |
| 162 | + {when: time.Now(), out: workersExampleOutput}, |
| 163 | + }, |
| 164 | + expected: &junitapi.JUnitTestCase{ |
| 165 | + Name: "[sig-cli][OCPFeatureGate:UpgradeStatus] oc adm upgrade status workers section is consistent", |
| 166 | + }, |
| 167 | + }, |
| 168 | + { |
| 169 | + name: "empty table shown for empty pool", |
| 170 | + snapshots: []snapshot{ |
| 171 | + {when: time.Now(), out: workersInEmptyPool}, |
| 172 | + }, |
| 173 | + expected: &junitapi.JUnitTestCase{ |
| 174 | + Name: "[sig-cli][OCPFeatureGate:UpgradeStatus] oc adm upgrade status workers section is consistent", |
| 175 | + FailureOutput: &junitapi.FailureOutput{ |
| 176 | + Message: "observed unexpected outputs in oc adm upgrade status workers section", |
| 177 | + }, |
| 178 | + }, |
| 179 | + }, |
| 180 | + { |
| 181 | + name: "pool node table shown for pool not present in pool table", |
| 182 | + snapshots: []snapshot{ |
| 183 | + {when: time.Now(), out: moreNodeTables}, |
| 184 | + }, |
| 185 | + expected: &junitapi.JUnitTestCase{ |
| 186 | + Name: "[sig-cli][OCPFeatureGate:UpgradeStatus] oc adm upgrade status workers section is consistent", |
| 187 | + FailureOutput: &junitapi.FailureOutput{ |
| 188 | + Message: "observed unexpected outputs in oc adm upgrade status workers section", |
| 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 workers check to work with |
| 204 | + _ = m.expectedLayout() |
| 205 | + |
| 206 | + result := m.workers() |
| 207 | + if diff := cmp.Diff(tc.expected, result, ignoreOutput); diff != "" { |
| 208 | + t.Errorf("unexpected result (-want +got):\n%s", diff) |
| 209 | + } |
| 210 | + }) |
| 211 | + } |
| 212 | +} |
0 commit comments