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

lib/runtime: improve not-master error #1712

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

robbat2
Copy link
Contributor

@robbat2 robbat2 commented Jul 8, 2023

For unclear reasons, there was an environment where the master was running, but the clients did not believe it was the master.

kernel.hostname returned the unqualified hostname, as expected, but the master check was looking for the FQDN.

Improve the error message as a start on making it easier to debug.

Signed-off-by: Robin H. Johnson robbat2@gentoo.org

For unclear reasons, there was an environment where the master was
running, but the clients did not believe it was the master.

kernel.hostname returned the unqualified hostname, as expected, but the
master check was looking for the FQDN.

Improve the error message as a start on making it easier to debug.

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
@robbat2
Copy link
Contributor Author

robbat2 commented Sep 21, 2023

@rbott @atta review please?

raise errors.OpPrereqError("This node, '%s', is not the master node,
" please connect to node '%s' and rerun "
" the command" %
% (myself, master), errors.ECODE_INVAL)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like there is an extra % at the start of the line. Otherwise LGTM.

master, errors.ECODE_INVAL)
# print our own name to aid debugging, esp. re FQDN
# common error is: hostname != hostname.domain.tld
raise errors.OpPrereqError("This node, '%s', is not the master node,
Copy link
Member

Choose a reason for hiding this comment

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

Also there seems a missing double quote at the end:

Exception occurred:
  File "/tmp/gntbuild.kZnFQSGG/ganeti/cli.py", line 62, in <module>
    from ganeti.runtime import (GetClient)
  File "/tmp/gntbuild.kZnFQSGG/ganeti/runtime.py", line 291
    raise errors.OpPrereqError("This node, '%s', is not the master node,
                                                                       ^
SyntaxError: EOL while scanning string literal

Comment on lines +291 to +294
raise errors.OpPrereqError("This node, '%s', is not the master node,
" please connect to node '%s' and rerun "
" the command" %
% (myself, master), errors.ECODE_INVAL)
Copy link
Contributor

Choose a reason for hiding this comment

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

In such cases I personally prefer f-strings

Suggested change
raise errors.OpPrereqError("This node, '%s', is not the master node,
" please connect to node '%s' and rerun "
" the command" %
% (myself, master), errors.ECODE_INVAL)
raise errors.OpPrereqError(f"This node, {myself}, is not the master node, "
f"please connect to node {master} and rerun "
"the command",
errors.ECODE_INVAL)

Perhaps the old %-style should be replaced by f-strings, which are supported in version 3.6?

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for your suggestion. f-strings look pretty readable. However for the moment we stay with the old % style to align with existing code. Maybe in future we can adopt to follow the language authorities standards.

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.

None yet

4 participants