Merge "Fix export location metadata updates by drivers" into stable/2024.1

This commit is contained in:
Zuul 2024-10-03 13:23:18 +00:00 committed by Gerrit Code Review
commit 84f0415f6e
3 changed files with 75 additions and 2 deletions

View File

@ -4534,9 +4534,17 @@ def _export_locations_update(
'deleted': 0,
})
el.save(session=context.session)
if el['el_metadata']:
new_export_metadata = next(
exl.get('metadata', {})
for exl in export_locations
if exl['path'] == el['path']
)
new_export_metadata = new_export_metadata or el['el_metadata']
if new_export_metadata:
_export_location_metadata_update(
context, el['uuid'], el['el_metadata'],
context, el['uuid'], new_export_metadata,
)
# Now add new export locations

View File

@ -2277,6 +2277,65 @@ class ShareExportLocationsDatabaseAPITestCase(test.TestCase):
# actual result should contain locations in exact same order
self.assertEqual(actual_result, update_locations)
def test_update_export_locations_with_metadata(self):
share = db_utils.create_share()
original_export_locations = [
{
'path': 'fake1/1/',
'is_admin_only': True,
'metadata': {
'foo': 'bar',
'preferred': '1'
},
},
{
'path': 'fake2/1/',
'is_admin_only': True,
'metadata': {
'clem': 'son',
'preferred': '0'
},
},
]
# add initial locations
db_api.export_locations_update(
self.ctxt, share.instance['id'], original_export_locations, False)
updated_export_locations = [
{
'path': 'fake1/1/',
'is_admin_only': True,
'metadata': {
'foo': 'quz',
'preferred': '0'
},
},
{
'path': 'fake2/1/',
'is_admin_only': True,
'metadata': {
'clem': 'son',
'preferred': '1',
},
},
]
# update locations
db_api.export_locations_update(
self.ctxt, share.instance['id'], updated_export_locations, True)
actual_result = db_api.export_location_get_all_by_share_id(
self.ctxt, share['id'])
actual_export_locations = [
{
'path': el['path'],
'is_admin_only': el['is_admin_only'],
'metadata': el['el_metadata'],
} for el in actual_result
]
self.assertEqual(updated_export_locations, actual_export_locations)
def test_update_string(self):
share = db_utils.create_share()
initial_location = 'fake1/1/'

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Share manager drivers can now update export location metadata
(such as the `preferred` attribute) during the `ensure_shares`
routine. (`Launchpad bug: 2053100 <https://launchpad.net/bugs/2053100>`_)