Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 39 additions & 26 deletions coriolis/providers/replicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def _get_session(self):
sess.verify = self._creds["ca_cert"]
return sess

@utils.retry_on_error()
@utils.retry_on_error(sleep_seconds=5)
def get_status(self, device=None, brief=True):
uri = "%s/api/v1/dev" % (self._base_uri)
if device is not None:
Expand Down Expand Up @@ -285,8 +285,14 @@ def _reconnect_ssh(self):
return self._ssh

def init_replicator(self):
self._credentials = utils.retry_on_error()(
self._setup_replicator)(self._ssh)
try:
self._credentials = utils.retry_on_error(sleep_seconds=5)(
self._setup_replicator)(self._ssh)
except Exception:
LOG.warn("Failed to setup replicator, trying to reconnect ssh")
self._reconnect_ssh()
self._credentials = utils.retry_on_error(sleep_seconds=5)(
self._setup_replicator)(self._ssh)
utils.retry_on_error()(
self._init_replicator_client)(self._credentials)
LOG.debug(
Expand Down Expand Up @@ -372,26 +378,29 @@ def attach_new_disk(
new_disks_status = None
new_device_paths = None
for i in range(retry_count):
new_disks_status = self._cli.get_status()
new_device_paths = [dev['device-path']
for dev in new_disks_status]
LOG.debug(
"Polled devices while waiting for disk '%s' to attach "
"(try %d/%d): %s", disk_id, i + 1, retry_count,
new_device_paths)

# check for missing/multiple new device paths:
missing_device_paths = (
set(previous_device_paths) - set(new_device_paths))
if missing_device_paths:
LOG.warn(
"The following devices from the previous disk state qeury "
"are no longer detected: %s", [
dev for dev in previous_disks_status
if dev['device-path'] in missing_device_paths])

new_device_paths = set(
new_device_paths) - set(previous_device_paths)
try:
new_disks_status = self._cli.get_status()
new_device_paths = [dev['device-path']
for dev in new_disks_status]
LOG.debug(
"Polled devices while waiting for disk '%s' to attach "
"(try %d/%d): %s", disk_id, i + 1, retry_count,
new_device_paths)

# check for missing/multiple new device paths:
missing_device_paths = (
set(previous_device_paths) - set(new_device_paths))
if missing_device_paths:
LOG.warn(
"The following devices from the previous disk state "
"qeury are no longer detected: %s", [
dev for dev in previous_disks_status
if dev['device-path'] in missing_device_paths])

new_device_paths = set(
new_device_paths) - set(previous_device_paths)
except Exception:
LOG.debug("Failed to get new device status")
if new_device_paths:
break
else:
Expand Down Expand Up @@ -466,16 +475,20 @@ def update_state(self, state, restart=False):
self.restart()
self._cli._test_connection()

@utils.retry_on_error()
@utils.retry_on_error(sleep_seconds=5)
def _get_ssh_client(self, args):
"""
gets a paramiko SSH client
"""
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(**args)
return ssh
try:
ssh.connect(**args)
return ssh
except Exception:
ssh.close()
raise
except paramiko.ssh_exception.SSHException as ex:
raise exception.CoriolisException(
"Failed to setup SSH client: %s" % str(ex)) from ex
Expand Down
2 changes: 1 addition & 1 deletion coriolis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def get_single_result(lis):
return lis[0]


def retry_on_error(max_attempts=5, sleep_seconds=0,
def retry_on_error(max_attempts=5, sleep_seconds=1,
terminal_exceptions=[]):
def _retry_on_error(func):
@functools.wraps(func)
Expand Down