Fix export location metadata updates by drivers

Drivers can set arbitrary key=value metadata to export
paths. The share manager now checks updates to previously
set metadata when drivers update this metadata with the
"ensure_shares" routine.

Change-Id: Ia42de608ba056d71a1deae2c59bfb43a11672ab7
Partial-Bug: #2053100
This commit is contained in:
Goutham Pacha Ravi 2024-09-11 22:19:37 -07:00
parent 1ffa0c1273
commit 3e9d535be1
3 changed files with 75 additions and 2 deletions

View File

@ -4553,9 +4553,17 @@ def _export_locations_update(
'deleted': 0, 'deleted': 0,
}) })
el.save(session=context.session) 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( _export_location_metadata_update(
context, el['uuid'], el['el_metadata'], context, el['uuid'], new_export_metadata,
) )
# Now add new export locations # Now add new export locations

View File

@ -2318,6 +2318,65 @@ class ShareExportLocationsDatabaseAPITestCase(test.TestCase):
# actual result should contain locations in exact same order # actual result should contain locations in exact same order
self.assertEqual(actual_result, update_locations) 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): def test_update_string(self):
share = db_utils.create_share() share = db_utils.create_share()
initial_location = 'fake1/1/' 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>`_)