Repository: dask/distributed

Issue:
worker : params processing done twice (nanny and worker)
When starting a worker with set `temprary-directory`, the `dask-worker-space` suffix is joined twice.

```
(pydata) ali@localhost:~/hacks/pydata$ cat "${DASK_CONFIG}/dask.yaml" | grep temporary
temporary-directory: '/tmp'
(pydata) ali@localhost:~/hacks/pydata$ dask-worker tcp://localhost:8786
nanny -> /tmp
distributed.nanny - INFO -         Start Nanny at: 'tcp://127.0.0.1:37347'
worker -> /tmp/dask-worker-space
distributed.worker - INFO -       Start worker at:      tcp://127.0.0.1:45815
distributed.worker - INFO -          Listening to:      tcp://127.0.0.1:45815
distributed.worker - INFO -          dashboard at:            127.0.0.1:33133
distributed.worker - INFO - Waiting to connect to:       tcp://localhost:8786
distributed.worker - INFO - -------------------------------------------------
distributed.worker - INFO -               Threads:                          1
distributed.worker - INFO -                Memory:                    2.08 GB
distributed.worker - INFO -       Local Directory: /tmp/dask-worker-space/dask-worker-space/worker-mauez8mj
distributed.worker - INFO - -------------------------------------------------
distributed.worker - INFO -         Registered to:       tcp://localhost:8786
distributed.worker - INFO - -------------------------------------------------
distributed.core - INFO - Starting established connection
```
The issue here is that the path is processed twice : Nanny and Worker

More generally, I think that parameters verification logic is duplicated on both classes and probably needs to be consolidated on one side for maintenance reasons (probably the worker since the nanny is just a wrapper)

**Environment**:

- Dask version: 2021.02.0+20.g1c9a9622
- Python version: 3.8.5
- Operating System: Ubuntu 20.04
- Install method (conda, pip, source): source


Discussion:
I an confirm this, will look into a fix.

Resolving patch:
diff --git a/distributed/nanny.py b/distributed/nanny.py
--- a/distributed/nanny.py
+++ b/distributed/nanny.py
@@ -168,7 +168,10 @@ def __init__(
             local_directory = dask.config.get("temporary-directory") or os.getcwd()
             if not os.path.exists(local_directory):
                 os.makedirs(local_directory)
+            self._original_local_dir = local_directory
             local_directory = os.path.join(local_directory, "dask-worker-space")
+        else:
+            self._original_local_dir = local_directory
 
         self.local_directory = local_directory
 
@@ -333,7 +336,7 @@ async def instantiate(self, comm=None) -> Status:
             worker_kwargs = dict(
                 scheduler_ip=self.scheduler_addr,
                 nthreads=self.nthreads,
-                local_directory=self.local_directory,
+                local_directory=self._original_local_dir,
                 services=self.services,
                 nanny=self.address,
                 name=self.name,


Test patch:
diff --git a/distributed/tests/test_nanny.py b/distributed/tests/test_nanny.py
--- a/distributed/tests/test_nanny.py
+++ b/distributed/tests/test_nanny.py
@@ -410,6 +410,7 @@ async def test_local_directory(s):
             w = await Nanny(s.address)
             assert w.local_directory.startswith(fn)
             assert "dask-worker-space" in w.local_directory
+            assert w.process.worker_dir.count("dask-worker-space") == 1
             await w.close()