'Test manager\'s failover method for clustered and not clustered.'

@ddt.data(None, 'cluster_name')
@mock.patch('cinder.volume.manager.VolumeManager.finish_failover')
@mock.patch('cinder.volume.manager.VolumeManager._get_my_volumes')
def test_failover_manager(self, cluster, get_vols_mock, finish_mock):

    rep_field = fields.ReplicationStatus
    svc = objects.Service(self.context, host=self.volume.host, binary=constants.VOLUME_BINARY, cluster_name=cluster, replication_status=rep_field.ENABLED)
    svc.create()
    vol = objects.Volume(self.context, host=self.volume.host)
    vol.create()
    get_vols_mock.return_value = [vol]
    with mock.patch.object(self.volume, 'driver') as driver:
        (called, not_called) = (driver.failover_host, driver.failover)
        if cluster:
            (called, not_called) = (not_called, called)
        called.return_value = ('secondary', [{'volume_id': vol.id, 'updates': {'status': 'error'}}], [])
        self.volume.failover(self.context, secondary_backend_id='secondary')
    not_called.assert_not_called()
    called.assert_called_once_with(self.context, [vol], secondary_id='secondary', groups=[])
    expected_update = {'replication_status': rep_field.FAILED_OVER, 'active_backend_id': 'secondary', 'disabled': True, 'disabled_reason': 'failed-over'}
    finish_mock.assert_called_once_with(self.context, svc, expected_update)
    volume = objects.Volume.get_by_id(self.context, vol.id)
    self.assertEqual('error', volume.status)
