Fix list zones if shared with multiple projects

This patch fixes a bug when listing zones or updating recordsets in
zones that are shared with more than one project.

Closes-Bug: #2025295
Change-Id: I8af9b5cf8c1473bbf7db71a1fb848fb64509db84
This commit is contained in:
Michael Johnson 2023-06-30 18:51:17 +00:00
parent 3621b9d1b1
commit 011ebe2e7c
3 changed files with 24 additions and 1 deletions

View File

@ -368,7 +368,8 @@ class SQLAlchemyStorage(base.SQLAlchemy):
literal_column('False')),
else_=literal_column('True')).label('shared')
query = select(
tables.zones, shared_case).outerjoin(tables.shared_zones)
tables.zones,
shared_case).outerjoin(tables.shared_zones).distinct()
zones = self._find(
context, tables.zones, objects.Zone, objects.ZoneList,

View File

@ -764,6 +764,23 @@ class SqlalchemyStorageTest(TestCase):
results = self.storage.find_zones(two_context)
self.assertEqual(1, len(results))
def test_find_zones_shared(self):
# Create an admin context
admin_context = self.get_admin_context()
# Create a zone in the admin context
zone = self.create_zone(context=admin_context)
# Share the zone with two other projects
self.share_zone(
zone_id=zone['id'], target_project_id=1, context=admin_context)
self.share_zone(
zone_id=zone['id'], target_project_id=2, context=admin_context)
# Ensure that one zone record is returned from find_zones (LP 2025295)
results = self.storage.find_zones(admin_context)
self.assertEqual(1, len(results))
def test_get_zone(self):
# Create a zone
expected = self.create_zone()

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Fixed issues with list zones and recordsets when a zone is shared with more
than one project.