diff --git a/manila/db/sqlalchemy/api.py b/manila/db/sqlalchemy/api.py index b1e9036a2e..d6e981950a 100644 --- a/manila/db/sqlalchemy/api.py +++ b/manila/db/sqlalchemy/api.py @@ -5110,20 +5110,20 @@ def share_server_search_by_identifier(context, identifier): identifier_field = models.ShareServer.identifier - # try if given identifier is a substring of existing entry's identifier + # try if given identifier is a suffix of existing entry's identifier result = (_share_server_get_query(context).filter( - identifier_field.like('%{}%'.format(identifier))).all()) + identifier_field.like('%{}'.format(identifier))).all()) if not result: # repeat it with underscores instead of hyphens result = (_share_server_get_query(context).filter( - identifier_field.like('%{}%'.format( + identifier_field.like('%{}'.format( identifier.replace("-", "_")))).all()) if not result: # repeat it with hypens instead of underscores result = (_share_server_get_query(context).filter( - identifier_field.like('%{}%'.format( + identifier_field.like('%{}'.format( identifier.replace("_", "-")))).all()) if not result: diff --git a/manila/tests/db/sqlalchemy/test_api.py b/manila/tests/db/sqlalchemy/test_api.py index 3c174bcb8e..2191414fe7 100644 --- a/manila/tests/db/sqlalchemy/test_api.py +++ b/manila/tests/db/sqlalchemy/test_api.py @@ -3731,8 +3731,9 @@ class ShareServerDatabaseAPITestCase(test.TestCase): self.assertEqual(num_records - 1, len(db_api.share_server_get_all(self.ctxt))) - @ddt.data('fake', '-fake-', 'foo_some_fake_identifier_bar', - 'foo-some-fake-identifier-bar', 'foobar') + @ddt.data('foobar', 'fake', '-fake-', 'some_fake_', 'some-fake-', + '-fake-identifier', '_fake_identifier', 'some-fake-identifier', + 'some_fake_identifier') def test_share_server_search_by_identifier(self, identifier): server = { @@ -3744,7 +3745,8 @@ class ShareServerDatabaseAPITestCase(test.TestCase): } server = db_utils.create_share_server(**server) - if identifier == 'foobar': + if identifier in ('foobar', 'fake', '-fake-', 'some_fake_', + 'some-fake-'): self.assertRaises(exception.ShareServerNotFound, db_api.share_server_search_by_identifier, self.ctxt, identifier) diff --git a/releasenotes/notes/fix_share_server_manager_match_id-276202295539dc0f.yaml b/releasenotes/notes/fix_share_server_manager_match_id-276202295539dc0f.yaml new file mode 100644 index 0000000000..c5086030f6 --- /dev/null +++ b/releasenotes/notes/fix_share_server_manager_match_id-276202295539dc0f.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Fix share server manager API match of identifiers by preffix. "Invalid + input received Error" now raises only if the identifiers suffixes matches. + For more details, please refer to + `launchpad bug #1982429 `_