From 7da5544955d17adfbb77d7687f0066304e51ae4e Mon Sep 17 00:00:00 2001 From: Tomer Figenblat Date: Mon, 7 Oct 2024 18:06:22 -0400 Subject: [PATCH] test: fix review change requests 2 - see body - Add nim-serving interception to odh intercept type safety mechanism - Add accelerators interception to odh intercept type safety mechanism Co-authored-by: Daniele Martinoli Co-authored-by: lokeshrangineni Signed-off-by: Tomer Figenblat --- frontend/src/__mocks__/mockNimResource.ts | 5 +++ .../cypress/cypress/support/commands/odh.ts | 24 +++++++++++--- .../src/__tests__/cypress/cypress/types.ts | 7 ++++ .../cypress/cypress/utils/nimUtils.ts | 32 +++++++++++-------- 4 files changed, 49 insertions(+), 19 deletions(-) diff --git a/frontend/src/__mocks__/mockNimResource.ts b/frontend/src/__mocks__/mockNimResource.ts index baa2fa0f90..39b6684141 100644 --- a/frontend/src/__mocks__/mockNimResource.ts +++ b/frontend/src/__mocks__/mockNimResource.ts @@ -9,6 +9,7 @@ import { } from '~/k8sTypes'; import { ServingRuntimeAPIProtocol, ServingRuntimePlatform } from '~/types'; import { mockProjectK8sResource } from '~/__mocks__/mockProjectK8sResource'; +import { NimServingResponse } from '~/__tests__/cypress/cypress/types'; import { mockConfigMap } from './mockConfigMap'; import { mockServingRuntimeK8sResource } from './mockServingRuntimeK8sResource'; import { mockInferenceServiceK8sResource } from './mockInferenceServiceK8sResource'; @@ -138,3 +139,7 @@ export const mockNimModelPVC = (): PersistentVolumeClaimKind => { }); return pvc; }; + +export const mockNimServingResource = ( + resource: ConfigMapKind | SecretKind, +): NimServingResponse => ({ body: { body: resource } }); diff --git a/frontend/src/__tests__/cypress/cypress/support/commands/odh.ts b/frontend/src/__tests__/cypress/cypress/support/commands/odh.ts index d16745d4d5..73e73463c3 100644 --- a/frontend/src/__tests__/cypress/cypress/support/commands/odh.ts +++ b/frontend/src/__tests__/cypress/cypress/support/commands/odh.ts @@ -1,4 +1,4 @@ -import type { K8sResourceListResult, K8sStatus } from '@openshift/dynamic-plugin-sdk-utils'; +import { K8sResourceCommon, K8sResourceListResult, K8sStatus } from '@openshift/dynamic-plugin-sdk-utils'; import type { GenericStaticResponse, RouteHandlerController } from 'cypress/types/net-stubbing'; import type { BaseMetricCreationResponse, BaseMetricListResponse } from '~/api'; import type { @@ -9,7 +9,7 @@ import type { RegisteredModel, RegisteredModelList, } from '~/concepts/modelRegistry/types'; -import type { +import { DashboardConfigKind, DataScienceClusterInitializationKindStatus, DataScienceClusterKindStatus, @@ -19,16 +19,16 @@ import type { TemplateKind, NotebookKind, ModelRegistryKind, - ConsoleLinkKind, + ConsoleLinkKind, RoleBindingSubject, RoleBindingRoleRef, ConfigMapKind, SecretKind, } from '~/k8sTypes'; import type { StartNotebookData } from '~/pages/projects/types'; import type { AllowedUser } from '~/pages/notebookController/screens/admin/types'; import type { GroupsConfig } from '~/pages/groupSettings/groupTypes'; import type { StatusResponse } from '~/redux/types'; -import type { +import { BYONImage, - ClusterSettingsType, + ClusterSettingsType, DetectedAccelerators, ImageInfo, OdhApplication, OdhDocument, @@ -54,6 +54,7 @@ import type { GrpcResponse } from '~/__mocks__/mlmd/utils'; import type { BuildMockPipelinveVersionsType } from '~/__mocks__'; import type { ArtifactStorage } from '~/concepts/pipelines/types'; import type { ConnectionTypeConfigMap } from '~/concepts/connectionTypes/types'; +import { NimServingResponse } from '~/__tests__/cypress/cypress/types'; type SuccessErrorResponse = { success: boolean; @@ -637,6 +638,19 @@ declare global { (( type: 'POST /api/modelRegistryRoleBindings', response: OdhResponse, + ) => Cypress.Chainable) & + (( + type: 'GET /api/accelerators', + response: OdhResponse, + ) => Cypress.Chainable) & + (( + type: 'GET /api/nim-serving/:resource', + options: { + path: { + resource: 'nvidia-nim-images-data' | 'nvidia-nim-access' | 'nvidia-nim-image-pull'; + }; + }, + response: OdhResponse, ) => Cypress.Chainable); } } diff --git a/frontend/src/__tests__/cypress/cypress/types.ts b/frontend/src/__tests__/cypress/cypress/types.ts index 6b7297b9aa..c26889457f 100644 --- a/frontend/src/__tests__/cypress/cypress/types.ts +++ b/frontend/src/__tests__/cypress/cypress/types.ts @@ -1,4 +1,5 @@ import type { RouteMatcher } from 'cypress/types/net-stubbing'; +import { ConfigMapKind, SecretKind } from '~/k8sTypes'; export type Snapshot = { method: string; @@ -71,3 +72,9 @@ export type TestConfig = { OCP_ADMIN_USER: UserAuthConfig; S3: AWSS3Buckets; }; + +export type NimServingResponse = { + body: { + body: ConfigMapKind | SecretKind; + }; +}; diff --git a/frontend/src/__tests__/cypress/cypress/utils/nimUtils.ts b/frontend/src/__tests__/cypress/cypress/utils/nimUtils.ts index 9073b9de7d..7b1e665d41 100644 --- a/frontend/src/__tests__/cypress/cypress/utils/nimUtils.ts +++ b/frontend/src/__tests__/cypress/cypress/utils/nimUtils.ts @@ -21,7 +21,7 @@ import { mockNimImages, mockNimInferenceService, mockNimModelPVC, - mockNimProject, + mockNimProject, mockNimServingResource, mockNimServingRuntime, mockNimServingRuntimeTemplate, mockNvidiaNimAccessSecret, @@ -197,7 +197,7 @@ export const initInterceptsToEnableNim = ({ hasAllModels = false }: EnableNimCon mockK8sResourceList([mockAcceleratorProfile({ namespace: 'opendatahub' })]), ); - cy.intercept('GET', '/api/accelerators', { + cy.interceptOdh('GET /api/accelerators', { configured: true, available: { 'nvidia.com/gpu': 1 }, total: { 'nvidia.com/gpu': 1 }, @@ -213,20 +213,24 @@ export const initInterceptsToDeployModel = (nimInferenceService: InferenceServic cy.interceptK8s('POST', ServingRuntimeModel, mockNimServingRuntime()).as('createServingRuntime'); - // NOTES: `body` field is needed! - cy.intercept( - { method: 'GET', pathname: '/api/nim-serving/nvidia-nim-images-data' }, - { - body: { body: mockNimImages() }, - }, + cy.interceptOdh( + `GET /api/nim-serving/:resource`, + { path: { resource: 'nvidia-nim-images-data' } }, + mockNimServingResource(mockNimImages()), + ); + + cy.interceptOdh( + `GET /api/nim-serving/:resource`, + { path: { resource: 'nvidia-nim-access' } }, + mockNimServingResource(mockNvidiaNimAccessSecret()), ); - cy.intercept( - { method: 'GET', pathname: '/api/nim-serving/nvidia-nim-access' }, - { body: { body: mockNvidiaNimAccessSecret() } }, + + cy.interceptOdh( + `GET /api/nim-serving/:resource`, + { path: { resource: 'nvidia-nim-image-pull' } }, + mockNimServingResource(mockNvidiaNimImagePullSecret()), ); - cy.intercept('GET', 'api/nim-serving/nvidia-nim-image-pull', { - body: { body: mockNvidiaNimImagePullSecret() }, - }); + cy.interceptK8s('POST', PVCModel, mockNimModelPVC()); };