Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some missing Unit options #396

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2599,18 +2599,37 @@ Alias of
Struct[{
Optional['Description'] => Variant[String,Array[String,1]],
Optional['Documentation'] => Variant[String,Array[String,1]],
Optional['DefaultDependencies'] => Boolean,
Optional['Wants'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['Requires'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['Requisite'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['BindsTo'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['PartOf'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['Upholds'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['Conflicts'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['Before'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['After'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['OnFailure'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['OnSuccess'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['PropagatesReloadTo'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['ReloadPropagatedFrom'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['PropagatesStopTo'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['StopPropagatedFrom'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['JoinsNamespaceOf'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['RequiresMountsFor'] => Variant[Enum[''],Stdlib::Unixpath,Array[Variant[Enum[''],Stdlib::Unixpath],1]],
Optional['OnSuccessJobMode'] => Enum['fail', 'replace', 'replace-irreversibly', 'isolate', 'flush', 'ignore-dependencies', 'ignore-requirements'],
Optional['OnFailureJobMode'] => Enum['fail', 'replace', 'replace-irreversibly', 'isolate', 'flush', 'ignore-dependencies', 'ignore-requirements'],
Optional['IgnoreOnIsolate'] => Boolean,
Optional['StopWhenUnneeded'] => Boolean,
Optional['RefuseManualStart'] => Boolean,
Optional['RefuseManualStop'] => Boolean,
Optional['AllowIsolate'] => Boolean,
Optional['DefaultDependencies'] => Boolean,
Optional['SurviveFinalKillSignal'] => Boolean,
Optional['CollectMode'] => Enum['inactive', 'inactive-or-failed'],
Optional['FailureAction'] => Enum['none', 'reboot', 'reboot-force', 'reboot-immediate', 'poweroff', 'poweroff-force', 'poweroff-immediate', 'exit', 'exit-force', 'soft-reboot', 'soft-reboot-force', 'kexec', 'kexec-force', 'halt', 'halt-force', 'halt-immediate'],
Optional['SuccessAction'] => Enum['none', 'reboot', 'reboot-force', 'reboot-immediate', 'poweroff', 'poweroff-force', 'poweroff-immediate', 'exit', 'exit-force', 'soft-reboot', 'soft-reboot-force', 'kexec', 'kexec-force', 'halt', 'halt-force', 'halt-immediate'],
Optional['FailureActionExitStatus'] => Variant[Enum[''],Integer[0, 255]],
Optional['SuccessActionExitStatus'] => Variant[Enum[''],Integer[0, 255]],
# Conditions and Asserts
Optional['ConditionPathExists'] => Variant[Enum[''],Stdlib::Unixpath,Pattern[/^!.*$/],Array[Variant[Enum[''],Stdlib::Unixpath,Pattern[/^!.*$/]],1]],
Optional['ConditionPathIsDirectory'] => Variant[Enum[''],Stdlib::Unixpath,Pattern[/^!.*$/],Array[Variant[Enum[''],Stdlib::Unixpath,Pattern[/^!.*$/]],1]],
Expand Down
65 changes: 60 additions & 5 deletions spec/type_aliases/systemd_unit_unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
it { is_expected.to allow_value({ 'Documentation' => %w[my special] }) }
it { is_expected.to allow_value({ 'Documentation' => ['', 'special'] }) }

%w[Wants Requires Requisite Wants PartOf Upholds Conflicts Before After OnFailure OnSuccess].each do |depend|
%w[Wants Requires Requisite BindsTo Wants PartOf Upholds Conflicts Before After OnFailure OnSuccess PropagatesReloadTo ReloadPropagatedFrom PropagatesStopTo StopPropagatedFrom JoinsNamespaceOf].each do |depend|
context "with a key of #{depend} can have values of units" do
it { is_expected.to allow_value({ depend.to_s => 'foobar.service' }) }
it { is_expected.to allow_value({ depend.to_s => ['foobar.service'] }) }
Expand All @@ -26,6 +26,58 @@
end
end

# JobModes
%w[OnSuccessJobMode OnFailureJobMode].each do |assert|
context "with a key of #{assert} can have appropriate values" do
it { is_expected.to allow_value({ assert.to_s => 'fail' }) }
it { is_expected.to allow_value({ assert.to_s => 'replace' }) }
it { is_expected.to allow_value({ assert.to_s => 'replace-irreversibly' }) }
it { is_expected.to allow_value({ assert.to_s => 'isolate' }) }
it { is_expected.to allow_value({ assert.to_s => 'flush' }) }
it { is_expected.to allow_value({ assert.to_s => 'ignore-dependencies' }) }
it { is_expected.to allow_value({ assert.to_s => 'ignore-requirements' }) }
it { is_expected.not_to allow_value({ assert.to_s => '' }) }
it { is_expected.not_to allow_value({ assert.to_s => 'some-other-mode' }) }
end
end

# Actions
%w[FailureAction SuccessAction].each do |assert|
context "with a key of #{assert} can have appropriate values" do
it { is_expected.to allow_value({ assert.to_s => 'none' }) }
it { is_expected.to allow_value({ assert.to_s => 'reboot' }) }
it { is_expected.to allow_value({ assert.to_s => 'reboot-force' }) }
it { is_expected.to allow_value({ assert.to_s => 'reboot-immediate' }) }
it { is_expected.to allow_value({ assert.to_s => 'poweroff' }) }
it { is_expected.to allow_value({ assert.to_s => 'poweroff-force' }) }
it { is_expected.to allow_value({ assert.to_s => 'poweroff-immediate' }) }
it { is_expected.to allow_value({ assert.to_s => 'exit' }) }
it { is_expected.to allow_value({ assert.to_s => 'exit-force' }) }
it { is_expected.to allow_value({ assert.to_s => 'soft-reboot' }) }
it { is_expected.to allow_value({ assert.to_s => 'soft-reboot-force' }) }
it { is_expected.to allow_value({ assert.to_s => 'kexec' }) }
it { is_expected.to allow_value({ assert.to_s => 'kexec-force' }) }
it { is_expected.to allow_value({ assert.to_s => 'halt' }) }
it { is_expected.to allow_value({ assert.to_s => 'halt-force' }) }
it { is_expected.to allow_value({ assert.to_s => 'halt-immediate' }) }
it { is_expected.not_to allow_value({ assert.to_s => '' }) }
it { is_expected.not_to allow_value({ assert.to_s => 'another-action' }) }
end
end

# ExitStatus
%w[FailureActionExitStatus SuccessActionExitStatus].each do |assert|
context "with a key of #{assert} can have appropriate values" do
it { is_expected.to allow_value({ assert.to_s => '' }) }
it { is_expected.to allow_value({ assert.to_s => 0 }) }
it { is_expected.to allow_value({ assert.to_s => 128 }) }
it { is_expected.to allow_value({ assert.to_s => 255 }) }
it { is_expected.not_to allow_value({ assert.to_s => -1 }) }
it { is_expected.not_to allow_value({ assert.to_s => 256 }) }
it { is_expected.not_to allow_value({ assert.to_s => '1' }) }
end
end

%w[ConditionPathExists ConditionPathIsDirectory AssertPathExists AssertPathIsDirectory].each do |assert|
context "with a key of #{assert} can have files or negated files" do
it { is_expected.to allow_value({ assert.to_s => '/my/existing/file' }) }
Expand All @@ -36,15 +88,14 @@
end

# Booleans
%w[DefaultDependencies].each do |assert|
%w[DefaultDependencies IgnoreOnIsolate StopWhenUnneeded RefuseManualStart RefuseManualStop AllowIsolate SurviveFinalKillSignal].each do |assert|
context "with a key of #{assert} can have values set to true" do
it { is_expected.to allow_value(assert.to_s => true) }
it { is_expected.to allow_value({ assert.to_s => true }) }
it { is_expected.to allow_value({ assert.to_s => false }) }
it { is_expected.not_to allow_value({ assert.to_s => 'yes' }) }
end
end

it { is_expected.not_to allow_value({ 'DefaultDependencies' => 'yes' }) }

it { is_expected.not_to allow_value({ 'Description' => 10 }) }
it { is_expected.not_to allow_value({ 'Wants' => '/unitwith.service' }) }

Expand All @@ -53,6 +104,10 @@
it { is_expected.not_to allow_value({ 'ConditionPathExists' => 'not/an/absolute/path' }) }
it { is_expected.not_to allow_value({ 'ConditionPathExists' => ['not/an/absolute/path'] }) }

it { is_expected.to allow_value({ 'CollectMode' => 'inactive' }) }
it { is_expected.to allow_value({ 'CollectMode' => 'inactive-or-failed' }) }
it { is_expected.not_to allow_value({ 'CollectMode' => 'active' }) }

it { is_expected.to allow_value({ 'RequiresMountsFor' => '/an/absolute/path' }) }
it { is_expected.to allow_value({ 'RequiresMountsFor' => '' }) }
it { is_expected.to allow_value({ 'RequiresMountsFor' => ['', '/an/absolute/path'] }) }
Expand Down
21 changes: 20 additions & 1 deletion types/unit/unit.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,37 @@
{
Optional['Description'] => Variant[String,Array[String,1]],
Optional['Documentation'] => Variant[String,Array[String,1]],
Optional['DefaultDependencies'] => Boolean,
Optional['Wants'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['Requires'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['Requisite'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['BindsTo'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['PartOf'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['Upholds'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['Conflicts'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['Before'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['After'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['OnFailure'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['OnSuccess'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['PropagatesReloadTo'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['ReloadPropagatedFrom'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['PropagatesStopTo'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['StopPropagatedFrom'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['JoinsNamespaceOf'] => Variant[Enum[''],Systemd::Unit,Array[Variant[Enum[''],Systemd::Unit],1]],
Optional['RequiresMountsFor'] => Variant[Enum[''],Stdlib::Unixpath,Array[Variant[Enum[''],Stdlib::Unixpath],1]],
Optional['OnSuccessJobMode'] => Enum['fail', 'replace', 'replace-irreversibly', 'isolate', 'flush', 'ignore-dependencies', 'ignore-requirements'],
Optional['OnFailureJobMode'] => Enum['fail', 'replace', 'replace-irreversibly', 'isolate', 'flush', 'ignore-dependencies', 'ignore-requirements'],
Optional['IgnoreOnIsolate'] => Boolean,
Optional['StopWhenUnneeded'] => Boolean,
Optional['RefuseManualStart'] => Boolean,
Optional['RefuseManualStop'] => Boolean,
Optional['AllowIsolate'] => Boolean,
Optional['DefaultDependencies'] => Boolean,
Optional['SurviveFinalKillSignal'] => Boolean,
Optional['CollectMode'] => Enum['inactive', 'inactive-or-failed'],
Optional['FailureAction'] => Enum['none', 'reboot', 'reboot-force', 'reboot-immediate', 'poweroff', 'poweroff-force', 'poweroff-immediate', 'exit', 'exit-force', 'soft-reboot', 'soft-reboot-force', 'kexec', 'kexec-force', 'halt', 'halt-force', 'halt-immediate'],
Optional['SuccessAction'] => Enum['none', 'reboot', 'reboot-force', 'reboot-immediate', 'poweroff', 'poweroff-force', 'poweroff-immediate', 'exit', 'exit-force', 'soft-reboot', 'soft-reboot-force', 'kexec', 'kexec-force', 'halt', 'halt-force', 'halt-immediate'],
Optional['FailureActionExitStatus'] => Variant[Enum[''],Integer[0, 255]],
Optional['SuccessActionExitStatus'] => Variant[Enum[''],Integer[0, 255]],
# Conditions and Asserts
Optional['ConditionPathExists'] => Variant[Enum[''],Stdlib::Unixpath,Pattern[/^!.*$/],Array[Variant[Enum[''],Stdlib::Unixpath,Pattern[/^!.*$/]],1]],
Optional['ConditionPathIsDirectory'] => Variant[Enum[''],Stdlib::Unixpath,Pattern[/^!.*$/],Array[Variant[Enum[''],Stdlib::Unixpath,Pattern[/^!.*$/]],1]],
Expand Down