def test_create_user_shell_not_permitted_raises(self, *args):
        access = [{'name': 'Common', 'role': 'guest'}]
        set_module_args(
            dict(username_credential='someuser',
                 password_credential='testpass',
                 partition_access=access,
                 update_password='******',
                 password='******',
                 server='localhost',
                 user='******',
                 shell='bash'))

        client = AnsibleF5Client(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            f5_product_name=self.spec.f5_product_name)

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(client)
        mm.is_version_less_than_13 = Mock(return_value=True)

        upm = UnparitionedManager(client)
        upm.create_on_device = Mock(return_value=True)
        upm.exists = Mock(return_value=False)

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

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

        client = AnsibleF5Client(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            f5_product_name=self.spec.f5_product_name)

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

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(client)
        mm.is_version_less_than_13 = Mock(return_value=True)

        upm = UnparitionedManager(client)
        upm.exists = Mock(return_value=True)
        upm.update_on_device = Mock(return_value=True)
        upm.read_current_from_device = Mock(return_value=current)

        results = upm.exec_module()

        assert results['changed'] is True
        assert results['shell'] == 'bash'
    def test_create_user_partition_access_raises(self, *args):
        set_module_args(
            dict(username_credential='someuser',
                 password='******',
                 server='localhost',
                 user='******'))

        client = AnsibleF5Client(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            f5_product_name=self.spec.f5_product_name)

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(client)
        mm.is_version_less_than_13 = Mock(return_value=True)

        upm = UnparitionedManager(client)
        upm.create_on_device = Mock(return_value=True)
        upm.exists = Mock(return_value=False)

        msg = "The 'partition_access' option " \
              "is required when creating a resource."

        with pytest.raises(F5ModuleError) as ex:
            upm.exec_module()
        assert str(ex.value) == msg
    def test_create_user_shell_bash(self, *args):
        access = [{'name': 'all', 'role': 'admin'}]
        set_module_args(
            dict(username_credential='someuser',
                 password_credential='testpass',
                 partition_access=access,
                 password='******',
                 server='localhost',
                 update_password='******',
                 user='******',
                 shell='bash'))

        client = AnsibleF5Client(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            f5_product_name=self.spec.f5_product_name)

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(client)
        mm.is_version_less_than_13 = Mock(return_value=True)

        upm = UnparitionedManager(client)
        upm.create_on_device = Mock(return_value=True)
        upm.exists = Mock(return_value=False)

        results = upm.exec_module()

        assert results['changed'] is True
        assert results['partition_access'] == access
    def test_create_user_raises(self, *args):
        access = [{'name': 'Common', 'role': 'guest'}]
        set_module_args(
            dict(username_credential='someuser',
                 password_credential='testpass',
                 partition_access=access,
                 password='******',
                 server='localhost',
                 user='******'))

        client = AnsibleF5Client(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            f5_product_name=self.spec.f5_product_name)

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

        pm = PartitionedManager(client)
        pm.create_on_device = Mock(return_value=True)
        pm.exists = Mock(return_value=False)

        msg = "The 'update_password' option " \
              "needs to be set to 'on_create' when creating " \
              "a resource with a password."

        with pytest.raises(F5ModuleError) as ex:
            pm.exec_module()
        assert str(ex.value) == msg
    def test_update_user_password_with_pass(self, *args):
        set_module_args(
            dict(username_credential='someuser',
                 password_credential='testpass',
                 password='******',
                 server='localhost',
                 user='******'))

        client = AnsibleF5Client(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            f5_product_name=self.spec.f5_product_name)

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

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

        pm = PartitionedManager(client)
        pm.exists = Mock(return_value=True)
        pm.update_on_device = Mock(return_value=True)
        pm.read_current_from_device = Mock(return_value=current)

        results = pm.exec_module()

        assert results['changed'] is True
