From dde80b9b5416be555be7a969a56428aa74964437 Mon Sep 17 00:00:00 2001 From: "spyroot@gmail.com" Date: Sat, 25 Jul 2026 05:51:18 +0400 Subject: [PATCH] Split boot option tests by domain --- .../test_boot_options_dualmode.py | 76 +++++++++++++++++++ .../test_boot_source_options_dualmode.py} | 74 ++---------------- tools/test_layout_baseline.txt | 1 - 3 files changed, 82 insertions(+), 69 deletions(-) create mode 100644 tests/boot_options/test_boot_options_dualmode.py rename tests/{test_boot_options_dualmode.py => boot_source/test_boot_source_options_dualmode.py} (58%) diff --git a/tests/boot_options/test_boot_options_dualmode.py b/tests/boot_options/test_boot_options_dualmode.py new file mode 100644 index 00000000..b291ea7d --- /dev/null +++ b/tests/boot_options/test_boot_options_dualmode.py @@ -0,0 +1,76 @@ +"""Dual-mode regression tests for BootOptions commands. + + redfish_ctl boot-sources + redfish_ctl boot-options +""" +import json + +import pytest +import requests + +from redfish_ctl.cmd_exceptions import ResourceNotFound +from redfish_ctl.idrac_manager import IDracManager +from redfish_ctl.idrac_shared import ApiRequestType +from redfish_ctl.redfish_manager import CommandResult + + +def test_boot_options_list_returns_member_uris(redfish_api): + """boot_sources_query returns BootOptions member Redfish URIs.""" + result = redfish_api.sync_invoke( + ApiRequestType.BootOptions, + "boot_sources_query", + ) + + assert isinstance(result, CommandResult) + assert isinstance(result.data, list) + assert result.data == [ + "/redfish/v1/Systems/System.Embedded.1/BootOptions/HardDisk.List.1-1", + "/redfish/v1/Systems/System.Embedded.1/BootOptions/NIC.PxeDevice.1-1", + ] + assert result.extra["Members@odata.count"] == 2 + + +def test_boot_options_list_404_non_json_raises_resource_not_found( + redfish_api, monkeypatch): + """Plain-text 404 BootOptions responses raise cleanly without JSON traceback.""" + original_api_get_call = IDracManager.api_get_call + + def api_get_call(self, request, headers=None): + """Return the X10-style non-JSON BootOptions failure. + + :param self: command instance issuing the GET. + :param request: BootOptions collection request URL. + :param headers: optional HTTP headers sent by the command. + :return: a plain-text 404 response. + """ + if "/BootOptions" not in request: + return original_api_get_call(self, request, headers) + response = requests.Response() + response.status_code = 404 + response._content = b"BootOptions not available" + response.headers["Content-Type"] = "text/plain" + return response + + monkeypatch.setattr(IDracManager, "api_get_call", api_get_call) + + with pytest.raises(ResourceNotFound): + redfish_api.sync_invoke( + ApiRequestType.BootOptions, + "boot_sources_query", + ) + + +def test_boot_options_query_returns_collection(redfish_api): + """boot_options_query returns the BootOptions collection resource.""" + result = redfish_api.sync_invoke( + ApiRequestType.BootOptionQuery, + "boot_options_query", + ) + + assert isinstance(result, CommandResult) + assert isinstance(result.data, dict) + json.dumps(result.data) + assert result.data["@odata.id"] == ( + "/redfish/v1/Systems/System.Embedded.1/BootOptions" + ) + assert result.data["Members"][0]["@odata.id"].endswith("/HardDisk.List.1-1") diff --git a/tests/test_boot_options_dualmode.py b/tests/boot_source/test_boot_source_options_dualmode.py similarity index 58% rename from tests/test_boot_options_dualmode.py rename to tests/boot_source/test_boot_source_options_dualmode.py index 778e45ff..c6e2ca98 100644 --- a/tests/test_boot_options_dualmode.py +++ b/tests/boot_source/test_boot_source_options_dualmode.py @@ -1,78 +1,16 @@ -"""Dual-mode tests for boot option and boot-source commands.""" -import json +"""Dual-mode regression tests for boot-source commands using BootOptions data. -import pytest -import requests + redfish_ctl boot-source + redfish_ctl boot-settings + redfish_ctl boot-options-clear +""" +import json from redfish_ctl.boot_source.cmd_clear_pending import BootOptionsClearPending -from redfish_ctl.cmd_exceptions import ResourceNotFound -from redfish_ctl.idrac_manager import IDracManager from redfish_ctl.idrac_shared import ApiRequestType from redfish_ctl.redfish_manager import CommandResult -def test_boot_options_list_returns_member_uris(redfish_api): - """boot_sources_query returns BootOptions member Redfish URIs.""" - result = redfish_api.sync_invoke( - ApiRequestType.BootOptions, - "boot_sources_query", - ) - - assert isinstance(result, CommandResult) - assert isinstance(result.data, list) - assert result.data == [ - "/redfish/v1/Systems/System.Embedded.1/BootOptions/HardDisk.List.1-1", - "/redfish/v1/Systems/System.Embedded.1/BootOptions/NIC.PxeDevice.1-1", - ] - assert result.extra["Members@odata.count"] == 2 - - -def test_boot_options_list_404_non_json_raises_resource_not_found( - redfish_api, monkeypatch): - """Plain-text 404 BootOptions responses raise cleanly without JSON traceback.""" - original_api_get_call = IDracManager.api_get_call - - def api_get_call(self, request, headers=None): - """Return the X10-style non-JSON BootOptions failure. - - :param self: command instance issuing the GET. - :param request: BootOptions collection request URL. - :param headers: optional HTTP headers sent by the command. - :return: a plain-text 404 response. - """ - if "/BootOptions" not in request: - return original_api_get_call(self, request, headers) - response = requests.Response() - response.status_code = 404 - response._content = b"BootOptions not available" - response.headers["Content-Type"] = "text/plain" - return response - - monkeypatch.setattr(IDracManager, "api_get_call", api_get_call) - - with pytest.raises(ResourceNotFound): - redfish_api.sync_invoke( - ApiRequestType.BootOptions, - "boot_sources_query", - ) - - -def test_boot_options_query_returns_collection(redfish_api): - """boot_options_query returns the BootOptions collection resource.""" - result = redfish_api.sync_invoke( - ApiRequestType.BootOptionQuery, - "boot_options_query", - ) - - assert isinstance(result, CommandResult) - assert isinstance(result.data, dict) - json.dumps(result.data) - assert result.data["@odata.id"] == ( - "/redfish/v1/Systems/System.Embedded.1/BootOptions" - ) - assert result.data["Members"][0]["@odata.id"].endswith("/HardDisk.List.1-1") - - def test_boot_source_query_filters_linked_boot_option(redfish_api): """boot_source_query follows BootOptions links and returns the requested device.""" result = redfish_api.sync_invoke( diff --git a/tools/test_layout_baseline.txt b/tools/test_layout_baseline.txt index 64e2deaf..99d0f78c 100644 --- a/tools/test_layout_baseline.txt +++ b/tools/test_layout_baseline.txt @@ -7,7 +7,6 @@ tests/request_benchmark.py tests/test_api_facade.py tests/test_ast_conventions.py tests/test_base_request_respond_async.py -tests/test_boot_options_dualmode.py tests/test_capability_report.py tests/test_cli_subcommand_uniqueness.py tests/test_cmd_utils.py