Merge "Remove some no-use code about failover"

This commit is contained in:
Zuul 2017-12-29 01:26:07 +00:00 committed by Gerrit Code Review
commit dfaf35ebeb
2 changed files with 14 additions and 38 deletions

View File

@ -1757,22 +1757,6 @@ class RBDTestCase(test.TestCase):
self.driver.failover_host, self.driver.failover_host,
self.context, volumes, None, []) self.context, volumes, None, [])
def test_failover_volume_non_replicated(self):
self.volume_a.replication_status = fields.ReplicationStatus.DISABLED
remote = {'name': 'name', 'user': 'user', 'conf': 'conf',
'pool': 'pool'}
expected = {
'volume_id': self.volume_a.id,
'updates': {
'status': 'error',
'previous_status': self.volume_a.status,
'replication_status': fields.ReplicationStatus.NOT_CAPABLE,
}
}
res = self.driver._failover_volume(
self.volume_a, remote, False, fields.ReplicationStatus.FAILED_OVER)
self.assertEqual(expected, res)
@ddt.data(True, False) @ddt.data(True, False)
@mock.patch.object(driver.RBDDriver, '_exec_on_volume', @mock.patch.object(driver.RBDDriver, '_exec_on_volume',
side_effect=Exception) side_effect=Exception)

View File

@ -1026,7 +1026,7 @@ class RBDDriver(driver.CloneableImageVD,
def _failover_volume(self, volume, remote, is_demoted, replication_status): def _failover_volume(self, volume, remote, is_demoted, replication_status):
"""Process failover for a volume. """Process failover for a volume.
There are 3 different cases that will return different update values There are 2 different cases that will return different update values
for the volume: for the volume:
- Volume has replication enabled and failover succeeded: Set - Volume has replication enabled and failover succeeded: Set
@ -1034,31 +1034,23 @@ class RBDDriver(driver.CloneableImageVD,
- Volume has replication enabled and failover fails: Set status to - Volume has replication enabled and failover fails: Set status to
error, replication status to failover-error, and store previous error, replication status to failover-error, and store previous
status in previous_status field. status in previous_status field.
- Volume replication is disabled: Set status to error, and store
status in previous_status field.
""" """
# Failover is allowed when volume has it enabled or it has already # Failover is allowed when volume has it enabled or it has already
# failed over, because we may want to do a second failover. # failed over, because we may want to do a second failover.
if self._is_replicated_type(volume.volume_type): vol_name = utils.convert_str(volume.name)
vol_name = utils.convert_str(volume.name) try:
try: self._exec_on_volume(vol_name, remote,
self._exec_on_volume(vol_name, remote, 'mirror_image_promote', not is_demoted)
'mirror_image_promote', not is_demoted)
return {'volume_id': volume.id, return {'volume_id': volume.id,
'updates': {'replication_status': replication_status}} 'updates': {'replication_status': replication_status}}
except Exception as e: except Exception as e:
replication_status = fields.ReplicationStatus.FAILOVER_ERROR replication_status = fields.ReplicationStatus.FAILOVER_ERROR
LOG.error('Failed to failover volume %(volume)s with ' LOG.error('Failed to failover volume %(volume)s with '
'error: %(error)s.', 'error: %(error)s.',
{'volume': volume.name, 'error': e}) {'volume': volume.name, 'error': e})
else:
replication_status = fields.ReplicationStatus.NOT_CAPABLE
LOG.debug('Skipping failover for non replicated volume '
'%(volume)s with status: %(status)s',
{'volume': volume.name, 'status': volume.status})
# Failover did not happen # Failover failed
error_result = { error_result = {
'volume_id': volume.id, 'volume_id': volume.id,
'updates': { 'updates': {
@ -1076,7 +1068,7 @@ class RBDDriver(driver.CloneableImageVD,
try_demoting = True try_demoting = True
for volume in volumes: for volume in volumes:
demoted = False demoted = False
if try_demoting and self._is_replicated_type(volume.volume_type): if try_demoting:
vol_name = utils.convert_str(volume.name) vol_name = utils.convert_str(volume.name)
try: try:
self._exec_on_volume(vol_name, self._active_config, self._exec_on_volume(vol_name, self._active_config,