Fix deployable get all sort issue and unit test failure.
Change-Id: I6a34c4038a6e0cb15cb77be95003d6b78b29f476
This commit is contained in:
parent
29c4d6c17b
commit
e82036d50c
|
@ -293,8 +293,8 @@ class Connection(api.Connection):
|
|||
return self.deployable_get_by_filters_sort(context, filters,
|
||||
limit=limit, marker=marker,
|
||||
join_columns=join_columns,
|
||||
sort_keys=[sort_key],
|
||||
sort_dirs=[sort_dir])
|
||||
sort_key=sort_key,
|
||||
sort_dir=sort_dir)
|
||||
|
||||
def _exact_deployable_filter_with_attributes(self, query,
|
||||
dpl_filters, legal_keys,
|
||||
|
@ -382,7 +382,7 @@ class Connection(api.Connection):
|
|||
|
||||
def deployable_get_by_filters_sort(self, context, filters, limit=None,
|
||||
marker=None, join_columns=None,
|
||||
sort_keys=None, sort_dirs=None):
|
||||
sort_key=None, sort_dir=None):
|
||||
"""Return deployables that match all filters sorted by the given
|
||||
keys. Deleted deployables will be returned by default, unless
|
||||
there's a filter that says otherwise.
|
||||
|
@ -391,10 +391,6 @@ class Connection(api.Connection):
|
|||
if limit == 0:
|
||||
return []
|
||||
|
||||
sort_keys, sort_dirs = self.process_sort_params(sort_keys,
|
||||
sort_dirs,
|
||||
default_dir='desc')
|
||||
|
||||
query_prefix = model_query(context, models.Deployable)
|
||||
filters = copy.deepcopy(filters)
|
||||
|
||||
|
@ -412,8 +408,8 @@ class Connection(api.Connection):
|
|||
exact_match_filter_names)
|
||||
if query_prefix is None:
|
||||
return []
|
||||
deployables = query_prefix.all()
|
||||
return deployables
|
||||
return _paginate_query(context, models.Deployable, limit, marker,
|
||||
sort_key, sort_dir, query_prefix)
|
||||
|
||||
def attribute_create(self, context, values):
|
||||
if not values.get('uuid'):
|
||||
|
|
|
@ -112,7 +112,15 @@ class Deployable(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
|||
def list(cls, context, filters={}):
|
||||
"""Return a list of Deployable objects."""
|
||||
if filters:
|
||||
db_deps = cls.dbapi.deployable_get_by_filters(context, filters)
|
||||
sort_dir = filters.pop('sort_dir', 'desc')
|
||||
sort_key = filters.pop('sort_key', 'create_at')
|
||||
limit = filters.pop('limit', None)
|
||||
marker = filters.pop('marker_obj', None)
|
||||
db_deps = cls.dbapi.deployable_get_by_filters(context, filters,
|
||||
sort_dir=sort_dir,
|
||||
sort_key=sort_key,
|
||||
limit=limit,
|
||||
marker=marker)
|
||||
else:
|
||||
db_deps = cls.dbapi.deployable_list(context)
|
||||
obj_dpl_list = cls._from_db_object_list(db_deps, context)
|
||||
|
|
|
@ -19,6 +19,7 @@ from six.moves import http_client
|
|||
from cyborg.api.controllers.v1.deployables import Deployable
|
||||
from cyborg.tests.unit.api.controllers.v1 import base as v1_test
|
||||
from cyborg.tests.unit import fake_deployable
|
||||
from cyborg.tests.unit.objects import utils as obj_utils
|
||||
|
||||
|
||||
class TestDeployableController(v1_test.APITestV1):
|
||||
|
@ -26,7 +27,8 @@ class TestDeployableController(v1_test.APITestV1):
|
|||
def setUp(self):
|
||||
super(TestDeployableController, self).setUp()
|
||||
self.headers = self.gen_headers(self.context)
|
||||
self.deployable_uuids = ['10efe63d-dfea-4a37-ad94-4116fba50981']
|
||||
self.deployable_uuids = ['10efe63d-dfea-4a37-ad94-4116fba50981',
|
||||
'10efe63d-dfea-4a37-ad94-4116fba50982']
|
||||
|
||||
@mock.patch('cyborg.objects.Deployable.get')
|
||||
def test_get_one(self, mock_get_dep):
|
||||
|
@ -74,3 +76,18 @@ class TestDeployableController(v1_test.APITestV1):
|
|||
data = response.json_body
|
||||
self.assertEqual(instance_uuid, data['instance_uuid'])
|
||||
mock_deployable_update.assert_called_once()
|
||||
|
||||
def test_get_all_with_sort(self):
|
||||
dps = []
|
||||
for uuid in self.deployable_uuids:
|
||||
dp = obj_utils.create_test_deployable(self.context,
|
||||
uuid=uuid)
|
||||
dps.append(dp)
|
||||
data = self.get_json('/accelerators/deployables?'
|
||||
'filters.field=sort_key&filters.value=created_at'
|
||||
'&filters.field=sort_dir&filters.value=desc',
|
||||
headers=self.headers)
|
||||
self.assertEqual(self.deployable_uuids[1],
|
||||
data['deployables'][0]['uuid'])
|
||||
self.assertEqual(self.deployable_uuids[0],
|
||||
data['deployables'][1]['uuid'])
|
||||
|
|
|
@ -29,3 +29,23 @@ def get_test_accelerator(**kw):
|
|||
'project_id': kw.get('project_id', 'b492a6fb12964ae3bd291ce585107d48'),
|
||||
'user_id': kw.get('user_id', '7009409e21614d1db1ef7a8c5ee101d8'),
|
||||
}
|
||||
|
||||
|
||||
def get_test_deployable(**kw):
|
||||
return {
|
||||
'uuid': kw.get('uuid', '10efe63d-dfea-4a37-ad94-4116fba5098'),
|
||||
'deleted': False,
|
||||
'name': kw.get('name', 'name'),
|
||||
'parent_uuid': kw.get('parent_uuid', None),
|
||||
'address': kw.get('address', '00:7f:0b.2'),
|
||||
'host': kw.get('host', 'host'),
|
||||
'board': kw.get('board', 'KU115'),
|
||||
'vendor': kw.get('vendor', 'Xilinx'),
|
||||
'version': kw.get('version', '1.0'),
|
||||
'type': kw.get('type', '1.0'),
|
||||
'interface_type': 'pci',
|
||||
'assignable': True,
|
||||
'instance_uuid': None,
|
||||
'availability': 'Available',
|
||||
'accelerator_id': kw.get('accelerator_id', 1),
|
||||
}
|
||||
|
|
|
@ -39,3 +39,23 @@ def create_test_accelerator(ctxt, **kw):
|
|||
acc = get_test_accelerator(ctxt, **kw)
|
||||
acc.create(ctxt)
|
||||
return acc
|
||||
|
||||
|
||||
def get_test_deployable(ctxt, **kw):
|
||||
"""Return an Deployable object with appropriate attributes.
|
||||
|
||||
NOTE: The object leaves the attributes marked as changed, such
|
||||
that a create() could be used to commit it to the DB.
|
||||
"""
|
||||
test_dp = db_utils.get_test_deployable(**kw)
|
||||
return objects.Deployable(ctxt, **test_dp)
|
||||
|
||||
|
||||
def create_test_deployable(ctxt, **kw):
|
||||
"""Create and return a test deployable object.
|
||||
|
||||
Create an deployable in the DB and return an Deployable object with
|
||||
appropriate attributes.
|
||||
"""
|
||||
dp = get_test_deployable(ctxt, **kw)
|
||||
return dp.create(ctxt)
|
||||
|
|
Loading…
Reference in New Issue