volume_api.enable_replication(ctxt, volume)
self.assertTrue(mock_enable_rep.called)
+ def test_enable_replication_driver_initialized(self):
+ volume = tests_utils.create_volume(self.context,
+ size=1,
+ host=CONF.host,
+ replication_status='enabling')
+ # set initialized to False
+ self.volume.driver._initialized = False
+
+ # start test
+ self.assertRaises(exception.DriverNotInitialized,
+ self.volume.enable_replication,
+ self.context,
+ volume)
+
def test_disable_replication_invalid_state(self):
volume_api = cinder.volume.api.API()
ctxt = context.get_admin_context()
volume_api.disable_replication(ctxt, volume)
self.assertTrue(mock_disable_rep.called)
+ def test_disable_replication_driver_initialized(self):
+ volume = tests_utils.create_volume(self.context,
+ size=1,
+ host=CONF.host,
+ replication_status='disabling')
+ # set initialized to False
+ self.volume.driver._initialized = False
+
+ # start test
+ self.assertRaises(exception.DriverNotInitialized,
+ self.volume.disable_replication,
+ self.context,
+ volume)
+
@mock.patch.object(utils, 'brick_get_connector_properties')
@mock.patch.object(cinder.volume.driver.VolumeDriver, '_attach_volume')
@mock.patch.object(cinder.volume.driver.VolumeDriver, '_detach_volume')
:param context: security context
:param volume: volume object returned by DB
"""
+ try:
+ # If the driver isn't initialized, we can't talk to the backend
+ # so the driver can't enable replication
+ utils.require_driver_initialized(self.driver)
+ except exception.DriverNotInitialized:
+ with excutils.save_and_reraise_exception():
+ LOG.error(_LE("Can't enable replication because the "
+ "driver isn't initialized"))
# NOTE(jdg): We're going to do fresh get from the DB and verify that
# we are in an expected state ('enabling')
err_msg = (_("Enable replication for volume failed."))
LOG.exception(err_msg, resource=volume)
raise exception.VolumeBackendAPIException(data=err_msg)
+
try:
if rep_driver_data:
volume = self.db.volume_update(context,
:param context: security context
:param volume: volume object returned by DB
"""
+ try:
+ # If the driver isn't initialized, we can't talk to the backend
+ # so the driver can't enable replication
+ utils.require_driver_initialized(self.driver)
+ except exception.DriverNotInitialized:
+ with excutils.save_and_reraise_exception():
+ LOG.error(_LE("Can't disable replication because the "
+ "driver isn't initialized"))
volume = self.db.volume_get(context, volume['id'])
if volume['replication_status'] != 'disabling':
:param volume: volume object returned by DB
:param secondary: Specifies rep target to fail over to
"""
+ # NOTE(hemna) We intentionally don't enforce the driver being
+ # initialized here. because the primary might actually be down,
+ # but we still want to give the driver a chance of doing some work
+ # against the target. It's entirely up to the driver to deal with
+ # not being able to talk to the primary array that it's configured
+ # to manage.
+
try:
volume = self.db.volume_get(context, volume['id'])
model_update = self.driver.replication_failover(context,
passwords or sensitive information.
"""
+ # NOTE(hemna) We intentionally don't enforce the driver being
+ # initialized here. because the primary might actually be down,
+ # but we still want to give the driver a chance of doing some work
+ # against the target. It's entirely up to the driver to deal with
+ # not being able to talk to the primary array that it's configured
+ # to manage.
try:
volume = self.db.volume_get(context, volume['id'])