Skip to content

Commit

Permalink
Make passwd and group files are available during tests
Browse files Browse the repository at this point in the history
  • Loading branch information
awicenec committed Feb 22, 2022
1 parent 127b188 commit 4597772
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
6 changes: 3 additions & 3 deletions daliuge-engine/dlg/apps/dockerapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ def initialize(self, **kwargs):
# on the host system. They are given either as a list or as a
# comma-separated string
self._additionalBindings = {}
bindings = [f"{DLG_ROOT}:{DLG_ROOT}",
f"{DLG_ROOT}/workspace/settings/passwd:/etc/passwd",
f"{DLG_ROOT}/workspace/settings/group:/etc/group"
bindings = [f"{utils.getDlgDir()}:{utils.getDlgDir()}",
f"{utils.getDlgDir()}/workspace/settings/passwd:/etc/passwd",
f"{utils.getDlgDir()}/workspace/settings/group:/etc/group"
]
bindings += self._getArg(kwargs, "additionalBindings", [])
bindings = bindings.split(",") if isinstance(bindings, str) else bindings
Expand Down
14 changes: 10 additions & 4 deletions daliuge-engine/dlg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@ def getDlgDir():
runtime.
"""
if "DLG_ROOT" in os.environ:
return os.environ["DLG_ROOT"]
return os.path.join(os.path.expanduser("~"), "dlg")
path = os.environ["DLG_ROOT"]
else:
path = os.path.join(os.path.expanduser("~"), "dlg")
os.environ["DLG_ROOT"] = path
logger.debug(f"DLG_ROOT directory is {path}")
return path


def getDlgPidDir():
Expand Down Expand Up @@ -494,7 +498,7 @@ def wait(self):
time.sleep(0.1)


def prepareUser(DLG_ROOT="."):
def prepareUser(DLG_ROOT=getDlgDir()):
workdir = f"{DLG_ROOT}/workspace/settings"
try:
os.makedirs(workdir, exist_ok=True)
Expand All @@ -508,11 +512,13 @@ def prepareUser(DLG_ROOT="."):
with open(os.path.join(workdir, "passwd"), "wt") as file:
file.write(open(os.path.join(template_dir, "passwd.template"), "rt").read())
file.write(f"{pw.pw_name}:x:{pw.pw_uid}:{pw.pw_gid}:{pw.pw_gecos}:{DLG_ROOT}:/bin/bash\n")
logger.debug(f"passwd file written {file.name}")
with open(os.path.join(workdir, "group"), "wt") as file:
file.write(open(os.path.join(template_dir, "group.template"), "rt").read())
file.write(f"{gr.gr_name}:x:{gr.gr_gid}:\n")
file.write(f"docker:x:{dgr.gr_gid}\n")

logger.debug(f"Group file written {file.name}")

return dgr.gr_gid


Expand Down
11 changes: 8 additions & 3 deletions daliuge-engine/test/apps/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# MA 02111-1307 USA
#

from asyncio.log import logger
import os
import shutil
import tempfile
Expand Down Expand Up @@ -60,10 +61,14 @@ def setUpClass(cls):
if cls._temp is None:
cls._temp = "/tmp/daliuge_tfiles"

os.environ["DLG_ROOT"] = cls._temp
logger.info(f"Preparing pwd and group files in {utils.getDlgDir()}")
_dum = utils.prepareUser(DLG_ROOT=utils.getDlgDir())

def tearDown(self):
shutil.rmtree("/tmp/daliuge_tfiles", True)
@classmethod
def tearDownClass(cls):
logger.debug(f"Removing temp directory {cls._temp}")
shutil.rmtree(cls._temp, True)

def test_simpleCopy(self):
"""
Expand Down Expand Up @@ -127,7 +132,7 @@ def test_clientServer(self):
b.handleInterest(c)

data = os.urandom(10)
with DROPWaiterCtx(self, d, 100):
with DROPWaiterCtx(self, d, 10):
a.write(data)
a.setCompleted()

Expand Down

0 comments on commit 4597772

Please sign in to comment.