| 1 |
# (c) 2018-2026, 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 |
|
| 7 |
from __future__ import (absolute_import, division, print_function) |
| 8 |
__metaclass__ = type |
| 9 |
|
| 10 |
import pytest |
| 11 |
import sys |
| 12 |
|
| 13 |
from ansible_collections.netapp.ontap.tests.unit.compat.mock import patch |
| 14 |
import ansible_collections.netapp.ontap.plugins.module_utils.netapp as netapp_utils |
| 15 |
# pylint: disable=unused-import |
| 16 |
from ansible_collections.netapp.ontap.tests.unit.plugins.module_utils.ansible_mocks import \ |
| 17 |
assert_warning_was_raised, call_main, clear_warnings, create_and_apply, create_module, expect_and_capture_ansible_exception, patch_ansible, print_warnings |
| 18 |
from ansible_collections.netapp.ontap.tests.unit.framework.mock_rest_and_zapi_requests import \ |
| 19 |
patch_request_and_invoke, register_responses |
| 20 |
from ansible_collections.netapp.ontap.tests.unit.framework.rest_factory import rest_responses |
| 21 |
from ansible_collections.netapp.ontap.tests.unit.framework.zapi_factory import build_zapi_response, zapi_responses |
| 22 |
|
| 23 |
from ansible_collections.netapp.ontap.plugins.modules.na_ontap_svm \ |
| 24 |
import NetAppOntapSVM as svm_module, main as my_main # module under test |
| 25 |
|
| 26 |
# if not netapp_utils.has_netapp_lib(): |
| 27 |
# pytestmark = pytest.mark.skip('skipping as missing required netapp_lib') |
| 28 |
|
| 29 |
if not netapp_utils.HAS_REQUESTS and sys.version_info < (2, 7): |
| 30 |
pytestmark = pytest.mark.skip('Skipping Unit Tests on 2.6 as requests is not available') |
| 31 |
|
| 32 |
# REST API canned responses when mocking send_request |
| 33 |
|
| 34 |
svm_info = { |
| 35 |
"uuid": "09e9fd5e-8ebd-11e9-b162-005056b39fe7", |
| 36 |
"name": "test_svm", |
| 37 |
"state": "running", |
| 38 |
"subtype": "default", |
| 39 |
"language": "c.utf_8", |
| 40 |
"aggregates": [{"name": "aggr_1", |
| 41 |
"uuid": "850dd65b-8811-4611-ac8c-6f6240475ff9"}, |
| 42 |
{"name": "aggr_2", |
| 43 |
"uuid": "850dd65b-8811-4611-ac8c-6f6240475ff9"}], |
| 44 |
"comment": "new comment", |
| 45 |
"ipspace": {"name": "ansible_ipspace", |
| 46 |
"uuid": "2b760d31-8dfd-11e9-b162-005056b39fe7"}, |
| 47 |
"snapshot_policy": {"uuid": "3b611707-8dfd-11e9-b162-005056b39fe7", |
| 48 |
"name": "old_snapshot_policy"}, |
| 49 |
"nfs": {"enabled": True, "allowed": True}, |
| 50 |
"cifs": {"enabled": False}, |
| 51 |
"iscsi": {"enabled": False}, |
| 52 |
"fcp": {"enabled": False}, |
| 53 |
"nvme": {"enabled": False}, |
| 54 |
"max_volumes": 3333, |
| 55 |
"auto_enable_analytics": False, |
| 56 |
"auto_enable_activity_tracking": False, |
| 57 |
"storage": {"limit": 0, |
| 58 |
"limit_threshold_alert": 90}, |
| 59 |
"anti_ransomware_default_volume_state": "disabled" |
| 60 |
} |
| 61 |
|
| 62 |
svm_info_cert1 = dict(svm_info) |
| 63 |
svm_info_cert1['certificate'] = {'name': 'cert_1', 'uuid': 'cert_uuid_1'} |
| 64 |
svm_info_cert2 = dict(svm_info) |
| 65 |
svm_info_cert2['certificate'] = {'name': 'cert_2', 'uuid': 'cert_uuid_2'} |
| 66 |
|
| 67 |
SRR = rest_responses({ |
| 68 |
'svm_record': (200, {'records': [svm_info]}, None), |
| 69 |
'svm_record_cert1': (200, {'records': [svm_info_cert1]}, None), |
| 70 |
'svm_record_cert2': (200, {'records': [svm_info_cert2]}, None), |
| 71 |
'svm_record_ap': (200, |
| 72 |
{'records': [{"name": "test_svm", |
| 73 |
"state": "running", |
| 74 |
"aggregates": [{"name": "aggr_1", |
| 75 |
"uuid": "850dd65b-8811-4611-ac8c-6f6240475ff9"}, |
| 76 |
{"name": "aggr_2", |
| 77 |
"uuid": "850dd65b-8811-4611-ac8c-6f6240475ff9"}], |
| 78 |
"ipspace": {"name": "ansible_ipspace", |
| 79 |
"uuid": "2b760d31-8dfd-11e9-b162-005056b39fe7"}, |
| 80 |
"snapshot_policy": {"uuid": "3b611707-8dfd-11e9-b162-005056b39fe7", |
| 81 |
"name": "old_snapshot_policy"}, |
| 82 |
"nfs": {"enabled": False}, |
| 83 |
"cifs": {"enabled": True, "allowed": True}, |
| 84 |
"iscsi": {"enabled": True, "allowed": True}, |
| 85 |
"fcp": {"enabled": False}, |
| 86 |
"nvme": {"enabled": False}, |
| 87 |
"s3": {"allowed": True, "enabled": False}, |
| 88 |
"language": "de.utf_8", |
| 89 |
"uuid": "svm_uuid" |
| 90 |
}]}, None), |
| 91 |
'cli_record': (200, |
| 92 |
{'records': [{"max_volumes": 100, "allowed_protocols": ['nfs', 'iscsi']}]}, None), |
| 93 |
'certificate_record_1': (200, |
| 94 |
{'records': [{"name": "cert_1", |
| 95 |
"uuid": "cert_uuid_1"}]}, None), |
| 96 |
'certificate_record_2': (200, |
| 97 |
{'records': [{"name": "cert_2", |
| 98 |
"uuid": "cert_uuid_2"}]}, None), |
| 99 |
'svm_web_record_1': (200, { |
| 100 |
'records': [{ |
| 101 |
'certificate': { |
| 102 |
"uuid": "cert_uuid_1" |
| 103 |
}, |
| 104 |
'client_enabled': False, |
| 105 |
'ocsp_enabled': False, |
| 106 |
}]}, None), |
| 107 |
'svm_web_record_2': (200, { |
| 108 |
'records': [{ |
| 109 |
'certificate': { |
| 110 |
"uuid": "cert_uuid_2" |
| 111 |
}, |
| 112 |
'client_enabled': True, |
| 113 |
'ocsp_enabled': True, |
| 114 |
}]}, None) |
| 115 |
}, False) |
| 116 |
|
| 117 |
DEFAULT_ARGS = { |
| 118 |
'name': 'test_svm', |
| 119 |
'aggr_list': 'aggr_1,aggr_2', |
| 120 |
'ipspace': 'ansible_ipspace', |
| 121 |
'comment': 'new comment', |
| 122 |
'subtype': 'default', |
| 123 |
'hostname': 'test', |
| 124 |
'username': 'test_user', |
| 125 |
'password': 'test_pass!' |
| 126 |
} |
| 127 |
|
| 128 |
vserver_info = { |
| 129 |
'num-records': 1, |
| 130 |
'attributes-list': { |
| 131 |
'vserver-info': { |
| 132 |
'vserver-name': 'test_svm', |
| 133 |
'ipspace': 'ansible_ipspace', |
| 134 |
'root-volume': 'ansible_vol', |
| 135 |
'root-volume-aggregate': 'ansible_aggr', |
| 136 |
'language': 'c.utf_8', |
| 137 |
'comment': 'new comment', |
| 138 |
'snapshot-policy': 'old_snapshot_policy', |
| 139 |
'vserver-subtype': 'default', |
| 140 |
'allowed-protocols': [{'protocol': 'nfs'}, {'protocol': 'cifs'}], |
| 141 |
'aggr-list': [{'aggr-name': 'aggr_1'}, {'aggr-name': 'aggr_2'}], |
| 142 |
}}} |
| 143 |
|
| 144 |
|
| 145 |
ZRR = zapi_responses({ |
| 146 |
'svm_record': build_zapi_response(vserver_info) |
| 147 |
}) |
| 148 |
|
| 149 |
|
| 150 |
def test_module_fail_when_required_args_missing(): |
| 151 |
''' required arguments are reported as errors ''' |
| 152 |
error = create_module(svm_module, {}, fail=True)['msg'] |
| 153 |
assert 'missing required arguments:' in error |
| 154 |
assert 'hostname' in error |
| 155 |
assert 'name' in error |
| 156 |
|
| 157 |
|
| 158 |
def test_error_missing_name(): |
| 159 |
''' Test if create throws an error if name is not specified''' |
| 160 |
register_responses([ |
| 161 |
]) |
| 162 |
args = dict(DEFAULT_ARGS) |
| 163 |
args.pop('name') |
| 164 |
assert create_module(svm_module, args, fail=True)['msg'] == 'missing required arguments: name' |
| 165 |
|
| 166 |
|
| 167 |
@patch('ansible_collections.netapp.ontap.plugins.module_utils.netapp.has_netapp_lib') |
| 168 |
def test_error_missing_netapp_lib(mock_has_netapp_lib): |
| 169 |
register_responses([ |
| 170 |
]) |
| 171 |
mock_has_netapp_lib.return_value = False |
| 172 |
msg = 'Error: the python NetApp-Lib module is required. Import error:' |
| 173 |
extra_args = {'use_rest': 'never'} |
| 174 |
assert msg in create_module(svm_module, DEFAULT_ARGS, extra_args, fail=True)['msg'] |
| 175 |
|
| 176 |
|
| 177 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 178 |
def test_successful_create_zapi(): |
| 179 |
'''Test successful create''' |
| 180 |
register_responses([ |
| 181 |
('GET', 'cluster', SRR['is_zapi']), |
| 182 |
('ZAPI', 'vserver-get-iter', ZRR['no_records']), |
| 183 |
('ZAPI', 'vserver-create', ZRR['success']), |
| 184 |
('ZAPI', 'vserver-modify', ZRR['success']), |
| 185 |
]) |
| 186 |
args = {'use_rest': 'auto'} |
| 187 |
assert create_and_apply(svm_module, DEFAULT_ARGS, args)['changed'] |
| 188 |
|
| 189 |
|
| 190 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 191 |
def test_create_idempotency(): |
| 192 |
'''Test API create''' |
| 193 |
register_responses([ |
| 194 |
('GET', 'cluster', SRR['is_zapi']), |
| 195 |
('ZAPI', 'vserver-get-iter', ZRR['svm_record']), |
| 196 |
]) |
| 197 |
args = {'use_rest': 'auto'} |
| 198 |
assert not create_and_apply(svm_module, DEFAULT_ARGS, args)['changed'] |
| 199 |
|
| 200 |
|
| 201 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 202 |
def test_create_error(): |
| 203 |
'''Test successful create''' |
| 204 |
register_responses([ |
| 205 |
('GET', 'cluster', SRR['is_zapi']), |
| 206 |
('ZAPI', 'vserver-get-iter', ZRR['no_records']), |
| 207 |
('ZAPI', 'vserver-create', ZRR['error']), |
| 208 |
]) |
| 209 |
args = {'use_rest': 'auto'} |
| 210 |
msg = 'Error provisioning SVM test_svm: NetApp API failed. Reason - 12345:synthetic error for UT purpose' |
| 211 |
assert create_and_apply(svm_module, DEFAULT_ARGS, args, fail=True)['msg'] == msg |
| 212 |
|
| 213 |
|
| 214 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 215 |
def test_successful_delete(): |
| 216 |
'''Test successful delete''' |
| 217 |
register_responses([ |
| 218 |
('GET', 'cluster', SRR['is_zapi']), |
| 219 |
('ZAPI', 'vserver-get-iter', ZRR['svm_record']), |
| 220 |
('ZAPI', 'vserver-destroy', ZRR['success']), |
| 221 |
]) |
| 222 |
_modify_options_with_expected_change('state', 'absent') |
| 223 |
|
| 224 |
|
| 225 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 226 |
def test_error_delete(): |
| 227 |
'''Test delete with ZAPI error |
| 228 |
''' |
| 229 |
register_responses([ |
| 230 |
('GET', 'cluster', SRR['is_zapi']), |
| 231 |
('ZAPI', 'vserver-get-iter', ZRR['svm_record']), |
| 232 |
('ZAPI', 'vserver-destroy', ZRR['error']), |
| 233 |
]) |
| 234 |
module_args = { |
| 235 |
'state': 'absent', |
| 236 |
'use_rest': 'auto' |
| 237 |
} |
| 238 |
msg = 'Error deleting SVM test_svm: NetApp API failed. Reason - 12345:synthetic error for UT purpose' |
| 239 |
assert call_main(my_main, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 240 |
|
| 241 |
|
| 242 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 243 |
def test_delete_idempotency(): |
| 244 |
'''Test delete idempotency ''' |
| 245 |
register_responses([ |
| 246 |
('GET', 'cluster', SRR['is_zapi']), |
| 247 |
('ZAPI', 'vserver-get-iter', ZRR['no_records']), |
| 248 |
]) |
| 249 |
module_args = { |
| 250 |
'state': 'absent', |
| 251 |
'use_rest': 'auto' |
| 252 |
} |
| 253 |
assert not create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 254 |
|
| 255 |
|
| 256 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 257 |
def test_init(): |
| 258 |
'''Validate that: |
| 259 |
admin_state is ignored with ZAPI |
| 260 |
language is set to lower case for C.UTF-8 |
| 261 |
''' |
| 262 |
register_responses([ |
| 263 |
('GET', 'cluster', SRR['is_zapi']), |
| 264 |
]) |
| 265 |
module_args = { |
| 266 |
'admin_state': 'running', |
| 267 |
'language': 'C.uTf-8', |
| 268 |
'use_rest': 'auto' |
| 269 |
} |
| 270 |
my_obj = create_module(svm_module, DEFAULT_ARGS, module_args) |
| 271 |
assert my_obj.parameters['language'] == 'c.utf_8' |
| 272 |
assert_warning_was_raised('admin_state is ignored when ZAPI is used.') |
| 273 |
|
| 274 |
|
| 275 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 276 |
def test_init_error(): |
| 277 |
'''Validate that: |
| 278 |
unallowed protocol raises an error |
| 279 |
services is not supported with ZAPI |
| 280 |
''' |
| 281 |
register_responses([ |
| 282 |
('GET', 'cluster', SRR['is_zapi']), |
| 283 |
('GET', 'cluster', SRR['is_zapi']), |
| 284 |
('GET', 'cluster', SRR['is_rest_96']), |
| 285 |
]) |
| 286 |
module_args = { |
| 287 |
'allowed_protocols': 'dummy,humpty,dumpty,cifs,nfs', |
| 288 |
'use_rest': 'auto' |
| 289 |
} |
| 290 |
error = create_module(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] |
| 291 |
assert 'Unexpected value dummy in allowed_protocols.' in error |
| 292 |
assert 'Unexpected value humpty in allowed_protocols.' in error |
| 293 |
assert 'Unexpected value dumpty in allowed_protocols.' in error |
| 294 |
assert 'cifs' not in error |
| 295 |
assert 'nfs' not in error |
| 296 |
|
| 297 |
module_args = { |
| 298 |
'services': {}, |
| 299 |
'use_rest': 'auto' |
| 300 |
} |
| 301 |
error = create_module(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] |
| 302 |
assert error == 'using services requires ONTAP 9.6 or later and REST must be enabled - Unreachable - using ZAPI.' |
| 303 |
module_args = { |
| 304 |
'services': {'ndmp': {'allowed': True}}, |
| 305 |
'use_rest': 'always' |
| 306 |
} |
| 307 |
error = create_module(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] |
| 308 |
assert error == 'using ndmp requires ONTAP 9.10.1 or later and REST must be enabled - ONTAP version: 9.6.0 - using REST.' |
| 309 |
|
| 310 |
|
| 311 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 312 |
def test_successful_rename(): |
| 313 |
'''Test successful rename''' |
| 314 |
register_responses([ |
| 315 |
('GET', 'cluster', SRR['is_zapi']), |
| 316 |
('ZAPI', 'vserver-get-iter', ZRR['no_records']), |
| 317 |
('ZAPI', 'vserver-get-iter', ZRR['svm_record']), |
| 318 |
('ZAPI', 'vserver-rename', ZRR['success']), |
| 319 |
]) |
| 320 |
module_args = { |
| 321 |
'from_name': 'test_svm', |
| 322 |
'name': 'test_new_svm', |
| 323 |
'use_rest': 'auto' |
| 324 |
} |
| 325 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 326 |
|
| 327 |
|
| 328 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 329 |
def test_error_rename_no_from(): |
| 330 |
'''Test error rename''' |
| 331 |
register_responses([ |
| 332 |
('GET', 'cluster', SRR['is_zapi']), |
| 333 |
('ZAPI', 'vserver-get-iter', ZRR['no_records']), |
| 334 |
('ZAPI', 'vserver-get-iter', ZRR['no_records']), |
| 335 |
]) |
| 336 |
module_args = { |
| 337 |
'from_name': 'test_svm', |
| 338 |
'name': 'test_new_svm', |
| 339 |
'use_rest': 'auto' |
| 340 |
} |
| 341 |
msg = 'Error renaming SVM test_new_svm: no SVM with from_name test_svm.' |
| 342 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 343 |
|
| 344 |
|
| 345 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 346 |
def test_error_rename_zapi(): |
| 347 |
'''Test error rename''' |
| 348 |
register_responses([ |
| 349 |
('GET', 'cluster', SRR['is_zapi']), |
| 350 |
('ZAPI', 'vserver-get-iter', ZRR['no_records']), |
| 351 |
('ZAPI', 'vserver-get-iter', ZRR['svm_record']), |
| 352 |
('ZAPI', 'vserver-rename', ZRR['error']), |
| 353 |
]) |
| 354 |
module_args = { |
| 355 |
'from_name': 'test_svm', |
| 356 |
'name': 'test_new_svm', |
| 357 |
'use_rest': 'auto' |
| 358 |
} |
| 359 |
msg = 'Error renaming SVM test_svm: NetApp API failed. Reason - 12345:synthetic error for UT purpose' |
| 360 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 361 |
|
| 362 |
|
| 363 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 364 |
def test_successful_modify_language(): |
| 365 |
'''Test successful modify language''' |
| 366 |
register_responses([ |
| 367 |
('GET', 'cluster', SRR['is_zapi']), |
| 368 |
('ZAPI', 'vserver-get-iter', ZRR['svm_record']), |
| 369 |
('ZAPI', 'vserver-modify', ZRR['success']), |
| 370 |
]) |
| 371 |
_modify_options_with_expected_change('language', 'c') |
| 372 |
|
| 373 |
|
| 374 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 375 |
def test_error_modify_language(): |
| 376 |
'''Test error modify language''' |
| 377 |
register_responses([ |
| 378 |
('GET', 'cluster', SRR['is_zapi']), |
| 379 |
('ZAPI', 'vserver-get-iter', ZRR['svm_record']), |
| 380 |
('ZAPI', 'vserver-modify', ZRR['error']), |
| 381 |
]) |
| 382 |
module_args = { |
| 383 |
'language': 'c', |
| 384 |
'use_rest': 'auto' |
| 385 |
} |
| 386 |
msg = 'Error modifying SVM test_svm: NetApp API failed. Reason - 12345:synthetic error for UT purpose' |
| 387 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 388 |
|
| 389 |
|
| 390 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 391 |
def test_error_modify_fixed_properties(): |
| 392 |
'''Test error modifying a fixed property''' |
| 393 |
register_responses([ |
| 394 |
('GET', 'cluster', SRR['is_zapi']), |
| 395 |
('ZAPI', 'vserver-get-iter', ZRR['svm_record']), |
| 396 |
('GET', 'cluster', SRR['is_zapi']), |
| 397 |
('ZAPI', 'vserver-get-iter', ZRR['svm_record']), |
| 398 |
]) |
| 399 |
module_args = { |
| 400 |
'ipspace': 'new', |
| 401 |
'use_rest': 'auto' |
| 402 |
} |
| 403 |
msg = 'Error modifying SVM test_svm: cannot modify ipspace - current: ansible_ipspace - desired: new.' |
| 404 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 405 |
module_args = { |
| 406 |
'ipspace': 'new', |
| 407 |
'root_volume': 'new_root', |
| 408 |
'use_rest': 'auto' |
| 409 |
} |
| 410 |
msg = 'Error modifying SVM test_svm: cannot modify root_volume - current: ansible_vol - desired: new_root, '\ |
| 411 |
'ipspace - current: ansible_ipspace - desired: new.' |
| 412 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 413 |
|
| 414 |
|
| 415 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 416 |
def test_successful_modify_snapshot_policy(): |
| 417 |
'''Test successful modify language''' |
| 418 |
register_responses([ |
| 419 |
('GET', 'cluster', SRR['is_zapi']), |
| 420 |
('ZAPI', 'vserver-get-iter', ZRR['svm_record']), |
| 421 |
('ZAPI', 'vserver-modify', ZRR['success']), |
| 422 |
]) |
| 423 |
_modify_options_with_expected_change( |
| 424 |
'snapshot_policy', 'new_snapshot_policy' |
| 425 |
) |
| 426 |
|
| 427 |
|
| 428 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 429 |
def test_successful_modify_allowed_protocols(): |
| 430 |
'''Test successful modify allowed protocols''' |
| 431 |
register_responses([ |
| 432 |
('GET', 'cluster', SRR['is_zapi']), |
| 433 |
('ZAPI', 'vserver-get-iter', ZRR['svm_record']), |
| 434 |
('ZAPI', 'vserver-modify', ZRR['success']), |
| 435 |
]) |
| 436 |
_modify_options_with_expected_change( |
| 437 |
'allowed_protocols', 'nvme,fcp', |
| 438 |
) |
| 439 |
|
| 440 |
|
| 441 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 442 |
def test_successful_modify_aggr_list(): |
| 443 |
'''Test successful modify aggr-list''' |
| 444 |
register_responses([ |
| 445 |
('GET', 'cluster', SRR['is_zapi']), |
| 446 |
('ZAPI', 'vserver-get-iter', ZRR['svm_record']), |
| 447 |
('ZAPI', 'vserver-modify', ZRR['success']), |
| 448 |
]) |
| 449 |
_modify_options_with_expected_change( |
| 450 |
'aggr_list', 'aggr_3,aggr_4' |
| 451 |
) |
| 452 |
|
| 453 |
|
| 454 |
@pytest.mark.skipif(not netapp_utils.has_netapp_lib(), reason="skipping as missing required netapp_lib") |
| 455 |
def test_successful_modify_aggr_list_star(): |
| 456 |
'''Test successful modify aggr-list''' |
| 457 |
register_responses([ |
| 458 |
('GET', 'cluster', SRR['is_zapi']), |
| 459 |
('ZAPI', 'vserver-get-iter', ZRR['svm_record']), |
| 460 |
('ZAPI', 'vserver-modify', ZRR['success']), |
| 461 |
]) |
| 462 |
module_args = { |
| 463 |
'aggr_list': '*', |
| 464 |
'use_rest': 'auto' |
| 465 |
} |
| 466 |
results = create_and_apply(svm_module, DEFAULT_ARGS, module_args) |
| 467 |
assert results['changed'] |
| 468 |
assert_warning_was_raised("na_ontap_svm: changed always 'True' when aggr_list is '*'.") |
| 469 |
|
| 470 |
|
| 471 |
def _modify_options_with_expected_change(arg0, arg1): |
| 472 |
module_args = { |
| 473 |
arg0: arg1, |
| 474 |
'use_rest': 'auto' |
| 475 |
} |
| 476 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 477 |
|
| 478 |
|
| 479 |
def test_rest_error(): |
| 480 |
register_responses([ |
| 481 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 482 |
('GET', 'svm/svms', SRR['generic_error']), |
| 483 |
]) |
| 484 |
module_args = { |
| 485 |
'root_volume': 'whatever', |
| 486 |
'aggr_list': '*', |
| 487 |
'ignore_rest_unsupported_options': 'true', |
| 488 |
} |
| 489 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == 'calling: svm/svms: got Expected error.' |
| 490 |
|
| 491 |
|
| 492 |
def test_rest_error_unsupported_parm(): |
| 493 |
register_responses([ |
| 494 |
]) |
| 495 |
module_args = { |
| 496 |
'root_volume': 'not_supported_by_rest', |
| 497 |
'use_rest': 'always', |
| 498 |
} |
| 499 |
assert create_module(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == "REST API currently does not support 'root_volume'" |
| 500 |
|
| 501 |
|
| 502 |
def test_rest_successfully_create(): |
| 503 |
register_responses([ |
| 504 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 505 |
('GET', 'svm/svms', SRR['zero_records']), |
| 506 |
('POST', 'svm/svms', SRR['success']), |
| 507 |
]) |
| 508 |
assert create_and_apply(svm_module, DEFAULT_ARGS)['changed'] |
| 509 |
|
| 510 |
|
| 511 |
def test_rest_error_create(): |
| 512 |
register_responses([ |
| 513 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 514 |
('GET', 'svm/svms', SRR['zero_records']), |
| 515 |
('POST', 'svm/svms', SRR['generic_error']), |
| 516 |
]) |
| 517 |
msg = 'Error in create: calling: svm/svms: got Expected error.' |
| 518 |
assert create_and_apply(svm_module, DEFAULT_ARGS, fail=True)['msg'] == msg |
| 519 |
|
| 520 |
|
| 521 |
def test_rest_create_idempotency(): |
| 522 |
register_responses([ |
| 523 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 524 |
('GET', 'svm/svms', SRR['svm_record']), |
| 525 |
]) |
| 526 |
module_args = { |
| 527 |
'root_volume': 'whatever', |
| 528 |
'aggr_list': '*', |
| 529 |
'ignore_rest_unsupported_options': 'true', |
| 530 |
} |
| 531 |
assert not create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 532 |
|
| 533 |
|
| 534 |
def test_rest_successful_delete(): |
| 535 |
'''Test successful delete''' |
| 536 |
register_responses([ |
| 537 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 538 |
('GET', 'svm/svms', SRR['svm_record']), |
| 539 |
('DELETE', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7', SRR['success']), |
| 540 |
]) |
| 541 |
module_args = { |
| 542 |
'state': 'absent', |
| 543 |
} |
| 544 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 545 |
|
| 546 |
|
| 547 |
def test_rest_error_delete(): |
| 548 |
'''Test error delete''' |
| 549 |
register_responses([ |
| 550 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 551 |
('GET', 'svm/svms', SRR['svm_record']), |
| 552 |
('DELETE', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7', SRR['generic_error']), |
| 553 |
]) |
| 554 |
module_args = { |
| 555 |
'state': 'absent', |
| 556 |
} |
| 557 |
msg = 'Error in delete: calling: svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7: got Expected error.' |
| 558 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 559 |
|
| 560 |
|
| 561 |
def test_rest_error_delete_no_svm(): |
| 562 |
'''Test error delete''' |
| 563 |
register_responses([ |
| 564 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 565 |
]) |
| 566 |
my_obj = create_module(svm_module, DEFAULT_ARGS) |
| 567 |
msg = 'Internal error, expecting SVM object in delete' |
| 568 |
assert expect_and_capture_ansible_exception(my_obj.delete_vserver, 'fail')['msg'] == msg |
| 569 |
|
| 570 |
|
| 571 |
def test_rest_delete_idempotency(): |
| 572 |
'''Test delete idempotency''' |
| 573 |
register_responses([ |
| 574 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 575 |
('GET', 'svm/svms', SRR['zero_records']), |
| 576 |
]) |
| 577 |
module_args = { |
| 578 |
'state': 'absent', |
| 579 |
} |
| 580 |
assert not create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 581 |
|
| 582 |
|
| 583 |
def test_rest_successful_rename(): |
| 584 |
'''Test successful rename''' |
| 585 |
register_responses([ |
| 586 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 587 |
('GET', 'svm/svms', SRR['zero_records']), |
| 588 |
('GET', 'svm/svms', SRR['svm_record']), |
| 589 |
('PATCH', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7', SRR['success']), |
| 590 |
]) |
| 591 |
module_args = { |
| 592 |
'from_name': 'test_svm', |
| 593 |
'name': 'test_new_svm', |
| 594 |
} |
| 595 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 596 |
|
| 597 |
|
| 598 |
def test_rest_successful_modify_language(): |
| 599 |
'''Test successful modify language''' |
| 600 |
register_responses([ |
| 601 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 602 |
('GET', 'svm/svms', SRR['svm_record']), |
| 603 |
('PATCH', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7', SRR['success']), |
| 604 |
]) |
| 605 |
module_args = { |
| 606 |
'language': 'c', |
| 607 |
} |
| 608 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 609 |
|
| 610 |
|
| 611 |
def test_rest_successful_get(): |
| 612 |
'''Test successful get''' |
| 613 |
register_responses([ |
| 614 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 615 |
('GET', 'svm/svms', SRR['svm_record']), |
| 616 |
('GET', 'svm/svms', SRR['svm_record_ap']), |
| 617 |
]) |
| 618 |
module_args = { |
| 619 |
'admin_state': 'running', |
| 620 |
'language': 'c' |
| 621 |
} |
| 622 |
my_obj = create_module(svm_module, DEFAULT_ARGS, module_args) |
| 623 |
current = my_obj.get_vserver() |
| 624 |
print(current) |
| 625 |
assert current['services']['nfs']['allowed'] |
| 626 |
assert not current['services']['cifs']['enabled'] |
| 627 |
current = my_obj.get_vserver() |
| 628 |
print(current) |
| 629 |
assert not current['services']['s3']['enabled'] |
| 630 |
assert not current['services']['nfs']['enabled'] |
| 631 |
assert current['services']['cifs']['allowed'] |
| 632 |
assert current['services']['iscsi']['allowed'] |
| 633 |
assert current['services']['s3']['allowed'] |
| 634 |
|
| 635 |
|
| 636 |
def test_rest_successfully_create_ignore_zapi_option(): |
| 637 |
register_responses([ |
| 638 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 639 |
('GET', 'svm/svms', SRR['zero_records']), |
| 640 |
('POST', 'svm/svms', SRR['success']), |
| 641 |
]) |
| 642 |
module_args = { |
| 643 |
'root_volume': 'whatever', |
| 644 |
'aggr_list': '*', |
| 645 |
'ignore_rest_unsupported_options': 'true', |
| 646 |
} |
| 647 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 648 |
|
| 649 |
|
| 650 |
def test_rest_successfully_create_with_service(): |
| 651 |
register_responses([ |
| 652 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 653 |
('GET', 'svm/svms', SRR['zero_records']), |
| 654 |
('POST', 'svm/svms', SRR['success']), |
| 655 |
]) |
| 656 |
module_args = { |
| 657 |
'services': {'nfs': {'allowed': True, 'enabled': True}, 'fcp': {'allowed': True, 'enabled': True}, 's3': {'allowed': True}} |
| 658 |
} |
| 659 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 660 |
|
| 661 |
|
| 662 |
def test_rest_successfully_modify_with_service(): |
| 663 |
register_responses([ |
| 664 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 665 |
('GET', 'svm/svms', SRR['svm_record']), |
| 666 |
('PATCH', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7', SRR['success']), |
| 667 |
('POST', 'protocols/san/fcp/services', SRR['success']), |
| 668 |
]) |
| 669 |
module_args = { |
| 670 |
'admin_state': 'stopped', |
| 671 |
'services': {'nfs': {'allowed': True, 'enabled': True}, 'fcp': {'allowed': True, 'enabled': True}, 's3': {'allowed': True}} |
| 672 |
} |
| 673 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 674 |
|
| 675 |
|
| 676 |
def test_rest_successfully_enable_service(): |
| 677 |
register_responses([ |
| 678 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 679 |
('POST', 'protocols/san/fcp/services', SRR['success']), |
| 680 |
]) |
| 681 |
module_args = { |
| 682 |
'admin_state': 'running', |
| 683 |
'services': {'nfs': {'allowed': True, 'enabled': True}} |
| 684 |
} |
| 685 |
my_obj = create_module(svm_module, DEFAULT_ARGS, module_args) |
| 686 |
modify = {'services': {'nfs': {'allowed': True}, 'fcp': {'enabled': True}}} |
| 687 |
current = {'services': {'nfs': {'allowed': True}}, 'uuid': 'uuid'} |
| 688 |
assert my_obj.modify_services(modify, current) is None |
| 689 |
|
| 690 |
|
| 691 |
def test_rest_successfully_reenable_service(): |
| 692 |
register_responses([ |
| 693 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 694 |
('PATCH', 'protocols/san/fcp/services/uuid', SRR['success']), |
| 695 |
]) |
| 696 |
module_args = { |
| 697 |
'admin_state': 'running', |
| 698 |
'services': {'nfs': {'allowed': True, 'enabled': True}} |
| 699 |
} |
| 700 |
my_obj = create_module(svm_module, DEFAULT_ARGS, module_args) |
| 701 |
modify = {'services': {'nfs': {'allowed': True}, 'fcp': {'enabled': True}}} |
| 702 |
fcp_dict = {'_links': {'self': {'href': 'fcp_link'}}} |
| 703 |
current = {'services': {'nfs': {'allowed': True}}, 'uuid': 'uuid', 'fcp': fcp_dict} |
| 704 |
assert my_obj.modify_services(modify, current) is None |
| 705 |
|
| 706 |
|
| 707 |
def test_rest_negative_enable_service(): |
| 708 |
register_responses([ |
| 709 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 710 |
]) |
| 711 |
module_args = { |
| 712 |
'admin_state': 'running', |
| 713 |
'services': {'nfs': {'allowed': True, 'enabled': True}} |
| 714 |
} |
| 715 |
my_obj = create_module(svm_module, DEFAULT_ARGS, module_args) |
| 716 |
modify = {'services': {'nfs': {'allowed': True}, 'bad_value': {'enabled': True}}, 'name': 'new_name'} |
| 717 |
current = {'services': {'nfs': {'allowed': True}}, 'uuid': 'uuid'} |
| 718 |
error = expect_and_capture_ansible_exception(my_obj.modify_services, 'fail', modify, current)['msg'] |
| 719 |
assert error == 'Internal error, unexpecting service: bad_value.' |
| 720 |
|
| 721 |
|
| 722 |
def test_rest_negative_modify_services(): |
| 723 |
register_responses([ |
| 724 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 725 |
('POST', 'protocols/san/fcp/services', SRR['generic_error']), |
| 726 |
]) |
| 727 |
module_args = { |
| 728 |
'admin_state': 'running', |
| 729 |
'services': {'nfs': {'allowed': True, 'enabled': True}} |
| 730 |
} |
| 731 |
my_obj = create_module(svm_module, DEFAULT_ARGS, module_args) |
| 732 |
modify = {'services': {'nfs': {'allowed': True}, 'fcp': {'enabled': True}}, 'name': 'new_name'} |
| 733 |
current = {'services': {'nfs': {'allowed': True}}, 'uuid': 'uuid'} |
| 734 |
error = expect_and_capture_ansible_exception(my_obj.modify_services, 'fail', modify, current)['msg'] |
| 735 |
assert error == 'Error in modify service for fcp: calling: protocols/san/fcp/services: got Expected error.' |
| 736 |
|
| 737 |
|
| 738 |
def test_rest_negative_modify_current_none(): |
| 739 |
register_responses([ |
| 740 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 741 |
]) |
| 742 |
module_args = { |
| 743 |
'admin_state': 'running', |
| 744 |
'services': {'nfs': {'allowed': True, 'enabled': True}} |
| 745 |
} |
| 746 |
my_obj = create_module(svm_module, DEFAULT_ARGS, module_args) |
| 747 |
modify = {'enabled_protocols': ['nfs', 'fcp']} |
| 748 |
current = None |
| 749 |
error = expect_and_capture_ansible_exception(my_obj.modify_vserver, 'fail', modify, current)['msg'] |
| 750 |
assert error == 'Internal error, expecting SVM object in modify.' |
| 751 |
|
| 752 |
|
| 753 |
def test_rest_negative_modify_modify_none(): |
| 754 |
register_responses([ |
| 755 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 756 |
]) |
| 757 |
module_args = { |
| 758 |
'admin_state': 'running', |
| 759 |
'services': {'nfs': {'allowed': True, 'enabled': True}} |
| 760 |
} |
| 761 |
my_obj = create_module(svm_module, DEFAULT_ARGS, module_args) |
| 762 |
modify = {} |
| 763 |
current = {'enabled_protocols': ['nfs'], 'disabled_protocols': ['fcp', 'iscsi', 'nvme'], 'uuid': 'uuid'} |
| 764 |
error = expect_and_capture_ansible_exception(my_obj.modify_vserver, 'fail', modify, current)['msg'] |
| 765 |
assert error == 'Internal error, expecting something to modify in modify.' |
| 766 |
|
| 767 |
|
| 768 |
def test_rest_negative_modify_error_1(): |
| 769 |
register_responses([ |
| 770 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 771 |
('PATCH', 'svm/svms/uuid', SRR['generic_error']), # rename |
| 772 |
]) |
| 773 |
module_args = { |
| 774 |
'admin_state': 'running', |
| 775 |
'language': 'klingon', |
| 776 |
'services': {'nfs': {'allowed': True, 'enabled': True}} |
| 777 |
} |
| 778 |
my_obj = create_module(svm_module, DEFAULT_ARGS, module_args) |
| 779 |
modify = {'enabled_protocols': ['nfs', 'fcp'], 'name': 'new_name', 'language': 'klingon'} |
| 780 |
current = {'enabled_protocols': ['nfs'], 'disabled_protocols': ['fcp', 'iscsi', 'nvme'], 'uuid': 'uuid'} |
| 781 |
error = expect_and_capture_ansible_exception(my_obj.modify_vserver, 'fail', modify, current)['msg'] |
| 782 |
assert error == 'Error in rename: calling: svm/svms/uuid: got Expected error.' |
| 783 |
|
| 784 |
|
| 785 |
def test_rest_negative_modify_error_2(): |
| 786 |
register_responses([ |
| 787 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 788 |
('PATCH', 'svm/svms/uuid', SRR['success']), # rename |
| 789 |
('PATCH', 'svm/svms/uuid', SRR['generic_error']), # modify |
| 790 |
]) |
| 791 |
module_args = { |
| 792 |
'admin_state': 'running', |
| 793 |
'language': 'klingon', |
| 794 |
'services': {'nfs': {'allowed': True, 'enabled': True}} |
| 795 |
} |
| 796 |
my_obj = create_module(svm_module, DEFAULT_ARGS, module_args) |
| 797 |
modify = {'enabled_protocols': ['nfs', 'fcp', 's3'], 'name': 'new_name', 'language': 'klingon'} |
| 798 |
current = {'enabled_protocols': ['nfs'], 'disabled_protocols': ['fcp', 'iscsi', 'nvme', 's3'], 'uuid': 'uuid'} |
| 799 |
error = expect_and_capture_ansible_exception(my_obj.modify_vserver, 'fail', modify, current)['msg'] |
| 800 |
assert error == 'Error in modify: calling: svm/svms/uuid: got Expected error.' |
| 801 |
|
| 802 |
|
| 803 |
def test_rest_successfully_get_older_rest(): |
| 804 |
register_responses([ |
| 805 |
('GET', 'cluster', SRR['is_rest_96']), |
| 806 |
('GET', 'svm/svms', SRR['svm_record']), |
| 807 |
('GET', 'private/cli/vserver', SRR['cli_record']), # get protocols |
| 808 |
]) |
| 809 |
module_args = { |
| 810 |
'admin_state': 'running', |
| 811 |
'services': {'nfs': {'allowed': True, 'enabled': True}} |
| 812 |
} |
| 813 |
assert not create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 814 |
|
| 815 |
|
| 816 |
def test_rest_successfully_add_protocols_on_create(): |
| 817 |
register_responses([ |
| 818 |
('GET', 'cluster', SRR['is_rest_96']), |
| 819 |
('GET', 'svm/svms', SRR['zero_records']), |
| 820 |
('POST', 'svm/svms', SRR['success']), |
| 821 |
('PATCH', 'private/cli/vserver/add-protocols', SRR['success']), |
| 822 |
]) |
| 823 |
module_args = { |
| 824 |
'admin_state': 'running', |
| 825 |
'services': {'nfs': {'allowed': True, 'enabled': True}} |
| 826 |
} |
| 827 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 828 |
|
| 829 |
|
| 830 |
def test_rest_successfully_add_s3_protocols_on_create(): |
| 831 |
register_responses([ |
| 832 |
('GET', 'cluster', SRR['is_rest_97']), |
| 833 |
('GET', 'svm/svms', SRR['zero_records']), |
| 834 |
('POST', 'svm/svms', SRR['success']), |
| 835 |
('PATCH', 'private/cli/vserver/add-protocols', SRR['success']), |
| 836 |
]) |
| 837 |
module_args = { |
| 838 |
'admin_state': 'running', |
| 839 |
'services': {'s3': {'allowed': True}} |
| 840 |
} |
| 841 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 842 |
|
| 843 |
|
| 844 |
def test_rest_successfully_add_remove_protocols_on_modify(): |
| 845 |
register_responses([ |
| 846 |
('GET', 'cluster', SRR['is_rest_96']), |
| 847 |
('GET', 'svm/svms', SRR['svm_record']), |
| 848 |
('GET', 'private/cli/vserver', SRR['cli_record']), # get protocols |
| 849 |
('PATCH', 'private/cli/vserver/add-protocols', SRR['success']), |
| 850 |
('PATCH', 'private/cli/vserver/remove-protocols', SRR['success']) |
| 851 |
]) |
| 852 |
module_args = { |
| 853 |
'admin_state': 'running', |
| 854 |
'services': {'nfs': {'allowed': True, 'enabled': True}, 'iscsi': {'allowed': False}, 'fcp': {'allowed': True}} |
| 855 |
} |
| 856 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 857 |
|
| 858 |
|
| 859 |
def test_rest_successfully_add_remove_protocols_on_modify_old_style(): |
| 860 |
register_responses([ |
| 861 |
('GET', 'cluster', SRR['is_rest_96']), |
| 862 |
('GET', 'svm/svms', SRR['svm_record']), |
| 863 |
('GET', 'private/cli/vserver', SRR['cli_record']), # get protocols |
| 864 |
('PATCH', 'private/cli/vserver/add-protocols', SRR['success']), |
| 865 |
('PATCH', 'private/cli/vserver/remove-protocols', SRR['success']) |
| 866 |
]) |
| 867 |
module_args = { |
| 868 |
'admin_state': 'running', |
| 869 |
'allowed_protocols': ['nfs', 'fcp'] |
| 870 |
} |
| 871 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 872 |
|
| 873 |
|
| 874 |
def test_validate_int_or_string_as_int(): |
| 875 |
register_responses([ |
| 876 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 877 |
]) |
| 878 |
module_args = { |
| 879 |
'admin_state': 'running', |
| 880 |
'services': {'nfs': {'allowed': True, 'enabled': True}} |
| 881 |
} |
| 882 |
assert create_module(svm_module, DEFAULT_ARGS, module_args).validate_int_or_string('10', 'whatever') is None |
| 883 |
|
| 884 |
|
| 885 |
def test_validate_int_or_string_as_str(): |
| 886 |
register_responses([ |
| 887 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 888 |
]) |
| 889 |
module_args = { |
| 890 |
'admin_state': 'running', |
| 891 |
'services': {'nfs': {'allowed': True, 'enabled': True}} |
| 892 |
} |
| 893 |
assert create_module(svm_module, DEFAULT_ARGS, module_args).validate_int_or_string('whatever', 'whatever') is None |
| 894 |
|
| 895 |
|
| 896 |
def test_negative_validate_int_or_string(): |
| 897 |
register_responses([ |
| 898 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 899 |
]) |
| 900 |
module_args = { |
| 901 |
'admin_state': 'running', |
| 902 |
'services': {'nfs': {'allowed': True, 'enabled': True}} |
| 903 |
} |
| 904 |
astring = 'testme' |
| 905 |
error = expect_and_capture_ansible_exception(create_module(svm_module, DEFAULT_ARGS, module_args).validate_int_or_string, 'fail', '10a', astring)['msg'] |
| 906 |
assert "expecting int value or '%s'" % astring in error |
| 907 |
|
| 908 |
|
| 909 |
def test_rest_successfully_modify_with_admin_state(): |
| 910 |
register_responses([ |
| 911 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 912 |
('GET', 'svm/svms', SRR['svm_record']), |
| 913 |
('PATCH', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7', SRR['success']) # change admin_state |
| 914 |
]) |
| 915 |
module_args = {'admin_state': 'stopped'} |
| 916 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 917 |
|
| 918 |
|
| 919 |
def test_rest_successfully_modify_with_create(): |
| 920 |
register_responses([ |
| 921 |
('GET', 'cluster', SRR['is_rest_9_9_1']), |
| 922 |
('GET', 'svm/svms', SRR['zero_records']), |
| 923 |
('POST', 'svm/svms', SRR['success']), |
| 924 |
('GET', 'svm/svms', SRR['svm_record']), |
| 925 |
('PATCH', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7', SRR['success']) # change admin_state |
| 926 |
]) |
| 927 |
module_args = {'admin_state': 'stopped'} |
| 928 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 929 |
|
| 930 |
# Tests for web services - 4 cases |
| 931 |
# ZAPI: not supported |
| 932 |
# REST < 9.8: not supported |
| 933 |
# REST 9.8, 9.9. 9.10.0: only certificate is supported, using deprecated certificate fields in svs/svms |
| 934 |
# REST >= 9.10.1: all options are supported, using svm/svms/uuid/web |
| 935 |
|
| 936 |
|
| 937 |
def test_web_services_error_zapi(): |
| 938 |
register_responses([ |
| 939 |
# ('GET', 'cluster', SRR['is_zapi']), |
| 940 |
]) |
| 941 |
module_args = { |
| 942 |
'web': {'certificate': 'cert_name'}, |
| 943 |
'use_rest': 'never' |
| 944 |
} |
| 945 |
msg = 'using web requires ONTAP 9.8 or later and REST must be enabled - using ZAPI.' |
| 946 |
assert create_module(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 947 |
|
| 948 |
|
| 949 |
def test_web_services_error_9_7_5(): |
| 950 |
register_responses([ |
| 951 |
('GET', 'cluster', SRR['is_rest_9_7_5']), |
| 952 |
]) |
| 953 |
module_args = {'web': {'certificate': 'cert_name'}} |
| 954 |
msg = 'using web requires ONTAP 9.8 or later and REST must be enabled - ONTAP version: 9.7.5 - using REST.' |
| 955 |
assert create_module(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 956 |
|
| 957 |
|
| 958 |
def test_web_services_error_9_8_0(): |
| 959 |
register_responses([ |
| 960 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 961 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 962 |
]) |
| 963 |
msg = "using ('client_enabled', 'ocsp_enabled') requires ONTAP 9.10.1 or later and REST must be enabled - ONTAP version: 9.8.0 - using REST." |
| 964 |
module_args = {'web': {'certificate': 'cert_name', 'client_enabled': True}} |
| 965 |
assert create_module(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 966 |
module_args = {'web': {'certificate': 'cert_name', 'ocsp_enabled': True}} |
| 967 |
assert create_module(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 968 |
|
| 969 |
|
| 970 |
def test_web_services_modify_certificate_9_8_0_none_set(): |
| 971 |
register_responses([ |
| 972 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 973 |
('GET', 'security/certificates', SRR['certificate_record_1']), |
| 974 |
('GET', 'svm/svms', SRR['svm_record']), |
| 975 |
('GET', 'private/cli/vserver', SRR['cli_record']), # get protocols |
| 976 |
('PATCH', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7', SRR['success']) # change certificate |
| 977 |
]) |
| 978 |
module_args = {'web': {'certificate': 'cert_name'}} |
| 979 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 980 |
|
| 981 |
|
| 982 |
def test_web_services_modify_certificate_9_8_0_other_set(): |
| 983 |
register_responses([ |
| 984 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 985 |
('GET', 'security/certificates', SRR['certificate_record_1']), |
| 986 |
('GET', 'svm/svms', SRR['svm_record_cert2']), |
| 987 |
('GET', 'private/cli/vserver', SRR['cli_record']), # get protocols |
| 988 |
('PATCH', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7', SRR['success']) # change certificate |
| 989 |
]) |
| 990 |
module_args = {'web': {'certificate': 'cert_name'}} |
| 991 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 992 |
|
| 993 |
|
| 994 |
def test_web_services_modify_certificate_9_8_0_idempotent(): |
| 995 |
register_responses([ |
| 996 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 997 |
('GET', 'security/certificates', SRR['certificate_record_1']), |
| 998 |
('GET', 'svm/svms', SRR['svm_record_cert1']), |
| 999 |
('GET', 'private/cli/vserver', SRR['cli_record']), # get protocols |
| 1000 |
]) |
| 1001 |
module_args = {'web': {'certificate': 'cert_name'}} |
| 1002 |
assert not create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 1003 |
|
| 1004 |
|
| 1005 |
def test_web_services_modify_certificate_9_8_0_error_not_found(): |
| 1006 |
register_responses([ |
| 1007 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 1008 |
('GET', 'security/certificates', SRR['zero_records']), |
| 1009 |
('GET', 'security/certificates', SRR['certificate_record_1']), |
| 1010 |
]) |
| 1011 |
module_args = {'web': {'certificate': 'cert_name'}} |
| 1012 |
msg = "Error certificate not found: {'name': 'cert_name'}. Current certificates with type=server: ['cert_1']" |
| 1013 |
assert create_module(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 1014 |
|
| 1015 |
|
| 1016 |
def test_web_services_modify_certificate_9_8_0_error_api1(): |
| 1017 |
register_responses([ |
| 1018 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 1019 |
('GET', 'security/certificates', SRR['generic_error']), |
| 1020 |
]) |
| 1021 |
module_args = {'web': {'certificate': 'cert_name'}} |
| 1022 |
msg = "Error retrieving certificate {'name': 'cert_name'}: calling: security/certificates: got Expected error." |
| 1023 |
assert create_module(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 1024 |
|
| 1025 |
|
| 1026 |
def test_web_services_modify_certificate_9_8_0_error_api2(): |
| 1027 |
register_responses([ |
| 1028 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 1029 |
('GET', 'security/certificates', SRR['zero_records']), |
| 1030 |
('GET', 'security/certificates', SRR['generic_error']), |
| 1031 |
]) |
| 1032 |
module_args = {'web': {'certificate': 'cert_name'}} |
| 1033 |
msg = "Error retrieving certificates: calling: security/certificates: got Expected error." |
| 1034 |
assert create_module(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 1035 |
|
| 1036 |
|
| 1037 |
def test_web_services_modify_certificate_9_10_1_none_set(): |
| 1038 |
register_responses([ |
| 1039 |
('GET', 'cluster', SRR['is_rest_9_10_1']), |
| 1040 |
('GET', 'security/certificates', SRR['certificate_record_1']), |
| 1041 |
('GET', 'svm/svms', SRR['svm_record']), |
| 1042 |
('GET', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7/web', SRR['zero_records']), |
| 1043 |
('PATCH', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7/web', SRR['success']) # change certificate |
| 1044 |
]) |
| 1045 |
module_args = {'web': {'certificate': 'cert_name'}} |
| 1046 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 1047 |
|
| 1048 |
|
| 1049 |
def test_web_services_modify_certificate_9_10_1_other_set(): |
| 1050 |
register_responses([ |
| 1051 |
('GET', 'cluster', SRR['is_rest_9_10_1']), |
| 1052 |
('GET', 'security/certificates', SRR['certificate_record_1']), |
| 1053 |
('GET', 'svm/svms', SRR['svm_record']), |
| 1054 |
('GET', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7/web', SRR['svm_web_record_2']), |
| 1055 |
('PATCH', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7/web', SRR['success']) # change certificate |
| 1056 |
]) |
| 1057 |
module_args = {'web': {'certificate': 'cert_name'}} |
| 1058 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 1059 |
|
| 1060 |
|
| 1061 |
def test_web_services_modify_certificate_9_10_1_idempotent(): |
| 1062 |
register_responses([ |
| 1063 |
('GET', 'cluster', SRR['is_rest_9_10_1']), |
| 1064 |
('GET', 'security/certificates', SRR['certificate_record_1']), |
| 1065 |
('GET', 'svm/svms', SRR['svm_record']), |
| 1066 |
('GET', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7/web', SRR['svm_web_record_1']), |
| 1067 |
]) |
| 1068 |
module_args = {'web': {'certificate': 'cert_name'}} |
| 1069 |
assert not create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 1070 |
|
| 1071 |
|
| 1072 |
def test_web_services_modify_certificate_9_10_1_error_not_found(): |
| 1073 |
register_responses([ |
| 1074 |
('GET', 'cluster', SRR['is_rest_9_10_1']), |
| 1075 |
('GET', 'security/certificates', SRR['zero_records']), |
| 1076 |
('GET', 'security/certificates', SRR['certificate_record_1']), |
| 1077 |
('GET', 'cluster', SRR['is_rest_9_10_1']), |
| 1078 |
('GET', 'security/certificates', SRR['zero_records']), |
| 1079 |
('GET', 'security/certificates', SRR['zero_records']), |
| 1080 |
]) |
| 1081 |
module_args = {'web': {'certificate': 'cert_name'}} |
| 1082 |
msg = "Error certificate not found: {'name': 'cert_name'}. Current certificates with type=server: ['cert_1']" |
| 1083 |
assert create_module(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 1084 |
msg = "Error certificate not found: {'name': 'cert_name'}. Current certificates with type=server: []" |
| 1085 |
assert create_module(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 1086 |
|
| 1087 |
|
| 1088 |
def test_web_services_modify_certificate_9_10_1_error_api1(): |
| 1089 |
register_responses([ |
| 1090 |
('GET', 'cluster', SRR['is_rest_9_10_1']), |
| 1091 |
('GET', 'security/certificates', SRR['generic_error']), |
| 1092 |
]) |
| 1093 |
module_args = {'web': {'certificate': 'cert_name'}} |
| 1094 |
msg = "Error retrieving certificate {'name': 'cert_name'}: calling: security/certificates: got Expected error." |
| 1095 |
assert create_module(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 1096 |
|
| 1097 |
|
| 1098 |
def test_web_services_modify_certificate_9_10_1_error_api2(): |
| 1099 |
register_responses([ |
| 1100 |
('GET', 'cluster', SRR['is_rest_9_10_1']), |
| 1101 |
('GET', 'security/certificates', SRR['zero_records']), |
| 1102 |
('GET', 'security/certificates', SRR['generic_error']), |
| 1103 |
]) |
| 1104 |
module_args = {'web': {'certificate': 'cert_name'}} |
| 1105 |
msg = "Error retrieving certificates: calling: security/certificates: got Expected error." |
| 1106 |
assert create_module(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 1107 |
|
| 1108 |
|
| 1109 |
def test_web_services_modify_certificate_9_10_1_error_api3(): |
| 1110 |
register_responses([ |
| 1111 |
('GET', 'cluster', SRR['is_rest_9_10_1']), |
| 1112 |
('GET', 'security/certificates', SRR['certificate_record_1']), |
| 1113 |
('GET', 'svm/svms', SRR['svm_record']), |
| 1114 |
('GET', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7/web', SRR['generic_error']), |
| 1115 |
]) |
| 1116 |
module_args = {'web': {'certificate': 'cert_name'}} |
| 1117 |
msg = 'Error retrieving web info: calling: svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7/web: got Expected error.' |
| 1118 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 1119 |
|
| 1120 |
|
| 1121 |
def test_web_services_modify_certificate_9_10_1_error_api4(): |
| 1122 |
register_responses([ |
| 1123 |
('GET', 'cluster', SRR['is_rest_9_10_1']), |
| 1124 |
('GET', 'security/certificates', SRR['certificate_record_1']), |
| 1125 |
('GET', 'svm/svms', SRR['svm_record']), |
| 1126 |
('GET', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7/web', SRR['svm_web_record_2']), |
| 1127 |
('PATCH', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7/web', SRR['generic_error']) # change certificate |
| 1128 |
]) |
| 1129 |
module_args = {'web': {'certificate': 'cert_name'}} |
| 1130 |
msg = "Error in modify web service for {'certificate': {'uuid': 'cert_uuid_1'}}: "\ |
| 1131 |
"calling: svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7/web: got Expected error." |
| 1132 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 1133 |
|
| 1134 |
|
| 1135 |
def test_web_services_modify_certificate_9_10_1_warning(): |
| 1136 |
register_responses([ |
| 1137 |
('GET', 'cluster', SRR['is_rest_9_10_1']), |
| 1138 |
('GET', 'security/certificates', SRR['certificate_record_1']), |
| 1139 |
]) |
| 1140 |
module_args = {'web': {'certificate': 'cert_name'}} |
| 1141 |
msg = "Error in modify web service for {'certificate': {'uuid': 'cert_uuid_1'}}: "\ |
| 1142 |
"calling: svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7/web: got Expected error." |
| 1143 |
my_obj = create_module(svm_module, DEFAULT_ARGS, module_args) |
| 1144 |
assert my_obj.modify_web_services({}, {'uuid': 'uuid'}) is None |
| 1145 |
assert_warning_was_raised('Nothing to change: {}') |
| 1146 |
clear_warnings() |
| 1147 |
assert my_obj.modify_web_services({'certificate': {'name': 'whatever'}}, {'uuid': 'uuid'}) is None |
| 1148 |
assert_warning_was_raised("Nothing to change: {'certificate': {}}") |
| 1149 |
clear_warnings() |
| 1150 |
assert my_obj.modify_web_services({'certificate': {}}, {'uuid': 'uuid'}) is None |
| 1151 |
assert_warning_was_raised("Nothing to change: {'certificate': {}}") |
| 1152 |
|
| 1153 |
|
| 1154 |
def test_rest_cli_max_volumes_get(): |
| 1155 |
register_responses([ |
| 1156 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 1157 |
('GET', 'svm/svms', SRR['svm_record_ap']), |
| 1158 |
('GET', 'private/cli/vserver', SRR['cli_record']), |
| 1159 |
]) |
| 1160 |
module_args = { |
| 1161 |
'max_volumes': 3333, |
| 1162 |
} |
| 1163 |
my_obj = create_module(svm_module, DEFAULT_ARGS, module_args) |
| 1164 |
record = my_obj.get_vserver() |
| 1165 |
assert 'name' in SRR['svm_record_ap'][1]['records'][0] |
| 1166 |
assert 'max_volumes' not in SRR['svm_record_ap'][1]['records'][0] |
| 1167 |
assert 'max_volumes' in record |
| 1168 |
|
| 1169 |
|
| 1170 |
def test_rest_cli_max_volumes_create(): |
| 1171 |
register_responses([ |
| 1172 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 1173 |
('GET', 'svm/svms', SRR['zero_records']), |
| 1174 |
('POST', 'svm/svms', SRR['success']), |
| 1175 |
('PATCH', 'private/cli/vserver', SRR['success']), |
| 1176 |
]) |
| 1177 |
module_args = { |
| 1178 |
'max_volumes': 3333, |
| 1179 |
} |
| 1180 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 1181 |
|
| 1182 |
|
| 1183 |
def test_rest_cli_max_volumes_modify(): |
| 1184 |
register_responses([ |
| 1185 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 1186 |
('GET', 'svm/svms', SRR['svm_record_ap']), |
| 1187 |
('GET', 'private/cli/vserver', SRR['cli_record']), |
| 1188 |
('PATCH', 'private/cli/vserver', SRR['success']), |
| 1189 |
]) |
| 1190 |
module_args = { |
| 1191 |
'max_volumes': 3333, |
| 1192 |
} |
| 1193 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 1194 |
|
| 1195 |
|
| 1196 |
def test_error_rest_cli_max_volumes_get(): |
| 1197 |
register_responses([ |
| 1198 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 1199 |
('GET', 'svm/svms', SRR['svm_record_ap']), |
| 1200 |
('GET', 'private/cli/vserver', SRR['generic_error']), |
| 1201 |
]) |
| 1202 |
module_args = { |
| 1203 |
'max_volumes': 3333, |
| 1204 |
} |
| 1205 |
msg = 'Error getting vserver info: calling: private/cli/vserver: got Expected error. - None' |
| 1206 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 1207 |
|
| 1208 |
|
| 1209 |
def test_error_rest_cli_max_volumes_modify(): |
| 1210 |
register_responses([ |
| 1211 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 1212 |
('GET', 'svm/svms', SRR['svm_record_ap']), |
| 1213 |
('GET', 'private/cli/vserver', SRR['cli_record']), |
| 1214 |
('PATCH', 'private/cli/vserver', SRR['generic_error']), |
| 1215 |
]) |
| 1216 |
module_args = { |
| 1217 |
'max_volumes': 3333, |
| 1218 |
} |
| 1219 |
msg = 'Error updating max_volumes: calling: private/cli/vserver: got Expected error. - None' |
| 1220 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 1221 |
|
| 1222 |
|
| 1223 |
def test_rest_cli_add_remove_protocols_create(): |
| 1224 |
register_responses([ |
| 1225 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 1226 |
('GET', 'svm/svms', SRR['zero_records']), |
| 1227 |
('POST', 'svm/svms', SRR['success']), |
| 1228 |
('PATCH', 'private/cli/vserver/add-protocols', SRR['success']), |
| 1229 |
('PATCH', 'private/cli/vserver/remove-protocols', SRR['success']), |
| 1230 |
]) |
| 1231 |
module_args = { |
| 1232 |
'allowed_protocols': 'nfs,cifs,s3', |
| 1233 |
} |
| 1234 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 1235 |
|
| 1236 |
|
| 1237 |
def test_error_rest_cli_add_protocols_create(): |
| 1238 |
register_responses([ |
| 1239 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 1240 |
('GET', 'svm/svms', SRR['zero_records']), |
| 1241 |
('POST', 'svm/svms', SRR['success']), |
| 1242 |
('PATCH', 'private/cli/vserver/add-protocols', SRR['generic_error']), |
| 1243 |
]) |
| 1244 |
module_args = { |
| 1245 |
'allowed_protocols': 'nfs,cifs,s3', |
| 1246 |
} |
| 1247 |
msg = 'Error adding protocols: calling: private/cli/vserver/add-protocols: got Expected error. - None' |
| 1248 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 1249 |
|
| 1250 |
|
| 1251 |
def test_rest_cli_remove_protocols_modify(): |
| 1252 |
register_responses([ |
| 1253 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 1254 |
('GET', 'svm/svms', SRR['svm_record_ap']), |
| 1255 |
('GET', 'private/cli/vserver', SRR['cli_record']), |
| 1256 |
('PATCH', 'private/cli/vserver/remove-protocols', SRR['success']), |
| 1257 |
]) |
| 1258 |
module_args = { |
| 1259 |
'allowed_protocols': 'nfs,cifs,s3', |
| 1260 |
} |
| 1261 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 1262 |
|
| 1263 |
|
| 1264 |
def test_error_rest_cli_remove_protocols_modify(): |
| 1265 |
register_responses([ |
| 1266 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 1267 |
('GET', 'svm/svms', SRR['svm_record_ap']), |
| 1268 |
('GET', 'private/cli/vserver', SRR['cli_record']), |
| 1269 |
('PATCH', 'private/cli/vserver/remove-protocols', SRR['generic_error']), |
| 1270 |
]) |
| 1271 |
module_args = { |
| 1272 |
'allowed_protocols': 'nfs,cifs,s3', |
| 1273 |
} |
| 1274 |
msg = 'Error removing protocols: calling: private/cli/vserver/remove-protocols: got Expected error. - None' |
| 1275 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args, fail=True)['msg'] == msg |
| 1276 |
|
| 1277 |
|
| 1278 |
def test_add_parameter_to_dict(): |
| 1279 |
register_responses([ |
| 1280 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 1281 |
]) |
| 1282 |
module_args = { |
| 1283 |
'name': 'svm', |
| 1284 |
'ipspace': 'ipspace', |
| 1285 |
'max_volumes': 3333, |
| 1286 |
} |
| 1287 |
my_obj = create_module(svm_module, DEFAULT_ARGS, module_args) |
| 1288 |
test_dict = {} |
| 1289 |
my_obj.add_parameter_to_dict(test_dict, 'name', None) |
| 1290 |
my_obj.add_parameter_to_dict(test_dict, 'ipspace', 'ipspace_key') |
| 1291 |
my_obj.add_parameter_to_dict(test_dict, 'max_volumes', None, True) |
| 1292 |
print(test_dict) |
| 1293 |
assert test_dict['name'] == 'svm' |
| 1294 |
assert test_dict['ipspace_key'] == 'ipspace' |
| 1295 |
assert test_dict['max_volumes'] == '3333' |
| 1296 |
|
| 1297 |
|
| 1298 |
def test_rest_language_match(): |
| 1299 |
register_responses([ |
| 1300 |
('GET', 'cluster', SRR['is_rest_9_8_0']), |
| 1301 |
('GET', 'svm/svms', SRR['svm_record_ap']), |
| 1302 |
('GET', 'private/cli/vserver', SRR['cli_record']), |
| 1303 |
('PATCH', 'svm/svms/svm_uuid', SRR['success']), |
| 1304 |
]) |
| 1305 |
module_args = { |
| 1306 |
'language': 'de.UTF-8' |
| 1307 |
} |
| 1308 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 1309 |
print_warnings() |
| 1310 |
assert_warning_was_raised( |
| 1311 |
'Attempting to change language from ONTAP value de.utf_8 to de.UTF-8. Use de.utf_8 to suppress this warning and maintain idempotency.') |
| 1312 |
|
| 1313 |
|
| 1314 |
def test_rest_storage_options_modify(): |
| 1315 |
register_responses([ |
| 1316 |
('GET', 'cluster', SRR['is_rest_9_13_1']), |
| 1317 |
('GET', 'svm/svms', SRR['svm_record']), |
| 1318 |
('PATCH', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7', SRR['success']), |
| 1319 |
]) |
| 1320 |
module_args = {'storage_limit': 524288000, 'storage_limit_threshold_alert': 95} |
| 1321 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |
| 1322 |
|
| 1323 |
|
| 1324 |
def test_rest_extended_params_modify(): |
| 1325 |
register_responses([ |
| 1326 |
('GET', 'cluster', SRR['is_rest_9_13_1']), |
| 1327 |
('GET', 'svm/svms', SRR['svm_record']), |
| 1328 |
('PATCH', 'svm/svms/09e9fd5e-8ebd-11e9-b162-005056b39fe7', SRR['success']), |
| 1329 |
]) |
| 1330 |
module_args = {'auto_enable_analytics': True, 'auto_enable_activity_tracking': True} |
| 1331 |
assert create_and_apply(svm_module, DEFAULT_ARGS, module_args)['changed'] |