Skip to content
This repository was archived by the owner on Mar 13, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions frontend/src/old-pages/Configure/Storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,17 @@ function storageValidate() {
return valid
}

function FsxLustreSettings({index}: any) {
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,
]

export function FsxLustreSettings({index}: any) {
const {t} = useTranslation()
const isLustrePersistent2Active = useFeatureFlag('lustre_persistent2')
const useExisting =
Expand All @@ -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']
Expand All @@ -145,11 +153,20 @@ 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,
isLustrePersistent2Active ? 'PERSISTENT_2' : 'PERSISTENT_1',
)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
storageCapacity,
lustreType,
Expand Down Expand Up @@ -233,11 +250,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)}
/>
Expand Down Expand Up @@ -324,7 +342,7 @@ function FsxLustreSettings({index}: any) {
>
<FormField label={t('wizard.storage.Fsx.throughput.label')}>
<Select
selectedOption={strToOption(storageThroughput || 125)}
selectedOption={strToOption(storageThroughput || '')}
onChange={({detail}) => {
setState(storageThroughputPath, detail.selectedOption.value)
}}
Expand Down
176 changes: 176 additions & 0 deletions frontend/src/old-pages/Configure/storage.test.tsx
Original file line number Diff line number Diff line change
@@ -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<Store>()
const MockProviders = (props: any) => (
<Provider store={mockStore}>
<I18nextProvider i18n={i18n}>{props.children}</I18nextProvider>
</Provider>
)

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(
<MockProviders>
<FsxLustreSettings index={0} />
</MockProviders>,
)
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(
<MockProviders>
<FsxLustreSettings index={0} />
</MockProviders>,
)
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(
<MockProviders>
<FsxLustreSettings index={0} />
</MockProviders>,
)
expect(setState).not.toHaveBeenCalledWith(
[
'app',
'wizard',
'config',
'SharedStorage',
0,
'FsxLustreSettings',
'PerUnitStorageThroughput',
],
expect.any(Number),
)
})
})
})
})