From b89f2f2f99aa107504a2815d379906a97672d1cc Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Sun, 3 Feb 2019 12:01:10 +0100 Subject: [PATCH] Workaround for driver stats bug Some drivers don't have a working stats cache as they should, and so they return an empty dictionary when we try to retrieve their cached stats by passing refresh=False. On such drivers is HPE's 3PAR. This patch works around this by checking returned value and call it again with refresh=True if the backend doesn't work as it should. --- HISTORY.rst | 2 +- cinderlib/cinderlib.py | 15 +++++++++++++++ cinderlib/exception.py | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index 3920b8b..8018510 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -8,7 +8,7 @@ History - Bug fixes: - Support MultiOpt configuration parameters - + - Workaround for Cinder cached stats bug 0.3.4 (2019-01-26) ------------------ diff --git a/cinderlib/cinderlib.py b/cinderlib/cinderlib.py index aaf1c1c..b5ccdad 100644 --- a/cinderlib/cinderlib.py +++ b/cinderlib/cinderlib.py @@ -38,6 +38,7 @@ from oslo_utils import importutils import urllib3 import cinderlib +from cinderlib import exception from cinderlib import nos_brick from cinderlib import objects from cinderlib import persistence @@ -46,6 +47,8 @@ from cinderlib import serialization __all__ = ['setup', 'Backend'] +LOG = logging.getLogger(__name__) + class Backend(object): """Representation of a Cinder Driver. @@ -120,6 +123,18 @@ class Backend(object): def stats(self, refresh=False): stats_data = self.driver.get_volume_stats(refresh=refresh) + # TODO(geguileo): Remove this workaround for some drivers' bug that + # don't have a working stats cache once they are fixed. + if not refresh and not stats_data: + LOG.warning('Refreshing cache to work around driver stats cache ' + 'bug') + stats_data = self.driver.get_volume_stats(refresh=True) + + if not stats_data: + msg = 'Driver not returning stats data' + LOG.error(msg) + raise exception.VolumeDriverException(message=msg) + # Fill pools for legacy driver reports if stats_data and 'pools' not in stats_data: pool = stats_data.copy() diff --git a/cinderlib/exception.py b/cinderlib/exception.py index 798934f..9915740 100644 --- a/cinderlib/exception.py +++ b/cinderlib/exception.py @@ -21,6 +21,7 @@ VolumeNotFound = exception.VolumeNotFound SnapshotNotFound = exception.SnapshotNotFound ConnectionNotFound = exception.VolumeAttachmentNotFound InvalidVolume = exception.InvalidVolume +VolumeDriverException = exception.VolumeDriverException class InvalidPersistence(Exception):