def test_modify_authentication_object_dump_json(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        expected = load_fixture('sslo_auth_modify_generated.json')
        set_module_args(
            dict(name='foobar',
                 ocsp=dict(
                     vlans=['/Common/client-vlan', '/Common/dlp-vlan'],
                     ssl_profile='fake_ssl',
                 ),
                 dump_json=True))

        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_config_auth.json'))
        # Override methods to force specific logic in the module to happen
        mm.client.get = Mock(side_effect=[exists, exists])

        results = mm.exec_module()

        assert results['changed'] is False
        assert results['json'] == expected
    def test_modify_authentication_object_failure(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        err = 'MODIFY operation error: 1841b2a3-5279-4472-b013-b80e8e771538 : ' \
              '[OrchestratorConfigProcessor] Deployment failed for Error: [HAAwareICRDeployProcessor] ' \
              'Error: transaction failed:01020036:3: ' \
              'The requested profile (/Common/ssloT_fake_ssl.app/ssloT_fake_ssl-cssl-vht) was not found.'
        set_module_args(
            dict(
                name='foobar',
                ocsp=dict(
                    vlans=['/Common/client-vlan', '/Common/dlp-vlan'],
                    ssl_profile='fake_ssl',
                ),
            ))

        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_config_auth.json'))
        error = dict(code=200,
                     contents=load_fixture(
                         'reply_sslo_auth_modify_failure_test_error.json'))
        # Override methods to force specific logic in the module to happen
        mm.client.post = Mock(return_value=dict(
            code=200,
            contents=load_fixture(
                'reply_sslo_auth_modify_failure_test_start.json')))
        mm.client.get = Mock(side_effect=[exists, exists, error])
        mm.client.delete = Mock(return_value=dict(
            code=200,
            contents=load_fixture(
                'reply_sslo_auth_failed_operation_delete.json')))

        with self.assertRaises(F5ModuleError) as res:
            mm.exec_module()

        assert str(res.exception) == err
        assert mm.client.delete.call_count == 1
        assert mm.client.delete.call_args[0][
            0] == '/mgmt/shared/iapp/blocks/1841b2a3-5279-4472-b013-b80e8e771538'
    def test_delete_authentication_object_dump_json(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        expected = load_fixture('sslo_auth_delete_generated.json')
        set_module_args(dict(name='foobar', state='absent', dump_json=True))

        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.client.get = Mock(return_value=dict(
            code=200, contents=load_fixture('load_sslo_config_auth.json')))

        results = mm.exec_module()

        assert results['changed'] is False
        assert results['json'] == expected
    def test_delete_authentication_object(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        set_module_args(dict(name='foobar', state='absent'), )

        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_config_auth.json'))
        done = dict(code=200,
                    contents=load_fixture('reply_sslo_auth_delete_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_auth_delete_start.json')))
        mm.client.get = Mock(side_effect=[exists, done])

        results = mm.exec_module()
        assert results['changed'] is True
    def test_create_authentication_object(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        set_module_args(
            dict(
                name='foobar',
                ocsp=dict(fqdn='baz.bar.net',
                          dest='192.168.1.1/32',
                          ssl_profile='fake_ssl_1',
                          vlans=['/Common/vlan1', '/Common/vlan2']),
            ))

        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_auth_create_start.json')))
        mm.client.get = Mock(return_value=dict(
            code=200,
            contents=load_fixture('reply_sslo_auth_create_done.json')))

        results = mm.exec_module()
        assert results['changed'] is True
        assert results['ocsp']['fqdn'] == 'baz.bar.net'
        assert results['ocsp']['dest'] == '192.168.1.1%0/32'
        assert results['ocsp']['ssl_profile'] == 'fake_ssl_1'
        assert results['ocsp']['vlans'] == [{
            'name': '/Common/vlan1',
            'value': '/Common/vlan1'
        }, {
            'name': '/Common/vlan2',
            'value': '/Common/vlan2'
        }]
    def test_modify_authentication_object(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        set_module_args(
            dict(
                name='foobar',
                ocsp=dict(
                    vlans=['/Common/client-vlan', '/Common/dlp-vlan'],
                    ssl_profile='fake_ssl',
                ),
            ))

        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_config_auth.json'))
        done = dict(code=200,
                    contents=load_fixture('reply_sslo_auth_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_auth_modify_start.json')))
        mm.client.get = Mock(side_effect=[exists, exists, done])

        results = mm.exec_module()
        assert results['changed'] is True
        assert results['ocsp']['ssl_profile'] == 'fake_ssl'
        assert results['ocsp']['vlans'] == [{
            'name': '/Common/client-vlan',
            'value': '/Common/client-vlan'
        }, {
            'name': '/Common/dlp-vlan',
            'value': '/Common/dlp-vlan'
        }]
    def test_create_authentication_object_dump_json(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        expected = load_fixture('sslo_auth_create_generated.json')
        set_module_args(
            dict(name='foobar',
                 ocsp=dict(fqdn='baz.bar.net',
                           dest='192.168.1.1/32',
                           ssl_profile='fake_ssl_1',
                           vlans=['/Common/vlan1', '/Common/vlan2']),
                 dump_json=True))

        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)

        results = mm.exec_module()

        assert results['changed'] is False
        assert results['json'] == expected