Skip to content

Commit

Permalink
Force the removal of the machines
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonRichardson committed May 20, 2019
1 parent 4b88b6f commit 55128b3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
9 changes: 8 additions & 1 deletion acceptancetests/assess_recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,22 @@ def restore_ha(bs_manager, controller_client):
will be in a down state"""
log.info("Restoring HA")
machines_to_remove = []
show_controller(controller_client)
controller_client.show_status()
# pause here, as all the machines can report back as being down, but after
# the pause, one will report back.
controller_client._backend.pause(300)
status = controller_client.get_status(controller=True)
# the order of the machines are normally wrong after a restore, so iterating
# through the machines until you find the correct ones to remove works.
for name, machine in status.iter_machines():
machine_status = machine['juju-status']
if machine_status["current"] == "down":
machines_to_remove.append(name)
if len(machines_to_remove) > 0:
controller_client.show_status()
condition = controller_client.remove_machine(machines_to_remove, force=True, controller=True)
controller_client.wait_for(condition)
show_controller(controller_client)
return enable_ha(bs_manager, controller_client)

def show_controller(client):
Expand Down
8 changes: 4 additions & 4 deletions acceptancetests/jujupy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,9 +857,9 @@ def remove_machine(self, machine_ids, force=False, controller=False):
"""
options = ()
if force:
options = ('--force',)
options = options + ('--force',)
if controller:
options = ('-m', 'controller',)
options = options + ('-m', 'controller',)
self.juju('remove-machine', options + tuple(machine_ids))
return self.make_remove_machine_condition(machine_ids)

Expand Down Expand Up @@ -1693,7 +1693,7 @@ def get_controller_member_status(info_dict):
"""Return the controller-member-status of the machine if it exists."""
return info_dict.get('controller-member-status')

def wait_for_ha(self, timeout=1200, start=None):
def wait_for_ha(self, timeout=1200, start=None, quorum=3):
"""Wait for voiting to be enabled.
May only be called on a controller client."""
Expand All @@ -1710,7 +1710,7 @@ def status_to_ha(status):
continue
states.setdefault(status, []).append(machine)
if list(states.keys()) == [desired_state]:
if len(states.get(desired_state, [])) >= 3:
if len(states.get(desired_state, [])) >= quorum:
return None
return states

Expand Down
2 changes: 1 addition & 1 deletion acceptancetests/jujupy/wait_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def iter_blocking_state(self, status):
if machine in self.machines:
machines.append(machine)
if len(machines) > 0:
yield machine[0], 'still-present'
yield machines[0], 'still-present'

def do_raise(self, model_name, status):
plural = "s"
Expand Down

0 comments on commit 55128b3

Please sign in to comment.