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

openshift_checks: refactor check results #4913

Merged
merged 2 commits into from
Aug 8, 2017
Merged

openshift_checks: refactor check results #4913

merged 2 commits into from
Aug 8, 2017

Conversation

sosiouxme
Copy link
Member

@sosiouxme sosiouxme commented Jul 27, 2017

Introduced the 'changed' property for checks that can make changes to track whether they did or not. Rather than the check's own logic having to track this and include it in the result hash, just set the property and have the action plugin insert it in the result hash after running (even if there is an exception).

Cleared out a lot of crufty "changed: false" hash entries.

Refactored logging checks:

  • Turned failure messages into exceptions.
  • Have tests look at exceptions raised instead of text intended for users.
  • Turned logging_namespace property into a method.
  • Got rid of _exec_oc and just use logging.exec_oc.

Copy link
Contributor

@rhcarvalho rhcarvalho left a comment

Choose a reason for hiding this comment

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

I like it, thanks @sosiouxme! I focused on some parts, glanced at others, ignored others. Please comment if there's some part you'd want better review.

@@ -69,13 +69,15 @@ def run(self, tmp=None, task_vars=None):
msg=str(e),
)

if check.changed:
r["changed"] = True
Copy link
Contributor

Choose a reason for hiding this comment

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

This is okay. Have you considered setting r['changed'] = check.changed unconditionally?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but I thought it wouldn't hurt to allow the check to continue to return it in the result hash if desired for some reason. But thinking about it, why complicate what is really quite simple... "one way to do it" is probably best here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I remembered why I did it this way. I don't want to clutter up every check result in -vvv output with "changed" when it won't matter for most. I think I'll leave it as-is.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right. We can omit from checks, but always set it in the task/action plugin level at most once.

Now whether to always include it on the task/action plugin level will depend on how Ansible interpret it when it is missing (default True or default False) ;-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Pretty sure Ansible defaults to missing == False

For this code, it seemed simplest to always set it at the task level.

def __init__(self, name, msg=None):
# msg is for the message the user will see when this is raised.
# name is for test code to identify the error without looking at msg text.
if msg is None: # for parameter backward compatibility
Copy link
Contributor

Choose a reason for hiding this comment

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

I think if we swap the order of the arguments we can avoid this little hack?

Copy link
Member Author

Choose a reason for hiding this comment

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

Of course, but I like to have the concise identifier first and then the blah blah blah when I'm looking at the code raising an exception. Selfish of me? And for once I thought it would be nice not to force a total transformation to the new method signature.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see 👍

@@ -34,6 +42,8 @@ def __init__(self, execute_module=None, task_vars=None, tmp=None):
self._execute_module = execute_module
self.task_vars = task_vars or {}
self.tmp = tmp
# set True when the check makes a change to the host so it can be reported to the user:
Copy link
Contributor

Choose a reason for hiding this comment

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

s/set True/set to True/ ?

s/so it can be reported to the user// ? "reporting to the user" is kind of optional, we don't need to make promises in this comment, but I'll leave it up to you, I'm fine either way.

Copy link
Member Author

@sosiouxme sosiouxme Jul 28, 2017

Choose a reason for hiding this comment

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

set to True 👍

"report to user" right that can be worded better. All we're doing is marking the task as having made a change so that the sum total of "changed" tasks can be reported at the end of the run. As if anyone cares (but there's always someone). That's all that's "reported" to the user unless they're looking at -vvv output.

    # set to True when the check changes the host so the total "changed" count is accurate

return {"failed": True, "changed": False, "msg": msg}

curator_pods = self.get_pods_for_component("curator")
self.check_curator(curator_pods)
# TODO(lmeyer): run it all again for the ops cluster
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still relevant?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sadly yes... these checks do nothing to examine the ops cluster. The main cluster is far more likely to fall over and affect users though so the focus is right. These little reminders are where they are because ideally we would literally just run the same high-level methods against a different set of pods/services/etc to do ops cluster checks.

