Commit 6f75fa90 authored by Kirill Smelkov's avatar Kirill Smelkov

fixup! trun: Spawn user test with sole regular uid/gid in /etc/{passwd,group} database

Even though slapos.core tests seem to mock getgrnam calls[1], disk group
is being looked up in /etc/groups for real which fails, if there is no
such group, e.g. as

    ERROR: test_not_existing (slapos.tests.test_slapgrid.TestSlapgridWithDevPermManagerDevPermEmptyLsblk)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/srv/slapgrid/slappart3/t/bvi/i/0/parts/slapos.core/slapos/tests/test_slapgrid.py", line 3246, in setUp
        self.setUpExpected()
      File "/srv/slapgrid/slappart3/t/bvi/i/0/parts/slapos.core/slapos/tests/test_slapgrid.py", line 3230, in setUpExpected
        gid = grp.getgrnam("disk").gr_gid
    KeyError: 'getgrnam(): name not found: disk'

-> Fix it up by also creating "disk" group in our namespace environment.

I'm not sure, but maybe the better long-term fix would be for
slapos.core tests not to access /etc/groups for real and to instead mock
access to this database completely.

Amends commits e6b7993c and b42ccfa5.

/reported-by @tomo
/reported-at nexedi/slapos!1107 (comment 148758)

[1] https://lab.nexedi.com/nexedi/slapos.core/blob/1.7.1-28-g0b6bf2af4/slapos/tests/test_slapformat.py#L160-166
parent 81b1907a
......@@ -265,6 +265,7 @@ TestCase('TESTCASE', %r)
assert captured.err == ''
# we expect only current user, root and nobody/nogroup to be present
# disk group should also be present, at least for now, because slapos.core tests need it
uok = [repr(u) for u in [
pwd.getpwuid(os.getuid()),
pwd.getpwnam('root'),
......@@ -272,7 +273,8 @@ TestCase('TESTCASE', %r)
gok = [repr(g) for g in [
grp.getgrgid(os.getgid()),
grp.getgrnam('root'),
grp.getgrnam('nogroup')]]
grp.getgrnam('nogroup'),
grp.getgrnam('disk')]]
want = '---- 8< ----\n' # XXX won't need this scissors, if we would test trun directly
for _ in sorted(uok) + sorted(gok):
want += _+'\n'
......
......@@ -178,6 +178,10 @@ def run_in_userns(f):
# expect to have zero ID and those names in the user/group database - see e.g.
# https://lab.nexedi.com/nexedi/slapos/merge_requests/1095#note_147177
# https://lab.nexedi.com/nexedi/slapos/merge_requests/1095#note_147201
#
# Include disk group as well as slapos.core tests currently depend on this group being present:
# https://lab.nexedi.com/nexedi/slapos/merge_requests/1107#note_148758
# https://lab.nexedi.com/nexedi/slapos.core/blob/1.7.1-28-g0b6bf2af4/slapos/tests/test_slapgrid.py#L3229-3230
xetc = "/tmp/xetc"
os.mkdir(xetc)
ustr = lambda u: "%s:%s:%d:%d:%s:%s:%s\n" % (u.pw_name, u.pw_passwd, u.pw_uid, u.pw_gid, u.pw_gecos, u.pw_dir, u.pw_shell)
......@@ -189,7 +193,8 @@ def run_in_userns(f):
writefile("%s/group" % xetc,
gstr(grp.getgrgid(os.getgid())) +
gstr(grp.getgrnam("root")) +
gstr(grp.getgrnam("nogroup")))
gstr(grp.getgrnam("nogroup")) +
gstr(grp.getgrnam("disk")))
xrun(["mount", "--bind", xetc+"/passwd", "/etc/passwd"])
xrun(["mount", "--bind", xetc+"/group", "/etc/group"])
def _():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment