示例#1
0
    def test_create(self, *args):
        set_module_args(
            dict(name='mysqdb',
                 parent='/Common/mysql',
                 interval=10,
                 timeout=30,
                 time_until_up=5,
                 target_username='******',
                 send='SELECT * from v$instance1',
                 database='instance1',
                 recv='OPEN',
                 recv_column='1',
                 recv_row='1',
                 count=10,
                 manual_resume=True,
                 debug=True,
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        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.exists = Mock(side_effect=[False, True])
        mm.create_on_device = Mock(return_value=True)

        results = mm.exec_module()

        assert results['changed'] is True
示例#2
0
    def test_set_asm_setting(self, *args):
        set_module_args(dict(
            name='long_request_buffer_size',
            value='30',
            state='present',
            provider=dict(
                server='localhost',
                password='******',
                user='******'
            )
        ))

        # Configure the parameters that would be returned by querying the
        # remote device
        current = ApiParameters(params=load_fixture('load_asm_settings.json'))

        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.read_current_from_device = Mock(return_value=current)
        mm.update_on_device = Mock(return_value=True)

        results = mm.exec_module()
        assert results['changed'] is True
    def test_create(self, *args):
        set_module_args(dict(
            name='foo',
            ip='10.10.10.10',
            description='foobar',
            port=1812,
            timeout=5,
            secret='secret1',
            state='present',
            provider=dict(
                password='******',
                server='localhost',
                user='******'
            )
        ))

        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)
        mm.exists = Mock(return_value=False)
        mm.create_on_device = Mock(return_value=True)

        results = mm.exec_module()
        assert results['changed'] is True
        assert results['ip'] == '10.10.10.10'
        assert results['port'] == 1812
        assert results['timeout'] == 5
        assert results['description'] == 'foobar'
示例#4
0
    def test_disable_listener(self, *args):
        set_module_args(dict(
            name='test-dns-listener',
            state='disabled',
            address='192.10.0.2',
            provider=dict(
                server='localhost',
                password='******',
                user='******'
            )
        ))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode
        )

        current = ApiParameters(
            dict(
                agent_status_traps='disabled'
            )
        )

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(module=module)
        mm.exists = Mock(return_value=True)
        mm.update_on_device = Mock(return_value=True)
        mm.read_current_from_device = Mock(return_value=current)
        results = mm.exec_module()

        assert results['changed'] is True
示例#5
0
    def test_create(self, *args):
        set_module_args(dict(
            servers=['foo1', 'foo2'],
            retries=5,
            service_type='login',
            accounting_bug=False,
            fallback_to_local=True,
            use_for_auth=True,
            state='present',
            provider=dict(
                password='******',
                server='localhost',
                user='******'
            )
        ))

        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)
        mm.exists = Mock(return_value=False)
        mm.create_on_device = Mock(return_value=True)
        mm.update_auth_source_on_device = Mock(return_value=True)
        mm.update_fallback_on_device = Mock(return_value=True)

        results = mm.exec_module()
        assert results['changed'] is True
        assert '/Common/foo1' and '/Common/foo2' in results['servers']
        assert results['retries'] == 5
        assert results['accounting_bug'] == 'disabled'
        assert results['service_type'] == 'login'
        assert results['fallback_to_local'] == 'yes'
示例#6
0
    def test_update(self, *args):
        set_module_args(dict(
            name='test-dns-listener',
            address='10.0.1.0',
            mask='255.255.255.0',
            port=53,
            advertise='no',
            state='present',
            description='this is description',
            ip_protocol='tcp',
            translate_address='yes',
            translate_port='no',
            enabled_vlans=[
                '/Common/vlan1',
                '/Common/vlan2'
            ],
            irules=[
                '/Common/rule1',
                '/Common/rule2'
            ],
            provider=dict(
                server='localhost',
                password='******',
                user='******'
            )
        ))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode
        )

        current = ApiParameters(
            dict(
                agent_status_traps='disabled'
            )
        )

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(module=module)
        mm.exists = Mock(return_value=True)
        mm.update_on_device = Mock(return_value=True)
        mm.read_current_from_device = Mock(return_value=current)
        results = mm.exec_module()

        assert results['changed'] is True
        assert results['address'] == '10.0.1.0'
        assert results['port'] == 53
        assert results['mask'] == '255.255.255.0'
        assert results['advertise'] == 'no'
        assert results['ip_protocol'] == 'tcp'
        assert results['description'] == 'this is description'
        assert results['translate_address'] == 'enabled'
        assert results['translate_port'] == 'disabled'
        assert results['enabled_vlans'][0] == '/Common/vlan1' and results['vlans'][1] == '/Common/vlan2'
        assert results['irules'][0] == '/Common/rule1' and results['irules'][1] == '/Common/rule2'
示例#7
0
    def test_disabled_vlans(self, *args):
        set_module_args(dict(
            name='test-dns-listener',
            address='10.0.1.0',
            mask='255.255.255.0',
            port=53,
            advertise='no',
            state='present',
            description='this is description',
            ip_protocol='tcp',
            translate_address='yes',
            translate_port='no',
            disabled_vlans='all',
            provider=dict(
                server='localhost',
                password='******',
                user='******'
            )
        ))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode
        )

        current = ApiParameters(
            dict(
                agent_status_traps='disabled'
            )
        )

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(module=module)
        mm.exists = Mock(return_value=True)
        mm.update_on_device = Mock(return_value=True)
        mm.read_current_from_device = Mock(return_value=current)

        with pytest.raises(F5ModuleError) as ex:
            mm.exec_module()
        assert 'You cannot disable all VLANs. You must name them individually.' in str(ex.value)
    def test_create(self, *args):
        set_module_args(dict(
            name='ssl_csr_1',
            common_name='ssl_csr_1',
            key_name='ssl_key_1',
            dest='/tmp/ssl_csr_1',
            force=True,
            state='present',
            provider=dict(
                server='localhost',
                password='******',
                user='******'
            )
        ))

        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.version_is_less_than_14 = Mock(return_value=False)
        mm.exists = Mock(return_value=False)
        mm.file_exists = Mock(return_value=False)
        mm.create_on_device = Mock(return_value=True)
        mm._move_csr_to_download = Mock(return_value=True)
        mm._delete_csr = Mock(return_value=True)
        mm._download_file = Mock(return_value=True)
        mm.remove_from_device = Mock(return_value=True)

        with patch('os.path.exists') as mo:
            mo.return_value = True
            results = mm.exec_module()

        assert results['changed'] is True