'Verifies that volumes are returned in the correct order.'

def _assertEqualsVolumeOrderResult(self, correct_order, limit=None, sort_keys=None, sort_dirs=None, filters=None, project_id=None, marker=None, match_keys=['id', 'display_name', 'volume_metadata', 'created_at']):

    if project_id:
        result = db.volume_get_all_by_project(self.ctxt, project_id, marker, limit, sort_keys=sort_keys, sort_dirs=sort_dirs, filters=filters)
    else:
        result = db.volume_get_all(self.ctxt, marker, limit, sort_keys=sort_keys, sort_dirs=sort_dirs, filters=filters)
    self.assertEqual(len(correct_order), len(result))
    for (vol1, vol2) in zip(result, correct_order):
        for key in match_keys:
            val1 = vol1.get(key)
            val2 = vol2.get(key)
            if (key == 'volume_metadata'):
                self.assertEqual(len(val1), len(val2))
                val1_dict = {x.key: x.value for x in val1}
                val2_dict = {x.key: x.value for x in val2}
                self.assertDictEqual(val1_dict, val2_dict)
            else:
                self.assertEqual(val1, val2)
    return result
