diff --git a/patroni/ctl.py b/patroni/ctl.py index 4f2fcd0b..d473da01 100644 --- a/patroni/ctl.py +++ b/patroni/ctl.py @@ -942,7 +942,7 @@ def toggle_pause(config, cluster_name, paused, wait): raise PatroniCtlException('Cluster is {0} paused'.format(paused and 'already' or 'not')) members = [] - if cluster.leader: + if cluster.leader and cluster.leader.member.api_url: members.append(cluster.leader.member) members.extend([m for m in cluster.members if m.api_url and (not members or members[0].name != m.name)]) @@ -1008,7 +1008,7 @@ def show_diff(before_editing, after_editing): If the output is to a tty the diff will be colored. Inputs are expected to be unicode strings. """ def listify(string): - return [l+'\n' for l in string.rstrip('\n').split('\n')] + return [line + '\n' for line in string.rstrip('\n').split('\n')] unified_diff = difflib.unified_diff(listify(before_editing), listify(after_editing)) diff --git a/patroni/ha.py b/patroni/ha.py index 5deb2d80..c0655ea0 100644 --- a/patroni/ha.py +++ b/patroni/ha.py @@ -523,7 +523,7 @@ class Ha(object): if cluster_history: self.dcs.set_history_value('[]') elif not cluster_history or cluster_history[-1][0] != master_timeline - 1 or len(cluster_history[-1]) != 4: - cluster_history = {l[0]: l for l in cluster_history or []} + cluster_history = {line[0]: line for line in cluster_history or []} history = self.state_handler.get_history(master_timeline) if history: history = history[-self.cluster.config.max_timelines_history:] diff --git a/patroni/postgresql/__init__.py b/patroni/postgresql/__init__.py index b0565968..566494db 100644 --- a/patroni/postgresql/__init__.py +++ b/patroni/postgresql/__init__.py @@ -655,7 +655,6 @@ class Postgresql(object): def controldata(self): """ return the contents of pg_controldata, or non-True value if pg_controldata call failed """ - result = {} # Don't try to call pg_controldata during backup restore if self._version_file_exists() and self.state != 'creating replica': try: @@ -663,13 +662,12 @@ class Postgresql(object): env.update(LANG='C', LC_ALL='C') data = subprocess.check_output([self.pgcommand('pg_controldata'), self._data_dir], env=env) if data: - data = data.decode('utf-8').splitlines() + data = filter(lambda e: ':' in e, data.decode('utf-8').splitlines()) # pg_controldata output depends on major version. Some of parameters are prefixed by 'Current ' - result = {l.split(':')[0].replace('Current ', '', 1): l.split(':', 1)[1].strip() for l in data - if l and ':' in l} + return {k.replace('Current ', '', 1): v.strip() for k, v in map(lambda e: e.split(':', 1), data)} except subprocess.CalledProcessError: logger.exception("Error when calling pg_controldata") - return result + return {} @contextmanager def get_replication_connection_cursor(self, host='localhost', port=5432, **kwargs):