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:
Goutham Pacha Ravi 2021-03-16 09:10:27 -07:00
parent e8810b2019
commit 6981031e31
2 changed files with 24 additions and 4 deletions

View File

@ -4170,7 +4170,11 @@ def share_server_get_all_with_filters(context, filters):
query = query.filter_by( query = query.filter_by(
source_share_server_id=filters.get('source_share_server_id')) source_share_server_id=filters.get('source_share_server_id'))
if filters.get('share_network_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 == models.ShareNetworkSubnet.share_network_id ==
filters.get('share_network_id')) filters.get('share_network_id'))
return query.all() return query.all()

View File

@ -3159,9 +3159,19 @@ class ShareServerDatabaseAPITestCase(test.TestCase):
@ddt.data({'host': 'fakepool@fakehost'}, @ddt.data({'host': 'fakepool@fakehost'},
{'status': constants.STATUS_SERVER_MIGRATING_TO}, {'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): 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() db_utils.create_share_server()
filter_keys = filters.keys() filter_keys = filters.keys()
@ -3170,6 +3180,12 @@ class ShareServerDatabaseAPITestCase(test.TestCase):
self.assertEqual(1, len(results)) self.assertEqual(1, len(results))
for result in results: for result in results:
for key in filter_keys: 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]) self.assertEqual(result[key], filters[key])
@ddt.data('fake@fake', 'host1@backend1') @ddt.data('fake@fake', 'host1@backend1')