-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(web): use queries to handle iSCSI configuration #1598
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2efcbe3
refactor(web): convert Initiator* components to TypeScript
imobachgs cfed0b9
refactor(web): add iSCSI types to types/storage
imobachgs 9c40a35
feat(web): use queries to handle the iSCSI initiator
imobachgs ea1e10e
refactor(web): convert iSCSI nodes components to TypeScript
imobachgs 6bfe7e6
fix(web): update the proposal on "DevicesDirty"
imobachgs 5043e96
refactor(web): use queries to retrieve iSCSI nodes
imobachgs b147b64
refactor(web): do not use the client to handle iSCSI nodes
imobachgs 05b6843
refactor(web): only refresh storage when loading ProposalPage
imobachgs 65ed7cc
refactor(web): fix App test
imobachgs 89eb4eb
refactor(web): clean-up and test InitiatorPresenter
imobachgs a030a26
refactor(web): clean-up and test TargetsSection
imobachgs aa79303
refactor(web): use the storage code using prettier
imobachgs 10998b9
fix(rust): do not send false ISCSIInitiatorChanged events
imobachgs 6733791
refactor(web): improve the update of iSCSI-related queries
imobachgs b619b84
Apply suggestions from code review
imobachgs abe872a
refactor(web): apply suggestions from code review
imobachgs 684d796
refactor(web): extend the iSCSI queries docs
imobachgs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright (c) [2024] SUSE LLC | ||
* | ||
* All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of version 2 of the GNU General Public License as published | ||
* by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, contact SUSE LLC. | ||
* | ||
* To contact SUSE LLC about this file by physical or electronic mail, you may | ||
* find current contact information at www.suse.com. | ||
*/ | ||
|
||
import { del, get, patch, post } from "~/api/http"; | ||
import { ISCSIInitiator, ISCSINode } from "~/api/storage/types"; | ||
|
||
const ISCSI_NODES_NAMESPACE = "/api/storage/iscsi/nodes"; | ||
|
||
const nodePath = (node: ISCSINode): string => ISCSI_NODES_NAMESPACE + "/" + node.id; | ||
|
||
/** | ||
* Returns the iSCSI initiator. | ||
*/ | ||
const fetchInitiator = (): Promise<ISCSIInitiator> => get("/api/storage/iscsi/initiator"); | ||
|
||
/** | ||
* Updates the name of the iSCSI initiator. | ||
*/ | ||
const updateInitiator = ({ name }) => patch("/api/storage/iscsi/initiator", { name }); | ||
|
||
/** | ||
* Returns the iSCSI nodes. | ||
*/ | ||
const fetchNodes = (): Promise<ISCSINode[]> => get("/api/storage/iscsi/nodes"); | ||
|
||
type LoginOptions = { | ||
// Password for authentication by target | ||
password?: string; | ||
// Username for authentication by target | ||
username?: string; | ||
// Password for authentication by initiator | ||
reversePassword?: string; | ||
// Username for authentication by initiator | ||
reverseUsername?: string; | ||
}; | ||
|
||
/** | ||
* Performs an iSCSI discovery. | ||
* | ||
* @param address - IP address of the ISCSI server | ||
* @param port - Port of the iSCSI server | ||
* @param options - Authentication options | ||
* @return true on success, false on failure | ||
*/ | ||
const discover = async (address: string, port: number, options: LoginOptions): Promise<boolean> => { | ||
const data = { address, port, options }; | ||
try { | ||
await post("/api/storage/iscsi/discover", data); | ||
return true; | ||
} catch (error) { | ||
console.error("Error discovering iSCSI targets:", error.message); | ||
return false; | ||
} | ||
}; | ||
|
||
const deleteNode = async (node: ISCSINode): Promise<void> => { | ||
await del(nodePath(node)); | ||
}; | ||
|
||
/* | ||
* Creates an iSCSI session on the given node. | ||
* | ||
* @param node - ISCSI node | ||
* @param options - Authentication options | ||
* @return operation result (0: success; 1: invalid startup; 2: failed) | ||
*/ | ||
const login = async (node: ISCSINode, options: LoginOptions) => { | ||
try { | ||
await post(nodePath(node) + "/login", options); | ||
return 0; | ||
} catch (error) { | ||
const { data: reason } = error.response; | ||
console.warn("Could not login into the iSCSI node:", error.message, "reason:", reason); | ||
return reason === "InvalidStartup" ? 1 : 2; | ||
} | ||
}; | ||
|
||
/* | ||
* Closes an iSCSI session on the given node. | ||
* | ||
* @param node - ISCSI node | ||
*/ | ||
const logout = async (node: ISCSINode) => post(nodePath(node) + "/logout"); | ||
|
||
/** | ||
* Sets the startup status of the connection | ||
* | ||
* @param node - ISCSI node | ||
* @param startup - startup status | ||
*/ | ||
const setStartup = async (node: ISCSINode, startup: string) => patch(nodePath(node), { startup }); | ||
|
||
export { | ||
fetchInitiator, | ||
fetchNodes, | ||
updateInitiator, | ||
discover, | ||
deleteNode, | ||
login, | ||
logout, | ||
setStartup, | ||
}; | ||
export type { LoginOptions }; |
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
File renamed without changes.
File renamed without changes.
67 changes: 67 additions & 0 deletions
67
web/src/components/storage/iscsi/InitiatorPresenter.test.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,67 @@ | ||
/* | ||
* Copyright (c) [2024] SUSE LLC | ||
* | ||
* All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of version 2 of the GNU General Public License as published | ||
* by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, contact SUSE LLC. | ||
* | ||
* To contact SUSE LLC about this file by physical or electronic mail, you may | ||
* find current contact information at www.suse.com. | ||
*/ | ||
|
||
import React from "react"; | ||
import { screen, within } from "@testing-library/react"; | ||
import { plainRender } from "~/test-utils"; | ||
|
||
import InitiatorPresenter from "./InitiatorPresenter"; | ||
import { ISCSIInitiator } from "~/types/storage"; | ||
|
||
const initiator: ISCSIInitiator = { | ||
name: "iqn.1996-04.de.suse:01:62b45cf7fc", | ||
ibft: true, | ||
offloadCard: "", | ||
}; | ||
|
||
const mockInitiatorMutation = { mutateAsync: jest.fn() }; | ||
|
||
jest.mock("~/queries/storage/iscsi", () => ({ | ||
...jest.requireActual("~/queries/storage/iscsi"), | ||
useInitiatorMutation: () => mockInitiatorMutation, | ||
})); | ||
|
||
describe("InitiatorPresenter", () => { | ||
it("displays the initiator data", () => { | ||
plainRender(<InitiatorPresenter initiator={initiator} />); | ||
screen.getByText(initiator.name); | ||
screen.getByRole("cell", { name: initiator.name }); | ||
}); | ||
|
||
it("updates the initiator data", async () => { | ||
const { user } = plainRender(<InitiatorPresenter initiator={initiator} />); | ||
|
||
const button = await screen.findByRole("button", { name: "Actions" }); | ||
await user.click(button); | ||
|
||
const editButton = await screen.findByRole("menuitem", { name: "Edit" }); | ||
await user.click(editButton); | ||
|
||
const dialog = await screen.findByRole("dialog"); | ||
const nameInput = await within(dialog).findByLabelText(/Name/); | ||
await user.clear(nameInput); | ||
await user.type(nameInput, "my-initiator"); | ||
const confirmButton = screen.getByRole("button", { name: "Confirm" }); | ||
await user.click(confirmButton); | ||
|
||
expect(mockInitiatorMutation.mutateAsync).toHaveBeenCalledWith({ name: "my-initiator" }); | ||
imobachgs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, startup is string, so it can accept any value? or is it kind of enum with limited statuses?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a generic string. I do not like it that much, but I decided to keep it as it was, considering it was out of this PR's scope. But sure we should improve how we handle the staus.