From 22044540946dbaef68c36ec45d5d5cdceb43c402 Mon Sep 17 00:00:00 2001 From: Ants Aasma Date: Mon, 11 Mar 2019 13:31:06 +0200 Subject: [PATCH] Remove unnecessary usage of relpath (#1002) `os.path.relpath` depends on being able to resolve the working directory. This will fail if Patroni is started in a directory that is later unlinked from the filesystem, creating an unnecessary exception when loading from DCS. --- patroni/dcs/consul.py | 2 +- patroni/dcs/etcd.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/patroni/dcs/consul.py b/patroni/dcs/consul.py index 278262b0..ded2776e 100644 --- a/patroni/dcs/consul.py +++ b/patroni/dcs/consul.py @@ -299,7 +299,7 @@ class Consul(AbstractDCS): nodes = {} for node in results: node['Value'] = (node['Value'] or b'').decode('utf-8') - nodes[os.path.relpath(node['Key'], path).replace('\\', '/')] = node + nodes[node['Key'][len(path):].lstrip('/')] = node # get initialize flag initialize = nodes.get(self._INITIALIZE) diff --git a/patroni/dcs/etcd.py b/patroni/dcs/etcd.py index a133538c..5fbf0f34 100644 --- a/patroni/dcs/etcd.py +++ b/patroni/dcs/etcd.py @@ -454,7 +454,7 @@ class Etcd(AbstractDCS): def _load_cluster(self): try: result = self.retry(self._client.read, self.client_path(''), recursive=True) - nodes = {os.path.relpath(node.key, result.key).replace('\\', '/'): node for node in result.leaves} + nodes = {node.key[len(result.key):].lstrip('/'): node for node in result.leaves} # get initialize flag initialize = nodes.get(self._INITIALIZE)