Skip to content

Commit

Permalink
[web] Only load LUNs when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Jul 3, 2023
1 parent a3b3309 commit 8330388
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
1 change: 1 addition & 0 deletions web/src/components/storage/ZFCPDiskForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { noop } from "~/utils";
*
* @callback onSubmitFn
* @param {FormData}
* @returns {number} 0 on success
*
* @typedef {object} FormData
* @property {string} channel
Expand Down
53 changes: 40 additions & 13 deletions web/src/components/storage/ZFCPPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ class Manager {
this.disks.splice(index, 1);
}

addLUNs(luns) {
for (const lun of luns) {
const existingLUN = this.luns.find(l => l.channel === lun.channel && l.wwpn === lun.wwpn && l.lun === lun.lun);
if (!existingLUN) this.luns.push(lun);
}
}

/**
* Gets the list of inactive LUNs.
*
Expand Down Expand Up @@ -306,13 +313,13 @@ const ControllersTable = ({ client, manager }) => {
let value;

switch (column.id) {
case 'channel':
case "channel":
value = controller.channel;
break;
case 'status':
case "status":
value = controller.active ? "Activated" : "Deactivated";
break;
case 'lunScan':
case "lunScan":
if (controller.active)
value = controller.lunScan ? "Yes" : "No";
else
Expand Down Expand Up @@ -637,6 +644,12 @@ const reducer = (state, action) => {
return { ...state };
}

case "ADD_LUNS": {
const { luns } = payload;
state.manager.addLUNs(luns);
return { ...state };
}

default: {
return state;
}
Expand All @@ -658,25 +671,33 @@ export default function ZFCPPage() {
const { cancellablePromise } = useCancellablePromise();
const [state, dispatch] = useReducer(reducer, initialState);

const getLUNs = useCallback(async (controller) => {
const luns = [];
const wwpns = await cancellablePromise(client.zfcp.getWWPNs(controller));
for (const wwpn of wwpns) {
const all = await cancellablePromise(client.zfcp.getLUNs(controller, wwpn));
for (const lun of all) {
luns.push({ channel: controller.channel, wwpn, lun });
}
}
return luns;
}, [client.zfcp, cancellablePromise]);

const load = useCallback(async () => {
dispatch({ type: "START_LOADING" });
await cancellablePromise(client.zfcp.probe());
const controllers = await cancellablePromise(client.zfcp.getControllers());
const disks = await cancellablePromise(client.zfcp.getDisks());
const luns = [];
for (const controller of controllers) {
const wwpns = await cancellablePromise(client.zfcp.getWWPNs(controller));
for (const wwpn of wwpns) {
const all = await cancellablePromise(client.zfcp.getLUNs(controller, wwpn));
for (const lun of all) {
luns.push({ channel: controller.channel, wwpn, lun });
}
if (controller.active && !controller.lunScan) {
luns.push(await getLUNs(controller));
}
}
const manager = new Manager(controllers, disks, luns);
const manager = new Manager(controllers, disks, luns.flat());
dispatch({ type: "SET_MANAGER", payload: { manager } });
dispatch({ type: "STOP_LOADING" });
}, [client.zfcp, cancellablePromise]);
}, [client.zfcp, cancellablePromise, getLUNs]);

useEffect(() => {
load().catch(console.error);
Expand All @@ -689,7 +710,13 @@ export default function ZFCPPage() {
const action = (type, payload) => dispatch({ type, payload });

subscriptions.push(
await client.zfcp.onControllerChanged(c => action("UPDATE_CONTROLLER", { controller: c })),
await client.zfcp.onControllerChanged(async (controller) => {
action("UPDATE_CONTROLLER", { controller });
if (controller.active && !controller.lunScan) {
const luns = await getLUNs(controller);
action("ADD_LUNS", { luns });
}
}),
await client.zfcp.onDiskAdded(d => action("ADD_DISK", { disk: d })),
await client.zfcp.onDiskChanged(d => action("UPDATE_DISK", { disk: d })),
await client.zfcp.onDiskRemoved(d => action("REMOVE_DISK", { disk: d }))
Expand All @@ -702,7 +729,7 @@ export default function ZFCPPage() {

subscribe();
return unsubscribe;
}, [client.zfcp, cancellablePromise]);
}, [client.zfcp, cancellablePromise, getLUNs]);

return (
<Page title="Storage zFCP" icon="hard_drive">
Expand Down
5 changes: 5 additions & 0 deletions web/src/components/storage/ZFCPPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@ beforeEach(() => {
});

it("loads the zFCP devices", async () => {
client.getWWPNs = jest.fn().mockResolvedValue(["0x500507630703d3b3", "0x500507630704d3b3"])

Check failure on line 73 in web/src/components/storage/ZFCPPage.test.jsx

View workflow job for this annotation

GitHub Actions / frontend_build (18.x)

Missing semicolon
installerRender(<ZFCPPage />);

screen.getAllByText(/PFSkeleton/);
expect(screen.queryAllByRole("grid").length).toBe(0);
await waitFor(() => expect(client.probe).toHaveBeenCalled());
await waitFor(() => expect(client.getLUNs).toHaveBeenCalledWith(controllers[1], "0x500507630703d3b3"));
await waitFor(() => expect(client.getLUNs).toHaveBeenCalledWith(controllers[1], "0x500507630704d3b3"));
await waitFor(() => expect(client.getLUNs).not.toHaveBeenCalledWith(controllers[0], "0x500507630703d3b3"));
await waitFor(() => expect(client.getLUNs).not.toHaveBeenCalledWith(controllers[0], "0x500507630704d3b3"));
expect(screen.getAllByRole("grid").length).toBe(2);
});

Expand Down

0 comments on commit 8330388

Please sign in to comment.