sssd_test_framework.misc

Miscellaneous functions.

Functions

attrs_ad_parse(output)

Parse AD object output into dictionary.

attrs_include_value(attr, value)

Include value to attribute list if it is not yet present.

attrs_parse(lines[, attrs])

Parse LDAP attributes from output.

attrs_to_hash(attrs)

Convert attributes into an Powershell hash table records.

delimiter_parse(lines[, delimiter])

Parse delimited lines from output.

get_attr(data, key[, default])

Retrieve a value from a dictionary with list-aware semantics.

ip_is_valid(ip)

Check ip is valid.

ip_to_ptr(ip_address[, prefixlen])

Get the reverse pointer from given address.

ip_version(ip_address)

Parse str and return the IP version.

parse_ldif(ldif)

Convert given LDIF to dictionary.

retry([max_retries, delay, on])

Decorated function will be retried if it raises an exception.

seconds_to_timespan(seconds)

Convert seconds to powershell timespan format, 'Days:Hours:Minutes:Seconds:Fractions'.

to_list(value)

Convert value into a list.

to_list_of_strings(value)

Convert given list or single value to list of strings.

to_list_without_none(r_list)

Remove all elements that are None from the list.

sssd_test_framework.misc.attrs_parse(lines: list[str], attrs: list[str] | None = None) dict[str, list[str]]

Parse LDAP attributes from output.

Parameters:
  • lines (list[str]) – Output.

  • attrs (list[str] | None, optional) – If set, only requested attributes are returned, defaults to None

Returns:

Dictionary with attribute name as a key.

Return type:

dict[str, list[str]]

sssd_test_framework.misc.delimiter_parse(lines: list[str], delimiter: str = ':') dict[str, str]

Parse delimited lines from output.

Parameters:
  • lines (list[str]) – Output.

  • delimiter (str, defaults to :) – Delimiter, optional

Returns:

Dictionary with first element as the name as a key.

Return type:

dict[str, str]

sssd_test_framework.misc.attrs_include_value(attr: Any | list[Any] | None, value: Any) list[Any]

Include value to attribute list if it is not yet present.

If attr is not a list, then it is first converted into a list.

Parameters:
  • attr (Any | list[Any]) – List of attribute values or a single value.

  • value (Any) – Value to add to the list.

Returns:

New list with the value included.

Return type:

list[Any]

sssd_test_framework.misc.to_list(value: Any | list[Any] | None) list[Any]

Convert value into a list.

  • if value is None then return an empty list

  • if value is already a list then return it unchanged

  • if value is not a list then return [value]

Parameters:

value (Any | list[Any] | None) – Value that should be converted to a list.

Returns:

List with the value as an element.

Return type:

list[Any]

sssd_test_framework.misc.to_list_of_strings(value: Any | list[Any] | None) list[str]

Convert given list or single value to list of strings.

The value is first converted to a list and then str(item) is run on each of its item.

Parameters:

value (Any | list[Any] | None) – Value to convert.

Returns:

List of strings.

Return type:

list[str]

sssd_test_framework.misc.to_list_without_none(r_list: list[Any]) list[Any]

Remove all elements that are None from the list.

Parameters:

r_list (list[Any]) – List of all elements.

Returns:

New list with all values from the given list that are not None.

Return type:

list[Any]

sssd_test_framework.misc.parse_ldif(ldif: str) dict[str, dict[str, list[str]]]

Convert given LDIF to dictionary.

Parameters:

ldif (str) – Output of ldbsearch.

Returns:

Data of given ldif in format: dict[dn, dict[attribute, list[attrvalue]]].

Return type:

dict[str, dict[str, list[str]]

sssd_test_framework.misc.attrs_to_hash(attrs: dict[str, Any]) str | None

Convert attributes into an Powershell hash table records.

Parameters:

attrs (dict[str, Any]) – Attributes names and values.

Returns:

Attributes in powershell hash record format.

Return type:

str | None

sssd_test_framework.misc.seconds_to_timespan(seconds: int) str

Convert seconds to powershell timespan format, ‘Days:Hours:Minutes:Seconds:Fractions’.

Parameters:

seconds (int) – Seconds.

Returns:

Time in timespan format.

Return type:

str

sssd_test_framework.misc.ip_to_ptr(ip_address: str, prefixlen: int | None = None) str

Get the reverse pointer from given address.

Parameters:
  • ip_address (str) – Address.

  • prefixlen (int | None = None) – Prefix length, optional

Returns:

Reverse pointer.

Return type:

str

sssd_test_framework.misc.ip_is_valid(ip: str) bool

Check ip is valid.

Parameters:

ip (str) – IP address.

Returns:

True, false if str is not an ip.

Return type:

bool

sssd_test_framework.misc.ip_version(ip_address: str) int | None

Parse str and return the IP version.

Parameters:

ip_address (str) – IP address.

Returns:

IP version or None if not found.

Return type:

int | None

sssd_test_framework.misc.retry(max_retries: int = 5, delay: float = 1, on: type[Exception] | list[type[Exception]] | None = None) Callable[[Callable[[Param], RetType]], Callable[[Param], RetType]]

Decorated function will be retried if it raises an exception.

Parameters:
  • max_retries (int, optional) – Maximum number of retry attempts, defaults to 5

  • delay (float, optional) – Delay in seconds between each retry, defaults to 1

  • on (type[Exception] | list[type[Exception]] | None, optional) – If set, retry only on given exceptions, defaults to None

Returns:

Decorated function.

Return type:

Callable

sssd_test_framework.misc.get_attr(data: dict[str, Any], key: str, default: Any | None = None) Any | list[Any]

Retrieve a value from a dictionary with list-aware semantics. This helper makes working with parsed command output or API responses easier: - Single-item lists → returns the first element. - Multi-item lists → returns the full list. - Missing, empty, or None values → returns default. - Non-list values → returned as-is.

Example usage
result = {
    "login": ["user-1"],
    "uidnumber": [1234567],
    "groups": ["admins", "developers"],
    "services": [],
    "nested": {
        "sshpubkey": ["ssh-rsa AAAAB3Nza..."],
        "email": ["user1@example.com"],
    },
}
assert get_attr(result, "login") == "user-1"
assert get_attr(result, "groups") == ["admins", "developers"]
assert get_attr(result, "uidnumber") == 1234567
assert get_attr(result, "services") is None
assert get_attr(result, "missing", default="N/A") == "N/A"
# Nested dictionary
nested = get_attr(result, "nested")
assert isinstance(nested, dict)
assert get_attr(nested, "email") == "user1@example.com"
Parameters:
  • data (dict[str, Any]) – Dictionary returned from command parsing.

  • key (str) – Attribute name to look up.

  • default (Any | None, optional) – Value to return if key is missing or empty, defaults to None.

Returns:

A single value or list of values.

Return type:

Any | list[Any]

sssd_test_framework.misc.attrs_ad_parse(output: str) dict[str, list[str]]

Parse AD object output into dictionary.

Parameters:

output (str) – PowerShell AD object output.

Returns:

Dictionary of AD object attributes.

Return type:

dict[str, list[str]]

Modules

errors

globals

ssh