self.assertEqual(1, mock_driver._disconnect_from_rados.call_count)
@common_mocks
- def test_connect_to_rados(self):
+ @mock.patch('time.sleep')
+ def test_connect_to_rados(self, sleep_mock):
# Default
self.cfg.rados_connect_timeout = -1
self.assertRaises(exception.VolumeBackendAPIException,
self.driver._connect_to_rados)
self.assertTrue(self.mock_rados.Rados.return_value.open_ioctx.called)
- self.mock_rados.Rados.return_value.shutdown.assert_called_once_with()
+ self.assertEqual(
+ 3, self.mock_rados.Rados.return_value.shutdown.call_count)
class RBDImageIOWrapperTestCase(test.TestCase):
from cinder.i18n import _, _LE, _LI, _LW
from cinder.image import image_utils
from cinder.openstack.common import fileutils
+from cinder import utils
from cinder.volume import driver
try:
cfg.IntOpt('rados_connect_timeout', default=-1,
help=_('Timeout value (in seconds) used when connecting to '
'ceph cluster. If value < 0, no timeout is set and '
- 'default librados value is used.'))
+ 'default librados value is used.')),
+ cfg.IntOpt('rados_connection_retries', default=3,
+ help=_('Number of retries if connection to ceph cluster '
+ 'failed.')),
+ cfg.IntOpt('rados_connection_interval', default=5,
+ help=_('Interval value (in seconds) between connection '
+ 'retries to ceph cluster.'))
]
CONF = cfg.CONF
args.extend(['--cluster', self.configuration.rbd_cluster_name])
return args
+ @utils.retry(exception.VolumeBackendAPIException,
+ CONF.rados_connection_interval,
+ CONF.rados_connection_retries)
def _connect_to_rados(self, pool=None):
LOG.debug("opening connection to ceph cluster (timeout=%s).",
self.configuration.rados_connect_timeout)
except self.rados.Error:
msg = _("Error connecting to ceph cluster.")
LOG.exception(msg)
- # shutdown cannot raise an exception
client.shutdown()
raise exception.VolumeBackendAPIException(data=msg)