def test_create_policy(self, *args):
        set_module_args(
            dict(name="foo",
                 description='foo description',
                 destinations=['dest1', 'dest2'],
                 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 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['description'] == 'foo description'
        assert results['destinations'] == ['/Common/dest1', '/Common/dest2']
    def test_update_settings(self, *args):
        set_module_args(dict(
            allow=['all'],
            banner='enabled',
            banner_text='asdf',
            inactivity_timeout='100',
            log_level='debug',
            login='******',
            port=1010,
            server='localhost',
            user='******',
            password='******'
        ))

        # Configure the parameters that would be returned by querying the
        # remote device
        current = ApiParameters(
            params=dict(
                allow=['172.27.1.1']
            )
        )

        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.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['allow'] == ['all']
    def test_update_interval_larger_than_existing_timeout(self, *args):
        set_module_args(
            dict(name='asdf',
                 interval=30,
                 partition='Common',
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        current = Parameters(params=load_fixture('load_ltm_monitor_http.json'))
        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(return_value=True)
        mm.read_current_from_device = Mock(return_value=current)
        mm.update_on_device = Mock(return_value=True)

        with pytest.raises(F5ModuleError) as ex:
            mm.exec_module()

        assert "must be less than" in str(ex.value)
    def test_command_with_commas(self, *args):
        set_module_args(
            dict(commands="""
              tmsh create /auth ldap system-auth {bind-dn uid=binduser,
              cn=users,dc=domain,dc=com bind-pw $ENCRYPTEDPW check-roles-group
              enabled search-base-dn cn=users,dc=domain,dc=com servers add {
              ldap.server.com } }
            """,
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))
        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode)
        m1 = V2Manager(module=module)
        m1.execute_on_device = Mock(return_value=['resp1', 'resp2'])

        mm = ModuleManager(module=module)
        mm.get_manager = Mock(return_value=m1)

        results = mm.exec_module()

        assert results['changed'] is True
        assert m1.execute_on_device.call_count == 2
Beispiel #5
0
    def test_update(self, *args):
        set_module_args(
            dict(enforced_policy='enforced1',
                 staged_policy='staged1',
                 service_policy='service1',
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

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

        current = ApiParameters(
            params=load_fixture('load_security_firewall_global_rules_1.json'))

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(module=module)
        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
Beispiel #6
0
    def test_update_issue_00522_as_list(self, *args):
        set_module_args(
            dict(ssl_cipher_suite=[
                'ECDHE-RSA-AES128-GCM-SHA256', 'ECDHE-RSA-AES256-GCM-SHA384'
            ],
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        current = Parameters(params=load_fixture('load_sys_httpd.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.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[
            'ssl_cipher_suite'] == 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384'
    def test_create_monitor(self, *args):
        set_module_args(
            dict(name='foo',
                 address='10.10.10.10',
                 service_port=80,
                 route_domain=20,
                 tsig_key='key1',
                 partition='Common',
                 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
Beispiel #8
0
    def test_absent_timezone(self, *args):
        set_module_args(
            dict(timezone='',
                 server='localhost',
                 user='******',
                 password='******',
                 state='absent'))

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

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            required_one_of=self.spec.required_one_of)
        mm = ModuleManager(module=module)

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

        results = mm.exec_module()
        assert results['changed'] is False
Beispiel #9
0
    def test_create(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        set_module_args(
            dict(name='foo',
                 parent='bar',
                 idle_timeout=500,
                 datagram_load_balancing=True,
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

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

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['idle_timeout'] == 500
    def test_create_service(self, *args):
        parameters = load_fixture(
            'create_iapp_service_parameters_f5_http.json')
        set_module_args(
            dict(name='foo',
                 template='f5.http',
                 parameters=parameters,
                 state='present',
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

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

        results = mm.exec_module()
        assert results['changed'] is True
Beispiel #11
0
    def test_create_vlan_untagged_interfaces(self, *args):
        set_module_args(
            dict(
                name='somevlan',
                untagged_interface=['2.1', '1.1'],
                server='localhost',
                password='******',
                user='******',
                partition='Common',
            ))

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

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['untagged_interfaces'] == ['1.1', '2.1']
Beispiel #12
0
    def test_update_expired_cert(self, *args):
        set_module_args(
            dict(days_valid=60,
                 provider=dict(server='localhost',
                               password='******',
                               user='******',
                               transport='cli',
                               server_port=22)))

        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)
        mm.expired = Mock(return_value=True)
        mm.update_certificate = Mock(return_value=True)
        mm.restart_daemon = Mock(return_value=True)
        mm.copy_files_to_trusted = Mock(return_value=True)

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['days_valid'] == 60
    def test_update_route_domain(self, *args):
        set_module_args(
            dict(name='foo',
                 route_domain=1,
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        current = ApiParameters(
            params=load_fixture('load_tm_auth_partition.json'))
        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(return_value=True)
        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
        assert results['route_domain'] == 1
Beispiel #14
0
    def test_ucs_installed(self, *args):
        set_module_args(
            dict(ucs="/root/bigip.localhost.localdomain.ucs",
                 server='localhost',
                 password='******',
                 user='******',
                 state='installed'))

        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.is_version_v1 = Mock(return_value=False)

        vm = V2Manager(module=module)
        vm.create_on_device = Mock(return_value=True)
        vm.exists = Mock(return_value=True)
        vm.install_on_device = Mock(return_value=True)

        results = vm.exec_module()

        assert results['changed'] is True
    def test_create_topology_region(self, *args):
        set_module_args(
            dict(name='foobar',
                 region_members=[
                     dict(country='Poland', negate=True),
                     dict(datacenter='bazcenter')
                 ],
                 partition='Common',
                 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(return_value=False)
        mm.create_on_device = Mock(return_value=True)

        results = mm.exec_module()

        assert results['changed'] is True
    def test_create_route_to_vlan(self, *args):
        set_module_args(
            dict(name='test-route',
                 state='present',
                 destination='10.10.10.10',
                 netmask='255.255.255.255',
                 vlan="test-vlan",
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            mutually_exclusive=self.spec.mutually_exclusive,
            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.create_on_device = Mock(return_value=True)
        results = mm.exec_module()

        assert results['changed'] is True
        assert results['vlan'] == '/Common/test-vlan'
    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
Beispiel #18
0
    def test_update_receive(self, *args):
        set_module_args(
            dict(name='foo',
                 receive='this is another receive string',
                 partition='Common',
                 server='localhost',
                 password='******',
                 user='******'))

        current = Parameters(params=load_fixture('load_ltm_monitor_tcp.json'))
        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(return_value=True)
        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
        assert results['receive'] == 'this is another receive string'
Beispiel #19
0
    def test_create(self, *args):
        set_module_args(
            dict(name='foo',
                 description='this is a description',
                 rules=['rule1', 'rule2', 'rule3'],
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

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

        results = mm.exec_module()

        assert results['changed'] is True
        assert 'rules' in results
        assert len(results['rules']) == 3
        assert results['description'] == 'this is a description'
Beispiel #20
0
    def test_create(self, *args):
        set_module_args(dict(
            name='foo',
            agent_type='UCD',
            community='public',
            cpu_coefficient='1.5',
            cpu_threshold='80',
            parent='/Common/snmp_dca',
            disk_coefficient='2.0',
            disk_threshold='90',
            memory_coefficient='1.0',
            memory_threshold='70',
            version='v1',
            interval=20,
            timeout=30,
            time_until_up=60,
            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
    def test_create(self, *args):
        set_module_args(
            dict(name='foo',
                 parent='/Common/dns',
                 query_name='foo',
                 interval=20,
                 timeout=30,
                 time_until_up=60,
                 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
    def test_update_LSN_pool(self, *args):
        set_module_args(
            dict(name='test_pool',
                 description='foobar',
                 mode='napt',
                 members=['15.15.15.0/25'],
                 backup_members='',
                 harpin_mode='yes',
                 route_advertisement='yes',
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))
        current = ApiParameters(
            params=load_fixture('load_cgnat_lsn_pool.json'))

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

        # Override methods in the specific type of manager
        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['description'] == 'foobar'
        assert results['mode'] == 'napt'
        assert results['members'] == ['15.15.15.0/25']
        assert results['backup_members'] == []
        assert results['harpin_mode'] == 'yes'
        assert results['route_advertisement'] == 'yes'
    def test_update_generic_peer(self, *args):
        set_module_args(dict(
            name='some',
            dst_address="blackhole",
            peer_selection_mode='ratio',
            peers=['/Common/example'],
            provider=dict(
                server='localhost',
                password='******',
                user='******'
            )
        ))

        current = ApiParameters(params=load_fixture('load_generic_route.json'))

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

        # Override methods in the specific type of manager
        gm = GenericModuleManager(module=module)
        gm.exists = Mock(return_value=True)
        gm.update_on_device = Mock(return_value=True)
        gm.read_current_from_device = Mock(return_value=current)

        mm = ModuleManager(module=module)
        mm.version_less_than_14 = Mock(return_value=False)
        mm.get_manager = Mock(return_value=gm)

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['dst_address'] == 'blackhole'
        assert results['peer_selection_mode'] == 'ratio'
        assert results['peers'] == ['/Common/example']
Beispiel #24
0
    def test_create(self, *args):
        set_module_args(
            dict(lines=[
                'bgp graceful-restart restart-time 120',
                'redistribute kernel route-map rhi',
                'neighbor 10.10.10.11 remote-as 65000',
                'neighbor 10.10.10.11 fall-over bfd',
                'neighbor 10.10.10.11 remote-as 65000',
                'neighbor 10.10.10.11 fall-over bfd'
            ],
                 parents='router bgp 64664',
                 before='bfd slow-timer 2000',
                 match='exact',
                 server='localhost',
                 password='******',
                 user='******'))

        current = load_fixture('load_imish_output_1.json')
        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            mutually_exclusive=self.spec.mutually_exclusive,
            required_if=self.spec.required_if,
            add_file_common_args=self.spec.add_file_common_args)

        # Override methods in the specific type of manager
        mm = ModuleManager(module=module)
        mm.read_current_from_device = Mock(
            return_value=current['commandResult'])
        mm.upload_file_to_device = Mock(return_value=True)
        mm.load_config_on_device = Mock(return_value=True)
        mm.remove_uploaded_file_from_device = Mock(return_value=True)

        results = mm.exec_module()

        assert results['changed'] is True
Beispiel #25
0
    def test_get_facts(self, *args):
        set_module_args(
            dict(gather_subset=['system-info'],
                 password='******',
                 server='localhost',
                 user='******'))

        fixture1 = load_fixture('load_shared_system_setup_1.json')

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

        tm = SystemInfoFactManager(module=module)
        tm.read_collection_from_device = Mock(return_value=fixture1)

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

        results = mm.exec_module()

        assert results['changed'] is True
        assert 'system_info' in results
    def test_create_monitor(self, *args):
        set_module_args(
            dict(name='foo',
                 ip='10.10.10.10',
                 port=80,
                 interval=20,
                 timeout=30,
                 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)
        mm.module_provisioned = Mock(return_value=True)

        results = mm.exec_module()

        assert results['changed'] is True
Beispiel #27
0
    def test_create(self, *args):
        set_module_args(dict(
            name='foo',
            description='my description',
            provider=dict(
                server='localhost',
                password='******',
                user='******'
            )
        ))

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

        mm = ModuleManager(module=module)
        mm.create_on_device = Mock(return_value=True)
        mm.exists = Mock(return_value=False)

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['description'] == 'my description'
Beispiel #28
0
    def test_create_blackhole(self, *args):
        set_module_args(
            dict(key='provision.cpu.afm',
                 value='1',
                 state='present',
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        # Configure the parameters that would be returned by querying the
        # remote device
        current = Parameters(
            dict(
                kind="tm:sys:db:dbstate",
                name="provision.cpu.afm",
                fullPath="provision.cpu.afm",
                generation=1,
                selfLink=
                "https://localhost/mgmt/tm/sys/db/provision.cpu.afm?ver=11.6.1",
                defaultValue="0",
                scfConfig="false",
                value="0",
                valueRange="integer min:0 max:100"))

        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_update_time_until_up(self, *args):
        set_module_args(
            dict(name='asdf',
                 time_until_up=300,
                 partition='Common',
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        current = Parameters(params=load_fixture('load_ltm_monitor_http.json'))
        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(return_value=True)
        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
        assert results['time_until_up'] == 300
    def test_update_ntp_servers(self, *args):
        ntp = ['10.1.1.1', '10.1.1.2']
        set_module_args(
            dict(ntp_servers=ntp,
                 server='localhost',
                 user='******',
                 password='******'))

        # Configure the parameters that would be returned by querying the
        # remote device
        current = Parameters(params=load_fixture('load_ntp.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.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['ntp_servers'] == ntp