| 1 |
# (c) 2018-2023, NetApp, Inc |
| 2 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 3 |
|
| 4 |
''' unit test template for ONTAP Ansible module ''' |
| 5 |
|
| 6 |
from __future__ import (absolute_import, division, print_function) |
| 7 |
__metaclass__ = type |
| 8 |
|
| 9 |
import copy |
| 10 |
import pytest |
| 11 |
|
| 12 |
from ansible_collections.netapp.ontap.tests.unit.compat.mock import patch |
| 13 |
import ansible_collections.netapp.ontap.plugins.module_utils.netapp as netapp_utils |
| 14 |
# pylint: disable=unused-import |
| 15 |
from ansible_collections.netapp.ontap.tests.unit.plugins.module_utils.ansible_mocks import \ |
| 16 |
assert_warning_was_raised, call_main, create_module, create_and_apply, expect_and_capture_ansible_exception, patch_ansible, print_warnings |
| 17 |
from ansible_collections.netapp.ontap.tests.unit.framework.mock_rest_and_zapi_requests import \ |
| 18 |
get_mock_record, patch_request_and_invoke, print_requests, register_responses |
| 19 |
from ansible_collections.netapp.ontap.tests.unit.framework.zapi_factory import build_zapi_error, build_zapi_response, zapi_error_message, zapi_responses |
| 20 |
|
| 21 |
from ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume \ |
| 22 |
import NetAppOntapVolume as vol_module, main as my_main # module under test |
| 23 |
|
| 24 |
if not netapp_utils.has_netapp_lib(): |
| 25 |
pytestmark = pytest.mark.skip('skipping as missing required netapp_lib') |
| 26 |
|
| 27 |
|
| 28 |
# REST API canned responses when mocking send_request |
| 29 |
SRR = { |
| 30 |
# common responses |
| 31 |
'is_rest': (200, {}, None), |
| 32 |
'is_zapi': (400, {}, "Unreachable"), |
| 33 |
'empty_good': (200, {}, None), |
| 34 |
'end_of_sequence': (500, None, "Unexpected call to send_request"), |
| 35 |
} |
| 36 |
|
| 37 |
MOCK_VOL = { |
| 38 |
'name': 'test_vol', |
| 39 |
'aggregate': 'test_aggr', |
| 40 |
'junction_path': '/test', |
| 41 |
'vserver': 'test_vserver', |
| 42 |
'size': 20971520, |
| 43 |
'unix_permissions': '755', |
| 44 |
'user_id': 100, |
| 45 |
'group_id': 1000, |
| 46 |
'snapshot_policy': 'default', |
| 47 |
'qos_policy_group': 'performance', |
| 48 |
'qos_adaptive_policy_group': 'performance', |
| 49 |
'percent_snapshot_space': 60, |
| 50 |
'language': 'en', |
| 51 |
'vserver_dr_protection': 'unprotected', |
| 52 |
'uuid': 'UUID' |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
def volume_info(style, vol_details=None, remove_keys=None, encrypt='false'): |
| 57 |
if not vol_details: |
| 58 |
vol_details = MOCK_VOL |
| 59 |
info = copy.deepcopy({ |
| 60 |
'num-records': 1, |
| 61 |
'attributes-list': { |
| 62 |
'volume-attributes': { |
| 63 |
'encrypt': encrypt, |
| 64 |
'volume-id-attributes': { |
| 65 |
'aggr-list': vol_details['aggregate'], |
| 66 |
'containing-aggregate-name': vol_details['aggregate'], |
| 67 |
'flexgroup-uuid': 'uuid', |
| 68 |
'junction-path': vol_details['junction_path'], |
| 69 |
'style-extended': style, |
| 70 |
'type': 'rw' |
| 71 |
}, |
| 72 |
'volume-comp-aggr-attributes': { |
| 73 |
'tiering-policy': 'snapshot-only' |
| 74 |
}, |
| 75 |
'volume-language-attributes': { |
| 76 |
'language-code': 'en' |
| 77 |
}, |
| 78 |
'volume-export-attributes': { |
| 79 |
'policy': 'default' |
| 80 |
}, |
| 81 |
'volume-performance-attributes': { |
| 82 |
'is-atime-update-enabled': 'true' |
| 83 |
}, |
| 84 |
'volume-state-attributes': { |
| 85 |
'state': "online", |
| 86 |
'is-nvfail-enabled': 'true' |
| 87 |
}, |
| 88 |
'volume-inode-attributes': { |
| 89 |
'files-total': '2000', |
| 90 |
}, |
| 91 |
'volume-space-attributes': { |
| 92 |
'space-guarantee': 'none', |
| 93 |
'size': vol_details['size'], |
| 94 |
'percentage-snapshot-reserve': vol_details['percent_snapshot_space'], |
| 95 |
'space-slo': 'thick' |
| 96 |
}, |
| 97 |
'volume-snapshot-attributes': { |
| 98 |
'snapshot-policy': vol_details['snapshot_policy'] |
| 99 |
}, |
| 100 |
'volume-security-attributes': { |
| 101 |
'volume-security-unix-attributes': { |
| 102 |
'permissions': vol_details['unix_permissions'], |
| 103 |
'group-id': vol_details['group_id'], |
| 104 |
'user-id': vol_details['user_id'] |
| 105 |
}, |
| 106 |
'style': 'unix', |
| 107 |
}, |
| 108 |
'volume-vserver-dr-protection-attributes': { |
| 109 |
'vserver-dr-protection': vol_details['vserver_dr_protection'], |
| 110 |
}, |
| 111 |
'volume-qos-attributes': { |
| 112 |
'policy-group-name': vol_details['qos_policy_group'], |
| 113 |
'adaptive-policy-group-name': vol_details['qos_adaptive_policy_group'] |
| 114 |
}, |
| 115 |
'volume-snapshot-autodelete-attributes': { |
| 116 |
'commitment': 'try', |
| 117 |
'is-autodelete-enabled': 'true', |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
}) |
| 122 |
if remove_keys: |
| 123 |
for key in remove_keys: |
| 124 |
if key == 'is_online': |
| 125 |
del info['attributes-list']['volume-attributes']['volume-state-attributes']['state'] |
| 126 |
else: |
| 127 |
raise KeyError('unexpected key %s' % key) |
| 128 |
return info |
| 129 |
|
| 130 |
|
| 131 |
def vol_encryption_conversion_status(status): |
| 132 |
return { |
| 133 |
'num-records': 1, |
| 134 |
'attributes-list': { |
| 135 |
'volume-encryption-conversion-info': { |
| 136 |
'status': status |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
def vol_move_status(status): |
| 143 |
return { |
| 144 |
'num-records': 1, |
| 145 |
'attributes-list': { |
| 146 |
'volume-move-info': { |
| 147 |
'state': status, |
| 148 |
'details': 'some info' |
| 149 |
} |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
def job_info(state, error): |
| 155 |
return { |
| 156 |
'num-records': 1, |
| 157 |
'attributes': { |
| 158 |
'job-info': { |
| 159 |
'job-state': state, |
| 160 |
'job-progress': 'progress', |
| 161 |
'job-completion': error, |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
def results_info(status): |
| 168 |
return { |
| 169 |
'result-status': status, |
| 170 |
'result-jobid': 'job12345', |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
def modify_async_results_info(status, error=None): |
| 175 |
list_name = 'failure-list' if error else 'success-list' |
| 176 |
info = { |
| 177 |
list_name: { |
| 178 |
'volume-modify-iter-async-info': { |
| 179 |
'status': status, |
| 180 |
'jobid': '1234' |
| 181 |
} |
| 182 |
} |
| 183 |
} |
| 184 |
if error: |
| 185 |
info[list_name]['volume-modify-iter-async-info']['error-message'] = error |
| 186 |
return info |
| 187 |
|
| 188 |
|
| 189 |
def sis_info(): |
| 190 |
return { |
| 191 |
'num-records': 1, |
| 192 |
'attributes-list': { |
| 193 |
'sis-status-info': { |
| 194 |
'policy': 'test', |
| 195 |
'is-compression-enabled': 'true', |
| 196 |
'sis-status-completion': 'false', |
| 197 |
} |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
ZRR = zapi_responses({ |
| 203 |
'get_flexgroup': build_zapi_response(volume_info('flexgroup')), |
| 204 |
'get_flexvol': build_zapi_response(volume_info('flexvol')), |
| 205 |
'get_flexvol_encrypted': build_zapi_response(volume_info('flexvol', encrypt='true')), |
| 206 |
'get_flexvol_no_online_key': build_zapi_response(volume_info('flexvol', remove_keys=['is_online'])), |
| 207 |
'job_failure': build_zapi_response(job_info('failure', 'failure')), |
| 208 |
'job_other': build_zapi_response(job_info('other', 'other_error')), |
| 209 |
'job_running': build_zapi_response(job_info('running', None)), |
| 210 |
'job_success': build_zapi_response(job_info('success', None)), |
| 211 |
'job_time_out': build_zapi_response(job_info('running', 'time_out')), |
| 212 |
'job_no_completion': build_zapi_response(job_info('failure', None)), |
| 213 |
'async_results': build_zapi_response(results_info('in_progress')), |
| 214 |
'failed_results': build_zapi_response(results_info('failed')), |
| 215 |
'modify_async_result_success': build_zapi_response(modify_async_results_info('in_progress')), |
| 216 |
'modify_async_result_failure': build_zapi_response(modify_async_results_info('failure', 'error_in_modify')), |
| 217 |
'vol_encryption_conversion_status_running': build_zapi_response(vol_encryption_conversion_status('running')), |
| 218 |
'vol_encryption_conversion_status_idle': build_zapi_response(vol_encryption_conversion_status('Not currently going on.')), |
| 219 |
'vol_encryption_conversion_status_error': build_zapi_response(vol_encryption_conversion_status('other')), |
| 220 |
'vol_move_status_running': build_zapi_response(vol_move_status('healthy')), |
| 221 |
'vol_move_status_idle': build_zapi_response(vol_move_status('done')), |
| 222 |
'vol_move_status_error': build_zapi_response(vol_move_status('failed')), |
| 223 |
'insufficient_privileges': build_zapi_error(12346, 'Insufficient privileges: user USERID does not have read access to this resource'), |
| 224 |
'get_sis_info': build_zapi_response(sis_info()), |
| 225 |
'error_15661': build_zapi_error(15661, 'force job not found error'), |
| 226 |
'error_tiering_94': build_zapi_error(94, 'volume-comp-aggr-attributes') |
| 227 |
}) |
| 228 |
|
| 229 |
|
| 230 |
MINIMUM_ARGS = { |
| 231 |
'hostname': 'test', |
| 232 |
'username': 'test_user', |
| 233 |
'password': 'test_pass!', |
| 234 |
'name': 'test_vol', |
| 235 |
'vserver': 'test_vserver', |
| 236 |
'use_rest': 'never' |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
DEFAULT_ARGS = { |
| 241 |
'hostname': 'test', |
| 242 |
'username': 'test_user', |
| 243 |
'password': 'test_pass!', |
| 244 |
'name': 'test_vol', |
| 245 |
'vserver': 'test_vserver', |
| 246 |
'policy': 'default', |
| 247 |
'language': 'en', |
| 248 |
'is_online': True, |
| 249 |
'unix_permissions': '---rwxr-xr-x', |
| 250 |
'user_id': 100, |
| 251 |
'group_id': 1000, |
| 252 |
'snapshot_policy': 'default', |
| 253 |
'qos_policy_group': 'performance', |
| 254 |
'qos_adaptive_policy_group': 'performance', |
| 255 |
'size': 20, |
| 256 |
'size_unit': 'mb', |
| 257 |
'junction_path': '/test', |
| 258 |
'percent_snapshot_space': 60, |
| 259 |
'type': 'rw', |
| 260 |
'nvfail_enabled': True, |
| 261 |
'space_slo': 'thick', |
| 262 |
'use_rest': 'never' |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
ZAPI_ERROR = 'NetApp API failed. Reason - 12345:synthetic error for UT purpose' |
| 267 |
|
| 268 |
|
| 269 |
def test_module_fail_when_required_args_missing(): |
| 270 |
''' required arguments are reported as errors ''' |
| 271 |
error = create_module(vol_module, {}, fail=True) |
| 272 |
print('Info: %s' % error['msg']) |
| 273 |
assert 'missing required arguments:' in error['msg'] |
| 274 |
|
| 275 |
|
| 276 |
def test_get_nonexistent_volume(): |
| 277 |
''' Test if get_volume returns None for non-existent volume ''' |
| 278 |
register_responses([ |
| 279 |
('ZAPI', 'volume-get-iter', ZRR['success']), |
| 280 |
]) |
| 281 |
assert create_module(vol_module, DEFAULT_ARGS).get_volume() is None |
| 282 |
|
| 283 |
|
| 284 |
def test_get_error(): |
| 285 |
''' Test if get_volume handles error ''' |
| 286 |
register_responses([ |
| 287 |
('ZAPI', 'volume-get-iter', ZRR['error']), |
| 288 |
]) |
| 289 |
error = 'Error fetching volume test_vol : %s' % ZAPI_ERROR |
| 290 |
assert expect_and_capture_ansible_exception(create_module(vol_module, DEFAULT_ARGS).get_volume, 'fail')['msg'] == error |
| 291 |
|
| 292 |
|
| 293 |
def test_get_existing_volume(): |
| 294 |
''' Test if get_volume returns details for existing volume ''' |
| 295 |
register_responses([ |
| 296 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 297 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 298 |
]) |
| 299 |
volume_info = create_module(vol_module, DEFAULT_ARGS).get_volume() |
| 300 |
assert volume_info is not None |
| 301 |
assert 'aggregate_name' in volume_info |
| 302 |
|
| 303 |
|
| 304 |
def test_create_error_missing_param(): |
| 305 |
''' Test if create throws an error if aggregate_name is not specified''' |
| 306 |
register_responses([ |
| 307 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), |
| 308 |
]) |
| 309 |
module_args = { |
| 310 |
'size': 20, |
| 311 |
'encrypt': True, |
| 312 |
} |
| 313 |
msg = 'Error provisioning volume test_vol: aggregate_name is required' |
| 314 |
assert msg == create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] |
| 315 |
|
| 316 |
|
| 317 |
def test_successful_create(): |
| 318 |
''' Test successful create ''' |
| 319 |
register_responses([ |
| 320 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), |
| 321 |
('ZAPI', 'volume-create', ZRR['success']), |
| 322 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 323 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 324 |
]) |
| 325 |
module_args = { |
| 326 |
'aggregate_name': MOCK_VOL['aggregate'], |
| 327 |
'size': 20, |
| 328 |
} |
| 329 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 330 |
|
| 331 |
|
| 332 |
@patch('time.sleep') |
| 333 |
def test_successful_create_with_completion(dont_sleep): |
| 334 |
''' Test successful create ''' |
| 335 |
register_responses([ |
| 336 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), |
| 337 |
('ZAPI', 'volume-create', ZRR['success']), |
| 338 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), # wait for online |
| 339 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), # wait for online |
| 340 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), # wait for online |
| 341 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 342 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 343 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 344 |
]) |
| 345 |
module_args = { |
| 346 |
'aggregate_name': MOCK_VOL['aggregate'], |
| 347 |
'size': 20, |
| 348 |
'wait_for_completion': True |
| 349 |
} |
| 350 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 351 |
|
| 352 |
|
| 353 |
@patch('time.sleep') |
| 354 |
def test_error_timeout_create_with_completion(dont_sleep): |
| 355 |
''' Test successful create ''' |
| 356 |
register_responses([ |
| 357 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), |
| 358 |
('ZAPI', 'volume-create', ZRR['success']), |
| 359 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), # wait for online |
| 360 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), # wait for online |
| 361 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), # wait for online |
| 362 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), # wait for online |
| 363 |
]) |
| 364 |
module_args = { |
| 365 |
'aggregate_name': MOCK_VOL['aggregate'], |
| 366 |
'size': 20, |
| 367 |
'time_out': 42, |
| 368 |
'wait_for_completion': True |
| 369 |
} |
| 370 |
error = "Error waiting for volume test_vol to come online: ['Timeout after 42 seconds']" |
| 371 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == error |
| 372 |
|
| 373 |
|
| 374 |
@patch('time.sleep') |
| 375 |
def test_error_timeout_keyerror_create_with_completion(dont_sleep): |
| 376 |
''' Test successful create ''' |
| 377 |
register_responses([ |
| 378 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), |
| 379 |
('ZAPI', 'volume-create', ZRR['success']), |
| 380 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), # wait for online |
| 381 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), # wait for online |
| 382 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol_no_online_key']), # wait for online |
| 383 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 384 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), # wait for online |
| 385 |
]) |
| 386 |
module_args = { |
| 387 |
'aggregate_name': MOCK_VOL['aggregate'], |
| 388 |
'size': 20, |
| 389 |
'time_out': 42, |
| 390 |
'wait_for_completion': True |
| 391 |
} |
| 392 |
error_py3x = '''Error waiting for volume test_vol to come online: ["KeyError('is_online')", 'Timeout after 42 seconds']''' |
| 393 |
error_py27 = '''Error waiting for volume test_vol to come online: ["KeyError('is_online',)", 'Timeout after 42 seconds']''' |
| 394 |
error = create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] |
| 395 |
print('error', error) |
| 396 |
assert error == error_py3x or error == error_py27 |
| 397 |
|
| 398 |
|
| 399 |
def test_error_create(): |
| 400 |
''' Test error on create ''' |
| 401 |
register_responses([ |
| 402 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), |
| 403 |
('ZAPI', 'volume-create', ZRR['error']), |
| 404 |
]) |
| 405 |
module_args = { |
| 406 |
'aggregate_name': MOCK_VOL['aggregate'], |
| 407 |
'size': 20, |
| 408 |
'encrypt': True, |
| 409 |
} |
| 410 |
error = 'Error provisioning volume test_vol of size 20971520: %s' % ZAPI_ERROR |
| 411 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == error |
| 412 |
|
| 413 |
|
| 414 |
def test_create_idempotency(): |
| 415 |
''' Test create idempotency ''' |
| 416 |
register_responses([ |
| 417 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 418 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 419 |
]) |
| 420 |
assert not create_and_apply(vol_module, DEFAULT_ARGS)['changed'] |
| 421 |
|
| 422 |
|
| 423 |
def test_successful_delete(): |
| 424 |
''' Test delete existing volume ''' |
| 425 |
register_responses([ |
| 426 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 427 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 428 |
('ZAPI', 'volume-destroy', ZRR['success']), |
| 429 |
]) |
| 430 |
module_args = { |
| 431 |
'state': 'absent', |
| 432 |
} |
| 433 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 434 |
|
| 435 |
|
| 436 |
def test_error_delete(): |
| 437 |
''' Test delete existing volume ''' |
| 438 |
register_responses([ |
| 439 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 440 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 441 |
('ZAPI', 'volume-destroy', ZRR['error']), |
| 442 |
('ZAPI', 'volume-destroy', ZRR['error']), |
| 443 |
]) |
| 444 |
module_args = { |
| 445 |
'state': 'absent', |
| 446 |
} |
| 447 |
error = 'Error deleting volume test_vol:' |
| 448 |
msg = create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] |
| 449 |
assert error in msg |
| 450 |
error = 'volume delete failed with unmount-and-offline option: %s' % ZAPI_ERROR |
| 451 |
assert error in msg |
| 452 |
error = 'volume delete failed without unmount-and-offline option: %s' % ZAPI_ERROR |
| 453 |
assert error in msg |
| 454 |
|
| 455 |
|
| 456 |
def test_error_delete_async(): |
| 457 |
''' Test delete existing volume ''' |
| 458 |
register_responses([ |
| 459 |
('ZAPI', 'volume-get-iter', ZRR['get_flexgroup']), |
| 460 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 461 |
('ZAPI', 'volume-unmount', ZRR['error']), |
| 462 |
('ZAPI', 'volume-offline-async', ZRR['error']), |
| 463 |
('ZAPI', 'volume-destroy-async', ZRR['error']), |
| 464 |
]) |
| 465 |
module_args = { |
| 466 |
'state': 'absent', |
| 467 |
|
| 468 |
} |
| 469 |
error = 'Error deleting volume test_vol: %s' % ZAPI_ERROR |
| 470 |
msg = create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] |
| 471 |
assert error in msg |
| 472 |
error = 'Error unmounting volume test_vol: %s' % ZAPI_ERROR |
| 473 |
assert error in msg |
| 474 |
error = 'Error changing the state of volume test_vol to offline: %s' % ZAPI_ERROR |
| 475 |
assert error in msg |
| 476 |
|
| 477 |
|
| 478 |
def test_delete_idempotency(): |
| 479 |
''' Test delete idempotency ''' |
| 480 |
register_responses([ |
| 481 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), |
| 482 |
]) |
| 483 |
module_args = { |
| 484 |
'state': 'absent', |
| 485 |
} |
| 486 |
assert not create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 487 |
|
| 488 |
|
| 489 |
def test_successful_modify_size(): |
| 490 |
''' Test successful modify size ''' |
| 491 |
register_responses([ |
| 492 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 493 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 494 |
('ZAPI', 'volume-size', ZRR['success']), |
| 495 |
]) |
| 496 |
module_args = { |
| 497 |
'size': 200, |
| 498 |
} |
| 499 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 500 |
print_requests() |
| 501 |
assert get_mock_record().is_text_in_zapi_request('<new-size>209715200', 2) |
| 502 |
|
| 503 |
|
| 504 |
def test_modify_idempotency(): |
| 505 |
''' Test modify idempotency ''' |
| 506 |
register_responses([ |
| 507 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 508 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 509 |
]) |
| 510 |
assert not create_and_apply(vol_module, DEFAULT_ARGS)['changed'] |
| 511 |
|
| 512 |
|
| 513 |
def test_modify_error(): |
| 514 |
''' Test modify idempotency ''' |
| 515 |
register_responses([ |
| 516 |
('ZAPI', 'volume-modify-iter', ZRR['error']), |
| 517 |
]) |
| 518 |
msg = 'Error modifying volume test_vol: %s' % ZAPI_ERROR |
| 519 |
assert msg == expect_and_capture_ansible_exception(create_module(vol_module, DEFAULT_ARGS).volume_modify_attributes, 'fail', {})['msg'] |
| 520 |
|
| 521 |
|
| 522 |
def test_mount_volume(): |
| 523 |
''' Test mount volume ''' |
| 524 |
register_responses([ |
| 525 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 526 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 527 |
('ZAPI', 'volume-mount', ZRR['success']), |
| 528 |
]) |
| 529 |
module_args = { |
| 530 |
'junction_path': '/test123', |
| 531 |
} |
| 532 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 533 |
|
| 534 |
|
| 535 |
def test_error_mount_volume(): |
| 536 |
''' Test mount volume ''' |
| 537 |
register_responses([ |
| 538 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 539 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 540 |
('ZAPI', 'volume-mount', ZRR['error']), |
| 541 |
]) |
| 542 |
module_args = { |
| 543 |
'junction_path': '/test123', |
| 544 |
} |
| 545 |
error = 'Error mounting volume test_vol on path /test123: %s' % ZAPI_ERROR |
| 546 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == error |
| 547 |
|
| 548 |
|
| 549 |
def test_unmount_volume(): |
| 550 |
''' Test unmount volume ''' |
| 551 |
register_responses([ |
| 552 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 553 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 554 |
('ZAPI', 'volume-unmount', ZRR['success']), |
| 555 |
]) |
| 556 |
module_args = { |
| 557 |
'junction_path': '', |
| 558 |
} |
| 559 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 560 |
|
| 561 |
|
| 562 |
def test_error_unmount_volume(): |
| 563 |
''' Test unmount volume ''' |
| 564 |
register_responses([ |
| 565 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 566 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 567 |
('ZAPI', 'volume-unmount', ZRR['error']), |
| 568 |
]) |
| 569 |
module_args = { |
| 570 |
'junction_path': '', |
| 571 |
} |
| 572 |
error = 'Error unmounting volume test_vol: %s' % ZAPI_ERROR |
| 573 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == error |
| 574 |
|
| 575 |
|
| 576 |
def test_successful_modify_space(): |
| 577 |
''' Test successful modify space ''' |
| 578 |
register_responses([ |
| 579 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 580 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 581 |
('ZAPI', 'volume-modify-iter', ZRR['success']), |
| 582 |
]) |
| 583 |
args = dict(DEFAULT_ARGS) |
| 584 |
del args['space_slo'] |
| 585 |
module_args = { |
| 586 |
'space_guarantee': 'volume', |
| 587 |
} |
| 588 |
assert create_and_apply(vol_module, args, module_args)['changed'] |
| 589 |
print_requests() |
| 590 |
assert get_mock_record().is_text_in_zapi_request('<space-guarantee>volume', 2) |
| 591 |
|
| 592 |
|
| 593 |
def test_successful_modify_unix_permissions(): |
| 594 |
''' Test successful modify unix_permissions ''' |
| 595 |
register_responses([ |
| 596 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 597 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 598 |
('ZAPI', 'volume-modify-iter', ZRR['success']), |
| 599 |
]) |
| 600 |
module_args = { |
| 601 |
'unix_permissions': '---rw-r-xr-x', |
| 602 |
} |
| 603 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 604 |
print_requests() |
| 605 |
assert get_mock_record().is_text_in_zapi_request('<permissions>---rw-r-xr-x', 2) |
| 606 |
|
| 607 |
|
| 608 |
def test_successful_modify_volume_security_style(): |
| 609 |
''' Test successful modify volume_security_style ''' |
| 610 |
register_responses([ |
| 611 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 612 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 613 |
('ZAPI', 'volume-modify-iter', ZRR['success']), |
| 614 |
]) |
| 615 |
module_args = { |
| 616 |
'volume_security_style': 'mixed', |
| 617 |
} |
| 618 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 619 |
print_requests() |
| 620 |
assert get_mock_record().is_text_in_zapi_request('<style>mixed</style>', 2) |
| 621 |
|
| 622 |
|
| 623 |
def test_successful_modify_max_files_and_encrypt(): |
| 624 |
''' Test successful modify unix_permissions ''' |
| 625 |
register_responses([ |
| 626 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 627 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 628 |
('ZAPI', 'volume-modify-iter', ZRR['success']), |
| 629 |
('ZAPI', 'volume-encryption-conversion-start', ZRR['success']), |
| 630 |
]) |
| 631 |
module_args = { |
| 632 |
'encrypt': True, |
| 633 |
'max_files': '3000', |
| 634 |
} |
| 635 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 636 |
print_requests() |
| 637 |
assert get_mock_record().is_text_in_zapi_request('<files-total>3000', 2) |
| 638 |
|
| 639 |
|
| 640 |
def test_successful_modify_snapshot_policy(): |
| 641 |
''' Test successful modify snapshot_policy ''' |
| 642 |
register_responses([ |
| 643 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 644 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 645 |
('ZAPI', 'volume-modify-iter', ZRR['success']), |
| 646 |
]) |
| 647 |
module_args = { |
| 648 |
'snapshot_policy': 'default-1weekly', |
| 649 |
} |
| 650 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 651 |
print_requests() |
| 652 |
assert get_mock_record().is_text_in_zapi_request('<snapshot-policy>default-1weekly', 2) |
| 653 |
|
| 654 |
|
| 655 |
def test_successful_modify_efficiency_policy(): |
| 656 |
''' Test successful modify efficiency_policy ''' |
| 657 |
register_responses([ |
| 658 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 659 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 660 |
('ZAPI', 'sis-enable', ZRR['success']), |
| 661 |
('ZAPI', 'sis-set-config', ZRR['success']), |
| 662 |
]) |
| 663 |
module_args = { |
| 664 |
'efficiency_policy': 'test', |
| 665 |
'inline_compression': True |
| 666 |
} |
| 667 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 668 |
print_requests() |
| 669 |
assert get_mock_record().is_text_in_zapi_request('<policy-name>test', 3) |
| 670 |
|
| 671 |
|
| 672 |
def test_successful_modify_efficiency_policy_idempotent(): |
| 673 |
''' Test successful modify efficiency_policy ''' |
| 674 |
register_responses([ |
| 675 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 676 |
('ZAPI', 'sis-get-iter', ZRR['get_sis_info']), |
| 677 |
]) |
| 678 |
module_args = { |
| 679 |
'efficiency_policy': 'test', |
| 680 |
'compression': True |
| 681 |
} |
| 682 |
assert not create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 683 |
|
| 684 |
|
| 685 |
def test_successful_modify_efficiency_policy_async(): |
| 686 |
''' Test successful modify efficiency_policy ''' |
| 687 |
register_responses([ |
| 688 |
('ZAPI', 'volume-get-iter', ZRR['get_flexgroup']), |
| 689 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 690 |
('ZAPI', 'sis-enable-async', ZRR['success']), |
| 691 |
('ZAPI', 'sis-set-config-async', ZRR['success']), |
| 692 |
]) |
| 693 |
module_args = { |
| 694 |
'aggr_list': 'aggr_0,aggr_1', |
| 695 |
'aggr_list_multiplier': 2, |
| 696 |
'efficiency_policy': 'test', |
| 697 |
'compression': True, |
| 698 |
'wait_for_completion': True, |
| 699 |
} |
| 700 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 701 |
print_requests() |
| 702 |
assert get_mock_record().is_text_in_zapi_request('<policy-name>test', 3) |
| 703 |
|
| 704 |
|
| 705 |
def test_error_set_efficiency_policy(): |
| 706 |
register_responses([ |
| 707 |
('ZAPI', 'sis-enable', ZRR['error']), |
| 708 |
]) |
| 709 |
module_args = {'efficiency_policy': 'test_policy'} |
| 710 |
msg = 'Error enable efficiency on volume test_vol: %s' % ZAPI_ERROR |
| 711 |
assert msg == expect_and_capture_ansible_exception(create_module(vol_module, MINIMUM_ARGS, module_args).set_efficiency_config, 'fail')['msg'] |
| 712 |
|
| 713 |
|
| 714 |
def test_error_modify_efficiency_policy(): |
| 715 |
''' Test error modify efficiency_policy ''' |
| 716 |
register_responses([ |
| 717 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 718 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 719 |
('ZAPI', 'sis-enable', ZRR['success']), |
| 720 |
('ZAPI', 'sis-set-config', ZRR['error']), |
| 721 |
]) |
| 722 |
module_args = { |
| 723 |
'efficiency_policy': 'test', |
| 724 |
} |
| 725 |
error = 'Error setting up efficiency attributes on volume test_vol: %s' % ZAPI_ERROR |
| 726 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == error |
| 727 |
|
| 728 |
|
| 729 |
def test_error_set_efficiency_policy_async(): |
| 730 |
register_responses([ |
| 731 |
('ZAPI', 'sis-enable-async', ZRR['error']), |
| 732 |
]) |
| 733 |
module_args = {'efficiency_policy': 'test_policy'} |
| 734 |
msg = 'Error enable efficiency on volume test_vol: %s' % ZAPI_ERROR |
| 735 |
assert msg == expect_and_capture_ansible_exception(create_module(vol_module, MINIMUM_ARGS, module_args).set_efficiency_config_async, 'fail')['msg'] |
| 736 |
|
| 737 |
|
| 738 |
def test_error_modify_efficiency_policy_async(): |
| 739 |
''' Test error modify efficiency_policy ''' |
| 740 |
register_responses([ |
| 741 |
('ZAPI', 'volume-get-iter', ZRR['get_flexgroup']), |
| 742 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 743 |
('ZAPI', 'sis-enable-async', ZRR['success']), |
| 744 |
('ZAPI', 'sis-set-config-async', ZRR['error']), |
| 745 |
]) |
| 746 |
module_args = { |
| 747 |
'aggr_list': 'aggr_0,aggr_1', |
| 748 |
'aggr_list_multiplier': 2, |
| 749 |
'efficiency_policy': 'test', |
| 750 |
} |
| 751 |
error = 'Error setting up efficiency attributes on volume test_vol: %s' % ZAPI_ERROR |
| 752 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == error |
| 753 |
|
| 754 |
|
| 755 |
def test_successful_modify_percent_snapshot_space(): |
| 756 |
''' Test successful modify percent_snapshot_space ''' |
| 757 |
register_responses([ |
| 758 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 759 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 760 |
('ZAPI', 'volume-modify-iter', ZRR['success']), |
| 761 |
]) |
| 762 |
module_args = { |
| 763 |
'percent_snapshot_space': 90, |
| 764 |
} |
| 765 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 766 |
print_requests() |
| 767 |
assert get_mock_record().is_text_in_zapi_request('<percentage-snapshot-reserve>90', 2) |
| 768 |
|
| 769 |
|
| 770 |
def test_successful_modify_qos_policy_group(): |
| 771 |
''' Test successful modify qos_policy_group ''' |
| 772 |
register_responses([ |
| 773 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 774 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 775 |
('ZAPI', 'volume-modify-iter', ZRR['success']), |
| 776 |
]) |
| 777 |
module_args = { |
| 778 |
'qos_policy_group': 'extreme', |
| 779 |
} |
| 780 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 781 |
print_requests() |
| 782 |
assert get_mock_record().is_text_in_zapi_request('<policy-group-name>extreme', 2) |
| 783 |
|
| 784 |
|
| 785 |
def test_successful_modify_qos_adaptive_policy_group(): |
| 786 |
''' Test successful modify qos_adaptive_policy_group ''' |
| 787 |
register_responses([ |
| 788 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 789 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 790 |
('ZAPI', 'volume-modify-iter', ZRR['success']), |
| 791 |
]) |
| 792 |
module_args = { |
| 793 |
'qos_adaptive_policy_group': 'extreme', |
| 794 |
} |
| 795 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 796 |
print_requests() |
| 797 |
assert get_mock_record().is_text_in_zapi_request('<adaptive-policy-group-name>extreme', 2) |
| 798 |
|
| 799 |
|
| 800 |
def test_successful_move(): |
| 801 |
''' Test successful modify aggregate ''' |
| 802 |
register_responses([ |
| 803 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 804 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 805 |
('ZAPI', 'volume-move-start', ZRR['success']), |
| 806 |
('ZAPI', 'volume-move-get-iter', ZRR['vol_move_status_idle']), |
| 807 |
]) |
| 808 |
module_args = { |
| 809 |
'aggregate_name': 'different_aggr', |
| 810 |
'cutover_action': 'abort_on_failure', |
| 811 |
'encrypt': True, |
| 812 |
'wait_for_completion': True |
| 813 |
} |
| 814 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 815 |
|
| 816 |
|
| 817 |
def test_unencrypt_volume(): |
| 818 |
''' Test successful modify aggregate ''' |
| 819 |
register_responses([ |
| 820 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol_encrypted']), |
| 821 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 822 |
('ZAPI', 'volume-move-start', ZRR['success']), |
| 823 |
('ZAPI', 'volume-move-get-iter', ZRR['vol_move_status_idle']), |
| 824 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol_encrypted']), |
| 825 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 826 |
('ZAPI', 'volume-move-start', ZRR['success']), |
| 827 |
('ZAPI', 'volume-move-get-iter', ZRR['vol_move_status_idle']), |
| 828 |
]) |
| 829 |
# without aggregate |
| 830 |
module_args = { |
| 831 |
'encrypt': False, |
| 832 |
'wait_for_completion': True |
| 833 |
} |
| 834 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 835 |
# with aggregate. |
| 836 |
module_args['aggregate_name'] = 'test_aggr' |
| 837 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 838 |
|
| 839 |
|
| 840 |
def test_error_move(): |
| 841 |
''' Test error modify aggregate ''' |
| 842 |
register_responses([ |
| 843 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 844 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 845 |
('ZAPI', 'volume-move-start', ZRR['error']), |
| 846 |
]) |
| 847 |
module_args = { |
| 848 |
'aggregate_name': 'different_aggr', |
| 849 |
} |
| 850 |
error = 'Error moving volume test_vol: %s - Retry failed with REST error: False' % ZAPI_ERROR |
| 851 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == error |
| 852 |
|
| 853 |
|
| 854 |
def setup_rename(is_isinfinite=None): |
| 855 |
module_args = { |
| 856 |
'from_name': MOCK_VOL['name'], |
| 857 |
'name': 'new_name', |
| 858 |
'time_out': 20 |
| 859 |
} |
| 860 |
current = { |
| 861 |
'hostname': 'test', |
| 862 |
'username': 'test_user', |
| 863 |
'password': 'test_pass!', |
| 864 |
'name': MOCK_VOL['name'], |
| 865 |
'uuid': MOCK_VOL['uuid'], |
| 866 |
'vserver': MOCK_VOL['vserver'], |
| 867 |
} |
| 868 |
if is_isinfinite is not None: |
| 869 |
module_args['is_infinite'] = is_isinfinite |
| 870 |
current['is_infinite'] = is_isinfinite |
| 871 |
return module_args, current |
| 872 |
|
| 873 |
|
| 874 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.get_volume') |
| 875 |
def test_successful_rename(get_volume): |
| 876 |
''' Test successful rename volume ''' |
| 877 |
register_responses([ |
| 878 |
('ZAPI', 'volume-rename', ZRR['success']), |
| 879 |
]) |
| 880 |
module_args, current = setup_rename() |
| 881 |
get_volume.side_effect = [ |
| 882 |
None, |
| 883 |
current |
| 884 |
] |
| 885 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 886 |
|
| 887 |
|
| 888 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.get_volume') |
| 889 |
def test_error_rename(get_volume): |
| 890 |
''' Test error rename volume ''' |
| 891 |
register_responses([ |
| 892 |
('ZAPI', 'volume-rename', ZRR['error']), |
| 893 |
]) |
| 894 |
module_args, current = setup_rename() |
| 895 |
get_volume.side_effect = [ |
| 896 |
None, |
| 897 |
current |
| 898 |
] |
| 899 |
error = 'Error renaming volume new_name: %s' % ZAPI_ERROR |
| 900 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == error |
| 901 |
|
| 902 |
|
| 903 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.get_volume') |
| 904 |
def test_error_rename_no_from(get_volume): |
| 905 |
''' Test error rename volume ''' |
| 906 |
register_responses([ |
| 907 |
]) |
| 908 |
module_args, current = setup_rename() |
| 909 |
get_volume.side_effect = [ |
| 910 |
None, |
| 911 |
None |
| 912 |
] |
| 913 |
error = 'Error renaming volume: cannot find %s' % MOCK_VOL['name'] |
| 914 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == error |
| 915 |
|
| 916 |
|
| 917 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.get_volume') |
| 918 |
def test_successful_rename_async(get_volume): |
| 919 |
''' Test successful rename volume ''' |
| 920 |
register_responses([ |
| 921 |
('ZAPI', 'volume-rename-async', ZRR['success']), |
| 922 |
]) |
| 923 |
module_args, current = setup_rename(is_isinfinite=True) |
| 924 |
get_volume.side_effect = [ |
| 925 |
None, |
| 926 |
current |
| 927 |
] |
| 928 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 929 |
|
| 930 |
|
| 931 |
def test_modify_helper(): |
| 932 |
register_responses([ |
| 933 |
('ZAPI', 'volume-unmount', ZRR['success']), |
| 934 |
('ZAPI', 'volume-offline', ZRR['success']), |
| 935 |
]) |
| 936 |
module_args = {'is_online': False} |
| 937 |
modify = {'is_online': False} |
| 938 |
assert create_module(vol_module, DEFAULT_ARGS, module_args).take_modify_actions(modify) is None |
| 939 |
|
| 940 |
|
| 941 |
def test_compare_chmod_value_true_1(): |
| 942 |
module_args = {'unix_permissions': '------------'} |
| 943 |
current = { |
| 944 |
'unix_permissions': '0' |
| 945 |
} |
| 946 |
vol_obj = create_module(vol_module, DEFAULT_ARGS, module_args) |
| 947 |
assert vol_obj.na_helper.compare_chmod_value(current['unix_permissions'], module_args['unix_permissions']) |
| 948 |
|
| 949 |
|
| 950 |
def test_compare_chmod_value_true_2(): |
| 951 |
module_args = {'unix_permissions': '---rwxrwxrwx'} |
| 952 |
current = { |
| 953 |
'unix_permissions': '777' |
| 954 |
} |
| 955 |
vol_obj = create_module(vol_module, DEFAULT_ARGS, module_args) |
| 956 |
assert vol_obj.na_helper.compare_chmod_value(current['unix_permissions'], module_args['unix_permissions']) |
| 957 |
|
| 958 |
|
| 959 |
def test_compare_chmod_value_true_3(): |
| 960 |
module_args = {'unix_permissions': '---rwxr-xr-x'} |
| 961 |
current = { |
| 962 |
'unix_permissions': '755' |
| 963 |
} |
| 964 |
vol_obj = create_module(vol_module, DEFAULT_ARGS, module_args) |
| 965 |
assert vol_obj.na_helper.compare_chmod_value(current['unix_permissions'], module_args['unix_permissions']) |
| 966 |
|
| 967 |
|
| 968 |
def test_compare_chmod_value_true_4(): |
| 969 |
module_args = {'unix_permissions': '755'} |
| 970 |
current = { |
| 971 |
'unix_permissions': '755' |
| 972 |
} |
| 973 |
vol_obj = create_module(vol_module, DEFAULT_ARGS, module_args) |
| 974 |
assert vol_obj.na_helper.compare_chmod_value(current['unix_permissions'], module_args['unix_permissions']) |
| 975 |
|
| 976 |
|
| 977 |
def test_compare_chmod_value_false_1(): |
| 978 |
module_args = {'unix_permissions': '---rwxrwxrwx'} |
| 979 |
current = { |
| 980 |
'unix_permissions': '0' |
| 981 |
} |
| 982 |
vol_obj = create_module(vol_module, DEFAULT_ARGS, module_args) |
| 983 |
assert not vol_obj.na_helper.compare_chmod_value(current['unix_permissions'], module_args['unix_permissions']) |
| 984 |
|
| 985 |
|
| 986 |
def test_compare_chmod_value_false_2(): |
| 987 |
module_args = {'unix_permissions': '---rwxrwxrwx'} |
| 988 |
current = None |
| 989 |
vol_obj = create_module(vol_module, DEFAULT_ARGS, module_args) |
| 990 |
assert not vol_obj.na_helper.compare_chmod_value(current, module_args['unix_permissions']) |
| 991 |
|
| 992 |
|
| 993 |
def test_compare_chmod_value_invalid_input_1(): |
| 994 |
module_args = {'unix_permissions': '---xwrxwrxwr'} |
| 995 |
current = { |
| 996 |
'unix_permissions': '777' |
| 997 |
} |
| 998 |
vol_obj = create_module(vol_module, DEFAULT_ARGS, module_args) |
| 999 |
assert not vol_obj.na_helper.compare_chmod_value(current['unix_permissions'], module_args['unix_permissions']) |
| 1000 |
|
| 1001 |
|
| 1002 |
def test_compare_chmod_value_invalid_input_2(): |
| 1003 |
module_args = {'unix_permissions': '---rwx-wx--a'} |
| 1004 |
current = { |
| 1005 |
'unix_permissions': '0' |
| 1006 |
} |
| 1007 |
vol_obj = create_module(vol_module, DEFAULT_ARGS, module_args) |
| 1008 |
assert not vol_obj.na_helper.compare_chmod_value(current['unix_permissions'], module_args['unix_permissions']) |
| 1009 |
|
| 1010 |
|
| 1011 |
def test_compare_chmod_value_invalid_input_3(): |
| 1012 |
module_args = {'unix_permissions': '---'} |
| 1013 |
current = { |
| 1014 |
'unix_permissions': '0' |
| 1015 |
} |
| 1016 |
vol_obj = create_module(vol_module, DEFAULT_ARGS, module_args) |
| 1017 |
assert not vol_obj.na_helper.compare_chmod_value(current['unix_permissions'], module_args['unix_permissions']) |
| 1018 |
|
| 1019 |
|
| 1020 |
def test_compare_chmod_value_invalid_input_4(): |
| 1021 |
module_args = {'unix_permissions': 'rwx---rwxrwx'} |
| 1022 |
current = { |
| 1023 |
'unix_permissions': '0' |
| 1024 |
} |
| 1025 |
vol_obj = create_module(vol_module, DEFAULT_ARGS, module_args) |
| 1026 |
assert not vol_obj.na_helper.compare_chmod_value(current['unix_permissions'], module_args['unix_permissions']) |
| 1027 |
|
| 1028 |
|
| 1029 |
def test_successful_create_flex_group_manually(): |
| 1030 |
''' Test successful create flexGroup manually ''' |
| 1031 |
register_responses([ |
| 1032 |
('ZAPI', 'volume-get-iter', ZRR['empty']), |
| 1033 |
('ZAPI', 'volume-create-async', ZRR['success']), |
| 1034 |
('ZAPI', 'volume-get-iter', ZRR['get_flexgroup']), |
| 1035 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 1036 |
('ZAPI', 'volume-modify-iter-async', ZRR['modify_async_result_success']), |
| 1037 |
('ZAPI', 'job-get', ZRR['job_success']), |
| 1038 |
]) |
| 1039 |
args = copy.deepcopy(DEFAULT_ARGS) |
| 1040 |
del args['space_slo'] |
| 1041 |
module_args = { |
| 1042 |
'aggr_list': 'aggr_0,aggr_1', |
| 1043 |
'aggr_list_multiplier': 2, |
| 1044 |
'space_guarantee': 'file', |
| 1045 |
'time_out': 20 |
| 1046 |
} |
| 1047 |
assert create_and_apply(vol_module, args, module_args)['changed'] |
| 1048 |
|
| 1049 |
|
| 1050 |
def test_error_create_flex_group_manually(): |
| 1051 |
''' Test error create flexGroup manually ''' |
| 1052 |
register_responses([ |
| 1053 |
('ZAPI', 'volume-get-iter', ZRR['empty']), |
| 1054 |
('ZAPI', 'volume-create-async', ZRR['error']), |
| 1055 |
]) |
| 1056 |
module_args = { |
| 1057 |
'aggr_list': 'aggr_0,aggr_1', |
| 1058 |
'aggr_list_multiplier': 2, |
| 1059 |
'time_out': 20 |
| 1060 |
} |
| 1061 |
error = 'Error provisioning volume test_vol of size 20971520: %s' % ZAPI_ERROR |
| 1062 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == error |
| 1063 |
|
| 1064 |
|
| 1065 |
def test_partial_error_create_flex_group_manually(): |
| 1066 |
''' Test error create flexGroup manually ''' |
| 1067 |
register_responses([ |
| 1068 |
('GET', 'cluster', SRR['is_rest']), |
| 1069 |
('ZAPI', 'volume-get-iter', ZRR['empty']), |
| 1070 |
('ZAPI', 'volume-create-async', ZRR['success']), |
| 1071 |
('ZAPI', 'volume-get-iter', ZRR['get_flexgroup']), |
| 1072 |
('ZAPI', 'sis-get-iter', ZRR['insufficient_privileges']), # ignored but raises a warning |
| 1073 |
('ZAPI', 'volume-modify-iter-async', ZRR['modify_async_result_failure']), |
| 1074 |
]) |
| 1075 |
args = copy.deepcopy(DEFAULT_ARGS) |
| 1076 |
del args['space_slo'] |
| 1077 |
module_args = { |
| 1078 |
'aggr_list': 'aggr_0,aggr_1', |
| 1079 |
'aggr_list_multiplier': 2, |
| 1080 |
'space_guarantee': 'file', |
| 1081 |
'time_out': 20, |
| 1082 |
'use_rest': 'auto' |
| 1083 |
} |
| 1084 |
error = 'Volume created with success, with missing attributes: Error modifying volume test_vol: error_in_modify' |
| 1085 |
assert create_and_apply(vol_module, args, module_args, fail=True)['msg'] == error |
| 1086 |
print_warnings() |
| 1087 |
assert_warning_was_raised('cannot read volume efficiency options (as expected when running as vserver): ' |
| 1088 |
'NetApp API failed. Reason - 12346:Insufficient privileges: user USERID does not have read access to this resource') |
| 1089 |
|
| 1090 |
|
| 1091 |
def test_successful_create_flex_group_auto_provision(): |
| 1092 |
''' Test successful create flexGroup auto provision ''' |
| 1093 |
register_responses([ |
| 1094 |
('ZAPI', 'volume-get-iter', ZRR['empty']), |
| 1095 |
('ZAPI', 'volume-create-async', ZRR['success']), |
| 1096 |
('ZAPI', 'volume-get-iter', ZRR['get_flexgroup']), |
| 1097 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 1098 |
]) |
| 1099 |
module_args = { |
| 1100 |
'auto_provision_as': 'flexgroup', |
| 1101 |
'time_out': 20 |
| 1102 |
} |
| 1103 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 1104 |
|
| 1105 |
|
| 1106 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.get_volume') |
| 1107 |
def test_successful_delete_flex_group(get_volume): |
| 1108 |
''' Test successful delete flexGroup ''' |
| 1109 |
register_responses([ |
| 1110 |
('ZAPI', 'volume-unmount', ZRR['success']), |
| 1111 |
('ZAPI', 'volume-offline-async', ZRR['job_success']), |
| 1112 |
('ZAPI', 'volume-destroy-async', ZRR['job_success']), |
| 1113 |
]) |
| 1114 |
module_args = { |
| 1115 |
'state': 'absent', |
| 1116 |
} |
| 1117 |
current = { |
| 1118 |
'hostname': 'test', |
| 1119 |
'username': 'test_user', |
| 1120 |
'password': 'test_pass!', |
| 1121 |
'name': MOCK_VOL['name'], |
| 1122 |
'vserver': MOCK_VOL['vserver'], |
| 1123 |
'style_extended': 'flexgroup', |
| 1124 |
'unix_permissions': '755', |
| 1125 |
'is_online': True, |
| 1126 |
'uuid': 'uuid' |
| 1127 |
} |
| 1128 |
get_volume.return_value = current |
| 1129 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 1130 |
|
| 1131 |
|
| 1132 |
def setup_resize(): |
| 1133 |
module_args = { |
| 1134 |
'size': 400, |
| 1135 |
'size_unit': 'mb' |
| 1136 |
} |
| 1137 |
current = { |
| 1138 |
'hostname': 'test', |
| 1139 |
'username': 'test_user', |
| 1140 |
'password': 'test_pass!', |
| 1141 |
'name': MOCK_VOL['name'], |
| 1142 |
'vserver': MOCK_VOL['vserver'], |
| 1143 |
'style_extended': 'flexgroup', |
| 1144 |
'size': 20971520, |
| 1145 |
'unix_permissions': '755', |
| 1146 |
'uuid': '1234' |
| 1147 |
} |
| 1148 |
return module_args, current |
| 1149 |
|
| 1150 |
|
| 1151 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.get_volume') |
| 1152 |
def test_successful_resize_flex_group(get_volume): |
| 1153 |
''' Test successful reszie flexGroup ''' |
| 1154 |
register_responses([ |
| 1155 |
('ZAPI', 'volume-size-async', ZRR['job_success']), |
| 1156 |
]) |
| 1157 |
module_args, current = setup_resize() |
| 1158 |
get_volume.return_value = current |
| 1159 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 1160 |
|
| 1161 |
|
| 1162 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.get_volume') |
| 1163 |
def test_error_resize_flex_group(get_volume): |
| 1164 |
''' Test error reszie flexGroup ''' |
| 1165 |
register_responses([ |
| 1166 |
('ZAPI', 'volume-size-async', ZRR['error']), |
| 1167 |
]) |
| 1168 |
module_args, current = setup_resize() |
| 1169 |
get_volume.return_value = current |
| 1170 |
error = 'Error re-sizing volume test_vol: %s' % ZAPI_ERROR |
| 1171 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == error |
| 1172 |
|
| 1173 |
|
| 1174 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.check_job_status') |
| 1175 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.get_volume') |
| 1176 |
def test_successful_modify_unix_permissions_flex_group(get_volume, check_job_status): |
| 1177 |
''' Test successful modify unix permissions flexGroup ''' |
| 1178 |
register_responses([ |
| 1179 |
('ZAPI', 'volume-modify-iter-async', ZRR['modify_async_result_success']), |
| 1180 |
]) |
| 1181 |
module_args = { |
| 1182 |
'unix_permissions': '---rw-r-xr-x', |
| 1183 |
'time_out': 20 |
| 1184 |
} |
| 1185 |
current = { |
| 1186 |
'hostname': 'test', |
| 1187 |
'username': 'test_user', |
| 1188 |
'password': 'test_pass!', |
| 1189 |
'name': MOCK_VOL['name'], |
| 1190 |
'vserver': MOCK_VOL['vserver'], |
| 1191 |
'style_extended': 'flexgroup', |
| 1192 |
'unix_permissions': '777', |
| 1193 |
'uuid': '1234' |
| 1194 |
} |
| 1195 |
get_volume.return_value = current |
| 1196 |
check_job_status.return_value = None |
| 1197 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 1198 |
|
| 1199 |
|
| 1200 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.get_volume') |
| 1201 |
def test_successful_modify_unix_permissions_flex_group_0_time_out(get_volume): |
| 1202 |
''' Test successful modify unix permissions flexGroup ''' |
| 1203 |
register_responses([ |
| 1204 |
('ZAPI', 'volume-modify-iter-async', ZRR['modify_async_result_success']), |
| 1205 |
]) |
| 1206 |
module_args = { |
| 1207 |
'unix_permissions': '---rw-r-xr-x', |
| 1208 |
'time_out': 0 |
| 1209 |
} |
| 1210 |
current = { |
| 1211 |
'hostname': 'test', |
| 1212 |
'username': 'test_user', |
| 1213 |
'password': 'test_pass!', |
| 1214 |
'name': MOCK_VOL['name'], |
| 1215 |
'vserver': MOCK_VOL['vserver'], |
| 1216 |
'style_extended': 'flexgroup', |
| 1217 |
'unix_permissions': '777', |
| 1218 |
'uuid': '1234' |
| 1219 |
} |
| 1220 |
get_volume.return_value = current |
| 1221 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 1222 |
|
| 1223 |
|
| 1224 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.get_volume') |
| 1225 |
def test_successful_modify_unix_permissions_flex_group_0_missing_result(get_volume): |
| 1226 |
''' Test successful modify unix permissions flexGroup ''' |
| 1227 |
register_responses([ |
| 1228 |
('ZAPI', 'volume-modify-iter-async', ZRR['job_running']), # bad response |
| 1229 |
]) |
| 1230 |
module_args = { |
| 1231 |
'unix_permissions': '---rw-r-xr-x', |
| 1232 |
'time_out': 0 |
| 1233 |
} |
| 1234 |
current = { |
| 1235 |
'hostname': 'test', |
| 1236 |
'username': 'test_user', |
| 1237 |
'password': 'test_pass!', |
| 1238 |
'name': MOCK_VOL['name'], |
| 1239 |
'vserver': MOCK_VOL['vserver'], |
| 1240 |
'style_extended': 'flexgroup', |
| 1241 |
'unix_permissions': '777', |
| 1242 |
'uuid': '1234' |
| 1243 |
} |
| 1244 |
get_volume.return_value = current |
| 1245 |
# check_job_status.side_effect = ['job_error'] |
| 1246 |
error = create_and_apply(vol_module, DEFAULT_ARGS, module_args, 'fail') |
| 1247 |
assert error['msg'].startswith('Unexpected error when modifying volume: result is:') |
| 1248 |
|
| 1249 |
|
| 1250 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.check_job_status') |
| 1251 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.get_volume') |
| 1252 |
def test_error_modify_unix_permissions_flex_group(get_volume, check_job_status): |
| 1253 |
''' Test error modify unix permissions flexGroup ''' |
| 1254 |
register_responses([ |
| 1255 |
('ZAPI', 'volume-modify-iter-async', ZRR['modify_async_result_success']), |
| 1256 |
]) |
| 1257 |
module_args = { |
| 1258 |
'unix_permissions': '---rw-r-xr-x', |
| 1259 |
'time_out': 20 |
| 1260 |
} |
| 1261 |
current = { |
| 1262 |
'hostname': 'test', |
| 1263 |
'username': 'test_user', |
| 1264 |
'password': 'test_pass!', |
| 1265 |
'name': MOCK_VOL['name'], |
| 1266 |
'vserver': MOCK_VOL['vserver'], |
| 1267 |
'style_extended': 'flexgroup', |
| 1268 |
'unix_permissions': '777', |
| 1269 |
'uuid': '1234' |
| 1270 |
} |
| 1271 |
get_volume.return_value = current |
| 1272 |
check_job_status.side_effect = ['job_error'] |
| 1273 |
error = create_and_apply(vol_module, DEFAULT_ARGS, module_args, 'fail') |
| 1274 |
assert error['msg'] == 'Error when modifying volume: job_error' |
| 1275 |
|
| 1276 |
|
| 1277 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.get_volume') |
| 1278 |
def test_failure_modify_unix_permissions_flex_group(get_volume): |
| 1279 |
''' Test failure modify unix permissions flexGroup ''' |
| 1280 |
register_responses([ |
| 1281 |
('ZAPI', 'volume-modify-iter-async', ZRR['modify_async_result_failure']), |
| 1282 |
]) |
| 1283 |
module_args = { |
| 1284 |
'unix_permissions': '---rw-r-xr-x', |
| 1285 |
'time_out': 20 |
| 1286 |
} |
| 1287 |
current = { |
| 1288 |
'hostname': 'test', |
| 1289 |
'username': 'test_user', |
| 1290 |
'password': 'test_pass!', |
| 1291 |
'name': MOCK_VOL['name'], |
| 1292 |
'vserver': MOCK_VOL['vserver'], |
| 1293 |
'style_extended': 'flexgroup', |
| 1294 |
'unix_permissions': '777', |
| 1295 |
'uuid': '1234' |
| 1296 |
} |
| 1297 |
get_volume.return_value = current |
| 1298 |
error = create_and_apply(vol_module, DEFAULT_ARGS, module_args, 'fail') |
| 1299 |
assert error['msg'] == 'Error modifying volume test_vol: error_in_modify' |
| 1300 |
|
| 1301 |
|
| 1302 |
def setup_offline_state(): |
| 1303 |
module_args = {'is_online': False} |
| 1304 |
current = { |
| 1305 |
'hostname': 'test', |
| 1306 |
'username': 'test_user', |
| 1307 |
'password': 'test_pass!', |
| 1308 |
'name': MOCK_VOL['name'], |
| 1309 |
'vserver': MOCK_VOL['vserver'], |
| 1310 |
'style_extended': 'flexgroup', |
| 1311 |
'is_online': True, |
| 1312 |
'junction_path': '/test', |
| 1313 |
'unix_permissions': '755', |
| 1314 |
'uuid': '1234' |
| 1315 |
} |
| 1316 |
return module_args, current |
| 1317 |
|
| 1318 |
|
| 1319 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.get_volume') |
| 1320 |
def test_successful_offline_state_flex_group(get_volume): |
| 1321 |
''' Test successful offline flexGroup state ''' |
| 1322 |
register_responses([ |
| 1323 |
('ZAPI', 'volume-unmount', ZRR['success']), |
| 1324 |
('ZAPI', 'volume-offline-async', ZRR['async_results']), |
| 1325 |
('ZAPI', 'job-get', ZRR['job_success']), |
| 1326 |
]) |
| 1327 |
module_args, current = setup_offline_state() |
| 1328 |
get_volume.return_value = current |
| 1329 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 1330 |
|
| 1331 |
|
| 1332 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.get_volume') |
| 1333 |
def test_error_offline_state_flex_group(get_volume): |
| 1334 |
''' Test error offline flexGroup state ''' |
| 1335 |
register_responses([ |
| 1336 |
('ZAPI', 'volume-unmount', ZRR['success']), |
| 1337 |
('ZAPI', 'volume-offline-async', ZRR['error']), |
| 1338 |
]) |
| 1339 |
module_args, current = setup_offline_state() |
| 1340 |
get_volume.return_value = current |
| 1341 |
error = 'Error changing the state of volume test_vol to offline: %s' % ZAPI_ERROR |
| 1342 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == error |
| 1343 |
|
| 1344 |
|
| 1345 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.get_volume') |
| 1346 |
def test_error_unmounting_offline_state_flex_group(get_volume): |
| 1347 |
''' Test error offline flexGroup state ''' |
| 1348 |
register_responses([ |
| 1349 |
('ZAPI', 'volume-unmount', ZRR['error']), |
| 1350 |
('ZAPI', 'volume-offline-async', ZRR['error']), |
| 1351 |
]) |
| 1352 |
module_args, current = setup_offline_state() |
| 1353 |
get_volume.return_value = current |
| 1354 |
error = 'Error changing the state of volume test_vol to offline: %s' % ZAPI_ERROR |
| 1355 |
msg = create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] |
| 1356 |
assert error in msg |
| 1357 |
errpr = 'Error unmounting volume test_vol: %s' % ZAPI_ERROR |
| 1358 |
assert error in msg |
| 1359 |
|
| 1360 |
|
| 1361 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.get_volume') |
| 1362 |
def test_successful_online_state_flex_group(get_volume): |
| 1363 |
''' Test successful online flexGroup state ''' |
| 1364 |
register_responses([ |
| 1365 |
('ZAPI', 'volume-online-async', ZRR['async_results']), |
| 1366 |
('ZAPI', 'job-get', ZRR['job_success']), |
| 1367 |
('ZAPI', 'volume-modify-iter-async', ZRR['modify_async_result_success']), |
| 1368 |
('ZAPI', 'job-get', ZRR['job_success']), |
| 1369 |
('ZAPI', 'volume-mount', ZRR['success']), |
| 1370 |
]) |
| 1371 |
current = { |
| 1372 |
'hostname': 'test', |
| 1373 |
'username': 'test_user', |
| 1374 |
'password': 'test_pass!', |
| 1375 |
'name': MOCK_VOL['name'], |
| 1376 |
'vserver': MOCK_VOL['vserver'], |
| 1377 |
'style_extended': 'flexgroup', |
| 1378 |
'is_online': False, |
| 1379 |
'junction_path': 'anything', |
| 1380 |
'unix_permissions': '755', |
| 1381 |
'uuid': '1234' |
| 1382 |
} |
| 1383 |
get_volume.return_value = current |
| 1384 |
assert create_and_apply(vol_module, DEFAULT_ARGS)['changed'] |
| 1385 |
print_requests() |
| 1386 |
assert get_mock_record().is_text_in_zapi_request('<group-id>', 2) |
| 1387 |
assert get_mock_record().is_text_in_zapi_request('<user-id>', 2) |
| 1388 |
assert get_mock_record().is_text_in_zapi_request('<percentage-snapshot-reserve>', 2) |
| 1389 |
assert get_mock_record().is_text_in_zapi_request('<junction-path>/test</junction-path>', 4) |
| 1390 |
|
| 1391 |
|
| 1392 |
def test_check_job_status_error(): |
| 1393 |
''' Test check job status error ''' |
| 1394 |
register_responses([ |
| 1395 |
('ZAPI', 'job-get', ZRR['error']), |
| 1396 |
]) |
| 1397 |
module_args = { |
| 1398 |
'aggr_list': 'aggr_0,aggr_1', |
| 1399 |
'aggr_list_multiplier': 2, |
| 1400 |
'time_out': 0 |
| 1401 |
} |
| 1402 |
error = 'Error fetching job info: %s' % ZAPI_ERROR |
| 1403 |
assert expect_and_capture_ansible_exception(create_module(vol_module, MINIMUM_ARGS, module_args).check_job_status, 'fail', '123')['msg'] == error |
| 1404 |
|
| 1405 |
|
| 1406 |
@patch('time.sleep') |
| 1407 |
def test_check_job_status_not_found(skip_sleep): |
| 1408 |
''' Test check job status error ''' |
| 1409 |
register_responses([ |
| 1410 |
('ZAPI', 'job-get', ZRR['error_15661']), |
| 1411 |
('ZAPI', 'vserver-get-iter', ZRR['no_records']), |
| 1412 |
('ZAPI', 'job-get', ZRR['error_15661']), |
| 1413 |
]) |
| 1414 |
module_args = { |
| 1415 |
'aggr_list': 'aggr_0,aggr_1', |
| 1416 |
'aggr_list_multiplier': 2, |
| 1417 |
'time_out': 50 |
| 1418 |
} |
| 1419 |
error = 'cannot locate job with id: 123' |
| 1420 |
assert create_module(vol_module, MINIMUM_ARGS, module_args).check_job_status('123') == error |
| 1421 |
|
| 1422 |
|
| 1423 |
@patch('time.sleep') |
| 1424 |
def test_check_job_status_failure(skip_sleep): |
| 1425 |
''' Test check job status error ''' |
| 1426 |
register_responses([ |
| 1427 |
('ZAPI', 'job-get', ZRR['job_running']), |
| 1428 |
('ZAPI', 'job-get', ZRR['job_running']), |
| 1429 |
('ZAPI', 'job-get', ZRR['job_failure']), |
| 1430 |
('ZAPI', 'job-get', ZRR['job_running']), |
| 1431 |
('ZAPI', 'job-get', ZRR['job_running']), |
| 1432 |
('ZAPI', 'job-get', ZRR['job_no_completion']), |
| 1433 |
]) |
| 1434 |
module_args = { |
| 1435 |
'aggr_list': 'aggr_0,aggr_1', |
| 1436 |
'aggr_list_multiplier': 2, |
| 1437 |
'time_out': 20 |
| 1438 |
} |
| 1439 |
msg = 'failure' |
| 1440 |
assert msg == create_module(vol_module, MINIMUM_ARGS, module_args).check_job_status('123') |
| 1441 |
msg = 'progress' |
| 1442 |
assert msg == create_module(vol_module, MINIMUM_ARGS, module_args).check_job_status('123') |
| 1443 |
|
| 1444 |
|
| 1445 |
def test_check_job_status_time_out_is_0(): |
| 1446 |
''' Test check job status time out is 0''' |
| 1447 |
register_responses([ |
| 1448 |
('ZAPI', 'job-get', ZRR['job_time_out']), |
| 1449 |
]) |
| 1450 |
module_args = { |
| 1451 |
'aggr_list': 'aggr_0,aggr_1', |
| 1452 |
'aggr_list_multiplier': 2, |
| 1453 |
'time_out': 0 |
| 1454 |
} |
| 1455 |
msg = 'job completion exceeded expected timer of: 0 seconds' |
| 1456 |
assert msg == create_module(vol_module, MINIMUM_ARGS, module_args).check_job_status('123') |
| 1457 |
|
| 1458 |
|
| 1459 |
def test_check_job_status_unexpected(): |
| 1460 |
''' Test check job status unexpected state ''' |
| 1461 |
register_responses([ |
| 1462 |
('ZAPI', 'job-get', ZRR['job_other']), |
| 1463 |
]) |
| 1464 |
module_args = { |
| 1465 |
'aggr_list': 'aggr_0,aggr_1', |
| 1466 |
'aggr_list_multiplier': 2, |
| 1467 |
'time_out': 20 |
| 1468 |
} |
| 1469 |
msg = 'Unexpected job status in:' |
| 1470 |
assert msg in expect_and_capture_ansible_exception(create_module(vol_module, MINIMUM_ARGS, module_args).check_job_status, 'fail', '123')['msg'] |
| 1471 |
|
| 1472 |
|
| 1473 |
def test_successful_modify_tiering_policy(): |
| 1474 |
''' Test successful modify tiering policy ''' |
| 1475 |
register_responses([ |
| 1476 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 1477 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 1478 |
('ZAPI', 'volume-modify-iter', ZRR['success']), |
| 1479 |
]) |
| 1480 |
module_args = {'tiering_policy': 'auto'} |
| 1481 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 1482 |
print_requests() |
| 1483 |
assert get_mock_record().is_text_in_zapi_request('<tiering-policy>auto</tiering-policy>', 2) |
| 1484 |
|
| 1485 |
|
| 1486 |
def test_error_modify_tiering_policy(): |
| 1487 |
''' Test successful modify tiering policy ''' |
| 1488 |
register_responses([ |
| 1489 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 1490 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 1491 |
('ZAPI', 'volume-modify-iter', ZRR['error']), |
| 1492 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 1493 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 1494 |
('ZAPI', 'volume-modify-iter', ZRR['error_tiering_94']), |
| 1495 |
]) |
| 1496 |
module_args = {'tiering_policy': 'auto'} |
| 1497 |
error = zapi_error_message('Error modifying volume test_vol') |
| 1498 |
assert error in create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] |
| 1499 |
error = zapi_error_message('Error modifying volume test_vol', 94, 'volume-comp-aggr-attributes', '. Added info: tiering option requires 9.4 or later.') |
| 1500 |
assert error in create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] |
| 1501 |
|
| 1502 |
|
| 1503 |
def test_successful_modify_vserver_dr_protection(): |
| 1504 |
''' Test successful modify vserver_dr_protection ''' |
| 1505 |
register_responses([ |
| 1506 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 1507 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 1508 |
('ZAPI', 'volume-modify-iter', ZRR['success']), |
| 1509 |
]) |
| 1510 |
module_args = {'vserver_dr_protection': 'protected'} |
| 1511 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 1512 |
print_requests() |
| 1513 |
assert get_mock_record().is_text_in_zapi_request('<vserver-dr-protection>protected</vserver-dr-protection>', 2) |
| 1514 |
|
| 1515 |
|
| 1516 |
def test_successful_group_id(): |
| 1517 |
''' Test successful modify group_id ''' |
| 1518 |
register_responses([ |
| 1519 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 1520 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 1521 |
('ZAPI', 'volume-modify-iter', ZRR['success']), |
| 1522 |
]) |
| 1523 |
module_args = {'group_id': 1001} |
| 1524 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 1525 |
print_requests() |
| 1526 |
assert get_mock_record().is_text_in_zapi_request('<group-id>1001</group-id>', 2) |
| 1527 |
|
| 1528 |
|
| 1529 |
def test_successful_modify_user_id(): |
| 1530 |
''' Test successful modify user_id ''' |
| 1531 |
register_responses([ |
| 1532 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 1533 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 1534 |
('ZAPI', 'volume-modify-iter', ZRR['success']), |
| 1535 |
]) |
| 1536 |
module_args = {'user_id': 101} |
| 1537 |
assert create_and_apply(vol_module, DEFAULT_ARGS, module_args)['changed'] |
| 1538 |
print_requests() |
| 1539 |
assert get_mock_record().is_text_in_zapi_request('<user-id>101</user-id>', 2) |
| 1540 |
|
| 1541 |
|
| 1542 |
@patch('ansible_collections.netapp.ontap.plugins.modules.na_ontap_volume.NetAppOntapVolume.get_volume') |
| 1543 |
def test_successful_modify_snapshot_auto_delete(get_volume): |
| 1544 |
''' Test successful modify unix permissions flexGroup ''' |
| 1545 |
register_responses([ |
| 1546 |
# One ZAPI call for each option! |
| 1547 |
('ZAPI', 'volume-modify-iter', ZRR['success']), |
| 1548 |
('ZAPI', 'snapshot-autodelete-set-option', ZRR['success']), |
| 1549 |
('ZAPI', 'snapshot-autodelete-set-option', ZRR['success']), |
| 1550 |
('ZAPI', 'snapshot-autodelete-set-option', ZRR['success']), |
| 1551 |
('ZAPI', 'snapshot-autodelete-set-option', ZRR['success']), |
| 1552 |
('ZAPI', 'snapshot-autodelete-set-option', ZRR['success']), |
| 1553 |
('ZAPI', 'snapshot-autodelete-set-option', ZRR['success']), |
| 1554 |
('ZAPI', 'snapshot-autodelete-set-option', ZRR['success']), |
| 1555 |
('ZAPI', 'snapshot-autodelete-set-option', ZRR['success']), |
| 1556 |
]) |
| 1557 |
module_args = { |
| 1558 |
'snapshot_auto_delete': { |
| 1559 |
'delete_order': 'oldest_first', 'destroy_list': 'lun_clone,vol_clone', |
| 1560 |
'target_free_space': 20, 'prefix': 'test', 'commitment': 'try', |
| 1561 |
'state': 'on', 'trigger': 'snap_reserve', 'defer_delete': 'scheduled'}} |
| 1562 |
current = { |
| 1563 |
'name': MOCK_VOL['name'], |
| 1564 |
'vserver': MOCK_VOL['vserver'], |
| 1565 |
'snapshot_auto_delete': { |
| 1566 |
'delete_order': 'newest_first', 'destroy_list': 'lun_clone,vol_clone', |
| 1567 |
'target_free_space': 30, 'prefix': 'test', 'commitment': 'try', |
| 1568 |
'state': 'on', 'trigger': 'snap_reserve', 'defer_delete': 'scheduled'}, |
| 1569 |
'uuid': '1234' |
| 1570 |
} |
| 1571 |
get_volume.return_value = current |
| 1572 |
assert create_and_apply(vol_module, MINIMUM_ARGS, module_args)['changed'] |
| 1573 |
|
| 1574 |
|
| 1575 |
def test_error_modify_snapshot_auto_delete(): |
| 1576 |
register_responses([ |
| 1577 |
('ZAPI', 'snapshot-autodelete-set-option', ZRR['error']), |
| 1578 |
]) |
| 1579 |
module_args = {'snapshot_auto_delete': { |
| 1580 |
'delete_order': 'oldest_first', 'destroy_list': 'lun_clone,vol_clone', |
| 1581 |
'target_free_space': 20, 'prefix': 'test', 'commitment': 'try', |
| 1582 |
'state': 'on', 'trigger': 'snap_reserve', 'defer_delete': 'scheduled'}} |
| 1583 |
msg = 'Error setting snapshot auto delete options for volume test_vol: %s' % ZAPI_ERROR |
| 1584 |
assert msg == expect_and_capture_ansible_exception(create_module(vol_module, MINIMUM_ARGS, module_args).set_snapshot_auto_delete, 'fail')['msg'] |
| 1585 |
|
| 1586 |
|
| 1587 |
def test_successful_volume_rehost(): |
| 1588 |
register_responses([ |
| 1589 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), |
| 1590 |
('ZAPI', 'volume-rehost', ZRR['success']), |
| 1591 |
]) |
| 1592 |
module_args = { |
| 1593 |
'from_vserver': 'source_vserver', |
| 1594 |
'auto_remap_luns': False, |
| 1595 |
} |
| 1596 |
assert create_and_apply(vol_module, MINIMUM_ARGS, module_args)['changed'] |
| 1597 |
|
| 1598 |
|
| 1599 |
def test_error_volume_rehost(): |
| 1600 |
register_responses([ |
| 1601 |
('ZAPI', 'volume-rehost', ZRR['error']), |
| 1602 |
]) |
| 1603 |
module_args = { |
| 1604 |
'from_vserver': 'source_vserver', |
| 1605 |
'force_unmap_luns': False, |
| 1606 |
} |
| 1607 |
msg = 'Error rehosting volume test_vol: %s' % ZAPI_ERROR |
| 1608 |
assert msg == expect_and_capture_ansible_exception(create_module(vol_module, MINIMUM_ARGS, module_args).rehost_volume, 'fail')['msg'] |
| 1609 |
|
| 1610 |
|
| 1611 |
def test_successful_volume_restore(): |
| 1612 |
register_responses([ |
| 1613 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 1614 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 1615 |
('ZAPI', 'snapshot-restore-volume', ZRR['success']), |
| 1616 |
]) |
| 1617 |
module_args = { |
| 1618 |
'snapshot_restore': 'snapshot_copy', |
| 1619 |
'force_restore': True, |
| 1620 |
'preserve_lun_ids': True |
| 1621 |
} |
| 1622 |
assert create_and_apply(vol_module, MINIMUM_ARGS, module_args)['changed'] |
| 1623 |
|
| 1624 |
|
| 1625 |
def test_error_volume_restore(): |
| 1626 |
register_responses([ |
| 1627 |
('ZAPI', 'snapshot-restore-volume', ZRR['error']), |
| 1628 |
]) |
| 1629 |
module_args = {'snapshot_restore': 'snapshot_copy'} |
| 1630 |
msg = 'Error restoring volume test_vol: %s' % ZAPI_ERROR |
| 1631 |
assert msg == expect_and_capture_ansible_exception(create_module(vol_module, MINIMUM_ARGS, module_args).snapshot_restore_volume, 'fail')['msg'] |
| 1632 |
|
| 1633 |
|
| 1634 |
def test_error_modify_flexvol_to_flexgroup(): |
| 1635 |
''' Test successful modify vserver_dr_protection ''' |
| 1636 |
register_responses([ |
| 1637 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 1638 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 1639 |
]) |
| 1640 |
module_args = {'auto_provision_as': 'flexgroup'} |
| 1641 |
msg = 'Error: changing a volume from one backend to another is not allowed. Current: flexvol, desired: flexgroup.' |
| 1642 |
assert msg == create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] |
| 1643 |
|
| 1644 |
|
| 1645 |
def test_error_modify_flexgroup_to_flexvol(): |
| 1646 |
''' Changing the style from flexgroup to flexvol is not allowed ''' |
| 1647 |
register_responses([ |
| 1648 |
('ZAPI', 'volume-get-iter', ZRR['get_flexgroup']), |
| 1649 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 1650 |
]) |
| 1651 |
module_args = {'aggregate_name': 'nothing'} |
| 1652 |
msg = 'Error: aggregate_name option cannot be used with FlexGroups.' |
| 1653 |
assert msg == create_and_apply(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] |
| 1654 |
|
| 1655 |
|
| 1656 |
def test_error_snaplock_not_supported_with_zapi(): |
| 1657 |
''' Test successful modify vserver_dr_protection ''' |
| 1658 |
module_args = {'snaplock': {'retention': {'default': 'P30TM'}}} |
| 1659 |
msg = 'Error: snaplock option is not supported with ZAPI. It can only be used with REST. use_rest: never.' |
| 1660 |
assert msg == create_module(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] |
| 1661 |
|
| 1662 |
|
| 1663 |
def test_wait_for_task_completion_no_records(): |
| 1664 |
register_responses([ |
| 1665 |
('ZAPI', 'results', ZRR['no_records']), |
| 1666 |
]) |
| 1667 |
# using response to build a request |
| 1668 |
zapi_iter, valid = build_zapi_response({'fake-iter': 'any'}) |
| 1669 |
my_obj = create_module(vol_module, DEFAULT_ARGS) |
| 1670 |
assert my_obj.wait_for_task_completion(zapi_iter, lambda: True) is None |
| 1671 |
|
| 1672 |
|
| 1673 |
def test_wait_for_task_completion_one_response(): |
| 1674 |
register_responses([ |
| 1675 |
('ZAPI', 'results', ZRR['one_record_no_data']), |
| 1676 |
]) |
| 1677 |
# using response to build a request |
| 1678 |
zapi_iter, valid = build_zapi_response({'fake-iter': 'any'}) |
| 1679 |
my_obj = create_module(vol_module, DEFAULT_ARGS) |
| 1680 |
assert my_obj.wait_for_task_completion(zapi_iter, lambda x: False) is None |
| 1681 |
|
| 1682 |
|
| 1683 |
@patch('time.sleep') |
| 1684 |
def test_wait_for_task_completion_loop(skip_sleep): |
| 1685 |
register_responses([ |
| 1686 |
('ZAPI', 'results', ZRR['one_record_no_data']), |
| 1687 |
('ZAPI', 'results', ZRR['one_record_no_data']), |
| 1688 |
('ZAPI', 'results', ZRR['one_record_no_data']), |
| 1689 |
]) |
| 1690 |
|
| 1691 |
def check_state(x): |
| 1692 |
check_state.counter += 1 |
| 1693 |
# True continues the wait loop |
| 1694 |
# False exits the loop |
| 1695 |
return (True, True, False)[check_state.counter - 1] |
| 1696 |
|
| 1697 |
check_state.counter = 0 |
| 1698 |
|
| 1699 |
# using response to build a request |
| 1700 |
zapi_iter, valid = build_zapi_response({'fake-iter': 'any'}) |
| 1701 |
my_obj = create_module(vol_module, DEFAULT_ARGS) |
| 1702 |
assert my_obj.wait_for_task_completion(zapi_iter, check_state) is None |
| 1703 |
|
| 1704 |
|
| 1705 |
@patch('time.sleep') |
| 1706 |
def test_wait_for_task_completion_loop_with_recoverable_error(skip_sleep): |
| 1707 |
register_responses([ |
| 1708 |
('ZAPI', 'results', ZRR['one_record_no_data']), |
| 1709 |
('ZAPI', 'results', ZRR['error']), |
| 1710 |
('ZAPI', 'results', ZRR['error']), |
| 1711 |
('ZAPI', 'results', ZRR['error']), |
| 1712 |
('ZAPI', 'results', ZRR['one_record_no_data']), |
| 1713 |
('ZAPI', 'results', ZRR['error']), |
| 1714 |
('ZAPI', 'results', ZRR['error']), |
| 1715 |
('ZAPI', 'results', ZRR['error']), |
| 1716 |
('ZAPI', 'results', ZRR['one_record_no_data']), |
| 1717 |
]) |
| 1718 |
|
| 1719 |
def check_state(x): |
| 1720 |
check_state.counter += 1 |
| 1721 |
return (True, True, False)[check_state.counter - 1] |
| 1722 |
|
| 1723 |
check_state.counter = 0 |
| 1724 |
|
| 1725 |
# using response to build a request |
| 1726 |
zapi_iter, valid = build_zapi_response({'fake-iter': 'any'}) |
| 1727 |
my_obj = create_module(vol_module, DEFAULT_ARGS) |
| 1728 |
assert my_obj.wait_for_task_completion(zapi_iter, check_state) is None |
| 1729 |
|
| 1730 |
|
| 1731 |
@patch('time.sleep') |
| 1732 |
def test_wait_for_task_completion_loop_with_non_recoverable_error(skip_sleep): |
| 1733 |
register_responses([ |
| 1734 |
('ZAPI', 'results', ZRR['one_record_no_data']), |
| 1735 |
('ZAPI', 'results', ZRR['error']), |
| 1736 |
('ZAPI', 'results', ZRR['error']), |
| 1737 |
('ZAPI', 'results', ZRR['error']), |
| 1738 |
('ZAPI', 'results', ZRR['one_record_no_data']), |
| 1739 |
('ZAPI', 'results', ZRR['error']), |
| 1740 |
('ZAPI', 'results', ZRR['error']), |
| 1741 |
('ZAPI', 'results', ZRR['error']), |
| 1742 |
('ZAPI', 'results', ZRR['error']), |
| 1743 |
]) |
| 1744 |
|
| 1745 |
# using response to build a request |
| 1746 |
zapi_iter, valid = build_zapi_response({'fake-iter': 'any'}) |
| 1747 |
my_obj = create_module(vol_module, DEFAULT_ARGS) |
| 1748 |
assert str(my_obj.wait_for_task_completion(zapi_iter, lambda x: True)) == ZAPI_ERROR |
| 1749 |
|
| 1750 |
|
| 1751 |
@patch('time.sleep') |
| 1752 |
def test_start_encryption_conversion(skip_sleep): |
| 1753 |
register_responses([ |
| 1754 |
('ZAPI', 'volume-encryption-conversion-start', ZRR['success']), |
| 1755 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['vol_encryption_conversion_status_running']), |
| 1756 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['vol_encryption_conversion_status_running']), |
| 1757 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['vol_encryption_conversion_status_idle']), |
| 1758 |
]) |
| 1759 |
module_args = { |
| 1760 |
'wait_for_completion': True, |
| 1761 |
'max_wait_time': 120 |
| 1762 |
} |
| 1763 |
my_obj = create_module(vol_module, DEFAULT_ARGS, module_args) |
| 1764 |
assert my_obj.start_encryption_conversion(True) is None |
| 1765 |
|
| 1766 |
|
| 1767 |
@patch('time.sleep') |
| 1768 |
def test_error_on_wait_for_start_encryption_conversion(skip_sleep): |
| 1769 |
register_responses([ |
| 1770 |
('ZAPI', 'volume-encryption-conversion-start', ZRR['success']), |
| 1771 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['vol_encryption_conversion_status_running']), |
| 1772 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['error']), |
| 1773 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['error']), |
| 1774 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['error']), |
| 1775 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['vol_encryption_conversion_status_running']), |
| 1776 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['error']), |
| 1777 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['error']), |
| 1778 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['error']), |
| 1779 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['error']), |
| 1780 |
]) |
| 1781 |
module_args = { |
| 1782 |
'wait_for_completion': True, |
| 1783 |
'max_wait_time': 280 |
| 1784 |
} |
| 1785 |
my_obj = create_module(vol_module, DEFAULT_ARGS, module_args) |
| 1786 |
error = expect_and_capture_ansible_exception(my_obj.start_encryption_conversion, 'fail', True)['msg'] |
| 1787 |
assert error == 'Error getting volume encryption_conversion status: %s' % ZAPI_ERROR |
| 1788 |
|
| 1789 |
|
| 1790 |
def test_error_start_encryption_conversion(): |
| 1791 |
register_responses([ |
| 1792 |
('ZAPI', 'volume-encryption-conversion-start', ZRR['error']), |
| 1793 |
]) |
| 1794 |
module_args = { |
| 1795 |
'wait_for_completion': True |
| 1796 |
} |
| 1797 |
my_obj = create_module(vol_module, DEFAULT_ARGS, module_args) |
| 1798 |
error = expect_and_capture_ansible_exception(my_obj.start_encryption_conversion, 'fail', True)['msg'] |
| 1799 |
assert error == 'Error enabling encryption for volume test_vol: %s' % ZAPI_ERROR |
| 1800 |
|
| 1801 |
|
| 1802 |
@patch('time.sleep') |
| 1803 |
def test_wait_for_volume_encryption_conversion_with_non_recoverable_error(skip_sleep): |
| 1804 |
register_responses([ |
| 1805 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['vol_encryption_conversion_status_running']), |
| 1806 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['error']), |
| 1807 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['error']), |
| 1808 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['error']), |
| 1809 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['vol_encryption_conversion_status_running']), |
| 1810 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['error']), |
| 1811 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['error']), |
| 1812 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['error']), |
| 1813 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['error']), |
| 1814 |
]) |
| 1815 |
my_obj = create_module(vol_module, DEFAULT_ARGS) |
| 1816 |
error = expect_and_capture_ansible_exception(my_obj.wait_for_volume_encryption_conversion, 'fail')['msg'] |
| 1817 |
assert error == 'Error getting volume encryption_conversion status: %s' % ZAPI_ERROR |
| 1818 |
|
| 1819 |
|
| 1820 |
@patch('time.sleep') |
| 1821 |
def test_wait_for_volume_encryption_conversion(skip_sleep): |
| 1822 |
register_responses([ |
| 1823 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['vol_encryption_conversion_status_running']), |
| 1824 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['error']), |
| 1825 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['error']), |
| 1826 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['error']), |
| 1827 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['vol_encryption_conversion_status_idle']), |
| 1828 |
]) |
| 1829 |
my_obj = create_module(vol_module, DEFAULT_ARGS) |
| 1830 |
assert my_obj.wait_for_volume_encryption_conversion() is None |
| 1831 |
|
| 1832 |
|
| 1833 |
def test_wait_for_volume_encryption_conversion_bad_status(): |
| 1834 |
register_responses([ |
| 1835 |
('ZAPI', 'volume-encryption-conversion-get-iter', ZRR['vol_encryption_conversion_status_error']), |
| 1836 |
]) |
| 1837 |
my_obj = create_module(vol_module, DEFAULT_ARGS) |
| 1838 |
error = expect_and_capture_ansible_exception(my_obj.wait_for_volume_encryption_conversion, 'fail')['msg'] |
| 1839 |
assert error == 'Error converting encryption for volume test_vol: other' |
| 1840 |
|
| 1841 |
|
| 1842 |
@patch('time.sleep') |
| 1843 |
def test_wait_for_volume_move_with_non_recoverable_error(skip_sleep): |
| 1844 |
register_responses([ |
| 1845 |
('ZAPI', 'volume-move-get-iter', ZRR['vol_move_status_running']), |
| 1846 |
('ZAPI', 'volume-move-get-iter', ZRR['error']), |
| 1847 |
('ZAPI', 'volume-move-get-iter', ZRR['error']), |
| 1848 |
('ZAPI', 'volume-move-get-iter', ZRR['error']), |
| 1849 |
('ZAPI', 'volume-move-get-iter', ZRR['vol_move_status_running']), |
| 1850 |
('ZAPI', 'volume-move-get-iter', ZRR['error']), |
| 1851 |
('ZAPI', 'volume-move-get-iter', ZRR['error']), |
| 1852 |
('ZAPI', 'volume-move-get-iter', ZRR['error']), |
| 1853 |
('ZAPI', 'volume-move-get-iter', ZRR['error']), |
| 1854 |
]) |
| 1855 |
my_obj = create_module(vol_module, DEFAULT_ARGS) |
| 1856 |
error = expect_and_capture_ansible_exception(my_obj.wait_for_volume_move, 'fail')['msg'] |
| 1857 |
assert error == 'Error getting volume move status: %s' % ZAPI_ERROR |
| 1858 |
|
| 1859 |
|
| 1860 |
@patch('time.sleep') |
| 1861 |
def test_wait_for_volume_move(skip_sleep): |
| 1862 |
register_responses([ |
| 1863 |
('ZAPI', 'volume-move-get-iter', ZRR['vol_move_status_running']), |
| 1864 |
('ZAPI', 'volume-move-get-iter', ZRR['error']), |
| 1865 |
('ZAPI', 'volume-move-get-iter', ZRR['error']), |
| 1866 |
('ZAPI', 'volume-move-get-iter', ZRR['error']), |
| 1867 |
('ZAPI', 'volume-move-get-iter', ZRR['vol_move_status_idle']), |
| 1868 |
]) |
| 1869 |
my_obj = create_module(vol_module, DEFAULT_ARGS) |
| 1870 |
assert my_obj.wait_for_volume_move() is None |
| 1871 |
|
| 1872 |
|
| 1873 |
def test_wait_for_volume_move_bad_status(): |
| 1874 |
register_responses([ |
| 1875 |
('ZAPI', 'volume-move-get-iter', ZRR['vol_move_status_error']), |
| 1876 |
]) |
| 1877 |
my_obj = create_module(vol_module, DEFAULT_ARGS) |
| 1878 |
error = expect_and_capture_ansible_exception(my_obj.wait_for_volume_move, 'fail')['msg'] |
| 1879 |
assert error == 'Error moving volume test_vol: some info' |
| 1880 |
|
| 1881 |
|
| 1882 |
def test_error_validate_snapshot_auto_delete(): |
| 1883 |
module_args = { |
| 1884 |
'snapshot_auto_delete': { |
| 1885 |
'commitment': 'whatever', |
| 1886 |
'unknown': 'unexpected option' |
| 1887 |
} |
| 1888 |
} |
| 1889 |
error = "snapshot_auto_delete option 'unknown' is not valid." |
| 1890 |
assert create_module(vol_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == error |
| 1891 |
|
| 1892 |
|
| 1893 |
def test_get_snapshot_auto_delete_attributes(): |
| 1894 |
register_responses([ |
| 1895 |
('ZAPI', 'volume-get-iter', ZRR['get_flexgroup']), |
| 1896 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 1897 |
]) |
| 1898 |
result = create_module(vol_module, DEFAULT_ARGS).get_volume() |
| 1899 |
assert 'snapshot_auto_delete' in result |
| 1900 |
assert 'is_autodelete_enabled' not in result['snapshot_auto_delete'] |
| 1901 |
assert result['snapshot_auto_delete']['state'] == 'on' |
| 1902 |
|
| 1903 |
|
| 1904 |
def test_error_on_get_efficiency_info(): |
| 1905 |
register_responses([ |
| 1906 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 1907 |
('ZAPI', 'sis-get-iter', ZRR['error']), |
| 1908 |
]) |
| 1909 |
error = 'Error fetching efficiency policy for volume test_vol: %s' % ZAPI_ERROR |
| 1910 |
assert call_main(my_main, DEFAULT_ARGS, fail=True)['msg'] == error |
| 1911 |
|
| 1912 |
|
| 1913 |
def test_create_volume_from_main(): |
| 1914 |
register_responses([ |
| 1915 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), |
| 1916 |
('ZAPI', 'volume-create', ZRR['success']), |
| 1917 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 1918 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 1919 |
('ZAPI', 'volume-modify-iter', ZRR['success']), |
| 1920 |
('ZAPI', 'volume-unmount', ZRR['success']), |
| 1921 |
('ZAPI', 'volume-offline', ZRR['success']) |
| 1922 |
]) |
| 1923 |
args = dict(DEFAULT_ARGS) |
| 1924 |
del args['space_slo'] |
| 1925 |
module_args = { |
| 1926 |
'aggregate_name': MOCK_VOL['aggregate'], |
| 1927 |
'comment': 'some comment', |
| 1928 |
'is_online': False, |
| 1929 |
'space_guarantee': 'file', |
| 1930 |
'tiering_policy': 'snapshot-only', |
| 1931 |
'volume_security_style': 'unix', |
| 1932 |
'vserver_dr_protection': 'unprotected', |
| 1933 |
} |
| 1934 |
assert call_main(my_main, args, module_args)['changed'] |
| 1935 |
|
| 1936 |
|
| 1937 |
def test_error_create_volume_change_in_type(): |
| 1938 |
register_responses([ |
| 1939 |
('ZAPI', 'volume-get-iter', ZRR['no_records']), |
| 1940 |
('ZAPI', 'volume-create', ZRR['success']), |
| 1941 |
('ZAPI', 'volume-get-iter', ZRR['get_flexvol']), |
| 1942 |
('ZAPI', 'sis-get-iter', ZRR['no_records']), |
| 1943 |
]) |
| 1944 |
args = dict(DEFAULT_ARGS) |
| 1945 |
module_args = { |
| 1946 |
'aggregate_name': MOCK_VOL['aggregate'], |
| 1947 |
'type': 'dp', |
| 1948 |
} |
| 1949 |
error = 'Error: volume type was not set properly at creation time. Current: rw, desired: dp.' |
| 1950 |
assert call_main(my_main, args, module_args, fail=True)['msg'] == error |
| 1951 |
|
| 1952 |
|
| 1953 |
def test_create_volume_attribute(): |
| 1954 |
obj = create_module(vol_module, DEFAULT_ARGS) |
| 1955 |
# str |
| 1956 |
obj.parameters['option_name'] = 'my_option' |
| 1957 |
parent = netapp_utils.zapi.NaElement('results') |
| 1958 |
obj.create_volume_attribute(None, parent, 'zapi_name', 'option_name') |
| 1959 |
print(parent.to_string()) |
| 1960 |
assert parent['zapi_name'] == 'my_option' |
| 1961 |
# int - fail, unless converted |
| 1962 |
obj.parameters['option_name'] = 123 |
| 1963 |
expect_and_capture_ansible_exception(obj.create_volume_attribute, TypeError, None, parent, 'zapi_name', 'option_name') |
| 1964 |
parent = netapp_utils.zapi.NaElement('results') |
| 1965 |
obj.create_volume_attribute(None, parent, 'zapi_name', 'option_name', int) |
| 1966 |
assert parent['zapi_name'] == '123' |
| 1967 |
# boolmodify_volume_efficiency_config |
| 1968 |
obj.parameters['option_name'] = False |
| 1969 |
parent = netapp_utils.zapi.NaElement('results') |
| 1970 |
obj.create_volume_attribute(None, parent, 'zapi_name', 'option_name', bool) |
| 1971 |
assert parent['zapi_name'] == 'false' |
| 1972 |
# parent->attrs->attr |
| 1973 |
# create child |
| 1974 |
parent = netapp_utils.zapi.NaElement('results') |
| 1975 |
obj.create_volume_attribute('child', parent, 'zapi_name', 'option_name', bool) |
| 1976 |
assert parent['child']['zapi_name'] == 'false' |
| 1977 |
# use existing child in parent |
| 1978 |
obj.create_volume_attribute('child', parent, 'zapi_name2', 'option_name', bool) |
| 1979 |
assert parent['child']['zapi_name2'] == 'false' |
| 1980 |
# pass child |
| 1981 |
parent = netapp_utils.zapi.NaElement('results') |
| 1982 |
child = netapp_utils.zapi.NaElement('child') |
| 1983 |
obj.create_volume_attribute(child, parent, 'zapi_name', 'option_name', bool) |
| 1984 |
assert parent['child']['zapi_name'] == 'false' |
| 1985 |
|
| 1986 |
|
| 1987 |
def test_check_invoke_result(): |
| 1988 |
register_responses([ |
| 1989 |
# 3rd run |
| 1990 |
('ZAPI', 'job-get', ZRR['job_success']), |
| 1991 |
# 3th run |
| 1992 |
('ZAPI', 'job-get', ZRR['job_failure']), |
| 1993 |
]) |
| 1994 |
module_args = { |
| 1995 |
'time_out': 0 |
| 1996 |
} |
| 1997 |
obj = create_module(vol_module, DEFAULT_ARGS, module_args) |
| 1998 |
# 1 - operation failed immediately |
| 1999 |
error = 'Operation failed when testing volume.' |
| 2000 |
assert error in expect_and_capture_ansible_exception(obj.check_invoke_result, 'fail', ZRR['failed_results'][0], 'testing')['msg'] |
| 2001 |
# 2 - operation in progress - exit immediately as time_out is 0 |
| 2002 |
assert obj.check_invoke_result(ZRR['async_results'][0], 'testing') is None |
| 2003 |
module_args = { |
| 2004 |
'time_out': 10 |
| 2005 |
} |
| 2006 |
# 3 - operation in progress - job reported success |
| 2007 |
obj = create_module(vol_module, DEFAULT_ARGS, module_args) |
| 2008 |
assert obj.check_invoke_result(ZRR['async_results'][0], 'testing') is None |
| 2009 |
# 4 - operation in progress - job reported a failure |
| 2010 |
obj = create_module(vol_module, DEFAULT_ARGS, module_args) |
| 2011 |
error = 'Error when testing volume: failure' |
| 2012 |
assert error in expect_and_capture_ansible_exception(obj.check_invoke_result, 'fail', ZRR['async_results'][0], 'testing')['msg'] |