Fix the bug of TypeError with JsonFilter

The default scheduler_hints value is None, and if we don't pass
the scheduler_hints , It will report TypeError when creating share
with JsonFilter with Rest API. The TypeError exception is added to
solve this problem.

Change-Id: Iad89491cbbaccac8df161f8f1157c7ebf3291458
Closes-Bug: #1959472
This commit is contained in:
huwenhui 2022-01-29 14:50:08 +08:00
parent 82b9dfe0a6
commit 064046a47f
3 changed files with 16 additions and 1 deletions

View File

@ -137,7 +137,9 @@ class JsonFilter(base_host.BaseHostFilter):
# and scheduler_hints.
try:
query = filter_properties['scheduler_hints']['query']
except KeyError:
# If filter_properties['scheduler_hints'] is None, and TypeError
# will occur, add TypeError exception here.
except (KeyError, TypeError):
query = None
if not query:
return True

View File

@ -264,6 +264,14 @@ class HostFiltersTestCase(test.TestCase):
self.assertRaises(KeyError,
self.filter.host_passes, host, filter_properties)
def test_json_filter_type_errror_passes(self):
filter_properties = {
'scheduler_hints': None
}
host = fakes.FakeHostState('host1',
{'capabilities': {'enabled': True}})
self.assertTrue(self.filter.host_passes, (host, filter_properties))
def test_json_filter_empty_filters_pass(self):
host = fakes.FakeHostState('host1',
{'capabilities': {'enabled': True}})

View File

@ -0,0 +1,5 @@
---
fixes:
- Fix the bug of TypeError with JsonFilter. If the scheduler_hints
value is None, the TypeError exception may occur when creating share
with JsonFilter. The TypeError exception is added to solve this problem.