Fix share server lookup
We were missing a join on the share network subnets table to be able to affect a lookup by share network ID. Change-Id: Id121ba942c7840a7cd7574f08a524fd4dbe06f64
This commit is contained in:
parent
e8810b2019
commit
6981031e31
@ -4170,7 +4170,11 @@ def share_server_get_all_with_filters(context, filters):
|
||||
query = query.filter_by(
|
||||
source_share_server_id=filters.get('source_share_server_id'))
|
||||
if filters.get('share_network_id'):
|
||||
query = query.filter(
|
||||
query = query.join(
|
||||
models.ShareNetworkSubnet,
|
||||
models.ShareNetworkSubnet.id ==
|
||||
models.ShareServer.share_network_subnet_id
|
||||
).filter(
|
||||
models.ShareNetworkSubnet.share_network_id ==
|
||||
filters.get('share_network_id'))
|
||||
return query.all()
|
||||
|
@ -3159,9 +3159,19 @@ class ShareServerDatabaseAPITestCase(test.TestCase):
|
||||
|
||||
@ddt.data({'host': 'fakepool@fakehost'},
|
||||
{'status': constants.STATUS_SERVER_MIGRATING_TO},
|
||||
{'source_share_server_id': 'fake_ss_id'})
|
||||
{'source_share_server_id': 'fake_ss_id'},
|
||||
{'share_network_id': uuidutils.generate_uuid()})
|
||||
def test_share_server_get_all_with_filters(self, filters):
|
||||
db_utils.create_share_server(**filters)
|
||||
server_data = copy.copy(filters)
|
||||
share_network_id = server_data.pop('share_network_id', None)
|
||||
share_network_subnet = {}
|
||||
if share_network_id:
|
||||
db_utils.create_share_network(id=share_network_id)
|
||||
share_network_subnet = db_utils.create_share_network_subnet(
|
||||
id=uuidutils.generate_uuid(),
|
||||
share_network_id=share_network_id)
|
||||
server_data['share_network_subnet_id'] = share_network_subnet['id']
|
||||
db_utils.create_share_server(**server_data)
|
||||
db_utils.create_share_server()
|
||||
filter_keys = filters.keys()
|
||||
|
||||
@ -3170,6 +3180,12 @@ class ShareServerDatabaseAPITestCase(test.TestCase):
|
||||
self.assertEqual(1, len(results))
|
||||
for result in results:
|
||||
for key in filter_keys:
|
||||
if key == 'share_network_id':
|
||||
self.assertEqual(share_network_subnet['share_network_id'],
|
||||
filters[key])
|
||||
self.assertEqual(share_network_subnet['id'],
|
||||
result['share_network_subnet_id'])
|
||||
else:
|
||||
self.assertEqual(result[key], filters[key])
|
||||
|
||||
@ddt.data('fake@fake', 'host1@backend1')
|
||||
|
Loading…
Reference in New Issue
Block a user