| 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 json |
| 16 |
from io import StringIO |
| 17 |
|
| 18 |
import pytest |
| 19 |
from ansible.module_utils._text import to_text |
| 20 |
from ansible.module_utils.six.moves.urllib.error import HTTPError, URLError |
| 21 |
from ansible_collections.dellemc.openmanage.plugins.modules import idrac_attributes |
| 22 |
from ansible_collections.dellemc.openmanage.tests.unit.plugins.modules.common import FakeAnsibleModule |
| 23 |
from unittest.mock import MagicMock |
| 24 |
|
| 25 |
SUCCESS_MSG = "Successfully updated the attributes." |
| 26 |
NO_CHANGES_MSG = "No changes found to be applied." |
| 27 |
CHANGES_MSG = "Changes found to be applied." |
| 28 |
SYSTEM_ID = "System.Embedded.1" |
| 29 |
MANAGER_ID = "iDRAC.Embedded.1" |
| 30 |
LC_ID = "LifecycleController.Embedded.1" |
| 31 |
IDRAC_URI = "/redfish/v1/Managers/{res_id}/Oem/Dell/DellAttributes/{attr_id}" |
| 32 |
MANAGERS_URI = "/redfish/v1/Managers" |
| 33 |
MODULE_PATH = 'ansible_collections.dellemc.openmanage.plugins.modules.idrac_attributes.' |
| 34 |
UTILS_PATH = 'ansible_collections.dellemc.openmanage.plugins.module_utils.utils.' |
| 35 |
SNMP_ADDRESS = "SNMP.1.IPAddress" |
| 36 |
|
| 37 |
|
| 38 |
@pytest.fixture |
| 39 |
def idrac_redfish_mock_for_attr(mocker, redfish_response_mock): |
| 40 |
connection_class_mock = mocker.patch(MODULE_PATH + 'iDRACRedfishAPI') |
| 41 |
idrac_connection_mock_obj = connection_class_mock.return_value.__enter__.return_value |
| 42 |
idrac_connection_mock_obj.invoke_request.return_value = redfish_response_mock |
| 43 |
return idrac_connection_mock_obj |
| 44 |
|
| 45 |
|
| 46 |
class TestIdracAttributes(FakeAnsibleModule): |
| 47 |
module = idrac_attributes |
| 48 |
|
| 49 |
@pytest.mark.parametrize("params", [{"id": "iDRAC.Embedded.1", "attr": {'SNMP.1.AgentCommunity': 'Disabled'}, |
| 50 |
"uri_dict": |
| 51 |
{"iDRAC.Embedded.1": "/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/DellAttributes/iDRAC.Embedded.1", |
| 52 |
"System.Embedded.1": "/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/DellAttributes/System.Embedded.1", |
| 53 |
"LifecycleController.Embedded.1": |
| 54 |
"/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/DellAttributes/LifecycleController.Embedded.1"}, |
| 55 |
"response_attr": {"SNMP.1.AgentCommunity": "Disabled"}}]) |
| 56 |
def test_get_response_attr(self, params, idrac_redfish_mock_for_attr, ome_response_mock): |
| 57 |
ome_response_mock.success = params.get("success", True) |
| 58 |
diff, response_attr = self.module.get_response_attr(idrac_redfish_mock_for_attr, params["id"], params["attr"], params["uri_dict"]) |
| 59 |
assert response_attr.keys() == params["response_attr"].keys() |
| 60 |
|
| 61 |
@pytest.mark.parametrize("params", [{"res_id": "iDRAC.Embedded.1", "attr": {'SNMP.1.AgentCommunity': 'Disabled'}, |
| 62 |
"uri_dict": { |
| 63 |
"iDRAC.Embedded.1": "/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/DellAttributes/iDRAC.Embedded.1", |
| 64 |
"System.Embedded.1": "/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/DellAttributes/System.Embedded.1", |
| 65 |
"LifecycleController.Embedded.1": |
| 66 |
"/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/DellAttributes/LifecycleController.Embedded.1"}, |
| 67 |
"response_attr": {"SNMP.1.AgentCommunity": "Disabled"}, |
| 68 |
"mparams": {'idrac_attributes': {"SNMP.1.AgentCommunity": "Enabled"} |
| 69 |
}, |
| 70 |
"system_response_attr": {}, |
| 71 |
"lc_response_attr": {}, |
| 72 |
"resp": { |
| 73 |
"iDRAC": { |
| 74 |
"@Message.ExtendedInfo": [ |
| 75 |
{ |
| 76 |
"Message": "The request completed successfully.", |
| 77 |
"MessageArgs": [], |
| 78 |
"[email protected]": 0, |
| 79 |
"MessageId": "Base.1.12.Success", |
| 80 |
"RelatedProperties": [], |
| 81 |
"[email protected]": 0, |
| 82 |
"Resolution": "None", |
| 83 |
"Severity": "OK" |
| 84 |
}, |
| 85 |
{ |
| 86 |
"Message": "The operation successfully completed.", |
| 87 |
"MessageArgs": [], |
| 88 |
"[email protected]": 0, |
| 89 |
"MessageId": "IDRAC.2.7.SYS413", |
| 90 |
"RelatedProperties": [], |
| 91 |
"[email protected]": 0, |
| 92 |
"Resolution": "No response action is required.", |
| 93 |
"Severity": "Informational" |
| 94 |
} |
| 95 |
] |
| 96 |
} |
| 97 |
}}]) |
| 98 |
def test_update_idrac_attributes(self, params, idrac_redfish_mock_for_attr, idrac_default_args): |
| 99 |
idrac_default_args.update(params.get('mparams')) |
| 100 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 101 |
resp = self.module.update_idrac_attributes(idrac_redfish_mock_for_attr, f_module, params["uri_dict"], |
| 102 |
params["response_attr"], params["system_response_attr"], |
| 103 |
params["lc_response_attr"]) |
| 104 |
assert resp.keys() == params["resp"].keys() |
| 105 |
|
| 106 |
@pytest.mark.parametrize("params", [{"res_id": "iDRAC.Embedded.1", |
| 107 |
"uri_dict": { |
| 108 |
"iDRAC.Embedded.1": "/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/DellAttributes/iDRAC.Embedded.1", |
| 109 |
"System.Embedded.1": "/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/DellAttributes/System.Embedded.1", |
| 110 |
"LifecycleController.Embedded.1": |
| 111 |
"/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/DellAttributes/LifecycleController.Embedded.1"}, |
| 112 |
"system_response_attr": {"ThermalSettings.1.ThermalProfile": "Sound Cap"}, |
| 113 |
"mparams": {'system_attributes': {"ThermalSettings.1.ThermalProfile": "Sound Cap"} |
| 114 |
}, |
| 115 |
"idrac_response_attr": {}, |
| 116 |
"lc_response_attr": {}, |
| 117 |
"resp": { |
| 118 |
"System": { |
| 119 |
"@Message.ExtendedInfo": [ |
| 120 |
{ |
| 121 |
"Message": "The request completed successfully.", |
| 122 |
"MessageArgs": [], |
| 123 |
"[email protected]": 0, |
| 124 |
"MessageId": "Base.1.12.Success", |
| 125 |
"RelatedProperties": [], |
| 126 |
"[email protected]": 0, |
| 127 |
"Resolution": "None", |
| 128 |
"Severity": "OK" |
| 129 |
}, |
| 130 |
{ |
| 131 |
"Message": "The operation successfully completed.", |
| 132 |
"MessageArgs": [], |
| 133 |
"[email protected]": 0, |
| 134 |
"MessageId": "IDRAC.2.7.SYS413", |
| 135 |
"RelatedProperties": [], |
| 136 |
"[email protected]": 0, |
| 137 |
"Resolution": "No response action is required.", |
| 138 |
"Severity": "Informational" |
| 139 |
} |
| 140 |
] |
| 141 |
} |
| 142 |
}}]) |
| 143 |
def test_update_idrac_attributes_case01(self, params, idrac_redfish_mock_for_attr, idrac_default_args): |
| 144 |
idrac_default_args.update(params.get('mparams')) |
| 145 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 146 |
resp = self.module.update_idrac_attributes(idrac_redfish_mock_for_attr, f_module, params["uri_dict"], |
| 147 |
params["idrac_response_attr"], params["system_response_attr"], |
| 148 |
params["lc_response_attr"]) |
| 149 |
assert resp.keys() == params["resp"].keys() |
| 150 |
|
| 151 |
@pytest.mark.parametrize("params", [{"res_id": "iDRAC.Embedded.1", |
| 152 |
"uri_dict": { |
| 153 |
"iDRAC.Embedded.1": "/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/DellAttributes/iDRAC.Embedded.1", |
| 154 |
"System.Embedded.1": "/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/DellAttributes/System.Embedded.1", |
| 155 |
"LifecycleController.Embedded.1": |
| 156 |
"/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/DellAttributes/LifecycleController.Embedded.1"}, |
| 157 |
"lc_response_attr": {"LCAttributes.1.AutoUpdate": "Enabled"}, |
| 158 |
"mparams": { |
| 159 |
'lifecycle_controller_attributes': {"LCAttributes.1.AutoUpdate": "Enabled"} |
| 160 |
}, |
| 161 |
"idrac_response_attr": {}, |
| 162 |
"system_response_attr": {}, |
| 163 |
"resp": { |
| 164 |
"Lifecycle Controller": { |
| 165 |
"@Message.ExtendedInfo": [ |
| 166 |
{ |
| 167 |
"Message": "The request completed successfully.", |
| 168 |
"MessageArgs": [], |
| 169 |
"[email protected]": 0, |
| 170 |
"MessageId": "Base.1.12.Success", |
| 171 |
"RelatedProperties": [], |
| 172 |
"[email protected]": 0, |
| 173 |
"Resolution": "None", |
| 174 |
"Severity": "OK" |
| 175 |
}, |
| 176 |
{ |
| 177 |
"Message": "The operation successfully completed.", |
| 178 |
"MessageArgs": [], |
| 179 |
"[email protected]": 0, |
| 180 |
"MessageId": "IDRAC.2.7.SYS413", |
| 181 |
"RelatedProperties": [], |
| 182 |
"[email protected]": 0, |
| 183 |
"Resolution": "No response action is required.", |
| 184 |
"Severity": "Informational" |
| 185 |
} |
| 186 |
] |
| 187 |
} |
| 188 |
}}]) |
| 189 |
def test_update_idrac_attributes_case02(self, params, idrac_redfish_mock_for_attr, idrac_default_args): |
| 190 |
idrac_default_args.update(params.get('mparams')) |
| 191 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 192 |
resp = self.module.update_idrac_attributes(idrac_redfish_mock_for_attr, f_module, params["uri_dict"], |
| 193 |
params["idrac_response_attr"], params["system_response_attr"], |
| 194 |
params["lc_response_attr"]) |
| 195 |
assert resp.keys() == params["resp"].keys() |
| 196 |
|
| 197 |
@pytest.mark.parametrize("exc_type", [HTTPError, URLError, IOError, ValueError, TypeError, ConnectionError, |
| 198 |
AttributeError, IndexError, KeyError]) |
| 199 |
def test_main_idrac_attributes_exception_handling_case(self, exc_type, idrac_redfish_mock_for_attr, |
| 200 |
idrac_default_args, mocker): |
| 201 |
idrac_default_args.update({'lifecycle_controller_attributes': {"LCAttributes.1.AutoUpdate": "Enabled"}}) |
| 202 |
json_str = to_text(json.dumps({"data": "out"})) |
| 203 |
if exc_type not in [HTTPError]: |
| 204 |
mocker.patch(MODULE_PATH + 'update_idrac_attributes', side_effect=exc_type('test')) |
| 205 |
else: |
| 206 |
mocker.patch(MODULE_PATH + 'update_idrac_attributes', |
| 207 |
side_effect=exc_type('https://testhost.com', 400, 'http error message', |
| 208 |
{"accept-type": "application/json"}, StringIO(json_str))) |
| 209 |
if exc_type != URLError: |
| 210 |
result = self._run_module(idrac_default_args) |
| 211 |
assert result['failed'] is True |
| 212 |
else: |
| 213 |
result = self._run_module(idrac_default_args) |
| 214 |
assert 'msg' in result |
| 215 |
|
| 216 |
def test_xml_data_conversion(self, idrac_redfish_mock_for_attr, idrac_default_args): |
| 217 |
attribute = {"Time.1.Timezone": "CST6CDT", "SNMP.1.SNMPProtocol": "All", |
| 218 |
"LCAttributes.1.AutoUpdate": "Disabled"} |
| 219 |
result = self.module.xml_data_conversion(attribute, "System.Embedded.1") |
| 220 |
assert isinstance(result[0], str) |
| 221 |
assert isinstance(result[1], dict) |
| 222 |
|
| 223 |
def test_validate_attr_name(self, idrac_redfish_mock_for_attr, idrac_default_args): |
| 224 |
attribute = [{"Name": "Time.1.Timezone", "Value": "CST6CDT"}, {"Name": "SNMP.1.SNMPProtocol", "Value": "All"}, |
| 225 |
{"Name": "LCAttributes.1.AutoUpdate", "Value": "Disabled"}] |
| 226 |
req_data = {"Time.1.Timezone": "CST6CDT", "SNMP.1.SNMPProtocol": "All", |
| 227 |
"LCAttributes.1.AutoUpdate": "Disabled"} |
| 228 |
result = self.module.validate_attr_name(attribute, req_data) |
| 229 |
assert result[0] == {'Time.1.Timezone': 'CST6CDT', 'SNMP.1.SNMPProtocol': 'All', |
| 230 |
'LCAttributes.1.AutoUpdate': 'Disabled'} |
| 231 |
assert result[1] == {} |
| 232 |
req_data = {"Time.2.Timezone": "CST6CDT", "SNMP.2.SNMPProtocol": "All"} |
| 233 |
result = self.module.validate_attr_name(attribute, req_data) |
| 234 |
assert result[0] == {} |
| 235 |
assert result[1] == {'Time.2.Timezone': 'Attribute does not exist.', |
| 236 |
'SNMP.2.SNMPProtocol': 'Attribute does not exist.'} |
| 237 |
|
| 238 |
def test_process_check_mode(self, idrac_redfish_mock_for_attr, idrac_default_args): |
| 239 |
idrac_default_args.update({'lifecycle_controller_attributes': {"LCAttributes.1.AutoUpdate": "Enabled"}}) |
| 240 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 241 |
with pytest.raises(Exception) as exc: |
| 242 |
self.module.process_check_mode(f_module, False) |
| 243 |
assert exc.value.args[0] == "No changes found to be applied." |
| 244 |
f_module.check_mode = True |
| 245 |
with pytest.raises(Exception) as exc: |
| 246 |
self.module.process_check_mode(f_module, True) |
| 247 |
assert exc.value.args[0] == "Changes found to be applied." |
| 248 |
|
| 249 |
def test_scp_idrac_attributes(self, idrac_redfish_mock_for_attr, redfish_response_mock, idrac_default_args, mocker): |
| 250 |
idrac_default_args.update({'lifecycle_controller_attributes': {"LCAttributes.1.AutoUpdate": "Enabled"}}) |
| 251 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 252 |
mocker.patch(MODULE_PATH + 'get_check_mode', return_value=None) |
| 253 |
mocker.patch(MODULE_PATH + 'xml_data_conversion', return_value=("<components></components>", |
| 254 |
{"LCAttributes.1.AutoUpdate": "Enabled"})) |
| 255 |
idrac_redfish_mock_for_attr.wait_for_job_completion.return_value = {"JobStatus": "Success"} |
| 256 |
result = self.module.scp_idrac_attributes(f_module, idrac_redfish_mock_for_attr, "LC.Embedded.1") |
| 257 |
assert result["JobStatus"] == "Success" |
| 258 |
idrac_default_args.update({'idrac_attributes': {"User.1.UserName": "username"}}) |
| 259 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 260 |
mocker.patch(MODULE_PATH + 'xml_data_conversion', return_value=("<components></components>", |
| 261 |
{"User.1.UserName": "username"})) |
| 262 |
idrac_redfish_mock_for_attr.wait_for_job_completion.return_value = {"JobStatus": "Success"} |
| 263 |
result = self.module.scp_idrac_attributes(f_module, idrac_redfish_mock_for_attr, MANAGER_ID) |
| 264 |
assert result["JobStatus"] == "Success" |
| 265 |
idrac_default_args.update({'system_attributes': {SNMP_ADDRESS: "XX.XX.XX.XX"}}) |
| 266 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 267 |
mocker.patch(MODULE_PATH + 'xml_data_conversion', return_value=("<components></components>", |
| 268 |
{SNMP_ADDRESS: "XX.XX.XX.XX"})) |
| 269 |
idrac_redfish_mock_for_attr.wait_for_job_completion.return_value = {"JobStatus": "Success"} |
| 270 |
result = self.module.scp_idrac_attributes(f_module, idrac_redfish_mock_for_attr, "System.Embedded.1") |
| 271 |
assert result["JobStatus"] == "Success" |
| 272 |
|
| 273 |
def test_get_check_mode(self, idrac_redfish_mock_for_attr, redfish_response_mock, idrac_default_args, mocker): |
| 274 |
idrac_json = {SNMP_ADDRESS: "XX.XX.XX.XX"} |
| 275 |
idrac_default_args.update({'idrac_attributes': idrac_json}) |
| 276 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 277 |
response_obj = MagicMock() |
| 278 |
idrac_redfish_mock_for_attr.export_scp.return_value = response_obj |
| 279 |
response_obj.json_data = { |
| 280 |
"SystemConfiguration": {"Components": [ |
| 281 |
{"FQDD": MANAGER_ID, "Attributes": {"Name": SNMP_ADDRESS, "Value": "XX.XX.XX.XX"}} |
| 282 |
]}} |
| 283 |
mocker.patch(MODULE_PATH + 'validate_attr_name', return_value=( |
| 284 |
idrac_json, {"SNMP.10.IPAddress": "Attribute does not exists."})) |
| 285 |
with pytest.raises(Exception) as exc: |
| 286 |
self.module.get_check_mode(f_module, idrac_redfish_mock_for_attr, idrac_json, {}, {}) |
| 287 |
assert exc.value.args[0] == "Attributes have invalid values." |
| 288 |
system_json = {"System.1.Attr": "Value"} |
| 289 |
idrac_default_args.update({'system_attributes': system_json}) |
| 290 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 291 |
response_obj.json_data = { |
| 292 |
"SystemConfiguration": {"Components": [ |
| 293 |
{"FQDD": "System.Embedded.1", "Attributes": {"Name": "System.1.Attr", "Value": "Value"}} |
| 294 |
]}} |
| 295 |
mocker.patch(MODULE_PATH + 'validate_attr_name', return_value=( |
| 296 |
system_json, {"System.10.Attr": "Attribute does not exists."})) |
| 297 |
with pytest.raises(Exception) as exc: |
| 298 |
self.module.get_check_mode(f_module, idrac_redfish_mock_for_attr, {}, system_json, {}) |
| 299 |
assert exc.value.args[0] == "Attributes have invalid values." |
| 300 |
lc_json = {"LCAttributes.1.AutoUpdate": "Enabled"} |
| 301 |
idrac_default_args.update({'lifecycle_controller_attributes': lc_json}) |
| 302 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 303 |
response_obj.json_data = { |
| 304 |
"SystemConfiguration": {"Components": [ |
| 305 |
{"FQDD": "LifecycleController.Embedded.1", "Attributes": {"Name": "LCAttributes.1.AutoUpdate", |
| 306 |
"Value": "Enabled"}} |
| 307 |
]}} |
| 308 |
mocker.patch(MODULE_PATH + 'validate_attr_name', return_value=( |
| 309 |
lc_json, {"LCAttributes.10.AutoUpdate": "Attribute does not exists."})) |
| 310 |
with pytest.raises(Exception) as exc: |
| 311 |
self.module.get_check_mode(f_module, idrac_redfish_mock_for_attr, {}, {}, lc_json) |
| 312 |
assert exc.value.args[0] == "Attributes have invalid values." |
| 313 |
lc_json = {"LCAttributes.1.AutoUpdate": "Enabled"} |
| 314 |
idrac_default_args.update({'lifecycle_controller_attributes': lc_json}) |
| 315 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 316 |
f_module.check_mode = True |
| 317 |
mocker.patch(MODULE_PATH + 'validate_attr_name', return_value=(lc_json, None)) |
| 318 |
with pytest.raises(Exception) as exc: |
| 319 |
self.module.get_check_mode(f_module, idrac_redfish_mock_for_attr, {}, {}, lc_json) |
| 320 |
assert exc.value.args[0] == "No changes found to be applied." |
| 321 |
mocker.patch(MODULE_PATH + 'validate_attr_name', return_value=({"LCAttributes.1.AutoUpdate": "Disabled"}, None)) |
| 322 |
with pytest.raises(Exception) as exc: |
| 323 |
self.module.get_check_mode(f_module, idrac_redfish_mock_for_attr, {}, {}, lc_json) |
| 324 |
assert exc.value.args[0] == "Changes found to be applied." |
| 325 |
|
| 326 |
def test_fetch_idrac_uri_attr(self, idrac_redfish_mock_for_attr, redfish_response_mock, idrac_default_args, mocker): |
| 327 |
idrac_json = {SNMP_ADDRESS: "XX.XX.XX.XX"} |
| 328 |
idrac_default_args.update({'idrac_attributes': idrac_json}) |
| 329 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 330 |
response_obj = MagicMock() |
| 331 |
idrac_redfish_mock_for_attr.invoke_request.return_value = response_obj |
| 332 |
response_obj.json_data = {"Links": {"Oem": {"Dell": {"DellAttributes": {}}}}, |
| 333 |
"Message": "None", "MessageId": "SYS069"} |
| 334 |
response_obj.status_code = 200 |
| 335 |
mocker.patch(MODULE_PATH + "scp_idrac_attributes", return_value=response_obj) |
| 336 |
with pytest.raises(Exception) as exc: |
| 337 |
self.module.fetch_idrac_uri_attr(idrac_redfish_mock_for_attr, f_module, MANAGER_ID) |
| 338 |
assert exc.value.args[0] == "No changes found to be applied." |
| 339 |
response_obj.json_data = {"Links": {"Oem": {"Dell": {"DellAttributes": {}}}}, |
| 340 |
"Message": "None", "MessageId": "SYS053"} |
| 341 |
mocker.patch(MODULE_PATH + "scp_idrac_attributes", return_value=response_obj) |
| 342 |
with pytest.raises(Exception) as exc: |
| 343 |
self.module.fetch_idrac_uri_attr(idrac_redfish_mock_for_attr, f_module, MANAGER_ID) |
| 344 |
assert exc.value.args[0] == "Successfully updated the attributes." |
| 345 |
response_obj.json_data = {"Links": {"Oem": {"Dell": {"DellAttributes": {}}}}, |
| 346 |
"Message": "Unable to complete application of configuration profile values.", |
| 347 |
"MessageId": "SYS080"} |
| 348 |
mocker.patch(MODULE_PATH + "scp_idrac_attributes", return_value=response_obj) |
| 349 |
with pytest.raises(Exception) as exc: |
| 350 |
self.module.fetch_idrac_uri_attr(idrac_redfish_mock_for_attr, f_module, MANAGER_ID) |
| 351 |
assert exc.value.args[0] == "Application of some of the attributes failed due to invalid value or enumeration." |
| 352 |
|
| 353 |
response_obj.json_data = {"Links": {"Oem": {"Dell": {"DellAttributes": {}}}}, |
| 354 |
"Message": "Unable to complete the task.", "MessageId": "SYS080"} |
| 355 |
mocker.patch(MODULE_PATH + "scp_idrac_attributes", return_value=response_obj) |
| 356 |
with pytest.raises(Exception) as exc: |
| 357 |
self.module.fetch_idrac_uri_attr(idrac_redfish_mock_for_attr, f_module, MANAGER_ID) |
| 358 |
assert exc.value.args[0] == "Unable to complete the task." |
| 359 |
|
| 360 |
def test_main_success(self, idrac_redfish_mock_for_attr, redfish_response_mock, idrac_default_args, mocker): |
| 361 |
idrac_default_args.update({"resource_id": "System.Embedded.1", "idrac_attributes": {"Attr": "Value"}}) |
| 362 |
mocker.patch(MODULE_PATH + "fetch_idrac_uri_attr", return_value=(None, None, None, None, None)) |
| 363 |
mocker.patch(MODULE_PATH + "process_check_mode", return_value=None) |
| 364 |
mocker.patch(MODULE_PATH + "update_idrac_attributes", return_value=None) |
| 365 |
result = self._run_module(idrac_default_args) |
| 366 |
assert result["changed"] |
| 367 |
assert result["msg"] == "Successfully updated the attributes." |
| 368 |
|
| 369 |
def test_validate_vs_registry(self, idrac_redfish_mock_for_attr, redfish_response_mock, idrac_default_args): |
| 370 |
idrac_default_args.update({"resource_id": "System.Embedded.1", "idrac_attributes": {"Attr": "Value"}}) |
| 371 |
attr_dict = {"attr": "value", "attr1": "value1", "attr2": 3} |
| 372 |
registry = {"attr": {"Readonly": True}, |
| 373 |
"attr1": {"Type": "Enumeration", "Value": [{"ValueDisplayName": "Attr"}]}, |
| 374 |
"attr2": {"Type": "Integer", "LowerBound": 1, "UpperBound": 2}} |
| 375 |
result = self.module.validate_vs_registry(registry, attr_dict) |
| 376 |
assert result["attr"] == "Read only Attribute cannot be modified." |
| 377 |
assert result["attr1"] == "Invalid value for Enumeration." |
| 378 |
assert result["attr2"] == "Integer out of valid range." |
| 379 |
|
| 380 |
def test_fetch_idrac_uri_attr_dell_attr(self, idrac_redfish_mock_for_attr, redfish_response_mock, |
| 381 |
idrac_default_args, mocker): |
| 382 |
idrac_default_args.update({"resource_id": "System.Embedded.1", "idrac_attributes": {"Attr": "Value"}}) |
| 383 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 384 |
mocker.patch(MODULE_PATH + "get_response_attr", return_value=(1, None)) |
| 385 |
mocker.patch(MODULE_PATH + "validate_vs_registry", return_value={"Attr": "Attribute does not exists"}) |
| 386 |
response_obj = MagicMock() |
| 387 |
idrac_redfish_mock_for_attr.invoke_request.return_value = response_obj |
| 388 |
response_obj.json_data = {"Links": {"Oem": {"Dell": { |
| 389 |
"DellAttributes": [ |
| 390 |
{"@odata.id": "/api/services/"} |
| 391 |
] |
| 392 |
}}}} |
| 393 |
with pytest.raises(Exception) as exc: |
| 394 |
self.module.fetch_idrac_uri_attr(idrac_redfish_mock_for_attr, f_module, "System.Embedded.1") |
| 395 |
assert exc.value.args[0] == "Attributes have invalid values." |
| 396 |
|
| 397 |
idrac_default_args.update({"resource_id": "System.Embedded.1", "system_attributes": {"Attr": "Value"}}) |
| 398 |
f_module = self.get_module_mock(params=idrac_default_args) |
| 399 |
mocker.patch(MODULE_PATH + "get_response_attr", return_value=(1, None)) |
| 400 |
mocker.patch(MODULE_PATH + "validate_vs_registry", return_value={"Attr": "Attribute does not exists"}) |
| 401 |
response_obj = MagicMock() |
| 402 |
idrac_redfish_mock_for_attr.invoke_request.return_value = response_obj |
| 403 |
response_obj.json_data = {"Links": {"Oem": {"Dell": { |
| 404 |
"DellAttributes": [ |
| 405 |
{"@odata.id": "/api/services/"} |
| 406 |
] |
| 407 |
}}}} |
| 408 |
with pytest.raises(Exception) as exc: |
| 409 |
self.module.fetch_idrac_uri_attr(idrac_redfish_mock_for_attr, f_module, "System.Embedded.1") |
| 410 |
assert exc.value.args[0] == "Attributes have invalid values." |