diff --git a/manila/db/sqlalchemy/api.py b/manila/db/sqlalchemy/api.py index 480d96ebed..091d101d52 100644 --- a/manila/db/sqlalchemy/api.py +++ b/manila/db/sqlalchemy/api.py @@ -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 diff --git a/manila/tests/db/sqlalchemy/test_api.py b/manila/tests/db/sqlalchemy/test_api.py index fa990faa30..a1d722ead9 100644 --- a/manila/tests/db/sqlalchemy/test_api.py +++ b/manila/tests/db/sqlalchemy/test_api.py @@ -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/' diff --git a/releasenotes/notes/bug-2053100-fix-export-path-preferred-attr-updates-32db001aacfc8563.yaml b/releasenotes/notes/bug-2053100-fix-export-path-preferred-attr-updates-32db001aacfc8563.yaml new file mode 100644 index 0000000000..990cc557f7 --- /dev/null +++ b/releasenotes/notes/bug-2053100-fix-export-path-preferred-attr-updates-32db001aacfc8563.yaml @@ -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 `_)