| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
from __future__ import (absolute_import, division, print_function) |
| 12 |
|
| 13 |
__metaclass__ = type |
| 14 |
|
| 15 |
import pytest |
| 16 |
import json |
| 17 |
from ansible_collections.dellemc.openmanage.plugins.modules import idrac_boot |
| 18 |
from ansible_collections.dellemc.openmanage.tests.unit.plugins.modules.common import FakeAnsibleModule |
| 19 |
from io import StringIO |
| 20 |
from ansible.module_utils._text import to_text |
| 21 |
from ansible.module_utils.six.moves.urllib.error import HTTPError, URLError |
| 22 |
from ansible.module_utils.urls import ConnectionError, SSLValidationError |
| 23 |
from unittest.mock import MagicMock |
| 24 |
|
| 25 |
MODULE_PATH = 'ansible_collections.dellemc.openmanage.plugins.modules.' |
| 26 |
MODULE_UTIL_PATH = 'ansible_collections.dellemc.openmanage.plugins.module_utils.utils.' |
| 27 |
|
| 28 |
|
| 29 |
@pytest.fixture |
| 30 |
def boot_connection_mock(mocker, redfish_response_mock): |
| 31 |
idrac_conn_mock = mocker.patch(MODULE_PATH + 'idrac_boot.iDRACRedfishAPI') |
| 32 |
idrac_conn_mock_obj = idrac_conn_mock.return_value.__enter__.return_value |
| 33 |
idrac_conn_mock_obj.invoke_request.return_value = redfish_response_mock |
| 34 |
return idrac_conn_mock_obj |
| 35 |
|
| 36 |
|
| 37 |
class TestConfigBios(FakeAnsibleModule): |
| 38 |
|
| 39 |
module = idrac_boot |
| 40 |
|
| 41 |
def test_get_response_attributes(self, boot_connection_mock, redfish_response_mock, idrac_default_args): |
| 42 |
idrac_default_args.update({"boot_options": {"display_name": "Boot001", "enabled": True}}) |
| 43 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 44 |
redfish_response_mock.success = True |
| 45 |
redfish_response_mock.json_data = {"Boot": { |
| 46 |
"BootOptions": "", "Certificates": "", "BootOrder": [], "[email protected]": 1, |
| 47 |
"BootSourceOverrideEnabled": "Disabled", "BootSourceOverrideMode": "Legacy", |
| 48 |
"BootSourceOverrideTarget": "None", "UefiTargetBootSourceOverride": None, |
| 49 |
"[email protected]": []}, |
| 50 |
"Actions": {"#ComputerSystem.Reset": {"[email protected]": ["ForceRestart"]}}} |
| 51 |
result = self.module.get_response_attributes(f_module, boot_connection_mock, "System.Embedded.1") |
| 52 |
assert result["BootSourceOverrideEnabled"] == "Disabled" |
| 53 |
|
| 54 |
redfish_response_mock.json_data.pop("Actions") |
| 55 |
result = self.module.get_response_attributes(f_module, boot_connection_mock, "System.Embedded.1") |
| 56 |
assert result["BootSourceOverrideEnabled"] == "Disabled" |
| 57 |
|
| 58 |
redfish_response_mock.json_data["Boot"].pop("BootOptions", None) |
| 59 |
with pytest.raises(Exception) as err: |
| 60 |
self.module.get_response_attributes(f_module, boot_connection_mock, "System.Embedded.1") |
| 61 |
assert err.value.args[0] == "The system does not support the BootOptions feature." |
| 62 |
|
| 63 |
def test_get_existing_boot_options(self, boot_connection_mock, redfish_response_mock, idrac_default_args): |
| 64 |
redfish_response_mock.success = True |
| 65 |
redfish_response_mock.json_data = {"Members": [ |
| 66 |
{"@odata.context": "/redfish/v1/$metadata#BootOption.BootOption", |
| 67 |
"@odata.id": "/redfish/v1/Systems/System.Embedded.1/BootOptions/HardDisk.List.1-1", |
| 68 |
"@odata.type": "#BootOption.v1_0_4.BootOption", "BootOptionEnabled": True, |
| 69 |
"BootOptionReference": "HardDisk.List.1-1", |
| 70 |
"Description": "Current settings of the Legacy Boot option", |
| 71 |
"DisplayName": "Hard drive C:", "Id": "HardDisk.List.1-1", "Name": "Legacy Boot option"}]} |
| 72 |
resp_data = {'Members': [{ |
| 73 |
'BootOptionEnabled': True, 'BootOptionReference': 'HardDisk.List.1-1', |
| 74 |
'Description': 'Current settings of the Legacy Boot option', |
| 75 |
'DisplayName': 'Hard drive C:', 'Id': 'HardDisk.List.1-1', |
| 76 |
'Name': 'Legacy Boot option'}]} |
| 77 |
result = self.module.get_existing_boot_options(boot_connection_mock, "System.Embedded.1") |
| 78 |
assert result == resp_data |
| 79 |
|
| 80 |
@pytest.mark.parametrize("code", [200, 204]) |
| 81 |
def test_system_reset(self, boot_connection_mock, redfish_response_mock, idrac_default_args, mocker, code): |
| 82 |
mocker.patch(MODULE_UTIL_PATH + 'time.sleep', return_value=None) |
| 83 |
redfish_response_mock.status_code = code |
| 84 |
idrac_default_args.update({"boot_source_override_mode": "uefi", "reset_type": "force_restart"}) |
| 85 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 86 |
reset, track_failed, reset_msg, resp_data = self.module.system_reset(f_module, boot_connection_mock, |
| 87 |
"System.Embedded.1") |
| 88 |
assert reset is True |
| 89 |
|
| 90 |
def test_get_scheduled_job(self, boot_connection_mock, redfish_response_mock, idrac_default_args, mocker): |
| 91 |
mocker.patch(MODULE_PATH + 'idrac_boot.time', return_value=None) |
| 92 |
redfish_response_mock.success = True |
| 93 |
redfish_response_mock.json_data = {"Members": [{ |
| 94 |
"Description": "Job Instance", "EndTime": "TIME_NA", "Id": "JID_609237056489", "JobState": "Scheduled", |
| 95 |
"JobType": "BIOSConfiguration", "Message": "Job scheduled successfully.", "MessageArgs": [], |
| 96 |
"MessageId": "PR19", "Name": "Configure: BIOS.Setup.1-1", "PercentComplete": 10}]} |
| 97 |
status, job = self.module.get_scheduled_job(boot_connection_mock) |
| 98 |
assert status is True |
| 99 |
|
| 100 |
def test_get_scheduled_job_job_state_not_none(self, boot_connection_mock, redfish_response_mock, idrac_default_args, mocker): |
| 101 |
mocker.patch(MODULE_PATH + 'idrac_boot.time', return_value=None) |
| 102 |
redfish_response_mock.success = True |
| 103 |
redfish_response_mock.json_data = {"Members": []} |
| 104 |
is_job, progress_job = self.module.get_scheduled_job(boot_connection_mock, ["Scheduled", "New", "Running"]) |
| 105 |
print(progress_job) |
| 106 |
assert is_job is False |
| 107 |
|
| 108 |
def test_get_scheduled_job_progress_job_none(self, boot_connection_mock, redfish_response_mock, idrac_default_args, mocker): |
| 109 |
mocker.patch(MODULE_PATH + 'idrac_boot.time', return_value=None) |
| 110 |
redfish_response_mock.success = True |
| 111 |
redfish_response_mock.json_data = {"Members": [{ |
| 112 |
"Description": "Job Instance", "EndTime": "TIME_NA", "Id": "JID_609237056489", "JobState": "Completed", |
| 113 |
"JobType": "BIOSConfiguration", "Message": "Job scheduled successfully.", "MessageArgs": [], |
| 114 |
"MessageId": "PR19", "Name": "Configure: BIOS.Setup.1-1", "PercentComplete": 10}]} |
| 115 |
status, job = self.module.get_scheduled_job(boot_connection_mock) |
| 116 |
assert status is False |
| 117 |
|
| 118 |
def test_configure_boot_options(self, boot_connection_mock, redfish_response_mock, idrac_default_args, mocker): |
| 119 |
idrac_default_args.update({"boot_source_override_mode": "uefi", "job_wait": True, "reset_type": "none", |
| 120 |
"job_wait_timeout": 900}) |
| 121 |
obj = MagicMock() |
| 122 |
obj.json_data = {"JobState": "Reset Successful"} |
| 123 |
|
| 124 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 125 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_scheduled_job', return_value=(True, {})) |
| 126 |
resp_data = {"BootOrder": ["Boot001", "Boot002", "Boot003"], "BootSourceOverrideEnabled": "Disabled", |
| 127 |
"BootSourceOverrideMode": "Legacy", "BootSourceOverrideTarget": "UefiTarget", |
| 128 |
"UefiTargetBootSourceOverride": "/0x31/0x33/0x01/0x01"} |
| 129 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_response_attributes', return_value=resp_data) |
| 130 |
with pytest.raises(Exception) as err: |
| 131 |
self.module.configure_boot_options(f_module, boot_connection_mock, "System.Embedded.1", {"Boot001": False}) |
| 132 |
assert err.value.args[0] == "Unable to complete the request because the BIOS configuration job already " \ |
| 133 |
"exists. Wait for the pending job to complete." |
| 134 |
redfish_response_mock.status_code = 202 |
| 135 |
redfish_response_mock.success = True |
| 136 |
redfish_response_mock.headers = {"Location": "/redfish/v1/Managers/iDRAC.Embedded.1/JID_123456789"} |
| 137 |
redfish_response_mock.json_data = {"Attributes": {"BootSeq": [{"Name": "Boot001", "Id": 0, "Enabled": True}, |
| 138 |
{"Name": "Boot000", "Id": 1, "Enabled": True}]}} |
| 139 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_scheduled_job', return_value=(False, {})) |
| 140 |
mocker.patch(MODULE_PATH + 'idrac_boot.idrac_system_reset', return_value=(False, False, "Completed", {})) |
| 141 |
mocker.patch(MODULE_PATH + 'idrac_boot.wait_for_idrac_job_completion', |
| 142 |
return_value=({}, "This job is not complete after 900 seconds.")) |
| 143 |
with pytest.raises(Exception) as err: |
| 144 |
self.module.configure_boot_options(f_module, boot_connection_mock, "System.Embedded.1", {"Boot001": False}) |
| 145 |
assert err.value.args[0] == "This job is not complete after 900 seconds." |
| 146 |
resp_data = {"BootOrder": ["Boot001", "Boot002", "Boot003"], "BootSourceOverrideEnabled": "Disabled", |
| 147 |
"BootSourceOverrideMode": "UEFI", "BootSourceOverrideTarget": "UefiTarget", |
| 148 |
"UefiTargetBootSourceOverride": "/0x31/0x33/0x01/0x01"} |
| 149 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_response_attributes', return_value=resp_data) |
| 150 |
idrac_default_args.update({"boot_source_override_mode": "legacy", "reset_type": "force_restart"}) |
| 151 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 152 |
redfish_response_mock.json_data = {"Attributes": {"UefiBootSeq": [ |
| 153 |
{"Name": "Boot001", "Id": 0, "Enabled": True}, {"Name": "Boot000", "Id": 1, "Enabled": True}]}} |
| 154 |
with pytest.raises(Exception) as err: |
| 155 |
self.module.configure_boot_options(f_module, boot_connection_mock, "System.Embedded.1", {"Boot001": False}) |
| 156 |
assert err.value.args[0] == "This job is not complete after 900 seconds." |
| 157 |
|
| 158 |
mocker.patch(MODULE_PATH + 'idrac_boot.system_reset', return_value=(False, False, "Completed Reset", None)) |
| 159 |
with pytest.raises(Exception) as err: |
| 160 |
self.module.configure_boot_options(f_module, boot_connection_mock, "System.Embedded.1", {"Boot001": False}) |
| 161 |
assert err.value.args[0] == "Completed Reset" |
| 162 |
|
| 163 |
redfish_response_mock.status_code = 201 |
| 164 |
redfish_response_mock.success = True |
| 165 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_scheduled_job', return_value=(False, {})) |
| 166 |
job_data = self.module.configure_boot_options(f_module, boot_connection_mock, "System.Embedded.1", {"Boot001": False}) |
| 167 |
assert job_data == {} |
| 168 |
|
| 169 |
def test_configure_boot_options_v2(self, boot_connection_mock, redfish_response_mock, idrac_default_args, mocker): |
| 170 |
idrac_default_args.update({"boot_source_override_mode": "uefi", "job_wait": True, "reset_type": "none", |
| 171 |
"job_wait_timeout": 900}) |
| 172 |
obj = MagicMock() |
| 173 |
obj.json_data = {"JobState": "Reset Successful"} |
| 174 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_scheduled_job', return_value=(True, {})) |
| 175 |
resp_data = {"BootOrder": ["Boot001", "Boot002", "Boot003"], "BootSourceOverrideEnabled": "Disabled", |
| 176 |
"BootSourceOverrideMode": "Legacy", "BootSourceOverrideTarget": "UefiTarget", |
| 177 |
"UefiTargetBootSourceOverride": "/0x31/0x33/0x01/0x01"} |
| 178 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_response_attributes', return_value=resp_data) |
| 179 |
redfish_response_mock.status_code = 202 |
| 180 |
redfish_response_mock.success = True |
| 181 |
redfish_response_mock.headers = {"Location": "/redfish/v1/Managers/iDRAC.Embedded.1/JID_123456789"} |
| 182 |
redfish_response_mock.json_data = {"Attributes": {"BootSeq": [{"Name": "Boot001", "Id": 0, "Enabled": True}, |
| 183 |
{"Name": "Boot000", "Id": 1, "Enabled": True}]}} |
| 184 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_scheduled_job', return_value=(False, {})) |
| 185 |
mocker.patch(MODULE_PATH + 'idrac_boot.system_reset', return_value=(True, False, "Completed", obj)) |
| 186 |
mocker.patch(MODULE_PATH + 'idrac_boot.wait_for_idrac_job_completion', |
| 187 |
return_value=(obj, "")) |
| 188 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 189 |
job_data = self.module.configure_boot_options(f_module, boot_connection_mock, "System.Embedded.1", {"Boot001": False}) |
| 190 |
assert job_data == {"JobState": "Reset Successful"} |
| 191 |
|
| 192 |
def test_apply_boot_settings(self, boot_connection_mock, redfish_response_mock, idrac_default_args, mocker): |
| 193 |
idrac_default_args.update({"boot_source_override_mode": "uefi", "job_wait": True, "reset_type": "none", |
| 194 |
"job_wait_timeout": 900}) |
| 195 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 196 |
payload = {"Boot": {"BootSourceOverrideMode": "UEFI"}} |
| 197 |
redfish_response_mock.success = True |
| 198 |
redfish_response_mock.status_code = 200 |
| 199 |
mocker.patch(MODULE_PATH + 'idrac_boot.idrac_system_reset', return_value=(False, False, "Completed", {})) |
| 200 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_scheduled_job', return_value=(True, [{"Id": "JID_123456789"}])) |
| 201 |
mocker.patch(MODULE_PATH + 'idrac_boot.wait_for_idrac_job_completion', |
| 202 |
return_value=({}, "This job is not complete after 900 seconds.")) |
| 203 |
with pytest.raises(Exception) as err: |
| 204 |
self.module.apply_boot_settings(f_module, boot_connection_mock, payload, "System.Embedded.1", 16) |
| 205 |
assert err.value.args[0] == "This job is not complete after 900 seconds." |
| 206 |
|
| 207 |
redfish_response_mock.status_code = 400 |
| 208 |
job_data = self.module.apply_boot_settings(f_module, boot_connection_mock, payload, "System.Embedded.1", 17) |
| 209 |
assert job_data == {} |
| 210 |
|
| 211 |
def test_apply_boot_settings_reset_type(self, boot_connection_mock, redfish_response_mock, idrac_default_args, mocker): |
| 212 |
idrac_default_args.update({"boot_source_override_mode": "uefi", "job_wait": True, "reset_type": "graceful_restart", |
| 213 |
"job_wait_timeout": 900}) |
| 214 |
boot_connection_mock.get_server_generation = (17, 'abc', 'iDRAC 10') |
| 215 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 216 |
payload = {"Boot": {"BootSourceOverrideMode": "UEFI"}} |
| 217 |
redfish_response_mock.success = True |
| 218 |
redfish_response_mock.status_code = 200 |
| 219 |
|
| 220 |
obj = MagicMock() |
| 221 |
obj.json_data = {"JobState": "Reset Successful"} |
| 222 |
mocker.patch(MODULE_PATH + 'idrac_boot.system_reset', return_value=(False, False, "Completed", obj)) |
| 223 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_scheduled_job', return_value=(False, [{"Id": "JID_123456789"}])) |
| 224 |
job_data = self.module.apply_boot_settings(f_module, boot_connection_mock, payload, "System.Embedded.1", 17) |
| 225 |
assert job_data == {"JobState": "Reset Successful"} |
| 226 |
|
| 227 |
mocker.patch(MODULE_PATH + 'idrac_boot.system_reset', return_value=(True, False, "Completed", {})) |
| 228 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_scheduled_job', return_value=(True, [{"Id": "JID_123456789"}])) |
| 229 |
mocker.patch(MODULE_PATH + 'idrac_boot.wait_for_idrac_job_completion', |
| 230 |
return_value=(obj, "")) |
| 231 |
job_data = self.module.apply_boot_settings(f_module, boot_connection_mock, payload, "System.Embedded.1", 16) |
| 232 |
assert job_data == {"JobState": "Reset Successful"} |
| 233 |
|
| 234 |
def test_configure_boot_settings(self, boot_connection_mock, redfish_response_mock, idrac_default_args, mocker): |
| 235 |
idrac_default_args.update({"boot_order": ["Boot005", "Boot001"], "job_wait": True, "reset_type": "none", |
| 236 |
"job_wait_timeout": 900, "boot_source_override_mode": "uefi", |
| 237 |
"boot_source_override_enabled": "once", "boot_source_override_target": "cd", |
| 238 |
"uefi_target_boot_source_override": "test_uefi_path"}) |
| 239 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 240 |
resp_data = {"BootOrder": ["Boot001", "Boot002", "Boot003"], "BootSourceOverrideEnabled": "Disabled", |
| 241 |
"BootSourceOverrideMode": "Legacy", "BootSourceOverrideTarget": "UefiTarget", |
| 242 |
"UefiTargetBootSourceOverride": "/0x31/0x33/0x01/0x01"} |
| 243 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_response_attributes', return_value=resp_data) |
| 244 |
boot_connection_mock.get_server_generation = (16, 'abc', 'iDRAC 9') |
| 245 |
with pytest.raises(Exception) as err: |
| 246 |
self.module.configure_boot_settings(f_module, boot_connection_mock, "System.Embedded.1") |
| 247 |
assert err.value.args[0] == "Invalid boot order reference provided." |
| 248 |
idrac_default_args.update({"boot_order": ["Boot001", "Boot001"]}) |
| 249 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 250 |
with pytest.raises(Exception) as err: |
| 251 |
self.module.configure_boot_settings(f_module, boot_connection_mock, "System.Embedded.1") |
| 252 |
assert err.value.args[0] == "Duplicate boot order reference provided." |
| 253 |
mocker.patch(MODULE_PATH + 'idrac_boot.apply_boot_settings', return_value={"JobStatus": "Completed"}) |
| 254 |
idrac_default_args.update({"boot_order": ["Boot001", "Boot003", "Boot002"]}) |
| 255 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 256 |
result = self.module.configure_boot_settings(f_module, boot_connection_mock, "System.Embedded.1") |
| 257 |
assert result["JobStatus"] == "Completed" |
| 258 |
f_module.check_mode = True |
| 259 |
with pytest.raises(Exception) as err: |
| 260 |
self.module.configure_boot_settings(f_module, boot_connection_mock, "System.Embedded.1") |
| 261 |
assert err.value.args[0] == "Changes found to be applied." |
| 262 |
|
| 263 |
def test_configure_boot_settings_v2(self, boot_connection_mock, redfish_response_mock, idrac_default_args, mocker): |
| 264 |
idrac_default_args.update({"boot_order": ["Boot001", "Boot002", "Boot003"], "job_wait": True, "reset_type": "none", |
| 265 |
"job_wait_timeout": 900, "boot_source_override_mode": "uefi", |
| 266 |
"boot_source_override_enabled": "once", "boot_source_override_target": "cd", |
| 267 |
"uefi_target_boot_source_override": "test_uefi_path"}) |
| 268 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 269 |
resp_data = {"BootSourceOverrideEnabled": "Disabled", |
| 270 |
"BootSourceOverrideMode": "Legacy", "BootSourceOverrideTarget": "UefiTarget", |
| 271 |
"UefiTargetBootSourceOverride": "/0x31/0x33/0x01/0x01", "BootOrder": ["Boot001", "Boot002", "Boot003"]} |
| 272 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_response_attributes', return_value=resp_data) |
| 273 |
mocker.patch(MODULE_PATH + 'idrac_boot.apply_boot_settings', return_value={"JobStatus": "Completed"}) |
| 274 |
|
| 275 |
boot_connection_mock.get_server_generation = (16, 'abc', 'iDRAC 9') |
| 276 |
job_resp = self.module.configure_boot_settings(f_module, boot_connection_mock, "System.Embedded.1") |
| 277 |
assert job_resp["JobStatus"] == "Completed" |
| 278 |
|
| 279 |
idrac_default_args.update({"boot_order": []}) |
| 280 |
with pytest.raises(Exception) as err: |
| 281 |
self.module.configure_boot_settings(f_module, boot_connection_mock, "System.Embedded.1") |
| 282 |
assert err.value.args[0] == "Unable to complete the operation because all boot devices are required for this operation." |
| 283 |
|
| 284 |
idrac_default_args.pop("boot_order") |
| 285 |
idrac_default_args.pop("boot_source_override_mode") |
| 286 |
idrac_default_args.pop("boot_source_override_enabled") |
| 287 |
job_resp = self.module.configure_boot_settings(f_module, boot_connection_mock, "System.Embedded.1") |
| 288 |
assert job_resp["JobStatus"] == "Completed" |
| 289 |
|
| 290 |
idrac_default_args.update({"boot_source_override_target": "uefi_target"}) |
| 291 |
resp_data.update({"BootSourceOverrideTarget": "cd"}) |
| 292 |
job_resp = self.module.configure_boot_settings(f_module, boot_connection_mock, "System.Embedded.1") |
| 293 |
assert job_resp["JobStatus"] == "Completed" |
| 294 |
|
| 295 |
def test_configure_idrac_boot(self, boot_connection_mock, redfish_response_mock, idrac_default_args, mocker): |
| 296 |
idrac_default_args.update({"job_wait": True, "reset_type": "none", "job_wait_timeout": 900, |
| 297 |
"boot_options": [{"boot_option_reference": "HardDisk.List.1-1", "enabled": True}]}) |
| 298 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 299 |
boot_return_data = {"Members": [{"BootOptionEnabled": False, "BootOptionReference": "HardDisk.List.1-1", |
| 300 |
"Description": "Current settings of the Legacy Boot option", |
| 301 |
"DisplayName": "Hard drive C:", "Id": "HardDisk.List.1-1", |
| 302 |
"Name": "Legacy Boot option", "UefiDevicePath": "VenHw(D6C0639F-823DE6)"}], |
| 303 |
"Name": "Boot Options Collection", "Description": "Collection of BootOptions"} |
| 304 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_existing_boot_options', return_value=boot_return_data) |
| 305 |
mocker.patch(MODULE_PATH + 'idrac_boot.configure_boot_options', return_value={"JobType": "Completed"}) |
| 306 |
mocker.patch(MODULE_PATH + 'idrac_boot.configure_boot_settings', return_value={"JobType": "Completed"}) |
| 307 |
result = self.module.configure_idrac_boot(f_module, boot_connection_mock, "System.Embedded.1") |
| 308 |
assert result["JobType"] == "Completed" |
| 309 |
idrac_default_args.update({"boot_options": [{"boot_option_reference": "HardDisk.List.1-2", "enabled": True}]}) |
| 310 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 311 |
with pytest.raises(Exception) as err: |
| 312 |
self.module.configure_idrac_boot(f_module, boot_connection_mock, "System.Embedded.1") |
| 313 |
assert err.value.args[0] == "Invalid boot_options provided." |
| 314 |
idrac_default_args.update({"boot_options": [{"boot_option_reference": "HardDisk.List.1-1", "enabled": True}, |
| 315 |
{"boot_option_reference": "HardDisk.List.1-1", "enabled": True}]}) |
| 316 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 317 |
with pytest.raises(Exception) as err: |
| 318 |
self.module.configure_idrac_boot(f_module, boot_connection_mock, "System.Embedded.1") |
| 319 |
assert err.value.args[0] == "Duplicate boot_options provided." |
| 320 |
idrac_default_args.update({"boot_options": [{"boot_option_reference": "HardDisk.List.1-1", "enabled": False}]}) |
| 321 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 322 |
f_module.check_mode = True |
| 323 |
with pytest.raises(Exception) as err: |
| 324 |
self.module.configure_idrac_boot(f_module, boot_connection_mock, "System.Embedded.1") |
| 325 |
assert err.value.args[0] == "No changes found to be applied." |
| 326 |
idrac_default_args.update({"boot_options": [{"boot_option_reference": "HardDisk.List.1-1", "enabled": True}]}) |
| 327 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 328 |
f_module.check_mode = True |
| 329 |
with pytest.raises(Exception) as err: |
| 330 |
self.module.configure_idrac_boot(f_module, boot_connection_mock, "System.Embedded.1") |
| 331 |
assert err.value.args[0] == "Changes found to be applied." |
| 332 |
|
| 333 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 334 |
idrac_default_args.pop("boot_options") |
| 335 |
job_resp = self.module.configure_idrac_boot(f_module, boot_connection_mock, "System.Embedded.1") |
| 336 |
assert job_resp == {"JobType": "Completed"} |
| 337 |
|
| 338 |
@pytest.mark.parametrize("exc_type", [HTTPError, RuntimeError, URLError, SSLValidationError, ConnectionError, KeyError, |
| 339 |
ImportError, ValueError, TypeError]) |
| 340 |
def test_main_exception(self, boot_connection_mock, redfish_response_mock, idrac_default_args, mocker, exc_type): |
| 341 |
idrac_default_args.update({"boot_source_override_mode": "legacy"}) |
| 342 |
json_str = to_text(json.dumps({"data": "out"})) |
| 343 |
if exc_type not in [HTTPError, SSLValidationError]: |
| 344 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_system_res_id', side_effect=exc_type('test')) |
| 345 |
else: |
| 346 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_system_res_id', |
| 347 |
side_effect=exc_type('https://testhost.com', 401, 'http error message', |
| 348 |
{"accept-type": "application/json"}, StringIO(json_str))) |
| 349 |
if exc_type != URLError: |
| 350 |
result = self._run_module_with_fail_json(idrac_default_args) |
| 351 |
assert result['failed'] is True |
| 352 |
else: |
| 353 |
result = self._run_module(idrac_default_args) |
| 354 |
assert 'msg' in result |
| 355 |
|
| 356 |
def test_main_success(self, boot_connection_mock, redfish_response_mock, idrac_default_args, mocker): |
| 357 |
idrac_default_args.update({"boot_source_override_mode": "legacy"}) |
| 358 |
redfish_response_mock.success = True |
| 359 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_system_res_id', return_value=("System.Embedded.1", "")) |
| 360 |
job_resp = {"Description": "Job Instance", "EndTime": "TIME_NA", "Id": "JID_609237056489", |
| 361 |
"JobState": "Completed", "JobType": "BIOSConfiguration", "MessageId": "PR19", |
| 362 |
"Message": "Job scheduled successfully.", "MessageArgs": [], |
| 363 |
"Name": "Configure: BIOS.Setup.1-1", "PercentComplete": 100} |
| 364 |
mocker.patch(MODULE_PATH + 'idrac_boot.configure_idrac_boot', return_value=job_resp) |
| 365 |
boot_return_data = {"Members": [{"BootOptionEnabled": False, "BootOptionReference": "HardDisk.List.1-1", |
| 366 |
"Description": "Current settings of the Legacy Boot option", |
| 367 |
"DisplayName": "Hard drive C:", "Id": "HardDisk.List.1-1", |
| 368 |
"Name": "Legacy Boot option", "UefiDevicePath": "VenHw(D6C0639F-823DE6)"}], |
| 369 |
"Name": "Boot Options Collection", "Description": "Collection of BootOptions"} |
| 370 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_existing_boot_options', return_value=boot_return_data) |
| 371 |
resp_data = {"BootOrder": ["Boot001", "Boot002", "Boot003"], "BootSourceOverrideEnabled": "Disabled", |
| 372 |
"BootSourceOverrideMode": "Legacy", "BootSourceOverrideTarget": "UefiTarget", |
| 373 |
"UefiTargetBootSourceOverride": "/0x31/0x33/0x01/0x01"} |
| 374 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_response_attributes', return_value=resp_data) |
| 375 |
result = self._run_module(idrac_default_args) |
| 376 |
assert result["msg"] == "Successfully updated the boot settings." |
| 377 |
|
| 378 |
def test_main_res_id_error(self, boot_connection_mock, redfish_response_mock, idrac_default_args, mocker): |
| 379 |
idrac_default_args.update({"boot_source_override_mode": "legacy"}) |
| 380 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_system_res_id', return_value=("System.Embedded.5", "Failed")) |
| 381 |
with pytest.raises(Exception) as err: |
| 382 |
self._run_module(idrac_default_args) |
| 383 |
assert err.value.args[0]["msg"] == "Failed" |
| 384 |
|
| 385 |
def test_manin_success_v2(self, boot_connection_mock, redfish_response_mock, idrac_default_args, mocker): |
| 386 |
idrac_default_args.update({"boot_source_override_mode": "legacy", "resource_id": "System.Embedded.1"}) |
| 387 |
redfish_response_mock.success = True |
| 388 |
job_resp = {"Description": "Job Instance", "EndTime": "TIME_NA", "Id": "JID_609237056489", |
| 389 |
"JobState": "Failed", "JobType": "BIOSConfiguration", "MessageId": "PR19", |
| 390 |
"Message": "Job scheduled successfully.", "MessageArgs": [], |
| 391 |
"Name": "Configure: BIOS.Setup.1-1", "PercentComplete": 100} |
| 392 |
mocker.patch(MODULE_PATH + 'idrac_boot.configure_idrac_boot', return_value=job_resp) |
| 393 |
boot_return_data = {"Members": [{"BootOptionEnabled": False, "BootOptionReference": "HardDisk.List.1-1", |
| 394 |
"Description": "Current settings of the Legacy Boot option", |
| 395 |
"DisplayName": "Hard drive C:", "Id": "HardDisk.List.1-1", |
| 396 |
"Name": "Legacy Boot option", "UefiDevicePath": "VenHw(D6C0639F-823DE6)"}], |
| 397 |
"Name": "Boot Options Collection", "Description": "Collection of BootOptions"} |
| 398 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_existing_boot_options', return_value=boot_return_data) |
| 399 |
resp_data = {"BootOrder": ["Boot001", "Boot002", "Boot003"], "BootSourceOverrideEnabled": "Disabled", |
| 400 |
"BootSourceOverrideMode": "Legacy", "BootSourceOverrideTarget": "UefiTarget", |
| 401 |
"UefiTargetBootSourceOverride": "/0x31/0x33/0x01/0x01"} |
| 402 |
mocker.patch(MODULE_PATH + 'idrac_boot.get_response_attributes', return_value=resp_data) |
| 403 |
mocker.patch(MODULE_PATH + 'idrac_boot.strip_substr_dict', return_value=job_resp) |
| 404 |
with pytest.raises(Exception) as err: |
| 405 |
self._run_module(idrac_default_args) |
| 406 |
assert err.value.args[0]["msg"] == "Failed to update the boot settings." |
| 407 |
|
| 408 |
idrac_default_args.update({"job_wait": False, "reset_type": "none"}) |
| 409 |
job_resp.update({"JobState": "Running"}) |
| 410 |
|
| 411 |
module_return = self._run_module(idrac_default_args) |
| 412 |
assert module_return["msg"] == "The boot settings operation is triggered/submitted successfully." |