'Test failover_host.'

@mock.patch.object(kaminario_common.KaminarioCinderDriver, '_check_for_status')
@mock.patch.object(objects.service.Service, 'get_by_args')
def test_failover_host(self, get_by_args, check_stauts):

    mock_args = mock.Mock()
    mock_args.active_backend_id = '10.0.0.1'
    self.vol.replication_status = 'failed-over'
    self.driver.configuration.san_ip = '10.0.0.1'
    get_by_args.side_effect = [mock_args, mock_args]
    self.driver.host = 'host'
    volumes = [self.vol, self.vol]
    self.driver.replica = Replication()
    self.driver.target = FakeKrest()
    self.driver.target.search().total = 1
    self.driver.client.search().total = 1
    (backend_ip, res_volumes, __) = self.driver.failover_host(None, volumes, [])
    self.assertEqual('10.0.0.1', backend_ip)
    status = res_volumes[0]['updates']['replication_status']
    self.assertEqual(fields.ReplicationStatus.FAILED_OVER, status)
    self.driver.configuration.san_ip = '10.0.0.2'
    self.driver.client.search().hits[0].state = 'in_sync'
    (backend_ip, res_volumes, __) = self.driver.failover_host(None, volumes, [])
    self.assertEqual('10.0.0.2', backend_ip)
    status = res_volumes[0]['updates']['replication_status']
    self.assertEqual(fields.ReplicationStatus.DISABLED, status)
