From b48fce71e052f15f731930550edab4899c156faa Mon Sep 17 00:00:00 2001 From: Mattia Franchetto Date: Mon, 31 Oct 2022 12:27:52 +0100 Subject: [PATCH 1/5] Extract default lustre throughput values in constants --- frontend/src/old-pages/Configure/Storage.tsx | 23 ++++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/frontend/src/old-pages/Configure/Storage.tsx b/frontend/src/old-pages/Configure/Storage.tsx index 758bf961..657e2869 100644 --- a/frontend/src/old-pages/Configure/Storage.tsx +++ b/frontend/src/old-pages/Configure/Storage.tsx @@ -107,6 +107,16 @@ function storageValidate() { return valid } +const LUSTRE_PERSISTENT1_DEFAULT_THROUGHPUT = 200 +const LUSTRE_PERSISTENT2_DEFAULT_THROUGHPUT = 125 +const storageThroughputsP1 = [50, 100, LUSTRE_PERSISTENT1_DEFAULT_THROUGHPUT] +const storageThroughputsP2 = [ + LUSTRE_PERSISTENT2_DEFAULT_THROUGHPUT, + 250, + 500, + 1000, +] + function FsxLustreSettings({index}: any) { const {t} = useTranslation() const isLustrePersistent2Active = useFeatureFlag('lustre_persistent2') @@ -124,8 +134,6 @@ function FsxLustreSettings({index}: any) { 'SCRATCH_2', ].filter(Boolean) const storageThroughputPath = [...fsxPath, 'PerUnitStorageThroughput'] - const storageThroughputsP1 = [50, 100, 200] - const storageThroughputsP2 = [125, 250, 500, 1000] const importPathPath = [...fsxPath, 'ImportPath'] const exportPathPath = [...fsxPath, 'ExportPath'] const compressionPath = [...fsxPath, 'DataCompressionType'] @@ -233,11 +241,12 @@ function FsxLustreSettings({index}: any) { selectedOption={strToOption(lustreType || 'PERSISTENT_1')} onChange={({detail}) => { setState(lustreTypePath, detail.selectedOption.value) - if (detail.selectedOption.value === 'PERSISTENT_1') { - setState(storageThroughputPath, 200) - } else { - clearState(storageThroughputPath) - } + setState( + storageThroughputPath, + detail.selectedOption.value === 'PERSISTENT_1' + ? LUSTRE_PERSISTENT1_DEFAULT_THROUGHPUT + : LUSTRE_PERSISTENT2_DEFAULT_THROUGHPUT, + ) }} options={lustreTypes.map(strToOption)} /> From 763fe430aae76650d31382f66447cbfd0672afa1 Mon Sep 17 00:00:00 2001 From: Mattia Franchetto Date: Mon, 31 Oct 2022 12:29:58 +0100 Subject: [PATCH 2/5] Populate PerUnitStorageThroughtput on Lustre storage --- frontend/src/old-pages/Configure/Storage.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/frontend/src/old-pages/Configure/Storage.tsx b/frontend/src/old-pages/Configure/Storage.tsx index 657e2869..29a97d32 100644 --- a/frontend/src/old-pages/Configure/Storage.tsx +++ b/frontend/src/old-pages/Configure/Storage.tsx @@ -153,6 +153,14 @@ function FsxLustreSettings({index}: any) { const lustreTypePath = [...fsxPath, 'DeploymentType'] if (storageCapacity === null && !useExisting) setState(storageCapacityPath, 1200) + if (!storageThroughput && !useExisting) { + setState( + storageThroughputPath, + lustreType === 'PERSISTENT_1' + ? LUSTRE_PERSISTENT1_DEFAULT_THROUGHPUT + : LUSTRE_PERSISTENT2_DEFAULT_THROUGHPUT, + ) + } if (lustreType === null && !useExisting) setState( lustreTypePath, @@ -160,6 +168,7 @@ function FsxLustreSettings({index}: any) { ) }, [ storageCapacity, + storageThroughputPath, lustreType, storageThroughput, index, From 6d7086ca2ac2cf8a05e50605cc12b8a153b056e2 Mon Sep 17 00:00:00 2001 From: Mattia Franchetto Date: Mon, 31 Oct 2022 12:32:23 +0100 Subject: [PATCH 3/5] Remove default display value for PerUnitStorageThroughput --- frontend/src/old-pages/Configure/Storage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/old-pages/Configure/Storage.tsx b/frontend/src/old-pages/Configure/Storage.tsx index 29a97d32..e138e376 100644 --- a/frontend/src/old-pages/Configure/Storage.tsx +++ b/frontend/src/old-pages/Configure/Storage.tsx @@ -342,7 +342,7 @@ function FsxLustreSettings({index}: any) { > { setState(storageThroughputPath, detail.selectedOption.value) }} diff --git a/frontend/src/old-pages/Configure/storage.test.tsx b/frontend/src/old-pages/Configure/storage.test.tsx new file mode 100644 index 00000000..cf268448 --- /dev/null +++ b/frontend/src/old-pages/Configure/storage.test.tsx @@ -0,0 +1,176 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance +// with the License. A copy of the License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES +// OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and +// limitations under the License. + +import {render} from '@testing-library/react' +import {I18nextProvider} from 'react-i18next' +import i18n from 'i18next' +import {initReactI18next} from 'react-i18next' +import mock from 'jest-mock-extended/lib/Mock' +import {Store} from '@reduxjs/toolkit' +import {Provider} from 'react-redux' +jest.mock('../../store', () => { + const originalModule = jest.requireActual('../../store') + + return { + __esModule: true, // Use it when dealing with esModules + ...originalModule, + setState: jest.fn(), + } +}) + +jest.mock('../../feature-flags/useFeatureFlag', () => ({ + useFeatureFlag: () => true, +})) +import {setState} from '../../store' +import {FsxLustreSettings} from './Storage' + +i18n.use(initReactI18next).init({ + resources: {}, + lng: 'en', +}) + +const mockStore = mock() +const MockProviders = (props: any) => ( + + {props.children} + +) + +describe('Given a Lustre storage component', () => { + beforeEach(() => { + ;(setState as jest.Mock).mockClear() + }) + describe("when it's initialized", () => { + describe('with a Persistent_1 type', () => { + beforeEach(() => { + mockStore.getState.mockReturnValue({ + app: { + wizard: { + config: { + SharedStorage: [ + { + FsxLustreSettings: { + DeploymentType: 'PERSISTENT_1', + }, + }, + ], + }, + }, + }, + }) + }) + it('should set the correct PerUnitStorageThroughPut value in the config', () => { + render( + + + , + ) + expect(setState).toHaveBeenCalledWith( + [ + 'app', + 'wizard', + 'config', + 'SharedStorage', + 0, + 'FsxLustreSettings', + 'PerUnitStorageThroughput', + ], + 200, + ) + }) + }) + describe('with a Persistent_2 type', () => { + beforeEach(() => { + mockStore.getState.mockReturnValue({ + app: { + wizard: { + config: { + SharedStorage: [ + { + FsxLustreSettings: { + DeploymentType: 'PERSISTENT_2', + }, + }, + ], + }, + }, + }, + }) + }) + it('should set the correct PerUnitStorageThroughPut value in the config', () => { + render( + + + , + ) + expect(setState).toHaveBeenCalledWith( + [ + 'app', + 'wizard', + 'config', + 'SharedStorage', + 0, + 'FsxLustreSettings', + 'PerUnitStorageThroughput', + ], + 125, + ) + }) + }) + + describe('when the user wants to link an already created Lustre', () => { + beforeEach(() => { + mockStore.getState.mockReturnValue({ + app: { + wizard: { + storage: { + ui: [ + { + useExisting: true, + }, + ], + }, + config: { + SharedStorage: [ + { + FsxLustreSettings: { + DeploymentType: 'PERSISTENT_2', + }, + }, + ], + }, + }, + }, + }) + }) + + it('should not set the PerUnitStorageThroughPut in the config', () => { + render( + + + , + ) + expect(setState).not.toHaveBeenCalledWith( + [ + 'app', + 'wizard', + 'config', + 'SharedStorage', + 0, + 'FsxLustreSettings', + 'PerUnitStorageThroughput', + ], + expect.any(Number), + ) + }) + }) + }) +}) From 81186f751664da9e2663b90382a9fb9c458f8407 Mon Sep 17 00:00:00 2001 From: Mattia Franchetto Date: Mon, 31 Oct 2022 16:09:37 +0100 Subject: [PATCH 5/5] Remove storage throughput path from default values check --- frontend/src/old-pages/Configure/Storage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/old-pages/Configure/Storage.tsx b/frontend/src/old-pages/Configure/Storage.tsx index a0aaf38c..d9e952b4 100644 --- a/frontend/src/old-pages/Configure/Storage.tsx +++ b/frontend/src/old-pages/Configure/Storage.tsx @@ -166,9 +166,9 @@ export function FsxLustreSettings({index}: any) { lustreTypePath, isLustrePersistent2Active ? 'PERSISTENT_2' : 'PERSISTENT_1', ) + // eslint-disable-next-line react-hooks/exhaustive-deps }, [ storageCapacity, - storageThroughputPath, lustreType, storageThroughput, index,