Skip to content

Conversation

phlogistonjohn
Copy link
Contributor

A few places in the code try to use a configurable name but others effectively hard-code "ubuntu". Fix these cases to support more flexible user naming.

@zmc
Copy link
Member

zmc commented Jul 25, 2025

This is a good change; let's just get this tested with .e.g. a single scheduled job in sepia

@phlogistonjohn phlogistonjohn changed the title [WIP] teuthology: use test user name from the config teuthology: use test user name from the config Jul 26, 2025
@phlogistonjohn phlogistonjohn marked this pull request as ready for review July 26, 2025 14:40
@phlogistonjohn phlogistonjohn requested a review from a team as a code owner July 26, 2025 14:40
@phlogistonjohn phlogistonjohn requested review from kamoltat and amathuria and removed request for a team July 26, 2025 14:40
@phlogistonjohn
Copy link
Contributor Author

OK, is that something you would like me to do, or something you will take care of?
If me, is there a particular suite or something I should try? I usually just test orch or the smb tests in orch.

@phlogistonjohn
Copy link
Contributor Author

phlogistonjohn commented Aug 4, 2025

https://pulpito.ceph.com/phlogistonjohn-2025-07-31_13:58:12-orch-wip-phlogistonjohn-testing-1-2025-07-22-0801-distro-default-gibba/
I performed this run having applied my patch from this PR on top of the teutholgoy main branch - no issues related to my change that I can see, just a known test flake in the smb orch suite.

# 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 = '.'
Copy link
Contributor

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.

Copy link
Contributor Author

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 like cephtest. However, a few places in the code did not honor that existing configuration parameter.

The function canonicalize_hostname does not treat None 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.

Copy link
Contributor

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:

Copy link
Contributor

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.

Copy link
Contributor

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 function user='.'.

_default_user = '.'

def canonicalize_hostname(hostname, user: Optional[str] = _default_user):
user = get_test_user() if user == _default_user else user
Copy link
Contributor

Choose a reason for hiding this comment

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

The get_test_user already has default value 'ubuntu' for 'test_user' config parameter.

@phlogistonjohn
Copy link
Contributor Author

@zmc ping

@kshtsk
Copy link
Contributor

kshtsk commented Aug 20, 2025

I guess the new behavior can be covered by a unit test, like adding a case to TestHostnames by https://github.com/ceph/teuthology/blob/main/teuthology/test/test_misc.py#L252-L313

A few places in the code try to use a configurable name but others
effectively hard-code "ubuntu". Fix these cases to support more
flexible user naming.

Signed-off-by: John Mulligan <[email protected]>
@kshtsk
Copy link
Contributor

kshtsk commented Aug 28, 2025

% grep -r "'ubuntu'" teuthology | grep user
teuthology/provision/cloud/test/test_openstack.py:        assert userdata['runcmd'][-2:] == [['passwd', '-d', 'ubuntu'], ['touch', '/.teuth_provisioned']]
teuthology/provision/cloud/openstack.py:        user='ubuntu',
teuthology/provision/cloud/base.py:            conf=None, user='ubuntu',
teuthology/provision/downburst.py:    for user in [little_old_me, 'ubuntu', 'teuthology']:
teuthology/provision/downburst.py:    def __init__(self, name, os_type, os_version, status=None, user='ubuntu',
teuthology/openstack/__init__.py:        self.username = 'ubuntu'
teuthology/misc.py:def canonicalize_hostname(hostname, user: Optional[str] ='ubuntu'):
teuthology/misc.py:    return config.get('test_user', 'ubuntu')

Also more places can be updated to respect test_user, like downburst and libcloud open stack.

@phlogistonjohn
Copy link
Contributor Author

@zmc as per our call yesterday: I have apparently been doing tests with this patch applied for weeks. I'm doing one more run today with it today after having rebased on teuthology main.

@phlogistonjohn
Copy link
Contributor Author

Today's test run showed no regressions, FWIW.

@phlogistonjohn
Copy link
Contributor Author

Also, I'd like to keep the scope of this change fairly small - I only really make use of it in my local teuthology setup. It's one where I don't generally test ubuntu based systems at all and feels weird to create a ubuntu user. I don't really expect to change the sepia lab values and start confusing everyone who is already used to this "quirk". Ultimately, I am just trying to carry fewer custom patches for that setup by up-streaming this. Thanks!

@zmc
Copy link
Member

zmc commented Sep 19, 2025

@phlogistonjohn can you link the run here please?

@phlogistonjohn
Copy link
Contributor Author

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