Fixes share server manager match of identifiers
Previsously, when trying to manage a share server with a given identifier, the db API checked if the identifier is a substring of any existing identifier and if it is True, it raised an InvalidInput Exception. Now, the InvalidInput expception is raised only if the identifier is a suffix of any existing identifier and it is ignored when it is just a preffix. Some queries from the sqlalchemy API share_server_search_by_identifier method were edited to implement this change. Depends-On: I14df0c9c7326ac49274699dc0ef1adb99570784b Closes-bug: #1982429 Change-Id: I4b340ef116625f28e431b069f399771fd29a8de9
This commit is contained in:
parent
1764a22086
commit
f7402cbf27
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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 <https://bugs.launchpad.net/manila/+bug/1982429>`_
|
Loading…
Reference in New Issue
Block a user