| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
from __future__ import (absolute_import, division, print_function) |
| 9 |
|
| 10 |
__metaclass__ = type |
| 11 |
|
| 12 |
import pytest |
| 13 |
from ansible_collections.dellemc.openmanage.plugins.modules import ome_identity_pool |
| 14 |
from ansible_collections.dellemc.openmanage.plugins.modules.ome_identity_pool import mac_to_base64_conversion |
| 15 |
from ansible_collections.dellemc.openmanage.tests.unit.plugins.modules.common import FakeAnsibleModule |
| 16 |
from ansible_collections.dellemc.openmanage.tests.unit.plugins.modules.common import AnsibleFailJSonException |
| 17 |
from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError |
| 18 |
from ansible.module_utils.urls import ConnectionError, SSLValidationError |
| 19 |
from ssl import SSLError |
| 20 |
from io import StringIO |
| 21 |
from ansible.module_utils._text import to_text |
| 22 |
import json |
| 23 |
|
| 24 |
MODULE_PATH = 'ansible_collections.dellemc.openmanage.plugins.modules.' |
| 25 |
|
| 26 |
|
| 27 |
@pytest.fixture |
| 28 |
def ome_connection_mock_for_identity_pool(mocker, ome_response_mock): |
| 29 |
connection_class_mock = mocker.patch( |
| 30 |
MODULE_PATH + 'ome_identity_pool.RestOME') |
| 31 |
ome_connection_mock_obj = connection_class_mock.return_value.__enter__.return_value |
| 32 |
ome_connection_mock_obj.invoke_request.return_value = ome_response_mock |
| 33 |
return ome_connection_mock_obj |
| 34 |
|
| 35 |
|
| 36 |
class TestOMeIdentityPool(FakeAnsibleModule): |
| 37 |
module = ome_identity_pool |
| 38 |
|
| 39 |
def test_main_ome_identity_pool_success_case1(self, mocker, ome_default_args, |
| 40 |
ome_connection_mock_for_identity_pool, ome_response_mock): |
| 41 |
sub_param = {"pool_name": "pool1", |
| 42 |
"pool_description": "Identity pool with ethernet and fcoe settings", |
| 43 |
"ethernet_settings": { |
| 44 |
"starting_mac_address": "50-50-50-50-50-00", |
| 45 |
"identity_count": 60}, |
| 46 |
"fcoe_settings": { |
| 47 |
"starting_mac_address": "70-70-70-70-70-00", |
| 48 |
"identity_count": 75 |
| 49 |
}, |
| 50 |
"iscsi_settings": { |
| 51 |
"identity_count": 30, |
| 52 |
"initiator_config": { |
| 53 |
"iqn_prefix": "iqn.myprefix." |
| 54 |
}, |
| 55 |
"initiator_ip_pool_settings": { |
| 56 |
"gateway": "192.168.4.1", |
| 57 |
"ip_range": "10.33.0.1-10.33.0.255", |
| 58 |
"primary_dns_server": "10.8.8.8", |
| 59 |
"secondary_dns_server": "8.8.8.8", |
| 60 |
"subnet_mask": "XXX.XXX.XXX.XXX" |
| 61 |
}, |
| 62 |
"starting_mac_address": "60:60:60:60:60:00" |
| 63 |
}, |
| 64 |
"fc_settings": { |
| 65 |
"identity_count": 45, |
| 66 |
"starting_address": "10-10-10-10-10-10" |
| 67 |
} |
| 68 |
} |
| 69 |
message_return = {"msg": "Successfully created an identity pool.", |
| 70 |
"result": {"Id": 36, "IsSuccessful": True, "Issues": []}} |
| 71 |
mocker.patch(MODULE_PATH + 'ome_identity_pool.pool_create_modify', |
| 72 |
return_value=message_return) |
| 73 |
ome_default_args.update(sub_param) |
| 74 |
result = self._run_module(ome_default_args) |
| 75 |
assert result['changed'] is True |
| 76 |
assert 'pool_status' in result and "msg" in result |
| 77 |
assert result["msg"] == "Successfully created an identity pool." |
| 78 |
assert result['pool_status'] == { |
| 79 |
"Id": 36, |
| 80 |
"IsSuccessful": True, |
| 81 |
"Issues": [] |
| 82 |
} |
| 83 |
|
| 84 |
@pytest.mark.parametrize("exc_type", |
| 85 |
[IOError, ValueError, SSLError, TypeError, ConnectionError, HTTPError, URLError]) |
| 86 |
def test_main_ome_identity_pool_failure_case1(self, exc_type, mocker, ome_default_args, |
| 87 |
ome_connection_mock_for_identity_pool, ome_response_mock): |
| 88 |
ome_default_args.update({"pool_name": "pool1"}) |
| 89 |
json_str = to_text(json.dumps({"info": "error_details"})) |
| 90 |
if exc_type == URLError: |
| 91 |
mocker.patch(MODULE_PATH + 'ome_identity_pool.pool_create_modify', |
| 92 |
side_effect=exc_type("ansible.module_utils.urls.open_url error")) |
| 93 |
result = self._run_module(ome_default_args) |
| 94 |
assert result["unreachable"] is True |
| 95 |
elif exc_type not in [HTTPError, SSLValidationError]: |
| 96 |
mocker.patch(MODULE_PATH + 'ome_identity_pool.pool_create_modify', |
| 97 |
side_effect=exc_type("exception message")) |
| 98 |
result = self._run_module(ome_default_args) |
| 99 |
assert result['failed'] is True |
| 100 |
else: |
| 101 |
mocker.patch(MODULE_PATH + 'ome_identity_pool.pool_create_modify', |
| 102 |
side_effect=exc_type('https://testhost.com', 400, |
| 103 |
'http error message', |
| 104 |
{"accept-type": "application/json"}, |
| 105 |
StringIO(json_str))) |
| 106 |
result = self._run_module(ome_default_args) |
| 107 |
assert result['failed'] is True |
| 108 |
assert 'pool_status' not in result |
| 109 |
assert 'msg' in result |
| 110 |
|
| 111 |
def test_main_ome_identity_pool_no_mandatory_arg_passed_failure_case(self, ome_default_args): |
| 112 |
result = self._run_module_with_fail_json(ome_default_args) |
| 113 |
assert 'pool_status' not in result |
| 114 |
|
| 115 |
@pytest.mark.parametrize("param", [{"ethernet_settings": {"invalid_key": "value"}}, |
| 116 |
{"fcoe_settings": {"invalid_key": "value"}}, |
| 117 |
{"iscsi_settings": {"invalid_key": "value"}}, |
| 118 |
{"iscsi_settings": {"initiator_config": {"invalid_key": "value"}}}, |
| 119 |
{"iscsi_settings": {"initiator_ip_pool_settings": {"gateway1": "192.168.4.1"}}}, |
| 120 |
{"iscsi_settings": { |
| 121 |
"initiator_ip_pool_settings": {"primary_dns_server": "192.168.4.1", |
| 122 |
"ip_range1": "value"}}}, |
| 123 |
{"fc_settings": {"invalid_key": "value"}}, |
| 124 |
{"name": "name1"}]) |
| 125 |
def test_main_ome_identity_pool_invalid_settings(self, param, ome_default_args, |
| 126 |
ome_connection_mock_for_identity_pool): |
| 127 |
ome_default_args.update(param) |
| 128 |
result = self._run_module_with_fail_json(ome_default_args) |
| 129 |
assert 'pool_status' not in result |
| 130 |
|
| 131 |
@pytest.mark.parametrize("action", ["create", "modify"]) |
| 132 |
def test_get_success_message(self, action): |
| 133 |
json_data = { |
| 134 |
"Id": 36, |
| 135 |
"IsSuccessful": True, |
| 136 |
"Issues": [] |
| 137 |
} |
| 138 |
message = self.module.get_success_message(action, json_data) |
| 139 |
if action == "create": |
| 140 |
assert message["msg"] == "Successfully created an identity pool." |
| 141 |
else: |
| 142 |
assert message["msg"] == "Successfully modified the identity pool." |
| 143 |
assert message["result"] == { |
| 144 |
"Id": 36, |
| 145 |
"IsSuccessful": True, |
| 146 |
"Issues": [] |
| 147 |
} |
| 148 |
|
| 149 |
def test_pool_create_modify_success_case_01(self, mocker, ome_connection_mock_for_identity_pool, ome_response_mock): |
| 150 |
params = {"pool_name": "pool_name"} |
| 151 |
mocker.patch( |
| 152 |
MODULE_PATH + 'ome_identity_pool.validate_modify_create_payload') |
| 153 |
mocker.patch( |
| 154 |
MODULE_PATH + 'ome_identity_pool.get_identity_pool_id_by_name', |
| 155 |
return_value=(10, {"paylaod": "value"})) |
| 156 |
mocker.patch(MODULE_PATH + 'ome_identity_pool.get_payload', |
| 157 |
return_value={"Name": "name"}) |
| 158 |
mocker.patch(MODULE_PATH + 'ome_identity_pool.get_success_message', |
| 159 |
return_value={"msg": "Successfully modified the identity pool"}) |
| 160 |
mocker.patch( |
| 161 |
MODULE_PATH + 'ome_identity_pool.get_updated_modify_payload') |
| 162 |
mocker.patch(MODULE_PATH + 'ome_identity_pool.compare_nested_dict', |
| 163 |
return_value=False) |
| 164 |
f_module = self.get_module_mock(params=params) |
| 165 |
message = self.module.pool_create_modify(f_module, ome_connection_mock_for_identity_pool) |
| 166 |
assert message == {"msg": "Successfully modified the identity pool"} |
| 167 |
|
| 168 |
def test_pool_create_modify_success_case_02(self, mocker, ome_connection_mock_for_identity_pool, ome_response_mock): |
| 169 |
params = {"pool_name": "pool_name"} |
| 170 |
mocker.patch( |
| 171 |
MODULE_PATH + 'ome_identity_pool.validate_modify_create_payload') |
| 172 |
mocker.patch( |
| 173 |
MODULE_PATH + 'ome_identity_pool.get_identity_pool_id_by_name', |
| 174 |
return_value=(0, None)) |
| 175 |
mocker.patch(MODULE_PATH + 'ome_identity_pool.get_payload', |
| 176 |
return_value={"Name": "name"}) |
| 177 |
mocker.patch(MODULE_PATH + 'ome_identity_pool.get_success_message', |
| 178 |
return_value={"msg": "Successfully created an identity pool"}) |
| 179 |
f_module = self.get_module_mock(params=params) |
| 180 |
message = self.module.pool_create_modify(f_module, ome_connection_mock_for_identity_pool) |
| 181 |
assert message == {"msg": "Successfully created an identity pool"} |
| 182 |
|
| 183 |
def test_pool_create_modify_success_case_03(self, mocker, ome_connection_mock_for_identity_pool, ome_response_mock): |
| 184 |
params = {"pool_name": "pool_name"} |
| 185 |
mocker.patch( |
| 186 |
MODULE_PATH + 'ome_identity_pool.get_identity_pool_id_by_name', |
| 187 |
return_value=(10, {"payload": "value"})) |
| 188 |
mocker.patch(MODULE_PATH + 'ome_identity_pool.get_payload', |
| 189 |
return_value={"Name": "pool1"}) |
| 190 |
mocker.patch(MODULE_PATH + 'ome_identity_pool.get_success_message', |
| 191 |
return_value={"msg": "Successfully modified the identity pool"}) |
| 192 |
mocker.patch( |
| 193 |
MODULE_PATH + 'ome_identity_pool.get_updated_modify_payload') |
| 194 |
mocker.patch(MODULE_PATH + 'ome_identity_pool.compare_nested_dict', |
| 195 |
return_value=True) |
| 196 |
f_module = self.get_module_mock(params=params) |
| 197 |
with pytest.raises(Exception) as exc: |
| 198 |
self.module.pool_create_modify(f_module, ome_connection_mock_for_identity_pool) |
| 199 |
assert exc.value.args[0] == "No changes found to be applied." |
| 200 |
|
| 201 |
def test_get_payload_create_case01(self): |
| 202 |
params = {"pool_name": "pool1", |
| 203 |
"pool_description": "Identity pool with ethernet and fcoe settings", |
| 204 |
"ethernet_settings": { |
| 205 |
"starting_mac_address": "50-50-50-50-50-00", |
| 206 |
"identity_count": 60}, |
| 207 |
"fcoe_settings": { |
| 208 |
"starting_mac_address": "70-70-70-70-70-00", |
| 209 |
"identity_count": 75 |
| 210 |
} |
| 211 |
} |
| 212 |
f_module = self.get_module_mock(params=params) |
| 213 |
payload = self.module.get_payload(f_module) |
| 214 |
assert payload == { |
| 215 |
"Name": "pool1", |
| 216 |
"Description": "Identity pool with ethernet and fcoe settings", |
| 217 |
"EthernetSettings": {"Mac": { |
| 218 |
"StartingMacAddress": "UFBQUFAA", |
| 219 |
"IdentityCount": 60}}, |
| 220 |
"FcoeSettings": {"Mac": { |
| 221 |
"StartingMacAddress": "cHBwcHAA", |
| 222 |
"IdentityCount": 75}}, |
| 223 |
} |
| 224 |
|
| 225 |
def test_get_payload_create_case02(self): |
| 226 |
"""new_pool_name should be ignored for create action""" |
| 227 |
params = {"pool_name": "pool1", |
| 228 |
"new_pool_name": "pool2", |
| 229 |
"pool_description": "Identity pool with ethernet and fcoe settings", |
| 230 |
"ethernet_settings": { |
| 231 |
"starting_mac_address": "50-50-50-50-50-00", |
| 232 |
"identity_count": 60}, |
| 233 |
"fcoe_settings": { |
| 234 |
"starting_mac_address": "70-70-70-70-70-00", |
| 235 |
"identity_count": 75 |
| 236 |
} |
| 237 |
} |
| 238 |
f_module = self.get_module_mock(params=params) |
| 239 |
payload = self.module.get_payload(f_module) |
| 240 |
assert payload == { |
| 241 |
"Name": "pool1", |
| 242 |
"Description": "Identity pool with ethernet and fcoe settings", |
| 243 |
"EthernetSettings": {"Mac": { |
| 244 |
"StartingMacAddress": "UFBQUFAA", |
| 245 |
"IdentityCount": 60}}, |
| 246 |
"FcoeSettings": {"Mac": { |
| 247 |
"StartingMacAddress": "cHBwcHAA", |
| 248 |
"IdentityCount": 75}}, |
| 249 |
} |
| 250 |
assert payload["Name"] == "pool1" |
| 251 |
|
| 252 |
def test_get_payload_create_case03(self): |
| 253 |
"""new_pool_name should be ignored for create action""" |
| 254 |
params = { |
| 255 |
"ethernet_settings": { |
| 256 |
"identity_count": 60, |
| 257 |
"starting_mac_address": "50:50:50:50:50:00" |
| 258 |
}, |
| 259 |
"fc_settings": { |
| 260 |
"identity_count": 45, |
| 261 |
"starting_address": "10-10-10-10-10-10" |
| 262 |
}, |
| 263 |
"fcoe_settings": { |
| 264 |
"identity_count": 75, |
| 265 |
"starting_mac_address": "aabb.ccdd.7070" |
| 266 |
}, |
| 267 |
"hostname": "XX.XX.XX.XX", |
| 268 |
"iscsi_settings": { |
| 269 |
"identity_count": 30, |
| 270 |
"initiator_config": { |
| 271 |
"iqn_prefix": "iqn.myprefix." |
| 272 |
}, |
| 273 |
"initiator_ip_pool_settings": { |
| 274 |
"gateway": "192.168.4.1", |
| 275 |
"ip_range": "10.33.0.1-10.33.0.255", |
| 276 |
"primary_dns_server": "10.8.8.8", |
| 277 |
"secondary_dns_server": "8.8.8.8", |
| 278 |
"subnet_mask": "XXX.XXX.XXX.XXX" |
| 279 |
}, |
| 280 |
"starting_mac_address": "60:60:60:60:60:00" |
| 281 |
}, |
| 282 |
"new_pool_name": None, |
| 283 |
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", |
| 284 |
"pool_description": "Identity pool with Ethernet, FCoE, ISCSI and FC settings", |
| 285 |
"pool_name": "pool1", |
| 286 |
"port": 443, |
| 287 |
"state": "present", |
| 288 |
"username": "admin" |
| 289 |
} |
| 290 |
f_module = self.get_module_mock(params=params) |
| 291 |
payload = self.module.get_payload(f_module) |
| 292 |
assert payload == { |
| 293 |
"Name": "pool1", |
| 294 |
"Description": "Identity pool with Ethernet, FCoE, ISCSI and FC settings", |
| 295 |
"EthernetSettings": { |
| 296 |
"Mac": { |
| 297 |
"IdentityCount": 60, |
| 298 |
"StartingMacAddress": "UFBQUFAA" |
| 299 |
} |
| 300 |
}, |
| 301 |
"IscsiSettings": { |
| 302 |
"Mac": { |
| 303 |
"IdentityCount": 30, |
| 304 |
"StartingMacAddress": "YGBgYGAA" |
| 305 |
}, |
| 306 |
"InitiatorConfig": { |
| 307 |
"IqnPrefix": "iqn.myprefix." |
| 308 |
}, |
| 309 |
"InitiatorIpPoolSettings": { |
| 310 |
"IpRange": "10.33.0.1-10.33.0.255", |
| 311 |
"SubnetMask": "XXX.XXX.XXX.XXX", |
| 312 |
"Gateway": "192.168.4.1", |
| 313 |
"PrimaryDnsServer": "10.8.8.8", |
| 314 |
"SecondaryDnsServer": "8.8.8.8" |
| 315 |
} |
| 316 |
}, |
| 317 |
"FcoeSettings": { |
| 318 |
"Mac": { |
| 319 |
"IdentityCount": 75, |
| 320 |
"StartingMacAddress": "qrvM3XBw" |
| 321 |
} |
| 322 |
}, |
| 323 |
"FcSettings": { |
| 324 |
"Wwnn": { |
| 325 |
"IdentityCount": 45, |
| 326 |
"StartingAddress": "IAAQEBAQEBA=" |
| 327 |
}, |
| 328 |
"Wwpn": { |
| 329 |
"IdentityCount": 45, |
| 330 |
"StartingAddress": "IAEQEBAQEBA=" |
| 331 |
} |
| 332 |
} |
| 333 |
} |
| 334 |
assert payload["FcSettings"]["Wwnn"] == {"IdentityCount": 45, "StartingAddress": "IAAQEBAQEBA="} |
| 335 |
assert payload["FcSettings"]["Wwpn"] == {"IdentityCount": 45, "StartingAddress": "IAEQEBAQEBA="} |
| 336 |
assert payload["IscsiSettings"]["Mac"] == {"IdentityCount": 30, "StartingMacAddress": "YGBgYGAA"} |
| 337 |
assert payload["IscsiSettings"]["InitiatorIpPoolSettings"] == { |
| 338 |
"IpRange": "10.33.0.1-10.33.0.255", |
| 339 |
"SubnetMask": "XXX.XXX.XXX.XXX", |
| 340 |
"Gateway": "192.168.4.1", |
| 341 |
"PrimaryDnsServer": "10.8.8.8", |
| 342 |
"SecondaryDnsServer": "8.8.8.8" |
| 343 |
} |
| 344 |
assert payload["IscsiSettings"]["InitiatorConfig"] == { |
| 345 |
"IqnPrefix": "iqn.myprefix." |
| 346 |
} |
| 347 |
|
| 348 |
@pytest.mark.parametrize("state", ["create", "modify"]) |
| 349 |
def test_get_payload_create_modify_case04(self, state): |
| 350 |
"""new_pool_name should be ignored for create action""" |
| 351 |
params = {"pool_name": "pool3", |
| 352 |
"new_pool_name": "pool4", |
| 353 |
"pool_description": "Identity pool with iscsi", |
| 354 |
"iscsi_settings": { |
| 355 |
"identity_count": 30, |
| 356 |
"initiator_config": { |
| 357 |
"iqn_prefix": "iqn.myprefix." |
| 358 |
}, |
| 359 |
"initiator_ip_pool_settings": { |
| 360 |
"gateway": "192.168.4.1", |
| 361 |
"ip_range": "20.33.0.1-20.33.0.255", |
| 362 |
"primary_dns_server": "10.8.8.8", |
| 363 |
"secondary_dns_server": "8.8.8.8", |
| 364 |
"subnet_mask": "XXX.XXX.XXX.XXX" |
| 365 |
}, |
| 366 |
"starting_mac_address": "10:10:10:10:10:00" |
| 367 |
} |
| 368 |
} |
| 369 |
f_module = self.get_module_mock(params=params) |
| 370 |
if state == "create": |
| 371 |
payload = self.module.get_payload(f_module) |
| 372 |
else: |
| 373 |
payload = self.module.get_payload(f_module, 11) |
| 374 |
assert "FcSettings" not in payload |
| 375 |
assert "FcoeSettings" not in payload |
| 376 |
assert payload["IscsiSettings"]["Mac"] == {"IdentityCount": 30, "StartingMacAddress": "EBAQEBAA"} |
| 377 |
assert payload["IscsiSettings"]["InitiatorIpPoolSettings"] == { |
| 378 |
"IpRange": "20.33.0.1-20.33.0.255", |
| 379 |
"SubnetMask": "XXX.XXX.XXX.XXX", |
| 380 |
"Gateway": "192.168.4.1", |
| 381 |
"PrimaryDnsServer": "10.8.8.8", |
| 382 |
"SecondaryDnsServer": "8.8.8.8" |
| 383 |
} |
| 384 |
assert payload["IscsiSettings"]["InitiatorConfig"] == { |
| 385 |
"IqnPrefix": "iqn.myprefix." |
| 386 |
} |
| 387 |
if state == "create": |
| 388 |
assert payload["Name"] == "pool3" |
| 389 |
assert "Id" not in payload |
| 390 |
else: |
| 391 |
assert payload["Name"] == "pool4" |
| 392 |
assert payload["Id"] == 11 |
| 393 |
|
| 394 |
@pytest.mark.parametrize("state", ["create", "modify"]) |
| 395 |
def test_get_payload_create_case05(self, state): |
| 396 |
"""new_pool_name should be ignored for create action and considered in modify""" |
| 397 |
params = {"pool_name": "pool3", |
| 398 |
"new_pool_name": "pool4", |
| 399 |
"pool_description": "Identity pool with iscsi", |
| 400 |
"fc_settings": { |
| 401 |
"identity_count": 48, |
| 402 |
"starting_address": "40:40:40:40:40:22" |
| 403 |
} |
| 404 |
} |
| 405 |
f_module = self.get_module_mock(params=params) |
| 406 |
if state == "create": |
| 407 |
payload = self.module.get_payload(f_module) |
| 408 |
else: |
| 409 |
payload = self.module.get_payload(f_module, 11) |
| 410 |
|
| 411 |
assert payload["FcSettings"]["Wwnn"]["StartingAddress"] == "IABAQEBAQCI=" |
| 412 |
assert payload["FcSettings"]["Wwpn"]["StartingAddress"] == "IAFAQEBAQCI=" |
| 413 |
assert payload["FcSettings"]["Wwnn"]["IdentityCount"] == 48 |
| 414 |
assert payload["FcSettings"]["Wwpn"]["IdentityCount"] == 48 |
| 415 |
if state == "create": |
| 416 |
assert payload["Name"] == "pool3" |
| 417 |
assert "Id" not in payload |
| 418 |
else: |
| 419 |
assert payload["Name"] == "pool4" |
| 420 |
assert payload["Id"] == 11 |
| 421 |
|
| 422 |
def test_get_payload_create_case06(self): |
| 423 |
params = {"pool_name": "pool1", |
| 424 |
"pool_description": "Identity pool with ethernet and fcoe settings", |
| 425 |
"fcoe_settings": {"starting_mac_address": "70-70-70-70-70-00", |
| 426 |
"identity_count": 75 |
| 427 |
}} |
| 428 |
f_module = self.get_module_mock(params=params) |
| 429 |
payload = self.module.get_payload(f_module) |
| 430 |
assert payload["Name"] == "pool1" |
| 431 |
assert "Id" not in payload |
| 432 |
assert "FcoeSettings" in payload |
| 433 |
assert "Ethernet_Settings" not in payload |
| 434 |
|
| 435 |
@pytest.mark.parametrize("state", ["create", "modify"]) |
| 436 |
def test_get_payload_create_case07(self, state): |
| 437 |
|
| 438 |
params = {"pool_name": "pool1", |
| 439 |
"pool_description": "Identity pool with ethernet and fcoe settings"} |
| 440 |
f_module = self.get_module_mock(params=params) |
| 441 |
if state == "create": |
| 442 |
payload = self.module.get_payload(f_module, None) |
| 443 |
else: |
| 444 |
payload = self.module.get_payload(f_module, 11) |
| 445 |
assert payload["Name"] == "pool1" |
| 446 |
if state == "modify": |
| 447 |
assert "Id" in payload |
| 448 |
else: |
| 449 |
assert "Id" not in payload |
| 450 |
assert "FcoeSettings" not in payload |
| 451 |
assert "Ethernet_Settings" not in payload |
| 452 |
assert "Ethernet_Settings" not in payload |
| 453 |
assert "Ethernet_Settings" not in payload |
| 454 |
|
| 455 |
def test_get_payload_modify_case01(self): |
| 456 |
"""moify action Name should be updated with ne_pool_name and Id has to be updated""" |
| 457 |
params = {"pool_name": "pool1", |
| 458 |
"new_pool_name": "pool2", |
| 459 |
"pool_description": "Identity pool with ethernet and fcoe settings", |
| 460 |
"ethernet_settings": {"starting_mac_address": "50-50-50-50-50-00", |
| 461 |
"identity_count": 60}, |
| 462 |
"fcoe_settings": { |
| 463 |
"starting_mac_address": "70-70-70-70-70-00", |
| 464 |
"identity_count": 75 |
| 465 |
} |
| 466 |
} |
| 467 |
f_module = self.get_module_mock(params=params) |
| 468 |
payload = self.module.get_payload(f_module, 10) |
| 469 |
assert payload == { |
| 470 |
"Id": 10, |
| 471 |
"Name": "pool2", |
| 472 |
"Description": "Identity pool with ethernet and fcoe settings", |
| 473 |
"EthernetSettings": {"Mac": { |
| 474 |
"StartingMacAddress": "UFBQUFAA", |
| 475 |
"IdentityCount": 60}}, |
| 476 |
"FcoeSettings": {"Mac": { |
| 477 |
"StartingMacAddress": "cHBwcHAA", |
| 478 |
"IdentityCount": 75}}, |
| 479 |
} |
| 480 |
assert payload["Name"] == "pool2" |
| 481 |
assert payload["Id"] == 10 |
| 482 |
|
| 483 |
def test_get_payload_modify_case02(self): |
| 484 |
"""payload for only ethernet setting |
| 485 |
if ne_ppol_name not passed payload Name should be updated with I(pool_name) |
| 486 |
""" |
| 487 |
params = {"pool_name": "pool1", |
| 488 |
"pool_description": "Identity pool with ethernet and fcoe settings", |
| 489 |
"ethernet_settings": {"starting_mac_address": "50-50-50-50-50-00", |
| 490 |
"identity_count": 60 |
| 491 |
} |
| 492 |
} |
| 493 |
f_module = self.get_module_mock(params=params) |
| 494 |
payload = self.module.get_payload(f_module, 10) |
| 495 |
assert payload["Name"] == "pool1" |
| 496 |
assert payload["Id"] == 10 |
| 497 |
assert "FcoeSettings" not in payload |
| 498 |
assert "EthernetSettings" in payload |
| 499 |
assert payload == {'Description': 'Identity pool with ethernet and fcoe settings', |
| 500 |
'Name': 'pool1', |
| 501 |
'Id': 10, |
| 502 |
'EthernetSettings': { |
| 503 |
'Mac': |
| 504 |
{'StartingMacAddress': 'UFBQUFAA', 'IdentityCount': 60 |
| 505 |
} |
| 506 |
} |
| 507 |
} |
| 508 |
|
| 509 |
def test_get_payload_modify_case03(self): |
| 510 |
params = {"pool_name": "pool1", "new_pool_name": "pool2"} |
| 511 |
f_module = self.get_module_mock(params=params) |
| 512 |
payload = self.module.get_payload(f_module, 11) |
| 513 |
assert payload["Name"] == "pool2" |
| 514 |
assert payload["Id"] == 11 |
| 515 |
assert "Description" not in payload |
| 516 |
assert "FcoeSettings" not in payload |
| 517 |
assert "Ethernet_Settings" not in payload |
| 518 |
|
| 519 |
def test_get_payload_modify_case04(self): |
| 520 |
"""check case when I(new_pool_name) is empty string |
| 521 |
ome is accepting it""" |
| 522 |
params = {"pool_name": "pool1", "new_pool_name": ""} |
| 523 |
f_module = self.get_module_mock(params=params) |
| 524 |
payload = self.module.get_payload(f_module, 11) |
| 525 |
assert payload["Name"] == "" |
| 526 |
assert payload["Id"] == 11 |
| 527 |
assert "Description" not in payload |
| 528 |
assert "FcoeSettings" not in payload |
| 529 |
assert "Ethernet_Settings" not in payload |
| 530 |
|
| 531 |
def test_update_mac_settings_case_01(self): |
| 532 |
f_module = self.get_module_mock() |
| 533 |
settings_params = {"starting_mac_address": "70-70-70-70-70-00", "identity_count": 10} |
| 534 |
payload = {"Name": "pool1"} |
| 535 |
self.module.update_mac_settings(payload, settings_params, "Ethernet_Settings", f_module) |
| 536 |
assert payload == { |
| 537 |
"Name": "pool1", |
| 538 |
"Ethernet_Settings": {"Mac": {"StartingMacAddress": "cHBwcHAA", "IdentityCount": 10}} |
| 539 |
} |
| 540 |
|
| 541 |
def test_update_mac_settings_case_02(self): |
| 542 |
f_module = self.get_module_mock() |
| 543 |
settings_params = {"starting_mac_address": "70-70-70-70-70-xx", "identity_count": 10} |
| 544 |
payload = {"Name": "pool1"} |
| 545 |
with pytest.raises(Exception) as exc: |
| 546 |
self.module.update_mac_settings(payload, settings_params, "EthernetSettings", f_module) |
| 547 |
assert exc.value.args[0] == "Please provide the valid MAC address format for Ethernet settings." |
| 548 |
|
| 549 |
def test_update_mac_settings_case_03(self): |
| 550 |
"""case when no sub settting exists""" |
| 551 |
settings_params = {} |
| 552 |
payload = {"Name": "pool1"} |
| 553 |
f_module = self.get_module_mock() |
| 554 |
self.module.update_mac_settings(payload, settings_params, "Ethernet_Settings", f_module) |
| 555 |
assert payload == { |
| 556 |
"Name": "pool1" |
| 557 |
} |
| 558 |
|
| 559 |
def test_get_identity_pool_id_by_name_exist_case(self, mocker, ome_connection_mock_for_identity_pool, |
| 560 |
ome_response_mock): |
| 561 |
pool_list = {"resp_obj": ome_response_mock, "report_list": [{"Name": "pool1", "Id": 10}, |
| 562 |
{"Name": "pool11", "Id": 11}]} |
| 563 |
ome_connection_mock_for_identity_pool.get_all_report_details.return_value = pool_list |
| 564 |
pool_id, _ = self.module.get_identity_pool_id_by_name("pool1", ome_connection_mock_for_identity_pool) |
| 565 |
assert pool_id == 10 |
| 566 |
|
| 567 |
def test_get_identity_pool_id_by_name_non_exist_case(self, mocker, ome_connection_mock_for_identity_pool, |
| 568 |
ome_response_mock): |
| 569 |
pool_list = {"resp_obj": ome_response_mock, "report_list": [{"Name": "pool2", "Id": 10}]} |
| 570 |
ome_connection_mock_for_identity_pool.get_all_report_details.return_value = pool_list |
| 571 |
pool_id, attributes = self.module.get_identity_pool_id_by_name("pool1", ome_connection_mock_for_identity_pool) |
| 572 |
assert pool_id == 0 and attributes is None |
| 573 |
|
| 574 |
def test_compare_payload_attributes_false_case_for_dummy_pool_setting(self): |
| 575 |
"""this put opeartion always gives success result without applying |
| 576 |
changes because identity count is not passed as pat of it""" |
| 577 |
modify_setting_payload = {'Name': 'pool4', 'EthernetSettings': {'Mac': {'StartingMacAddress': 'qrvM3e6q'}}, |
| 578 |
'Id': 33} |
| 579 |
existing_setting_payload = { |
| 580 |
"@odata.context": "/api/$metadata#IdentityPoolService.IdentityPool", |
| 581 |
"@odata.type": "#IdentityPoolService.IdentityPool", |
| 582 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(33)", |
| 583 |
"Id": 33, |
| 584 |
"Name": "pool4", |
| 585 |
"Description": None, |
| 586 |
"CreatedBy": "admin", |
| 587 |
"CreationTime": "2020-01-31 14:53:18.59163", |
| 588 |
"LastUpdatedBy": "admin", |
| 589 |
"LastUpdateTime": "2020-01-31 15:22:08.34596", |
| 590 |
"EthernetSettings": None, |
| 591 |
"IscsiSettings": None, |
| 592 |
"FcoeSettings": None, |
| 593 |
"FcSettings": None, |
| 594 |
"UsageCounts": { |
| 595 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(33)/UsageCounts" |
| 596 |
}, |
| 597 |
"[email protected]": "/api/IdentityPoolService/IdentityPools(33)/UsageIdentitySets" |
| 598 |
} |
| 599 |
val = self.module.compare_nested_dict(modify_setting_payload, existing_setting_payload) |
| 600 |
assert val is False |
| 601 |
|
| 602 |
@pytest.mark.parametrize("modify_payload", |
| 603 |
[{"Description": "Identity pool with ethernet and fcoe settings2"}, {"Name": "pool2"}, |
| 604 |
{"EthernetSettings": {"Mac": {"IdentityCount": 61, "StartingMacAddress": "UFBQUFAA"}}}, |
| 605 |
{"EthernetSettings": {"Mac": {"IdentityCount": 60, "StartingMacAddress": "qrvM3e6q"}}}, |
| 606 |
{"FcoeSettings": {"Mac": {"IdentityCount": 70, "StartingMacAddress": "abcdfe"}}}, |
| 607 |
{"FcoeSettings": {"Mac": {"IdentityCount": 71, "StartingMacAddress": "cHBwcHAA"}}}, |
| 608 |
{"EthernetSettings": {"Mac": {"IdentityCount": 60, "StartingMacAddress": "cHBwcHAA"}}, |
| 609 |
"FcoeSettings": {"Mac": {"IdentityCount": 70, "StartingMacAddress": "qrvM3e6q"}}}, |
| 610 |
{"Description": "Identity pool with ethernet and fcoe settings2", |
| 611 |
"EthernetSettings": {"Mac": {"IdentityCount": 60, "StartingMacAddress": "UFBQUFAA"}}, |
| 612 |
"FcoeSettings": {"Mac": {"IdentityCount": 70, "StartingMacAddress": "cHBwcHAA"}}}]) |
| 613 |
def test_compare_payload_attributes_case_false(self, modify_payload): |
| 614 |
"""case when chages are exists and payload can be used for modify opeartion""" |
| 615 |
modify_setting_payload = modify_payload |
| 616 |
existing_setting_payload = { |
| 617 |
"@odata.context": "/api/$metadata#IdentityPoolService.IdentityPool", |
| 618 |
"@odata.type": "#IdentityPoolService.IdentityPool", |
| 619 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(23)", |
| 620 |
"Id": 23, |
| 621 |
"Name": "pool1", |
| 622 |
"Description": "Identity pool with ethernet and fcoe settings1", |
| 623 |
"CreatedBy": "admin", |
| 624 |
"CreationTime": "2020-01-31 09:28:16.491424", |
| 625 |
"LastUpdatedBy": "admin", |
| 626 |
"LastUpdateTime": "2020-01-31 09:49:59.012549", |
| 627 |
"EthernetSettings": { |
| 628 |
"Mac": { |
| 629 |
"IdentityCount": 60, |
| 630 |
"StartingMacAddress": "UFBQUFAA" |
| 631 |
} |
| 632 |
}, |
| 633 |
"IscsiSettings": None, |
| 634 |
"FcoeSettings": { |
| 635 |
"Mac": { |
| 636 |
"IdentityCount": 70, |
| 637 |
"StartingMacAddress": "cHBwcHAA" |
| 638 |
} |
| 639 |
}, |
| 640 |
"FcSettings": None, |
| 641 |
"UsageCounts": { |
| 642 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(23)/UsageCounts" |
| 643 |
}, |
| 644 |
"[email protected]": "/api/IdentityPoolService/IdentityPools(23)/UsageIdentitySets" |
| 645 |
} |
| 646 |
val = self.module.compare_nested_dict(modify_setting_payload, existing_setting_payload) |
| 647 |
assert val is False |
| 648 |
|
| 649 |
@pytest.mark.parametrize("modify_payload", [ |
| 650 |
{"Name": "pool1", "EthernetSettings": {"Mac": {"StartingMacAddress": "qrvM3e6q"}}}, |
| 651 |
{"Name": "pool1", "EthernetSettings": {"Mac": {"IdentityCount": 70}}}, |
| 652 |
{"Name": "pool1", "EthernetSettings": {"Mac": {"StartingMacAddress": "qrvM3e6q"}}}, |
| 653 |
{"Name": "pool1", "EthernetSettings": {"Mac": {"StartingMacAddress": "qrvM3e6q"}}, |
| 654 |
"FcoeSettings": {"Mac": {"StartingMacAddress": "cHBwcHAA"}}}, |
| 655 |
{"EthernetSettings": {"Mac": {"IdentityCount": 70, "StartingMacAddress": "qrvM3e6q"}}}, |
| 656 |
{"Description": "Identity pool with ethernet setting"}, |
| 657 |
{"Name": "pool1"}, |
| 658 |
{"FcoeSettings": {"Mac": {"IdentityCount": 70, "StartingMacAddress": "cHBwcHAA"}}}, |
| 659 |
{"EthernetSettings": {"Mac": {"IdentityCount": 70, "StartingMacAddress": "qrvM3e6q"}}, |
| 660 |
"FcoeSettings": {"Mac": {"IdentityCount": 70, "StartingMacAddress": "cHBwcHAA"}}}, |
| 661 |
{"Description": "Identity pool with ethernet setting", |
| 662 |
"EthernetSettings": {"Mac": {"IdentityCount": 70, "StartingMacAddress": "qrvM3e6q"}}, |
| 663 |
"FcoeSettings": {"Mac": {"IdentityCount": 70, "StartingMacAddress": "cHBwcHAA"}}}]) |
| 664 |
def test_compare_payload_attributes_case_true(self, modify_payload): |
| 665 |
"""setting values are same as existing payload and no need to apply the changes again""" |
| 666 |
modify_setting_payload = modify_payload |
| 667 |
existing_setting_payload = { |
| 668 |
"@odata.context": "/api/$metadata#IdentityPoolService.IdentityPool", |
| 669 |
"@odata.type": "#IdentityPoolService.IdentityPool", |
| 670 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(30)", |
| 671 |
"Id": 30, |
| 672 |
"Name": "pool1", |
| 673 |
"Description": "Identity pool with ethernet setting", |
| 674 |
"CreatedBy": "admin", |
| 675 |
"CreationTime": "2020-01-31 11:31:13.621182", |
| 676 |
"LastUpdatedBy": "admin", |
| 677 |
"LastUpdateTime": "2020-01-31 11:34:28.00876", |
| 678 |
"EthernetSettings": { |
| 679 |
"Mac": { |
| 680 |
"IdentityCount": 70, |
| 681 |
"StartingMacAddress": "qrvM3e6q" |
| 682 |
} |
| 683 |
}, |
| 684 |
"IscsiSettings": None, |
| 685 |
"FcoeSettings": { |
| 686 |
"Mac": { |
| 687 |
"IdentityCount": 70, |
| 688 |
"StartingMacAddress": "cHBwcHAA" |
| 689 |
} |
| 690 |
}, |
| 691 |
"FcSettings": None, |
| 692 |
"UsageCounts": { |
| 693 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(30)/UsageCounts" |
| 694 |
}, |
| 695 |
"[email protected]": "/api/IdentityPoolService/IdentityPools(30)/UsageIdentitySets" |
| 696 |
} |
| 697 |
val = self.module.compare_nested_dict(modify_setting_payload, existing_setting_payload) |
| 698 |
assert val is True |
| 699 |
|
| 700 |
def test_get_updated_modify_payload_case_01(self): |
| 701 |
"""when setting not exists in current requested payload, update payload from existing setting value if exists""" |
| 702 |
payload = {"Name": "pool1"} |
| 703 |
existing_setting_payload = { |
| 704 |
"@odata.context": "/api/$metadata#IdentityPoolService.IdentityPool", |
| 705 |
"@odata.type": "#IdentityPoolService.IdentityPool", |
| 706 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(30)", |
| 707 |
"Id": 30, |
| 708 |
"Name": "pool1", |
| 709 |
"Description": "Identity pool with ethernet setting", |
| 710 |
"CreatedBy": "admin", |
| 711 |
"CreationTime": "2020-01-31 11:31:13.621182", |
| 712 |
"LastUpdatedBy": "admin", |
| 713 |
"LastUpdateTime": "2020-01-31 11:34:28.00876", |
| 714 |
"EthernetSettings": { |
| 715 |
"Mac": { |
| 716 |
"IdentityCount": 70, |
| 717 |
"StartingMacAddress": "qrvM3e6q" |
| 718 |
} |
| 719 |
}, |
| 720 |
"IscsiSettings": None, |
| 721 |
"FcoeSettings": { |
| 722 |
"Mac": { |
| 723 |
"IdentityCount": 70, |
| 724 |
"StartingMacAddress": "cHBwcHAA" |
| 725 |
} |
| 726 |
}, |
| 727 |
"FcSettings": None, |
| 728 |
"UsageCounts": { |
| 729 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(30)/UsageCounts" |
| 730 |
}, |
| 731 |
"[email protected]": "/api/IdentityPoolService/IdentityPools(30)/UsageIdentitySets" |
| 732 |
} |
| 733 |
payload = self.module.get_updated_modify_payload(payload, existing_setting_payload) |
| 734 |
assert payload["Description"] == "Identity pool with ethernet setting" |
| 735 |
assert payload["EthernetSettings"]["Mac"]["IdentityCount"] == 70 |
| 736 |
assert payload["EthernetSettings"]["Mac"]["StartingMacAddress"] == "qrvM3e6q" |
| 737 |
assert payload["FcoeSettings"]["Mac"]["IdentityCount"] == 70 |
| 738 |
assert payload["FcoeSettings"]["Mac"]["StartingMacAddress"] == "cHBwcHAA" |
| 739 |
|
| 740 |
def test_get_updated_modify_payload_case_02(self): |
| 741 |
"""when setting exists in current requested payload, do not |
| 742 |
update payload from existing setting value if exists""" |
| 743 |
payload = {"Name": "pool1", "EthernetSettings": {"Mac": {"IdentityCount": 55, "StartingMacAddress": "abcd"}}, |
| 744 |
"FcoeSettings": {"Mac": {"IdentityCount": 65, "StartingMacAddress": "xyz"}}} |
| 745 |
existing_setting_payload = { |
| 746 |
"@odata.context": "/api/$metadata#IdentityPoolService.IdentityPool", |
| 747 |
"@odata.type": "#IdentityPoolService.IdentityPool", |
| 748 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(30)", |
| 749 |
"Id": 30, |
| 750 |
"Name": "pool1", |
| 751 |
"Description": "Identity pool with ethernet setting", |
| 752 |
"CreatedBy": "admin", |
| 753 |
"CreationTime": "2020-01-31 11:31:13.621182", |
| 754 |
"LastUpdatedBy": "admin", |
| 755 |
"LastUpdateTime": "2020-01-31 11:34:28.00876", |
| 756 |
"EthernetSettings": { |
| 757 |
"Mac": { |
| 758 |
"IdentityCount": 70, |
| 759 |
"StartingMacAddress": "qrvM3e6q" |
| 760 |
} |
| 761 |
}, |
| 762 |
"IscsiSettings": None, |
| 763 |
"FcoeSettings": { |
| 764 |
"Mac": { |
| 765 |
"IdentityCount": 70, |
| 766 |
"StartingMacAddress": "cHBwcHAA" |
| 767 |
} |
| 768 |
}, |
| 769 |
"FcSettings": None, |
| 770 |
"UsageCounts": { |
| 771 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(30)/UsageCounts" |
| 772 |
}, |
| 773 |
"[email protected]": "/api/IdentityPoolService/IdentityPools(30)/UsageIdentitySets" |
| 774 |
} |
| 775 |
payload = self.module.get_updated_modify_payload(payload, existing_setting_payload) |
| 776 |
assert payload["Description"] == "Identity pool with ethernet setting" |
| 777 |
assert payload["EthernetSettings"]["Mac"]["IdentityCount"] == 55 |
| 778 |
assert payload["EthernetSettings"]["Mac"]["StartingMacAddress"] == "abcd" |
| 779 |
assert payload["FcoeSettings"]["Mac"]["IdentityCount"] == 65 |
| 780 |
assert payload["FcoeSettings"]["Mac"]["StartingMacAddress"] == "xyz" |
| 781 |
|
| 782 |
def test_get_updated_modify_payload_case_03(self): |
| 783 |
"""update new description""" |
| 784 |
payload = {"Name": "pool1", "Description": "new description"} |
| 785 |
existing_setting_payload = { |
| 786 |
"@odata.context": "/api/$metadata#IdentityPoolService.IdentityPool", |
| 787 |
"@odata.type": "#IdentityPoolService.IdentityPool", |
| 788 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(30)", |
| 789 |
"Id": 30, |
| 790 |
"Name": "pool1", |
| 791 |
"Description": "Identity pool with ethernet setting", |
| 792 |
"CreatedBy": "admin", |
| 793 |
"CreationTime": "2020-01-31 11:31:13.621182", |
| 794 |
"LastUpdatedBy": "admin", |
| 795 |
"LastUpdateTime": "2020-01-31 11:34:28.00876", |
| 796 |
"EthernetSettings": None, |
| 797 |
"IscsiSettings": None, |
| 798 |
"FcoeSettings": None, |
| 799 |
"FcSettings": None, |
| 800 |
"UsageCounts": { |
| 801 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(30)/UsageCounts" |
| 802 |
}, |
| 803 |
"[email protected]": "/api/IdentityPoolService/IdentityPools(30)/UsageIdentitySets" |
| 804 |
} |
| 805 |
payload = self.module.get_updated_modify_payload(payload, existing_setting_payload) |
| 806 |
assert payload["Description"] == "new description" |
| 807 |
assert "EthernetSettings" not in payload |
| 808 |
assert "FcoeSettings" not in payload |
| 809 |
|
| 810 |
def test_get_updated_modify_payload_case_04(self): |
| 811 |
"""update remaining parameter of ethernet and fcoe setting |
| 812 |
if not exists in payload but exists in existing setting payload""" |
| 813 |
payload = {"Name": "pool1", "EthernetSettings": {"Mac": {"StartingMacAddress": "abcd"}}, |
| 814 |
"FcoeSettings": {"Mac": {"IdentityCount": 65}}} |
| 815 |
existing_setting_payload = { |
| 816 |
"@odata.context": "/api/$metadata#IdentityPoolService.IdentityPool", |
| 817 |
"@odata.type": "#IdentityPoolService.IdentityPool", |
| 818 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(30)", |
| 819 |
"Id": 30, |
| 820 |
"Name": "pool1", |
| 821 |
"Description": "Identity pool with ethernet setting", |
| 822 |
"CreatedBy": "admin", |
| 823 |
"CreationTime": "2020-01-31 11:31:13.621182", |
| 824 |
"LastUpdatedBy": "admin", |
| 825 |
"LastUpdateTime": "2020-01-31 11:34:28.00876", |
| 826 |
"EthernetSettings": { |
| 827 |
"Mac": { |
| 828 |
"IdentityCount": 70, |
| 829 |
"StartingMacAddress": "qrvM3e6q" |
| 830 |
} |
| 831 |
}, |
| 832 |
"IscsiSettings": None, |
| 833 |
"FcoeSettings": { |
| 834 |
"Mac": { |
| 835 |
"IdentityCount": 70, |
| 836 |
"StartingMacAddress": "cHBwcHAA" |
| 837 |
} |
| 838 |
}, |
| 839 |
"FcSettings": None, |
| 840 |
"UsageCounts": { |
| 841 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(30)/UsageCounts" |
| 842 |
}, |
| 843 |
"[email protected]": "/api/IdentityPoolService/IdentityPools(30)/UsageIdentitySets" |
| 844 |
} |
| 845 |
payload = self.module.get_updated_modify_payload(payload, existing_setting_payload) |
| 846 |
assert payload["Description"] == "Identity pool with ethernet setting" |
| 847 |
assert payload["EthernetSettings"]["Mac"]["IdentityCount"] == 70 |
| 848 |
assert payload["EthernetSettings"]["Mac"]["StartingMacAddress"] == "abcd" |
| 849 |
assert payload["FcoeSettings"]["Mac"]["IdentityCount"] == 65 |
| 850 |
assert payload["FcoeSettings"]["Mac"]["StartingMacAddress"] == "cHBwcHAA" |
| 851 |
|
| 852 |
def test_get_updated_modify_payload_case_05(self): |
| 853 |
"""update remaining parameter of ethernet and fcoe setting will be null if not exists in existing payload""" |
| 854 |
payload = {"Name": "pool1", "EthernetSettings": {"Mac": {"StartingMacAddress": "abcd"}}, } |
| 855 |
existing_setting_payload = {"@odata.context": "/api/$metadata#IdentityPoolService.IdentityPool", |
| 856 |
"@odata.type": "#IdentityPoolService.IdentityPool", |
| 857 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(30)", "Id": 30, |
| 858 |
"Name": "pool1", |
| 859 |
"Description": "Identity pool with ethernet setting", "CreatedBy": "admin", |
| 860 |
"CreationTime": "2020-01-31 11:31:13.621182", |
| 861 |
"LastUpdatedBy": "admin", "LastUpdateTime": "2020-01-31 11:34:28.00876", |
| 862 |
"EthernetSettings": {"Mac": {"StartingMacAddress": "qrvM3e6q"}}, |
| 863 |
"IscsiSettings": None, |
| 864 |
"FcoeSettings": {"Mac": {"StartingMacAddress": "cHBwcHAA"}}, "FcSettings": None, |
| 865 |
"UsageCounts": { |
| 866 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(30)/UsageCounts"}, |
| 867 |
"[email protected]": "/api/IdentityPoolService/IdentityPools(30)/UsageIdentitySets"} |
| 868 |
payload = self.module.get_updated_modify_payload(payload, existing_setting_payload) |
| 869 |
assert payload["Description"] == "Identity pool with ethernet setting" |
| 870 |
assert payload["EthernetSettings"]["Mac"]["StartingMacAddress"] == "abcd" |
| 871 |
assert "IdentityCount" not in payload["EthernetSettings"]["Mac"] |
| 872 |
|
| 873 |
@pytest.mark.parametrize("setting", ["EthernetSettings", "FcoeSettings"]) |
| 874 |
def test_get_updated_modify_payload_case_06(self, setting): |
| 875 |
modify_payload = {"Name": "pool1", "EthernetSettings": {"Mac": {"StartingMacAddress": "abcd"}}, } |
| 876 |
existing_payload = {"@odata.context": "/api/$metadata#IdentityPoolService.IdentityPool", |
| 877 |
"@odata.type": "#IdentityPoolService.IdentityPool", |
| 878 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(35)", |
| 879 |
"Id": 35, "Name": "pool1", |
| 880 |
"Description": "Identity pool with ethernet and fcoe settings1", |
| 881 |
"CreatedBy": "admin", "CreationTime": "2020-02-01 07:55:59.923838", |
| 882 |
"LastUpdatedBy": "admin", "LastUpdateTime": "2020-02-01 07:55:59.923838", |
| 883 |
"EthernetSettings": {"Mac": {"IdentityCount": 60, "StartingMacAddress": "UFBQUFAA"}}, |
| 884 |
"IscsiSettings": None, |
| 885 |
"FcoeSettings": {"Mac": {"IdentityCount": 70, "StartingMacAddress": "cHBwcHAA"}}, |
| 886 |
"FcSettings": None, |
| 887 |
"UsageCounts": {"@odata.id": "/api/IdentityPoolService/IdentityPools(35)/UsageCounts"}, |
| 888 |
"[email protected]": "/api/IdentityPoolService/IdentityPools(35)/UsageIdentitySets"} |
| 889 |
modify_payload = self.module.get_updated_modify_payload(modify_payload, existing_payload) |
| 890 |
assert modify_payload["EthernetSettings"]["Mac"]["StartingMacAddress"] == "abcd" |
| 891 |
assert modify_payload["EthernetSettings"]["Mac"]["IdentityCount"] == 60 |
| 892 |
assert modify_payload["FcoeSettings"]["Mac"]["StartingMacAddress"] == "cHBwcHAA" |
| 893 |
assert modify_payload["FcoeSettings"]["Mac"]["IdentityCount"] == 70 |
| 894 |
|
| 895 |
@pytest.mark.parametrize("setting", ["EthernetSettings", "FcoeSettings"]) |
| 896 |
def test_update_modify_setting_case_success(self, setting): |
| 897 |
modify_payload = {"Name": "pool1", "EthernetSettings": {"Mac": {"StartingMacAddress": "abcd"}}, |
| 898 |
"FcoeSettings": {"Mac": {"IdentityCount": 55}}} |
| 899 |
existing_payload = {"@odata.context": "/api/$metadata#IdentityPoolService.IdentityPool", |
| 900 |
"@odata.type": "#IdentityPoolService.IdentityPool", |
| 901 |
"@odata.id": "/api/IdentityPoolService/IdentityPools(35)", |
| 902 |
"Id": 35, "Name": "pool1", |
| 903 |
"Description": "Identity pool with ethernet and fcoe settings1", |
| 904 |
"CreatedBy": "admin", "CreationTime": "2020-02-01 07:55:59.923838", |
| 905 |
"LastUpdatedBy": "admin", "LastUpdateTime": "2020-02-01 07:55:59.923838", |
| 906 |
"EthernetSettings": {"Mac": {"IdentityCount": 60, "StartingMacAddress": "UFBQUFAA"}}, |
| 907 |
"IscsiSettings": None, |
| 908 |
"FcoeSettings": {"Mac": {"IdentityCount": 70, "StartingMacAddress": "cHBwcHAA"}}, |
| 909 |
"FcSettings": None, |
| 910 |
"UsageCounts": {"@odata.id": "/api/IdentityPoolService/IdentityPools(35)/UsageCounts"}, |
| 911 |
"[email protected]": "/api/IdentityPoolService/IdentityPools(35)/UsageIdentitySets"} |
| 912 |
if setting == "EthernetSettings": |
| 913 |
self.module.update_modify_setting(modify_payload, existing_payload, setting, ["Mac"]) |
| 914 |
assert modify_payload["EthernetSettings"]["Mac"]["StartingMacAddress"] == "abcd" |
| 915 |
assert modify_payload["EthernetSettings"]["Mac"]["IdentityCount"] == 60 |
| 916 |
else: |
| 917 |
self.module.update_modify_setting(modify_payload, existing_payload, setting, ["Mac"]) |
| 918 |
assert modify_payload["FcoeSettings"]["Mac"]["StartingMacAddress"] == "cHBwcHAA" |
| 919 |
assert modify_payload["FcoeSettings"]["Mac"]["IdentityCount"] == 55 |
| 920 |
|
| 921 |
@pytest.mark.parametrize("mac_address", |
| 922 |
['50-50-50-50-50-50', '50:50:50:50:50:50', '5050.5050.5050', 'ab:cd:ef:70:80:70', |
| 923 |
'aabb.ccdd.7070']) |
| 924 |
def test_mac_validation_match_case(self, mac_address): |
| 925 |
"""valid MAC address formats""" |
| 926 |
match = self.module.mac_validation(mac_address) |
| 927 |
assert match is not None |
| 928 |
|
| 929 |
@pytest.mark.parametrize("mac_address", ['50--50--50--50--50-50', |
| 930 |
'50::50::50::50::50::50', |
| 931 |
'5050..5050..5050', |
| 932 |
'ab/cd/ef/70/80/70', |
| 933 |
'50-50:50.50-50-50', |
| 934 |
'xy:gh:yk:lm:30:10', |
| 935 |
'50-50-50-50-50', |
| 936 |
'50-50-50-50-50-50-50-50']) |
| 937 |
def test_mac_validation_match_case(self, mac_address): |
| 938 |
match = self.module.mac_validation(mac_address) |
| 939 |
assert match is None |
| 940 |
|
| 941 |
@pytest.mark.parametrize("mac_address_base64_map", [{'50-50-50-50-50-50': 'UFBQUFBQ'}, |
| 942 |
{'50:50:50:50:50:50': 'UFBQUFBQ'}, |
| 943 |
{'5050.5050.5050': 'UFBQUFBQ'}, |
| 944 |
{'ab:cd:ef:70:80:70': 'q83vcIBw'}, |
| 945 |
{'20-00-50-50-50-50-50-50': 'IABQUFBQUFA='}, |
| 946 |
{'20-01-50-50-50-50-50-50': 'IAFQUFBQUFA='}, |
| 947 |
{'20:00:50:50:50:50:50:50': 'IABQUFBQUFA='}, |
| 948 |
{'20:01:50:50:50:50:50:50': 'IAFQUFBQUFA='}, |
| 949 |
{'2000.5050.5050.5050': 'IABQUFBQUFA='}, |
| 950 |
{'2001.5050.5050.5050': 'IAFQUFBQUFA='}, |
| 951 |
{'20:00:ab:cd:ef:70:80:70': 'IACrze9wgHA='}, |
| 952 |
{'20:01:ab:cd:ef:70:80:70': 'IAGrze9wgHA='}, |
| 953 |
]) |
| 954 |
def test_mac_to_base64_conversion(self, mac_address_base64_map): |
| 955 |
f_module = self.get_module_mock() |
| 956 |
mac_address = list(mac_address_base64_map.keys())[0] |
| 957 |
base_64_val_expected = list(mac_address_base64_map.values())[0] |
| 958 |
base_64_val = self.module.mac_to_base64_conversion(mac_address, f_module) |
| 959 |
assert base_64_val == base_64_val_expected |
| 960 |
|
| 961 |
def test_mac_to_base64_invalid_hex_raises_exit_json(self): |
| 962 |
f_module = self.get_module_mock() |
| 963 |
mac_input = "00:11:22:GG:44:55" |
| 964 |
with pytest.raises(AnsibleFailJSonException) as exc_info: |
| 965 |
mac_to_base64_conversion(mac_input, f_module) |
| 966 |
|
| 967 |
assert "Encoding of MAC address" in str(exc_info.value) |
| 968 |
|
| 969 |
def test_pool_delete_case_01(self, ome_connection_mock_for_identity_pool, mocker): |
| 970 |
params = {"pool_name": "pool_name"} |
| 971 |
mocker.patch( |
| 972 |
MODULE_PATH + 'ome_identity_pool.get_identity_pool_id_by_name', |
| 973 |
return_value=(1, {"value": "data"})) |
| 974 |
f_module = self.get_module_mock(params=params) |
| 975 |
message = self.module.pool_delete(f_module, ome_connection_mock_for_identity_pool) |
| 976 |
assert message["msg"] == "Successfully deleted the identity pool." |
| 977 |
|
| 978 |
def test_pool_delete_case_02(self, ome_connection_mock_for_identity_pool, mocker): |
| 979 |
params = {"pool_name": "pool_name"} |
| 980 |
mocker.patch( |
| 981 |
MODULE_PATH + 'ome_identity_pool.get_identity_pool_id_by_name', |
| 982 |
return_value=(0, {})) |
| 983 |
f_module = self.get_module_mock(params=params) |
| 984 |
with pytest.raises(Exception) as exc: |
| 985 |
self.module.pool_delete(f_module, ome_connection_mock_for_identity_pool) |
| 986 |
assert exc.value.args[0] == "The identity pool '{0}' is not present in the system.".format(params["pool_name"]) |
| 987 |
|
| 988 |
def test_delete_identity_pool_check_mode(self, mocker, ome_connection_mock_for_identity_pool): |
| 989 |
params = {"pool_name": "pool_name"} |
| 990 |
f_module = self.get_module_mock(params=params) |
| 991 |
f_module.check_mode = True |
| 992 |
mocker.patch( |
| 993 |
MODULE_PATH + 'ome_identity_pool.get_identity_pool_id_by_name', return_value=(1, {"value": "data"})) |
| 994 |
with pytest.raises(AnsibleFailJSonException) as exc: |
| 995 |
self.module.pool_delete(f_module, ome_connection_mock_for_identity_pool) |
| 996 |
assert "Changes found to be applied." in str(exc.value) |
| 997 |
|
| 998 |
def test_create_modify_identity_pool_check_mode(self, ome_connection_mock_for_identity_pool): |
| 999 |
params = {"pool_name": "pool_name"} |
| 1000 |
f_module = self.get_module_mock(params=params) |
| 1001 |
f_module.check_mode = True |
| 1002 |
with pytest.raises(AnsibleFailJSonException) as exc: |
| 1003 |
self.module.pool_create_modify(f_module, ome_connection_mock_for_identity_pool) |
| 1004 |
assert "Changes found to be applied." in str(exc.value) |
| 1005 |
|
| 1006 |
def test_pool_delete_error_case_02(self, mocker, ome_connection_mock_for_identity_pool, ome_response_mock): |
| 1007 |
msg = "exception message" |
| 1008 |
params = {"pool_name": "pool_name"} |
| 1009 |
mocker.patch( |
| 1010 |
MODULE_PATH + 'ome_identity_pool.get_identity_pool_id_by_name', |
| 1011 |
return_value=(1, "data")) |
| 1012 |
f_module = self.get_module_mock(params=params) |
| 1013 |
ome_connection_mock_for_identity_pool.invoke_request.side_effect = Exception(msg) |
| 1014 |
with pytest.raises(Exception, match=msg): |
| 1015 |
self.module.pool_delete(f_module, ome_connection_mock_for_identity_pool) |
| 1016 |
|
| 1017 |
def test_main_ome_identity_pool_delete_success_case1(self, mocker, ome_default_args, |
| 1018 |
ome_connection_mock_for_identity_pool, ome_response_mock): |
| 1019 |
sub_param = {"pool_name": "pool1", |
| 1020 |
"state": "absent", } |
| 1021 |
message_return = {"msg": "Successfully deleted the identity pool."} |
| 1022 |
mocker.patch(MODULE_PATH + 'ome_identity_pool.pool_delete', |
| 1023 |
return_value=message_return) |
| 1024 |
ome_default_args.update(sub_param) |
| 1025 |
result = self._run_module(ome_default_args) |
| 1026 |
assert 'pool_status' not in result |
| 1027 |
assert result["msg"] == "Successfully deleted the identity pool." |
| 1028 |
|
| 1029 |
def test_validate_modify_create_payload_no_exception_case(self): |
| 1030 |
modify_payload = { |
| 1031 |
"Id": 59, |
| 1032 |
"Name": "pool_new", |
| 1033 |
"EthernetSettings": { |
| 1034 |
"Mac": { |
| 1035 |
"IdentityCount": 61, |
| 1036 |
"StartingMacAddress": "kJCQkJCQ" |
| 1037 |
} |
| 1038 |
}, |
| 1039 |
"IscsiSettings": { |
| 1040 |
"Mac": { |
| 1041 |
"IdentityCount": 30, |
| 1042 |
"StartingMacAddress": "YGBgYGAA" |
| 1043 |
}, |
| 1044 |
"InitiatorConfig": { |
| 1045 |
"IqnPrefix": "iqn.myprefix." |
| 1046 |
}, |
| 1047 |
"InitiatorIpPoolSettings": { |
| 1048 |
"IpRange": "10.33.0.1-10.33.0.255", |
| 1049 |
"SubnetMask": "XXX.XXX.XXX.XXX", |
| 1050 |
"Gateway": "192.168.4.1", |
| 1051 |
"PrimaryDnsServer": "10.8.8.8", |
| 1052 |
"SecondaryDnsServer": "8.8.8.8" |
| 1053 |
} |
| 1054 |
}, |
| 1055 |
"FcoeSettings": { |
| 1056 |
"Mac": { |
| 1057 |
"IdentityCount": 77, |
| 1058 |
"StartingMacAddress": "qrvM3VBQ" |
| 1059 |
} |
| 1060 |
}, |
| 1061 |
"FcSettings": { |
| 1062 |
"Wwnn": { |
| 1063 |
"IdentityCount": 45, |
| 1064 |
"StartingAddress": "IAAQEBAQEBA=" |
| 1065 |
}, |
| 1066 |
"Wwpn": { |
| 1067 |
"IdentityCount": 45, |
| 1068 |
"StartingAddress": "IAEQEBAQEBA=" |
| 1069 |
} |
| 1070 |
} |
| 1071 |
} |
| 1072 |
f_module = self.get_module_mock() |
| 1073 |
self.module.validate_modify_create_payload(modify_payload, f_module, "create") |
| 1074 |
|
| 1075 |
modify_payload1 = { |
| 1076 |
"Mac": { |
| 1077 |
"IdentityCount": 61, |
| 1078 |
} |
| 1079 |
} |
| 1080 |
modify_payload2 = { |
| 1081 |
"Mac": { |
| 1082 |
"StartingMacAddress": "kJCQkJCQ" |
| 1083 |
} |
| 1084 |
} |
| 1085 |
|
| 1086 |
modify_payload3 = { |
| 1087 |
"Mac": { |
| 1088 |
} |
| 1089 |
} |
| 1090 |
|
| 1091 |
modify_payload4 = { |
| 1092 |
"Mac": None |
| 1093 |
} |
| 1094 |
|
| 1095 |
@pytest.mark.parametrize("setting", ["EthernetSettings", "FcoeSettings"]) |
| 1096 |
@pytest.mark.parametrize("action", ["create", "modify"]) |
| 1097 |
@pytest.mark.parametrize("payload", [modify_payload1, modify_payload2, modify_payload3, modify_payload4]) |
| 1098 |
def test_validate_modify_create_payload_failure_case1(self, payload, action, setting): |
| 1099 |
modify_payload = {"Id": 59, "Name": "pool_new"} |
| 1100 |
modify_payload[setting] = payload |
| 1101 |
f_module = self.get_module_mock() |
| 1102 |
msg = "Both starting MAC address and identity count is required to {0} an identity pool using {1} settings.".format( |
| 1103 |
action, ''.join(setting.split('Settings'))) |
| 1104 |
with pytest.raises(Exception, match=msg): |
| 1105 |
self.module.validate_modify_create_payload(modify_payload, f_module, action) |
| 1106 |
|
| 1107 |
modify_fc_setting1 = {"FcSettings": { |
| 1108 |
"Wwnn": { |
| 1109 |
"IdentityCount": 45, |
| 1110 |
}, |
| 1111 |
"Wwpn": { |
| 1112 |
"IdentityCount": 45, |
| 1113 |
} |
| 1114 |
}} |
| 1115 |
modify_fc_setting2 = {"FcSettings": { |
| 1116 |
"Wwnn": { |
| 1117 |
"StartingAddress": "IAAQEBAQEBA=" |
| 1118 |
}, |
| 1119 |
"Wwpn": { |
| 1120 |
"IdentityCount": 45, |
| 1121 |
"StartingAddress": "IAEQEBAQEBA=" |
| 1122 |
} |
| 1123 |
}} |
| 1124 |
modify_fc_setting3 = {"FcSettings": { |
| 1125 |
"Wwnn": { |
| 1126 |
"StartingAddress": "IAAQEBAQEBA=" |
| 1127 |
}, |
| 1128 |
"Wwpn": { |
| 1129 |
"StartingAddress": "IAEQEBAQEBA=" |
| 1130 |
} |
| 1131 |
}} |
| 1132 |
modify_fc_setting4 = {"FcSettings": { |
| 1133 |
"Wwnn": { |
| 1134 |
}, |
| 1135 |
"Wwpn": { |
| 1136 |
} |
| 1137 |
}} |
| 1138 |
modify_fc_setting5 = {"FcSettings": { |
| 1139 |
"Wwnn": None, |
| 1140 |
"Wwpn": None}} |
| 1141 |
|
| 1142 |
@pytest.mark.parametrize("action", ["create", "modify"]) |
| 1143 |
@pytest.mark.parametrize("modify_payload", |
| 1144 |
[modify_fc_setting1, modify_fc_setting2, modify_fc_setting3, modify_fc_setting4, |
| 1145 |
modify_fc_setting5]) |
| 1146 |
def test_validate_modify_create_payload_failure_fc_setting_case(self, modify_payload, action): |
| 1147 |
payload = {"Id": 59, "Name": "pool_new"} |
| 1148 |
modify_payload.update(payload) |
| 1149 |
f_module = self.get_module_mock() |
| 1150 |
msg = "Both starting MAC address and identity count is required to {0} an identity pool using Fc settings.".format( |
| 1151 |
action) |
| 1152 |
with pytest.raises(Exception, match=msg): |
| 1153 |
self.module.validate_modify_create_payload(modify_payload, f_module, action) |
| 1154 |
|
| 1155 |
payload_iscsi1 = {"IscsiSettings": { |
| 1156 |
"Mac": { |
| 1157 |
"IdentityCount": 30 |
| 1158 |
}}} |
| 1159 |
|
| 1160 |
payload_iscsi2 = {"IscsiSettings": { |
| 1161 |
"Mac": { |
| 1162 |
"StartingMacAddress": "kJCQkJCQ" |
| 1163 |
}}} |
| 1164 |
payload_iscsi3 = {"IscsiSettings": { |
| 1165 |
"Mac": { |
| 1166 |
}}} |
| 1167 |
|
| 1168 |
@pytest.mark.parametrize("action", ["create", "modify"]) |
| 1169 |
@pytest.mark.parametrize("modify_payload", [payload_iscsi1, payload_iscsi2, payload_iscsi3]) |
| 1170 |
def test_validate_modify_create_payload_failure_iscsi_setting_case1(self, modify_payload, action): |
| 1171 |
payload = {"Id": 59, "Name": "pool_new"} |
| 1172 |
modify_payload.update(payload) |
| 1173 |
f_module = self.get_module_mock() |
| 1174 |
msg = "Both starting MAC address and identity count is required to {0} an identity pool using Iscsi settings.".format( |
| 1175 |
action) |
| 1176 |
with pytest.raises(Exception, match=msg): |
| 1177 |
self.module.validate_modify_create_payload(modify_payload, f_module, action) |
| 1178 |
|
| 1179 |
payload_iscsi3 = { |
| 1180 |
"SubnetMask": "XXX.XXX.XXX.XXX", |
| 1181 |
"Gateway": "192.168.4.1", |
| 1182 |
"PrimaryDnsServer": "10.8.8.8", |
| 1183 |
"SecondaryDnsServer": "8.8.8.8" |
| 1184 |
} |
| 1185 |
|
| 1186 |
payload_iscsi4 = { |
| 1187 |
"IpRange": "10.33.0.1-10.33.0.255", |
| 1188 |
"Gateway": "192.168.4.1", |
| 1189 |
"PrimaryDnsServer": "10.8.8.8", |
| 1190 |
"SecondaryDnsServer": "8.8.8.8" |
| 1191 |
} |
| 1192 |
payload_iscsi5 = { |
| 1193 |
"PrimaryDnsServer": "10.8.8.8", |
| 1194 |
"SecondaryDnsServer": "8.8.8.8" |
| 1195 |
} |
| 1196 |
|
| 1197 |
@pytest.mark.parametrize("action", ["create", "modify"]) |
| 1198 |
@pytest.mark.parametrize("initiatorip_payload", |
| 1199 |
[payload_iscsi3, payload_iscsi4, payload_iscsi5]) |
| 1200 |
def test_validate_modify_create_payload_failure_iscsi_setting_case2(self, initiatorip_payload, action): |
| 1201 |
modify_payload = {"Id": 59, "Name": "pool_new", |
| 1202 |
"IscsiSettings": {"Mac": { |
| 1203 |
"IdentityCount": 30, |
| 1204 |
"StartingMacAddress": "kJCQkJCQ" |
| 1205 |
}, |
| 1206 |
"InitiatorConfig": {"IqnPrefix": "abc"}}, |
| 1207 |
} |
| 1208 |
modify_payload["IscsiSettings"]["InitiatorIpPoolSettings"] = initiatorip_payload |
| 1209 |
f_module = self.get_module_mock() |
| 1210 |
msg = "Both ip range and subnet mask in required to {0} an identity pool using iSCSI settings.".format(action) |
| 1211 |
with pytest.raises(Exception, match=msg): |
| 1212 |
self.module.validate_modify_create_payload(modify_payload, f_module, action) |
| 1213 |
|
| 1214 |
def test_update_fc_settings_success_case1(self): |
| 1215 |
setting_params = { |
| 1216 |
"identity_count": 45, |
| 1217 |
"starting_address": "10-10-10-10-10-10" |
| 1218 |
} |
| 1219 |
payload = {"Name": "pool_name"} |
| 1220 |
f_module = self.get_module_mock() |
| 1221 |
self.module.update_fc_settings(payload, setting_params, "FcSettings", f_module) |
| 1222 |
assert payload == { |
| 1223 |
"Name": "pool_name", |
| 1224 |
'FcSettings': {'Wwnn': {'IdentityCount': 45, 'StartingAddress': 'IAAQEBAQEBA='}, |
| 1225 |
'Wwpn': {'IdentityCount': 45, 'StartingAddress': 'IAEQEBAQEBA='} |
| 1226 |
} |
| 1227 |
} |
| 1228 |
|
| 1229 |
def test_update_fc_settings_success_case2(self): |
| 1230 |
setting_params = { |
| 1231 |
"identity_count": 45 |
| 1232 |
} |
| 1233 |
payload = {"Name": "pool_name"} |
| 1234 |
f_module = self.get_module_mock() |
| 1235 |
self.module.update_fc_settings(payload, setting_params, "FcSettings", f_module) |
| 1236 |
assert payload == { |
| 1237 |
"Name": "pool_name", |
| 1238 |
'FcSettings': {'Wwnn': {'IdentityCount': 45}, |
| 1239 |
'Wwpn': {'IdentityCount': 45}} |
| 1240 |
} |
| 1241 |
|
| 1242 |
def test_update_fc_settings_success_case3(self): |
| 1243 |
setting_params = { |
| 1244 |
"starting_address": "10-10-10-10-10-10" |
| 1245 |
} |
| 1246 |
payload = {"Name": "pool_name"} |
| 1247 |
f_module = self.get_module_mock() |
| 1248 |
self.module.update_fc_settings(payload, setting_params, "FcSettings", f_module) |
| 1249 |
assert payload == { |
| 1250 |
"Name": "pool_name", |
| 1251 |
'FcSettings': {'Wwnn': {'StartingAddress': 'IAAQEBAQEBA='}, |
| 1252 |
'Wwpn': {'StartingAddress': 'IAEQEBAQEBA='} |
| 1253 |
} |
| 1254 |
} |
| 1255 |
|
| 1256 |
def test_update_fc_settings_mac_failure_case1(self): |
| 1257 |
setting_params = { |
| 1258 |
"identity_count": 45, |
| 1259 |
"starting_address": "abcd.1010:1010" |
| 1260 |
} |
| 1261 |
payload = {"Name": "pool_name"} |
| 1262 |
setting_type = "FcSettings" |
| 1263 |
f_module = self.get_module_mock() |
| 1264 |
msg = "Please provide the valid starting address format for FC settings." |
| 1265 |
with pytest.raises(Exception, match=msg): |
| 1266 |
self.module.update_fc_settings(payload, setting_params, setting_type, f_module) |
| 1267 |
|
| 1268 |
@pytest.mark.parametrize("mac", [{'50-50-50-50-50-50': ['20-00-', '20-01-']}, |
| 1269 |
{'50:50:50:50:50:50': ['20:00:', '20:01:']}, |
| 1270 |
{'5050.5050.5050': ['2000.', '2001.']}, |
| 1271 |
{'ab:cd:ef:70:80:70': ['20:00:', '20:01:']}, |
| 1272 |
{'aabb.ccdd.7070': ['2000.', '2001.']}]) |
| 1273 |
def test_get_wwn_address(self, mac): |
| 1274 |
mac_address = list(mac.keys())[0] |
| 1275 |
expected_values = list(mac.values())[0] |
| 1276 |
wwnn_address_expected = expected_values[0] |
| 1277 |
wwpn_address_expected = expected_values[1] |
| 1278 |
wwnn_address, wwpn_address = self.module.get_wwn_address_prefix(mac_address) |
| 1279 |
assert wwnn_address == wwnn_address_expected |
| 1280 |
assert wwpn_address == wwpn_address_expected |
| 1281 |
|
| 1282 |
def test_update_iscsi_specific_settings_case1(self): |
| 1283 |
setting_type = "IscsiSettings" |
| 1284 |
payload = {"Name": "pool_new", setting_type: {"Mac": {"IdentityCount": 30, "StartingMacAddress": "YGBgYGAA"}}} |
| 1285 |
settings_params = { |
| 1286 |
"identity_count": 30, |
| 1287 |
"initiator_config": { |
| 1288 |
"iqn_prefix": "iqn.myprefix." |
| 1289 |
}, |
| 1290 |
"initiator_ip_pool_settings": { |
| 1291 |
"gateway": "192.168.4.1", |
| 1292 |
"ip_range": "10.33.0.1-10.33.0.255", |
| 1293 |
"primary_dns_server": "10.8.8.8", |
| 1294 |
"secondary_dns_server": "8.8.8.8", |
| 1295 |
"subnet_mask": "XXX.XXX.XXX.XXX" |
| 1296 |
}, |
| 1297 |
"starting_mac_address": "60:60:60:60:60:00" |
| 1298 |
} |
| 1299 |
self.module.update_iscsi_specific_settings(payload, settings_params, setting_type) |
| 1300 |
assert payload == { |
| 1301 |
"Name": "pool_new", |
| 1302 |
"IscsiSettings": { |
| 1303 |
"Mac": { |
| 1304 |
"IdentityCount": 30, |
| 1305 |
"StartingMacAddress": "YGBgYGAA" |
| 1306 |
}, |
| 1307 |
"InitiatorConfig": { |
| 1308 |
"IqnPrefix": "iqn.myprefix." |
| 1309 |
}, |
| 1310 |
"InitiatorIpPoolSettings": { |
| 1311 |
"IpRange": "10.33.0.1-10.33.0.255", |
| 1312 |
"SubnetMask": "XXX.XXX.XXX.XXX", |
| 1313 |
"Gateway": "192.168.4.1", |
| 1314 |
"PrimaryDnsServer": "10.8.8.8", |
| 1315 |
"SecondaryDnsServer": "8.8.8.8" |
| 1316 |
} |
| 1317 |
}} |
| 1318 |
|
| 1319 |
def test_update_iscsi_specific_settings_case2(self): |
| 1320 |
setting_type = "IscsiSettings" |
| 1321 |
payload = {"Name": "pool_new", "Description": "description"} |
| 1322 |
settings_params = { |
| 1323 |
"initiator_ip_pool_settings": { |
| 1324 |
"gateway": "192.168.4.1", |
| 1325 |
"ip_range": "10.33.0.1-10.33.0.255", |
| 1326 |
"subnet_mask": "XXX.XXX.XXX.XXX" |
| 1327 |
} |
| 1328 |
} |
| 1329 |
self.module.update_iscsi_specific_settings(payload, settings_params, setting_type) |
| 1330 |
assert payload == { |
| 1331 |
"Name": "pool_new", "Description": "description", |
| 1332 |
"IscsiSettings": { |
| 1333 |
"InitiatorIpPoolSettings": { |
| 1334 |
"IpRange": "10.33.0.1-10.33.0.255", |
| 1335 |
"SubnetMask": "XXX.XXX.XXX.XXX", |
| 1336 |
"Gateway": "192.168.4.1" |
| 1337 |
} |
| 1338 |
}} |