Ejemplo n.º 1
0
    def test_create(self, *args):
        set_module_args(
            dict(license_key='XXXX-XXXX-XXXX-XXXX-XXXX',
                 accept_eula=True,
                 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)
        mm.wait_for_initial_license_activation = Mock(return_value=True)
        mm.wait_for_utility_license_activation = Mock(return_value=True)

        results = mm.exec_module()

        assert results['changed'] is True
    def test_create(self, *args):
        # Configure the arguments that would be sent to the Ansible module
        set_module_args(
            dict(name='foo',
                 match_across_virtuals='yes',
                 parent='bar',
                 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['match_across_virtuals'] == 'yes'
    def test_create(self, *args):
        set_module_args(
            dict(regkey_pool='foo',
                 license_key='XXXX-XXXX-XXXX-XXXX-XXXX',
                 accept_eula=True,
                 description='this is a 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)

        # 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['description'] == 'this is a description'
Ejemplo n.º 4
0
    def test_create_monitor(self, *args):
        set_module_args(
            dict(name='foo',
                 smtp_server='1.1.1.1',
                 smtp_server_port='25',
                 smtp_server_username='******',
                 smtp_server_password='******',
                 local_host_name='smtp.mydomain.com',
                 encryption='tls',
                 update_password='******',
                 from_address='*****@*****.**',
                 authentication=True,
                 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
        assert results['encryption'] == 'tls'
        assert results['smtp_server'] == '1.1.1.1'
        assert results['smtp_server_port'] == 25
        assert results['local_host_name'] == 'smtp.mydomain.com'
        assert results['authentication'] is True
        assert results['from_address'] == '*****@*****.**'
        assert 'smtp_server_username' not in results
        assert 'smtp_server_password' not in results
Ejemplo n.º 5
0
    def test_create(self, *args):
        set_module_args(
            dict(name='foo',
                 description='my description',
                 service_environment='bar',
                 servers=[
                     dict(address='1.2.3.4', port=8080),
                     dict(address='5.6.7.8', port=8000)
                 ],
                 inbound_virtual=dict(address='2.2.2.2',
                                      netmask='255.255.255.255',
                                      port=80),
                 redirect_virtual=dict(address='3.3.3.3',
                                       netmask='255.255.255.255',
                                       port=80),
                 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.check_bigiq_version = Mock(return_value=True)
        mm.has_no_service_environment = Mock(return_value=False)
        mm.wait_for_apply_template_task = Mock(return_value=True)

        mm.create_on_device = Mock(return_value=True)
        mm.exists = Mock(side_effect=[False, True])

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['description'] == 'my description'
    def test_update_settings(self, *args):
        set_module_args(dict(
            config_sync_ip="10.1.30.1",
            mirror_primary_address="10.1.30.1",
            unicast_failover=[
                dict(
                    address="10.1.30.1"
                )
            ],
            provider=dict(
                server='localhost',
                password='******',
                user='******'
            )
        ))

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

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            required_together=self.spec.required_together
        )
        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['config_sync_ip'] == '10.1.30.1'
        assert results['mirror_primary_address'] == '10.1.30.1'
        assert len(results.keys()) == 4
Ejemplo n.º 7
0
    def test_update_ftp_profile(self, *args):
        set_module_args(dict(
            name='foo',
            description='my description',
            allow_ftps=False,
            inherit_parent_profile=False,
            port=2048,
            log_profile='alg_profile',
            log_publisher='baz_publish',
            provider=dict(
                server='localhost',
                password='******',
                user='******'
            )
        ))

        current = ApiParameters(params=load_fixture('load_ltm_profile_ftp.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.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'] == 'my description'
        assert results['allow_ftps'] == 'no'
        assert results['inherit_parent_profile'] == 'no'
        assert results['port'] == 2048
        assert results['log_profile'] == '/Common/alg_profile'
        assert results['log_publisher'] == '/Common/baz_publish'
    def test_create_wideip_with_pool_idempotent(self, *args):
        set_module_args(
            dict(name='foo.bar.com',
                 lb_method='round-robin',
                 type='a',
                 pools=[
                     dict(
                         name='baz',
                         ratio=10,
                     ),
                     dict(name='maz', ratio=10, order=1),
                     dict(name='vaz', ratio=11, order=2)
                 ],
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        current = ApiParameters(
            params=load_fixture('load_gtm_wide_ip_with_pools.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
        tm = TypedManager(module=module, params=module.params)
        tm.exists = Mock(return_value=True)
        tm.read_current_from_device = Mock(return_value=current)
        tm.version_is_less_than_12 = Mock(return_value=False)

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

        results = mm.exec_module()

        assert results['changed'] is False
Ejemplo n.º 9
0
    def test_update_asm_dos_profile(self, *args):
        set_module_args(dict(
            profile='test',
            heavy_urls=dict(
                latency_threshold=3000,
                exclude=['/exclude1.html', '/exclude2.html'],
                include=[dict(url='include1.html', threshold='auto'),
                         dict(url='include2.html', threshold='2000')]
            ),
            provider=dict(
                server='localhost',
                password='******',
                user='******'
            )
        ))

        current = ApiParameters(params=load_fixture('load_asm_dos.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.update_on_device = Mock(return_value=True)
        mm.read_current_from_device = Mock(return_value=current)
        mm.version_less_than_13_1 = Mock(return_value=False)

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['heavy_urls'] == dict(latency_threshold=3000, exclude=['/exclude1.html', '/exclude2.html'],
                                             include=[dict(url='/include1.html', threshold='auto'),
                                                      dict(url='/include2.html', threshold='2000')]
                                             )
Ejemplo n.º 10
0
    def test_create_trap(self, *args):
        set_module_args(dict(
            name='foo',
            snmp_version='1',
            community='public',
            destination='10.10.10.10',
            port=1000,
            network='other',
            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
        m0 = ModuleManager(module=module)
        m0.is_version_without_network = Mock(return_value=False)
        m0.is_version_with_default_network = Mock(return_value=True)

        patches = dict(
            create_on_device=DEFAULT,
            exists=DEFAULT
        )
        with patch.multiple(V2Manager, **patches) as mo:
            mo['create_on_device'].side_effect = Mock(return_value=True)
            mo['exists'].side_effect = Mock(return_value=False)
            results = m0.exec_module()

        assert results['changed'] is True
        assert results['port'] == 1000
        assert results['snmp_version'] == '1'
    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_create_wideip(self, *args):
        set_module_args(
            dict(name='foo.baz.bar',
                 lb_method='round-robin',
                 type='a',
                 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
        assert results['name'] == 'foo.baz.bar'
        assert results['state'] == 'present'
        assert results['lb_method'] == 'round-robin'
Ejemplo n.º 13
0
    def test_update_agent_status_traps(self, *args):
        set_module_args(
            dict(agent_status_traps='enabled',
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        # Configure the parameters that would be returned by querying the
        # remote device
        current = ApiParameters(params=dict(agent_status_traps='disabled'))

        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['agent_status_traps'] == 'enabled'
    def test_update_interval_larger_than_existing_timeout(self, *args):
        set_module_args(
            dict(name='foo',
                 interval=30,
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        current = Parameters(
            params=load_fixture('load_ltm_monitor_tcp_half_open.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)
Ejemplo n.º 15
0
    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
Ejemplo n.º 16
0
    def test_delete_virtual_address(self, *args):
        set_module_args(dict(
            state='absent',
            address='1.1.1.1',
            provider=dict(
                server='localhost',
                password='******',
                user='******'
            )
        ))

        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.exists = Mock(side_effect=[True, False])
        mm.remove_from_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',
            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
Ejemplo n.º 18
0
    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_absent_timezone(self, *args):
        set_module_args(
            dict(timezone='',
                 state='absent',
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        # 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
    def test_create(self, *args):
        set_module_args(dict(
            name='foo',
            interfaces=[
                '1.3', '1.1'
            ],
            link_selection_policy='auto',
            frame_distribution_hash='destination-mac',
            lacp_enabled=True,
            lacp_mode='active',
            lacp_timeout='long',
            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.create_on_device = Mock(return_value=True)
        mm.exists = Mock(return_value=False)

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['link_selection_policy'] == 'auto'
        assert results['frame_distribution_hash'] == 'destination-mac'
        assert results['lacp_enabled'] is True
        assert results['lacp_mode'] == 'active'
        assert results['lacp_timeout'] == 'long'
Ejemplo n.º 21
0
    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_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
Ejemplo n.º 23
0
    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']
Ejemplo n.º 24
0
    def test_create_node(self, *args):
        set_module_args(
            dict(host='10.20.30.40',
                 name='mytestserver',
                 monitors=['/Common/icmp'],
                 partition='Common',
                 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(side_effect=[False, True])
        mm.create_on_device = Mock(return_value=True)

        results = mm.exec_module()

        assert results['changed'] is True
    def test_create_monitor(self, *args):
        set_module_args(
            dict(name='foo',
                 ip='10.10.10.10',
                 port=80,
                 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
Ejemplo n.º 26
0
    def test_update(self, *args):
        set_module_args(
            dict(arp_log_level='debug',
                 layer4_log_level='debug',
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        # Configure the parameters that would be returned by querying the
        # remote device
        current = ApiParameters(params=load_fixture('load_tmm_log.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_update_time_until_up(self, *args):
        set_module_args(
            dict(name='foo',
                 time_until_up=300,
                 provider=dict(server='localhost',
                               password='******',
                               user='******')))

        current = Parameters(
            params=load_fixture('load_ltm_monitor_tcp_half_open.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_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',
                 provider=dict(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
Ejemplo n.º 29
0
    def test_modify_profiles(self, *args):
        set_module_args(
            dict(name="my-virtual-server",
                 partition="Common",
                 profiles=['http', 'clientssl'],
                 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_ltm_virtual_2.json'))
        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            mutually_exclusive=self.spec.mutually_exclusive)

        # Override methods to force specific logic in the module to happen
        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 len(results['profiles']) == 2
        assert 'name' in results['profiles'][0]
        assert 'context' in results['profiles'][0]
        assert results['profiles'][0]['name'] == 'http'
        assert results['profiles'][0]['context'] == 'all'
        assert 'name' in results['profiles'][1]
        assert 'context' in results['profiles'][1]
        assert results['profiles'][1]['name'] == 'clientssl'
        assert results['profiles'][1]['context'] == 'clientside'
    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'