| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
"""Unit Tests for Device V2 module on PowerFlex""" |
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
|
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
import pytest |
| 12 |
|
| 13 |
|
| 14 |
from ansible_collections.dellemc.powerflex.tests.unit.plugins.module_utils.libraries \ |
| 15 |
import initial_mock |
| 16 |
from mock.mock import MagicMock |
| 17 |
from ansible_collections.dellemc.powerflex.tests.unit.plugins.module_utils.mock_device_api_v2 \ |
| 18 |
import MockDeviceV2Api |
| 19 |
from ansible_collections.dellemc.powerflex.tests.unit.plugins.module_utils.mock_api_exception \ |
| 20 |
import MockApiException |
| 21 |
from ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell import utils |
| 22 |
from ansible_collections.dellemc.powerflex.tests.unit.plugins.module_utils.mock_fail_json import ( |
| 23 |
FailJsonException, |
| 24 |
fail_json, |
| 25 |
) |
| 26 |
from ansible_collections.dellemc.powerflex.plugins.modules.device_v2 import PowerFlexDeviceV2, DeviceHandler |
| 27 |
from ansible.module_utils import basic |
| 28 |
|
| 29 |
utils.get_logger = MagicMock() |
| 30 |
utils.get_powerflex_gateway_host_connection = MagicMock() |
| 31 |
utils.PowerFlexClient = MagicMock() |
| 32 |
basic.AnsibleModule = MagicMock() |
| 33 |
|
| 34 |
|
| 35 |
class TestPowerFlexDeviceV2(): |
| 36 |
|
| 37 |
get_module_args = MockDeviceV2Api.DEVICE_COMMON_ARGS |
| 38 |
|
| 39 |
@pytest.fixture |
| 40 |
def device_module_mock(self, mocker): |
| 41 |
utils.is_version_less = MagicMock(return_value=False) |
| 42 |
utils.is_version_ge_or_eq = MagicMock(return_value=True) |
| 43 |
device_module_mock = PowerFlexDeviceV2() |
| 44 |
device_module_mock.module.check_mode = False |
| 45 |
device_module_mock.module._diff = True |
| 46 |
device_module_mock.module.fail_json = fail_json |
| 47 |
return device_module_mock |
| 48 |
|
| 49 |
def capture_fail_json_call(self, error_msg, device_module_mock): |
| 50 |
try: |
| 51 |
DeviceHandler().handle(device_module_mock, device_module_mock.module.params) |
| 52 |
except FailJsonException as fj_object: |
| 53 |
assert error_msg in fj_object.message |
| 54 |
|
| 55 |
def test_get_device_detail_using_path_storage_node_id(self, device_module_mock): |
| 56 |
self.get_module_args.update({ |
| 57 |
"current_pathname": MockDeviceV2Api.PATH_1, |
| 58 |
"storage_node_id": MockDeviceV2Api.NODE_ID_1, |
| 59 |
"state": "present" |
| 60 |
}) |
| 61 |
device_module_mock.module.params = self.get_module_args |
| 62 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 63 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST) |
| 64 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 65 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 66 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 67 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 68 |
DeviceHandler().handle(device_module_mock, device_module_mock.module.params) |
| 69 |
device_module_mock.powerflex_conn.device.get.assert_called() |
| 70 |
|
| 71 |
def test_get_device_detail_without_state(self, device_module_mock): |
| 72 |
self.get_module_args.update({ |
| 73 |
"current_pathname": MockDeviceV2Api.PATH_1, |
| 74 |
"storage_node_name": MockDeviceV2Api.NODE_NAME_1 |
| 75 |
}) |
| 76 |
device_module_mock.module.params = self.get_module_args |
| 77 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 78 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST) |
| 79 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 80 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 81 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 82 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 83 |
DeviceHandler().handle(device_module_mock, device_module_mock.module.params) |
| 84 |
device_module_mock.powerflex_conn.device.get.assert_called() |
| 85 |
|
| 86 |
def test_get_device_detail_using_path_storage_node_name(self, device_module_mock): |
| 87 |
self.get_module_args.update({ |
| 88 |
"current_pathname": MockDeviceV2Api.PATH_1, |
| 89 |
"storage_node_name": MockDeviceV2Api.NODE_NAME_1, |
| 90 |
"state": "present" |
| 91 |
}) |
| 92 |
device_module_mock.module.params = self.get_module_args |
| 93 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 94 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST) |
| 95 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 96 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 97 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 98 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 99 |
DeviceHandler().handle(device_module_mock, device_module_mock.module.params) |
| 100 |
device_module_mock.powerflex_conn.device.get.assert_called() |
| 101 |
|
| 102 |
def test_get_device_detail_using_dev_id(self, device_module_mock): |
| 103 |
self.get_module_args.update({ |
| 104 |
"device_id": MockDeviceV2Api.DEVICE_ID_1, |
| 105 |
"state": "present" |
| 106 |
}) |
| 107 |
device_module_mock.module.params = self.get_module_args |
| 108 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 109 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST) |
| 110 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 111 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 112 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 113 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 114 |
DeviceHandler().handle(device_module_mock, device_module_mock.module.params) |
| 115 |
device_module_mock.powerflex_conn.device.get.assert_called() |
| 116 |
|
| 117 |
def test_get_device_detail_using_dev_name(self, device_module_mock): |
| 118 |
self.get_module_args.update({ |
| 119 |
"device_id": MockDeviceV2Api.DEVICE_ID_1, |
| 120 |
"state": "present" |
| 121 |
}) |
| 122 |
device_module_mock.module.params = self.get_module_args |
| 123 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 124 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST) |
| 125 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 126 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 127 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 128 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 129 |
DeviceHandler().handle(device_module_mock, device_module_mock.module.params) |
| 130 |
device_module_mock.powerflex_conn.device.get.assert_called() |
| 131 |
|
| 132 |
def test_get_device_exception(self, device_module_mock): |
| 133 |
self.get_module_args.update({ |
| 134 |
"device_id": MockDeviceV2Api.DEVICE_ID_1, |
| 135 |
"state": "present" |
| 136 |
}) |
| 137 |
device_module_mock.module.params = self.get_module_args |
| 138 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 139 |
side_effect=MockApiException) |
| 140 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 141 |
'get_device_exception'), device_module_mock) |
| 142 |
|
| 143 |
def test_create_device(self, device_module_mock): |
| 144 |
self.get_module_args.update({ |
| 145 |
"current_pathname": MockDeviceV2Api.PATH_1, |
| 146 |
"storage_node_id": MockDeviceV2Api.NODE_ID_1, |
| 147 |
"device_group_id": MockDeviceV2Api.DG_ID_1, |
| 148 |
"media_type": "SSD", |
| 149 |
"state": "present" |
| 150 |
}) |
| 151 |
device_module_mock.module.params = self.get_module_args |
| 152 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 153 |
return_value=None) |
| 154 |
device_module_mock.powerflex_conn.device.create = MagicMock( |
| 155 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST[0]) |
| 156 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 157 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 158 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 159 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 160 |
DeviceHandler().handle(device_module_mock, device_module_mock.module.params) |
| 161 |
device_module_mock.powerflex_conn.device.create.assert_called() |
| 162 |
|
| 163 |
def test_create_device_exception(self, device_module_mock): |
| 164 |
self.get_module_args.update({ |
| 165 |
"current_pathname": MockDeviceV2Api.PATH_1, |
| 166 |
"storage_node_id": MockDeviceV2Api.NODE_ID_1, |
| 167 |
"device_group_id": MockDeviceV2Api.DG_ID_1, |
| 168 |
"media_type": "SSD", |
| 169 |
"state": "present" |
| 170 |
}) |
| 171 |
device_module_mock.module.params = self.get_module_args |
| 172 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 173 |
return_value=None) |
| 174 |
device_module_mock.powerflex_conn.device.create = MagicMock( |
| 175 |
side_effect=MockApiException) |
| 176 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 177 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 178 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 179 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 180 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 181 |
'create_device_exception'), device_module_mock) |
| 182 |
|
| 183 |
def test_create_device_force(self, device_module_mock): |
| 184 |
self.get_module_args.update({ |
| 185 |
"current_pathname": MockDeviceV2Api.PATH_1, |
| 186 |
"device_name": MockDeviceV2Api.DEVICE_NAME_1, |
| 187 |
"storage_node_name": MockDeviceV2Api.NODE_NAME_1, |
| 188 |
"device_group_name": MockDeviceV2Api.DG_NAME_1, |
| 189 |
"media_type": "SSD", |
| 190 |
"force": True, |
| 191 |
"state": "present" |
| 192 |
}) |
| 193 |
device_module_mock.module.params = self.get_module_args |
| 194 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 195 |
return_value=None) |
| 196 |
device_module_mock.powerflex_conn.device.create = MagicMock( |
| 197 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST[0]) |
| 198 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 199 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 200 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 201 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 202 |
DeviceHandler().handle(device_module_mock, device_module_mock.module.params) |
| 203 |
device_module_mock.powerflex_conn.device.create.assert_called() |
| 204 |
|
| 205 |
def test_create_device_without_path_exception(self, device_module_mock): |
| 206 |
self.get_module_args.update({ |
| 207 |
"storage_node_id": MockDeviceV2Api.NODE_ID_1, |
| 208 |
"device_group_id": MockDeviceV2Api.DG_ID_1, |
| 209 |
"media_type": "SSD", |
| 210 |
"state": "present" |
| 211 |
}) |
| 212 |
device_module_mock.module.params = self.get_module_args |
| 213 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 214 |
return_value=None) |
| 215 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 216 |
'create_device_without_path'), device_module_mock) |
| 217 |
|
| 218 |
def test_create_device_without_media_type_exception(self, device_module_mock): |
| 219 |
self.get_module_args.update({ |
| 220 |
"current_pathname": MockDeviceV2Api.PATH_1, |
| 221 |
"storage_node_id": MockDeviceV2Api.NODE_ID_1, |
| 222 |
"device_group_id": MockDeviceV2Api.DG_ID_1, |
| 223 |
"state": "present" |
| 224 |
}) |
| 225 |
device_module_mock.module.params = self.get_module_args |
| 226 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 227 |
return_value=None) |
| 228 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 229 |
'create_device_without_media_type'), device_module_mock) |
| 230 |
|
| 231 |
def test_create_device_without_device_group_exception(self, device_module_mock): |
| 232 |
self.get_module_args.update({ |
| 233 |
"current_pathname": MockDeviceV2Api.PATH_1, |
| 234 |
"storage_node_id": MockDeviceV2Api.NODE_ID_1, |
| 235 |
"media_type": "SSD", |
| 236 |
"state": "present" |
| 237 |
}) |
| 238 |
device_module_mock.module.params = self.get_module_args |
| 239 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 240 |
return_value=None) |
| 241 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 242 |
'create_device_without_device_group'), device_module_mock) |
| 243 |
|
| 244 |
def test_create_device_without_storage_node_exception(self, device_module_mock): |
| 245 |
self.get_module_args.update({ |
| 246 |
"current_pathname": MockDeviceV2Api.PATH_1, |
| 247 |
"device_group_id": MockDeviceV2Api.DG_ID_1, |
| 248 |
"media_type": "SSD", |
| 249 |
"state": "present" |
| 250 |
}) |
| 251 |
device_module_mock.module.params = self.get_module_args |
| 252 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 253 |
return_value=None) |
| 254 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 255 |
'create_device_without_node'), device_module_mock) |
| 256 |
|
| 257 |
def test_create_device_with_id_exception(self, device_module_mock): |
| 258 |
self.get_module_args.update({ |
| 259 |
"current_pathname": MockDeviceV2Api.PATH_1, |
| 260 |
"device_id": MockDeviceV2Api.DEVICE_ID_1, |
| 261 |
"storage_node_id": MockDeviceV2Api.NODE_ID_1, |
| 262 |
"device_group_id": MockDeviceV2Api.DG_ID_1, |
| 263 |
"media_type": "SSD", |
| 264 |
"state": "present" |
| 265 |
}) |
| 266 |
device_module_mock.module.params = self.get_module_args |
| 267 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 268 |
return_value=None) |
| 269 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 270 |
'create_device_with_id'), device_module_mock) |
| 271 |
|
| 272 |
def test_create_device_with_empty_name_exception(self, device_module_mock): |
| 273 |
self.get_module_args.update({ |
| 274 |
"device_name": "", |
| 275 |
"current_pathname": MockDeviceV2Api.PATH_1, |
| 276 |
"storage_node_id": MockDeviceV2Api.NODE_ID_1, |
| 277 |
"device_group_id": MockDeviceV2Api.DG_ID_1, |
| 278 |
"media_type": "SSD", |
| 279 |
"state": "present" |
| 280 |
}) |
| 281 |
device_module_mock.module.params = self.get_module_args |
| 282 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 283 |
return_value=None) |
| 284 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 285 |
'create_device_with_empty_name'), device_module_mock) |
| 286 |
|
| 287 |
def test_create_device_with_empty_path_exception(self, device_module_mock): |
| 288 |
self.get_module_args.update({ |
| 289 |
"current_pathname": "", |
| 290 |
"storage_node_id": MockDeviceV2Api.NODE_ID_1, |
| 291 |
"device_group_id": MockDeviceV2Api.DG_ID_1, |
| 292 |
"media_type": "SSD", |
| 293 |
"state": "present" |
| 294 |
}) |
| 295 |
device_module_mock.module.params = self.get_module_args |
| 296 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 297 |
return_value=None) |
| 298 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 299 |
'create_device_without_path'), device_module_mock) |
| 300 |
|
| 301 |
def test_create_device_with_empty_media_type_exception(self, device_module_mock): |
| 302 |
self.get_module_args.update({ |
| 303 |
"current_pathname": MockDeviceV2Api.PATH_1, |
| 304 |
"storage_node_id": MockDeviceV2Api.NODE_ID_1, |
| 305 |
"device_group_id": MockDeviceV2Api.DG_ID_1, |
| 306 |
"media_type": "", |
| 307 |
"state": "present" |
| 308 |
}) |
| 309 |
device_module_mock.module.params = self.get_module_args |
| 310 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 311 |
return_value=None) |
| 312 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 313 |
'create_device_without_media_type'), device_module_mock) |
| 314 |
|
| 315 |
def test_create_device_with_empty_device_group_exception(self, device_module_mock): |
| 316 |
self.get_module_args.update({ |
| 317 |
"current_pathname": MockDeviceV2Api.PATH_1, |
| 318 |
"storage_node_id": MockDeviceV2Api.NODE_ID_1, |
| 319 |
"device_group_name": "", |
| 320 |
"media_type": "SSD", |
| 321 |
"state": "present" |
| 322 |
}) |
| 323 |
device_module_mock.module.params = self.get_module_args |
| 324 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 325 |
return_value=None) |
| 326 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 327 |
'create_device_without_device_group'), device_module_mock) |
| 328 |
|
| 329 |
def test_create_device_with_empty_storage_node_exception(self, device_module_mock): |
| 330 |
self.get_module_args.update({ |
| 331 |
"current_pathname": MockDeviceV2Api.PATH_1, |
| 332 |
"device_group_id": MockDeviceV2Api.DG_ID_1, |
| 333 |
"storage_node_name": "", |
| 334 |
"media_type": "SSD", |
| 335 |
"state": "present" |
| 336 |
}) |
| 337 |
device_module_mock.module.params = self.get_module_args |
| 338 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 339 |
return_value=None) |
| 340 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 341 |
'create_device_without_node'), device_module_mock) |
| 342 |
|
| 343 |
def test_modify_device(self, device_module_mock): |
| 344 |
self.get_module_args.update({ |
| 345 |
"device_name": MockDeviceV2Api.DEVICE_NAME_1, |
| 346 |
"new_device_name": "ansible_device_rename", |
| 347 |
"capacity_limit_gb": 500, |
| 348 |
"clear_error": True, |
| 349 |
"force": True, |
| 350 |
"state": "present" |
| 351 |
}) |
| 352 |
device_module_mock.module.params = self.get_module_args |
| 353 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 354 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST) |
| 355 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 356 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 357 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 358 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 359 |
DeviceHandler().handle(device_module_mock, device_module_mock.module.params) |
| 360 |
device_module_mock.powerflex_conn.device.rename.assert_called() |
| 361 |
device_module_mock.powerflex_conn.device.set_capacity_limit.assert_called() |
| 362 |
device_module_mock.powerflex_conn.device.clear_errors.assert_called() |
| 363 |
|
| 364 |
def test_rename_device_with_empty_name_exception(self, device_module_mock): |
| 365 |
self.get_module_args.update({ |
| 366 |
"device_name": MockDeviceV2Api.DEVICE_NAME_1, |
| 367 |
"new_device_name": "", |
| 368 |
"state": "present" |
| 369 |
}) |
| 370 |
device_module_mock.module.params = self.get_module_args |
| 371 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 372 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST) |
| 373 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 374 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 375 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 376 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 377 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 378 |
'rename_device_with_empty_name'), device_module_mock) |
| 379 |
|
| 380 |
def test_rename_device_exception(self, device_module_mock): |
| 381 |
self.get_module_args.update({ |
| 382 |
"device_name": MockDeviceV2Api.DEVICE_NAME_1, |
| 383 |
"new_device_name": "ansible_device_rename", |
| 384 |
"state": "present" |
| 385 |
}) |
| 386 |
device_module_mock.module.params = self.get_module_args |
| 387 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 388 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST) |
| 389 |
device_module_mock.powerflex_conn.device.rename = MagicMock( |
| 390 |
side_effect=MockApiException) |
| 391 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 392 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 393 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 394 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 395 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 396 |
'rename_exception'), device_module_mock) |
| 397 |
|
| 398 |
def test_delete_device(self, device_module_mock): |
| 399 |
self.get_module_args.update({ |
| 400 |
"device_name": MockDeviceV2Api.DEVICE_NAME_1, |
| 401 |
"state": "absent" |
| 402 |
}) |
| 403 |
device_module_mock.module.params = self.get_module_args |
| 404 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 405 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST) |
| 406 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 407 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 408 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 409 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 410 |
DeviceHandler().handle(device_module_mock, device_module_mock.module.params) |
| 411 |
device_module_mock.powerflex_conn.device.delete.assert_called() |
| 412 |
|
| 413 |
def test_delete_device_exception(self, device_module_mock): |
| 414 |
self.get_module_args.update({ |
| 415 |
"device_name": MockDeviceV2Api.DEVICE_NAME_1, |
| 416 |
"state": "absent" |
| 417 |
}) |
| 418 |
device_module_mock.module.params = self.get_module_args |
| 419 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 420 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST) |
| 421 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 422 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 423 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 424 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 425 |
device_module_mock.powerflex_conn.device.delete = MagicMock( |
| 426 |
side_effect=MockApiException) |
| 427 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 428 |
'delete_exception'), device_module_mock) |
| 429 |
|
| 430 |
def test_get_storage_node_exception(self, device_module_mock): |
| 431 |
self.get_module_args.update({ |
| 432 |
"device_name": MockDeviceV2Api.DEVICE_NAME_1, |
| 433 |
"state": "absent" |
| 434 |
}) |
| 435 |
device_module_mock.module.params = self.get_module_args |
| 436 |
device_module_mock.module.params = self.get_module_args |
| 437 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 438 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST) |
| 439 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 440 |
side_effect=MockApiException) |
| 441 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 442 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 443 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 444 |
'get_storage_node_exception'), device_module_mock) |
| 445 |
|
| 446 |
def test_get_storage_node_empty_exception(self, device_module_mock): |
| 447 |
self.get_module_args.update({ |
| 448 |
"device_name": MockDeviceV2Api.DEVICE_NAME_1, |
| 449 |
"state": "absent" |
| 450 |
}) |
| 451 |
device_module_mock.module.params = self.get_module_args |
| 452 |
device_module_mock.module.params = self.get_module_args |
| 453 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 454 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST) |
| 455 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 456 |
return_value=None) |
| 457 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 458 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 459 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 460 |
'get_storage_node_exception'), device_module_mock) |
| 461 |
|
| 462 |
def test_get_device_group_exception(self, device_module_mock): |
| 463 |
self.get_module_args.update({ |
| 464 |
"device_name": MockDeviceV2Api.DEVICE_NAME_1, |
| 465 |
"state": "absent" |
| 466 |
}) |
| 467 |
device_module_mock.module.params = self.get_module_args |
| 468 |
device_module_mock.module.params = self.get_module_args |
| 469 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 470 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST) |
| 471 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 472 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 473 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 474 |
side_effect=MockApiException) |
| 475 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 476 |
'get_device_group_exception'), device_module_mock) |
| 477 |
|
| 478 |
def test_get_device_group_empty_exception(self, device_module_mock): |
| 479 |
self.get_module_args.update({ |
| 480 |
"device_name": MockDeviceV2Api.DEVICE_NAME_1, |
| 481 |
"state": "absent" |
| 482 |
}) |
| 483 |
device_module_mock.module.params = self.get_module_args |
| 484 |
device_module_mock.module.params = self.get_module_args |
| 485 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 486 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST) |
| 487 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 488 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 489 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 490 |
return_value=None) |
| 491 |
self.capture_fail_json_call(MockDeviceV2Api.get_device_exception_response( |
| 492 |
'get_device_group_empty'), device_module_mock) |
| 493 |
|
| 494 |
def test_create_device_check_mode(self, device_module_mock): |
| 495 |
self.get_module_args.update({ |
| 496 |
"current_pathname": MockDeviceV2Api.PATH_1, |
| 497 |
"storage_node_id": MockDeviceV2Api.NODE_ID_1, |
| 498 |
"device_group_id": MockDeviceV2Api.DG_ID_1, |
| 499 |
"media_type": "SSD", |
| 500 |
"state": "present" |
| 501 |
}) |
| 502 |
device_module_mock.module.check_mode = True |
| 503 |
device_module_mock.module.params = self.get_module_args |
| 504 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 505 |
return_value=None) |
| 506 |
device_module_mock.powerflex_conn.device.create = MagicMock( |
| 507 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST[0]) |
| 508 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 509 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 510 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 511 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 512 |
DeviceHandler().handle(device_module_mock, device_module_mock.module.params) |
| 513 |
device_module_mock.powerflex_conn.device.create.assert_not_called() |
| 514 |
|
| 515 |
def test_modify_device_check_mode(self, device_module_mock): |
| 516 |
self.get_module_args.update({ |
| 517 |
"device_name": MockDeviceV2Api.DEVICE_NAME_1, |
| 518 |
"new_device_name": "ansible_device_rename", |
| 519 |
"capacity_limit_gb": 500, |
| 520 |
"clear_error": True, |
| 521 |
"force": True, |
| 522 |
"state": "present" |
| 523 |
}) |
| 524 |
device_module_mock.module.check_mode = True |
| 525 |
device_module_mock.module.params = self.get_module_args |
| 526 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 527 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST) |
| 528 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 529 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 530 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 531 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 532 |
DeviceHandler().handle(device_module_mock, device_module_mock.module.params) |
| 533 |
device_module_mock.powerflex_conn.device.rename.assert_not_called() |
| 534 |
device_module_mock.powerflex_conn.device.set_capacity_limit.assert_not_called() |
| 535 |
device_module_mock.powerflex_conn.device.clear_errors.assert_not_called() |
| 536 |
|
| 537 |
def test_delete_device_check_mode(self, device_module_mock): |
| 538 |
self.get_module_args.update({ |
| 539 |
"device_name": MockDeviceV2Api.DEVICE_NAME_1, |
| 540 |
"state": "absent" |
| 541 |
}) |
| 542 |
device_module_mock.module.check_mode = True |
| 543 |
device_module_mock.module.params = self.get_module_args |
| 544 |
device_module_mock.powerflex_conn.device.get = MagicMock( |
| 545 |
return_value=MockDeviceV2Api.DEVICE_GET_LIST) |
| 546 |
device_module_mock.powerflex_conn.storage_node.get = MagicMock( |
| 547 |
return_value=MockDeviceV2Api.NODE_DETAILS_1) |
| 548 |
device_module_mock.powerflex_conn.device_group.get = MagicMock( |
| 549 |
return_value=MockDeviceV2Api.DG_DETAILS_1) |
| 550 |
DeviceHandler().handle(device_module_mock, device_module_mock.module.params) |
| 551 |
device_module_mock.powerflex_conn.device.delete.assert_not_called() |