tests/docker: fix a win32 error due to portability

docker.py is run during configure, and produces an error: No module
named 'pwd'.

Use a more portable and recommended alternative to lookup the user
"login name".

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20230306122751.2355515-4-marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau 2023-03-06 16:27:43 +04:00
parent 8467936e3d
commit e387ef472f

View File

@ -23,10 +23,10 @@ import enum
import tempfile
import re
import signal
import getpass
from tarfile import TarFile, TarInfo
from io import StringIO, BytesIO
from shutil import copy, rmtree
from pwd import getpwuid
from datetime import datetime, timedelta
@ -316,7 +316,7 @@ class Docker(object):
if user:
uid = os.getuid()
uname = getpwuid(uid).pw_name
uname = getpass.getuser()
tmp_df.write("\n")
tmp_df.write("RUN id %s 2>/dev/null || useradd -u %d -U %s" %
(uname, uid, uname))
@ -570,7 +570,7 @@ class UpdateCommand(SubCommand):
if args.user:
uid = os.getuid()
uname = getpwuid(uid).pw_name
uname = getpass.getuser()
df.write("\n")
df.write("RUN id %s 2>/dev/null || useradd -u %d -U %s" %
(uname, uid, uname))