Пример #1
0
    def test_create_snat_translation(self, *args):
        set_module_args(
            dict(name='my-snat-translation',
                 address='1.1.1.1',
                 arp='yes',
                 connection_limit=300,
                 description='My description',
                 ip_idle_timeout='50',
                 state='present',
                 tcp_idle_timeout='20',
                 udp_idle_timeout='100',
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        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)

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['address'] == '1.1.1.1'
        assert results['arp'] == 'yes'
        assert results['connection_limit'] == 300
        assert results['description'] == 'My description'
        assert results['ip_idle_timeout'] == '50'
        assert results['tcp_idle_timeout'] == '20'
        assert results['udp_idle_timeout'] == '100'
Пример #2
0
    def test_update_snat_translation(self, *args):
        set_module_args(dict(
            name='my-snat-translation',
            address='1.1.1.1',
            arp='yes',
            connection_limit=300,
            description='',
            ip_idle_timeout='500',
            state='disabled',
            tcp_idle_timeout='indefinite',
            traffic_group='traffic-group-1',
            udp_idle_timeout='indefinite',
            provider=dict(
                server='localhost',
                password='******',
                user='******'
            )
        ))
        current = ApiParameters(params=load_fixture('load_ltm_snat_translation_default.json'))

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

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['arp'] == 'yes'
        assert results['connection_limit'] == 300
        assert results['description'] == ''
        assert results['ip_idle_timeout'] == '500'
        assert results['tcp_idle_timeout'] == 'indefinite'
        assert results['udp_idle_timeout'] == 'indefinite'