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

SystemD and Windows resources when not resource found will now return error #9175

Merged

Conversation

cthorn42
Copy link
Collaborator

@cthorn42 cthorn42 commented Nov 29, 2023

Previously when Windows or SystemD attempted to managed a non-existant resource Puppet would just return that the service was stopped. This could be a bit confusing since if the service doesn't exist, that should be made explicit and we should do more then just returning that the service is in a 'stopped' state.
This change will cause Puppet to return an error message if a Windows/Systemd service is not found while trying to manage said service.

When managing the `ensure` state for a service, the provider queries the
service status to determine if it's running or not. However, if the
service doesn't exist, then it returns that the service is `stopped`.

When trying to ensure a non-existent service is stopped, puppet thinks
the service is "insync", so returns exit code 0.

This commit updates the systemd provider's enable method to return
either :running, :stopped or :absent. To differentiate between `stopped`
vs `absent`, the provider first checks if the service exists.

This adds `absent` as a valid value for the `ensure` property, however,
it can't be set on a provider, since we don't want to remove services:

    puppet resource service ufw ensure=absent
    Error: The systemd provider can not handle attribute ensure
@cthorn42 cthorn42 requested a review from a team as a code owner November 29, 2023 22:02
@cthorn42 cthorn42 force-pushed the bug_fix/main/error_when_resource_not_found branch 4 times, most recently from 935be7a to dfc2bad Compare December 15, 2023 19:21
@joshcooper
Copy link
Contributor

Could you remove the lib/puppet/.DS_Store file from this PR and update the commit summary to describe the behavior change (how previously the windows and systemd providers reported the non-existent service as stopped and now it will be absent)?

@cthorn42 cthorn42 force-pushed the bug_fix/main/error_when_resource_not_found branch 3 times, most recently from 5104059 to 129115f Compare December 18, 2023 20:56
@cthorn42 cthorn42 changed the title Bug fix/main/error when resource not found SystemD and Windows resources when not resource found will now return error Dec 18, 2023
@cthorn42 cthorn42 force-pushed the bug_fix/main/error_when_resource_not_found branch 2 times, most recently from d92c0b5 to 1dd8fe2 Compare December 19, 2023 23:53
…sent

Previously if a service was not present on a system and a user tried to manage that
service with `puppet resource service`, and that service wasn't there an error message
would appear on the screen but the puppet command would return a 0 exit code.
This commit is meant to bubble up those error messages so they will be reflected on the command
line properly.
First pass will be to update the Windows and Systemd providers.

blank
@cthorn42 cthorn42 force-pushed the bug_fix/main/error_when_resource_not_found branch from 1dd8fe2 to 4f6a2ea Compare December 20, 2023 17:23
@joshcooper joshcooper merged commit da413eb into puppetlabs:main Dec 20, 2023
9 checks passed
@joshcooper joshcooper added the backport 7.x Generate a backport PR to 7.x label Dec 20, 2023
Copy link

Backport failed for 7.x, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally.

git fetch origin 7.x
git worktree add -d .worktree/backport-9175-to-7.x origin/7.x
cd .worktree/backport-9175-to-7.x
git checkout -b backport-9175-to-7.x
ancref=$(git merge-base 9ceca21e565f0771b9bffe88a20894506c015602 4f6a2ea27ffa4451a327002bca045194d937f7aa)
git cherry-pick -x $ancref..4f6a2ea27ffa4451a327002bca045194d937f7aa

@joshcooper joshcooper added the maintenance Maintenance chores are excluded from changelogs label Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 7.x Generate a backport PR to 7.x maintenance Maintenance chores are excluded from changelogs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants