Skip to content

Commit a73e32f

Browse files
teuthology: use test user name from the config
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]>
1 parent 6fb2580 commit a73e32f

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

teuthology/misc.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ def host_shortname(hostname):
5151
else:
5252
return hostname.split('.', 1)[0]
5353

54-
def canonicalize_hostname(hostname, user: Optional[str] ='ubuntu'):
54+
# sentinel value to indicate the default user value is to be used.
55+
# None and the empty string are reserved for specifying no user value
56+
# to be backwards compatible with older code.
57+
_default_user = '.'
58+
59+
def canonicalize_hostname(hostname, user: Optional[str] = _default_user):
60+
user = get_test_user() if user == _default_user else user
5561
hostname_expr = hostname_expr_templ.format(
5662
lab_domain=config.lab_domain.replace('.', r'\.'))
5763
match = re.match(hostname_expr, hostname)

teuthology/task/ssh_keys.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,22 @@ def tweak_ssh_config(ctx, config):
9393
"""
9494
Turn off StrictHostKeyChecking
9595
"""
96+
user = misc.get_test_user()
9697
run.wait(
9798
ctx.cluster.run(
9899
args=[
99100
'echo',
100101
'StrictHostKeyChecking no\n',
101102
run.Raw('>'),
102-
run.Raw('/home/ubuntu/.ssh/config'),
103+
run.Raw(f'/home/{user}/.ssh/config'),
103104
run.Raw('&&'),
104105
'echo',
105106
'UserKnownHostsFile ',
106107
run.Raw('/dev/null'),
107108
run.Raw('>>'),
108-
run.Raw('/home/ubuntu/.ssh/config'),
109+
run.Raw(f'/home/{user}/.ssh/config'),
109110
run.Raw('&&'),
110-
run.Raw('chmod 600 /home/ubuntu/.ssh/config'),
111+
run.Raw(f'chmod 600 /home/{user}/.ssh/config'),
111112
],
112113
wait=False,
113114
)
@@ -119,7 +120,7 @@ def tweak_ssh_config(ctx, config):
119120
finally:
120121
run.wait(
121122
ctx.cluster.run(
122-
args=['rm',run.Raw('/home/ubuntu/.ssh/config')],
123+
args=['rm',run.Raw(f'/home/{user}/.ssh/config')],
123124
wait=False
124125
),
125126
)

0 commit comments

Comments
 (0)