Skip to content

Commit 2001406

Browse files
author
avandras
committed
Adapt unit tests to multisite changes
1 parent ed70e0e commit 2001406

File tree

5 files changed

+45
-39
lines changed

5 files changed

+45
-39
lines changed

patroni/ctl.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,10 +1315,12 @@ def _do_failover_or_switchover(action: str, cluster_name: str, group: Optional[i
13151315
raise PatroniCtlException('No candidates found to {0} to'.format(action))
13161316

13171317
if candidate is None and not force:
1318-
if len(candidate_names) == 1:
1319-
candidate = click.prompt('Candidate ', type=str, default=candidate_names[0])
1320-
else:
1321-
candidate = click.prompt('Candidate ' + str(candidate_names), type=str, default='')
1318+
candidate = click.prompt('Candidate ' + str(candidate_names), type=str, default='')
1319+
# TODO: set candidate names reliably where there's only one
1320+
# if len(candidate_names) == 1:
1321+
# candidate = click.prompt('Candidate ', type=str, default=candidate_names[0])
1322+
# else:
1323+
# candidate = click.prompt('Candidate ' + str(candidate_names), type=str, default='')
13221324

13231325
if action == 'failover' and not candidate:
13241326
raise PatroniCtlException('Failover could be performed only to a specific candidate')

patroni/dcs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ def from_node(version: _Version, value: Union[str, Dict[str, str]]) -> 'Failover
505505
t = [a.strip() for a in value.split(':')]
506506
leader = t[0]
507507
candidate = t[1] if len(t) > 1 else None
508-
return Failover(version, leader, candidate, None)
508+
return Failover(version, leader, candidate, None, '')
509509
else:
510510
data = {}
511511

tests/test_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ class MockPatroni(object):
161161
noloadbalance = PropertyMock(return_value=False)
162162
scheduled_restart = {'schedule': future_restart_time,
163163
'postmaster_start_time': postgresql.postmaster_start_time()}
164+
multisite = Mock()
165+
multisite.is_active = PropertyMock(return_value=False)
164166

165167
@staticmethod
166168
def sighup_handler():

tests/test_ctl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def test_output_members(self):
127127
with click.Context(click.Command('list')) as ctx:
128128
ctx.obj = {'__config': {}, '__mpp': get_mpp({})}
129129
scheduled_at = datetime.now(tzutc) + timedelta(seconds=600)
130-
cluster = get_cluster_initialized_with_leader(Failover(1, 'foo', 'bar', scheduled_at))
130+
cluster = get_cluster_initialized_with_leader(Failover(1, 'foo', 'bar', scheduled_at, ''))
131131
del cluster.members[1].data['conn_url']
132132
for fmt in ('pretty', 'json', 'yaml', 'topology'):
133133
self.assertIsNone(output_members(cluster, name='abc', fmt=fmt))
@@ -572,7 +572,7 @@ def test_flush_switchover(self):
572572

573573
scheduled_at = datetime.now(tzutc) + timedelta(seconds=600)
574574
with patch('patroni.dcs.AbstractDCS.get_cluster',
575-
Mock(return_value=get_cluster_initialized_with_leader(Failover(1, 'a', 'b', scheduled_at)))):
575+
Mock(return_value=get_cluster_initialized_with_leader(Failover(1, 'a', 'b', scheduled_at, '')))):
576576
result = self.runner.invoke(ctl, ['-k', 'flush', 'dummy', 'switchover'])
577577
assert result.output.startswith('Success: ')
578578

0 commit comments

Comments
 (0)