Example #1
0
    def test_create_icap_object_missing_custom_headers(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        err = "The host parameter is not defined. Custom header configuration requires the 'referrer', 'host', " \
              "'user_agent' and 'h_from' values to be defined during CREATE operation when'enable' " \
              "parameter is set to 'True'."
        set_module_args(
            dict(name='fooicap',
                 devices=[
                     dict(ip='1.1.1.1', port=1344),
                     dict(ip='2.2.2.2', port=1348)
                 ],
                 headers=dict(enable='yes', referrer='foo_referrer')))

        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)

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

        assert str(res.exception) == err
Example #2
0
    def test_modify_icap_service_object(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        set_module_args(
            dict(name='foobar',
                 headers=dict(enable='no'),
                 enable_one_connect='no',
                 preview_length=1024,
                 service_down_action='drop',
                 allow_http10='yes'))

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

        results = mm.exec_module()
        assert results['changed'] is True
        assert results['headers'] == {'enable': False}
        assert results['preview_length'] == 1024
        assert results['allow_http10'] is True
        assert results['enable_one_connect'] is False
Example #3
0
    def test_modify_icap_service_object_dump_json(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        expected = load_fixture('sslo_icap_modify_generated.json')
        set_module_args(
            dict(name='foobar',
                 headers=dict(enable='no'),
                 enable_one_connect='no',
                 preview_length=1024,
                 service_down_action='drop',
                 allow_http10='yes',
                 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_service_icap.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
Example #4
0
    def test_create_icap_object_missing_devices(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        err = 'The devices parameter is not defined. Devices must be defined during CREATE operation.'
        set_module_args(dict(name='foobar'))

        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)

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

        assert str(res.exception) == err
Example #5
0
    def test_delete_icap_service_object_dump_json(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        expected = load_fixture('sslo_icap_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_service_icap.json')))

        results = mm.exec_module()

        assert results['changed'] is False
        assert results['json'] == expected
Example #6
0
    def test_delete_icap_service_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)

        # Override methods to force specific logic in the module to happen
        exists = dict(code=200,
                      contents=load_fixture('load_sslo_service_icap.json'))
        done = dict(code=200,
                    contents=load_fixture('reply_sslo_icap_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_icap_delete_start.json')))
        mm.client.get = Mock(side_effect=[exists, done])

        results = mm.exec_module()
        assert results['changed'] is True
Example #7
0
    def test_create_icap_service_object_dump_json(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        expected = load_fixture('sslo_icap_create_generated.json')
        set_module_args(
            dict(name='foobar',
                 ip_family='ipv4',
                 devices=[
                     dict(ip='1.1.1.1', port=1344),
                     dict(ip='2.2.2.2', port=1348)
                 ],
                 headers=dict(enable='yes',
                              referrer='foo_referrer',
                              host='foo_host',
                              user_agent='foo_ua',
                              h_from='foo_from'),
                 enable_one_connect='yes',
                 request_uri='/avscan',
                 response_uri='/avscan',
                 preview_length=2048,
                 service_down_action='ignore',
                 allow_http10='no',
                 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
Example #8
0
    def test_create_icap_service_object(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        set_module_args(
            dict(
                name='foobar',
                ip_family='ipv4',
                devices=[
                    dict(ip='1.1.1.1', port=1344),
                    dict(ip='2.2.2.2', port=1348)
                ],
                headers=dict(enable='yes',
                             referrer='foo_referrer',
                             host='foo_host',
                             user_agent='foo_ua',
                             h_from='foo_from'),
                enable_one_connect='yes',
                request_uri='/avscan',
                response_uri='/avscan',
                preview_length=2048,
                service_down_action='ignore',
                allow_http10='no',
            ))

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

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['allow_http10'] is False
        assert results['devices'] == [{
            'port': 1344,
            'ip': '1.1.1.1'
        }, {
            'port': 1348,
            'ip': '2.2.2.2'
        }]
        assert results['enable_one_connect'] is True
        assert results['headers'] == {
            'enable': True,
            'referrer': 'foo_referrer',
            'host': 'foo_host',
            'user_agent': 'foo_ua',
            'h_from': 'foo_from'
        }
        assert results['ip_family'] == 'ipv4'
        assert results['preview_length'] == 2048
        assert results[
            'request_uri'] == 'icap://${SERVER_IP}:${SERVER_PORT}/avscan'
        assert results[
            'response_uri'] == 'icap://${SERVER_IP}:${SERVER_PORT}/avscan'
        assert results['service_down_action'] == 'ignore'