Repository navigation
Implement Unit.SetProperties, add CPUWeight and other cgroup signatures - #137
Merged
Merged
Conversation
Unit.SetProperties(runtime, properties) went through the generic method call, which refuses a(sv) arguments with NotImplementedError, so there was no way to do the equivalent of `systemctl set-property` on a Unit object (systemd#122). Override it like Manager.SetUnitProperties: each property is sent with the type from KNOWN_UNIT_SIGNATURES. signature_array (and so both methods) now also takes a list of (name, value) pairs, the D-Bus a(sv) shape, besides a dict. CPUWeight itself, the example in systemd#122, was missing from KNOWN_UNIT_SIGNATURES, as were the other settable cgroup properties. Add them with the types systemd 259 exposes: CPUWeight, StartupCPUWeight, CPUQuotaPeriodUSec "t"; AllowedCPUs, StartupAllowedCPUs, AllowedMemoryNodes, StartupAllowedMemoryNodes "ay"; IOWeight, StartupIOWeight "t"; IODeviceWeight, IORead/WriteBandwidthMax, IORead/WriteIOPSMax, IODeviceLatencyTargetUSec "a(st)"; MemoryMin, MemoryZSwapMax "t"; MemoryZSwapWriteback "b"; MemoryPressureWatch "s", MemoryPressureThresholdUSec "t". Tested on Fedora 44 (systemd 259): the systemd#122 example, Unit("system.slice").Unit.SetProperties(True, [(b"CPUWeight", 200)]), sets system.slice/cpu.weight to 200. Each new property is accepted at unit creation (pystemd.run(extra=...)) and reads back the value set; all but MemoryPressureWatch and MemoryPressureThresholdUSec can also be changed at runtime with SetProperties (systemd only takes those two at creation). New e2e test for SetProperties; tests/ and e2e/ pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Unit.SetProperties(runtime, properties) went through the generic method call, which refuses a(sv) arguments with NotImplementedError, so there was no way to do the equivalent of
systemctl set-propertyon a Unit object (#122). Override it like Manager.SetUnitProperties: each property is sent with the type from KNOWN_UNIT_SIGNATURES. signature_array (and so both methods) now also takes a list of (name, value) pairs, the D-Bus a(sv) shape, besides a dict.CPUWeight itself, the example in #122, was missing from KNOWN_UNIT_SIGNATURES, as were the other settable cgroup properties. Add them with the types systemd 259 exposes: CPUWeight, StartupCPUWeight, CPUQuotaPeriodUSec "t"; AllowedCPUs, StartupAllowedCPUs, AllowedMemoryNodes, StartupAllowedMemoryNodes "ay"; IOWeight, StartupIOWeight "t"; IODeviceWeight, IORead/WriteBandwidthMax, IORead/WriteIOPSMax, IODeviceLatencyTargetUSec "a(st)"; MemoryMin, MemoryZSwapMax "t"; MemoryZSwapWriteback "b"; MemoryPressureWatch "s", MemoryPressureThresholdUSec "t".
Tested on Fedora 44 (systemd 259): the #122 example, Unit("system.slice").Unit.SetProperties(True, [(b"CPUWeight", 200)]), sets system.slice/cpu.weight to 200. Each new property is accepted at unit creation (pystemd.run(extra=...)) and reads back the value set; all but MemoryPressureWatch and MemoryPressureThresholdUSec can also be changed at runtime with SetProperties (systemd only takes those two at creation). New e2e test for SetProperties; tests/ and e2e/ pass.