예제 #1
0
    def test_update_user_password_with_pass(self, *args):
        set_module_args(dict(
            username_credential='someuser',
            password_credential='testpass',
            provider=dict(
                server='localhost',
                password='******',
                user='******'
            )
        ))

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

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

        # Override methods to force specific logic in the module to happen
        pm = PartitionedManager(module=module, params=module.params)
        pm.exists = Mock(return_value=True)
        pm.update_on_device = Mock(return_value=True)
        pm.read_current_from_device = Mock(return_value=current)

        mm = ModuleManager(module=module)
        mm.is_version_less_than_13 = Mock(return_value=False)
        mm.get_manager = Mock(return_value=pm)

        results = mm.exec_module()

        assert results['changed'] is True
예제 #2
0
    def test_api_parameters(self):
        access = [{'name': 'Common', 'role': 'guest'}]
        args = dict(
            name='someuser',
            description='Fake Person',
            partitionAccess=access,
            shell='none'
        )

        p = Parameters(params=args)
        assert p.name == 'someuser'
        assert p.full_name == 'Fake Person'
        assert p.partition_access == access
        assert p.shell == 'none'
예제 #3
0
    def test_module_parameters(self):
        access = [{'name': 'Common', 'role': 'guest'}]
        args = dict(
            username_credential='someuser',
            password_credential='testpass',
            full_name='Fake Person',
            partition_access=access,
            update_password='******'
        )

        p = Parameters(params=args)
        assert p.username_credential == 'someuser'
        assert p.password_credential == 'testpass'
        assert p.full_name == 'Fake Person'
        assert p.partition_access == access
        assert p.update_password == 'always'
예제 #4
0
    def test_update_user_shell_to_bash_mutliple_roles(self, *args):
        set_module_args(dict(
            username_credential='someuser',
            shell='bash',
            provider=dict(
                server='localhost',
                password='******',
                user='******'
            )
        ))

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

        # Configure the parameters that would be returned by querying the
        # remote device
        access = [
            {'name': 'Common', 'role': 'operator'},
            {'name': 'all', 'role': 'guest'}
        ]
        current = Parameters(
            params=dict(
                user='******',
                shell='tmsh',
                partition_access=access
            )
        )

        # Override methods to force specific logic in the module to happen
        upm = UnpartitionedManager(module=module, params=module.params)
        upm.exists = Mock(return_value=True)
        upm.update_on_device = Mock(return_value=True)
        upm.read_current_from_device = Mock(return_value=current)

        mm = ModuleManager(module=module)
        mm.is_version_less_than_13 = Mock(return_value=True)
        mm.get_manager = Mock(return_value=upm)

        msg = "Shell access is only available to 'admin' or " \
              "'resource-admin' roles."

        with pytest.raises(F5ModuleError) as ex:
            mm.exec_module()
        assert str(ex.value) == msg
예제 #5
0
    def test_update_user_shell_to_bash(self, *args):
        set_module_args(dict(
            username_credential='someuser',
            shell='bash',
            provider=dict(
                server='localhost',
                password='******',
                user='******'
            )
        ))

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

        # Configure the parameters that would be returned by querying the
        # remote device
        access = [{'name': 'all', 'role': 'admin'}]
        current = Parameters(
            params=dict(
                user='******',
                shell='tmsh',
                partition_access=access
            )
        )

        # Override methods to force specific logic in the module to happen
        upm = UnpartitionedManager(module=module, params=module.params)
        upm.exists = Mock(return_value=True)
        upm.update_on_device = Mock(return_value=True)
        upm.read_current_from_device = Mock(return_value=current)

        mm = ModuleManager(module=module)
        mm.is_version_less_than_13 = Mock(return_value=True)
        mm.get_manager = Mock(return_value=upm)

        results = mm.exec_module()

        assert results['changed'] is True
        assert results['shell'] == 'bash'