From 70d0931fcadd5f89b3c82440e6dc4bbdaf71d9e1 Mon Sep 17 00:00:00 2001 From: Oliver Sanders Date: Fri, 9 Jul 2021 10:03:50 +0100 Subject: [PATCH] portability: path mac os dns issues --- .github/workflows/test_fast.yml | 3 --- .github/workflows/test_functional.yml | 3 --- cylc/flow/hostuserutil.py | 19 ++++++++++++++++++- etc/conf/macos-patch | 13 ------------- 4 files changed, 18 insertions(+), 20 deletions(-) delete mode 100644 etc/conf/macos-patch diff --git a/.github/workflows/test_fast.yml b/.github/workflows/test_fast.yml index bc3f40c9076..6545c8f05fb 100644 --- a/.github/workflows/test_fast.yml +++ b/.github/workflows/test_fast.yml @@ -44,9 +44,6 @@ jobs: - name: Brew Install if: startsWith(matrix.os, 'macos') run: | - # apply DNS patch - patch cylc/flow/hostuserutil.py < etc/conf/macos-patch - brew update brew install shellcheck sqlite3 bash coreutils diff --git a/.github/workflows/test_functional.yml b/.github/workflows/test_functional.yml index f10f93b7b45..47d15a6b1d6 100644 --- a/.github/workflows/test_functional.yml +++ b/.github/workflows/test_functional.yml @@ -92,9 +92,6 @@ jobs: - name: Brew Install if: startsWith(matrix.os, 'macos') run: | - # apply DNS patch - patch cylc/flow/hostuserutil.py < etc/conf/macos-patch - # install system deps brew update brew install bash coreutils gnu-sed diff --git a/cylc/flow/hostuserutil.py b/cylc/flow/hostuserutil.py index 3a6099ae82d..9ae71a8fd8a 100644 --- a/cylc/flow/hostuserutil.py +++ b/cylc/flow/hostuserutil.py @@ -44,15 +44,19 @@ """ +from contextlib import suppress import os import pwd import socket -from contextlib import suppress +import sys from time import time from cylc.flow.cfgspec.glbl_cfg import glbl_cfg +IS_MAC_OS = 'darwin' in sys.platform.lower() + + class HostUtil: """host and user ID utility.""" @@ -114,6 +118,19 @@ def _get_host_info(self, target=None): if target not in self._host_exs: if target is None: target = socket.getfqdn() + if ( + IS_MAC_OS + and target == ( + '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.' + '0.0.0.0.0.0.ip6.arpa' + ) + ): + # Python's socket bindings don't play nicely with mac os + # so by default we get the above ip6.arpa adresss from + # socket.getfqdn, note this does *not* match `hostname -f`. + # https://github.com/cylc/cylc-flow/issues/2689 + # https://github.com/cylc/cylc-flow/issues/3595 + target = socket.gethostname() try: self._host_exs[target] = socket.gethostbyname_ex(target) except IOError as exc: diff --git a/etc/conf/macos-patch b/etc/conf/macos-patch deleted file mode 100644 index 51ef158d55e..00000000000 --- a/etc/conf/macos-patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/cylc/flow/hostuserutil.py b/cylc/flow/hostuserutil.py -index 21e51735e..17917b8fc 100644 ---- a/cylc/flow/hostuserutil.py -+++ b/cylc/flow/hostuserutil.py -@@ -113,7 +113,7 @@ class HostUtil: - """Return the extended info of the current host.""" - if target not in self._host_exs: - if target is None: -- target = socket.getfqdn() -+ target = socket.gethostname() - try: - self._host_exs[target] = socket.gethostbyname_ex(target) - except IOError as exc: