Exemplo n.º 1
0
    def test_deactivate_policy_exists_inactive(self, *args):
        set_module_args(
            dict(name='fake_policy',
                 state='present',
                 server='localhost',
                 password='******',
                 user='******',
                 active='no'))

        current = V1Parameters(
            params=load_fixture('load_asm_policy_inactive.json'))
        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
        v1 = V1Manager(module=module)
        v1.exists = Mock(return_value=True)
        v1.read_current_from_device = Mock(return_value=current)

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(module=module)
        mm.version_is_less_than_13 = Mock(return_value=False)
        mm.get_manager = Mock(return_value=v1)

        results = mm.exec_module()

        assert results['changed'] is False
Exemplo n.º 2
0
    def test_activate_policy_raises(self, *args):
        set_module_args(
            dict(
                name='fake_policy',
                state='present',
                active='yes',
                server='localhost',
                password='******',
                user='******',
            ))

        current = V1Parameters(
            params=load_fixture('load_asm_policy_inactive.json'))
        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode)

        msg = 'Apply policy task failed.'
        # Override methods to force specific logic in the module to happen
        v1 = V1Manager(module=module)
        v1.exists = Mock(return_value=True)
        v1.wait_for_task = Mock(return_value=False)
        v1.update_on_device = Mock(return_value=True)
        v1.read_current_from_device = Mock(return_value=current)
        v1.apply_on_device = Mock(return_value=True)

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(module=module)
        mm.version_is_less_than_13 = Mock(return_value=False)
        mm.get_manager = Mock(return_value=v1)

        with pytest.raises(F5ModuleError) as err:
            mm.exec_module()
        assert str(err.value) == msg
Exemplo n.º 3
0
    def test_create_by_name(self, *args):
        set_module_args(dict(
            name='fake_policy',
            state='present',
            server='localhost',
            password='******',
            user='******',
        ))

        current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode
        )

        v1 = V1Manager(module=module)
        v1.exists = Mock(return_value=False)
        v1.import_to_device = Mock(return_value=True)
        v1.wait_for_task = Mock(side_effect=[True, True])
        v1.create_on_device = Mock(return_value=True)
        v1.create_blank = Mock(return_value=True)
        v1.read_current_from_device = Mock(return_value=current)
        v1.apply_on_device = Mock(return_value=True)
        v1._file_is_missing = Mock(return_value=False)

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(module=module)
        mm.version_is_less_than_13 = Mock(return_value=False)
        mm.get_manager = Mock(return_value=v1)

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['name'] == 'fake_policy'
        assert results['active'] is False
Exemplo n.º 4
0
    def test_module_parameters_template(self):
        args = dict(name='fake_policy',
                    state='present',
                    template='LotusDomino 6.5 (http)')

        p = V1Parameters(params=args)
        assert p.name == 'fake_policy'
        assert p.state == 'present'
        assert p.template == 'POLICY_TEMPLATE_LOTUSDOMINO_6_5_HTTP'
Exemplo n.º 5
0
    def test_module_parameters(self):
        args = dict(name='fake_policy',
                    state='present',
                    file='/var/fake/fake.xml')

        p = V1Parameters(params=args)
        assert p.name == 'fake_policy'
        assert p.state == 'present'
        assert p.file == '/var/fake/fake.xml'