'Verifies sort order with pagination for deleted instances.'

def test_instance_get_deleted_by_filters_sort_keys_paginate(self, mock_get_regexp):

    ctxt = context.get_admin_context()
    test1_active = self.create_instance_with_args(display_name='test1', vm_state=vm_states.ACTIVE)
    db.instance_destroy(ctxt, test1_active['uuid'])
    test1_error = self.create_instance_with_args(display_name='test1', vm_state=vm_states.ERROR)
    db.instance_destroy(ctxt, test1_error['uuid'])
    test1_error2 = self.create_instance_with_args(display_name='test1', vm_state=vm_states.ERROR)
    db.instance_destroy(ctxt, test1_error2['uuid'])
    test2_active = self.create_instance_with_args(display_name='test2', vm_state=vm_states.ACTIVE)
    db.instance_destroy(ctxt, test2_active['uuid'])
    test2_error = self.create_instance_with_args(display_name='test2', vm_state=vm_states.ERROR)
    db.instance_destroy(ctxt, test2_error['uuid'])
    test2_error2 = self.create_instance_with_args(display_name='test2', vm_state=vm_states.ERROR)
    db.instance_destroy(ctxt, test2_error2['uuid'])
    self.create_instance_with_args(display_name='other')
    self.create_instance_with_args(display_name='other')
    filters = {'display_name': '%test%', 'deleted': True}
    sort_keys = ['display_name', 'vm_state', 'created_at']
    sort_dirs = ['asc', 'desc', 'asc']
    correct_order = [test1_error, test1_error2, test1_active, test2_error, test2_error2, test2_active]
    for limit in range(1, 4):
        marker = None
        for i in range(0, 7, limit):
            if (i == len(correct_order)):
                correct = []
            else:
                correct = correct_order[i:(i + limit)]
            insts = self._assert_equals_inst_order(correct, filters, sort_keys=sort_keys, sort_dirs=sort_dirs, limit=limit, marker=marker)
            if correct:
                marker = insts[(-1)]['uuid']
                self.assertEqual(correct[(-1)]['uuid'], marker)
