@@ -5,7 +5,7 @@ import Withinable = Cypress.Withinable;
55import Shadow = Cypress . Shadow ;
66import 'cypress-wait-until' ;
77import { operatorHubPage } from '../../views/operator-hub-page' ;
8-
8+ import { nav } from '../../views/nav' ;
99
1010export { } ;
1111
@@ -22,12 +22,12 @@ declare global {
2222 }
2323 }
2424
25-
2625const readyTimeoutMilliseconds = Cypress . config ( 'readyTimeoutMilliseconds' ) as number ;
2726const installTimeoutMilliseconds = Cypress . config ( 'installTimeoutMilliseconds' ) as number ;
2827
29- Cypress . Commands . add ( 'beforeBlock' , ( MP : { namespace : string , operatorName : string } ) => {
30-
28+ // Shared operator utilities
29+ const operatorUtils = {
30+ loginAndAuth ( ) : void {
3131 cy . log ( 'Before block' ) ;
3232 cy . adminCLI (
3333 `oc adm policy add-cluster-role-to-user cluster-admin ${ Cypress . env ( 'LOGIN_USERNAME' ) } ` ,
@@ -46,8 +46,8 @@ Cypress.Commands.add('beforeBlock', (MP: { namespace: string, operatorName: stri
4646 } else {
4747 throw new Error ( `Execution of oc get oauthclient failed
4848 Exit code: ${ result . code }
49- Stdout:\n${ result . stdout }
50- Stderr:\n${ result . stderr } ` ) ;
49+ Stdout:\\ n${ result . stdout }
50+ Stderr:\\ n${ result . stderr } ` ) ;
5151 }
5252 } ) ;
5353 cy . get ( '@oauthorigin' ) . then ( ( oauthorigin ) => {
@@ -58,7 +58,9 @@ Cypress.Commands.add('beforeBlock', (MP: { namespace: string, operatorName: stri
5858 oauthorigin ,
5959 ) ;
6060 } ) ;
61-
61+ } ,
62+
63+ setupMonitoringPluginImage ( MP : { namespace : string } ) : void {
6264 cy . log ( 'Set Monitoring Plugin image in operator CSV' ) ;
6365 if ( Cypress . env ( 'MP_IMAGE' ) ) {
6466 cy . log ( 'MP_IMAGE is set. the image will be patched in CMO operator CSV' ) ;
@@ -80,71 +82,9 @@ Cypress.Commands.add('beforeBlock', (MP: { namespace: string, operatorName: stri
8082 } else {
8183 cy . log ( 'MP_IMAGE is NOT set. Skipping patching the image in CMO operator CSV.' ) ;
8284 }
83-
84- cy . task ( 'clearDownloads' ) ;
85- cy . log ( 'Before block completed' ) ;
86- } ) ;
87-
88- Cypress . Commands . add ( 'afterBlock' , ( MP : { namespace : string , operatorName : string } ) => {
89- cy . log ( 'After block' ) ;
90- if ( Cypress . env ( 'MP_IMAGE' ) ) {
91- cy . log ( 'MP_IMAGE is set. Lets revert CMO operator CSV' ) ;
92- cy . exec (
93- './cypress/fixtures/cmo/reenable-monitoring.sh' ,
94- {
95- env : {
96- MP_IMAGE : Cypress . env ( 'MP_IMAGE' ) ,
97- KUBECONFIG : Cypress . env ( 'KUBECONFIG_PATH' ) ,
98- MP_NAMESPACE : `${ MP . namespace } `
99- } ,
100- timeout : readyTimeoutMilliseconds ,
101- failOnNonZeroExit : true
102- }
103- ) . then ( ( result ) => {
104- expect ( result . code ) . to . eq ( 0 ) ;
105- cy . log ( `CMO CSV reverted successfully with Monitoring Plugin image: ${ result . stdout } ` ) ;
106- } ) ;
107- } else {
108- cy . log ( 'MP_IMAGE is NOT set. Skipping reverting the image in CMO operator CSV.' ) ;
109- }
110-
111- cy . log ( 'After block completed' ) ;
112- } ) ;
113-
114- Cypress . Commands . add ( 'beforeBlockCOO' , ( MCP : { namespace : string , operatorName : string , packageName : string } , MP : { namespace : string , operatorName : string } ) => {
115- cy . log ( 'Before block COO' ) ;
116-
117- cy . log ( 'Before all' ) ;
118- cy . adminCLI (
119- `oc adm policy add-cluster-role-to-user cluster-admin ${ Cypress . env ( 'LOGIN_USERNAME' ) } ` ,
120- ) ;
121- // Getting the oauth url for hypershift cluster login
122- cy . exec (
123- `oc get oauthclient openshift-browser-client -o go-template --template="{{index .redirectURIs 0}}" --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` ,
124- ) . then ( ( result ) => {
125- if ( expect ( result . stderr ) . to . be . empty ) {
126- const oauth = result . stdout ;
127- // Trimming the origin part of the url
128- const oauthurl = new URL ( oauth ) ;
129- const oauthorigin = oauthurl . origin ;
130- cy . log ( oauthorigin ) ;
131- cy . wrap ( oauthorigin ) . as ( 'oauthorigin' ) ;
132- } else {
133- throw new Error ( `Execution of oc get oauthclient failed
134- Exit code: ${ result . code }
135- Stdout:\n${ result . stdout }
136- Stderr:\n${ result . stderr } ` ) ;
137- }
138- } ) ;
139- cy . get ( '@oauthorigin' ) . then ( ( oauthorigin ) => {
140- cy . login (
141- Cypress . env ( 'LOGIN_IDP' ) ,
142- Cypress . env ( 'LOGIN_USERNAME' ) ,
143- Cypress . env ( 'LOGIN_PASSWORD' ) ,
144- oauthorigin ,
145- ) ;
146- } ) ;
147-
85+ } ,
86+
87+ installCOO ( MCP : { namespace : string , packageName : string } ) : void {
14888 if ( Cypress . env ( 'SKIP_COO_INSTALL' ) ) {
14989 cy . log ( 'SKIP_COO_INSTALL is set. Skipping Cluster Observability Operator installation.' ) ;
15090 } else if ( Cypress . env ( 'COO_UI_INSTALL' ) ) {
@@ -203,11 +143,12 @@ Cypress.Commands.add('beforeBlock', (MP: { namespace: string, operatorName: stri
203143 timeout : installTimeoutMilliseconds
204144 }
205145 ) ;
206-
207146 } else {
208147 throw new Error ( 'No CYPRESS env set for operator installation, check the README for more details.' ) ;
209148 }
210-
149+ } ,
150+
151+ waitForCOOReady ( MCP : { namespace : string } ) : void {
211152 cy . log ( 'Check Cluster Observability Operator status' ) ;
212153 cy . exec (
213154 `sleep 15 && oc wait --for=condition=Ready pods --selector=app.kubernetes.io/name=observability-operator -n ${ MCP . namespace } --timeout=60s --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` ,
@@ -219,15 +160,17 @@ Cypress.Commands.add('beforeBlock', (MP: { namespace: string, operatorName: stri
219160 expect ( result . code ) . to . eq ( 0 ) ;
220161 cy . log ( `Observability-operator pod is now running in namespace: ${ MCP . namespace } ` ) ;
221162 } ) ;
222-
163+
223164 cy . get ( '#page-sidebar' ) . then ( ( $sidebar ) => {
224165 const section = $sidebar . text ( ) . includes ( 'Ecosystem' ) ? 'Ecosystem' : 'Operators' ;
225- cy . clickNavLink ( [ section , 'Installed Operators' ] ) ;
166+ nav . sidenav . clickNavLink ( [ section , 'Installed Operators' ] ) ;
226167 } ) ;
227-
168+
228169 cy . byTestID ( 'name-filter-input' ) . should ( 'be.visible' ) . type ( 'Cluster Observability{enter}' ) ;
229170 cy . get ( '[data-test="status-text"]' , { timeout : installTimeoutMilliseconds } ) . eq ( 0 ) . should ( 'contain.text' , 'Succeeded' , { timeout : installTimeoutMilliseconds } ) ;
230-
171+ } ,
172+
173+ setupMonitoringConsolePlugin ( MCP : { namespace : string } ) : void {
231174 cy . log ( 'Set Monitoring Console Plugin image in operator CSV' ) ;
232175 if ( Cypress . env ( 'MCP_CONSOLE_IMAGE' ) ) {
233176 cy . log ( 'MCP_CONSOLE_IMAGE is set. the image will be patched in COO operator CSV' ) ;
@@ -249,13 +192,15 @@ Cypress.Commands.add('beforeBlock', (MP: { namespace: string, operatorName: stri
249192 } else {
250193 cy . log ( 'MCP_CONSOLE_IMAGE is NOT set. Skipping patching the image in COO operator CSV.' ) ;
251194 }
252-
195+ } ,
196+
197+ setupDashboardsAndPlugins ( MCP : { namespace : string } ) : void {
253198 cy . log ( 'Create PersesDashboard instance.' ) ;
254199 cy . exec ( `oc apply -f ./cypress/fixtures/coo/openshift-cluster-sample-dashboard.yaml --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` ) ;
255-
200+
256201 cy . log ( 'Create Thanos Querier instance.' ) ;
257202 cy . exec ( `oc apply -f ./cypress/fixtures/coo/thanos-querier-datasource.yaml --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` ) ;
258-
203+
259204 cy . log ( 'Create Monitoring UI Plugin instance.' ) ;
260205 cy . exec ( `oc apply -f ./cypress/fixtures/coo/monitoring-ui-plugin.yaml --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` ) ;
261206 cy . exec (
@@ -268,27 +213,17 @@ Cypress.Commands.add('beforeBlock', (MP: { namespace: string, operatorName: stri
268213 expect ( result . code ) . to . eq ( 0 ) ;
269214 cy . log ( `Monitoring plugin pod is now running in namespace: ${ MCP . namespace } ` ) ;
270215 } ) ;
271- cy . exec ( `oc label namespace openshift-cluster-observability-operator openshift.io/cluster-monitoring="true" --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` )
272- //TODO: https://issues.redhat.com/browse/OCPBUGS-58468 - console reload and logout was happening more often
273- // cy.get('.pf-v5-c-alert, .pf-v6-c-alert', { timeout: readyTimeoutMilliseconds })
274- // .contains('Web console update is available')
275- // .then(($alert) => {
276- // // If the alert is found, assert that it exists
277- // expect($alert).to.exist;
278- // }, () => {
279- // // If the alert is not found within the timeout, visit and assert the /monitoring/v2/dashboards page
280- // cy.visit('/monitoring/v2/dashboards');
281- // cy.url().should('include', '/monitoring/v2/dashboards');
282- // });
216+ cy . exec ( `oc label namespace openshift-cluster-observability-operator openshift.io/cluster-monitoring="true" --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` ) ;
283217 cy . reload ( ) ;
284218 cy . visit ( '/monitoring/v2/dashboards' ) ;
285219 cy . url ( ) . should ( 'include' , '/monitoring/v2/dashboards' ) ;
286-
287- cy . log ( 'Set Monitoring Plugin image in operator CSV' ) ;
220+ } ,
221+
222+ revertMonitoringPluginImage ( MP : { namespace : string } ) : void {
288223 if ( Cypress . env ( 'MP_IMAGE' ) ) {
289- cy . log ( 'MP_IMAGE is set. the image will be patched in CMO operator CSV' ) ;
224+ cy . log ( 'MP_IMAGE is set. Lets revert CMO operator CSV' ) ;
290225 cy . exec (
291- './cypress/fixtures/cmo/update -monitoring-plugin-image .sh' ,
226+ './cypress/fixtures/cmo/reenable -monitoring.sh' ,
292227 {
293228 env : {
294229 MP_IMAGE : Cypress . env ( 'MP_IMAGE' ) ,
@@ -300,55 +235,71 @@ Cypress.Commands.add('beforeBlock', (MP: { namespace: string, operatorName: stri
300235 }
301236 ) . then ( ( result ) => {
302237 expect ( result . code ) . to . eq ( 0 ) ;
303- cy . log ( `CMO CSV updated successfully with Monitoring Plugin image: ${ result . stdout } ` ) ;
238+ cy . log ( `CMO CSV reverted successfully with Monitoring Plugin image: ${ result . stdout } ` ) ;
304239 } ) ;
305240 } else {
306- cy . log ( 'MP_IMAGE is NOT set. Skipping patching the image in CMO operator CSV.' ) ;
241+ cy . log ( 'MP_IMAGE is NOT set. Skipping reverting the image in CMO operator CSV.' ) ;
307242 }
308-
309- cy . log ( 'Before block COO completed' ) ;
310- } ) ;
311-
312- Cypress . Commands . add ( 'afterBlockCOO' , ( MCP : { namespace : string , operatorName : string , packageName : string } , MP : { namespace : string , operatorName : string } ) => {
313- cy . log ( 'After block COO' ) ;
243+ } ,
244+
245+ cleanup ( MCP : { namespace : string , config ?: { kind : string , name : string } } ) : void {
246+ const config = MCP . config || { kind : 'UIPlugin' , name : 'monitoring' } ;
247+
314248 if ( Cypress . env ( 'SKIP_COO_INSTALL' ) ) {
315249 cy . log ( 'Delete Monitoring UI Plugin instance.' ) ;
316250 cy . executeAndDelete (
317- `oc delete ${ MCP . config . kind } ${ MCP . config . name } --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` ,
251+ `oc delete ${ config . kind } ${ config . name } --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` ,
318252 ) ;
319-
253+
320254 cy . log ( 'Remove cluster-admin role from user.' ) ;
321255 cy . executeAndDelete (
322256 `oc adm policy remove-cluster-role-from-user cluster-admin ${ Cypress . env ( 'LOGIN_USERNAME' ) } --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` ,
323257 ) ;
324258 } else {
325259 cy . log ( 'Delete Monitoring UI Plugin instance.' ) ;
326260 cy . executeAndDelete (
327- `oc delete ${ MCP . config . kind } ${ MCP . config . name } --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` ,
261+ `oc delete ${ config . kind } ${ config . name } --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` ,
328262 ) ;
329-
263+
330264 cy . log ( 'Remove Cluster Observability Operator' ) ;
331265 cy . executeAndDelete ( `oc delete namespace ${ MCP . namespace } --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` ) ;
332-
266+
333267 cy . log ( 'Remove cluster-admin role from user.' ) ;
334268 cy . executeAndDelete (
335269 `oc adm policy remove-cluster-role-from-user cluster-admin ${ Cypress . env ( 'LOGIN_USERNAME' ) } --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` ,
336270 ) ;
271+
272+ cy . executeAndDelete ( `oc label namespace openshift-cluster-observability-operator openshift.io/cluster-monitoring- --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` ) ;
273+ }
274+ }
275+ } ;
276+
277+ Cypress . Commands . add ( 'beforeBlock' , ( MP : { namespace : string , operatorName : string } ) => {
278+ operatorUtils . loginAndAuth ( ) ;
279+ operatorUtils . setupMonitoringPluginImage ( MP ) ;
280+ cy . task ( 'clearDownloads' ) ;
281+ cy . log ( 'Before block completed' ) ;
282+ } ) ;
337283
338- cy . executeAndDelete ( `oc label namespace openshift-cluster-observability-operator openshift.io/cluster-monitoring- --kubeconfig ${ Cypress . env ( 'KUBECONFIG_PATH' ) } ` )
284+ Cypress . Commands . add ( 'afterBlock' , ( MP : { namespace : string , operatorName : string } ) => {
285+ cy . log ( 'After block' ) ;
286+ operatorUtils . revertMonitoringPluginImage ( MP ) ;
287+ cy . log ( 'After block completed' ) ;
288+ } ) ;
339289
340- //TODO: https://issues.redhat.com/browse/OCPBUGS-58468 - console reload and logout was happening more often
341- // cy.get('.pf-v5-c-alert, .pf-v6-c-alert', { timeout: 120000 })
342- // .contains('Web console update is available')
343- // .then(($alert) => {
344- // // If the alert is found, assert that it exists
345- // expect($alert).to.exist;
346- // }, () => {
347- // // If the alert is not found within the timeout, visit and assert the /monitoring/v2/dashboards page
348- // cy.visit('/monitoring/v2/dashboards');
349- // cy.url().should('not.include', '/monitoring/v2/dashboards');
350- // });
290+ Cypress . Commands . add ( 'beforeBlockCOO' , ( MCP : { namespace : string , operatorName : string , packageName : string } , MP : { namespace : string , operatorName : string } ) => {
291+ cy . log ( 'Before block COO' ) ;
292+ operatorUtils . loginAndAuth ( ) ;
293+ operatorUtils . installCOO ( MCP ) ;
294+ operatorUtils . waitForCOOReady ( MCP ) ;
295+ operatorUtils . setupMonitoringConsolePlugin ( MCP ) ;
296+ operatorUtils . setupDashboardsAndPlugins ( MCP ) ;
297+ operatorUtils . setupMonitoringPluginImage ( MP ) ;
298+ cy . log ( 'Before block COO completed' ) ;
299+ } ) ;
351300
352- }
301+ Cypress . Commands . add ( 'afterBlockCOO' , ( MCP : { namespace : string , operatorName : string , packageName : string } , MP : { namespace : string , operatorName : string } ) => {
302+ cy . log ( 'After block COO' ) ;
303+ operatorUtils . cleanup ( MCP ) ;
353304 cy . log ( 'After block COO completed' ) ;
354305 } ) ;
0 commit comments