-
Notifications
You must be signed in to change notification settings - Fork 308
teuthology: use test user name from the config #2071
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
Open
phlogistonjohn
wants to merge
1
commit into
ceph:main
Choose a base branch
from
phlogistonjohn:jjm-hax-2025
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,15 @@ def host_shortname(hostname): | |
else: | ||
return hostname.split('.', 1)[0] | ||
|
||
def canonicalize_hostname(hostname, user: Optional[str] ='ubuntu'): | ||
# sentinel value to indicate the default user value is to be used. | ||
# None and the empty string are reserved for specifying no user value | ||
# to be backwards compatible with older code. | ||
_default_user = '.' | ||
|
||
def canonicalize_hostname( | ||
hostname: str, user: Optional[str] = _default_user | ||
) -> str: | ||
user = get_test_user() if user == _default_user else user | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
hostname_expr = hostname_expr_templ.format( | ||
lab_domain=config.lab_domain.replace('.', r'\.')) | ||
match = re.match(hostname_expr, hostname) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand this, why 'None' does not work, in the context of the change it is the same.
Introducing the _default_user with value '.', instead of, for example, 'ubuntu', overcomplicates the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the comment doesn't explain the situation enough. The issue at hand is twofold - I do not want to use the username
ubuntu
on my test systems, I find it confusing as I mainly test on non-ubuntu systems. I have my teuthology configuration use something likecephtest
. However, a few places in the code did not honor that existing configuration parameter.The function
canonicalize_hostname
does not treatNone
as meaning "use the default user from the config" it is something more like "don't include a username component in the resulting hostname string".I did not want to change this behavior because I didn't want to have to find all the existing callers and potentially change them.
I did consider making a sentinel object - like
_deafult_user = object()
but that would require a change to the type annotation and I thought that'd be ugly. I thought '.' seems like an obvious and safe sentinel value as it's not a real username and is akin to "here" in unix file systems and some other tools.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understood, the cannonicalize_hostname takes user name defaults = 'ubuntu', when user is None, it should return hostname without any user "@" suffix.
I don't think we ever used user=None. However you're saying that it would
be still useful to keep this possibility to suppress any user.
I would suggest to drop the comment above, and instead add doctoring for the
canonicalize_hostname
adding description of what is expected to be done and parameters and return value.And as soon as we're touching the function signature, could you please add return typing for it, like
-> str:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And instead of confusing
_default_user
it would be better to user self descriptive naming. Since_canonicalize_hostname_default_user_sentinel
is too long, maybe just use_default_user_sentinel
or_user_sentinel
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understand about sentinel pattern the default value is just an
object()
, but I am not strictly against longly.
character, it just looks strange, and introduce hidden behavior, in case someone call the functionuser='.'
.