pass


class LoggingErrorList(OpenShiftCheckException):
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this doesn't need to have "Logging" in the name? It could as well sit next to "OpenShiftCheckException" and be an alternative to it? class OpenShiftCheckExceptionList(OpenShiftCheckException)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't sure if it would be useful anywhere else. I'm not sure any other checks have a need to compile a list of failures instead of just quitting on the first. But again, thinking about it... it will probably come up. I guess I'll generalize it.

Copy link
Member Author

Choose a reason for hiding this comment

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

That name is too long though 🤔

@sosiouxme
Copy link
Member Author

@rhcarvalho you saw the bits I thought you'd find interesting. Thanks for the feedback.

I might run the "changed" commit in a different PR; the rest of this is more tedious than I expected.

Copy link
Contributor

@rhcarvalho rhcarvalho left a comment

Choose a reason for hiding this comment

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

LGTM, let's run the tests

@rhcarvalho
Copy link
Contributor

aos-ci-test

@rhcarvalho
Copy link
Contributor

@sosiouxme if this is good to go please remove the [WIP] from the title ;)

@openshift-bot
Copy link

success: "aos-ci-jenkins/OS_3.6_NOT_containerized, aos-ci-jenkins/OS_3.6_NOT_containerized_e2e_tests" for e7e6575 (logs)

@openshift-bot
Copy link

success: "aos-ci-jenkins/OS_3.6_containerized, aos-ci-jenkins/OS_3.6_containerized_e2e_tests" for e7e6575 (logs)

@sosiouxme sosiouxme changed the title [WIP] openshift_checks: refactor check results openshift_checks: refactor check results Jul 31, 2017
@sosiouxme
Copy link
Member Author

It can be good to go. There are a lot of other checks to get the same treatment but there's no need to hold up these changes for that.

Introduced the 'changed' property for checks that can make changes to
track whether they did or not. Rather than the check's own logic having
to track this and include it in the result hash, just set the property
and have the action plugin insert it in the result hash after running
(even if there is an exception).

Cleared out a lot of crufty "changed: false" hash entries.
Turn failure messages into exceptions that tests can look for without
depending on text meant for humans.
Turn logging_namespace property into a method.
Get rid of _exec_oc and just use logging.exec_oc.
@sosiouxme
Copy link
Member Author

aos-ci-test

@openshift-bot
Copy link

success: "aos-ci-jenkins/OS_3.6_NOT_containerized, aos-ci-jenkins/OS_3.6_NOT_containerized_e2e_tests" for 06a6fb9 (logs)

@openshift-bot
Copy link

success: "aos-ci-jenkins/OS_3.6_containerized, aos-ci-jenkins/OS_3.6_containerized_e2e_tests" for 06a6fb9 (logs)

@sosiouxme
Copy link
Member Author

[merge]

@sosiouxme
Copy link
Member Author

sosiouxme commented Aug 7, 2017

@sosiouxme
Copy link
Member Author

sosiouxme commented Aug 8, 2017

@openshift-bot
Copy link

Evaluated for openshift ansible merge up to 06a6fb9

@openshift-bot
Copy link

continuous-integration/openshift-jenkins/merge FAILURE (https://ci.openshift.redhat.com/jenkins/job/merge_pull_request_openshift_ansible/811/) (Base Commit: 0569c50) (PR Branch Commit: 06a6fb9)

@rhcarvalho
Copy link
Contributor

Flake openshift/origin#13977

@rhcarvalho
Copy link
Contributor

@sosiouxme okay for us to manually merge this after the recent changes that merged in?

@sosiouxme
Copy link
Member Author

@rhcarvalho yes that would be nice... enough test failures already.

@rhcarvalho
Copy link
Contributor

@rhcarvalho rhcarvalho merged commit 7121e06 into openshift:master Aug 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants