| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
"""Unit Tests for info module on PowerFlex""" |
| 6 |
|
| 7 |
from __future__ import (absolute_import, division, print_function) |
| 8 |
|
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
import pytest |
| 12 |
|
| 13 |
from ansible_collections.dellemc.powerflex.tests.unit.plugins.module_utils.libraries import initial_mock |
| 14 |
from mock.mock import MagicMock |
| 15 |
from ansible_collections.dellemc.powerflex.tests.unit.plugins.module_utils.mock_info_api import MockInfoApi |
| 16 |
from ansible_collections.dellemc.powerflex.tests.unit.plugins.module_utils.mock_fault_set_api import MockFaultSetApi |
| 17 |
from ansible_collections.dellemc.powerflex.tests.unit.plugins.module_utils.mock_api_exception \ |
| 18 |
import MockApiException |
| 19 |
from ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell \ |
| 20 |
import utils |
| 21 |
from ansible_collections.dellemc.powerflex.tests.unit.plugins.module_utils.mock_fail_json \ |
| 22 |
import FailJsonException, fail_json |
| 23 |
|
| 24 |
utils.get_logger = MagicMock() |
| 25 |
utils.get_powerflex_gateway_host_connection = MagicMock() |
| 26 |
utils.PowerFlexClient = MagicMock() |
| 27 |
utils.filter_response = MagicMock() |
| 28 |
|
| 29 |
from ansible.module_utils import basic |
| 30 |
basic.AnsibleModule = MagicMock() |
| 31 |
from ansible_collections.dellemc.powerflex.plugins.modules.info import PowerFlexInfo, get_powerflex_info_parameters |
| 32 |
INVALID_SORT_MSG = 'messageCode=PARSE002 displayMessage=An invalid column name: invalid is entered in the sort list' |
| 33 |
|
| 34 |
|
| 35 |
class TestPowerflexInfo(): |
| 36 |
|
| 37 |
get_module_args = MockInfoApi.INFO_COMMON_ARGS |
| 38 |
|
| 39 |
@pytest.fixture |
| 40 |
def info_module_mock(self, mocker): |
| 41 |
mocker.patch( |
| 42 |
MockInfoApi.MODULE_UTILS_PATH + '.PowerFlexClient', |
| 43 |
new=MockApiException) |
| 44 |
utils.is_version_less = MagicMock(return_value=True) |
| 45 |
utils.is_version_ge_or_eq = MagicMock(return_value=False) |
| 46 |
info_module_mock = PowerFlexInfo() |
| 47 |
info_module_mock.module.argument_spec = get_powerflex_info_parameters() |
| 48 |
info_module_mock.module.check_mode = False |
| 49 |
info_module_mock.powerflex_conn.system.get = MagicMock( |
| 50 |
return_value=MockInfoApi.INFO_ARRAY_DETAILS |
| 51 |
) |
| 52 |
info_module_mock.module.fail_json = fail_json |
| 53 |
return info_module_mock |
| 54 |
|
| 55 |
def capture_fail_json_call(self, error_msg, info_module_mock): |
| 56 |
try: |
| 57 |
info_module_mock.perform_module_operation() |
| 58 |
except FailJsonException as fj_object: |
| 59 |
assert error_msg in fj_object.message |
| 60 |
|
| 61 |
def test_get_volume_details(self, info_module_mock): |
| 62 |
self.get_module_args.update({ |
| 63 |
"gather_subset": ['vol'] |
| 64 |
}) |
| 65 |
info_module_mock.module.params = self.get_module_args |
| 66 |
volume_resp = MockInfoApi.INFO_VOLUME_GET_LIST |
| 67 |
info_module_mock.powerflex_conn.volume.get = MagicMock( |
| 68 |
return_value=volume_resp |
| 69 |
) |
| 70 |
volume_stat_resp = MockInfoApi.INFO_VOLUME_STATISTICS |
| 71 |
info_module_mock.powerflex_conn.utility.get_statistics_for_all_volumes = MagicMock( |
| 72 |
return_value=volume_stat_resp |
| 73 |
) |
| 74 |
info_module_mock.perform_module_operation() |
| 75 |
info_module_mock.powerflex_conn.volume.get.assert_called() |
| 76 |
info_module_mock.powerflex_conn.utility.get_statistics_for_all_volumes.assert_called() |
| 77 |
|
| 78 |
def test_get_volume_details_filter(self, info_module_mock): |
| 79 |
self.get_module_args.update({ |
| 80 |
"gather_subset": ['vol'], |
| 81 |
"filters": [{ |
| 82 |
"filter_key": "storagePoolId", |
| 83 |
"filter_operator": "equal", |
| 84 |
"filter_value": "test_pool_id_1" |
| 85 |
}] |
| 86 |
}) |
| 87 |
info_module_mock.module.params = self.get_module_args |
| 88 |
vol_resp = MockInfoApi.INFO_VOLUME_GET_LIST |
| 89 |
info_module_mock.powerflex_conn.volume.get = MagicMock( |
| 90 |
return_value=vol_resp |
| 91 |
) |
| 92 |
info_module_mock.perform_module_operation() |
| 93 |
info_module_mock.powerflex_conn.volume.get.assert_called() |
| 94 |
|
| 95 |
def test_get_volume_details_with_exception(self, info_module_mock): |
| 96 |
self.get_module_args.update({ |
| 97 |
"gather_subset": ['vol'] |
| 98 |
}) |
| 99 |
info_module_mock.module.params = self.get_module_args |
| 100 |
volume_resp = MockInfoApi.INFO_VOLUME_GET_LIST |
| 101 |
info_module_mock.powerflex_conn.volume.get = MagicMock( |
| 102 |
return_value=volume_resp |
| 103 |
) |
| 104 |
info_module_mock.powerflex_conn.utility.get_statistics_for_all_volumes = MagicMock( |
| 105 |
side_effect=MockApiException |
| 106 |
) |
| 107 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 108 |
'volume_get_details'), info_module_mock) |
| 109 |
|
| 110 |
def test_get_sp_details(self, info_module_mock): |
| 111 |
self.get_module_args.update({ |
| 112 |
"gather_subset": ['storage_pool'] |
| 113 |
}) |
| 114 |
info_module_mock.module.params = self.get_module_args |
| 115 |
sp_resp = MockInfoApi.INFO_STORAGE_POOL_GET_LIST |
| 116 |
info_module_mock.powerflex_conn.storage_pool.get = MagicMock( |
| 117 |
return_value=sp_resp |
| 118 |
) |
| 119 |
sp_stat_resp = MockInfoApi.INFO_STORAGE_POOL_STATISTICS |
| 120 |
info_module_mock.powerflex_conn.utility.get_statistics_for_all_storagepools = MagicMock( |
| 121 |
return_value=sp_stat_resp |
| 122 |
) |
| 123 |
info_module_mock.perform_module_operation() |
| 124 |
info_module_mock.powerflex_conn.storage_pool.get.assert_called() |
| 125 |
info_module_mock.powerflex_conn.utility.get_statistics_for_all_storagepools.assert_called() |
| 126 |
|
| 127 |
def test_get_sp_details_filter(self, info_module_mock): |
| 128 |
self.get_module_args.update({ |
| 129 |
"gather_subset": ['storage_pool'], |
| 130 |
"filters": [{ |
| 131 |
"filter_key": "id", |
| 132 |
"filter_operator": "equal", |
| 133 |
"filter_value": "test_pool_id_1" |
| 134 |
}] |
| 135 |
}) |
| 136 |
info_module_mock.module.params = self.get_module_args |
| 137 |
storage_pool_resp = MockInfoApi.INFO_STORAGE_POOL_GET_LIST |
| 138 |
info_module_mock.powerflex_conn.storage_pool.get = MagicMock( |
| 139 |
return_value=storage_pool_resp |
| 140 |
) |
| 141 |
info_module_mock.perform_module_operation() |
| 142 |
info_module_mock.powerflex_conn.storage_pool.get.assert_called() |
| 143 |
|
| 144 |
def test_get_sp_details_with_exception(self, info_module_mock): |
| 145 |
self.get_module_args.update({ |
| 146 |
"gather_subset": ['storage_pool'] |
| 147 |
}) |
| 148 |
info_module_mock.module.params = self.get_module_args |
| 149 |
sp_resp = MockInfoApi.INFO_STORAGE_POOL_GET_LIST |
| 150 |
info_module_mock.powerflex_conn.storage_pool.get = MagicMock( |
| 151 |
return_value=sp_resp |
| 152 |
) |
| 153 |
info_module_mock.powerflex_conn.utility.get_statistics_for_all_storagepools = MagicMock( |
| 154 |
side_effect=MockApiException |
| 155 |
) |
| 156 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 157 |
'sp_get_details'), info_module_mock) |
| 158 |
|
| 159 |
def test_get_rcg_details(self, info_module_mock): |
| 160 |
self.get_module_args.update({ |
| 161 |
"gather_subset": ['rcg'] |
| 162 |
}) |
| 163 |
info_module_mock.module.params = self.get_module_args |
| 164 |
rcg_resp = MockInfoApi.RCG_LIST |
| 165 |
info_module_mock.powerflex_conn.replication_consistency_group.get = MagicMock( |
| 166 |
return_value=rcg_resp) |
| 167 |
info_module_mock.perform_module_operation() |
| 168 |
info_module_mock.powerflex_conn.replication_consistency_group.get.assert_called() |
| 169 |
|
| 170 |
def test_get_rcg_filter_details(self, info_module_mock): |
| 171 |
self.get_module_args.update({ |
| 172 |
"gather_subset": ['rcg'], |
| 173 |
"filters": [{ |
| 174 |
"filter_key": "id", |
| 175 |
"filter_operator": "equal", |
| 176 |
"filter_value": "aadc17d500000000" |
| 177 |
}] |
| 178 |
}) |
| 179 |
info_module_mock.module.params = self.get_module_args |
| 180 |
rcg_resp = MockInfoApi.RCG_LIST |
| 181 |
info_module_mock.powerflex_conn.replication_consistency_group.get = MagicMock( |
| 182 |
return_value=rcg_resp) |
| 183 |
info_module_mock.perform_module_operation() |
| 184 |
info_module_mock.powerflex_conn.replication_consistency_group.get.assert_called() |
| 185 |
|
| 186 |
def test_get_rcg_details_throws_exception(self, info_module_mock): |
| 187 |
self.get_module_args.update({ |
| 188 |
"gather_subset": ['rcg'] |
| 189 |
}) |
| 190 |
info_module_mock.module.params = self.get_module_args |
| 191 |
info_module_mock.powerflex_conn.replication_consistency_group.get = MagicMock( |
| 192 |
side_effect=MockApiException |
| 193 |
) |
| 194 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 195 |
'rcg_get_details'), info_module_mock) |
| 196 |
|
| 197 |
def test_get_replication_pair_details(self, info_module_mock): |
| 198 |
self.get_module_args.update({ |
| 199 |
"gather_subset": ['replication_pair'] |
| 200 |
}) |
| 201 |
info_module_mock.module.params = self.get_module_args |
| 202 |
info_module_mock.powerflex_conn.replication_pair.get = MagicMock( |
| 203 |
return_value=MockInfoApi.PAIR_LIST) |
| 204 |
info_module_mock.perform_module_operation() |
| 205 |
info_module_mock.powerflex_conn.replication_pair.get.assert_called() |
| 206 |
|
| 207 |
def test_get_replication_pair_details_throws_exception(self, info_module_mock): |
| 208 |
self.get_module_args.update({ |
| 209 |
"gather_subset": ['replication_pair'] |
| 210 |
}) |
| 211 |
info_module_mock.module.params = self.get_module_args |
| 212 |
info_module_mock.powerflex_conn.replication_pair.get = MagicMock( |
| 213 |
side_effect=MockApiException |
| 214 |
) |
| 215 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 216 |
'replication_pair_get_details'), info_module_mock) |
| 217 |
|
| 218 |
def test_get_snapshot_policy_details(self, info_module_mock): |
| 219 |
self.get_module_args.update({ |
| 220 |
"gather_subset": ['snapshot_policy'] |
| 221 |
}) |
| 222 |
info_module_mock.module.params = self.get_module_args |
| 223 |
snapshot_policy_resp = MockInfoApi.INFO_SNAPSHOT_POLICY_GET_LIST |
| 224 |
info_module_mock.powerflex_conn.snapshot_policy.get = MagicMock( |
| 225 |
return_value=snapshot_policy_resp |
| 226 |
) |
| 227 |
snapshot_policy_stat_resp = MockInfoApi.INFO_SNAPSHOT_POLICY_STATISTICS |
| 228 |
info_module_mock.powerflex_conn.utility.get_statistics_for_all_snapshot_policies = MagicMock( |
| 229 |
return_value=snapshot_policy_stat_resp |
| 230 |
) |
| 231 |
info_module_mock.perform_module_operation() |
| 232 |
info_module_mock.powerflex_conn.snapshot_policy.get.assert_called() |
| 233 |
info_module_mock.powerflex_conn.utility.get_statistics_for_all_snapshot_policies.assert_called() |
| 234 |
|
| 235 |
def test_get_snapshot_policy_details_with_exception(self, info_module_mock): |
| 236 |
self.get_module_args.update({ |
| 237 |
"gather_subset": ['snapshot_policy'] |
| 238 |
}) |
| 239 |
info_module_mock.module.params = self.get_module_args |
| 240 |
snapshot_policy_resp = MockInfoApi.INFO_SNAPSHOT_POLICY_GET_LIST |
| 241 |
info_module_mock.powerflex_conn.snapshot_policy.get = MagicMock( |
| 242 |
return_value=snapshot_policy_resp |
| 243 |
) |
| 244 |
info_module_mock.powerflex_conn.utility.get_statistics_for_all_snapshot_policies = MagicMock( |
| 245 |
side_effect=MockApiException |
| 246 |
) |
| 247 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 248 |
'snapshot_policy_get_details'), info_module_mock) |
| 249 |
|
| 250 |
def test_get_sdc_details(self, info_module_mock): |
| 251 |
self.get_module_args.update({ |
| 252 |
"gather_subset": ['sdc'] |
| 253 |
}) |
| 254 |
info_module_mock.module.params = self.get_module_args |
| 255 |
sdc_resp = MockInfoApi.INFO_SDC_FILTER_LIST |
| 256 |
info_module_mock.powerflex_conn.sdc.get = MagicMock( |
| 257 |
return_value=sdc_resp |
| 258 |
) |
| 259 |
info_module_mock.perform_module_operation() |
| 260 |
info_module_mock.powerflex_conn.sdc.get.assert_called() |
| 261 |
|
| 262 |
def test_get_sdc_details_filter(self, info_module_mock): |
| 263 |
self.get_module_args.update({ |
| 264 |
"gather_subset": ['sdc'], |
| 265 |
"filters": [{ |
| 266 |
"filter_key": "name", |
| 267 |
"filter_operator": "equal", |
| 268 |
"filter_value": "sdc_1" |
| 269 |
}] |
| 270 |
}) |
| 271 |
info_module_mock.module.params = self.get_module_args |
| 272 |
sdc_resp = MockInfoApi.INFO_SDC_FILTER_LIST |
| 273 |
info_module_mock.powerflex_conn.sdc.create = MagicMock( |
| 274 |
return_value=sdc_resp |
| 275 |
) |
| 276 |
info_module_mock.perform_module_operation() |
| 277 |
info_module_mock.powerflex_conn.sdc.get.assert_called() |
| 278 |
|
| 279 |
def test_get_sdc_details_exception(self, info_module_mock): |
| 280 |
self.get_module_args.update({ |
| 281 |
"gather_subset": ['sdc'] |
| 282 |
}) |
| 283 |
info_module_mock.module.params = self.get_module_args |
| 284 |
info_module_mock.powerflex_conn.sdc.get = MagicMock( |
| 285 |
side_effect=MockApiException |
| 286 |
) |
| 287 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 288 |
'sdc_get_details'), info_module_mock) |
| 289 |
|
| 290 |
def test_get_sds_details(self, info_module_mock): |
| 291 |
self.get_module_args.update({ |
| 292 |
"gather_subset": ['sds'] |
| 293 |
}) |
| 294 |
info_module_mock.module.params = self.get_module_args |
| 295 |
sds_resp = MockInfoApi.INFO_SDS_GET_LIST |
| 296 |
info_module_mock.powerflex_conn.sds.get = MagicMock( |
| 297 |
return_value=sds_resp |
| 298 |
) |
| 299 |
info_module_mock.perform_module_operation() |
| 300 |
info_module_mock.powerflex_conn.sds.get.assert_called() |
| 301 |
|
| 302 |
def test_get_sds_filter_details(self, info_module_mock): |
| 303 |
self.get_module_args.update({ |
| 304 |
"gather_subset": ['sds'], |
| 305 |
"filters": [ |
| 306 |
{ |
| 307 |
"filter_key": "name", |
| 308 |
"filter_operator": "equal", |
| 309 |
"filter_value": "node0", |
| 310 |
}, |
| 311 |
{ |
| 312 |
"filter_key": "name", |
| 313 |
"filter_operator": "equal", |
| 314 |
"filter_value": "node1", |
| 315 |
}, |
| 316 |
{ |
| 317 |
"filter_key": "id", |
| 318 |
"filter_operator": "equal", |
| 319 |
"filter_value": "8f3bb15300000001", |
| 320 |
} |
| 321 |
] |
| 322 |
}) |
| 323 |
info_module_mock.module.params = self.get_module_args |
| 324 |
sds_resp = MockInfoApi.INFO_SDS_GET_LIST |
| 325 |
info_module_mock.powerflex_conn.sds.get = MagicMock( |
| 326 |
return_value=sds_resp |
| 327 |
) |
| 328 |
info_module_mock.perform_module_operation() |
| 329 |
info_module_mock.powerflex_conn.sds.get.assert_called() |
| 330 |
|
| 331 |
def test_get_sds_details_filter_invalid(self, info_module_mock): |
| 332 |
self.get_module_args.update({ |
| 333 |
"gather_subset": ['sds'], |
| 334 |
"filters": [{ |
| 335 |
"filter_key": "name", |
| 336 |
"filter_op": "equal", |
| 337 |
"filter_value": "LGLAP203", |
| 338 |
}] |
| 339 |
}) |
| 340 |
info_module_mock.module.params = self.get_module_args |
| 341 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 342 |
'get_sds_details_filter_invalid'), info_module_mock) |
| 343 |
|
| 344 |
def test_get_sds_details_filter_empty(self, info_module_mock): |
| 345 |
self.get_module_args.update({ |
| 346 |
"gather_subset": ['sds'], |
| 347 |
"filters": [{ |
| 348 |
"filter_key": "name", |
| 349 |
"filter_operator": None, |
| 350 |
"filter_value": "LGLAP203", |
| 351 |
}] |
| 352 |
}) |
| 353 |
info_module_mock.module.params = self.get_module_args |
| 354 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 355 |
'get_sds_details_filter_empty'), info_module_mock) |
| 356 |
|
| 357 |
def test_get_sds_details_exception(self, info_module_mock): |
| 358 |
self.get_module_args.update({ |
| 359 |
"gather_subset": ['sds'] |
| 360 |
}) |
| 361 |
info_module_mock.module.params = self.get_module_args |
| 362 |
info_module_mock.powerflex_conn.sds.get = MagicMock( |
| 363 |
side_effect=MockApiException |
| 364 |
) |
| 365 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 366 |
'sds_get_details'), info_module_mock) |
| 367 |
|
| 368 |
def test_get_pd_details(self, info_module_mock): |
| 369 |
self.get_module_args.update({ |
| 370 |
"gather_subset": ['protection_domain'] |
| 371 |
}) |
| 372 |
info_module_mock.module.params = self.get_module_args |
| 373 |
pd_resp = MockInfoApi.INFO_GET_PD_LIST |
| 374 |
info_module_mock.powerflex_conn.protection_domain.get = MagicMock( |
| 375 |
return_value=pd_resp |
| 376 |
) |
| 377 |
info_module_mock.perform_module_operation() |
| 378 |
info_module_mock.powerflex_conn.protection_domain.get.assert_called() |
| 379 |
|
| 380 |
def test_get_pd_filter_details(self, info_module_mock): |
| 381 |
self.get_module_args.update({ |
| 382 |
"gather_subset": ['protection_domain'], |
| 383 |
"filters": [{ |
| 384 |
"filter_key": "name", |
| 385 |
"filter_operator": "equal", |
| 386 |
"filter_value": "domain1", |
| 387 |
}] |
| 388 |
}) |
| 389 |
info_module_mock.module.params = self.get_module_args |
| 390 |
pd_resp = MockInfoApi.INFO_GET_PD_LIST |
| 391 |
info_module_mock.powerflex_conn.protection_domain.get = MagicMock( |
| 392 |
return_value=pd_resp |
| 393 |
) |
| 394 |
info_module_mock.perform_module_operation() |
| 395 |
info_module_mock.powerflex_conn.protection_domain.get.assert_called() |
| 396 |
|
| 397 |
def test_get_pd_details_exception(self, info_module_mock): |
| 398 |
self.get_module_args.update({ |
| 399 |
"gather_subset": ['protection_domain'] |
| 400 |
}) |
| 401 |
info_module_mock.module.params = self.get_module_args |
| 402 |
info_module_mock.powerflex_conn.protection_domain.get = MagicMock( |
| 403 |
side_effect=MockApiException |
| 404 |
) |
| 405 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 406 |
'pd_get_details'), info_module_mock) |
| 407 |
|
| 408 |
def test_get_device_details(self, info_module_mock): |
| 409 |
self.get_module_args.update({ |
| 410 |
"gather_subset": ['device'] |
| 411 |
}) |
| 412 |
info_module_mock.module.params = self.get_module_args |
| 413 |
device_resp = MockInfoApi.INFO_GET_DEVICE_LIST |
| 414 |
info_module_mock.powerflex_conn.device.get = MagicMock( |
| 415 |
return_value=device_resp |
| 416 |
) |
| 417 |
info_module_mock.perform_module_operation() |
| 418 |
info_module_mock.powerflex_conn.device.get.assert_called() |
| 419 |
|
| 420 |
def test_get_device_filter_details(self, info_module_mock): |
| 421 |
self.get_module_args.update({ |
| 422 |
"gather_subset": ['device'], |
| 423 |
"filters": [{ |
| 424 |
"filter_key": "name", |
| 425 |
"filter_operator": "equal", |
| 426 |
"filter_value": "device230", |
| 427 |
}] |
| 428 |
}) |
| 429 |
info_module_mock.module.params = self.get_module_args |
| 430 |
device_resp = MockInfoApi.INFO_GET_DEVICE_LIST |
| 431 |
info_module_mock.powerflex_conn.device.get = MagicMock( |
| 432 |
return_value=device_resp |
| 433 |
) |
| 434 |
info_module_mock.perform_module_operation() |
| 435 |
info_module_mock.powerflex_conn.device.get.assert_called() |
| 436 |
|
| 437 |
def test_get_device_details_exception(self, info_module_mock): |
| 438 |
self.get_module_args.update({ |
| 439 |
"gather_subset": ['device'] |
| 440 |
}) |
| 441 |
info_module_mock.module.params = self.get_module_args |
| 442 |
info_module_mock.powerflex_conn.device.get = MagicMock( |
| 443 |
side_effect=MockApiException |
| 444 |
) |
| 445 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 446 |
'device_get_details'), info_module_mock) |
| 447 |
|
| 448 |
def test_get_fault_set_details(self, info_module_mock): |
| 449 |
self.get_module_args.update({ |
| 450 |
"gather_subset": ['fault_set'] |
| 451 |
}) |
| 452 |
info_module_mock.module.params = self.get_module_args |
| 453 |
pd_resp = MockFaultSetApi.PROTECTION_DOMAIN |
| 454 |
info_module_mock.powerflex_conn.protection_domain.get = MagicMock( |
| 455 |
return_value=pd_resp['protectiondomain']) |
| 456 |
fault_set_resp = MockInfoApi.INFO_GET_FAULT_SET_LIST |
| 457 |
info_module_mock.powerflex_conn.fault_set.get = MagicMock( |
| 458 |
return_value=fault_set_resp |
| 459 |
) |
| 460 |
info_module_mock.perform_module_operation() |
| 461 |
info_module_mock.powerflex_conn.fault_set.get.assert_called() |
| 462 |
|
| 463 |
def test_get_fault_set_details_exception(self, info_module_mock): |
| 464 |
self.get_module_args.update({ |
| 465 |
"gather_subset": ['fault_set'] |
| 466 |
}) |
| 467 |
info_module_mock.module.params = self.get_module_args |
| 468 |
info_module_mock.powerflex_conn.fault_set.get = MagicMock( |
| 469 |
side_effect=MockApiException |
| 470 |
) |
| 471 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 472 |
'fault_set_get_details'), info_module_mock) |
| 473 |
|
| 474 |
def test_get_fault_set_details_invalid_filter_operator_exception(self, info_module_mock): |
| 475 |
self.get_module_args.update({ |
| 476 |
"gather_subset": ['fault_set'], |
| 477 |
"filters": [{ |
| 478 |
"filter_key": "name", |
| 479 |
"filter_operator": "does_not_contain", |
| 480 |
"filter_value": "LGLAP203", |
| 481 |
}] |
| 482 |
}) |
| 483 |
info_module_mock.module.params = self.get_module_args |
| 484 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 485 |
'invalid_filter_operator_exception'), info_module_mock) |
| 486 |
|
| 487 |
def test_get_fault_set_details_api_exception(self, info_module_mock): |
| 488 |
self.get_module_args.update({ |
| 489 |
"gather_subset": ['fault_set'] |
| 490 |
}) |
| 491 |
info_module_mock.module.params = self.get_module_args |
| 492 |
info_module_mock.powerflex_conn.system.api_version = MagicMock( |
| 493 |
side_effect=MockApiException |
| 494 |
) |
| 495 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 496 |
'api_exception'), info_module_mock) |
| 497 |
|
| 498 |
def test_get_fault_set_details_system_exception(self, info_module_mock): |
| 499 |
self.get_module_args.update({ |
| 500 |
"gather_subset": ['fault_set'] |
| 501 |
}) |
| 502 |
info_module_mock.module.params = self.get_module_args |
| 503 |
info_module_mock.powerflex_conn.system.get = MagicMock( |
| 504 |
side_effect=MockApiException |
| 505 |
) |
| 506 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 507 |
'system_exception'), info_module_mock) |
| 508 |
|
| 509 |
def test_get_managed_device_details(self, info_module_mock): |
| 510 |
self.get_module_args.update({ |
| 511 |
"gather_subset": ['managed_device'] |
| 512 |
}) |
| 513 |
info_module_mock.module.params = self.get_module_args |
| 514 |
info_module_mock.powerflex_conn.managed_device.get = MagicMock() |
| 515 |
info_module_mock.perform_module_operation() |
| 516 |
info_module_mock.powerflex_conn.managed_device.get.assert_called() |
| 517 |
|
| 518 |
def test_get_managed_device_details_throws_exception(self, info_module_mock): |
| 519 |
self.get_module_args.update({ |
| 520 |
"gather_subset": ['managed_device'] |
| 521 |
}) |
| 522 |
info_module_mock.module.params = self.get_module_args |
| 523 |
info_module_mock.powerflex_conn.managed_device.get = MagicMock( |
| 524 |
side_effect=MockApiException |
| 525 |
) |
| 526 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 527 |
'managed_device_get_error'), info_module_mock) |
| 528 |
|
| 529 |
def test_get_service_template_details(self, info_module_mock): |
| 530 |
self.get_module_args.update({ |
| 531 |
"gather_subset": ['service_template'] |
| 532 |
}) |
| 533 |
info_module_mock.module.params = self.get_module_args |
| 534 |
info_module_mock.powerflex_conn.service_template.get = MagicMock() |
| 535 |
info_module_mock.perform_module_operation() |
| 536 |
info_module_mock.powerflex_conn.service_template.get.assert_called() |
| 537 |
|
| 538 |
def test_get_service_template_details_throws_exception(self, info_module_mock): |
| 539 |
self.get_module_args.update({ |
| 540 |
"gather_subset": ['service_template'] |
| 541 |
}) |
| 542 |
info_module_mock.module.params = self.get_module_args |
| 543 |
info_module_mock.powerflex_conn.service_template.get = MagicMock( |
| 544 |
side_effect=MockApiException |
| 545 |
) |
| 546 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 547 |
'service_template_get_error'), info_module_mock) |
| 548 |
|
| 549 |
def test_get_deployment_details(self, info_module_mock): |
| 550 |
self.get_module_args.update({ |
| 551 |
"gather_subset": ['deployment'], |
| 552 |
"limit": 20 |
| 553 |
}) |
| 554 |
info_module_mock.module.params = self.get_module_args |
| 555 |
info_module_mock.powerflex_conn.deployment.get = MagicMock() |
| 556 |
info_module_mock.perform_module_operation() |
| 557 |
info_module_mock.powerflex_conn.deployment.get.assert_called() |
| 558 |
|
| 559 |
def test_get_deployment_details_throws_exception(self, info_module_mock): |
| 560 |
self.get_module_args.update({ |
| 561 |
"gather_subset": ['deployment'] |
| 562 |
}) |
| 563 |
info_module_mock.module.params = self.get_module_args |
| 564 |
info_module_mock.powerflex_conn.deployment.get = MagicMock( |
| 565 |
side_effect=MockApiException |
| 566 |
) |
| 567 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 568 |
'deployment_get_error'), info_module_mock) |
| 569 |
|
| 570 |
def test_get_deployment_details_throws_exception_invalid_sort(self, info_module_mock): |
| 571 |
self.get_module_args.update({ |
| 572 |
"gather_subset": ['deployment'], |
| 573 |
"sort": 'invalid' |
| 574 |
}) |
| 575 |
info_module_mock.module.params = self.get_module_args |
| 576 |
info_module_mock.powerflex_conn.deployment.get = MagicMock( |
| 577 |
side_effect=MockApiException(INVALID_SORT_MSG) |
| 578 |
) |
| 579 |
info_module_mock.perform_module_operation() |
| 580 |
assert info_module_mock.get_deployments_list() == [] |
| 581 |
|
| 582 |
def test_get_with_multiple_gather_subset(self, info_module_mock): |
| 583 |
self.get_module_args.update({ |
| 584 |
"gather_subset": ['deployment', 'service_template'], |
| 585 |
"sort": 'name', "filters": [{"filter_key": "name", "filter_operator": "equal", "filter_value": "rack"}], |
| 586 |
}) |
| 587 |
info_module_mock.module.params = self.get_module_args |
| 588 |
info_module_mock.perform_module_operation() |
| 589 |
assert info_module_mock.populate_filter_list() == [] |
| 590 |
assert info_module_mock.get_param_value('sort') is None |
| 591 |
|
| 592 |
def test_get_with_invalid_offset_and_limit_for_subset(self, info_module_mock): |
| 593 |
self.get_module_args.update({ |
| 594 |
"gather_subset": ['deployment'], |
| 595 |
"limit": -1, "offset": -1 |
| 596 |
}) |
| 597 |
info_module_mock.module.params = self.get_module_args |
| 598 |
info_module_mock.perform_module_operation() |
| 599 |
assert info_module_mock.get_param_value('limit') is None |
| 600 |
assert info_module_mock.get_param_value('offset') is None |
| 601 |
|
| 602 |
def test_get_firmware_repository_details(self, info_module_mock): |
| 603 |
self.get_module_args.update({ |
| 604 |
"gather_subset": ['firmware_repository'], |
| 605 |
"limit": 20 |
| 606 |
}) |
| 607 |
info_module_mock.module.params = self.get_module_args |
| 608 |
info_module_mock.powerflex_conn.firmware_repository.get = MagicMock() |
| 609 |
info_module_mock.perform_module_operation() |
| 610 |
info_module_mock.powerflex_conn.firmware_repository.get.assert_called() |
| 611 |
|
| 612 |
def test_get_deployment_details_throws_exception(self, info_module_mock): |
| 613 |
self.get_module_args.update({ |
| 614 |
"gather_subset": ['firmware_repository'] |
| 615 |
}) |
| 616 |
info_module_mock.module.params = self.get_module_args |
| 617 |
info_module_mock.powerflex_conn.firmware_repository.get = MagicMock( |
| 618 |
side_effect=MockApiException |
| 619 |
) |
| 620 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 621 |
'firmware_repository_get_error'), info_module_mock) |
| 622 |
|
| 623 |
def test_get_nvme_host_details(self, info_module_mock): |
| 624 |
self.get_module_args.update({ |
| 625 |
"gather_subset": ['nvme_host'] |
| 626 |
}) |
| 627 |
info_module_mock.module.params = self.get_module_args |
| 628 |
nvme_host_resp = MockInfoApi.INFO_NVME_HOST_LIST |
| 629 |
info_module_mock.powerflex_conn.sdc.get = MagicMock( |
| 630 |
return_value=nvme_host_resp |
| 631 |
) |
| 632 |
info_module_mock.perform_module_operation() |
| 633 |
info_module_mock.powerflex_conn.sdc.get.assert_called() |
| 634 |
|
| 635 |
def test_get_nvme_host_details_filter(self, info_module_mock): |
| 636 |
self.get_module_args.update({ |
| 637 |
"gather_subset": ['nvme_host'], |
| 638 |
"filters": [{ |
| 639 |
"filter_key": "name", |
| 640 |
"filter_operator": "equal", |
| 641 |
"filter_value": "fake_host_name_1" |
| 642 |
}] |
| 643 |
}) |
| 644 |
info_module_mock.module.params = self.get_module_args |
| 645 |
nvme_host_resp = MockInfoApi.INFO_SDC_FILTER_LIST |
| 646 |
info_module_mock.powerflex_conn.sdc.get = MagicMock( |
| 647 |
return_value=nvme_host_resp |
| 648 |
) |
| 649 |
info_module_mock.perform_module_operation() |
| 650 |
info_module_mock.powerflex_conn.sdc.get.assert_called() |
| 651 |
|
| 652 |
def test_get_nvme_host_details_exception(self, info_module_mock): |
| 653 |
self.get_module_args.update({ |
| 654 |
"gather_subset": ['nvme_host'] |
| 655 |
}) |
| 656 |
info_module_mock.module.params = self.get_module_args |
| 657 |
info_module_mock.powerflex_conn.sdc.get = MagicMock( |
| 658 |
side_effect=MockApiException |
| 659 |
) |
| 660 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 661 |
'nvme_host_get_details'), info_module_mock) |
| 662 |
|
| 663 |
def test_get_sdt_details(self, info_module_mock): |
| 664 |
self.get_module_args.update({ |
| 665 |
"gather_subset": ['sdt'] |
| 666 |
}) |
| 667 |
info_module_mock.module.params = self.get_module_args |
| 668 |
info_module_mock.powerflex_conn.sdt.get = MagicMock( |
| 669 |
return_value=MockInfoApi.INFO_GET_SDT_LIST |
| 670 |
) |
| 671 |
info_module_mock.powerflex_conn.sdc.get = MagicMock( |
| 672 |
return_value=MockInfoApi.INFO_GET_SDT_NVME_HOST_LIST |
| 673 |
) |
| 674 |
info_module_mock.powerflex_conn.host.get_related = MagicMock( |
| 675 |
return_value=MockInfoApi.INFO_GET_SDT_NVME_CONTROLLER_LIST |
| 676 |
) |
| 677 |
info_module_mock.perform_module_operation() |
| 678 |
info_module_mock.powerflex_conn.sdt.get.assert_called() |
| 679 |
info_module_mock.powerflex_conn.sdc.get.assert_called() |
| 680 |
info_module_mock.powerflex_conn.host.get_related.assert_called() |
| 681 |
|
| 682 |
def test_get_sdt_details_filter(self, info_module_mock): |
| 683 |
self.get_module_args.update({ |
| 684 |
"gather_subset": ['sdt'], |
| 685 |
"filters": [{ |
| 686 |
"filter_key": "name", |
| 687 |
"filter_operator": "equal", |
| 688 |
"filter_value": "sdt-name", |
| 689 |
}] |
| 690 |
}) |
| 691 |
info_module_mock.module.params = self.get_module_args |
| 692 |
info_module_mock.powerflex_conn.sdt.get = MagicMock( |
| 693 |
return_value=MockInfoApi.INFO_GET_SDT_LIST |
| 694 |
) |
| 695 |
info_module_mock.powerflex_conn.sdc.get = MagicMock( |
| 696 |
return_value=MockInfoApi.INFO_GET_SDT_NVME_HOST_LIST |
| 697 |
) |
| 698 |
info_module_mock.powerflex_conn.host.get_related = MagicMock( |
| 699 |
return_value=MockInfoApi.INFO_GET_SDT_NVME_CONTROLLER_LIST |
| 700 |
) |
| 701 |
info_module_mock.perform_module_operation() |
| 702 |
info_module_mock.powerflex_conn.sdt.get.assert_called() |
| 703 |
info_module_mock.powerflex_conn.sdc.get.assert_called() |
| 704 |
info_module_mock.powerflex_conn.host.get_related.assert_called() |
| 705 |
|
| 706 |
def test_get_sdt_details_exception(self, info_module_mock): |
| 707 |
self.get_module_args.update({ |
| 708 |
"gather_subset": ['sdt'] |
| 709 |
}) |
| 710 |
info_module_mock.module.params = self.get_module_args |
| 711 |
info_module_mock.powerflex_conn.sdc.get = MagicMock( |
| 712 |
side_effect=MockApiException |
| 713 |
) |
| 714 |
self.capture_fail_json_call(MockInfoApi.get_exception_response( |
| 715 |
'sdt_get_error'), info_module_mock) |