Exemple #7
0
    def test_create_user_no_password(self, *args):
        access = [{'name': 'Common', 'role': 'guest'}]
        set_module_args(
            dict(username_credential='someuser',
                 partition_access=access,
                 server='localhost',
                 password='******',
                 user='******'))

        client = AnsibleF5Client(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            f5_product_name=self.spec.f5_product_name)

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(client)
        mm.is_version_less_than_13 = lambda: True
        mm.exit_json = lambda x: False

        upm = UnparitionedManager(client)
        upm.create_on_device = lambda: True
        upm.exists = lambda: False

        results = upm.exec_module()

        assert results['changed'] is True
        assert results['partition_access'] == access
Exemple #8
0
    def test_update_user_shell_to_none_shell_attribute_missing(self, *args):
        set_module_args(
            dict(username_credential='someuser',
                 password='******',
                 server='localhost',
                 user='******',
                 shell='none'))

        client = AnsibleF5Client(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            f5_product_name=self.spec.f5_product_name)

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

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(client)
        mm.is_version_less_than_13 = lambda: True
        mm.exit_json = lambda x: False

        upm = UnparitionedManager(client)
        upm.exists = lambda: True
        upm.update_on_device = lambda: True
        upm.read_current_from_device = lambda: current

        results = upm.exec_module()

        assert results['changed'] is False
        assert not hasattr(results, 'shell')
Exemple #9
0
    def test_update_user_shell_to_none(self, *args):
        set_module_args(
            dict(username_credential='someuser',
                 password='******',
                 server='localhost',
                 user='******',
                 shell='none'))

        client = AnsibleF5Client(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            f5_product_name=self.spec.f5_product_name)

        # Configure the parameters that would be returned by querying the
        # remote device
        current = Parameters(dict(user='******', shell='tmsh'))

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(client)
        mm.is_version_less_than_13 = lambda: False
        mm.exit_json = lambda x: False

        pm = PartitionedManager(client)
        pm.exists = lambda: True
        pm.update_on_device = lambda: True
        pm.read_current_from_device = lambda: current

        results = pm.exec_module()

        assert results['changed'] is True
        assert results['shell'] == 'none'
    def test_update_user_shell_to_none_shell_attribute_missing(self, *args):
        set_module_args(
            dict(username_credential='someuser',
                 password='******',
                 server='localhost',
                 user='******',
                 shell='none'))

        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': 'guest'}]
        current = Parameters(
            params=dict(user='******', partition_access=access))

        # Override methods to force specific logic in the module to happen
        upm = UnparitionedManager(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 False
        assert not hasattr(results, 'shell')
    def test_create_user_no_password(self, *args):
        access = [{'name': 'Common', 'role': 'guest'}]
        set_module_args(
            dict(username_credential='someuser',
                 partition_access=access,
                 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
        upm = UnparitionedManager(module=module, params=module.params)
        upm.create_on_device = Mock(return_value=True)
        upm.exists = Mock(return_value=False)

        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['partition_access'] == access
    def test_update_user_shell_to_none(self, *args):
        set_module_args(
            dict(username_credential='someuser',
                 password='******',
                 server='localhost',
                 user='******',
                 shell='none'))

        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=dict(user='******', shell='tmsh'))

        # 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
        assert results['shell'] == 'none'
Exemple #13
0
    def test_update_user_shell_to_bash_mutliple_roles(self, *args):
        set_module_args(dict(
            username_credential='someuser',
            password='******',
            server='localhost',
            user='******',
            shell='bash'
        ))

        client = AnsibleF5Client(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            f5_product_name=self.spec.f5_product_name
        )

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

        # Override methods to force specific logic in the module to happen
        mm = ModuleManager(client)
        mm.is_version_less_than_13 = lambda: True
        mm.exit_json = lambda x: False

        upm = UnparitionedManager(client)
        upm.exists = lambda: True
        upm.update_on_device = lambda: True
        upm.read_current_from_device = lambda: current

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

        with pytest.raises(F5ModuleError) as ex:
            upm.exec_module()
        assert str(ex.value) == msg