From cc32f4ded7e87ac2a5b28b1ac972c3dcecdbf5d6 Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Tue, 5 Mar 2024 15:43:19 +0100 Subject: [PATCH] Allow CPUQuota to be greater than 100% CPUQuota can be more that 100% A bug was introduced in #422 restricting it to the range from 0 to 100%. * https://www.freedesktop.org/software/systemd/man/latest/systemd.resource-control.html#CPUQuota= --- REFERENCE.md | 4 ++-- spec/type_aliases/systemd_unit_service_spec.rb | 5 +++++ spec/type_aliases/systemd_unit_slice_spec.rb | 4 ++++ types/unit/service.pp | 2 +- types/unit/slice.pp | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index f8fc2293..01a891b3 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -2632,7 +2632,7 @@ Struct[{ Optional['CPUAccounting'] => Boolean, Optional['CPUShares'] => Integer[2,262144], Optional['StartupCPUShares'] => Integer[2,262144], - Optional['CPUQuota'] => Systemd::Unit::Percent, + Optional['CPUQuota'] => Pattern['^([1-9][0-9]*)%$'], # bigger than 100% is okay. Optional['MemoryAccounting'] => Boolean, Optional['MemoryLow'] => Systemd::Unit::AmountOrPercent, Optional['MemoryMin'] => Systemd::Unit::AmountOrPercent, @@ -2737,7 +2737,7 @@ Alias of ```puppet Struct[{ Optional['CPUAccounting'] => Boolean, - Optional['CPUQuota'] => Systemd::Unit::Percent, + Optional['CPUQuota'] => Pattern['^([1-9][0-9]*)%$'], # bigger than 100% is okay. Optional['CPUShares'] => Integer[2,262144], Optional['CPUWeight'] => Variant[Enum['idle'],Integer[1,10000]], Optional['Delegate'] => Boolean, diff --git a/spec/type_aliases/systemd_unit_service_spec.rb b/spec/type_aliases/systemd_unit_service_spec.rb index 91c2eaa6..c40ed1f7 100644 --- a/spec/type_aliases/systemd_unit_service_spec.rb +++ b/spec/type_aliases/systemd_unit_service_spec.rb @@ -88,6 +88,9 @@ it { is_expected.to allow_value({ 'MemoryAccounting' => true }) } + it { is_expected.to allow_value({ 'CPUQuota' => '1%' }) } + it { is_expected.to allow_value({ 'CPUQuota' => '110%' }) } + it { is_expected.to allow_value( { @@ -100,5 +103,7 @@ ) } + it { is_expected.not_to allow_value({ 'CPUQuota' => 50 }) } + it { is_expected.not_to allow_value({ 'CPUQuota' => '0%' }) } it { is_expected.not_to allow_value({ 'MemoryHigh' => '1Y' }) } end diff --git a/spec/type_aliases/systemd_unit_slice_spec.rb b/spec/type_aliases/systemd_unit_slice_spec.rb index 90050558..e7442857 100644 --- a/spec/type_aliases/systemd_unit_slice_spec.rb +++ b/spec/type_aliases/systemd_unit_slice_spec.rb @@ -5,6 +5,8 @@ describe 'Systemd::Unit::Slice' do it { is_expected.to allow_value({ 'MemoryAccounting' => true }) } it { is_expected.to allow_value({ 'CPUWeight' => 100 }) } + it { is_expected.to allow_value({ 'CPUQuota' => '1%' }) } + it { is_expected.to allow_value({ 'CPUQuota' => '110%' }) } it { is_expected.to allow_value({ 'CPUWeight' => 'idle' }) } it { is_expected.to allow_value({ 'IPAccounting' => true }) } it { is_expected.to allow_value({ 'IOAccounting' => false }) } @@ -26,5 +28,7 @@ ) } + it { is_expected.not_to allow_value({ 'CPUQuota' => 50 }) } + it { is_expected.not_to allow_value({ 'CPUQuota' => '0%' }) } it { is_expected.not_to allow_value({ 'MemoryHigh' => '1Y' }) } end diff --git a/types/unit/service.pp b/types/unit/service.pp index a4c63e5f..e2521abe 100644 --- a/types/unit/service.pp +++ b/types/unit/service.pp @@ -50,7 +50,7 @@ Optional['CPUAccounting'] => Boolean, Optional['CPUShares'] => Integer[2,262144], Optional['StartupCPUShares'] => Integer[2,262144], - Optional['CPUQuota'] => Systemd::Unit::Percent, + Optional['CPUQuota'] => Pattern['^([1-9][0-9]*)%$'], # bigger than 100% is okay. Optional['MemoryAccounting'] => Boolean, Optional['MemoryLow'] => Systemd::Unit::AmountOrPercent, Optional['MemoryMin'] => Systemd::Unit::AmountOrPercent, diff --git a/types/unit/slice.pp b/types/unit/slice.pp index 93252aee..4439cc00 100644 --- a/types/unit/slice.pp +++ b/types/unit/slice.pp @@ -5,7 +5,7 @@ type Systemd::Unit::Slice = Struct[ { Optional['CPUAccounting'] => Boolean, - Optional['CPUQuota'] => Systemd::Unit::Percent, + Optional['CPUQuota'] => Pattern['^([1-9][0-9]*)%$'], # bigger than 100% is okay. Optional['CPUShares'] => Integer[2,262144], Optional['CPUWeight'] => Variant[Enum['idle'],Integer[1,10000]], Optional['Delegate'] => Boolean,