Repository: DataBiosphere/toil

Issue:
ValueError: badly formed hexadecimal UUID string for singleMachine mode on Mac
I am getting this error only Mac, it works fine on Linux. This is caused by getNodeID() returning at 14 character digit which would be invalid for a UUID.

Version: Latest master, commit: 92c9d23aea219b07f92c37cdf702c81254067357
Full traceback:

```
Traceback (most recent call last):
  File "/Users/kumarn1/work/toil/toil_venv/bin/toil-cwl-runner", line 33, in <module>
    sys.exit(load_entry_point('toil', 'console_scripts', 'toil-cwl-runner')())
  File "/Users/kumarn1/work/toil/toil/src/toil/cwl/cwltoil.py", line 2399, in main
    outobj = toil.start(wf1)
  File "/Users/kumarn1/work/toil/toil/src/toil/common.py", line 813, in start
    self._batchSystem = self.createBatchSystem(self.config)
  File "/Users/kumarn1/work/toil/toil/src/toil/common.py", line 959, in createBatchSystem
    return batch_system(**kwargs)
  File "/Users/kumarn1/work/toil/toil/src/toil/batchSystems/singleMachine.py", line 93, in __init__
    workdir = Toil.getLocalWorkflowDir(config.workflowID, config.workDir)  # config.workDir may be None; this sets a real directory
  File "/Users/kumarn1/work/toil/toil/src/toil/common.py", line 1096, in getLocalWorkflowDir
    workflowDir: str = os.path.join(base, str(uuid.uuid5(uuid.UUID(getNodeID()), workflowID)).replace('-', ''))
  File "/Users/kumarn1/miniconda3/lib/python3.8/uuid.py", line 169, in __init__
    raise ValueError('badly formed hexadecimal UUID string')
ValueError: badly formed hexadecimal UUID string
```

I have a PR ready that will fix this.

┆Issue is synchronized with this [Jira Task](https://ucsc-cgl.atlassian.net/browse/TOIL-893)
┆Issue Number: TOIL-893



Discussion:

Resolving patch:
diff --git a/src/toil/common.py b/src/toil/common.py
--- a/src/toil/common.py
+++ b/src/toil/common.py
@@ -44,6 +44,7 @@
 
 # aim to pack autoscaling jobs within a 30 minute block before provisioning a new node
 defaultTargetTime = 1800
+UUID_LENGTH = 32
 logger = logging.getLogger(__name__)
 
 
@@ -657,7 +658,7 @@ def parseBool(val):
 
 def getNodeID() -> str:
     """
-    Return unique ID of the current node (host).
+    Return unique ID of the current node (host). The resulting string will be convertable to a uuid.UUID.
 
     Tries several methods until success. The returned ID should be identical across calls from different processes on
     the same node at least until the next OS reboot.
@@ -703,6 +704,13 @@ def getNodeID() -> str:
         logger.warning("Failed to generate stable node ID, returning empty string. If you see this message with a "
                        "work dir on a shared file system when using workers running on multiple nodes, you might "
                        "experience cryptic job failures")
+    if len(nodeID.replace('-', '')) < UUID_LENGTH:
+        # Some platforms (Mac) give us not enough actual hex characters.
+        # Repeat them so the result is convertable to a uuid.UUID
+        nodeID = nodeID.replace('-', '')
+        num_repeats = UUID_LENGTH // len(nodeID) + 1
+        nodeID = nodeID * num_repeats
+        nodeID = nodeID[:UUID_LENGTH]
     return nodeID
 
 


Test patch: