Skip to content

AssertionError calling Manager.StartTransientUnit() #120

Description

@ipilcher

I am attempting to call StartTransientUnit(), using the following code.

import pystemd.systemd1     # type: ignore[import-untyped]
import typing


class _StartTransientUnitProtocol(typing.Protocol):

    def StartTransientUnit(
        self,
        name: bytes,
        mode: bytes,
        properties: list[tuple[bytes, typing.Any]],
        aux: list[typing.Any]
    ) -> (
        bytes
    ):
        ...


class SystemdManager(object):

    def __init__(self) -> None:
        self._mgr: _StartTransientUnitProtocol = pystemd.systemd1.Manager()
        self._mgr.load()

    def start_unit(
        self,
        name: bytes,
        mode: bytes,
        properties: list[tuple[bytes, typing.Any]],
    ) -> (
        bytes
    ):
        for k, v in properties:
            print(k, type(v), v)
        return self._mgr.StartTransientUnit(name, mode, properties, [])

When I attempt to use this, I get the following (example) output:

b'Description' <class 'bytes'> b'Early network interface: bond_test'
b'Before' <class 'list'> [b'firewalld.service', b'nftables.service', b'iptables.service', b'ip6tables.service', b'network-pre.target']
b'Wants' <class 'list'> [b'network-pre.target']
b'Type' <class 'bytes'> b'oneshot'
b'RemainAfterExit' <class 'bool'> True
b'ExecStart' <class 'list'> [(b'/usr/bin/ip', [b'link', b'add', b'dev', b'bond_test', b'type', b'bond'], False)]
Traceback (most recent call last):
  File "/home/pilcher/projects/early-netif/early-netif.py", line 116, in <module>
    create_units(interfaces.values())
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/home/pilcher/projects/early-netif/early-netif.py", line 108, in create_units
    create_unit(mgr, i)
    ~~~~~~~~~~~^^^^^^^^
  File "/home/pilcher/projects/early-netif/early-netif.py", line 97, in create_unit
    mgr.start_unit(name, b'fail', properties)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pilcher/projects/early-netif/sdmgr2.py", line 35, in start_unit
    return self._mgr.StartTransientUnit(name, mode, properties, [])
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.14/site-packages/pystemd/systemd1/manager.py", line 39, in StartTransientUnit
    assert interface_name == b"org.freedesktop.systemd1.Manager"
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

What am I doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions