1
0
mirror of https://github.com/ARM-software/devlib.git synced 2024-10-05 18:30:50 +01:00

target: Check command output sanity

Check that no element in the chain adds any unwanted content to stdout
or stderr when running a command. This is especially important as PAM
modules can just write arbitrary messages to stdout when using sudo,
such as password expiry notification. There unfortunately seems to be no
way of silencing it, but we can at least catch it before it triggers
errors down the line.
This commit is contained in:
Douglas Raillard 2024-09-24 10:52:08 +01:00
parent f42156028c
commit b0a394a507

View File

@ -535,9 +535,17 @@ class Target(object):
"""
Check that the connection works without obvious issues.
"""
out = await self.execute.asyn('true', as_root=False)
if out.strip():
raise TargetStableError('The shell seems to not be functional and adds content to stderr: {}'.format(out))
async def check(**kwargs):
out = await self.execute.asyn('true', **kwargs)
if out:
raise TargetStableError('The shell seems to not be functional and adds content to stderr: {!r}'.format(out))
await check(as_root=False)
# If we are rooted, we usually run with sudo. Unfortunately, PAM
# modules can write random text to stdout such as:
# Your password will expire in XXX days.
if self.is_rooted:
await check(as_root=True)
def disconnect(self):
connections = self._conn.get_all_values()