Repository: easybuilders/easybuild-easyblocks

Issue:
OpenFOAM sanity check requires write permission in installation directory
The OpenFOAM easyblock can currently not be used with `--module-only` unless you have write permissions to the installation directory:

```
== 2021-04-27 09:24:02,719 build_log.py:169 ERROR EasyBuild crashed with an error (at easybuild/software/EasyBuild/4.3.4/lib/python3.8/site-packages/easybuild/base/exceptions.py:124 in __init__): Sanity check failed: sanity check command cp -a /cvmfs/pilot.eessi-hpc.org/2021.03/software/linux/x86_64/amd/zen2/software/OpenFOAM/8-foss-2020a/OpenFOAM-8/tutorials/incompressible/simpleFoam/motorBike /cvmfs/pilot.eessi-hpc.org/2021.03/software/linux/x86_64/amd/zen2/software/OpenFOAM/8-foss-2020a && cd /cvmfs/pilot.eessi-hpc.org/2021.03/software/linux/x86_64/amd/zen2/software/OpenFOAM/8-foss-2020a/motorBike && source $FOAM_BASH && . $WM_PROJECT_DIR/bin/tools/RunFunctions && cp $FOAM_TUTORIALS/resources/geometry/motorBike.obj.gz constant/triSurface/ && runApplication surfaceFeatures && runApplication blockMesh && runApplication decomposePar -copyZero && runParallel snappyHexMesh -overwrite && runParallel patchSummary && runParallel potentialFoam && runParallel simpleFoam && runApplication reconstructParMesh -constant && runApplication reconstructPar -latestTime && cd /cvmfs/pilot.eessi-hpc.org/2021.03/software/linux/x86_64/amd/zen2/software/OpenFOAM/8-foss-2020a && rm -r motorBike exited with code 1 (output: cp: cannot create directory '/cvmfs/pilot.eessi-hpc.org/2021.03/software/linux/x86_64/amd/zen2/software/OpenFOAM/8-foss-2020a/motorBike': Read-only file system
```


Discussion:

Resolving patch:
diff --git a/easybuild/easyblocks/o/openfoam.py b/easybuild/easyblocks/o/openfoam.py
--- a/easybuild/easyblocks/o/openfoam.py
+++ b/easybuild/easyblocks/o/openfoam.py
@@ -40,6 +40,7 @@
 import re
 import shutil
 import stat
+import tempfile
 from distutils.version import LooseVersion
 
 import easybuild.tools.environment as env
@@ -489,9 +490,10 @@ def sanity_check_step(self):
             openfoamdir_path = os.path.join(self.installdir, self.openfoamdir)
             motorbike_path = os.path.join(openfoamdir_path, 'tutorials', 'incompressible', 'simpleFoam', 'motorBike')
             if os.path.exists(motorbike_path):
+                test_dir = tempfile.mkdtemp()
                 cmds = [
-                    "cp -a %s %s" % (motorbike_path, self.builddir),
-                    "cd %s" % os.path.join(self.builddir, os.path.basename(motorbike_path)),
+                    "cp -a %s %s" % (motorbike_path, test_dir),
+                    "cd %s" % os.path.join(test_dir, os.path.basename(motorbike_path)),
                     "source $FOAM_BASH",
                     ". $WM_PROJECT_DIR/bin/tools/RunFunctions",
                     "cp $FOAM_TUTORIALS/resources/geometry/motorBike.obj.gz constant/triSurface/",
@@ -505,7 +507,7 @@ def sanity_check_step(self):
                     "runApplication reconstructParMesh -constant",
                     "runApplication reconstructPar -latestTime",
                     "cd %s" % self.builddir,
-                    "rm -r %s" % os.path.basename(motorbike_path),
+                    "rm -r %s" % test_dir,
                 ]
                 # all commands need to be run in a single shell command,
                 # because sourcing $FOAM_BASH sets up environment


Test patch: