Commit 3e56c364 authored by Antoine Millet's avatar Antoine Millet

Handle retry on storage update

parent 3068b6ef
......@@ -17,6 +17,7 @@
"""Helpers for libvirt."""
import logging
import time
from itertools import chain, imap, count
from StringIO import StringIO
from xml.etree import cElementTree as et
......@@ -303,7 +304,7 @@ class StorageIndex(object):
self.paths = None
self.update()
def update(self):
def update(self, retry=1):
"""Update storage pools and volumes."""
# go through all storage pools and check if it is already in the index
for lv_storage in imap(
......@@ -315,7 +316,7 @@ class StorageIndex(object):
):
if lv_storage.name() in self.storages:
# update
self.storages[lv_storage.name()].update()
self.storages[lv_storage.name()].update(retry)
else:
# add storage pool
s = Storage(lv_storage)
......@@ -416,6 +417,7 @@ class Storage(object):
"""Storage abstraction."""
SHARED_TYPES = ['rbd']
REFRESH_RETRY_INTERVAL = 1
def __init__(self, lv_storage):
"""
......@@ -438,9 +440,17 @@ class Storage(object):
def is_shared(self):
return True if self.type in Storage.SHARED_TYPES else False
def update(self):
def update(self, retry=1):
for _ in xrange(retry):
try:
self.lv_storage.refresh()
except libvirt.libvirtError as err:
logger.warning('Unable to refresh storage %s: %s', self.name, err)
time.sleep(self.REFRESH_RETRY_INTERVAL)
else:
break
try:
self.lv_storage.refresh()
self.update_attr()
# update volumes
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment