'Test replication failover_host with invalid_target.
When failingover fails due to an invalid target exception we return
replication_status to its previous status, and we decide what that is
depending on the currect active backend.'

@mock.patch('cinder.objects.VolumeList.get_all')
@mock.patch('cinder.volume.driver.BaseVD.failover_host', side_effect=exception.InvalidReplicationTarget(''))
@ddt.data(('backend2', 'default', fields.ReplicationStatus.FAILED_OVER), ('backend2', 'backend3', fields.ReplicationStatus.FAILED_OVER), (None, 'backend2', fields.ReplicationStatus.ENABLED), ('', 'backend2', fields.ReplicationStatus.ENABLED))
@ddt.unpack
def test_failover_host_invalid_target(self, svc_backend, new_backend, expected, mock_failover, mock_getall):

    svc = utils.create_service(self.context, {'host': self.host, 'binary': constants.VOLUME_BINARY, 'active_backend_id': svc_backend, 'replication_status': fields.ReplicationStatus.FAILING_OVER})
    self.manager.failover_host(self.context, new_backend)
    mock_getall.assert_called_once_with(self.context, filters={'host': self.host})
    mock_failover.assert_called_once_with(self.context, [], secondary_id=new_backend, groups=[])
    db_svc = objects.Service.get_by_id(self.context, svc.id)
    self.assertEqual(expected, db_svc.replication_status)
