-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1091 from SanjalKatiyar/rbd_default_sc
set RBD as default StorageClass
- Loading branch information
Showing
8 changed files
with
237 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...orage-system/create-storage-system-steps/backing-storage-step/set-rbd-sc-default.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import * as React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { SetCephRBDStorageClassDefault } from './set-rbd-sc-default'; | ||
|
||
describe('Setting Ceph RBD StorageClass as default, during installation', () => { | ||
it('renders the FC, on infra with existing default StorageClass', async () => { | ||
const uEvent = userEvent.setup(); | ||
const Wrapper = () => { | ||
const [isRBDStorageClassDefault, dispatch] = React.useState(false); | ||
const dispatchWrapper = ({ payload }) => dispatch(payload); | ||
return ( | ||
<SetCephRBDStorageClassDefault | ||
doesDefaultSCAlreadyExists={true} | ||
isRBDStorageClassDefault={isRBDStorageClassDefault} | ||
dispatch={dispatchWrapper} | ||
/> | ||
); | ||
}; | ||
|
||
const { container, rerender } = render(<Wrapper />); | ||
const checkbox = container.querySelector( | ||
'[data-test="set-rbd-sc-default"]' | ||
) as HTMLInputElement; | ||
|
||
expect( | ||
screen.getByText('Set Ceph RBD as the default StorageClass') | ||
).toBeInTheDocument(); | ||
|
||
// by defaut checkbox should not be checked | ||
expect(checkbox.checked).toBe(false); | ||
|
||
// on clicking, checkbox should get checked | ||
await uEvent.click(checkbox); | ||
expect(checkbox.checked).toBe(true); | ||
|
||
// re-render should not change the checkbox state | ||
rerender(<Wrapper />); | ||
expect(checkbox.checked).toBe(true); | ||
}); | ||
|
||
it('renders the FC, on infra with non-existing default StorageClass', async () => { | ||
const uEvent = userEvent.setup(); | ||
const Wrapper = () => { | ||
const [isRBDStorageClassDefault, dispatch] = React.useState(false); | ||
const dispatchWrapper = ({ payload }) => dispatch(payload); | ||
return ( | ||
<SetCephRBDStorageClassDefault | ||
doesDefaultSCAlreadyExists={false} | ||
isRBDStorageClassDefault={isRBDStorageClassDefault} | ||
dispatch={dispatchWrapper} | ||
/> | ||
); | ||
}; | ||
|
||
const { container, rerender } = render(<Wrapper />); | ||
const checkbox = container.querySelector( | ||
'[data-test="set-rbd-sc-default"]' | ||
) as HTMLInputElement; | ||
|
||
expect( | ||
screen.getByText('Set Ceph RBD as the default StorageClass') | ||
).toBeInTheDocument(); | ||
|
||
// by defaut checkbox should be checked | ||
expect(checkbox.checked).toBe(true); | ||
|
||
// on clicking, checkbox should get un-checked | ||
await uEvent.click(checkbox); | ||
expect(checkbox.checked).toBe(false); | ||
|
||
// re-render should not change the checkbox state | ||
rerender(<Wrapper />); | ||
expect(checkbox.checked).toBe(false); | ||
}); | ||
}); |
49 changes: 49 additions & 0 deletions
49
...te-storage-system/create-storage-system-steps/backing-storage-step/set-rbd-sc-default.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as React from 'react'; | ||
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook'; | ||
import { FormGroup, Checkbox } from '@patternfly/react-core'; | ||
import { WizardDispatch, WizardState } from '../../reducer'; | ||
import './backing-storage-step.scss'; | ||
|
||
export const SetCephRBDStorageClassDefault: React.FC<SetCephRBDStorageClassDefaultProps> = | ||
({ dispatch, isRBDStorageClassDefault, doesDefaultSCAlreadyExists }) => { | ||
const { t } = useCustomTranslation(); | ||
|
||
// for infra with already existing "default" SC (eg: say gp3-csi): option should be default unchecked. | ||
// for infra with no "default" SC (BM here): option should be default checked. | ||
React.useEffect(() => { | ||
if (!doesDefaultSCAlreadyExists) { | ||
dispatch({ | ||
type: 'backingStorage/setIsRBDStorageClassDefault', | ||
payload: true, | ||
}); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return ( | ||
<FormGroup> | ||
<Checkbox | ||
id="set-rbd-sc-default" | ||
data-test="set-rbd-sc-default" | ||
label={t('Set Ceph RBD as the default StorageClass')} | ||
description={t( | ||
'Configure a default RBD StorageClass to eliminate manual annotations within a StorageClass or selecting a specific StorageClass when making storage requests or provisions in your PVCs.' | ||
)} | ||
isChecked={isRBDStorageClassDefault} | ||
onChange={() => | ||
dispatch({ | ||
type: 'backingStorage/setIsRBDStorageClassDefault', | ||
payload: !isRBDStorageClassDefault, | ||
}) | ||
} | ||
className="odf-backing-store__radio--margin-bottom" | ||
/> | ||
</FormGroup> | ||
); | ||
}; | ||
|
||
type SetCephRBDStorageClassDefaultProps = { | ||
dispatch: WizardDispatch; | ||
isRBDStorageClassDefault: WizardState['backingStorage']['isRBDStorageClassDefault']; | ||
doesDefaultSCAlreadyExists: boolean; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.