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

Fix plan return value #209

Merged
merged 4 commits into from
Jun 12, 2019
Merged

Conversation

reidmv
Copy link
Contributor

@reidmv reidmv commented Jun 5, 2019

Assuming some nodes successfully reboot and some nodes don't, when the
reboot plan is invoked with _catch_errors => true, it should return
meaningful data so that the end user can decide how to handle or report
on which nodes failed to reboot while potentially continuing forward
to another task with the set of nodes that succeeded.

This commit makes the reboot plan always return meaningful data, even
when erroring.

@reidmv reidmv force-pushed the fix-plan-return-value branch 4 times, most recently from 80c936d to 2a5e8b1 Compare June 6, 2019 17:32
Copy link
Contributor

@MikaelSmith MikaelSmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems ok. The failure contents changes, not sure if that's significant enough to impact current users.

@sheenaajay
Copy link
Contributor

Thanks for submitting the PR @reidmv .
Running the adhoc jobs for the changes.

@sheenaajay
Copy link
Contributor

@reidmv The testcases ran clean on all platform except the redhat8.Thank you.

@reidmv
Copy link
Contributor Author

reidmv commented Jun 11, 2019

Just noticed there's still a fail_plan() in here that can be reached even if fail_plan_on_errors is false. https://github.com/puppetlabs/puppetlabs-reboot/pull/209/files#diff-605910045eeb5889bfac80d8f6ab6d26L71

Will work on fixing that and updating PR shortly...

@reidmv
Copy link
Contributor Author

reidmv commented Jun 11, 2019

Updated PR. Should be good to go now.

Prior to this commit the reboot plan raised an error calling max()
without a valid argument. This commit causes the plan to short-circuit
and return an empty ResultSet in the event an empty TargetSpec was given
as the $nodes argument.

Long-term, the plan should probably be modified to always return a
meaningful ResultSet value on completion.
Assuming some nodes successfully reboot and some nodes don't, when the
reboot plan is invoked with _catch_errors => true, it should return
meaningful data so that the end user can decide how to handle or report
on which nodes failed to reboot while potentially continuing forward
to another task with the set of nodes that succeeded.

This commit makes the reboot plan always return meaningful data, even
when erroring.

Side note: gonna open a ticket to make it easier to _catch_errors for a
plan, for the end user...
A common use case for using the reboot plan with _catch_errors => true
would be to review which systems didn't reboot and remediate or move
forwards only with those that did. However, even with _catch_errors =>
true, the caller has to check if the plan result is an error and go down
a different code path if so to deal with it and extract the ResultSet
they need.

This commit provides a new Boolean plan option, fail_plan_on_error,
which if set to false will ensure the plan always returns exactly the
same data type regardless of whether or not any individual target failed
to reboot. The consuming plan author can then simplify their own code,
secure in the knowledge of what kind of data will be returned.
This commit fixes a missed fail_plan() invocation that would have
allowed a plan to fail even if fail_plan_on_errors was set to false. In
doing so, it further linearizes the logic, allowing for a slight
simplification of the main reduce function.

While making the commit, it seemed like a good idea to restore the
fail_plan() detail key that was used previously, in order to retain
compatibility with previous failure return results.

Clean up the spec test a bit while in here.
@sheenaajay
Copy link
Contributor

@reidmv Thanks for the quick turn around. Will rerun the ad-hoc jobs.

@sheenaajay
Copy link
Contributor

Screen Shot 2019-06-12 at 10 52 11

@sheenaajay sheenaajay merged commit f5d3edc into puppetlabs:master Jun 12, 2019
@LukasAud LukasAud added the bugfix label Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants