def test_create_ssl_object_rev_proxy(self, *args): # Configure the arguments that would be sent to the Ansible module set_module_args( dict(name='foobar', client_settings=dict(proxy_type='reverse', cert='/Common/default.crt', key='/Common/default.key'))) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, ) mm = ModuleManager(module=module) # Override methods to force specific logic in the module to happen mm.exists = Mock(return_value=False) mm.client.post = Mock(return_value=dict( code=202, contents=load_fixture( 'reply_sslo_ssl_create_rev_proxy_start.json'))) mm.client.get = Mock(return_value=dict( code=200, contents=load_fixture( 'reply_sslo_ssl_create_rev_proxy_done.json'))) results = mm.exec_module() assert results['changed'] is True assert results['client_settings'] == { 'proxy_type': 'reverse', 'cert': '/Common/default.crt', 'key': '/Common/default.key' }
def test_primary_auth_uri_invalid_protocol_l3_out(self, sslo): # Configure the arguments that would be sent to the Ansible module sslo.return_value = '8.2' err = "The 'primary_auth_uri' key can only be used with an outbound L3 TCP topology." set_module_args( dict(name='l3_topo_out', topology_type='outbound_l3', vlans=['/Common/fake'], protocol='other', primary_auth_uri='/fake')) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, mutually_exclusive=self.spec.mutually_exclusive, required_together=self.spec.required_together, required_if=self.spec.required_if) mm = ModuleManager(module=module) # Override methods to force specific logic in the module to happen mm.exists = Mock(return_value=False) mm.return_sslo_global = Mock(return_value=True) with self.assertRaises(F5ModuleError) as res: mm.exec_module() assert str(res.exception) == err
def test_create_swg_service_object_with_defaults(self, *args): # Configure the arguments that would be sent to the Ansible module set_module_args(dict(name='swg_default', swg_policy='/Common/test-swg')) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, ) mm = ModuleManager(module=module) # Override methods to force specific logic in the module to happen mm.exists = Mock(return_value=False) mm.client.post = Mock(return_value=dict( code=202, contents=load_fixture( 'reply_sslo_swg_create_defaults_start.json'))) mm.client.get = Mock(return_value=dict( code=200, contents=load_fixture('reply_sslo_swg_create_defaults_done.json'))) results = mm.exec_module() assert results['changed'] is True assert results['swg_policy'] == '/Common/test-swg'
def test_create_expl_out_topology_object_dump_json(self, *args): # Configure the arguments that would be sent to the Ansible module expected = load_fixture('sslo_l3_expl_topo_create_generated.json') set_module_args( dict(name='expl_topo', topology_type='outbound_explicit', proxy_ip='192.168.1.1', proxy_port=3211, security_policy='from_gui', ssl_settings='foobar', vlans=['/Common/fake1'], dump_json=True)) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, mutually_exclusive=self.spec.mutually_exclusive, required_together=self.spec.required_together, required_if=self.spec.required_if) mm = ModuleManager(module=module) # Override methods to force specific logic in the module to happen mm.exists = Mock(return_value=False) mm.client.get = Mock(return_value=dict( code=200, contents=load_fixture('sslo_gs_present.json'))) results = mm.exec_module() assert results['changed'] is False assert results['json'] == expected
def test_profile_scope_named_invalid_version(self, *args): # Configure the arguments that would be sent to the Ansible module err = "The 'primary_auth_uri', 'profile_scope_value' or 'profile_scope' are " \ "supported on SSLO version 8.2 and above, your SSLO version is 7.5." set_module_args( dict(name='l3_topo_out', topology_type='outbound_l3', vlans=['/Common/fake'], profile_scope='named', profile_scope_value='some_value', primary_auth_uri='/foofake')) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, mutually_exclusive=self.spec.mutually_exclusive, required_together=self.spec.required_together, required_if=self.spec.required_if) mm = ModuleManager(module=module) # Override methods to force specific logic in the module to happen mm.exists = Mock(return_value=False) mm.return_sslo_global = Mock(return_value=True) with self.assertRaises(F5ModuleError) as res: mm.exec_module() assert str(res.exception) == err
def test_import_image_progress_check_import_fails(self, *args): set_module_args( dict( image_name='F5OS-C-1.1.0-3198.PARTITION.iso', state='present', )) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, required_if=self.spec.required_if) importing = dict( code=200, contents=dict( load_fixture('partition_image_import_progress.json'))) fail = dict(code=200, contents=dict( load_fixture('partition_image_import_fail.json'))) mm = ModuleManager(module=module) mm.exists = Mock(return_value=False) mm.is_imported = Mock(side_effect=[False, False]) mm.client.post = Mock(side_effect=[importing, fail]) with self.assertRaises(F5ModuleError) as err: mm.exec_module() assert "Error uploading image: File Not Found, HTTP Error 404" in str( err.exception) assert mm.client.post.call_count == 2
def test_security_policy_missing_explicit_proxy(self, *args): # Configure the arguments that would be sent to the Ansible module set_module_args( dict(name='explicit_out', topology_type='outbound_explicit', proxy_ip='191.1.1.1', proxy_port=1234, vlans=['/Common/fake'])) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, mutually_exclusive=self.spec.mutually_exclusive, required_together=self.spec.required_together, required_if=self.spec.required_if) mm = ModuleManager(module=module) # Override methods to force specific logic in the module to happen mm.exists = Mock(return_value=False) mm.return_sslo_global = Mock(return_value=True) with self.assertRaises(F5ModuleError) as res: mm.exec_module() assert str( res.exception ) == "The 'security_policy' is required when creating explicit proxy type topology."
def test_modify_service_chain_object(self, *args): # Configure the arguments that would be sent to the Ansible module set_module_args( dict(name="foobar", services=[ dict(service_name="layer3a", type="L3", ip_family="ipv4") ])) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, required_if=self.spec.required_if) mm = ModuleManager(module=module) exists = dict(code=200, contents=load_fixture('load_sslo_sc.json')) done = dict(code=200, contents=load_fixture('reply_sslo_sc_modify_done.json')) # Override methods to force specific logic in the module to happen mm.client.post = Mock(return_value=dict( code=202, contents=load_fixture( 'reply_sslo_sc_modify_start.json'))) mm.client.get = Mock(side_effect=[exists, exists, done]) results = mm.exec_module() assert results['changed'] is True assert results['services'] == [{ 'name': 'ssloS_layer3a', 'ipFamily': 'ipv4', 'serviceType': 'L3' }]
def test_start_software_install(self, *args): set_module_args(dict( image='13.0.0.iso', volume='HD1.2', )) current = ApiParameters() current.read_image_from_device = Mock(side_effect=[ ['13.0.0.iso'], ['BIGIP-12.1.3.4-0.0.2.iso'], ]) volumes = dict(code=200, contents=load_fixture('load_volumes.json')) volume = dict(code=404, contents=dict()) images = dict(code=200, contents=load_fixture('load_software_image.json')) hotfixes = dict(code=404, contents=dict()) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode) # Override methods in the specific type of manager mm = ModuleManager(module=module) mm.have = current mm.client.get = Mock( side_effect=[volumes, volume, volumes, volume, images, hotfixes]) mm.client.post = Mock(return_value=dict(code=200, contents=dict())) results = mm.exec_module() assert results['changed'] is True assert results[ 'message'] == 'Started software image installation 13.0.0.iso on volume HD1.2.' assert results['volume_uri'] == '/mgmt/tm/sys/software/volume/HD1.2'
def test_remove_image_failed(self): set_module_args( dict( image_name= 'BIGIP-bigip14.1.x-miro-14.1.2.5-0.0.336.ALL-VELOS.qcow2.zip', state='absent', )) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, required_if=self.spec.required_if) response = dict( code=200, contents={"f5-tenant-images:output": { "result": "Failed." }}) mm = ModuleManager(module=module) mm.exists = Mock(return_value=True) mm.client.post = Mock(return_value=response) with self.assertRaises(F5ModuleError) as err: mm.exec_module() assert 'Failed to remove tenant image: ' \ 'BIGIP-bigip14.1.x-miro-14.1.2.5-0.0.336.ALL-VELOS.qcow2.zip Failed.' in str(err.exception)
def test_update_rpm_package_failure_specific_error(self, *args): package_name = os.path.join(fixture_path, 'MyApp-0.1.0-0001.noarch.rpm') # Configure the arguments that would be sent to the Ansible module set_module_args(dict( package=package_name, utility='rpm-update', )) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, required_if=self.spec.required_if) mm = ModuleManager(module=module) # Override methods to force specific logic in the module to happen mm.same_sslo_version = Mock(return_value=False) mm.upload_to_device = Mock(return_value=True) mm.client.post = Mock(return_value=dict( code=202, contents=load_fixture('sslo_rpm_update_start.json'))) mm.client.get = Mock(return_value=dict( code=200, contents=load_fixture( 'sslo_rpm_update_failed_error_provided.json'))) with self.assertRaises(F5ModuleError) as res: mm.exec_module() assert "Package MyApp-0.1.0-0001.noarch.rpm is corrupted, aborting." in str( res.exception)
def test_remove_image(self): set_module_args( dict( image_name= 'BIGIP-bigip14.1.x-miro-14.1.2.5-0.0.336.ALL-VELOS.qcow2.zip', state='absent', )) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, required_if=self.spec.required_if) response = dict( code=200, contents={"f5-tenant-images:output": { "result": "Successful." }}) mm = ModuleManager(module=module) mm.exists = Mock(side_effect=[True, False]) mm.client.post = Mock(return_value=response) results = mm.exec_module() assert results['changed'] is True
def test_image_imported_failed_verification(self): set_module_args( dict( image_name= 'BIGIP-bigip14.1.x-miro-14.1.2.5-0.0.336.ALL-VELOS.qcow2.zip', state='present', )) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, required_if=self.spec.required_if) msg = 'The image: BIGIP-bigip14.1.x-miro-14.1.2.5-0.0.336.ALL-VELOS.qcow2.zip was imported, ' \ 'but it failed signature verification, remove the image and try again.' importing = dict(code=200, contents={"f5-tenant-images:status": "importing"}) verifying = dict(code=200, contents={"f5-tenant-images:status": "verifying"}) failed = dict( code=200, contents={"f5-tenant-images:status": "verification-failed"}) mm = ModuleManager(module=module) mm.exists = Mock(return_value=False) mm.client.get = Mock( side_effect=[importing, importing, verifying, verifying, failed]) with self.assertRaises(F5ModuleError) as err: mm.exec_module() assert msg in str(err.exception) assert mm.client.get.call_count == 5
def test_modify_ssl_object_fwd_proxy(self, *args): # Configure the arguments that would be sent to the Ansible module set_module_args( dict(name='barfoo', client_settings=dict(proxy_type='forward', ca_cert='/Common/sslo_test.crt', ca_key='/Common/sslo_test.key'))) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, ) mm = ModuleManager(module=module) exists = dict(code=200, contents=load_fixture('load_sslo_ssl_fwd_proxy.json')) done = dict( code=200, contents=load_fixture('reply_sslo_ssl_modify_fwd_proxy_done.json')) # Override methods to force specific logic in the module to happen mm.client.post = Mock(return_value=dict( code=202, contents=load_fixture( 'reply_sslo_ssl_modify_fwd_proxy_start.json'))) mm.client.get = Mock(side_effect=[exists, exists, done]) results = mm.exec_module() assert results['changed'] is True assert results['client_settings'] == { 'ca_cert': '/Common/sslo_test.crt', 'ca_key': '/Common/sslo_test.key' }
def test_modify_http_service_object(self, *args): # Configure the arguments that would be sent to the Ansible module set_module_args( dict( name='proxy1a', snat='snatlist', snat_list=['198.19.64.10', '198.19.64.11'], )) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, ) mm = ModuleManager(module=module) exists = dict(code=200, contents=load_fixture('load_sslo_service_http.json')) done = dict(code=200, contents=load_fixture('reply_sslo_http_modify_done.json')) # Override methods to force specific logic in the module to happen mm.client.post = Mock(return_value=dict( code=202, contents=load_fixture('reply_sslo_http_modify_start.json'))) mm.client.get = Mock(side_effect=[exists, exists, done]) results = mm.exec_module() assert results['changed'] is True assert results['snat'] == 'snatlist' assert results['snat_list'] == ['198.19.64.10', '198.19.64.11']
def test_check_task_download_ucs(self, *args): set_module_args( dict(backup='yes', dest='/tmp/foo.ucs', src='remote.ucs', task_id='e7550a12-994b-483f-84ee-761eb9af6750', timeout=400)) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, add_file_common_args=self.spec.add_file_common_args, ) # Override methods to force specific logic in the module to happen mm = ModuleManager(module=module) mm.async_wait = Mock(return_value=True) mm._get_backup_file = Mock(return_value='/tmp/foo.backup') mm.download_from_device = Mock(return_value=True) mm._set_checksum = Mock(return_value=12345) mm._set_md5sum = Mock(return_value=54321) p1 = patch('os.path.exists', return_value=True) p1.start() p2 = patch('os.path.isdir', return_value=False) p2.start() results = mm.exec_module() p1.stop() p2.stop() assert results['changed'] is True
def test_import_image_progress_check(self, *args): set_module_args( dict( image_name='F5OS-C-1.1.0-3198.PARTITION.iso', state='present', )) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, required_if=self.spec.required_if) importing = dict( code=200, contents=dict( load_fixture('partition_image_import_progress.json'))) completed = dict( code=200, contents=dict(load_fixture('partition_image_import_success.json'))) mm = ModuleManager(module=module) mm.exists = Mock(return_value=False) mm.is_imported = Mock(side_effect=[False, False, True]) mm.client.post = Mock(side_effect=[importing, completed]) results = mm.exec_module() assert results['changed'] is True assert results['message'] == 'Image F5OS-C-1.1.0-3198.PARTITION.iso ' \ 'import successful.' assert mm.client.post.call_count == 2
def test_create(self, *args): set_module_args(dict( pool='foo-pool', key='XXXX-XXXX-XXXX-XXXX-XXXX', device='1.1.1.1', device_username='******', device_password='******', managed='no', state='present' )) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, required_if=self.spec.required_if ) mm = ModuleManager(module=module) # Override methods to force specific logic in the module to happen mm.exists = Mock(side_effect=[False, True]) mm.create_on_device = Mock(return_value=True) mm.wait_for_device_to_be_licensed = Mock(return_value=True) results = mm.exec_module() assert results['changed'] is True
def test_remove_image_success(self): set_module_args( dict( image_name='F5OS-C-1.1.0-3198.PARTITION.iso', state='absent', )) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, required_if=self.spec.required_if) response = dict(code=200, contents={ "f5-system-image:output": { "response": "specified images removed" } }) mm = ModuleManager(module=module) mm.exists = Mock(side_effect=[True, False]) mm.client.post = Mock(return_value=response) results = mm.exec_module() assert results['changed'] is True
def test_partition_interface_delete_switched_vlan(self, *args): set_module_args(dict(name="2/1.0", trunk_vlans=[444], state='absent')) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, ) mm = ModuleManager(module=module) mm.exists = Mock(side_effect=[True, False]) mm.client.delete = Mock(return_value=dict(code=204, contents="")) mm.client.get = Mock(return_value=dict( code=200, contents=load_fixture( "load_velos_partition_interface_swichedvlan_config.json"))) fixdata = [] fixdata.append( load_fixture("load_velos_partition_interface_config.json")) newdata = { "openconfig-interfaces:interface": fixdata, } mm.client.get = Mock( return_value=dict(code=200, contents=dict(newdata))) results = mm.exec_module() assert results['changed'] is True
def test_proxy_ip_defined_for_non_explict_proxy_type(self, *args): # Configure the arguments that would be sent to the Ansible module err = "The 'proxy_ip' key is only to be used with explicit proxy type, use 'dest' key instead." set_module_args( dict(name='l2_out', topology_type='outbound_l2', proxy_ip='191.1.1.1', proxy_port=1234, ssl_settings='fakesettings', vlans=['/Common/fake'])) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, mutually_exclusive=self.spec.mutually_exclusive, required_together=self.spec.required_together, required_if=self.spec.required_if) mm = ModuleManager(module=module) # Override methods to force specific logic in the module to happen mm.exists = Mock(return_value=False) mm.return_sslo_global = Mock(return_value=True) with self.assertRaises(F5ModuleError) as res: mm.exec_module() assert str(res.exception) == err
def test_cli_command(self, *args): set_module_args(dict(commands=["show sys version"], )) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode) m1 = V1Manager(module=module) m1.execute_on_device = Mock(return_value=['resp1', 'resp2', 'resp3']) mm = ModuleManager(module=module) mm._run_commands = Mock(return_value=[]) mm.get_manager = Mock(return_value=m1) results = mm.exec_module() assert results['changed'] is False # call count is two on CLI transport because we must first # determine if the remote CLI is in tmsh mode or advanced shell # (bash) mode. # # 1 call for the shell check # 1 call for the command in the "commands" list above # # Can we change this in the future by making the terminal plugin # find this out ahead of time? assert m1.execute_on_device.call_count == 3
def test_ip_family_mismatch_proxy(self, *args): # Configure the arguments that would be sent to the Ansible module set_module_args( dict(name='fake_explicit', topology_type='outbound_explicit', vlans=['/Common/fake'], proxy_ip='19.1.1.1', proxy_port=1234, source='2001:0db8:85a3:0000:0000:8a2e:0370:7334/32')) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, mutually_exclusive=self.spec.mutually_exclusive, required_together=self.spec.required_together, required_if=self.spec.required_if) mm = ModuleManager(module=module) # Override methods to force specific logic in the module to happen mm.exists = Mock(return_value=False) mm.return_sslo_global = Mock(return_value=True) with self.assertRaises(F5ModuleError) as res: mm.exec_module() assert str( res.exception ) == 'Source and proxy addresses must be in the same IP family.'
def test_remove_fast_application(self, *args): set_module_args( dict( tenant='sample_tenant', application='sample_app', state='absent', )) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, required_if=self.spec.required_if, required_together=self.spec.required_together) mm = ModuleManager(module=module) # Override methods to force specific logic in the module to happen mm.exists = Mock(side_effect=[True, False]) mm.remove_from_device = Mock(return_value=True) results = mm.exec_module() assert mm.want.timeout == (3, 100) assert results['changed'] is True assert results['tenant'] == 'sample_tenant' assert results['application'] == 'sample_app'
def test_verify_accept_invalid_version(self, *args): # Configure the arguments that would be sent to the Ansible module err = "The 'verify_accept' key is supported on SSLO version 9.0 and above, your SSLO version is 7.5." set_module_args( dict(name='l2_topo_out', topology_type='inbound_l2', vlans=['/Common/fake'], verify_accept='no')) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, mutually_exclusive=self.spec.mutually_exclusive, required_together=self.spec.required_together, required_if=self.spec.required_if) mm = ModuleManager(module=module) # Override methods to force specific logic in the module to happen mm.exists = Mock(return_value=False) mm.return_sslo_global = Mock(return_value=True) with self.assertRaises(F5ModuleError) as res: mm.exec_module() assert str(res.exception) == err
def test_create_fast_application(self, *args): declaration = load_fixture('new_fast_app.json') set_module_args( dict(content=declaration, template='examples/simple_http', state='create', timeout=600)) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, required_if=self.spec.required_if, required_together=self.spec.required_together) mm = ModuleManager(module=module) # Override methods to force specific logic in the module to happen mm.template_exists = Mock(return_value=True) mm.create_on_device = Mock(return_value=True) results = mm.exec_module() assert mm.want.timeout == (6, 100) assert results['changed'] is True assert results['template'] == 'examples/simple_http' assert results['content'] == declaration
def test_ssl_settings_invalid_protocol_udp_l2_out(self, *args): # Configure the arguments that would be sent to the Ansible module set_module_args( dict(name='l2_topo_out', topology_type='outbound_l2', vlans=['/Common/fake'], protocol='udp', ssl_settings='foobar')) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, mutually_exclusive=self.spec.mutually_exclusive, required_together=self.spec.required_together, required_if=self.spec.required_if) mm = ModuleManager(module=module) # Override methods to force specific logic in the module to happen mm.exists = Mock(return_value=False) mm.return_sslo_global = Mock(return_value=True) with self.assertRaises(F5ModuleError) as res: mm.exec_module() assert str( res.exception ) == 'The Outbound L2 topology for UDP traffic cannot contain an ssl_settings key.'
def test_update_fast_application(self, *args): declaration = load_fixture('fast_app_update.json') set_module_args( dict( content=declaration, tenant='sample_tenant', application='sample_app', state='present', )) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, required_if=self.spec.required_if, required_together=self.spec.required_together) mm = ModuleManager(module=module) # Override methods to force specific logic in the module to happen mm.exists = Mock(return_value=True) mm.upsert_on_device = Mock(return_value=True) results = mm.exec_module() assert mm.want.timeout == (3, 100) assert results['changed'] is True assert results['tenant'] == 'sample_tenant' assert results['application'] == 'sample_app' assert results['content'] == declaration
def test_wait_running(self, *args): """ Transition to running state. """ set_module_args(dict( name='foo', state='running', timeout=100, )) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode) # Override methods to force specific logic in the module to happen mm = ModuleManager(module=module) # Simulate the tenant is not present until the 3rd loop iteration at # which time it is present and in the configured state. mm.partition_exists = Mock(side_effect=[False, False, True]) configured_state = load_fixture( 'load_partition_status_provisioned.json') mm.read_partition_from_device = Mock(return_value=configured_state) results = mm.exec_module() assert results['changed'] is False # assert results['elapsed'] >= 2 assert mm.partition_exists.called assert mm.read_partition_from_device.called
def test_tenant_update(self, *args): set_module_args(dict( name='foo', vlans=[444, 333], running_state='deployed', )) module = AnsibleModule( argument_spec=self.spec.argument_spec, supports_check_mode=self.spec.supports_check_mode, ) mm = ModuleManager(module=module) mm.exists = Mock(return_value=True) mm.client.patch = Mock(return_value=dict(code=204, contents={})) mm.client.get = Mock(return_value=dict(code=200, contents=load_fixture('load_tenant_status_configured.json'))) results = mm.exec_module() assert results['changed'] is True assert results['vlans'] == [333, 444] assert results['running_state'] == 'deployed' assert mm.client.patch.call_count == 2 assert mm.client.patch.call_args_list[0][0][0] == '/f5-tenants:tenants/tenant=foo/config/vlans' assert mm.client.patch.call_args_list[1][0][0] == '/f5-tenants:tenants/tenant=foo/config/running-state' assert mm.client.patch.call_args_list[0][1] == {'data': {'vlans': [333, 444]}} assert mm.client.patch.call_args_list[1][1] == {'data': {'running-state': 'deployed'}}