1# -*- coding: utf-8 -*- 2# 3# Copyright (c) 2017 F5 Networks Inc. 4# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 5 6from __future__ import (absolute_import, division, print_function) 7__metaclass__ = type 8 9import os 10import json 11import pytest 12import sys 13 14if sys.version_info < (2, 7): 15 pytestmark = pytest.mark.skip("F5 Ansible modules require Python >= 2.7") 16 17from ansible.module_utils.basic import AnsibleModule 18 19from ansible_collections.f5networks.f5_modules.plugins.modules.bigip_virtual_server import ( 20 ApiParameters, ModuleParameters, ModuleManager, ArgumentSpec 21) 22from ansible_collections.f5networks.f5_modules.tests.unit.compat import unittest 23from ansible_collections.f5networks.f5_modules.tests.unit.compat.mock import Mock, patch 24from ansible_collections.f5networks.f5_modules.tests.unit.modules.utils import set_module_args 25 26 27fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures') 28fixture_data = {} 29 30 31def load_fixture(name): 32 path = os.path.join(fixture_path, name) 33 34 if path in fixture_data: 35 return fixture_data[path] 36 37 with open(path) as f: 38 data = f.read() 39 40 try: 41 data = json.loads(data) 42 except Exception: 43 pass 44 45 fixture_data[path] = data 46 return data 47 48 49class TestParameters(unittest.TestCase): 50 def test_destination_mutex_1(self): 51 args = dict( 52 destination='1.1.1.1' 53 ) 54 p = ApiParameters(params=args) 55 assert p.destination_tuple.ip == '1.1.1.1' 56 57 def test_destination_mutex_2(self): 58 args = dict( 59 destination='1.1.1.1%2' 60 ) 61 p = ApiParameters(params=args) 62 assert p.destination_tuple.ip == '1.1.1.1' 63 assert p.destination_tuple.route_domain == 2 64 65 def test_destination_mutex_3(self): 66 args = dict( 67 destination='1.1.1.1:80' 68 ) 69 p = ApiParameters(params=args) 70 assert p.destination_tuple.ip == '1.1.1.1' 71 assert p.destination_tuple.port == 80 72 73 def test_destination_mutex_4(self): 74 args = dict( 75 destination='1.1.1.1%2:80' 76 ) 77 p = ApiParameters(params=args) 78 assert p.destination_tuple.ip == '1.1.1.1' 79 assert p.destination_tuple.port == 80 80 assert p.destination_tuple.route_domain == 2 81 82 def test_api_destination_mutex_5(self): 83 args = dict( 84 destination='/Common/1.1.1.1' 85 ) 86 p = ApiParameters(params=args) 87 assert p.destination_tuple.ip == '1.1.1.1' 88 89 def test_api_destination_mutex_6(self): 90 args = dict( 91 destination='/Common/1.1.1.1%2' 92 ) 93 p = ApiParameters(params=args) 94 assert p.destination_tuple.ip == '1.1.1.1' 95 assert p.destination_tuple.route_domain == 2 96 97 def test_api_destination_mutex_7(self): 98 args = dict( 99 destination='/Common/1.1.1.1:80' 100 ) 101 p = ApiParameters(params=args) 102 assert p.destination_tuple.ip == '1.1.1.1' 103 assert p.destination_tuple.port == 80 104 105 def test_api_destination_mutex_8(self): 106 args = dict( 107 destination='/Common/1.1.1.1%2:80' 108 ) 109 p = ApiParameters(params=args) 110 assert p.destination_tuple.ip == '1.1.1.1' 111 assert p.destination_tuple.port == 80 112 assert p.destination_tuple.route_domain == 2 113 114 def test_destination_mutex_9(self): 115 args = dict( 116 destination='2700:bc00:1f10:101::6' 117 ) 118 p = ApiParameters(params=args) 119 assert p.destination_tuple.ip == '2700:bc00:1f10:101::6' 120 121 def test_destination_mutex_10(self): 122 args = dict( 123 destination='2700:bc00:1f10:101::6%2' 124 ) 125 p = ApiParameters(params=args) 126 assert p.destination_tuple.ip == '2700:bc00:1f10:101::6' 127 assert p.destination_tuple.route_domain == 2 128 129 def test_destination_mutex_11(self): 130 args = dict( 131 destination='2700:bc00:1f10:101::6.80' 132 ) 133 p = ApiParameters(params=args) 134 assert p.destination_tuple.ip == '2700:bc00:1f10:101::6' 135 assert p.destination_tuple.port == 80 136 137 def test_destination_mutex_12(self): 138 args = dict( 139 destination='2700:bc00:1f10:101::6%2.80' 140 ) 141 p = ApiParameters(params=args) 142 assert p.destination_tuple.ip == '2700:bc00:1f10:101::6' 143 assert p.destination_tuple.port == 80 144 assert p.destination_tuple.route_domain == 2 145 146 def test_module_no_partition_prefix_parameters(self): 147 args = dict( 148 state='present', 149 partition='Common', 150 name='my-virtual-server', 151 destination='10.10.10.10', 152 port=443, 153 pool='my-pool', 154 snat='Automap', 155 description='Test Virtual Server', 156 profiles=[ 157 dict( 158 name='fix', 159 context='all' 160 ) 161 ], 162 enabled_vlans=['vlan2'] 163 ) 164 p = ModuleParameters(params=args) 165 assert p.name == 'my-virtual-server' 166 assert p.partition == 'Common' 167 assert p.port == 443 168 assert p.destination == '/Common/10.10.10.10:443' 169 assert p.pool == '/Common/my-pool' 170 assert p.snat == {'type': 'automap'} 171 assert p.description == 'Test Virtual Server' 172 assert len(p.profiles) == 1 173 assert 'context' in p.profiles[0] 174 assert 'name' in p.profiles[0] 175 assert '/Common/vlan2' in p.enabled_vlans 176 177 def test_module_partition_prefix_parameters(self): 178 args = dict( 179 state='present', 180 partition='Common', 181 name='my-virtual-server', 182 destination='10.10.10.10', 183 port=443, 184 pool='/Common/my-pool', 185 snat='Automap', 186 description='Test Virtual Server', 187 profiles=[ 188 dict( 189 name='fix', 190 context='all' 191 ) 192 ], 193 enabled_vlans=['/Common/vlan2'] 194 ) 195 p = ModuleParameters(params=args) 196 assert p.name == 'my-virtual-server' 197 assert p.partition == 'Common' 198 assert p.port == 443 199 assert p.destination == '/Common/10.10.10.10:443' 200 assert p.pool == '/Common/my-pool' 201 assert p.snat == {'type': 'automap'} 202 assert p.description == 'Test Virtual Server' 203 assert len(p.profiles) == 1 204 assert 'context' in p.profiles[0] 205 assert 'name' in p.profiles[0] 206 assert '/Common/vlan2' in p.enabled_vlans 207 208 def test_api_parameters_variables(self): 209 args = { 210 "kind": "tm:ltm:virtual:virtualstate", 211 "name": "my-virtual-server", 212 "partition": "Common", 213 "fullPath": "/Common/my-virtual-server", 214 "generation": 54, 215 "selfLink": "https://localhost/mgmt/tm/ltm/virtual/~Common~my-virtual-server?expandSubcollections=true&ver=12.1.2", 216 "addressStatus": "yes", 217 "autoLasthop": "default", 218 "cmpEnabled": "yes", 219 "connectionLimit": 0, 220 "description": "Test Virtual Server", 221 "destination": "/Common/10.10.10.10:443", 222 "enabled": True, 223 "gtmScore": 0, 224 "ipProtocol": "tcp", 225 "mask": "255.255.255.255", 226 "mirror": "disabled", 227 "mobileAppTunnel": "disabled", 228 "nat64": "disabled", 229 "rateLimit": "disabled", 230 "rateLimitDstMask": 0, 231 "rateLimitMode": "object", 232 "rateLimitSrcMask": 0, 233 "serviceDownImmediateAction": "none", 234 "source": "0.0.0.0/0", 235 "sourceAddressTranslation": { 236 "type": "automap" 237 }, 238 "sourcePort": "preserve", 239 "synCookieStatus": "not-activated", 240 "translateAddress": "enabled", 241 "translatePort": "enabled", 242 "vlansEnabled": True, 243 "vsIndex": 3, 244 "vlans": [ 245 "/Common/net1" 246 ], 247 "vlansReference": [ 248 { 249 "link": "https://localhost/mgmt/tm/net/vlan/~Common~net1?ver=12.1.2" 250 } 251 ], 252 "policiesReference": { 253 "link": "https://localhost/mgmt/tm/ltm/virtual/~Common~my-virtual-server/policies?ver=12.1.2", 254 "isSubcollection": True 255 }, 256 "profilesReference": { 257 "link": "https://localhost/mgmt/tm/ltm/virtual/~Common~my-virtual-server/profiles?ver=12.1.2", 258 "isSubcollection": True, 259 "items": [ 260 { 261 "kind": "tm:ltm:virtual:profiles:profilesstate", 262 "name": "http", 263 "partition": "Common", 264 "fullPath": "/Common/http", 265 "generation": 54, 266 "selfLink": "https://localhost/mgmt/tm/ltm/virtual/~Common~my-virtual-server/profiles/~Common~http?ver=12.1.2", 267 "context": "all", 268 "nameReference": { 269 "link": "https://localhost/mgmt/tm/ltm/profile/http/~Common~http?ver=12.1.2" 270 } 271 }, 272 { 273 "kind": "tm:ltm:virtual:profiles:profilesstate", 274 "name": "serverssl", 275 "partition": "Common", 276 "fullPath": "/Common/serverssl", 277 "generation": 54, 278 "selfLink": "https://localhost/mgmt/tm/ltm/virtual/~Common~my-virtual-server/profiles/~Common~serverssl?ver=12.1.2", 279 "context": "serverside", 280 "nameReference": { 281 "link": "https://localhost/mgmt/tm/ltm/profile/server-ssl/~Common~serverssl?ver=12.1.2" 282 } 283 }, 284 { 285 "kind": "tm:ltm:virtual:profiles:profilesstate", 286 "name": "tcp", 287 "partition": "Common", 288 "fullPath": "/Common/tcp", 289 "generation": 54, 290 "selfLink": "https://localhost/mgmt/tm/ltm/virtual/~Common~my-virtual-server/profiles/~Common~tcp?ver=12.1.2", 291 "context": "all", 292 "nameReference": { 293 "link": "https://localhost/mgmt/tm/ltm/profile/tcp/~Common~tcp?ver=12.1.2" 294 } 295 } 296 ] 297 } 298 } 299 p = ApiParameters(params=args) 300 assert p.name == 'my-virtual-server' 301 assert p.partition == 'Common' 302 assert p.port == 443 303 assert p.destination == '/Common/10.10.10.10:443' 304 assert p.snat == {'type': 'automap'} 305 assert p.description == 'Test Virtual Server' 306 assert 'context' in p.profiles[0] 307 assert 'name' in p.profiles[0] 308 assert 'fullPath' in p.profiles[0] 309 assert p.profiles[0]['context'] == 'all' 310 assert p.profiles[0]['name'] == 'http' 311 assert p.profiles[0]['fullPath'] == '/Common/http' 312 assert '/Common/net1' in p.vlans 313 314 def test_module_address_translation_enabled(self): 315 args = dict( 316 address_translation=True 317 ) 318 p = ModuleParameters(params=args) 319 assert p.address_translation == 'enabled' 320 321 def test_module_address_translation_disabled(self): 322 args = dict( 323 address_translation=False 324 ) 325 p = ModuleParameters(params=args) 326 assert p.address_translation == 'disabled' 327 328 329class TestManager(unittest.TestCase): 330 331 def setUp(self): 332 self.spec = ArgumentSpec() 333 self.p1 = patch('ansible_collections.f5networks.f5_modules.plugins.modules.bigip_virtual_server.modules_provisioned') 334 self.m1 = self.p1.start() 335 self.m1.return_value = ['ltm', 'gtm', 'asm'] 336 self.p2 = patch( 337 'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_virtual_server.Parameters._read_current_clientssl_profiles_from_device' 338 ) 339 self.p3 = patch( 340 'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_virtual_server.Parameters._read_current_serverssl_profiles_from_device' 341 ) 342 self.p4 = patch( 343 'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_virtual_server.VirtualServerValidator.check_create' 344 ) 345 self.p5 = patch( 346 'ansible_collections.f5networks.f5_modules.plugins.modules.bigip_virtual_server.VirtualServerValidator.check_update' 347 ) 348 self.m2 = self.p2.start() 349 self.m3 = self.p3.start() 350 self.m4 = self.p4.start() 351 self.m5 = self.p5.start() 352 self.m2.return_value = ['asda', 'clientssl', 'cs_foobar.star.local'] 353 self.m3.return_value = ['baz', 'serverssl', 'ss_foobar.star.local'] 354 self.m4.return_value = Mock(return_value=True) 355 self.m5.return_value = Mock(return_value=True) 356 357 self.p6 = patch('ansible_collections.f5networks.f5_modules.plugins.modules.bigip_virtual_server.tmos_version') 358 self.p7 = patch('ansible_collections.f5networks.f5_modules.plugins.modules.bigip_virtual_server.send_teem') 359 self.m6 = self.p6.start() 360 self.m6.return_value = '14.1.0' 361 self.m7 = self.p7.start() 362 self.m7.return_value = True 363 364 def tearDown(self): 365 self.p1.stop() 366 self.p2.stop() 367 self.p3.stop() 368 self.p4.stop() 369 self.p5.stop() 370 371 def test_create_virtual_server(self, *args): 372 set_module_args(dict( 373 all_profiles=[ 374 dict( 375 name='http' 376 ), 377 dict( 378 name='clientssl' 379 ) 380 ], 381 description="Test Virtual Server", 382 destination="10.10.10.10", 383 name="my-snat-pool", 384 partition="Common", 385 port="443", 386 snat="Automap", 387 state="present", 388 provider=dict( 389 server='localhost', 390 password='password', 391 user='admin' 392 ) 393 394 )) 395 396 module = AnsibleModule( 397 argument_spec=self.spec.argument_spec, 398 supports_check_mode=self.spec.supports_check_mode, 399 mutually_exclusive=self.spec.mutually_exclusive 400 ) 401 402 # Override methods to force specific logic in the module to happen 403 mm = ModuleManager(module=module) 404 mm.exists = Mock(return_value=False) 405 mm.create_on_device = Mock(return_value=True) 406 results = mm.exec_module() 407 408 assert results['changed'] is True 409 410 def test_delete_virtual_server(self, *args): 411 set_module_args(dict( 412 all_profiles=[ 413 'http', 'clientssl' 414 ], 415 description="Test Virtual Server", 416 destination="10.10.10.10", 417 name="my-snat-pool", 418 partition="Common", 419 port="443", 420 snat="Automap", 421 state="absent", 422 provider=dict( 423 server='localhost', 424 password='password', 425 user='admin' 426 ) 427 )) 428 429 module = AnsibleModule( 430 argument_spec=self.spec.argument_spec, 431 supports_check_mode=self.spec.supports_check_mode, 432 mutually_exclusive=self.spec.mutually_exclusive 433 ) 434 435 # Override methods to force specific logic in the module to happen 436 mm = ModuleManager(module=module) 437 mm.exists = Mock(return_value=False) 438 439 results = mm.exec_module() 440 441 assert results['changed'] is False 442 443 def test_enable_vs_that_is_already_enabled(self, *args): 444 set_module_args(dict( 445 all_profiles=[ 446 'http', 'clientssl' 447 ], 448 description="Test Virtual Server", 449 destination="10.10.10.10", 450 name="my-snat-pool", 451 partition="Common", 452 port="443", 453 snat="Automap", 454 state="absent", 455 provider=dict( 456 server='localhost', 457 password='password', 458 user='admin' 459 ) 460 )) 461 462 # Configure the parameters that would be returned by querying the 463 # remote device 464 current = ApiParameters( 465 dict( 466 agent_status_traps='disabled' 467 ) 468 ) 469 470 module = AnsibleModule( 471 argument_spec=self.spec.argument_spec, 472 supports_check_mode=self.spec.supports_check_mode, 473 mutually_exclusive=self.spec.mutually_exclusive 474 ) 475 476 # Override methods to force specific logic in the module to happen 477 mm = ModuleManager(module=module) 478 mm.exists = Mock(return_value=False) 479 mm.update_on_device = Mock(return_value=True) 480 mm.read_current_from_device = Mock(return_value=current) 481 results = mm.exec_module() 482 483 assert results['changed'] is False 484 485 def test_modify_port(self, *args): 486 set_module_args(dict( 487 name="my-virtual-server", 488 partition="Common", 489 port="10443", 490 state="present", 491 provider=dict( 492 server='localhost', 493 password='password', 494 user='admin' 495 ) 496 )) 497 498 # Configure the parameters that would be returned by querying the 499 # remote device 500 current = ApiParameters(params=load_fixture('load_ltm_virtual_1.json')) 501 502 module = AnsibleModule( 503 argument_spec=self.spec.argument_spec, 504 supports_check_mode=self.spec.supports_check_mode, 505 mutually_exclusive=self.spec.mutually_exclusive 506 ) 507 508 # Override methods to force specific logic in the module to happen 509 mm = ModuleManager(module=module) 510 mm.exists = Mock(return_value=True) 511 mm.read_current_from_device = Mock(return_value=current) 512 mm.update_on_device = Mock(return_value=True) 513 results = mm.exec_module() 514 515 assert results['changed'] is True 516 517 def test_modify_port_idempotent(self, *args): 518 set_module_args(dict( 519 name="my-virtual-server", 520 partition="Common", 521 port="443", 522 state="present", 523 provider=dict( 524 server='localhost', 525 password='password', 526 user='admin' 527 ) 528 )) 529 530 # Configure the parameters that would be returned by querying the 531 # remote device 532 current = ApiParameters(params=load_fixture('load_ltm_virtual_1.json')) 533 534 module = AnsibleModule( 535 argument_spec=self.spec.argument_spec, 536 supports_check_mode=self.spec.supports_check_mode, 537 mutually_exclusive=self.spec.mutually_exclusive 538 ) 539 540 # Override methods to force specific logic in the module to happen 541 mm = ModuleManager(module=module) 542 mm.exists = Mock(return_value=True) 543 mm.read_current_from_device = Mock(return_value=current) 544 results = mm.exec_module() 545 546 assert results['changed'] is False 547 548 def test_modify_vlans_idempotent(self, *args): 549 set_module_args(dict( 550 name="my-virtual-server", 551 partition="Common", 552 disabled_vlans=[ 553 "net1" 554 ], 555 state="present", 556 provider=dict( 557 server='localhost', 558 password='password', 559 user='admin' 560 ) 561 )) 562 563 # Configure the parameters that would be returned by querying the 564 # remote device 565 current = ApiParameters(params=load_fixture('load_ltm_virtual_2.json')) 566 567 module = AnsibleModule( 568 argument_spec=self.spec.argument_spec, 569 supports_check_mode=self.spec.supports_check_mode, 570 mutually_exclusive=self.spec.mutually_exclusive 571 ) 572 573 # Override methods to force specific logic in the module to happen 574 mm = ModuleManager(module=module) 575 mm.exists = Mock(return_value=True) 576 mm.read_current_from_device = Mock(return_value=current) 577 578 results = mm.exec_module() 579 580 assert results['changed'] is False 581 582 def test_modify_profiles(self, *args): 583 set_module_args(dict( 584 name="my-virtual-server", 585 partition="Common", 586 profiles=[ 587 'http', 'clientssl' 588 ], 589 state="present", 590 provider=dict( 591 server='localhost', 592 password='password', 593 user='admin' 594 ) 595 )) 596 597 # Configure the parameters that would be returned by querying the 598 # remote device 599 current = ApiParameters(params=load_fixture('load_ltm_virtual_2.json')) 600 module = AnsibleModule( 601 argument_spec=self.spec.argument_spec, 602 supports_check_mode=self.spec.supports_check_mode, 603 mutually_exclusive=self.spec.mutually_exclusive 604 ) 605 606 # Override methods to force specific logic in the module to happen 607 mm = ModuleManager(module=module) 608 mm.exists = Mock(return_value=True) 609 mm.read_current_from_device = Mock(return_value=current) 610 mm.update_on_device = Mock(return_value=True) 611 612 results = mm.exec_module() 613 614 assert results['changed'] is True 615 assert len(results['profiles']) == 2 616 assert 'name' in results['profiles'][0] 617 assert 'context' in results['profiles'][0] 618 assert results['profiles'][0]['name'] == 'http' 619 assert results['profiles'][0]['context'] == 'all' 620 assert 'name' in results['profiles'][1] 621 assert 'context' in results['profiles'][1] 622 assert results['profiles'][1]['name'] == 'clientssl' 623 assert results['profiles'][1]['context'] == 'clientside' 624 625 def test_update_virtual_server(self, *args): 626 set_module_args(dict( 627 profiles=[ 628 dict( 629 name='http' 630 ), 631 dict( 632 name='clientssl' 633 ) 634 ], 635 description="foo virtual", 636 destination="1.1.1.1", 637 name="my-virtual-server", 638 partition="Common", 639 port="8443", 640 snat="snat-pool1", 641 state="disabled", 642 source='1.2.3.4/32', 643 irules=[ 644 'irule1', 645 'irule2' 646 ], 647 policies=[ 648 'policy1', 649 'policy2' 650 ], 651 enabled_vlans=[ 652 'vlan1', 653 'vlan2' 654 ], 655 pool='my-pool', 656 default_persistence_profile='source_addr', 657 fallback_persistence_profile='dest_addr', 658 provider=dict( 659 server='localhost', 660 password='password', 661 user='admin' 662 ) 663 )) 664 665 # Configure the parameters that would be returned by querying the 666 # remote device 667 current = ApiParameters(params=load_fixture('load_ltm_virtual_3.json')) 668 669 module = AnsibleModule( 670 argument_spec=self.spec.argument_spec, 671 supports_check_mode=self.spec.supports_check_mode, 672 mutually_exclusive=self.spec.mutually_exclusive 673 ) 674 675 # Override methods to force specific logic in the module to happen 676 mm = ModuleManager(module=module) 677 mm.exists = Mock(return_value=True) 678 mm.read_current_from_device = Mock(return_value=current) 679 mm.update_on_device = Mock(return_value=True) 680 681 results = mm.exec_module() 682 683 assert results['changed'] is True 684 assert results['source'] == '1.2.3.4/32' 685 assert results['description'] == 'foo virtual' 686 assert results['snat'] == '/Common/snat-pool1' 687 assert results['destination'] == '1.1.1.1' 688 assert results['port'] == 8443 689 assert results['default_persistence_profile'] == '/Common/source_addr' 690 assert results['fallback_persistence_profile'] == '/Common/dest_addr' 691 692 # policies 693 assert len(results['policies']) == 2 694 assert '/Common/policy1' in results['policies'] 695 assert '/Common/policy2' in results['policies'] 696 697 # irules 698 assert len(results['irules']) == 2 699 assert '/Common/irule1' in results['irules'] 700 assert '/Common/irule2' in results['irules'] 701 702 # vlans 703 assert len(results['enabled_vlans']) == 2 704 assert '/Common/vlan1' in results['enabled_vlans'] 705 assert '/Common/vlan2' in results['enabled_vlans'] 706 707 # profiles 708 assert len(results['profiles']) == 2 709 assert 'name' in results['profiles'][0] 710 assert 'context' in results['profiles'][0] 711 assert results['profiles'][0]['name'] == 'http' 712 assert results['profiles'][0]['context'] == 'all' 713 assert 'name' in results['profiles'][1] 714 assert 'context' in results['profiles'][1] 715 assert results['profiles'][1]['name'] == 'clientssl' 716 assert results['profiles'][1]['context'] == 'clientside' 717 718 def test_create_virtual_server_with_address_translation_bool_true(self, *args): 719 set_module_args(dict( 720 destination="10.10.10.10", 721 address_translation=True, 722 name="my-snat-pool", 723 partition="Common", 724 port="443", 725 state="present", 726 provider=dict( 727 server='localhost', 728 password='password', 729 user='admin' 730 ) 731 )) 732 733 module = AnsibleModule( 734 argument_spec=self.spec.argument_spec, 735 supports_check_mode=self.spec.supports_check_mode, 736 mutually_exclusive=self.spec.mutually_exclusive 737 ) 738 739 # Override methods to force specific logic in the module to happen 740 mm = ModuleManager(module=module) 741 mm.exists = Mock(return_value=False) 742 mm.create_on_device = Mock(return_value=True) 743 results = mm.exec_module() 744 745 assert results['changed'] is True 746 assert results['address_translation'] is True 747 748 def test_create_virtual_server_with_address_translation_string_yes(self, *args): 749 set_module_args(dict( 750 destination="10.10.10.10", 751 address_translation='yes', 752 name="my-snat-pool", 753 partition="Common", 754 port="443", 755 state="present", 756 provider=dict( 757 server='localhost', 758 password='password', 759 user='admin' 760 ) 761 )) 762 763 module = AnsibleModule( 764 argument_spec=self.spec.argument_spec, 765 supports_check_mode=self.spec.supports_check_mode, 766 mutually_exclusive=self.spec.mutually_exclusive 767 ) 768 769 # Override methods to force specific logic in the module to happen 770 mm = ModuleManager(module=module) 771 mm.exists = Mock(return_value=False) 772 mm.create_on_device = Mock(return_value=True) 773 results = mm.exec_module() 774 775 assert results['changed'] is True 776 assert results['address_translation'] is True 777 778 def test_create_virtual_server_with_address_translation_bool_false(self, *args): 779 set_module_args(dict( 780 destination="10.10.10.10", 781 address_translation=False, 782 name="my-snat-pool", 783 partition="Common", 784 port="443", 785 state="present", 786 provider=dict( 787 server='localhost', 788 password='password', 789 user='admin' 790 ) 791 )) 792 793 module = AnsibleModule( 794 argument_spec=self.spec.argument_spec, 795 supports_check_mode=self.spec.supports_check_mode, 796 mutually_exclusive=self.spec.mutually_exclusive 797 ) 798 799 # Override methods to force specific logic in the module to happen 800 mm = ModuleManager(module=module) 801 mm.exists = Mock(return_value=False) 802 mm.create_on_device = Mock(return_value=True) 803 results = mm.exec_module() 804 805 assert results['changed'] is True 806 assert results['address_translation'] is False 807 808 def test_create_virtual_server_with_address_translation_string_no(self, *args): 809 set_module_args(dict( 810 destination="10.10.10.10", 811 address_translation='no', 812 name="my-snat-pool", 813 partition="Common", 814 port="443", 815 state="present", 816 provider=dict( 817 server='localhost', 818 password='password', 819 user='admin' 820 ) 821 )) 822 823 module = AnsibleModule( 824 argument_spec=self.spec.argument_spec, 825 supports_check_mode=self.spec.supports_check_mode, 826 mutually_exclusive=self.spec.mutually_exclusive 827 ) 828 829 # Override methods to force specific logic in the module to happen 830 mm = ModuleManager(module=module) 831 mm.exists = Mock(return_value=False) 832 mm.create_on_device = Mock(return_value=True) 833 results = mm.exec_module() 834 835 assert results['changed'] is True 836 assert results['address_translation'] is False 837 838 def test_create_virtual_server_with_port_translation_bool_true(self, *args): 839 set_module_args(dict( 840 destination="10.10.10.10", 841 port_translation=True, 842 name="my-snat-pool", 843 partition="Common", 844 port="443", 845 state="present", 846 provider=dict( 847 server='localhost', 848 password='password', 849 user='admin' 850 ) 851 )) 852 853 module = AnsibleModule( 854 argument_spec=self.spec.argument_spec, 855 supports_check_mode=self.spec.supports_check_mode, 856 mutually_exclusive=self.spec.mutually_exclusive 857 ) 858 859 # Override methods to force specific logic in the module to happen 860 mm = ModuleManager(module=module) 861 mm.exists = Mock(return_value=False) 862 mm.create_on_device = Mock(return_value=True) 863 results = mm.exec_module() 864 865 assert results['changed'] is True 866 assert results['port_translation'] is True 867 868 def test_create_virtual_server_with_port_translation_string_yes(self, *args): 869 set_module_args(dict( 870 destination="10.10.10.10", 871 port_translation='yes', 872 name="my-snat-pool", 873 partition="Common", 874 port="443", 875 state="present", 876 provider=dict( 877 server='localhost', 878 password='password', 879 user='admin' 880 ) 881 )) 882 883 module = AnsibleModule( 884 argument_spec=self.spec.argument_spec, 885 supports_check_mode=self.spec.supports_check_mode, 886 mutually_exclusive=self.spec.mutually_exclusive 887 ) 888 889 # Override methods to force specific logic in the module to happen 890 mm = ModuleManager(module=module) 891 mm.exists = Mock(return_value=False) 892 mm.create_on_device = Mock(return_value=True) 893 results = mm.exec_module() 894 895 assert results['changed'] is True 896 assert results['port_translation'] is True 897 898 def test_create_virtual_server_with_port_translation_bool_false(self, *args): 899 set_module_args(dict( 900 destination="10.10.10.10", 901 port_translation=False, 902 name="my-snat-pool", 903 partition="Common", 904 port="443", 905 state="present", 906 provider=dict( 907 server='localhost', 908 password='password', 909 user='admin' 910 ) 911 )) 912 913 module = AnsibleModule( 914 argument_spec=self.spec.argument_spec, 915 supports_check_mode=self.spec.supports_check_mode, 916 mutually_exclusive=self.spec.mutually_exclusive 917 ) 918 919 # Override methods to force specific logic in the module to happen 920 mm = ModuleManager(module=module) 921 mm.exists = Mock(return_value=False) 922 mm.create_on_device = Mock(return_value=True) 923 results = mm.exec_module() 924 925 assert results['changed'] is True 926 assert results['port_translation'] is False 927 928 def test_create_virtual_server_with_port_translation_string_no(self, *args): 929 set_module_args(dict( 930 destination="10.10.10.10", 931 port_translation='no', 932 name="my-snat-pool", 933 partition="Common", 934 port="443", 935 state="present", 936 provider=dict( 937 server='localhost', 938 password='password', 939 user='admin' 940 ) 941 )) 942 943 module = AnsibleModule( 944 argument_spec=self.spec.argument_spec, 945 supports_check_mode=self.spec.supports_check_mode, 946 mutually_exclusive=self.spec.mutually_exclusive 947 ) 948 949 # Override methods to force specific logic in the module to happen 950 mm = ModuleManager(module=module) 951 mm.exists = Mock(return_value=False) 952 mm.create_on_device = Mock(return_value=True) 953 results = mm.exec_module() 954 955 assert results['changed'] is True 956 assert results['port_translation'] is False 957 958 def test_create_virtual_server_with_check_profiles_bool_true(self, *args): 959 set_module_args(dict( 960 all_profiles=[ 961 'http', 'clientssl' 962 ], 963 destination="10.10.10.10", 964 name="my-snat-pool", 965 partition="Common", 966 port="443", 967 state="present", 968 check_profiles='yes', 969 provider=dict( 970 server='localhost', 971 password='password', 972 user='admin' 973 ) 974 )) 975 976 module = AnsibleModule( 977 argument_spec=self.spec.argument_spec, 978 supports_check_mode=self.spec.supports_check_mode, 979 mutually_exclusive=self.spec.mutually_exclusive 980 ) 981 982 # Override methods to force specific logic in the module to happen 983 mm = ModuleManager(module=module) 984 mm.exists = Mock(return_value=False) 985 mm.create_on_device = Mock(return_value=True) 986 results = mm.exec_module() 987 988 assert results['changed'] is True 989 990 def test_create_virtual_server_with_check_profiles_bool_false(self, *args): 991 set_module_args(dict( 992 all_profiles=[ 993 'http', 'clientssl' 994 ], 995 destination="10.10.10.10", 996 name="my-snat-pool", 997 partition="Common", 998 port="443", 999 state="present", 1000 check_profiles='no', 1001 provider=dict( 1002 server='localhost', 1003 password='password', 1004 user='admin' 1005 ) 1006 )) 1007 1008 module = AnsibleModule( 1009 argument_spec=self.spec.argument_spec, 1010 supports_check_mode=self.spec.supports_check_mode, 1011 mutually_exclusive=self.spec.mutually_exclusive 1012 ) 1013 1014 # Override methods to force specific logic in the module to happen 1015 mm = ModuleManager(module=module) 1016 mm.exists = Mock(return_value=False) 1017 mm.create_on_device = Mock(return_value=True) 1018 results = mm.exec_module() 1019 1020 assert results['changed'] is True 1021