Fix get_all API to pass search option filter to cinder api
Change-Id: Ic01956a0fc1ef641dd1b9a28caa40debdc8c114c Closes-Bug: #1391748
This commit is contained in:
parent
3d13a8dc54
commit
1054a90648
|
@ -27,8 +27,11 @@ class FakeCinderClient(object):
|
|||
def get(self, volume_id):
|
||||
return {'id': volume_id}
|
||||
|
||||
def list(self, detailed):
|
||||
return [{'id': 'id1'}, {'id': 'id2'}]
|
||||
def list(self, detailed, search_opts=None):
|
||||
if search_opts is not None and 'id' in search_opts:
|
||||
return [{'id': search_opts['id']}]
|
||||
else:
|
||||
return [{'id': 'id1'}, {'id': 'id2'}]
|
||||
|
||||
def create(self, *args, **kwargs):
|
||||
return {'id': 'created_id'}
|
||||
|
@ -128,6 +131,15 @@ class CinderApiTestCase(test.NoDBTestCase):
|
|||
|
||||
self.assertEqual(['id1', 'id2'], self.api.get_all(self.ctx))
|
||||
|
||||
def test_get_all_with_search(self):
|
||||
cinder.cinderclient(self.ctx).AndReturn(self.cinderclient)
|
||||
cinder._untranslate_volume_summary_view(self.ctx,
|
||||
{'id': 'id1'}).AndReturn('id1')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.assertEqual(['id1'], self.api.get_all(self.ctx,
|
||||
search_opts={'id': 'id1'}))
|
||||
|
||||
def test_check_attach_volume_status_error(self):
|
||||
volume = {'id': 'fake', 'status': 'error'}
|
||||
self.assertRaises(exception.InvalidVolume,
|
||||
|
|
|
@ -286,7 +286,9 @@ class API(object):
|
|||
|
||||
def get_all(self, context, search_opts=None):
|
||||
search_opts = search_opts or {}
|
||||
items = cinderclient(context).volumes.list(detailed=True)
|
||||
items = cinderclient(context).volumes.list(detailed=True,
|
||||
search_opts=search_opts)
|
||||
|
||||
rval = []
|
||||
|
||||
for item in items:
|
||||
|
|
Loading…
Reference in New Issue