-
Notifications
You must be signed in to change notification settings - Fork 366
nvme iopolicy get and set definitions in utils #6210
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -529,3 +529,41 @@ def get_subsystem_using_ctrl_name(ctrl): | |
| if ctrl in ctrls: | ||
| return get_subsys_name_with_nqn(device_nqn) | ||
| return "" | ||
|
|
||
|
|
||
| def get_nvme_subsystem_io_policy(subsystem): | ||
| """ | ||
| Read io policy parameter from sysfs folder and returns a string | ||
|
|
||
| :param subsystem: Name of the subsystem | ||
| :rtype: String | ||
| """ | ||
| subsys_iopolicy_path = f"/sys/class/nvme-subsystem/{subsystem}/iopolicy" | ||
| if os.path.isfile(subsys_iopolicy_path): | ||
| return open(subsys_iopolicy_path, "r", encoding="utf-8").readline().rstrip("\n") | ||
| raise NvmeException(f"iopolicy file not found: {subsys_iopolicy_path}") | ||
|
|
||
|
|
||
| def change_nvme_subsystem_io_policy(subsystem, io_policy): | ||
| """ | ||
| Changes io policy of nvme device to specified io policy | ||
| Change in io policy is not persistent | ||
|
|
||
| :param subsystem: Name of the subsystem | ||
| :param io_policy: Name of the io_policy to which we want to set | ||
| :raises: NvmeException on command failures | ||
| :rtype: Boolean | ||
| """ | ||
| subsys_iopolicy_path = f"/sys/class/nvme-subsystem/{subsystem}/iopolicy" | ||
| if get_nvme_subsystem_io_policy(subsystem) == io_policy: | ||
| LOGGER.info("Returning True as iopolicy is same as current") | ||
| return True | ||
| if os.path.isfile(subsys_iopolicy_path): | ||
| with open(subsys_iopolicy_path, "w", encoding="utf-8") as subsys_iopolicy_file: | ||
| subsys_iopolicy_file.write(io_policy) | ||
| subsys_iopolicy_file.close() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you are using the |
||
| else: | ||
| raise NvmeException(f"iopolicy file not found: {subsys_iopolicy_path}") | ||
| if get_nvme_subsystem_io_policy(subsystem) == io_policy: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please explain to me why the lines 567,568,569 are needed? IIUIC any issues with changing the policy will raise an error during the write operation at line 563 where you should handle it. |
||
| return True | ||
| raise NvmeException("Failed to change iopolicy") | ||
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.
💡 Verification agent
🧩 Analysis chain
Satisfy Ruff TRY003.
Shorten messages and/or raise from the underlying exception as shown above.
Run:
Also applies to: 566-566, 569-569
🏁 Script executed:
#!/bin/bash ruff check avocado/utils/nvme.pyLength of output: 17897
Comply with Ruff TRY003 on exception messages
In avocado/utils/nvme.py at lines 544, 566 and 569 the literal exception texts exceed Ruff’s length limit—shorten them or chain from the original error (e.g.
raise NvmeException("iopolicy file missing") from err).🧰 Tools
🪛 Ruff (0.12.2)
544-544: Avoid specifying long messages outside the exception class
(TRY003)
🤖 Prompt for AI Agents